You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jo...@apache.org on 2001/08/17 08:02:01 UTC

cvs commit: jakarta-turbine-3/src/java/org/apache/turbine/services/pull PullService.java TurbinePull.java TurbinePullService.java

jon         01/08/16 23:02:01

  Modified:    src/java/org/apache/turbine TemplateContext.java
               src/java/org/apache/turbine/modules
                        DefaultTemplateContext.java Module.java
               src/java/org/apache/turbine/pipeline ClassicPipeline.java
               src/java/org/apache/turbine/services/pull PullService.java
                        TurbinePull.java TurbinePullService.java
  Log:
  fixed an issue with use of globalcontext. all context.put's were being
  cached globally...and now that i realize it...all REQUESTS were using the
  SAME! context! gag. no wonder we were seeing weird stuff during scarab
  development...i'm surprised anything was working properly...
  
  -jon
  
  Revision  Changes    Path
  1.2       +25 -0     jakarta-turbine-3/src/java/org/apache/turbine/TemplateContext.java
  
  Index: TemplateContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/TemplateContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TemplateContext.java	2001/08/16 04:41:33	1.1
  +++ TemplateContext.java	2001/08/17 06:02:01	1.2
  @@ -54,6 +54,8 @@
    * <http://www.apache.org/>.
    */
   
  +import java.util.Set;
  +
   /**
    * A completely minimal interface for the time being
    * to allow the decoupling of the template services
  @@ -61,7 +63,30 @@
    */
   public interface TemplateContext
   {
  +    /**
  +     * Adds a name/value pair to the context.
  +     *
  +     * @param key   The name to key the provided value with.
  +     * @param value The corresponding value.
  +     */
       public Object put(String key, Object value);
  +
  +    /**
  +     * Gets the value corresponding to the provided key from the context.
  +     *
  +     * @param key The name of the desired value.
  +     * @return    The value corresponding to the provided key.
  +     */
       public Object get(String key);
  +
  +    /**
  +     * Removes the value associated with the specified key from the context.
  +     *
  +     * @param key The name of the value to remove.
  +     * @return    The value that the key was mapped to, or <code>null</code>
  +     *            if unmapped.
  +     */
       public Object remove(Object target);
  +    
  +    public Set keySet();
   }
  
  
  
  1.2       +7 -1      jakarta-turbine-3/src/java/org/apache/turbine/modules/DefaultTemplateContext.java
  
  Index: DefaultTemplateContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/modules/DefaultTemplateContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultTemplateContext.java	2001/08/16 04:41:35	1.1
  +++ DefaultTemplateContext.java	2001/08/17 06:02:01	1.2
  @@ -55,12 +55,13 @@
    */
   
   import java.util.HashMap;
  +import java.util.Set;
   import org.apache.turbine.TemplateContext;
   
   public class DefaultTemplateContext
       implements TemplateContext
   {
  -    private HashMap context = new HashMap();
  +    HashMap context = new HashMap();
   
       public Object put(String key, Object value)
       {
  @@ -77,6 +78,11 @@
       {
           context.remove(target);
           return target;
  +    }
  +    
  +    public Set keySet()
  +    {
  +        return context.keySet();
       }
   }
   
  
  
  
  1.2       +8 -14     jakarta-turbine-3/src/java/org/apache/turbine/modules/Module.java
  
  Index: Module.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/modules/Module.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Module.java	2001/08/16 04:41:35	1.1
  +++ Module.java	2001/08/17 06:02:01	1.2
  @@ -68,7 +68,7 @@
    * future use is yet to be determined.
    *
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: Module.java,v 1.1 2001/08/16 04:41:35 jvanzyl Exp $
  + * @version $Id: Module.java,v 1.2 2001/08/17 06:02:01 jon Exp $
    */
   public class Module
   {
  @@ -132,11 +132,12 @@
           doBuildTemplate(data, getTemplateContext(data));
       }
   
  -    public static TemplateContext getTemplateContext()
  -    {
  -        return TurbinePull.getGlobalContext();
  -    }
  -
  +    /**
  +     * Populates the TemplateContext with Pull Tools and the
  +     * RunData object.
  +     *
  +     * @param data Turbine information.
  +     */
       public static TemplateContext getTemplateContext(RunData data)
       {
           // Attempt to get it from the data first.  If it doesn't
  @@ -146,15 +147,8 @@
   
           if (context == null)
           {
  -            context = getTemplateContext();
  +            context = TurbinePull.getRuntimeContext(data);
               context.put ( "data", data );
  -
  -            // Populate the toolbox with request scope, session scope
  -            // and persistent scope tools (global tools are already in
  -            // the toolBoxContent which has been wrapped to construct
  -            // this request-specific context).
  -            TurbinePull.populateContext(context, data);
  -
               data.setTemp(Turbine.CONTEXT, context);
           }
           return context;
  
  
  
  1.2       +2 -2      jakarta-turbine-3/src/java/org/apache/turbine/pipeline/ClassicPipeline.java
  
  Index: ClassicPipeline.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/pipeline/ClassicPipeline.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassicPipeline.java	2001/08/16 04:41:37	1.1
  +++ ClassicPipeline.java	2001/08/17 06:02:01	1.2
  @@ -264,8 +264,8 @@
       public void preExecuteAction(RunData data)
           throws Exception
       {
  -        TemplateContext context = Module.getTemplateContext(data);
  -        data.setTemp(Turbine.CONTEXT, context);
  +        // Puts a copy of the Context into the data.setTemp()
  +        Module.getTemplateContext(data);
       }
   
       public void executeAction(RunData data)
  
  
  
  1.2       +10 -1     jakarta-turbine-3/src/java/org/apache/turbine/services/pull/PullService.java
  
  Index: PullService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/pull/PullService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PullService.java	2001/08/16 04:41:45	1.1
  +++ PullService.java	2001/08/17 06:02:01	1.2
  @@ -85,7 +85,7 @@
    * be specified as well.
    *
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
  - * @version $Id: PullService.java,v 1.1 2001/08/16 04:41:45 jvanzyl Exp $
  + * @version $Id: PullService.java,v 1.2 2001/08/17 06:02:01 jon Exp $
    */
   public interface PullService extends Service
   {
  @@ -99,6 +99,15 @@
        * use as part of the Turbine Pull Model.
        */
       public TemplateContext getGlobalContext();
  +
  +    /**
  +     * This is used to populate a TemplateContext with all of the
  +     * various tools. The order of population is:
  +     * Request, Session, Persistent, Global
  +     *
  +     * @param data Turbine information.
  +     */
  +    public TemplateContext getRuntimeContext(RunData data);
   
       /**
        * Populate the given context with all request, session
  
  
  
  1.2       +13 -1     jakarta-turbine-3/src/java/org/apache/turbine/services/pull/TurbinePull.java
  
  Index: TurbinePull.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/pull/TurbinePull.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TurbinePull.java	2001/08/16 04:41:45	1.1
  +++ TurbinePull.java	2001/08/17 06:02:01	1.2
  @@ -67,7 +67,7 @@
    *
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  - * @version $Id: TurbinePull.java,v 1.1 2001/08/16 04:41:45 jvanzyl Exp $
  + * @version $Id: TurbinePull.java,v 1.2 2001/08/17 06:02:01 jon Exp $
    */
   public abstract class TurbinePull
   {
  @@ -93,6 +93,18 @@
       public static final TemplateContext getGlobalContext()
       {
           return getService().getGlobalContext();
  +    }
  +
  +    /**
  +     * This is used to populate a TemplateContext with all of the
  +     * various tools. The order of population is:
  +     * Request, Session, Persistent, Global
  +     *
  +     * @param data Turbine information.
  +     */
  +    public static TemplateContext getRuntimeContext(RunData data)
  +    {
  +        return getService().getRuntimeContext(data);
       }
   
       /**
  
  
  
  1.2       +31 -6     jakarta-turbine-3/src/java/org/apache/turbine/services/pull/TurbinePullService.java
  
  Index: TurbinePullService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/pull/TurbinePullService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TurbinePullService.java	2001/08/16 04:41:45	1.1
  +++ TurbinePullService.java	2001/08/17 06:02:01	1.2
  @@ -142,7 +142,7 @@
    *
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
    * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
  - * @version $Id: TurbinePullService.java,v 1.1 2001/08/16 04:41:45 jvanzyl Exp $
  + * @version $Id: TurbinePullService.java,v 1.2 2001/08/17 06:02:01 jon Exp $
    */
   public class TurbinePullService
       extends BaseService
  @@ -353,12 +353,37 @@
       }
   
       /**
  +     * This is used to populate a TemplateContext with all of the
  +     * various tools. The order of population is:
  +     * Request, Session, Persistent, Global
  +     *
  +     * @param data Turbine information.
  +     */
  +    public TemplateContext getRuntimeContext(RunData data)
  +    {
  +        TemplateContext tc = new DefaultTemplateContext();
  +        populateContext(tc, data);
  +
  +        // copy global context values into tc
  +        // FIXME: this could probably be optimized with the use of
  +        // chained contexts, but that is currently not implemented
  +        // in TemplateContext
  +        Iterator i = getGlobalContext().keySet().iterator();
  +        while (i.hasNext())
  +        {
  +            String key = (String)i.next();
  +            tc.put (key, getGlobalContext().get(key));            
  +        }
  +        return tc;
  +    }
  +
  +    /**
        * Populate the given context with all request, session
        * and persistent scope tools (it is assumed that the context
        * already wraps the global context, and thus already contains
        * the global tools).
        *
  -     * @param context a Velocity Context to populate
  +     * @param context a TemplateContext to populate
        * @param data a RunData object for request specific data
        */
       public void populateContext(TemplateContext context, RunData data)
  @@ -380,7 +405,7 @@
       /**
        * Populate the given context with the global tools
        *
  -     * @param context a Velocity Context to populate
  +     * @param context a TemplateContext to populate
        */
       private void populateWithGlobalTools(TemplateContext context)
       {
  @@ -415,7 +440,7 @@
       /**
        * Populate the given context with the request-scope tools
        *
  -     * @param context a Velocity Context to populate
  +     * @param context a TemplateContext to populate
        * @param data a RunData instance
        */
       private void populateWithRequestTools(TemplateContext context, RunData data)
  @@ -452,7 +477,7 @@
       /**
        * Populate the given context with the session-scope tools
        *
  -     * @param context a Velocity Context to populate
  +     * @param context a TemplateContext to populate
        * @param data a RunData instance
        */
       private void populateWithSessionTools(List tools,
  @@ -573,7 +598,7 @@
        * Release the request-scope tool instances in the
        * given Context back to the pool
        *
  -     * @param context the Velocity Context to release tools from
  +     * @param context the TemplateContext to release tools from
        */
       public void releaseTools(TemplateContext context)
       {
  
  
  

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