org.apache.commons.digester.plugins

Class PluginCreateRule

Implemented Interfaces:
InitializableRule

public class PluginCreateRule
extends Rule
implements InitializableRule

Allows the original rules for parsing the configuration file to define points at which plugins are allowed, by configuring a PluginCreateRule with the appropriate pattern.

Since:
1.6

Field Summary

private Class
baseClass
A base class that any plugin must derive from.
private Declaration
defaultPlugin
Info about optional default plugin to be used if no plugin-id is specified in the input data.
private PluginConfigurationException
initException
Currently, none of the Rules methods allow exceptions to be thrown.
private String
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.
private String
pluginClassAttr
private String
pluginClassAttrNs
private String
pluginIdAttr
private String
pluginIdAttrNs

Fields inherited from class org.apache.commons.digester.Rule

digester, namespaceURI

Constructor Summary

PluginCreateRule(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

void
begin(String namespace, String name, org.xml.sax.Attributes attributes)
Invoked when the Digester matches this rule against an xml element.
void
body(String namespace, String name, String text)
Process the body text of this element.
void
end(String namespace, String name)
Invoked by the digester when the closing tag matching this Rule's pattern is encountered.
void
fireBeginMethods(List rules, String namespace, String name, org.xml.sax.Attributes list)
Duplicate the processing that the Digester does when firing the begin methods of rules.
private void
fireBodyMethods(List rules, String namespaceURI, String name, String text)
Duplicate the processing that the Digester does when firing the body methods of rules.
void
fireEndMethods(List rules, String namespaceURI, String name)
Duplicate the processing that the Digester does when firing the end methods of rules.
String
getPattern()
Return the pattern that this Rule is associated with.
void
postRegisterInit(String matchPattern)
Invoked after this rule has been added to the set of digester rules, associated with the specified pattern.
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.digester.Rule

begin, begin, body, body, end, end, finish, getDigester, getNamespaceURI, setDigester, setNamespaceURI

Field Details

baseClass

private Class baseClass
A base class that any plugin must derive from.


defaultPlugin

private Declaration 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

private PluginConfigurationException 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.


pattern

private String 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.


pluginClassAttr

private String pluginClassAttr


pluginClassAttrNs

private String pluginClassAttrNs


pluginIdAttr

private String pluginIdAttr


pluginIdAttrNs

private String pluginIdAttrNs

Constructor Details

PluginCreateRule

public PluginCreateRule(Class baseClass)
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

public PluginCreateRule(Class baseClass,
                        Class dfltPluginClass)
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

begin

public void begin(String namespace,
                  String name,
                  org.xml.sax.Attributes attributes)
            throws java.lang.Exception
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.

Parameters:
namespace -
name -
attributes -


body

public void body(String namespace,
                 String name,
                 String text)
            throws Exception
Process the body text of this element.
Overrides:
body in interface Rule

Parameters:
text - The body text of this element


end

public void end(String namespace,
                String name)
            throws Exception
Invoked by the digester when the closing tag matching this Rule's pattern is encountered.
Overrides:
end in interface Rule

Parameters:
namespace - Description of the Parameter
name - Description of the Parameter

See Also:
begin(String,String,Attributes)


fireBeginMethods

public void fireBeginMethods(List rules,
                             String namespace,
                             String name,
                             org.xml.sax.Attributes list)
            throws java.lang.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.


fireBodyMethods

private void fireBodyMethods(List rules,
                             String namespaceURI,
                             String name,
                             String text)
            throws Exception
Duplicate the processing that the Digester does when firing the body methods of rules. It would be really nice if the Digester class provided a way for this functionality to just be invoked directly.


fireEndMethods

public void fireEndMethods(List rules,
                           String namespaceURI,
                           String name)
            throws Exception
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.


getPattern

public String 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


postRegisterInit

public void postRegisterInit(String matchPattern)
            throws PluginConfigurationException
Invoked after this rule has been added to the set of digester rules, associated with the specified pattern. Check all configuration data is valid and remember the pattern for later.
Specified by:
postRegisterInit in interface InitializableRule

Parameters:
matchPattern - is the digester match pattern that is associated with this rule instance, eg "root/widget".

Throws:
PluginConfigurationException -


setPluginClassAttribute

public void setPluginClassAttribute(String namespaceUri,
                                    String attrName)


setPluginIdAttribute

public void setPluginIdAttribute(String namespaceUri,
                                 String attrName)


Copyright (c) 2001-2004 - Apache Software Foundation