org.apache.commons.digester3.plugins
Class PluginRules

java.lang.Object
  extended by org.apache.commons.digester3.plugins.PluginRules
All Implemented Interfaces:
Rules

public class PluginRules
extends Object
implements Rules

A custom digester Rules manager which must be used as the Rules object when using the plugins module functionality.

During parsing, a linked list of PluginCreateRule instances develop, and this list also acts like a stack. The original instance that was set before the Digester started parsing is always at the tail of the list, and the Digester always holds a reference to the instance at the head of the list in the rules member. Initially, this list/stack holds just one instance, ie head and tail are the same object.

When the start of an xml element causes a PluginCreateRule to fire, a new PluginRules instance is created and inserted at the head of the list (ie pushed onto the stack of Rules objects). Digester.getRules() therefore returns this new Rules object, and any custom rules associated with that plugin are added to that instance.

When the end of the xml element is encountered (and therefore the PluginCreateRule end method fires), the stack of Rules objects is popped, so that Digester.getRules returns the previous Rules object.

Since:
1.6

Field Summary
protected  Digester digester
          The Digester instance with which this Rules instance is associated.
 
Constructor Summary
PluginRules()
          Constructor for top-level Rules objects.
PluginRules(Rules decoratedRules)
          Constructor for top-level Rules object which handles rule-matching using the specified implementation.
 
Method Summary
 void add(String pattern, Rule rule)
          Register a new Rule instance matching the specified pattern.
 void clear()
          Clear all rules.
 Digester getDigester()
          Return the Digester instance with which this instance is associated.
 String getNamespaceURI()
          Return the namespace URI that will be applied to all subsequently added Rule objects.
 Rules getParent()
          Return the parent Rules object.
 String getPluginClassAttr()
          See PluginContext.getPluginClassAttr().
 String getPluginClassAttrNs()
          See PluginContext.getPluginClassAttrNs().
 String getPluginIdAttr()
          See PluginContext.getPluginIdAttr().
 String getPluginIdAttrNs()
          See PluginContext.getPluginIdAttrNs().
 PluginManager getPluginManager()
          Return the object which "knows" about all declared plugins.
 List<RuleFinder> getRuleFinders()
          See PluginContext.getRuleFinders().
 RulesFactory getRulesFactory()
          Return the rules factory object (or null if one has not been specified).
 List<Rule> match(String namespaceURI, String path, String name, Attributes attributes)
          Return a List of all registered Rule instances that match the specified nesting pattern, or a zero-length List if there are no matches.
 List<Rule> rules()
          Return the list of rules registered with this object, in the order they were registered with this object.
 void setDigester(Digester digester)
          Set the Digester instance with which this Rules instance is associated.
 void setNamespaceURI(String namespaceURI)
          Set the namespace URI that will be applied to all subsequently added Rule objects.
 void setPluginClassAttribute(String namespaceUri, String attrName)
          See PluginContext.setPluginClassAttribute(java.lang.String, java.lang.String).
 void setPluginIdAttribute(String namespaceUri, String attrName)
          See PluginContext.setPluginIdAttribute(java.lang.String, java.lang.String).
 void setRuleFinders(List<RuleFinder> ruleFinders)
          See PluginContext.setRuleFinders(java.util.List).
 void setRulesFactory(RulesFactory factory)
          Set the object which is used to generate the new Rules instances created to hold and process the rules associated with each plugged-in class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

digester

protected Digester digester
The Digester instance with which this Rules instance is associated.

Constructor Detail

PluginRules

public PluginRules()
Constructor for top-level Rules objects. Exactly one of these must be created and installed into the Digester instance as the Rules object before parsing starts.


PluginRules

public PluginRules(Rules decoratedRules)
Constructor for top-level Rules object which handles rule-matching using the specified implementation.

Parameters:
decoratedRules - The top-level Rules object which handles rule-matching using the specified implementation.
Method Detail

getParent

public Rules getParent()
Return the parent Rules object.

Returns:
the parent Rules object.

getDigester

public Digester getDigester()
Return the Digester instance with which this instance is associated.

Specified by:
getDigester in interface Rules
Returns:
the Digester instance with which this instance is associated.

setDigester

public void setDigester(Digester digester)
Set the Digester instance with which this Rules instance is associated.

Specified by:
setDigester in interface Rules
Parameters:
digester - The newly associated Digester instance

getNamespaceURI

public String getNamespaceURI()
Return the namespace URI that will be applied to all subsequently added Rule objects.

Specified by:
getNamespaceURI in interface Rules
Returns:
the namespace URI that will be applied to all subsequently added Rule objects.

setNamespaceURI

public void setNamespaceURI(String namespaceURI)
Set the namespace URI that will be applied to all subsequently added Rule objects.

Specified by:
setNamespaceURI in interface Rules
Parameters:
namespaceURI - Namespace URI that must match on all subsequently added rules, or null for matching regardless of the current namespace URI

getPluginManager

public PluginManager getPluginManager()
Return the object which "knows" about all declared plugins.

Returns:
The pluginManager value

getRuleFinders

public List<RuleFinder> getRuleFinders()
See PluginContext.getRuleFinders().

Returns:
the list of RuleFinder objects

setRuleFinders

public void setRuleFinders(List<RuleFinder> ruleFinders)
See PluginContext.setRuleFinders(java.util.List).

Parameters:
ruleFinders - the list of RuleFinder objects

getRulesFactory

public RulesFactory getRulesFactory()
Return the rules factory object (or null if one has not been specified).

Returns:
the rules factory object.

setRulesFactory

public void setRulesFactory(RulesFactory factory)
Set the object which is used to generate the new Rules instances created to hold and process the rules associated with each plugged-in class.

Parameters:
factory - the rules factory object

rules

public List<Rule> rules()
Return the list of rules registered with this object, in the order they were registered with this object.

Note that Rule objects stored in parent Rules objects are not returned by this method.

Specified by:
rules in interface Rules
Returns:
list of all Rule objects known to this Rules instance.

add

public void add(String pattern,
                Rule rule)
Register a new Rule instance matching the specified pattern.

Specified by:
add in interface Rules
Parameters:
pattern - Nesting pattern to be matched for this Rule. This parameter treats equally patterns that begin with and without a leading slash ('/').
rule - Rule instance to be registered

clear

public void clear()
Clear all rules.

Specified by:
clear in interface Rules

match

public List<Rule> match(String namespaceURI,
                        String path,
                        String name,
                        Attributes attributes)
Return a List of all registered Rule instances that match the specified nesting pattern, or a zero-length List if there are no matches. If more than one Rule instance matches, they must be returned in the order originally registered through the add() method.

Specified by:
match in interface Rules
Parameters:
namespaceURI - Namespace URI for which to select matching rules, or null to match regardless of namespace URI
path - Nesting pattern to be matched
name - the local name if the parser is namespace aware, or just the element name otherwise
attributes - The attribute list of the current matching element
Returns:
a List of all registered Rule instances that match the specified nesting pattern

setPluginClassAttribute

public void setPluginClassAttribute(String namespaceUri,
                                    String attrName)
See PluginContext.setPluginClassAttribute(java.lang.String, java.lang.String).

Parameters:
namespaceUri - is the namespace uri that the specified attribute is in. If the attribute is in no namespace, then this should be null. Note that if a namespace is used, the attrName value should not contain any kind of namespace-prefix. Note also that if you are using a non-namespace-aware parser, this parameter must be null.
attrName - is the attribute whose value contains the name of the class to be instantiated.

setPluginIdAttribute

public void setPluginIdAttribute(String namespaceUri,
                                 String attrName)
See PluginContext.setPluginIdAttribute(java.lang.String, java.lang.String).

Parameters:
namespaceUri - is the namespace uri that the specified attribute is in. If the attribute is in no namespace, then this should be null. Note that if a namespace is used, the attrName value should not contain any kind of namespace-prefix. Note also that if you are using a non-namespace-aware parser, this parameter must be null.
attrName - is the attribute whose value contains the id of the plugin declaration to be used when instantiating an object.

getPluginClassAttrNs

public String getPluginClassAttrNs()
See PluginContext.getPluginClassAttrNs().

Returns:
the namespace for the xml attribute which indicates which class is to be plugged in.

getPluginClassAttr

public String getPluginClassAttr()
See PluginContext.getPluginClassAttr().

Returns:
the namespace for the xml attribute which indicates which class is to be plugged in.

getPluginIdAttrNs

public String getPluginIdAttrNs()
See PluginContext.getPluginIdAttrNs().

Returns:
the namespace for the xml attribute which indicates which previous plugin declaration should be used.

getPluginIdAttr

public String getPluginIdAttr()
See PluginContext.getPluginIdAttr().

Returns:
the namespace for the xml attribute which indicates which previous plugin declaration should be used.


Copyright © 2001-2011 The Apache Software Foundation. All Rights Reserved.