You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by dl...@apache.org on 2001/12/30 09:38:52 UTC

cvs commit: jakarta-turbine-3/src/java/org/apache/turbine/modules ModuleLoader.java

dlr         01/12/30 00:38:52

  Modified:    src/java/org/apache/turbine/modules ModuleLoader.java
  Log:
  o Iterators are only guaranteed useable for a single shot.  Corrected
  problem usage in getModule().  Pointed out by Sven Homburg
  <sv...@hsofttec.com>.
  
  o General clean/JavaDoc, including one backwards incompatible API
  change, where the return value for getPossibleModules(String) was
  changed from Iterator to List to reflect the fact that the return
  value must be iterated over multiple times (re-constructing a List
  from the Iterator is not a good use of resources, especially for a
  method which is called many times).
  
  Revision  Changes    Path
  1.7       +44 -26    jakarta-turbine-3/src/java/org/apache/turbine/modules/ModuleLoader.java
  
  Index: ModuleLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/modules/ModuleLoader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -u -r1.6 -r1.7
  --- ModuleLoader.java	15 Nov 2001 17:27:45 -0000	1.6
  +++ ModuleLoader.java	30 Dec 2001 08:38:52 -0000	1.7
  @@ -74,7 +74,7 @@
    * Load modules for use in the view pipeline.
    *
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: ModuleLoader.java,v 1.6 2001/11/15 17:27:45 mikeh Exp $
  + * @version $Id: ModuleLoader.java,v 1.7 2001/12/30 08:38:52 dlr Exp $
    */
   public class ModuleLoader
   {
  @@ -184,33 +184,31 @@
       /**
        * Get an instance of a module
        *
  -     * NOTE  
        * All clients should use Turbine.getResolver().getModule(type,name)
        * to get the module.  The only client of ModuleLoader.getModule(type,name)
        * should be the resolver.
        *
  -     * @param String name
  -     * @param String type
  -     * @return Module
  +     * @param name
  +     * @param type
  +     * @return The desired <code>Module</code>, or <code>null</code>
  +     * if not found..
        */
       public Module getModule(String type, String name)
           throws Exception
       {
           Module module = null; 
           
  -        Iterator i,j,k = null;
  -        i = modulePackages.iterator();
  -        
  +        Iterator k;
           if (type.equals("actions"))
           {
  -            k = getAllPossibleActions(i,name);            
  +            k = getAllPossibleActions(name);
           }
           else
           {
               StringBuffer sb = new StringBuffer();
               PipelineUtil.parseTemplatePath(name, sb);
  -            j = getPossibleModules(sb.toString());
  -            k = getAllPossibleModules(i,j,type);
  +            List names = getPossibleModules(sb.toString());
  +            k = getAllPossibleModules(names, type);
           }
           
           while (k.hasNext())
  @@ -224,9 +222,9 @@
                   Log.debug("[ModuleLoader] " + name + " => " + moduleClass);
                   break;
               }                        
  -            catch (Exception e)
  +            catch (Exception ignored)
               {
  -                // do nothing.
  +                // Likely a non-existant class name combination.
               }
           }
   
  @@ -239,18 +237,26 @@
           return module;
       }
   
  -    private Iterator getAllPossibleModules(Iterator i, Iterator j, String type)
  +    /**
  +     * Returns the cross product of module packages, names, and type.
  +     *
  +     * @param names Possible modules for a specific template.
  +     * @param type The type modules to generate possibile fully
  +     * qualified class names for.
  +     */
  +    private Iterator getAllPossibleModules(List names, String type)
       {
           FastArrayList modules = new FastArrayList();
           FastArrayList defaultModules = new FastArrayList();
  -        
  +
  +        Iterator i = modulePackages.iterator();
           while (i.hasNext())
           {
               String modulePackage = (String) i.next();
  -            
  -            while (j.hasNext())
  +            Iterator m = (Iterator) names.iterator();
  +            while (m.hasNext())
               {
  -                String module = modulePackage + "." + type + "." + (String) j.next();
  +                String module = modulePackage + "." + type + "." + m.next();
                   modules.add(module);
                   
               }
  @@ -264,10 +270,15 @@
           return modules.iterator();
       }
   
  -    private Iterator getAllPossibleActions(Iterator i, String name)
  +    /**
  +     * @param name The name of the <code>Action</code> to retrieve
  +     * class names for.
  +     */
  +    private Iterator getAllPossibleActions(String name)
       {
           FastArrayList actions = new FastArrayList();
  -        
  +
  +        Iterator i = modulePackages.iterator();
           while (i.hasNext())
           {
               String action = (String) i.next() + ".actions." + name;
  @@ -294,7 +305,9 @@
           defaultModules.put(type, defaultModule);
       }
   
  -    // New module stuff
  +    /**
  +     * "New module stuff"
  +     */
       public String getDefaultModule(String moduleType)
       {
           return (String) defaultModules.get(moduleType);
  @@ -310,10 +323,16 @@
           scriptingEnabled = state;
       }
   
  -     protected Iterator getPossibleModules(String template)
  +    /**
  +     *
  +     *
  +     * @param template
  +     * @return
  +     */
  +     protected List getPossibleModules(String template)
           throws Exception
       {
  -        List packages = new ArrayList();
  +        List packages = new FastArrayList();
   
           // Parse the template name and change it into a package.
           StringBuffer pckage = new StringBuffer();
  @@ -331,7 +350,7 @@
               {
                   if (pckage.charAt(j) == '/')
                   {
  -                    pckage.setCharAt(j,'.');
  +                    pckage.setCharAt(j, '.');
                   }
               }
           }
  @@ -378,7 +397,6 @@
           }
   
           // Not found, return the default module name.
  -        return packages.iterator();
  +        return packages;
       }
  -
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>