Author: byron
Date: Sun Mar  8 15:31:49 2009
New Revision: 751446

URL: http://svn.apache.org/viewvc?rev=751446&view=rev
Log:
Change to dynamic scoping for references

Modified:
    
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/context/ProxyVMContext.java
    
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/issues/Velocity62TestCase.java

Modified: 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/context/ProxyVMContext.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/context/ProxyVMContext.java?rev=751446&r1=751445&r2=751446&view=diff
==============================================================================
--- 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/context/ProxyVMContext.java
 (original)
+++ 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/context/ProxyVMContext.java
 Sun Mar  8 15:31:49 2009
@@ -36,6 +36,8 @@
     
     /** If we are operating in global or localscope */
     boolean localscope = true;
+        
+    private Context globalContext = null;
     
     /**
      * @param context the parent context
@@ -43,10 +45,9 @@
      */
     public ProxyVMContext(InternalContextAdapter context, boolean 
localScopeContext)
     {
-        // By always constructing with the base then calling super methods 
will always
-        // access the global context.
-        super(context.getBaseContext());        
+        super(context);
         localscope = localScopeContext;
+        globalContext = context.getBaseContext();
     }
     
     /**
@@ -61,7 +62,7 @@
         if (localscope)    
           return localcontext.put(key, value);
         else
-          return super.put(key, value);
+          return globalContext.put(key, value);
     }
 
     /**
@@ -71,7 +72,7 @@
     {
         switch (scope)
         {
-            case GLOBAL: return super.put(key, value);
+            case GLOBAL: return globalContext.put(key, value);
             case LOCAL: return localcontext.put(key, value);
             default: return put(key, value);  // DEFAULT scope
         }
@@ -84,7 +85,7 @@
     {
         switch (scope)
         {
-            case GLOBAL: return super.get(key);
+            case GLOBAL: return globalContext.get(key);
             case LOCAL: return localcontext.get(key);
             default: return get(key);  // DEFAULT scope
         }      
@@ -97,7 +98,7 @@
     {
         switch (scope)
         {
-            case GLOBAL: return super.containsKey(key);
+            case GLOBAL: return globalContext.containsKey(key);
             case LOCAL: return localcontext.containsKey(key);
             default: return containsKey(key);  // DEFAULT scope
         }            

Modified: 
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/issues/Velocity62TestCase.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/issues/Velocity62TestCase.java?rev=751446&r1=751445&r2=751446&view=diff
==============================================================================
--- 
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/issues/Velocity62TestCase.java
 (original)
+++ 
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/issues/Velocity62TestCase.java
 Sun Mar  8 15:31:49 2009
@@ -45,7 +45,7 @@
         String template = "#macro( outer )#set( $foo = 'bar' )#inner()#end"+
                           "#macro( inner )$foo#end"+
                           "#inner()#outer()#inner()";
-        assertEvalEquals("foofoofoo", template);
+        assertEvalEquals("foobarfoo", template);
     }
 
     public void testRecursive()


Reply via email to