velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From by...@apache.org
Subject svn commit: r733438 - in /velocity/engine/trunk/src/java/org/apache/velocity/runtime: VelocimacroManager.java directive/RuntimeMacro.java directive/VelocimacroProxy.java
Date Sun, 11 Jan 2009 09:32:39 GMT
Author: byron
Date: Sun Jan 11 01:32:38 2009
New Revision: 733438

URL: http://svn.apache.org/viewvc?rev=733438&view=rev
Log:
Cleanup macro initialization, prevent the init methods of ASTNodes within macros and of VelocimacroProxy
from being called more then once.  Remove calling init methods during render.


Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java?rev=733438&r1=733437&r2=733438&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java Sun
Jan 11 01:32:38 2009
@@ -58,6 +58,8 @@
 
     /** set of names of library tempates/namespaces */
     private final Set libraries = Collections.synchronizedSet(new HashSet());
+    
+    private RuntimeServices rsvc = null;
 
     /*
      * big switch for namespaces.  If true, then properties control
@@ -77,6 +79,7 @@
          */
 
         globalNamespace = addNamespace(GLOBAL_NAMESPACE);
+        this.rsvc = rsvc;
     }
 
     /**
@@ -100,7 +103,7 @@
             throw new RuntimeException("Null AST for "+vmName+" in "+namespace);
         }
 
-        MacroEntry me = new MacroEntry(vmName, macroBody, argArray, namespace);
+        MacroEntry me = new MacroEntry(vmName, macroBody, argArray, namespace, rsvc);
 
         me.setFromLibrary(registerFromLib);
         
@@ -451,7 +454,8 @@
         private VelocimacroProxy vp;
 
         private MacroEntry(final String vmName, final Node macro,
-                   final String argArray[], final String sourceTemplate)
+                   final String argArray[], final String sourceTemplate,
+                   RuntimeServices rsvc)
         {
             this.vmName = vmName;
             this.argArray = argArray;
@@ -462,6 +466,7 @@
             vp.setName(this.vmName);
             vp.setArgArray(this.argArray);
             vp.setNodeTree(this.nodeTree);
+            vp.init(rsvc);
         }
         
         /**

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java?rev=733438&r1=733437&r2=733438&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
Sun Jan 11 01:32:38 2009
@@ -226,7 +226,7 @@
             try
             {
             	// mainly check the number of arguments
-                vmProxy.init(rsvc, context, node);
+                vmProxy.checkArgs(context, node);
             }
             catch (TemplateInitException die)
             {

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?rev=733438&r1=733437&r2=733438&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
Sun Jan 11 01:32:38 2009
@@ -226,43 +226,31 @@
     }
 
     /**
-     * The major meat of VelocimacroProxy, init() checks the # of arguments.
-     * 
-     * @param rs
-     * @param context
-     * @param node
-     * @throws TemplateInitException
+     * Initialize members of VelocimacroProxy.  called from MacroEntry
      */
-    public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
-            throws TemplateInitException
+    public void init(RuntimeServices rs)
     {
-        // there can be multiple threads here so avoid double inits
-        synchronized (this)
-        {
-            if (!preInit)
-            {
-                super.init(rs, context, node);
-
-                // this is a very expensive call (ExtendedProperties is very slow)
-                strictArguments = rs.getConfiguration().getBoolean(
-                        RuntimeConstants.VM_ARGUMENTS_STRICT, false);
-
-                // support for local context scope feature, where all references are local
-                // we do not have to check this at every invocation of ProxyVMContext
-                localContextScope = rsvc.getBoolean(RuntimeConstants.VM_CONTEXT_LOCALSCOPE,
false);
-
-                // get the macro call depth limit
-                maxCallDepth = rsvc.getInt(RuntimeConstants.VM_MAX_DEPTH);
-
-                // initialize the parsed AST
-                // since this is context independent we need to do this only once so
-                // do it here instead of the render method
-                nodeTree.init(context, rs);
-
-                preInit = true;
-            }
-        }
+        rsvc = rs;
+      
+        // this is a very expensive call (ExtendedProperties is very slow)
+        strictArguments = rs.getConfiguration().getBoolean(
+            RuntimeConstants.VM_ARGUMENTS_STRICT, false);
+
+        // support for local context scope feature, where all references are local
+        // we do not have to check this at every invocation of ProxyVMContext
+        localContextScope = rsvc.getBoolean(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, false);
 
+        // get the macro call depth limit
+        maxCallDepth = rsvc.getInt(RuntimeConstants.VM_MAX_DEPTH);
+    }
+    
+    /**
+     * check if we are calling this macro with the right number of arguments.  If 
+     * we are not, and strictArguments is active, then throw TemplateInitException.
+     * This method must be thread safe.
+     */
+    public void checkArgs(InternalContextAdapter context, Node node)
+    {
         // check how many arguments we got
         int i = node.jjtGetNumChildren();
 



Mime
View raw message