You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jv...@apache.org on 2001/08/14 15:36:33 UTC

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

jvanzyl     01/08/14 06:36:33

  Modified:    src/java/org/apache/turbine/modules ModuleLoader.java
  Log:
  - moving module loader specific logic out of the resolver and
    into the module loader. i imagine it is still confusing for someone
    looking at it but it will be cleaned up today
  
  Revision  Changes    Path
  1.6       +72 -69    jakarta-turbine/src/java/org/apache/turbine/modules/ModuleLoader.java
  
  Index: ModuleLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/modules/ModuleLoader.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ModuleLoader.java	2001/08/10 12:12:28	1.5
  +++ ModuleLoader.java	2001/08/14 13:36:33	1.6
  @@ -61,7 +61,7 @@
   import org.apache.turbine.RunData;
   import org.apache.turbine.Turbine;
   import org.apache.turbine.TurbineException;
  -import org.apache.turbine.modules.ScriptableModule;
  +import org.apache.turbine.pipeline.Resolver;
   import org.apache.commons.collections.FastArrayList;
   import org.apache.commons.collections.FastHashMap;
   import org.apache.turbine.util.Log;
  @@ -72,7 +72,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.5 2001/08/10 12:12:28 knielsen Exp $
  + * @version $Id: ModuleLoader.java,v 1.6 2001/08/14 13:36:33 jvanzyl Exp $
    */
   public class ModuleLoader
   {
  @@ -116,8 +116,6 @@
   
       protected Configuration configuration;
   
  -    protected Map moduleMappings;
  -
       /**
        * Default constructor.
        */
  @@ -127,7 +125,6 @@
           modulePackages = new FastArrayList();
           modulePackagesNames = new StringBuffer();
           defaultModules = new FastHashMap();
  -        moduleMappings = new FastHashMap();
       }
   
       /**
  @@ -179,16 +176,6 @@
           {
               String moduleType = (String) j.next();
               String defaultModule = moduleTypes.getString(moduleType);
  -
  -            // Look for a 'base' module.
  -            if (moduleType.equals("base"))
  -            {
  -                setDefaultModule(defaultModule);
  -            }
  -
  -            Log.debug("Adding module type " + moduleType +
  -                " with a default of " + defaultModule);
  -
               addModuleType(moduleType);
   
               // Add the default module for the particular
  @@ -196,10 +183,6 @@
               setDefaultModule(moduleType, defaultModule);
           }
   
  -        // Add the default set of modules which live within
  -        // the org.apache.turbine.module namespace.
  -        addModulePackage(Turbine.DEFAULT_MODULE_PACKAGE);
  -
           // Grab our list of module packages so that we can
           // add them to the search list of the ModuleLoader.
           Vector modulePackages = configuration.getVector(Turbine.MODULE_PACKAGES);
  @@ -210,21 +193,11 @@
           {
               addModulePackage((String) i.next());
           }
  -
  -        // Module Map
  -        Configuration map = configuration.subset("module.mapping");
  -
  -        Iterator k = map.getKeys();
  -
  -        while (k.hasNext())
  -        {
  -            String type = (String) k.next();
  -            String mapTo = map.getString(type);
  -
  -            Log.debug("[ModuleLoader] Adding module mapping: " + type + " => " + mapTo);
  -
  -            moduleMappings.put(type, mapTo);
  -        }
  +        
  +        // Add the package for Turbine's default modules.
  +        // This package must be added last so it is searched
  +        // for last.
  +        addModulePackage(Turbine.DEFAULT_MODULE_PACKAGE);
       }
   
       /**
  @@ -237,65 +210,57 @@
       public Module getModule(String type, String name)
           throws Exception
       {
  -        // Check module mappings and change the type if
  -        // necessary. This mapping will slow things down for.
  -        // A more elegant solution is needed.
  -        String typeMapping = (String) moduleMappings.get(type);
  -
  -        if (typeMapping != null)
  -        {
  -            type = typeMapping;
  -        }
  -
  -        Log.debug("[ModuleLoader] type => " + type);
  -        Log.debug("[ModuleLoader] typeMapping => " + typeMapping);
  -
           // Try and retrieve the module of the specified type
  -        // with the specified name.
           Module module = (Module) ((Map) moduleCache.get(type)).get(name);
  -
  +        
           if (module != null)
           {
               return module;
           }
           else
           {
  -            Iterator i = modulePackages.iterator();
  -
  -            while (i.hasNext())
  +            Iterator i,j,k = null;
  +            i = modulePackages.iterator();
  +            
  +            
  +            
  +            if (type.equals("actions"))
               {
  -                String moduleClass;
  -                // The type of 'base' is a special case
  -
  -                if (type.equals("base"))
  -                {
  -                    moduleClass = (String) i.next() + "." + defaultModule;
  -                }
  -                else
  -                {
  -                    moduleClass = (String) i.next() + "." +  type + "." + name;
  -                }
  -
  +                k = getAllPossibleActions(i,name);            
  +            }
  +            else
  +            {
  +                StringBuffer sb = new StringBuffer();
  +                Resolver.parseTemplatePath(name, sb);
  +                j = Resolver.getPossibleModules(sb.toString());
  +                k = getAllPossibleModules(i,j,type);
  +            }
  +            
  +            while (k.hasNext())
  +            {
  +                String moduleClass = (String) k.next();
  +              
                   try
                   {
                       Log.debug("[ModuleLoader] Looking for " + moduleClass);
                       module = (Module) Class.forName(moduleClass).newInstance();
  -
  -                    // Store the found module is caching is enabled.
  +                
  +                    // Store the found module if caching is enabled.
                       if (cacheEnabled)
                       {
                           Log.debug("[ModuleLoader] Adding to cache => " + moduleClass);
                           ((Map) moduleCache.get(type)).put(name, module);
                       }
   
  +                    Log.debug("[ModuleLoader] " + name + " => " + moduleClass);
                       break;
  -                }
  +                }                        
                   catch (Exception e)
                   {
                       // do nothing.
                   }
               }
  -        }
  +        }            
   
           if (scriptingEnabled && module == null)
           {
  @@ -306,10 +271,48 @@
           if (module == null)
           {
               throw new Exception(
  -                "Can't find module: " + name + " in " + modulePackagesNames);
  +                "Can't find module for " + name + " in " + modulePackagesNames);
           }
   
           return module;
  +    }
  +
  +    private Iterator getAllPossibleModules(Iterator i, Iterator j, String type)
  +    {
  +        FastArrayList modules = new FastArrayList();
  +        FastArrayList defaultModules = new FastArrayList();
  +        
  +        while (i.hasNext())
  +        {
  +            String modulePackage = (String) i.next();
  +            
  +            while (j.hasNext())
  +            {
  +                String module = modulePackage + "." + type + "." + (String) j.next();
  +                modules.add(module);
  +                
  +            }
  +            
  +            // Add default for type
  +            defaultModules.add(modulePackage + "." + getDefaultModule(type));
  +        }            
  +
  +        modules.addAll(defaultModules);
  +
  +        return modules.iterator();
  +    }
  +
  +    private Iterator getAllPossibleActions(Iterator i, String name)
  +    {
  +        FastArrayList actions = new FastArrayList();
  +        
  +        while (i.hasNext())
  +        {
  +            String action = (String) i.next() + ".actions." + name;
  +            actions.add(action);
  +        }            
  +        
  +        return actions.iterator();
       }
   
       /**
  
  
  

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