Class PluginCreateRule
- All Implemented Interfaces:
InitializableRule
- Since:
- 1.6
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Class
<?> A base class that any plugin must derive from.private Declaration
Info about optional default plugin to be used if no plugin-id is specified in the input data.private PluginConfigurationException
Currently, none of the Rules methods allow exceptions to be thrown.private String
In order to invoke the addRules method on the plugin class correctly, we need to know the pattern which this rule is matched by.private String
private String
private String
private String
-
Constructor Summary
ConstructorsConstructorDescriptionPluginCreateRule
(Class<?> baseClass) Create a plugin rule where the user must specify a plugin-class or plugin-id.PluginCreateRule
(Class<?> baseClass, Class<?> dfltPluginClass) Create a plugin rule where the user may specify a plugin.PluginCreateRule
(Class<?> baseClass, Class<?> dfltPluginClass, RuleLoader dfltPluginRuleLoader) Create a plugin rule where the user may specify a plugin. -
Method Summary
Modifier and TypeMethodDescriptionvoid
begin
(String namespace, String name, Attributes attributes) Invoked when the Digester matches this rule against an xml element.void
This method is called when the body of a matching XML element is encountered.void
This method is called when the end of a matching XML element is encountered.void
fireBeginMethods
(List<Rule> rules, String namespace, String name, Attributes list) Duplicate the processing that the Digester does when firing the begin methods of rules.private void
Duplicate the processing that the Digester does when firing theRule.body(String, String, String)
methods of rules.void
fireEndMethods
(List<Rule> rules, String namespaceURI, String name) Duplicate the processing that the Digester does when firing the end methods of rules.Return the pattern that this Rule is associated with.void
postRegisterInit
(String matchPattern) Called after this Rule object has been added to the list of all Rules.void
setPluginClassAttribute
(String namespaceUri, String attrName) Sets the xml attribute which the input xml uses to indicate to a PluginCreateRule which class should be instantiated.void
setPluginIdAttribute
(String namespaceUri, String attrName) Sets the xml attribute which the input xml uses to indicate to a PluginCreateRule which plugin declaration is being referenced.Methods inherited from class org.apache.commons.digester3.Rule
finish, getDigester, getNamespaceURI, setDigester, setNamespaceURI
-
Field Details
-
pluginClassAttrNs
-
pluginClassAttr
-
pluginIdAttrNs
-
pluginIdAttr
-
pattern
In order to invoke the addRules method on the plugin class correctly, we need to know the pattern which this rule is matched by. -
baseClass
A base class that any plugin must derive from. -
defaultPlugin
Info about optional default plugin to be used if no plugin-id is specified in the input data. This can simplify the syntax where one particular plugin is usually used. -
initException
Currently, none of the Rules methods allow exceptions to be thrown. Therefore if this class cannot initialise itself properly, it cannot cause the digester to stop. Instead, we cache the exception and throw it the first time the begin() method is called.
-
-
Constructor Details
-
PluginCreateRule
Create a plugin rule where the user must specify a plugin-class or plugin-id.- Parameters:
baseClass
- is the class which any specified plugin must be descended from.
-
PluginCreateRule
Create a plugin rule where the user may specify a plugin. If the user doesn't specify a plugin, then the default class specified in this constructor is used.- Parameters:
baseClass
- is the class which any specified plugin must be descended from.dfltPluginClass
- is the class which will be used if the user doesn't specify any plugin-class or plugin-id. This class will have custom rules installed for it just like a declared plugin.
-
PluginCreateRule
public PluginCreateRule(Class<?> baseClass, Class<?> dfltPluginClass, RuleLoader dfltPluginRuleLoader) Create a plugin rule where the user may specify a plugin. If the user doesn't specify a plugin, then the default class specified in this constructor is used.- Parameters:
baseClass
- is the class which any specified plugin must be descended from.dfltPluginClass
- is the class which will be used if the user doesn't specify any plugin-class or plugin-id. This class will have custom rules installed for it just like a declared plugin.dfltPluginRuleLoader
- is a RuleLoader instance which knows how to load the custom rules associated with this default plugin.
-
-
Method Details
-
setPluginClassAttribute
Sets the xml attribute which the input xml uses to indicate to a PluginCreateRule which class should be instantiated.See
PluginRules.setPluginClassAttribute(java.lang.String, java.lang.String)
for more info.- 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
Sets the xml attribute which the input xml uses to indicate to a PluginCreateRule which plugin declaration is being referenced.See
PluginRules.setPluginIdAttribute(java.lang.String, java.lang.String)
for more info.- 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.
-
postRegisterInit
Called after this Rule object has been added to the list of all Rules. Note that if a single InitializableRule instance is associated with more than one pattern, then this method will be called more than once.- Specified by:
postRegisterInit
in interfaceInitializableRule
- Parameters:
matchPattern
- is the digester match pattern that will trigger this rule.
-
begin
Invoked when the Digester matches this rule against an xml element.A new instance of the target class is created, and pushed onto the stack. A new "private" PluginRules object is then created and set as the digester's default Rules object. Any custom rules associated with the plugin class are then loaded into that new Rules object. Finally, any custom rules that are associated with the current pattern (such as SetPropertiesRules) have their begin methods executed.
- Overrides:
begin
in classRule
- Parameters:
namespace
- the namespace URI of the matching element, or an empty string if the parser is not namespace aware or the element has no namespacename
- the local name if the parser is namespace aware, or just the element name otherwiseattributes
- The attribute list of this element- Throws:
Exception
- if any error occurs
-
body
This method is called when the body of a matching XML element is encountered. If the element has no body, this method is called with an empty string as the body text.- Overrides:
body
in classRule
- Parameters:
namespace
- the namespace URI of the matching element, or an empty string if the parser is not namespace aware or the element has no namespacename
- the local name if the parser is namespace aware, or just the element name otherwisetext
- The text of the body of this element- Throws:
Exception
- if any error occurs
-
end
This method is called when the end of a matching XML element is encountered.- Overrides:
end
in classRule
- Parameters:
namespace
- the namespace URI of the matching element, or an empty string if the parser is not namespace aware or the element has no namespacename
- the local name if the parser is namespace aware, or just the element name otherwise- Throws:
Exception
- if any error occurs
-
getPattern
Return the pattern that this Rule is associated with.In general, Rule instances can be associated with multiple patterns. A PluginCreateRule, however, will only function correctly when associated with a single pattern. It is possible to fix this, but I can't be bothered just now because this feature is unlikely to be used.
- Returns:
- The pattern value
-
fireBeginMethods
public void fireBeginMethods(List<Rule> rules, String namespace, String name, Attributes list) throws Exception Duplicate the processing that the Digester does when firing the begin methods of rules. It would be really nice if the Digester class provided a way for this functionality to just be invoked directly.- Parameters:
rules
- The rules whichRule.begin(String, String, Attributes)
method has to be firednamespace
- the namespace URI of the matching element, or an empty string if the parser is not namespace aware or the element has no namespacename
- the local name if the parser is namespace aware, or just the element name otherwiselist
- The attribute list of this element- Throws:
Exception
- if any error occurs
-
fireBodyMethods
private void fireBodyMethods(List<Rule> rules, String namespaceURI, String name, String text) throws Exception Duplicate the processing that the Digester does when firing theRule.body(String, String, String)
methods of rules. It would be really nice if the Digester class provided a way for this functionality to just be invoked directly.- Parameters:
rules
- The rules whichRule.body(String, String, String)
method has to be firedname
- the local name if the parser is namespace aware, or just the element name otherwisetext
- The text of the body of this elementnamespace
- the namespace URI of the matching element, or an empty string if the parser is not namespace aware or the element has no namespace- Throws:
Exception
- if any error occurs
-
fireEndMethods
Duplicate the processing that the Digester does when firing the end methods of rules. It would be really nice if the Digester class provided a way for this functionality to just be invoked directly.- Parameters:
rules
- The rules whichRule.end(String, String)
method has to be firednamespaceURI
- the namespace URI of the matching element, or an empty string if the parser is not namespace aware or the element has no namespacename
- the local name if the parser is namespace aware, or just the element name otherwise- Throws:
Exception
- if any error occurs
-