Class PluginRules
- All Implemented Interfaces:
Rules
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
FieldsModifier and TypeFieldDescriptionprivate Rules
The rules implementation that we are "enhancing" with plugins functionality, as per the Decorator pattern.protected Digester
The Digester instance with which this Rules instance is associated.private String
The path below which this rules object has responsibility.private PluginRules
The Rules object that holds rules applying "above" the mountpoint, ie the next Rules object down in the stack.private PluginContext
A reference to the object that holds all data which should only exist once per digester instance.private PluginManager
Object which contains information about all known plugins.private RulesFactory
The (optional) object which generates new rules instances. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for top-level Rules objects.PluginRules
(Digester digester, String mountPoint, PluginRules parent, Class<?> pluginClass) Constructs a Rules instance which has a parent Rules object (which is different from having a delegate rules object).PluginRules
(Rules decoratedRules) Constructor for top-level Rules object which handles rule-matching using the specified implementation. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Register a new Rule instance matching the specified pattern.void
clear()
Clear all rules.(package private) Rules
This package-scope method is used by the PluginCreateRule class to get direct access to the rules that were dynamically added by the plugin.Return the Digester instance with which this instance is associated.Return the namespace URI that will be applied to all subsequently addedRule
objects.Return the parent Rules object.Return the object which "knows" about all declared plugins.Return the rules factory object (or null if one has not been specified).Deprecated.Call match(namespaceURI,pattern) instead.Return a List of all registered Rule instances that match the specified nodepath, or a zero-length List if there are no matches.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 addedRule
objects.void
setPluginClassAttribute
(String namespaceUri, String attrName) void
setPluginIdAttribute
(String namespaceUri, String attrName) void
setRuleFinders
(List<RuleFinder> ruleFinders) 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.
-
Field Details
-
digester
The Digester instance with which this Rules instance is associated. -
rulesFactory
The (optional) object which generates new rules instances. -
decoratedRules
The rules implementation that we are "enhancing" with plugins functionality, as per the Decorator pattern. -
pluginManager
Object which contains information about all known plugins. -
mountPoint
The path below which this rules object has responsibility. For paths shorter than or equal the mountpoint, the parent's match is called. -
parent
The Rules object that holds rules applying "above" the mountpoint, ie the next Rules object down in the stack. -
pluginContext
A reference to the object that holds all data which should only exist once per digester instance.
-
-
Constructor Details
-
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
Constructor for top-level Rules object which handles rule-matching using the specified implementation. -
PluginRules
PluginRules(Digester digester, String mountPoint, PluginRules parent, Class<?> pluginClass) throws PluginException Constructs a Rules instance which has a parent Rules object (which is different from having a delegate rules object).One of these is created each time a PluginCreateRule's begin method fires, in order to manage the custom rules associated with whatever concrete plugin class the user has specified.
- Parameters:
digester
- is the object this rules will be associated with.mountPoint
- is the digester match path for the element matching a PluginCreateRule which caused this "nested parsing scope" to begin. This is expected to be equal to digester.getMatch().parent
- must be non-null.pluginClass
- is the plugin class whose custom rules will be loaded into this new PluginRules object.- Throws:
PluginException
-
-
Method Details
-
getParent
Return the parent Rules object. -
getDigester
Return the Digester instance with which this instance is associated.- Specified by:
getDigester
in interfaceRules
-
setDigester
Set the Digester instance with which this Rules instance is associated.- Specified by:
setDigester
in interfaceRules
- Parameters:
digester
- The newly associated Digester instance
-
getNamespaceURI
Return the namespace URI that will be applied to all subsequently addedRule
objects.- Specified by:
getNamespaceURI
in interfaceRules
-
setNamespaceURI
Set the namespace URI that will be applied to all subsequently addedRule
objects.- Specified by:
setNamespaceURI
in interfaceRules
- Parameters:
namespaceURI
- Namespace URI that must match on all subsequently added rules, ornull
for matching regardless of the current namespace URI
-
getPluginManager
Return the object which "knows" about all declared plugins.- Returns:
- The pluginManager value
-
getRuleFinders
-
setRuleFinders
-
getRulesFactory
Return the rules factory object (or null if one has not been specified). -
setRulesFactory
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. -
getDecoratedRules
Rules getDecoratedRules()This package-scope method is used by the PluginCreateRule class to get direct access to the rules that were dynamically added by the plugin. No other class should need access to this object. -
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.
-
add
Register a new Rule instance matching the specified pattern. -
clear
public void clear()Clear all rules. -
match
Deprecated.Call match(namespaceURI,pattern) instead.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 theadd()
method. -
match
Return a List of all registered Rule instances that match the specified nodepath, 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 theadd()
method. -
setPluginClassAttribute
-
setPluginIdAttribute
-
getPluginClassAttrNs
-
getPluginClassAttr
-
getPluginIdAttrNs
-
getPluginIdAttr
-