public class WithDefaultsRulesWrapper extends java.lang.Object implements 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.
Constructor and Description |
---|
WithDefaultsRulesWrapper(Rules wrappedRules)
Base constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String pattern,
Rule rule)
Adds a Rule to be fired on given pattern.
|
void |
addDefault(Rule rule)
Adds a rule to be fired when wrapped implementation returns no matches
|
void |
clear()
Clears all Rule's
|
java.util.List<Rule> |
getDefaults()
Gets Rule's which will be fired when the wrapped implementation returns no matches
|
Digester |
getDigester()
Gets digester using these Rules
|
java.lang.String |
getNamespaceURI()
Gets namespace to apply to Rule's added
|
java.util.List<Rule> |
match(java.lang.String namespaceURI,
java.lang.String pattern)
Return list of rules matching given pattern.
|
java.util.List<Rule> |
rules()
Gets all rules
|
void |
setDigester(Digester digester)
Sets digester using these Rules
|
void |
setNamespaceURI(java.lang.String namespaceURI)
Sets namespace to apply to Rule's added subsequently
|
public WithDefaultsRulesWrapper(Rules wrappedRules)
wrappedRules
- the wrapped Rules
implementation, not nulljava.lang.IllegalArgumentException
- when wrappedRules
is nullpublic Digester getDigester()
getDigester
in interface Rules
public void setDigester(Digester digester)
setDigester
in interface Rules
digester
- The newly associated Digester instancepublic java.lang.String getNamespaceURI()
getNamespaceURI
in interface Rules
public void setNamespaceURI(java.lang.String namespaceURI)
setNamespaceURI
in interface Rules
namespaceURI
- Namespace URI that must match on all
subsequently added rules, or null
for matching
regardless of the current namespace URIpublic java.util.List<Rule> getDefaults()
public java.util.List<Rule> match(java.lang.String namespaceURI, java.lang.String pattern)
public void addDefault(Rule rule)
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.