commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/plugins PluginDeclarationRule.java
Date Wed, 14 Apr 2004 08:30:54 GMT
skitching    2004/04/14 01:30:54

  Modified:    digester/src/java/org/apache/commons/digester/plugins
                        PluginDeclarationRule.java
  Log:
  * Move guts of implementation to a public static method where it can be
    called from other code to "manually" add plugin declarations.
  * Remove restriction on redeclaring plugins and mapping two ids to the
    same plugin. These were both due to limitations on earlier plugins
    implementations that no longer apply with the latest code.
  
  Revision  Changes    Path
  1.13      +32 -44    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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PluginDeclarationRule.java	8 Apr 2004 06:11:37 -0000	1.12
  +++ PluginDeclarationRule.java	14 Apr 2004 08:30:54 -0000	1.13
  @@ -66,71 +66,59 @@
                         org.xml.sax.Attributes attributes)
                         throws java.lang.Exception {
                    
  +        int nAttrs = attributes.getLength();
  +        Properties props = new Properties();
  +        for(int i=0; i<nAttrs; ++i) {
  +            String key = attributes.getLocalName(i);
  +            if ((key == null) || (key.length() == 0)) {
  +                key = attributes.getQName(i);
  +            }
  +            String value = attributes.getValue(i);
  +            props.setProperty(key, value);
  +        }
  +        
  +        try {
  +            declarePlugin(digester, props);
  +        } catch(PluginInvalidInputException ex) {
  +            throw new PluginInvalidInputException(
  +                "Error on element [" + digester.getMatch() + 
  +                "]: " + ex.getMessage());
  +        }
  +    }
  +    
  +    public static void declarePlugin(Digester digester, Properties props)
  +    throws PluginException {
  +        
           Log log = digester.getLogger();
           boolean debug = log.isDebugEnabled();
           
  -        String id = attributes.getValue("id");
  -        String pluginClassName = attributes.getValue("class");
  +        String id = props.getProperty("id");
  +        String pluginClassName = props.getProperty("class");
           
           if (id == null) {
               throw new PluginInvalidInputException(
  -                    "mandatory attribute id not present on tag" +
  -                       " <" + name + ">");
  +                "mandatory attribute id not present on plugin declaration");
           }
   
           if (pluginClassName == null) {
               throw new PluginInvalidInputException(
  -                    "mandatory attribute class not present on tag" +
  -                       " <" + name + ">");
  +                "mandatory attribute class not present on plugin declaration");
           }
   
  -        int nAttrs = attributes.getLength();
  -        Properties props = new Properties();
  -        for(int i=0; i<nAttrs; ++i) {
  -            String key = attributes.getLocalName(i);
  -            if ((key == null) || (key.length() == 0)) {
  -                key = attributes.getQName(i);
  -            }
  -            String value = attributes.getValue(i);
  -            props.setProperty(key, value);
  -        }
  -        
           Declaration newDecl = new Declaration(pluginClassName);
           newDecl.setId(id);
           newDecl.setProperties(props);
   
           PluginRules rc = (PluginRules) digester.getRules();
           PluginManager pm = rc.getPluginManager();
  -        Declaration oldDecl = pm.getDeclarationById(id);
  -        if (oldDecl != null) {
  -            if (oldDecl.isEquivalent(newDecl)) {
  -                // this is a redeclaration of the same plugin mapping.
  -                // this could happen when using xml Entities to include
  -                // external files into the main config file, or to include
  -                // the same external file at multiple locations within a
  -                // parent document. if the declaration is identical,
  -                // then we just ignore it.
  -                if (debug) {
  -                    log.debug("plugin redeclaration is identical: ignoring");
  -                }
  -                return;
  -            } else {
  -                throw new PluginInvalidInputException(
  -                    "Plugin id [" + id + "] is not unique");
  -            }
  -        }
  -
  -        // check whether this class has already been mapped to a different
  -        // name. It might be nice someday to allow this but lets keep it
  -        // simple for now.
  -        if (pm.getDeclarationByClass(pluginClassName) != null) {
  -            throw new PluginInvalidInputException(
  -                    "Plugin id [" + id + "] maps to class [" + pluginClassName + "]" +
  -                     " which has already been mapped by some other id.");
  -        }
   
           newDecl.init(digester, pm);
           pm.addDeclaration(newDecl);
  +        
  +        // Note that it is perfectly safe to redeclare a plugin, because
  +        // the declaration doesn't add any rules to digester; all it does
  +        // is create a RuleLoader instance whch is *capable* of adding the
  +        // rules to the digester.
       }
   }
   
  
  
  

---------------------------------------------------------------------
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