Package org.apache.commons.logging

Examples of org.apache.commons.logging.Log


     * with this rule instance, eg "root/widget".
     * @exception PluginConfigurationException
     */
    public void postRegisterInit(String matchPattern)
                                 throws PluginConfigurationException {
        Log log = LogUtils.getLogger(digester);
        boolean debug = log.isDebugEnabled();
        if (debug) {
            log.debug("PluginCreateRule.postRegisterInit" +
                      ": rule registered for pattern [" + matchPattern + "]");
        }

        if (digester == 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;
        }
       
        PluginRules rules = (PluginRules) digester.getRules();
        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(digester, pm);
               
            } catch(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 + "]");
            }
        }
View Full Code Here


     * This parameter treats equally patterns that begin with and without
     * a leading slash ('/').
     * @param rule Rule instance to be registered
     */
    public void add(String pattern, Rule rule) {
        Log log = LogUtils.getLogger(digester);
        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) {
            if (!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 (PluginConfigurationException e) {
                // Currently, Digester doesn't handle exceptions well
                // from the add method. The workaround is for the
                // initialisable rule to remember that its initialisation
                // failed, and to throw the exception when begin is
                // called for the first time.
                if (debug) {
                    log.debug("Rule initialisation 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() + "]");
        }
    }
View Full Code Here

     * @param namespaceURI Namespace URI for which to select matching rules,
     *  or <code>null</code> to match regardless of namespace URI
     * @param path the path to the xml nodes to be matched.
     */
    public List match(String namespaceURI, String path) {
        Log log = LogUtils.getLogger(digester);
        boolean debug = log.isDebugEnabled();
       
        if (debug) {
            log.debug(
                "Matching path [" + path +
                "] on rules object " + this.toString());
        }

        List matches;
        if ((mountPoint != null) &&
            (path.length() <= mountPoint.length())) {
            if (debug) {
                log.debug(
                    "Path [" + path + "] delegated to parent.");
            }
           
            matches = parent.match(namespaceURI, path);
           
            // Note that in the case where path equals mountPoint,
            // we deliberately return only the rules from the parent,
            // even though this object may hold some rules matching
            // this same path. See PluginCreateRule's begin, body and end
            // methods for the reason.
        } else {
                log.debug("delegating to decorated rules.");
            matches = decoratedRules.match(namespaceURI, path);
        }

        return matches;
    }
View Full Code Here

    /**
     * Add the rules previously loaded from the input stream into the
     * specified digester.
     */
    public void addRules(Digester d, String path) throws PluginException {
        Log log = d.getLogger();
        boolean debug = log.isDebugEnabled();
        if (debug) {
            log.debug(
                "LoaderFromStream: loading rules for plugin at path ["
                + path + "]");
        }

        // Note that this input-source doesn't have any idea of its
View Full Code Here

   
    /**
     * Just invoke the target method.
     */
    public void addRules(Digester d, String path) throws PluginException {
        Log log = d.getLogger();
        boolean debug = log.isDebugEnabled();
        if (debug) {
            log.debug(
                "LoaderFromClass loading rules for plugin at path ["
                + path + "]");
        }

        try {
View Full Code Here

import org.apache.commons.logging.LogFactory;

public class HelloWorld {

  public static void main(String[] args) {
    Log log = LogFactory.getLog(HelloWorld.class);
    log.info("Hello world");
  }
View Full Code Here

     * @throws PluginConfigurationException
     */
    public void begin(String namespace, String name,
                      org.xml.sax.Attributes attributes)
                      throws java.lang.Exception {
        Log log = digester.getLogger();
        boolean debug = log.isDebugEnabled();
        if (debug) {
            log.debug("PluginCreateRule.begin" + ": pattern=[" + pattern + "]" +
                  " match=[" + digester.getMatch() + "]");
        }

        if (initException != null) {
            // we had a problem during initialisation that we could
            // not report then; report it now.
            throw initException;
        }
       
        // load any custom rules associated with the plugin
        PluginRules oldRules = (PluginRules) digester.getRules();
        PluginManager pluginManager = oldRules.getPluginManager();
        Declaration currDeclaration = null;
           
        String pluginClassName;
        if (pluginClassAttrNs == null) {
            // Yep, this is ugly.
            //
            // In a namespace-aware parser, the one-param version will
            // return attributes with no namespace.
            //
            // In a non-namespace-aware parser, the two-param version will
            // never return any attributes, ever.
            pluginClassName = attributes.getValue(pluginClassAttr);
        } else {
            pluginClassName =
                attributes.getValue(pluginClassAttrNs, pluginClassAttr);
        }

        String pluginId;
        if (pluginIdAttrNs == null) {
            pluginId = attributes.getValue(pluginIdAttr);
        } else {
            pluginId =
                attributes.getValue(pluginIdAttrNs, pluginIdAttr);
        }
       
        if (pluginClassName != null) {
            // The user is using a plugin "inline", ie without a previous
            // explicit declaration. If they have used the same plugin class
            // before, we have already gone to the effort of creating a
            // Declaration object, so retrieve it. If there is no existing
            // declaration object for this class, then create one.

            currDeclaration = pluginManager.getDeclarationByClass(
                pluginClassName);

            if (currDeclaration == null) {
                currDeclaration = new Declaration(pluginClassName);
                try {
                    currDeclaration.init(digester, pluginManager);
                } catch(PluginException pwe) {
                    throw new PluginInvalidInputException(
                        pwe.getMessage(), pwe.getCause());
                }
                pluginManager.addDeclaration(currDeclaration);
            }
        } else if (pluginId != null) {
            currDeclaration = pluginManager.getDeclarationById(pluginId);
               
            if (currDeclaration == null) {
                throw new PluginInvalidInputException(
                    "Plugin id [" + pluginId + "] is not defined.");
            }
        } else if (defaultPlugin != null) {
            currDeclaration = defaultPlugin;
        } else {
            throw new PluginInvalidInputException(
                "No plugin class specified for element " +
                pattern);
        }
           
        // get the class of the user plugged-in type
        Class pluginClass = currDeclaration.getPluginClass();
       
        String path = digester.getMatch();

        // create a new Rules object and effectively push it onto a stack of
        // rules objects. The stack is actually a linked list; using the
        // PluginRules constructor below causes the new instance to link
        // to the previous head-of-stack, then the Digester.setRules() makes
        // the new instance the new head-of-stack.
        PluginRules newRules = new PluginRules(digester, path, oldRules, pluginClass);
        digester.setRules(newRules);
       
        if (debug) {
            log.debug("PluginCreateRule.begin: installing new plugin: " +
                "oldrules=" + oldRules.toString() +
                ", newrules=" + newRules.toString());
        }
             
        // load up the custom rules
        currDeclaration.configure(digester, pattern);

        // create an instance of the plugin class
        Object instance = pluginClass.newInstance();
        getDigester().push(instance);
        if (debug) {
            log.debug(
                "PluginCreateRule.begin" + ": pattern=[" + pattern + "]" +
                " match=[" + digester.getMatch() + "]" +
                " pushed instance of plugin [" + pluginClass.getName() + "]");
        }
       
View Full Code Here

                      String namespace, String name,
                      org.xml.sax.Attributes list)
                      throws java.lang.Exception {
       
        if ((rules != null) && (rules.size() > 0)) {
            Log log = digester.getLogger();
            boolean debug = log.isDebugEnabled();
            for (int i = 0; i < rules.size(); i++) {
                try {
                    Rule rule = (Rule) rules.get(i);
                    if (debug) {
                        log.debug("  Fire begin() for " + rule);
                    }
                    rule.begin(namespace, name, list);
                } catch (Exception e) {
                    throw digester.createSAXException(e);
                } catch (Error e) {
View Full Code Here

    private void fireBodyMethods(List rules,
                    String namespaceURI, String name,
                    String text) throws Exception {

        if ((rules != null) && (rules.size() > 0)) {
            Log log = digester.getLogger();
            boolean debug = log.isDebugEnabled();
            for (int i = 0; i < rules.size(); i++) {
                try {
                    Rule rule = (Rule) rules.get(i);
                    if (debug) {
                        log.debug("  Fire body() for " + rule);
                    }
                    rule.body(namespaceURI, name, text);
                } catch (Exception e) {
                    throw digester.createSAXException(e);
                } catch (Error e) {
View Full Code Here

                    String namespaceURI, String name)
                    throws Exception {

        // Fire "end" events for all relevant rules in reverse order
        if (rules != null) {
            Log log = digester.getLogger();
            boolean debug = log.isDebugEnabled();
            for (int i = 0; i < rules.size(); i++) {
                int j = (rules.size() - i) - 1;
                try {
                    Rule rule = (Rule) rules.get(j);
                    if (debug) {
                        log.debug("  Fire end() for " + rule);
                    }
                    rule.end(namespaceURI, name);
                } catch (Exception e) {
                    throw digester.createSAXException(e);
                } catch (Error e) {
View Full Code Here

TOP

Related Classes of org.apache.commons.logging.Log

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.