cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <lgaw...@apache.org>
Subject Re: svn commit: r154841 - in cocoon/trunk/src: blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java blocks/template/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
Date Tue, 22 Feb 2005 13:11:09 GMT
lgawron@apache.org wrote:
> Author: lgawron
> Date: Tue Feb 22 05:01:08 2005
> New Revision: 154841
> 
> URL: http://svn.apache.org/viewcvs?view=rev&rev=154841
> Log:
> turns out that that <jx:set var="tags" value="${java.util.HashMap()}"/> worked
not due to Jexl mechanisms 
> but due to Rhino features (AFAIU NativeJavaClass executed as function with some parameters
passed returned an appropriate object)
> In order to keep backward functionality NativeJavaPackage has to be registered as property
of template object model.
> 
> Modified:
>     cocoon/trunk/src/blocks/template/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java
>     cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java
>     cocoon/trunk/src/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
> 
<snip/>

> 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?view=diff&r1=154840&r2=154841
> ==============================================================================
> --- cocoon/trunk/src/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
(original)
> +++ cocoon/trunk/src/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
Tue Feb 22 05:01:08 2005
  >  /**
> @@ -129,6 +134,30 @@
>              fillContext(contextObject, map);
>          }
>          
> +        Object javaPkg = FOM_JavaScriptFlowHelper.getJavaPackage(objectModel);
> +        Object pkgs = FOM_JavaScriptFlowHelper.getPackages(objectModel);
> +        
> +        if ( javaPkg != null && pkgs != null ) {
> +            map.put( "Packages", javaPkg );
> +            map.put( "java", pkgs );
> +        } 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,
> +                                                                                JAVA_PACKAGE
) );
> +                map.put( "Packages", newPackages );
> +                map.put( "java", ScriptableObject.getProperty( scope, "java" ) );
> +            } finally {
> +                Context.exit();
> +            }
> +        }
>          return map;
>      }

Right now every test case for new jxtg passes. The problem is: do we 
want our template object model messed up like this?

As I have implemented the fix having no knowlegde of rhino internals at 
all I have some questions to rhino gurus:

1. Scriptable scope = cx.initStandardObjects() is a time consuming 
operation. What is the proper way to share some global scope?

2. If I share a global scope can I put newPackages into it for good? It 
seems like it's not possible as NativeJavaPackage is bound to thread's 
classloader. Am I right?

-- 
Leszek Gawron                                                 MobileBox
lgawron@apache.org                              http://www.mobilebox.pl

Mime
View raw message