All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feilong.lib.digester3.binder.AbstractBackToLinkedRuleBuilder Maven / Gradle / Ivy

Go to download

feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.

There is a newer version: 4.0.8
Show newest version
package com.feilong.lib.digester3.binder;

import com.feilong.lib.digester3.Rule;

/**
 * Builder invoked to back to main {@link LinkedRuleBuilder}.
 *
 * @since 3.0
 */
abstract class AbstractBackToLinkedRuleBuilder implements RuleProvider{

    private final String      keyPattern;

    private final String      namespaceURI;

    private final RulesBinder mainBinder;

    AbstractBackToLinkedRuleBuilder(final String keyPattern, final String namespaceURI, final RulesBinder mainBinder,
                    final LinkedRuleBuilder mainBuilder){
        this.keyPattern = keyPattern;
        this.namespaceURI = namespaceURI;
        this.mainBinder = mainBinder;
    }

    /**
     * Returns the namespace URI for which this Rule is relevant, if any.
     *
     * @return The namespace URI for which this Rule is relevant, if any
     */
    public final String getNamespaceURI(){
        return this.namespaceURI;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final R get(){
        R rule = this.createRule();
        if (rule != null && this.namespaceURI != null){
            rule.setNamespaceURI(this.namespaceURI);
        }
        return rule;
    }

    protected final void reportError(String methodChain,String message){
        this.mainBinder.addError("{ forPattern( \"%s\" ).%s } %s", this.keyPattern, methodChain, message);
    }

    /**
     * Returns the rule pattern associated to this builder.
     *
     * @return The rule pattern associated to this builder
     */
    public final String getPattern(){
        return keyPattern;
    }

    /**
     * Provides an instance of {@link Rule}. Must never return null.
     *
     * @return an instance of {@link Rule}.
     * @see #get()
     */
    protected abstract R createRule();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy