Class WithDefaultsRulesWrapper
java.lang.Object
org.apache.commons.digester3.WithDefaultsRulesWrapper
- All Implemented Interfaces:
Rules
Rules Decorator that returns default rules when no matches are returned by the wrapped
implementation.
This allows default Rule instances to be added to any existing Rules implementation. These
default Rule instances will be returned for any match for which the wrapped implementation does not
return any matches.
For example,
Rule alpha; ... WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new BaseRules()); rules.addDefault(alpha); ... digester.setRules(rules); ...when a pattern does not match any other rule, then rule alpha will be called.
WithDefaultsRulesWrapper follows the Decorator pattern.
- Since:
- 1.6
-
Field Summary
FieldsModifier and TypeFieldDescriptionAll rules (preserves order in which they were originally added)Rules to be fired when the wrapped implementations returns none.private RulesThe Rules implementation that this class wraps. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRegister a new Rule instance matching the specified pattern.voidaddDefault(Rule rule) Adds a rule to be fired when wrapped implementation returns no matchesvoidclear()Clear all existing Rule instance registrations.Gets Rule's which will be fired when the wrapped implementation returns no matchesReturn the Digester instance with which this Rules instance is associated.Return the namespace URI that will be applied to all subsequently addedRuleobjects.match(String namespaceURI, String pattern, 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.rules()Return a List of all registered Rule instances, or a zero-length List if there are no registered Rule instances.voidsetDigester(Digester digester) Set the Digester instance with which this Rules instance is associated.voidsetNamespaceURI(String namespaceURI) Set the namespace URI that will be applied to all subsequently addedRuleobjects.
-
Field Details
-
wrappedRules
The Rules implementation that this class wraps. -
defaultRules
-
allRules
-
-
Constructor Details
-
WithDefaultsRulesWrapper
Base constructor.- Parameters:
wrappedRules- the wrappedRulesimplementation, not null
-
-
Method Details
-
getDigester
Return the Digester instance with which this Rules instance is associated.- Specified by:
getDigesterin interfaceRules- Returns:
- the Digester instance with which this Rules instance is associated
-
setDigester
Set the Digester instance with which this Rules instance is associated.- Specified by:
setDigesterin interfaceRules- Parameters:
digester- The newly associated Digester instance
-
getNamespaceURI
Return the namespace URI that will be applied to all subsequently addedRuleobjects.- Specified by:
getNamespaceURIin interfaceRules- Returns:
- the namespace URI that will be applied to all subsequently added
Ruleobjects.
-
setNamespaceURI
Set the namespace URI that will be applied to all subsequently addedRuleobjects.- Specified by:
setNamespaceURIin interfaceRules- Parameters:
namespaceURI- Namespace URI that must match on all subsequently added rules, ornullfor matching regardless of the current namespace URI
-
getDefaults
-
match
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.- Specified by:
matchin interfaceRules- Parameters:
namespaceURI- Namespace URI for which to select matching rules, ornullto match regardless of namespace URIpattern- Nesting pattern to be matchedname- the local name if the parser is namespace aware, or just the element name otherwiseattributes- The attribute list of the current matching element- Returns:
- a List of all registered Rule instances that match the specified nesting pattern
-
addDefault
Adds a rule to be fired when wrapped implementation returns no matches- Parameters:
rule- a Rule to be fired when wrapped implementation returns no matches
-
rules
Return a List of all registered Rule instances, or a zero-length List if there are no registered Rule instances. If more than one Rule instance has been registered, they must be returned in the order originally registered through theadd()method. -
clear
-
add
-