/* $Id: RulesBase.java 992060 2010-09-02 19:09:47Z simonetripodi $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.ArrayList; import java.util.HashMap; import java.util.List; /** *
Default implementation of the Rules
interface that supports
* the standard rule matching behavior. This class can also be used as a
* base class for specialized Rules
implementations.
The matching policies implemented by this class support two different * types of pattern matching rules:
*<c>
element, nested inside a <b>
* element, which is nested inside an <a>
element.<b>
element, nested inside an <a>
* element, no matter how deeply the pair is nested.Note that wildcard patterns are ignored if an explicit match can be found * (and when multiple wildcard patterns match, only the longest, ie most * explicit, pattern is considered a match).
* *See the package documentation for package org.apache.commons.digester * for more information.
*/ public class RulesBase implements Rules { // ----------------------------------------------------- Instance Variables /** * The set of registered Rule instances, keyed by the matching pattern. * Each value is a List containing the Rules for that pattern, in the * order that they were orginally registered. */ protected HashMapRule
* objects are relevant, or null
for matching independent
* of namespaces.
*/
protected String namespaceURI = null;
/**
* The set of registered Rule instances, in the order that they were
* originally registered.
*/
protected ArrayListRule
objects.
*/
public String getNamespaceURI() {
return (this.namespaceURI);
}
/**
* Set the namespace URI that will be applied to all subsequently
* added Rule
objects.
*
* @param namespaceURI Namespace URI that must match on all
* subsequently added rules, or null
for matching
* regardless of the current namespace URI
*/
public void setNamespaceURI(String namespaceURI) {
this.namespaceURI = namespaceURI;
}
// --------------------------------------------------------- Public Methods
/**
* Register a new Rule instance matching the specified pattern.
*
* @param pattern Nesting pattern to be matched for this Rule
* @param rule Rule instance to be registered
*/
public void add(String pattern, Rule rule) {
// to help users who accidently add '/' to the end of their patterns
int patternLength = pattern.length();
if (patternLength>1 && pattern.endsWith("/")) {
pattern = pattern.substring(0, patternLength-1);
}
Listadd()
* method.
*
* @param pattern Nesting pattern to be matched
*
* @deprecated Call match(namespaceURI,pattern) instead.
*/
@Deprecated
public Listadd()
* method.
*
* @param namespaceURI Namespace URI for which to select matching rules,
* or null
to match regardless of namespace URI
* @param pattern Nesting pattern to be matched
*/
public Listadd()
* method.
*/
public Listnull
.
*
* @param namespaceURI Namespace URI to match, or null
to
* select matching rules regardless of namespace URI
* @param pattern Pattern to be matched
*/
protected List