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/09 16:26:38 UTC

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

jvanzyl     01/08/09 07:26:38

  Modified:    src/java/org/apache/turbine/modules ModuleLoader.java
  Removed:     src/java/org/apache/turbine/modules/layouts
                        TemplateLayout.java
               src/java/org/apache/turbine/modules/navigations
                        TemplateNavigation.java
  Log:
  - moved moduler loader logic from Turbine.java into the module loader.
  - added a mapping mechanism whereby a base module can be used for more
    than one type.
  
    in the case of the classic pipeline the layouts and navigations can
    map to the standard org.apache.turbine.modules.Module. this is fully
    configurable and the Push model will work, but this will allow us to
    move to a fully Pull system where all module work is performed
    by org.apache.turbine.modules.Module or a single subclass thereof.
  
    in doing this it is apparent that actions are distinctly different
    that modules for producing content. i think it might be wise to
    change our nomenclature to speak of modules as producing content
    while actions are a different beast all together. just as scheduled
    jobs were not modules.
  
  Revision  Changes    Path
  1.4       +139 -4    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ModuleLoader.java	2001/07/17 18:15:58	1.3
  +++ ModuleLoader.java	2001/08/09 14:26:37	1.4
  @@ -58,18 +58,21 @@
   import java.util.List;
   import java.util.Vector;
   import java.util.Map;
  +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.RunData;
   import org.apache.commons.collections.FastArrayList;
   import org.apache.commons.collections.FastHashMap;
   import org.apache.turbine.util.Log;
   
  +import org.apache.velocity.runtime.configuration.Configuration;
  +
   /**
    * 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.3 2001/07/17 18:15:58 jvanzyl Exp $
  + * @version $Id: ModuleLoader.java,v 1.4 2001/08/09 14:26:37 jvanzyl Exp $
    */
   public class ModuleLoader
   {
  @@ -95,11 +98,26 @@
       protected StringBuffer modulePackagesNames;
   
       /**
  +     * The default module to load when nothing else
  +     * can be found.
  +     */
  +    protected String defaultModule;
  +
  +    /**
  +     * The defaults modules for the various defined types.
  +     */
  +    protected Map defaultModules;
  +
  +    /**
        * Property that controls whether scripting is enabled
        * for this module loader.
        */
       protected boolean scriptingEnabled;
   
  +    protected Configuration configuration;
  +
  +    protected Map moduleMappings;
  +
       /**
        * Default constructor.
        */
  @@ -108,6 +126,8 @@
           moduleCache = new FastHashMap();
           modulePackages = new FastArrayList();
           modulePackagesNames = new StringBuffer();
  +        defaultModules = new FastHashMap();
  +        moduleMappings = new FastHashMap();
       }
   
       /**
  @@ -132,10 +152,79 @@
       }
   
       /**
  +     * Set the configuration for the module loader
  +     */
  +    public void setConfiguration(Configuration configuration)
  +    {
  +        this.configuration = configuration;
  +    }
  +
  +    /**
        * Initialize this module loader.
        */
       public void init()
  +        throws TurbineException
       {
  +        Configuration moduleTypes = configuration.subset("module.default");
  +        
  +        if (moduleTypes == null)
  +        {
  +            throw new TurbineException(
  +                "module.default subset is missing from TR.props");
  +        }
  +
  +        Iterator j = moduleTypes.getKeys();
  +
  +        while (j.hasNext())
  +        {
  +            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
  +            // module type to our container for module defaults.
  +            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);
  +
  +        Iterator i = modulePackages.iterator();
  +
  +        while (i.hasNext())
  +        {
  +            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);
  +        }            
       }
   
       /**
  @@ -148,6 +237,19 @@
       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);
  @@ -162,7 +264,17 @@
                   
               while (i.hasNext())
               {
  -                String moduleClass = (String) i.next() + "." + type + "." + name;
  +                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;
  +                }                    
                   
                   try
                   {
  @@ -175,7 +287,7 @@
                           Log.debug("[ModuleLoader] Adding to cache => " + moduleClass);
                           ((Map) moduleCache.get(type)).put(name, module);
                       }
  -                    
  +
                       break;
                   }
                   catch (Exception e)
  @@ -198,6 +310,29 @@
           }                    
           
           return module;
  +    }
  +
  +    /**
  +     * Set the default module to load when no other module
  +     * can be found.
  +     */
  +    public void setDefaultModule(String defaultModule)
  +    {
  +        this.defaultModule = defaultModule;
  +    }        
  +
  +    /** 
  +     * Set the default module for a type.
  +     */
  +    public void setDefaultModule(String type, String defaultModule)
  +    {
  +        defaultModules.put(type, defaultModule);
  +    }
  +
  +    // New module stuff
  +    public String getDefaultModule(String moduleType)
  +    {
  +        return (String) defaultModules.get(moduleType);
       }
   
       /**
  
  
  

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