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/strategies FinderFromDfltResource.java FinderFromFile.java FinderFromResource.java
Date Sat, 03 Apr 2004 06:52:44 GMT
skitching    2004/04/02 22:52:44

  Modified:    digester/src/java/org/apache/commons/digester/plugins/strategies
                        Tag: DIGESTER_PLUGIN_REFACTORING_BRANCH
                        FinderFromDfltResource.java FinderFromFile.java
                        FinderFromResource.java
  Log:
  Implement support for having plugin rules expressed in xmlrules syntax.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.2   +4 -11     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/Attic/FinderFromDfltResource.java
  
  Index: FinderFromDfltResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/Attic/FinderFromDfltResource.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- FinderFromDfltResource.java	28 Mar 2004 05:37:31 -0000	1.1.2.1
  +++ FinderFromDfltResource.java	3 Apr 2004 06:52:44 -0000	1.1.2.2
  @@ -23,6 +23,7 @@
   import org.apache.commons.digester.plugins.RuleFinder;
   import org.apache.commons.digester.plugins.RuleLoader;
   import org.apache.commons.digester.plugins.PluginException;
  +import org.apache.commons.logging.Log;
   
   /**
    * A rule-finding algorithm which looks for a resource file in the classpath
  @@ -68,7 +69,7 @@
                           throws PluginException {
   
           String resourceName = 
  -            pluginClass.getClass().getName().replace('.', '/') 
  +            pluginClass.getName().replace('.', '/') 
                       + resourceSuffix;
               
           InputStream is = 
  @@ -79,16 +80,8 @@
               // ok, no such resource
               return null;
           }
  -            
  -        // the rest is not yet implemented
  -        throw new PluginException(
  -            "FinderFromDfltResource not implemented.");
  -
  -        /*
  -        RuleLoader loader = new LoaderFromStream(is);
  -        close(is);
  -        return loader;
  -        */
  +
  +        return FinderFromResource.loadRules(d, pluginClass, is, resourceName);
       }
   }
   
  
  
  
  1.1.2.2   +16 -9     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/Attic/FinderFromFile.java
  
  Index: FinderFromFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/Attic/FinderFromFile.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- FinderFromFile.java	28 Mar 2004 05:37:31 -0000	1.1.2.1
  +++ FinderFromFile.java	3 Apr 2004 06:52:44 -0000	1.1.2.2
  @@ -81,15 +81,22 @@
                   "Unable to process file [" + rulesFileName + "]", ioe);
           }
           
  -        // the rest is not yet implemented
  -        throw new PluginException(
  -            "FinderFromFile not implemented.");
  -
  -        /*
  -        RuleLoader loader = new LoaderFromStream(is);
  -        is.close();
  -        return loader;
  -        */
  +        try {
  +            RuleLoader loader = new LoaderFromStream(is);
  +            return loader;
  +        } catch(Exception e) {
  +            throw new PluginException(
  +                "Unable to load xmlrules from file [" + 
  +                rulesFileName + "]", e);
  +        } finally {
  +            try {
  +                is.close();
  +            } catch(java.io.IOException ioe) {
  +                throw new PluginException(
  +                    "Unable to close stream for file [" + 
  +                    rulesFileName + "]", ioe);
  +            }
  +        }
       }
   }
   
  
  
  
  1.1.2.2   +39 -13    jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/Attic/FinderFromResource.java
  
  Index: FinderFromResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/Attic/FinderFromResource.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- FinderFromResource.java	28 Mar 2004 05:37:31 -0000	1.1.2.1
  +++ FinderFromResource.java	3 Apr 2004 06:52:44 -0000	1.1.2.2
  @@ -63,8 +63,8 @@
       public RuleLoader findLoader(Digester d, Class pluginClass, Properties p)
                           throws PluginException {
   
  -        String ruleResource = p.getProperty(resourceAttr);
  -        if (ruleResource == null) {
  +        String resourceName = p.getProperty(resourceAttr);
  +        if (resourceName == null) {
               // nope, user hasn't requested dynamic rules to be loaded
               // from a specific file.
               return null;
  @@ -72,21 +72,47 @@
           
           InputStream is = 
               pluginClass.getClassLoader().getResourceAsStream(
  -                ruleResource);
  +                resourceName);
  +
           if (is == null) {
               throw new PluginException(
  -                "Resource " + ruleResource + " not found.");
  +                "Resource " + resourceName + " not found.");
           }
           
  -        // the rest is not yet implemented
  -        throw new PluginException(
  -            "FinderFromResource not implemented.");
  -            
  -        /*
  -        RuleLoader loader = new LoaderFromStream(is);
  -        is.close();
  -        return loader;
  -        */
  +         return loadRules(d, pluginClass, is, resourceName);
  +    }
  +    
  +    /**
  +     * Open the specified resource file (ie a file in the classpath, 
  +     * including being within a jar in the classpath), run it through
  +     * the xmlrules module and return an object encapsulating those rules.
  +     * 
  +     * @param d is the digester into which rules will eventually be loaded.
  +     * @param pluginClass is the class whose xml params the rules are parsing.
  +     * @param is is where the xmlrules will be read from, and must be non-null.
  +     * @param resourceName is a string describing the source of the xmlrules,
  +     *  for use in generating error messages.
  +     */
  +    public static RuleLoader loadRules(Digester d, Class pluginClass, 
  +                        InputStream is, String resourceName)
  +                        throws PluginException {
  +
  +        try {
  +            RuleLoader loader = new LoaderFromStream(is);
  +            return loader;
  +        } catch(Exception e) {
  +            throw new PluginException(
  +                "Unable to load xmlrules from resource [" + 
  +                resourceName + "]", e);
  +        } finally {
  +            try {
  +                is.close();
  +            } catch(java.io.IOException ioe) {
  +                throw new PluginException(
  +                    "Unable to close stream for resource [" + 
  +                    resourceName + "]", ioe);
  +            }
  +        }
       }
   }
   
  
  
  

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