Commits

Anonymous committed 52ecc42

XW-703 Add a flag to disabled OGNL expression cache

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@2001e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 83432cd

Comments (0)

Files changed (3)

File core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java

                .factory(XWorkBasicConverter.class, Scope.SINGLETON);
         props.setProperty("devMode", Boolean.FALSE.toString());
         props.setProperty("logMissingProperties", Boolean.FALSE.toString());
+        props.setProperty("enableOGNLExpressionCache", Boolean.TRUE.toString());
     }
 
 }

File core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java

 
     private TypeConverter defaultConverter;
     static boolean devMode = false;
+    static boolean enableExpressionCache = true;
 
     @Inject
     public void setXWorkConverter(XWorkConverter conv) {
     public static void setDevMode(String mode) {
         devMode = "true".equals(mode);
     }
-    
+
+    @Inject("enableOGNLExpressionCache")
+    public static void setEnableExpressionCache(String cache) {
+       enableExpressionCache = "true".equals(cache);
+    }
+
     /**
      * Sets the object's properties using the default type converter, defaulting to not throw
      * exceptions for problems setting the properties.
 
 
     public Object compile(String expression) throws OgnlException {
-        Object o = expressions.get(expression);
-        if (o == null) {
-            o = Ognl.parseExpression(expression);
-            expressions.put(expression, o);
-        }
-        return o;
+        if (enableExpressionCache) {
+            Object o = expressions.get(expression);
+            if (o == null) {
+                o = Ognl.parseExpression(expression);
+                expressions.put(expression, o);
+            }
+            return o;
+        } else
+            return Ognl.parseExpression(expression);
     }
 
     /**

File core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java

         assertEquals(dogName, owner.getDog().getName());
     }
 
+    public void testCacheEnabled() throws OgnlException {
+        OgnlUtil.setEnableExpressionCache("true");
+        Object expr0 = ognlUtil.compile("test");
+        Object expr2 = ognlUtil.compile("test");
+        assertSame(expr0, expr2);
+    }
+
+     public void testCacheDisabled() throws OgnlException {
+        OgnlUtil.setEnableExpressionCache("false");
+        Object expr0 = ognlUtil.compile("test");
+        Object expr2 = ognlUtil.compile("test");
+        assertNotSame(expr0, expr2);
+    }
+
     public void testCanSetDependentObjectArray() {
         EmailAction action = new EmailAction();
         Map<String, Object> context = Ognl.createDefaultContext(action);