public void add()

in commons-digester3-core/src/main/java/org/apache/commons/digester3/plugins/PluginRules.java [155:216]


    public void add( String pattern, final Rule rule )
    {
        final Log log = LogUtils.getLogger( digester );
        final boolean debug = log.isDebugEnabled();

        if ( debug )
        {
            log.debug( "add entry" + ": mapping pattern [" + pattern + "]" + " to rule of type ["
                + rule.getClass().getName() + "]" );
        }

        // allow patterns with a leading slash character
        if ( pattern.startsWith( "/" ) )
        {
            pattern = pattern.substring( 1 );
        }

        if ( mountPoint != null && !pattern.equals( mountPoint ) && !pattern.startsWith( mountPoint + "/" ) )
        {
            // This can only occur if a plugin attempts to add a
            // rule with a pattern that doesn't start with the
            // prefix passed to the addRules method. Plugins mustn't
            // add rules outside the scope of the tag they were specified
            // on, so refuse this.

            // alas, can't throw exception
            log.warn( "An attempt was made to add a rule with a pattern that"
                + "is not at or below the mountpoint of the current" + " PluginRules object." + " Rule pattern: "
                + pattern + ", mountpoint: " + mountPoint + ", rule type: " + rule.getClass().getName() );
            return;
        }

        decoratedRules.add( pattern, rule );

        if ( rule instanceof InitializableRule )
        {
            try
            {
                ( (InitializableRule) rule ).postRegisterInit( pattern );
            }
            catch ( final PluginConfigurationException e )
            {
                // Currently, Digester doesn't handle exceptions well
                // from the add method. The workaround is for the
                // initializable rule to remember that its initialization
                // failed, and to throw the exception when begin is
                // called for the first time.
                if ( debug )
                {
                    log.debug( "Rule initialization failed", e );
                }
                // throw e; -- alas, can't do this
                return;
            }
        }

        if ( debug )
        {
            log.debug( "add exit" + ": mapped pattern [" + pattern + "]" + " to rule of type ["
                + rule.getClass().getName() + "]" );
        }
    }