You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2003/07/15 13:28:34 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/velocity TurbineVelocityService.java

henning     2003/07/15 04:28:34

  Modified:    src/java/org/apache/turbine/services/velocity
                        TurbineVelocityService.java
  Log:
  There are some subtilities in the sequence of pull and velocity service which are
  quite fragile in respect to the caching of the global context. Simply rip it out,
  get it from the Pull Service every time we need. it.
  
  Replace the Facade methods with a locally cached pullService reference.
  
  Revision  Changes    Path
  1.25      +16 -22    jakarta-turbine-2/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java
  
  Index: TurbineVelocityService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- TurbineVelocityService.java	15 Jul 2003 09:07:32 -0000	1.24
  +++ TurbineVelocityService.java	15 Jul 2003 11:28:34 -0000	1.25
  @@ -76,6 +76,7 @@
   
   import org.apache.turbine.Turbine;
   import org.apache.turbine.services.InitializationException;
  +import org.apache.turbine.services.pull.PullService;
   import org.apache.turbine.services.pull.TurbinePull;
   import org.apache.turbine.services.template.BaseTemplateEngineService;
   import org.apache.turbine.util.RunData;
  @@ -134,12 +135,6 @@
       /** Logging */
       private static Log log = LogFactory.getLog(TurbineVelocityService.class);
   
  -    /**
  -     * The context used to the store the context
  -     * containing the global application tools.
  -     */
  -    private Context globalContext = null;
  -
       /** Is the pullModelActive? */
       private boolean pullModelActive = false;
   
  @@ -152,6 +147,10 @@
       /** Shall we catch Velocity Errors and report them in the log file? */
       private boolean catchErrors = true;
   
  +    /** Internal Reference to the pull Service */
  +    private PullService pullService = null;
  +
  +
       /**
        * Load all configured components and initialize them. This is
        * a zero parameter variant which queries the Turbine Servlet
  @@ -167,26 +166,17 @@
           {
               initVelocity();
   
  -            globalContext = null;
  -
               // We can only load the Pull Model ToolBox
               // if the Pull service has been listed in the TR.props
               // and the service has successfully been initialized.
               if (TurbinePull.isRegistered())
               {
  -                globalContext = TurbinePull.getGlobalContext();
  -
                   pullModelActive = true;
   
  -                refreshToolsPerRequest = TurbinePull.refreshToolsPerRequest();
  -                log.debug("Activated Pull Tools");
  -            }
  +                pullService = TurbinePull.getService();
   
  -            // If the Pull service is inactive then we create
  -            // an empty toolBoxContext
  -            if (globalContext == null)
  -            {
  -                globalContext = getNewContext();
  +                refreshToolsPerRequest = pullService.refreshToolsPerRequest();
  +                log.debug("Activated Pull Tools");
               }
   
               // Register with the template service.
  @@ -229,6 +219,9 @@
        */
       public Context getContext()
       {
  +        Context globalContext = 
  +                pullModelActive ? pullService.getGlobalContext() : null;
  +
           Context ctx = new VelocityContext(globalContext);
           addEventCartridge(ctx);
   
  @@ -239,7 +232,7 @@
           //
           if (pullModelActive && refreshToolsPerRequest)
           {
  -            TurbinePull.refreshGlobalTools();
  +            pullService.refreshGlobalTools();
           }
           return ctx;
       }
  @@ -267,6 +260,7 @@
           EventCartridge ec = new EventCartridge();
           ec.addEventHandler(this);
           ec.attachToContext(ctx);
  +        log.debug("Activated Velocity Event Cartridge for Context " + ctx);
       }
   
       /**
  @@ -321,7 +315,7 @@
                   // 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);
  +                pullService.populateContext(context, data);
               }
   
               data.getTemplateInfo().setTemplateContext(
  @@ -692,7 +686,7 @@
       {
           if (pullModelActive)
           {
  -            TurbinePull.releaseTools(context);
  +            pullService.releaseTools(context);
           }
       }
   }
  
  
  

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