cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <res1c...@verizon.net>
Subject Re: svn commit: r169150 - /cocoon/trunk/src/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
Date Wed, 25 May 2005 19:42:58 GMT
lgawron@apache.org wrote:

>Author: lgawron
>Date: Sun May  8 12:25:12 2005
>New Revision: 169150
>
>URL: http://svn.apache.org/viewcvs?rev=169150&view=rev
>Log:
>share root rhino scope
>
>Modified:
>    cocoon/trunk/src/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
>
>Modified: cocoon/trunk/src/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
>URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java?rev=169150&r1=169149&r2=169150&view=diff
>==============================================================================
>--- cocoon/trunk/src/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
(original)
>+++ cocoon/trunk/src/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
Sun May  8 12:25:12 2005
>@@ -42,9 +42,23 @@
>  * @version CVS $Id$
>  */
> public class TemplateObjectModelHelper {
>+    private static Scriptable rootScope = null;
>+    
>     /** Avoid instantiation */
>     private TemplateObjectModelHelper() {}
> 
>+    public static Scriptable getRootScope() {
>+        if (rootScope == null) {
>+            // Create it if never used up to now
>+            Context ctx = Context.enter();
>+            try {
>+                rootScope = ctx.initStandardObjects(null);
>+            } finally {
>+                Context.exit();
>+            }
>+        }
>+        return rootScope;
>+    }
>     public static void fillContext(Object contextObject, Map map) {
>         // Hack: I use jxpath to populate the context object's properties
>         // in the jexl context
>@@ -102,23 +116,20 @@
>         // Needed for the FOM wrappers
>         Context cx = Context.enter();
>         try {
>-            //FIXME: we surely need to share the scope as this operation is time consuming
>-            Scriptable scope = cx.initStandardObjects();
>-        
>             // cocoon.request
>             final Request request = ObjectModelHelper.getRequest( objectModel );
>-            cocoon.put("request", new FOM_Cocoon.FOM_Request(scope, request));
>+            cocoon.put("request", new FOM_Cocoon.FOM_Request(getRootScope(), request));
>             
>             // cocoon.session
>             final Session session = request.getSession(false);
>             if (session != null) {
>-                cocoon.put("session", new FOM_Cocoon.FOM_Session(scope, session));
>+                cocoon.put("session", new FOM_Cocoon.FOM_Session(getRootScope(), session));
>             }
>         
>             // cocoon.context
>             final org.apache.cocoon.environment.Context context =
>                 ObjectModelHelper.getContext( objectModel );
>-            cocoon.put("context", new FOM_Cocoon.FOM_Context(scope, context));
>+            cocoon.put("context", new FOM_Cocoon.FOM_Context(getRootScope(), context));
> 
>         } finally {
>             Context.exit();
>@@ -164,17 +175,14 @@
>         } else { 
>             Context cx = Context.enter();
>             try {
>-                //FIXME: we surely need to share the scope as this operation is time
consuming
>-                Scriptable scope = cx.initStandardObjects();
>-
>                 final String JAVA_PACKAGE = "JavaPackage";
>                 ClassLoader cl = Thread.currentThread().getContextClassLoader();
>                 Scriptable newPackages = new NativeJavaPackage( "", cl );
>-                newPackages.setParentScope( scope );
>-                newPackages.setPrototype( ScriptableObject.getClassPrototype(   scope,
>+                newPackages.setParentScope( getRootScope() );
>+                newPackages.setPrototype( ScriptableObject.getClassPrototype(   getRootScope(),
>                                                                                 JAVA_PACKAGE
) );
>                 objectModel.put( "Packages", newPackages );
>-                objectModel.put( "java", ScriptableObject.getProperty( scope, "java"
) );
>+                objectModel.put( "java", ScriptableObject.getProperty( getRootScope(),
"java" ) );
>             } finally {
>                 Context.exit();
>             }
>
>
>
>
>  
>



Mime
View raw message