Author: tv
Date: Sun Jan  4 07:23:55 2009
New Revision: 731268

URL: http://svn.apache.org/viewvc?rev=731268&view=rev
Log:
Moved the different loader caches into the AssemblerBrokerService and 
centralized several loader features. The loaders do no longer extend
Hashtable.

Modified:
    turbine/core/trunk/src/java/org/apache/turbine/TurbineConstants.java
    turbine/core/trunk/src/java/org/apache/turbine/modules/ActionLoader.java
    turbine/core/trunk/src/java/org/apache/turbine/modules/GenericLoader.java
    turbine/core/trunk/src/java/org/apache/turbine/modules/LayoutLoader.java
    turbine/core/trunk/src/java/org/apache/turbine/modules/Loader.java
    turbine/core/trunk/src/java/org/apache/turbine/modules/NavigationLoader.java
    turbine/core/trunk/src/java/org/apache/turbine/modules/PageLoader.java
    
turbine/core/trunk/src/java/org/apache/turbine/modules/ScheduledJobLoader.java
    turbine/core/trunk/src/java/org/apache/turbine/modules/ScreenLoader.java
    
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java
    
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaActionFactory.java
    
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaBaseFactory.java
    turbine/core/trunk/xdocs/changes.xml

Modified: turbine/core/trunk/src/java/org/apache/turbine/TurbineConstants.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/TurbineConstants.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/TurbineConstants.java 
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/TurbineConstants.java Sun 
Jan  4 07:23:55 2009
@@ -74,6 +74,12 @@
        /** Default value of the Turbine Module Caching */
        boolean MODULE_CACHE_DEFAULT = true;
 
+    /** Property that controls the module cache size. */
+    String MODULE_CACHE_SIZE_KEY = "module.cache.size";
+
+    /** Default value of the Turbine Module Cache Size */
+    int MODULE_CACHE_SIZE_DEFAULT = 128;
+
        /** The packages where Turbine will look for modules. */
        String MODULE_PACKAGES = "module.packages";
 

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/modules/ActionLoader.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/ActionLoader.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/ActionLoader.java 
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/ActionLoader.java 
Sun Jan  4 07:23:55 2009
@@ -21,13 +21,8 @@
 
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.turbine.Turbine;
-import org.apache.turbine.TurbineConstants;
 import org.apache.turbine.pipeline.PipelineData;
-import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
-import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
 import org.apache.turbine.util.RunData;
 
 /**
@@ -43,14 +38,8 @@
     extends GenericLoader
     implements Loader
 {
-    /** Logging */
-    private static Log log = LogFactory.getLog(ActionLoader.class);
-
     /** The single instance of this class. */
-    private static ActionLoader instance = new 
ActionLoader(getConfiguredCacheSize());
-
-    /** The Assembler Broker Service */
-    private static AssemblerBrokerService ab = 
TurbineAssemblerBroker.getService();
+    private static ActionLoader instance = new ActionLoader();
 
     /**
      * These ctor's are private to force clients to use getInstance()
@@ -62,29 +51,6 @@
     }
 
     /**
-     * These ctor's are private to force clients to use getInstance()
-     * to access this class.
-     */
-    private ActionLoader(int i)
-    {
-        super(i);
-    }
-
-    /**
-     * Adds an instance of an object into the hashtable.
-     *
-     * @param name Name of object.
-     * @param action Action to be associated with name.
-     */
-    private void addInstance(String name, Action action)
-    {
-        if (cache())
-        {
-            this.put(name, action);
-        }
-    }
-
-    /**
      * Attempts to load and execute the external action.
      * @deprecated Use PipelineData version instead.
      * @param data Turbine information.
@@ -148,56 +114,36 @@
     {
         Action action = null;
 
-        // Check if the action is already in the cache
-        if (cache() && this.containsKey(name))
-        {
-            action = (Action) this.get(name);
-            log.debug("Found Action " + name + " in the cache!");
-        }
-        else
+        try
         {
-            log.debug("Loading Action " + name + " from the Assembler Broker");
-
-            try
+            if (ab != null)
             {
-                // Attempt to load the screen
+                // Attempt to load the action
                 action = (Action) ab.getAssembler(Action.NAME, name);
             }
-            catch (ClassCastException cce)
-            {
-                // This can alternatively let this exception be thrown
-                // So that the ClassCastException is shown in the
-                // browser window.  Like this it shows "Screen not Found"
-                action = null;
-            }
+        }
+        catch (ClassCastException cce)
+        {
+            // This can alternatively let this exception be thrown
+            // So that the ClassCastException is shown in the
+            // browser window.  Like this it shows "Screen not Found"
+            action = null;
+        }
 
-            if (action == null)
-            {
-                // If we did not find a screen we should try and give
-                // the user a reason for that...
-                // FIX ME: The AssemblerFactories should each add it's
-                // own string here...
-                List packages = Turbine.getConfiguration()
-                    .getList(TurbineConstants.MODULE_PACKAGES);
-
-                String basePackage = GenericLoader.getBasePackage();
-
-                if (!packages.contains(basePackage))
-                {
-                    packages.add(basePackage);
-                }
-
-                throw new ClassNotFoundException(
-                        "\n\n\tRequested Action not found: " + name +
-                        "\n\tTurbine looked in the following " +
-                        "modules.packages path: \n\t" + packages.toString() + 
"\n");
-            }
-            else if (cache())
-            {
-                // The new instance is added to the cache
-                addInstance(name, action);
-            }
+        if (action == null)
+        {
+            // If we did not find a screen we should try and give
+            // the user a reason for that...
+            // FIX ME: The AssemblerFactories should each add it's
+            // own string here...
+            List packages = GenericLoader.getPackages();
+
+            throw new ClassNotFoundException(
+                    "\n\n\tRequested Action not found: " + name +
+                    "\n\tTurbine looked in the following " +
+                    "modules.packages path: \n\t" + packages.toString() + 
"\n");
         }
+
         return action;
     }
 

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/modules/GenericLoader.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/GenericLoader.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/GenericLoader.java 
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/GenericLoader.java 
Sun Jan  4 07:23:55 2009
@@ -20,10 +20,13 @@
  */
 
 import java.util.Hashtable;
+import java.util.List;
 
 import org.apache.turbine.Turbine;
 import org.apache.turbine.TurbineConstants;
 import org.apache.turbine.pipeline.PipelineData;
+import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
+import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
 import org.apache.turbine.util.RunData;
 
 /**
@@ -37,47 +40,26 @@
  * @version $Id$
  */
 public abstract class GenericLoader
-    extends Hashtable
 {
-    /** @serial This can be serialized */
-    private boolean reload = false;
+    /** The Assembler Broker Service */
+    protected static AssemblerBrokerService ab = 
TurbineAssemblerBroker.getService();
 
     /** @serial This can be serialized */
-    private boolean isCaching = true;
+    private boolean reload = false;
 
     /** Base packages path for Turbine */
     private static final String TURBINE_PACKAGE = "org.apache.turbine.modules";
 
+    /** Packages paths for Turbine */
+    private static final List TURBINE_PACKAGES = 
+        Turbine.getConfiguration().getList(TurbineConstants.MODULE_PACKAGES);
+
     /**
      * Basic constructor for creating a loader.
      */
     public GenericLoader()
     {
         super();
-        isCaching = Turbine.getConfiguration()
-            .getBoolean(TurbineConstants.MODULE_CACHE_KEY,
-                        TurbineConstants.MODULE_CACHE_DEFAULT);
-    }
-
-    /**
-     * Basic constructor for creating a loader.
-     */
-    public GenericLoader(int i)
-    {
-        super(i);
-        isCaching = Turbine.getConfiguration()
-            .getBoolean(TurbineConstants.MODULE_CACHE_KEY,
-                        TurbineConstants.MODULE_CACHE_DEFAULT);
-    }
-
-    /**
-     * If set to true, then cache the Loader objects.
-     *
-     * @return True if the Loader objects are being cached.
-     */
-    public boolean cache()
-    {
-        return this.isCaching;
     }
 
     /**
@@ -153,6 +135,32 @@
         return TURBINE_PACKAGE;
     }
 
+    /**
+     * Gets the package list where Turbine should find its
+     * modules.
+     *
+     * @return A List with the package names (including the base package).
+     */
+    public static List getPackages()
+    {
+        List packages = TURBINE_PACKAGES;
+        
+        if (!packages.contains(TURBINE_PACKAGE))
+        {
+            packages.add(TURBINE_PACKAGE);
+        }
+
+        return packages;
+    }
+
+    /**
+     * Helper method to cast from PipelineData to RunData. This will go when
+     * the pipeline is fully implemented and the RunData-methods are removed
+     * 
+     * @param pipelineData a PipelineData object
+     * 
+     * @return the input object casted to RunData
+     */
     private RunData getRunData(PipelineData pipelineData)
     {
         if(!(pipelineData instanceof RunData)){
@@ -160,5 +168,4 @@
         }
         return (RunData)pipelineData;
     }
-
 }

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/modules/LayoutLoader.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/LayoutLoader.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/LayoutLoader.java 
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/LayoutLoader.java 
Sun Jan  4 07:23:55 2009
@@ -21,14 +21,8 @@
 
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.turbine.Turbine;
-import org.apache.turbine.TurbineConstants;
 import org.apache.turbine.pipeline.PipelineData;
-import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
-import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
-import org.apache.turbine.util.ObjectUtils;
 import org.apache.turbine.util.RunData;
 
 /**
@@ -44,14 +38,8 @@
     extends GenericLoader
     implements Loader
 {
-    /** Logging */
-    private static Log log = LogFactory.getLog(LayoutLoader.class);
-
     /** The single instance of this class. */
-    private static LayoutLoader instance = new 
LayoutLoader(getConfiguredCacheSize());
-
-    /** The Assembler Broker Service */
-    private static AssemblerBrokerService ab = 
TurbineAssemblerBroker.getService();
+    private static LayoutLoader instance = new LayoutLoader();
 
     /**
      * These ctor's are private to force clients to use getInstance()
@@ -63,29 +51,6 @@
     }
 
     /**
-     * These ctor's are private to force clients to use getInstance()
-     * to access this class.
-     */
-    private LayoutLoader(int i)
-    {
-        super(i);
-    }
-
-    /**
-     * Adds an instance of an object into the hashtable.
-     *
-     * @param name Name of object.
-     * @param layout Layout to be associated with name.
-     */
-    private void addInstance(String name, Layout layout)
-    {
-        if (cache())
-        {
-            this.put(name, layout);
-        }
-    }
-
-    /**
      * Attempts to load and execute the external layout.
      *
      * @deprecated Use PipelineData version instead.
@@ -150,55 +115,36 @@
     {
         Layout layout = null;
 
-        // Check if the layout is already in the cache
-        if (cache() && this.containsKey(name))
-        {
-            layout = (Layout) this.get(name);
-            log.debug("Found Layout " + name + " in the cache!");
-        }
-        else
+        try
         {
-            log.debug("Loading Layout " + name + " from the Assembler Broker");
-
-            try
+            if (ab != null)
             {
-                if (ab != null)
-                {
-                    // Attempt to load the layout
-                    layout = (Layout) ab.getAssembler(Layout.NAME, name);
-                }
-            }
-            catch (ClassCastException cce)
-            {
-                // This can alternatively let this exception be thrown
-                // So that the ClassCastException is shown in the
-                // browser window.  Like this it shows "Screen not Found"
-                layout = null;
+                // Attempt to load the layout
+                layout = (Layout) ab.getAssembler(Layout.NAME, name);
             }
+        }
+        catch (ClassCastException cce)
+        {
+            // This can alternatively let this exception be thrown
+            // So that the ClassCastException is shown in the
+            // browser window.  Like this it shows "Screen not Found"
+            layout = null;
+        }
 
-            if (layout == null)
-            {
-                // If we did not find a screen we should try and give
-                // the user a reason for that...
-                // FIX ME: The AssemblerFactories should each add it's
-                // own string here...
-                List packages = Turbine.getConfiguration()
-                    .getList(TurbineConstants.MODULE_PACKAGES);
-
-                ObjectUtils.addOnce(packages,
-                        GenericLoader.getBasePackage());
-
-                throw new ClassNotFoundException(
-                        "\n\n\tRequested Layout not found: " + name +
-                        "\n\tTurbine looked in the following " +
-                        "modules.packages path: \n\t" + packages.toString() + 
"\n");
-            }
-            else if (cache())
-            {
-                // The new instance is added to the cache
-                addInstance(name, layout);
-            }
+        if (layout == null)
+        {
+            // If we did not find a layout we should try and give
+            // the user a reason for that...
+            // FIX ME: The AssemblerFactories should each add it's
+            // own string here...
+            List packages = GenericLoader.getPackages();
+
+            throw new ClassNotFoundException(
+                    "\n\n\tRequested Layout not found: " + name +
+                    "\n\tTurbine looked in the following " +
+                    "modules.packages path: \n\t" + packages.toString() + 
"\n");
         }
+
         return layout;
     }
 

Modified: turbine/core/trunk/src/java/org/apache/turbine/modules/Loader.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/Loader.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/Loader.java 
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/Loader.java Sun Jan  
4 07:23:55 2009
@@ -1,5 +1,7 @@
 package org.apache.turbine.modules;
 
+import org.apache.turbine.services.assemblerbroker.util.AssemblerFactory;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -26,19 +28,9 @@
  * @version $Id$
  */
 
-public interface Loader
+public interface Loader extends AssemblerFactory
 {
     /**
-     * Pulls out an instance of an Assembler Object by name.
-     *
-     * @param name Name of requested Object.
-     * @return An Assembler object or null.
-     * @exception Exception a generic exception.
-     */
-    public Assembler getAssembler(String name)
-        throws Exception;
-    
-    /**
      * Get the size of a possibly configured cache
      * 
      * @return the size of the cache in bytes

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/modules/NavigationLoader.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/NavigationLoader.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/modules/NavigationLoader.java 
(original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/modules/NavigationLoader.java 
Sun Jan  4 07:23:55 2009
@@ -21,15 +21,9 @@
 
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.ecs.ConcreteElement;
 import org.apache.turbine.Turbine;
-import org.apache.turbine.TurbineConstants;
 import org.apache.turbine.pipeline.PipelineData;
-import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
-import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
-import org.apache.turbine.util.ObjectUtils;
 import org.apache.turbine.util.RunData;
 
 /**
@@ -45,14 +39,8 @@
     extends GenericLoader
     implements Loader
 {
-    /** Logging */
-    private static Log log = LogFactory.getLog(NavigationLoader.class);
-
     /** The single instance of this class. */
-    private static NavigationLoader instance = new 
NavigationLoader(getConfiguredCacheSize());
-
-    /** The Assembler Broker Service */
-    private static AssemblerBrokerService ab = 
TurbineAssemblerBroker.getService();
+    private static NavigationLoader instance = new NavigationLoader();
 
     /**
      * These ctor's are private to force clients to use getInstance()
@@ -64,29 +52,6 @@
     }
 
     /**
-     * These ctor's are private to force clients to use getInstance()
-     * to access this class.
-     */
-    private NavigationLoader(int i)
-    {
-        super(i);
-    }
-
-    /**
-     * Adds an instance of an object into the hashtable.
-     *
-     * @param name Name of object.
-     * @param navigation Navigation to be associated with name.
-     */
-    private void addInstance(String name, Navigation navigation)
-    {
-        if (cache())
-        {
-            this.put(name, navigation);
-        }
-    }
-
-    /**
      * Attempts to load and execute the external Navigation. This is
      * used when you want to execute a Navigation which returns its
      * output via a MultiPartElement instead of out the data.getPage()
@@ -188,55 +153,36 @@
     {
         Navigation navigation = null;
 
-        // Check if the navigation is already in the cache
-        if (cache() && this.containsKey(name))
-        {
-            navigation = (Navigation) this.get(name);
-            log.debug("Found Navigation " + name + " in the cache!");
-        }
-        else
+        try
         {
-            log.debug("Loading Navigation " + name + " from the Assembler 
Broker");
-
-            try
+            if (ab != null)
             {
-                if (ab != null)
-                {
-                    // Attempt to load the navigation
-                    navigation = (Navigation) ab.getAssembler(Navigation.NAME, 
name);
-                }
-            }
-            catch (ClassCastException cce)
-            {
-                // This can alternatively let this exception be thrown
-                // So that the ClassCastException is shown in the
-                // browser window.  Like this it shows "Screen not Found"
-                navigation = null;
+                // Attempt to load the navigation
+                navigation = (Navigation) ab.getAssembler(Navigation.NAME, 
name);
             }
+        }
+        catch (ClassCastException cce)
+        {
+            // This can alternatively let this exception be thrown
+            // So that the ClassCastException is shown in the
+            // browser window.  Like this it shows "Screen not Found"
+            navigation = null;
+        }
 
-            if (navigation == null)
-            {
-                // If we did not find a screen we should try and give
-                // the user a reason for that...
-                // FIX ME: The AssemblerFactories should each add it's
-                // own string here...
-                List packages = Turbine.getConfiguration()
-                    .getList(TurbineConstants.MODULE_PACKAGES);
-
-                ObjectUtils.addOnce(packages,
-                        GenericLoader.getBasePackage());
-
-                throw new ClassNotFoundException(
-                        "\n\n\tRequested Navigation not found: " + name +
-                        "\n\tTurbine looked in the following " +
-                        "modules.packages path: \n\t" + packages.toString() + 
"\n");
-            }
-            else if (cache())
-            {
-                // The new instance is added to the cache
-                addInstance(name, navigation);
-            }
+        if (navigation == null)
+        {
+            // If we did not find a navigation we should try and give
+            // the user a reason for that...
+            // FIX ME: The AssemblerFactories should each add it's
+            // own string here...
+            List packages = GenericLoader.getPackages();
+
+            throw new ClassNotFoundException(
+                    "\n\n\tRequested Navigation not found: " + name +
+                    "\n\tTurbine looked in the following " +
+                    "modules.packages path: \n\t" + packages.toString() + 
"\n");
         }
+
         return navigation;
     }
 

Modified: turbine/core/trunk/src/java/org/apache/turbine/modules/PageLoader.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/PageLoader.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/PageLoader.java 
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/PageLoader.java Sun 
Jan  4 07:23:55 2009
@@ -21,14 +21,8 @@
 
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.turbine.Turbine;
-import org.apache.turbine.TurbineConstants;
 import org.apache.turbine.pipeline.PipelineData;
-import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
-import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
-import org.apache.turbine.util.ObjectUtils;
 import org.apache.turbine.util.RunData;
 
 /**
@@ -44,14 +38,8 @@
     extends GenericLoader
     implements Loader
 {
-    /** Logging */
-    private static Log log = LogFactory.getLog(PageLoader.class);
-
     /** The single instance of this class. */
-    private static PageLoader instance = new 
PageLoader(getConfiguredCacheSize());
-
-    /** The Assembler Broker Service */
-    private static AssemblerBrokerService ab = 
TurbineAssemblerBroker.getService();
+    private static PageLoader instance = new PageLoader();
 
     /**
      * These ctor's are private to force clients to use getInstance()
@@ -63,29 +51,6 @@
     }
 
     /**
-     * These ctor's are private to force clients to use getInstance()
-     * to access this class.
-     */
-    private PageLoader(int i)
-    {
-        super(i);
-    }
-
-    /**
-     * Adds an instance of an object into the hashtable.
-     *
-     * @param name Name of object.
-     * @param page Page to be associated with name.
-     */
-    private void addInstance(String name, Page page)
-    {
-        if (cache())
-        {
-            this.put(name, page);
-        }
-    }
-
-    /**
      * Attempts to load and execute the external page.
      * @deprecated Use PipelineData version instead.
      * @param data Turbine information.
@@ -152,55 +117,36 @@
     {
         Page page = null;
 
-        // Check if the screen is already in the cache
-        if (cache() && this.containsKey(name))
-        {
-            page = (Page) this.get(name);
-            log.debug("Found Page " + name + " in the cache!");
-        }
-        else
+        try
         {
-            log.debug("Loading Page " + name + " from the Assembler Broker");
-
-            try
+            if (ab != null)
             {
-                if (ab != null)
-                {
-                    // Attempt to load the screen
-                    page = (Page) ab.getAssembler(Page.NAME, name);
-                }
-            }
-            catch (ClassCastException cce)
-            {
-                // This can alternatively let this exception be thrown
-                // So that the ClassCastException is shown in the
-                // browser window.  Like this it shows "Screen not Found"
-                page = null;
+                // Attempt to load the screen
+                page = (Page) ab.getAssembler(Page.NAME, name);
             }
+        }
+        catch (ClassCastException cce)
+        {
+            // This can alternatively let this exception be thrown
+            // So that the ClassCastException is shown in the
+            // browser window.  Like this it shows "Screen not Found"
+            page = null;
+        }
 
-            if (page == null)
-            {
-                // If we did not find a screen we should try and give
-                // the user a reason for that...
-                // FIX ME: The AssemblerFactories should each add it's
-                // own string here...
-                List packages = Turbine.getConfiguration()
-                    .getList(TurbineConstants.MODULE_PACKAGES);
-
-                ObjectUtils.addOnce(packages,
-                        GenericLoader.getBasePackage());
-
-                throw new ClassNotFoundException(
-                        "\n\n\tRequested Page not found: " + name +
-                        "\n\tTurbine looked in the following " +
-                        "modules.packages path: \n\t" + packages.toString() + 
"\n");
-            }
-            else if (cache())
-            {
-                // The new instance is added to the cache
-                addInstance(name, page);
-            }
+        if (page == null)
+        {
+            // If we did not find a page we should try and give
+            // the user a reason for that...
+            // FIX ME: The AssemblerFactories should each add it's
+            // own string here...
+            List packages = GenericLoader.getPackages();
+
+            throw new ClassNotFoundException(
+                    "\n\n\tRequested Page not found: " + name +
+                    "\n\tTurbine looked in the following " +
+                    "modules.packages path: \n\t" + packages.toString() + 
"\n");
         }
+
         return page;
     }
 

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/modules/ScheduledJobLoader.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/ScheduledJobLoader.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/modules/ScheduledJobLoader.java 
(original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/modules/ScheduledJobLoader.java 
Sun Jan  4 07:23:55 2009
@@ -23,14 +23,8 @@
 
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.turbine.Turbine;
-import org.apache.turbine.TurbineConstants;
-import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
-import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
 import org.apache.turbine.services.schedule.JobEntry;
-import org.apache.turbine.util.ObjectUtils;
 import org.apache.turbine.util.RunData;
 
 /**
@@ -44,15 +38,8 @@
     extends GenericLoader
     implements Loader
 {
-    /** Logging */
-    private static Log log = LogFactory.getLog(ScheduledJobLoader.class);
-
     /** The single instance of this class. */
-    private static ScheduledJobLoader instance =
-        new ScheduledJobLoader(getConfiguredCacheSize());
-
-    /** The Assembler Broker Service */
-    private static AssemblerBrokerService ab = 
TurbineAssemblerBroker.getService();
+    private static ScheduledJobLoader instance = new ScheduledJobLoader();
 
     /**
      * These ctor's are private to force clients to use getInstance()
@@ -64,29 +51,6 @@
     }
 
     /**
-     * These ctor's are private to force clients to use getInstance()
-     * to access this class.
-     */
-    private ScheduledJobLoader(int i)
-    {
-        super(i);
-    }
-
-    /**
-     * Adds an instance of an object into the hashtable.
-     *
-     * @param name Name of object.
-     * @param job Job to be associated with name.
-     */
-    private void addInstance(String name, ScheduledJob job)
-    {
-        if (cache())
-        {
-            this.put(name, job);
-        }
-    }
-
-    /**
      * Attempts to load and execute the external ScheduledJob.
      *
      * @param job The JobEntry.
@@ -157,54 +121,36 @@
     {
         ScheduledJob job = null;
 
-        // Check if the screen is already in the cache
-        if (cache() && this.containsKey(name))
-        {
-            job = (ScheduledJob) this.get(name);
-            log.debug("Found Job " + name + " in the cache!");
-        }
-        else
+        try
         {
-            log.debug("Loading Job " + name + " from the Assembler Broker");
-
-            try
+            if (ab != null)
             {
-                if (ab != null)
-                {
-                    // Attempt to load the job
-                    job = (ScheduledJob) ab.getAssembler(ScheduledJob.NAME, 
name);
-                }
-            }
-            catch (ClassCastException cce)
-            {
-                // This can alternatively let this exception be thrown
-                // So that the ClassCastException is shown in the
-                // browser window.  Like this it shows "Screen not Found"
-                job = null;
+                // Attempt to load the job
+                job = (ScheduledJob) ab.getAssembler(ScheduledJob.NAME, name);
             }
+        }
+        catch (ClassCastException cce)
+        {
+            // This can alternatively let this exception be thrown
+            // So that the ClassCastException is shown in the
+            // browser window.  Like this it shows "Screen not Found"
+            job = null;
+        }
 
-            if (job == null)
-            {
-                // If we did not find a screen we should try and give
-                // the user a reason for that...
-                // FIX ME: The AssemblerFactories should each add it's
-                // own string here...
-                List packages = Turbine.getConfiguration()
-                    .getList(TurbineConstants.MODULE_PACKAGES);
-
-                ObjectUtils.addOnce(packages, GenericLoader.getBasePackage());
-
-                throw new ClassNotFoundException(
-                        "\n\n\tRequested ScheduledJob not found: " + name +
-                        "\n\tTurbine looked in the following " +
-                        "modules.packages path: \n\t" + packages.toString() + 
"\n");
-            }
-            else if (cache())
-            {
-                // The new instance is added to the cache
-                addInstance(name, job);
-            }
+        if (job == null)
+        {
+            // If we did not find a scheduled job we should try and give
+            // the user a reason for that...
+            // FIX ME: The AssemblerFactories should each add it's
+            // own string here...
+            List packages = GenericLoader.getPackages();
+
+            throw new ClassNotFoundException(
+                    "\n\n\tRequested ScheduledJob not found: " + name +
+                    "\n\tTurbine looked in the following " +
+                    "modules.packages path: \n\t" + packages.toString() + 
"\n");
         }
+
         return job;
     }
 

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/modules/ScreenLoader.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/modules/ScreenLoader.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/modules/ScreenLoader.java 
(original)
+++ turbine/core/trunk/src/java/org/apache/turbine/modules/ScreenLoader.java 
Sun Jan  4 07:23:55 2009
@@ -23,15 +23,9 @@
 
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.ecs.ConcreteElement;
 import org.apache.turbine.Turbine;
-import org.apache.turbine.TurbineConstants;
 import org.apache.turbine.pipeline.PipelineData;
-import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
-import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
-import org.apache.turbine.util.ObjectUtils;
 import org.apache.turbine.util.RunData;
 
 /**
@@ -47,14 +41,8 @@
     extends GenericLoader
     implements Loader
 {
-    /** Logging */
-    private static Log log = LogFactory.getLog(ScreenLoader.class);
-
     /** The single instance of this class. */
-    private static ScreenLoader instance = new 
ScreenLoader(getConfiguredCacheSize());
-
-    /** The Assembler Broker Service */
-    private static AssemblerBrokerService ab = 
TurbineAssemblerBroker.getService();
+    private static ScreenLoader instance = new ScreenLoader();
 
     /**
      * These ctor's are private to force clients to use getInstance()
@@ -66,29 +54,6 @@
     }
 
     /**
-     * These ctor's are private to force clients to use getInstance()
-     * to access this class.
-     */
-    private ScreenLoader(int i)
-    {
-        super(i);
-    }
-
-    /**
-     * Adds an instance of an object into the hashtable.
-     *
-     * @param name Name of object.
-     * @param screen Screen to be associated with name.
-     */
-    private void addInstance(String name, Screen screen)
-    {
-        if (cache())
-        {
-            this.put(name, screen);
-        }
-    }
-
-    /**
      * Attempts to load and execute the external Screen. This is used
      * when you want to execute a Screen which returns its output via
      * a MultiPartElement instead of out the data.getPage() value.
@@ -124,6 +89,7 @@
         // Execute screen
         return getInstance(name).build(pipelineData);
     }
+    
     /**
      * Attempts to load and execute the Screen. This is used when you
      * want to execute a Screen which returns its output via the
@@ -153,6 +119,7 @@
        {
         this.eval(pipelineData, name);
        }
+    
     /**
      * Pulls out an instance of the object by name.  Name is just the
      * single name of the object. This is equal to getInstance but
@@ -190,55 +157,36 @@
     {
         Screen screen = null;
 
-        // Check if the screen is already in the cache
-        if (cache() && this.containsKey(name))
-        {
-            screen = (Screen) this.get(name);
-            log.debug("Found Screen " + name + " in the cache!");
-        }
-        else
+        try
         {
-            log.debug("Loading Screen " + name + " from the Assembler Broker");
-
-            try
+            if (ab != null)
             {
-                if (ab != null)
-                {
-                    // Attempt to load the screen
-                    screen = (Screen) ab.getAssembler(Screen.NAME, name);
-                }
-            }
-            catch (ClassCastException cce)
-            {
-                // This can alternatively let this exception be thrown
-                // So that the ClassCastException is shown in the
-                // browser window.  Like this it shows "Screen not Found"
-                screen = null;
+                // Attempt to load the screen
+                screen = (Screen) ab.getAssembler(Screen.NAME, name);
             }
+        }
+        catch (ClassCastException cce)
+        {
+            // This can alternatively let this exception be thrown
+            // So that the ClassCastException is shown in the
+            // browser window.  Like this it shows "Screen not Found"
+            screen = null;
+        }
 
-            if (screen == null)
-            {
-                // If we did not find a screen we should try and give
-                // the user a reason for that...
-                // FIX ME: The AssemblerFactories should each add it's
-                // own string here...
-                List packages = Turbine.getConfiguration()
-                    .getList(TurbineConstants.MODULE_PACKAGES);
-
-                ObjectUtils.addOnce(packages,
-                        GenericLoader.getBasePackage());
-
-                throw new ClassNotFoundException(
-                        "\n\n\tRequested Screen not found: " + name +
-                        "\n\tTurbine looked in the following " +
-                        "modules.packages path: \n\t" + packages.toString() + 
"\n");
-            }
-            else if (cache())
-            {
-                // The new instance is added to the cache
-                addInstance(name, screen);
-            }
+        if (screen == null)
+        {
+            // If we did not find a screen we should try and give
+            // the user a reason for that...
+            // FIX ME: The AssemblerFactories should each add it's
+            // own string here...
+            List packages = GenericLoader.getPackages();
+            
+            throw new ClassNotFoundException(
+                    "\n\n\tRequested Screen not found: " + name +
+                    "\n\tTurbine looked in the following " +
+                    "modules.packages path: \n\t" + packages.toString() + 
"\n");
         }
+
         return screen;
     }
 

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java
 (original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java
 Sun Jan  4 07:23:55 2009
@@ -27,9 +27,12 @@
 import java.util.Map;
 import java.util.Vector;
 
+import org.apache.commons.collections.map.LRUMap;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.turbine.Turbine;
+import org.apache.turbine.TurbineConstants;
 import org.apache.turbine.modules.Assembler;
 import org.apache.turbine.services.InitializationException;
 import org.apache.turbine.services.TurbineBaseService;
@@ -56,7 +59,13 @@
 
     /** A structure that holds the registered AssemblerFactories */
     private Map factories = null;
-
+    
+    /** A cache that holds the generated Assemblers */
+    private Map assemblerCache = null;
+    
+    /** Caching on/off */
+    private boolean isCaching;
+    
     /**
      * Get a list of AssemblerFactories of a certain type
      *
@@ -122,6 +131,7 @@
         throws InitializationException
     {
         factories = new HashMap();
+        
         try
         {
             Configuration conf = getConfiguration();
@@ -141,6 +151,20 @@
             throw new InitializationException(
                     "AssemblerBrokerService failed to initialize", e);
         }
+        
+        isCaching = Turbine.getConfiguration()
+            .getBoolean(TurbineConstants.MODULE_CACHE_KEY,
+                        TurbineConstants.MODULE_CACHE_DEFAULT);
+     
+        if (isCaching)
+        {
+            int cacheSize = Turbine.getConfiguration()
+                .getInt(TurbineConstants.MODULE_CACHE_SIZE_KEY,
+                        TurbineConstants.MODULE_CACHE_SIZE_DEFAULT);
+            
+            assemblerCache = new LRUMap(cacheSize);
+        }
+        
         setInit(true);
     }
 
@@ -169,24 +193,42 @@
     public Assembler getAssembler(String type, String name)
         throws TurbineException
     {
-        List facs = getFactoryGroup(type);
-
+        String key = type + ":" + name;
         Assembler assembler = null;
-        for (Iterator it = facs.iterator(); (assembler == null) && 
it.hasNext();)
+        
+        if (isCaching && assemblerCache.containsKey(key))
         {
-            AssemblerFactory fac = (AssemblerFactory) it.next();
-            try
-            {
-                assembler = fac.getAssembler(name);
-            }
-            catch (Exception e)
+            assembler = (Assembler)assemblerCache.get(key);
+            log.debug("Found " + key + " in the cache!");
+        }
+        else
+        {
+            log.debug("Loading " + key);
+            List facs = getFactoryGroup(type);
+    
+            for (Iterator it = facs.iterator(); (assembler == null) && 
it.hasNext();)
             {
-                throw new TurbineException("Failed to load an assembler for "
-                                           + name + " from the "
-                                           + type + " factory "
-                                           + fac.getClass().getName(), e);
+                AssemblerFactory fac = (AssemblerFactory) it.next();
+                
+                try
+                {
+                    assembler = fac.getAssembler(name);
+                }
+                catch (Exception e)
+                {
+                    throw new TurbineException("Failed to load an assembler 
for "
+                                               + name + " from the "
+                                               + type + " factory "
+                                               + fac.getClass().getName(), e);
+                }
+                
+                if (isCaching && assembler != null)
+                {
+                    assemblerCache.put(key, assembler);
+                }
             }
         }
+        
         return assembler;
     }
 }

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaActionFactory.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaActionFactory.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaActionFactory.java
 (original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaActionFactory.java
 Sun Jan  4 07:23:55 2009
@@ -23,6 +23,7 @@
 
 import org.apache.turbine.modules.Action;
 import org.apache.turbine.modules.Assembler;
+import org.apache.turbine.modules.Loader;
 
 /**
  * An action factory that attempts to load a java class from
@@ -33,7 +34,8 @@
  * @version $Id$
  */
 public class JavaActionFactory
-        extends JavaBaseFactory
+    extends JavaBaseFactory
+    implements Loader
 {
     /**
      * Get an Assembler.
@@ -45,4 +47,10 @@
     {
         return getAssembler(Action.PREFIX, name);
     }
+
+    public int getCacheSize()
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
 }

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaBaseFactory.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaBaseFactory.java?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaBaseFactory.java
 (original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaBaseFactory.java
 Sun Jan  4 07:23:55 2009
@@ -29,13 +29,9 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
-import org.apache.turbine.Turbine;
-import org.apache.turbine.TurbineConstants;
 import org.apache.turbine.modules.Assembler;
 import org.apache.turbine.modules.GenericLoader;
 import org.apache.turbine.services.assemblerbroker.util.AssemblerFactory;
-import org.apache.turbine.util.ObjectUtils;
 
 /**
  * A screen factory that attempts to load a java class from
@@ -49,8 +45,7 @@
     implements AssemblerFactory
 {
     /** A vector of packages. */
-    private static List packages =
-        Turbine.getConfiguration().getList(TurbineConstants.MODULE_PACKAGES);
+    private static List packages = GenericLoader.getPackages();
 
     /** Logging */
     protected Log log = LogFactory.getLog(this.getClass());
@@ -61,11 +56,6 @@
      */
     private Map classCache = Collections.synchronizedMap(new HashMap());
 
-    static
-    {
-        ObjectUtils.addOnce(packages, GenericLoader.getBasePackage());
-    }
-
     /**
      * Get an Assembler.
      *

Modified: turbine/core/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/xdocs/changes.xml?rev=731268&r1=731267&r2=731268&view=diff
==============================================================================
--- turbine/core/trunk/xdocs/changes.xml (original)
+++ turbine/core/trunk/xdocs/changes.xml Sun Jan  4 07:23:55 2009
@@ -24,7 +24,12 @@
   </properties>
 
   <body>
-    <release version="2.4-M2" date="in Subversion">
+    <release version="4.0-dev" date="in Subversion">
+      <action type="update" dev="tv">
+        Moved the different loader caches into the AssemblerBrokerService and 
+        centralized several loader features. The loaders do no longer extend
+        Hashtable.
+      </action>
       <action type="update" dev="tv">
         Removed the references to the different module types from 
TurbineConstants
         and tried to reduce the number of inter-dependencies in the module, 
loader


Reply via email to