commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/plugins Declaration.java PluginCreateRule.java PluginDeclarationRule.java PluginManager.java PluginRules.java
Date Tue, 28 Oct 2003 23:31:08 GMT
rdonkin     2003/10/28 15:31:08

  Modified:    digester/src/java/org/apache/commons/digester/plugins
                        Declaration.java PluginCreateRule.java
                        PluginDeclarationRule.java PluginManager.java
                        PluginRules.java
  Log:
  Improvements to bring logging in line with the practice in the rest of digester.  Submitted
by Simon Kitching.
  
  Revision  Changes    Path
  1.5       +16 -9     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/Declaration.java
  
  Index: Declaration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/Declaration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Declaration.java	27 Oct 2003 13:37:35 -0000	1.4
  +++ Declaration.java	28 Oct 2003 23:31:08 -0000	1.5
  @@ -69,7 +69,6 @@
   import org.apache.commons.beanutils.MethodUtils;
   import org.apache.commons.digester.Digester;
   import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   
   /**
    * Simple structure to store the set of attributes that can be present on 
  @@ -78,7 +77,6 @@
    * @author Simon Kitching
    */
   public class Declaration {
  -    private static Log log = LogFactory.getLog(Declaration.class);
   
       /** 
        * The name of the method looked for on the plugin class and any
  @@ -225,7 +223,11 @@
        */
       public void init(Digester digester)
       throws PluginWrappedException {
  -        log.debug("init being called!");
  +        Log log = digester.getLogger();
  +        boolean debug = log.isDebugEnabled();
  +        if (debug) {
  +            log.debug("init being called!");
  +        }
           
           if (initialised_) {
               throw new PluginAssertionError("Init called multiple times.");
  @@ -292,7 +294,11 @@
        
       public void configure(Digester digester, String pattern)
       throws PluginWrappedException {
  -        log.debug("configure being called!");
  +        Log log = digester.getLogger();
  +        boolean debug = log.isDebugEnabled();
  +        if (debug) {
  +            log.debug("configure being called!");
  +        }
           
           if (!initialised_) {
               throw new PluginAssertionError("Not initialised.");
  @@ -350,7 +356,7 @@
   
           // look for rule class
           {
  -            if (log.isDebugEnabled()) {
  +            if (debug) {
                   log.debug("plugin class type:" + pluginClass_.getName());
               }
               String ruleClassName = pluginClass_.getName() + "RuleInfo";
  @@ -385,7 +391,7 @@
           
           // try autoSetProperties
           if (autoSetProperties_) {
  -            if (log.isDebugEnabled()) {
  +            if (debug) {
                   log.debug("adding autoset for pattern [" + pattern + "]");
               }
               digester.addSetProperties(pattern);
  @@ -410,6 +416,7 @@
                   is.close();
               }
               catch(IOException ioe) {
  +                Log log = digester.getLogger();
                   log.warn("Unable to close stream after reading rules", ioe);
               }
           }
  
  
  
  1.5       +19 -13    jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginCreateRule.java
  
  Index: PluginCreateRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginCreateRule.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PluginCreateRule.java	27 Oct 2003 13:37:35 -0000	1.4
  +++ PluginCreateRule.java	28 Oct 2003 23:31:08 -0000	1.5
  @@ -70,7 +70,6 @@
   import org.apache.commons.digester.Rule;
   import org.apache.commons.digester.Rules;
   import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   
   /**
    * Allows the original rules for parsing the configuration file to define
  @@ -81,8 +80,6 @@
    */
   public class PluginCreateRule extends Rule implements InitializableRule {
   
  -    private static Log log = LogFactory.getLog(PluginCreateRule.class);
  -
       private static final String PLUGIN_CLASS_ATTR = "plugin-class";
       private static final String PLUGIN_ID_ATTR = "plugin-id";
       
  @@ -195,8 +192,12 @@
        */
       public void postRegisterInit(String pattern)
       throws PluginConfigurationException {
  -        log.debug("PluginCreateRule.postRegisterInit" + 
  -                  ": rule registered for pattern [" + pattern + "]");
  +        Log log = LogUtils.getLogger(digester);
  +        boolean debug = log.isDebugEnabled();
  +        if (debug) {
  +            log.debug("PluginCreateRule.postRegisterInit" + 
  +                      ": rule registered for pattern [" + pattern + "]");
  +        }
   
           if (digester == null) {
               // We require setDigester to be called before this method.
  @@ -300,7 +301,9 @@
       String namespace, String name, 
       org.xml.sax.Attributes attributes)
       throws java.lang.Exception {
  -        if (log.isDebugEnabled()) {
  +        Log log = digester.getLogger();
  +        boolean debug = log.isDebugEnabled();
  +        if (debug) {
               log.debug("PluginCreateRule.begin" + ": pattern=[" + pattern_ + "]" + 
                     " match=[" + digester.getMatch() + "]");
           }
  @@ -325,7 +328,7 @@
               PluginManager pluginManager = localRules_.getPluginManager();
               Declaration currDeclaration = null;
               
  -            if (log.isDebugEnabled()) {
  +            if (debug) {
                   log.debug("PluginCreateRule.begin: installing new plugin: " 
                       + "oldrules=" + oldRules.toString()
                       + ", localrules=" + localRules_.toString());
  @@ -376,7 +379,7 @@
                   
                   Object instance = pluginClass.newInstance();
                   getDigester().push(instance);
  -                if (log.isDebugEnabled()) {
  +                if (debug) {
                       log.debug(
                           "PluginCreateRule.begin" + ": pattern=[" + pattern_ + "]" + 
                           " match=[" + digester.getMatch() + "]" + 
  @@ -391,7 +394,7 @@
           // fire the begin method of all custom rules
           Rules oldRules = digester.getRules();
           
  -        if (log.isDebugEnabled()) {
  +        if (debug) {
               log.debug("PluginCreateRule.begin: firing nested rules: " 
                   + "oldrules=" + oldRules.toString()
                   + ", localrules=" + localRules_.toString());
  @@ -402,7 +405,7 @@
           delegateBegin(namespace, name, attributes);
           digester.setRules(oldRules);
   
  -        if (log.isDebugEnabled()) {
  +        if (debug) {
               log.debug("PluginCreateRule.begin: restored old rules to " 
                   + "oldrules=" + oldRules.toString());
           }
  @@ -491,6 +494,7 @@
       throws java.lang.Exception {
           
           // Fire "begin" events for all relevant rules
  +        Log log = digester.getLogger();
           boolean debug = log.isDebugEnabled();
           String match = digester.getMatch();
           List rules = digester.getRules().match(namespace, match);
  @@ -510,6 +514,7 @@
       public void delegateBody(String namespace, String name, String text)
       throws Exception {
           // Fire "body" events for all relevant rules
  +        Log log = digester.getLogger();
           boolean debug = log.isDebugEnabled();
           String match = digester.getMatch();
           List rules = digester.getRules().match(namespace, match);
  @@ -529,6 +534,7 @@
       public void delegateEnd(String namespace, String name)
       throws Exception {
           // Fire "end" events for all relevant rules in reverse order
  +        Log log = digester.getLogger();
           boolean debug = log.isDebugEnabled();
           String match = digester.getMatch();
           List rules = digester.getRules().match(namespace, match);
  
  
  
  1.5       +11 -7     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginDeclarationRule.java
  
  Index: PluginDeclarationRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginDeclarationRule.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PluginDeclarationRule.java	27 Oct 2003 13:37:35 -0000	1.4
  +++ PluginDeclarationRule.java	28 Oct 2003 23:31:08 -0000	1.5
  @@ -68,7 +68,6 @@
   import org.apache.commons.beanutils.MethodUtils;
   
   import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   
   /**
    * A Digester rule which allows the user to pre-declare a class which is to
  @@ -82,7 +81,6 @@
    */
   
   public class PluginDeclarationRule extends Rule {
  -    private static Log log = LogFactory.getLog(PluginDeclarationRule.class);
   
       //------------------- constructors ---------------------------------------
   
  @@ -114,6 +112,10 @@
               String name,
               org.xml.sax.Attributes attributes)
                throws java.lang.Exception {
  +                 
  +        Log log = digester.getLogger();
  +        boolean debug = log.isDebugEnabled();
  +        
           String id = attributes.getValue("id");
           String pluginClassName = attributes.getValue("class");
           String ruleMethodName = attributes.getValue("method");
  @@ -122,7 +124,7 @@
           String ruleFile = attributes.getValue("file");
           String autoSetPropertiesStr = attributes.getValue("setprops");
   
  -        if (log.isDebugEnabled()) {
  +        if (debug) {
               log.debug(
                   "mapping id [" + id + "] -> [" + pluginClassName + "]");
           }
  @@ -184,7 +186,9 @@
                   // the same external file at multiple locations within a
                   // parent document. if the declaration is identical,
                   // then we just ignore it.
  -                log.debug("plugin redeclaration is identical: ignoring");
  +                if (debug) {
  +                    log.debug("plugin redeclaration is identical: ignoring");
  +                }
                   return;
               } else {
                   throw new PluginInvalidInputException(
  
  
  
  1.4       +12 -7     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginManager.java
  
  Index: PluginManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PluginManager.java	9 Oct 2003 21:09:48 -0000	1.3
  +++ PluginManager.java	28 Oct 2003 23:31:08 -0000	1.4
  @@ -66,7 +66,6 @@
   import org.apache.commons.digester.Digester;
   
   import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   
   /**
    * Coordinates between PluginDeclarationRule and PluginCreateRule objects,
  @@ -79,7 +78,6 @@
    */
   
   public class PluginManager {
  -    private static Log log = LogFactory.getLog(PluginManager.class);
   
       /** Map of classname->Declaration */
       private HashMap declarationsByClass_ = new HashMap();
  @@ -89,7 +87,7 @@
   
       /** the parent manager to which this one may delegate lookups. */
       private PluginManager parent_;
  -    
  +
       //------------------- constructors ---------------------------------------
       
       /** Constructor. */
  @@ -105,10 +103,17 @@
   
       /**
        * Add the declaration to the set of known declarations.
  +     * <p>
  +     * TODO: somehow get a reference to a Digester object
  +     * so that we can really log here. Currently, all
  +     * logging is disabled from this method.
        *
        *@param decl an object representing a plugin class.
        */
       public void addDeclaration(Declaration decl) {
  +        Log log = LogUtils.getLogger(null);
  +        boolean debug = log.isDebugEnabled();
  +        
           Class pluginClass = decl.getPluginClass();
           String id = decl.getId();
           
  @@ -116,7 +121,7 @@
               
           if (id != null) {
               declarationsById_.put(id, decl);
  -            if (log.isDebugEnabled()) {
  +            if (debug) {
                   log.debug(
                       "Indexing plugin-id [" + id + "]"
                       + " -> class [" + pluginClass.getName() + "]");
  
  
  
  1.4       +28 -12    jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java
  
  Index: PluginRules.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PluginRules.java	9 Oct 2003 21:09:48 -0000	1.3
  +++ PluginRules.java	28 Oct 2003 23:31:08 -0000	1.4
  @@ -75,7 +75,6 @@
   import org.apache.commons.digester.Rules;
   import org.apache.commons.digester.RulesBase;
   import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   
   /**
    * A custom digester Rules manager which must be used as the Rules object
  @@ -85,7 +84,6 @@
    */
   
   public class PluginRules implements Rules {
  -    private static Log log = LogFactory.getLog(PluginRules.class);
                                                  
       /** 
        * The rules implementation that we are "enhancing" with plugins
  @@ -230,10 +228,14 @@
        * @param rule Rule instance to be registered
        */
       public void add(String pattern, Rule rule) {
  -        if (log.isDebugEnabled()) {
  +        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() + "]");
           }
  +        
           decoratedRules_.add(pattern, rule);
   
           if (rule instanceof InitializableRule) {
  @@ -245,13 +247,15 @@
                   // initialisable rule to remember that its initialisation
                   // failed, and to throw the exception when begin is
                   // called for the first time.
  -                log.debug("Rule initialisation failed", e);
  +                if (debug) {
  +                    log.debug("Rule initialisation failed", e);
  +                }
                   // throw e; -- alas, can't do this
                   return;
               }
           }
           
  -        if (log.isDebugEnabled()) {
  +        if (debug) {
               log.debug("add exit" + ": mapped pattern [" + pattern + "]" + 
                     " to rule of type [" + rule.getClass().getName() + "]");
           }
  @@ -298,16 +302,20 @@
        * @param pattern Nesting pattern to be matched
        */
       public List match(String namespaceURI, String pattern) {
  -        if (log.isDebugEnabled()) {
  +        Log log = LogUtils.getLogger(digester_);
  +        boolean debug = log.isDebugEnabled();
  +        
  +        if (debug) {
               log.debug(
                   "Matching pattern [" + pattern 
                   + "] on rules object " + this.toString());
           }
  +
           List matches;
           if ((currPluginCreateRule_ != null) && 
               (pattern.length() > currPluginCreateRule_.getPattern().length())) {
               // assert pattern.startsWith(currPluginCreateRule.getPattern())
  -            if (log.isDebugEnabled()) {
  +            if (debug) {
                   log.debug(
                       "Pattern [" + pattern + "] matching PluginCreateRule " 
                       + currPluginCreateRule_.toString());
  @@ -332,15 +340,20 @@
        * endPlugin method is called.
        */
       public void beginPlugin(PluginCreateRule pcr) {
  +        Log log = LogUtils.getLogger(digester_);
  +        boolean debug = log.isDebugEnabled();
  +
           if (currPluginCreateRule_ != null) {
               throw new PluginAssertionError(
                   "endPlugin called when currPluginCreateRule_ is not null.");
           }
  -        if (log.isDebugEnabled()) {
  +
  +        if (debug) {
               log.debug(
                   "Entering PluginCreateRule " + pcr.toString() 
                   + " on rules object " + this.toString());
           }
  +
           currPluginCreateRule_ = pcr;
       }
       
  @@ -349,6 +362,9 @@
        * See {@link #beginPlugin}.
        */
       public void endPlugin(PluginCreateRule pcr) {
  +        Log log = LogUtils.getLogger(digester_);
  +        boolean debug = log.isDebugEnabled();
  +
           if (currPluginCreateRule_ == null) {
               throw new PluginAssertionError(
                   "endPlugin called when currPluginCreateRule_ is null.");
  @@ -360,7 +376,7 @@
           }
           
           currPluginCreateRule_ = null;
  -        if (log.isDebugEnabled()) {
  +        if (debug) {
               log.debug(
                   "Leaving PluginCreateRule " + pcr.toString()
                   + " on rules object " + this.toString());
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message