in commons-digester3-core/src/main/java/org/apache/commons/digester3/plugins/PluginCreateRule.java [164:296]
public void postRegisterInit( final String matchPattern )
{
final Log log = LogUtils.getLogger( getDigester() );
final boolean debug = log.isDebugEnabled();
if ( debug )
{
log.debug( "PluginCreateRule.postRegisterInit" + ": rule registered for pattern [" + matchPattern + "]" );
}
if ( getDigester() == null )
{
// We require setDigester to be called before this method.
// Note that this means that PluginCreateRule cannot be added
// to a Rules object which has not yet been added to a
// Digester object.
initException =
new PluginConfigurationException( "Invalid invocation of postRegisterInit" + ": digester not set." );
throw initException;
}
if ( pattern != null )
{
// We have been called twice, ie a single instance has been
// associated with multiple patterns.
//
// Generally, Digester Rule instances can be associated with
// multiple patterns. However for plugins, this creates some
// complications. Some day this may be supported; however for
// now we just reject this situation.
initException =
new PluginConfigurationException( "A single PluginCreateRule instance has been mapped to"
+ " multiple patterns; this is not supported." );
throw initException;
}
if ( matchPattern.indexOf( '*' ) != -1 )
{
// having wildcards in patterns is extremely difficult to
// deal with. For now, we refuse to allow this.
//
// TODO: check for any chars not valid in xml element name
// rather than just *.
//
// Reasons include:
// (a) handling recursive plugins, and
// (b) determining whether one pattern is "below" another,
// as done by PluginRules. Without wildcards, "below"
// just means startsWith, which is easy to check.
initException =
new PluginConfigurationException( "A PluginCreateRule instance has been mapped to" + " pattern ["
+ matchPattern + "]." + " This pattern includes a wildcard character."
+ " This is not supported by the plugin architecture." );
throw initException;
}
if ( baseClass == null )
{
baseClass = Object.class;
}
final PluginRules rules = (PluginRules) getDigester().getRules();
final PluginManager pm = rules.getPluginManager();
// check default class is valid
if ( defaultPlugin != null )
{
if ( !baseClass.isAssignableFrom( defaultPlugin.getPluginClass() ) )
{
initException =
new PluginConfigurationException( "Default class [" + defaultPlugin.getPluginClass().getName()
+ "] does not inherit from [" + baseClass.getName() + "]." );
throw initException;
}
try
{
defaultPlugin.init( getDigester(), pm );
}
catch ( final PluginException pwe )
{
throw new PluginConfigurationException( pwe.getMessage(), pwe.getCause() );
}
}
// remember the pattern for later
pattern = matchPattern;
if ( pluginClassAttr == null )
{
// the user hasn't set explicit xml attr names on this rule,
// so fetch the default values
pluginClassAttrNs = rules.getPluginClassAttrNs();
pluginClassAttr = rules.getPluginClassAttr();
if ( debug )
{
log.debug( "init: pluginClassAttr set to per-digester values [" + "ns=" + pluginClassAttrNs + ", name="
+ pluginClassAttr + "]" );
}
}
else
{
if ( debug )
{
log.debug( "init: pluginClassAttr set to rule-specific values [" + "ns=" + pluginClassAttrNs
+ ", name=" + pluginClassAttr + "]" );
}
}
if ( pluginIdAttr == null )
{
// the user hasn't set explicit xml attr names on this rule,
// so fetch the default values
pluginIdAttrNs = rules.getPluginIdAttrNs();
pluginIdAttr = rules.getPluginIdAttr();
if ( debug )
{
log.debug( "init: pluginIdAttr set to per-digester values [" + "ns=" + pluginIdAttrNs + ", name="
+ pluginIdAttr + "]" );
}
}
else
{
if ( debug )
{
log.debug( "init: pluginIdAttr set to rule-specific values [" + "ns=" + pluginIdAttrNs + ", name="
+ pluginIdAttr + "]" );
}
}
}