Commits

plightbo  committed 87ae87d

turned off the evaluation tracing a implemented our own (better, smaller) system for type conversion

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

  • Participants
  • Parent commits e197b56

Comments (0)

Files changed (3)

File src/java/com/opensymphony/xwork/util/CompoundRootAccessor.java

                 try {
                     if ((OgnlRuntime.hasGetProperty(ognlContext, o, name)) || ((o instanceof Map) && ((Map) o).containsKey(name))) {
                         Object value = OgnlRuntime.getProperty(ognlContext, o, name);
-
-                        //Ognl.getValue(OgnlUtil.compile((String) name), context, o);
-                        Evaluation currentEvaluation = ognlContext.getCurrentEvaluation();
-
-                        SimpleNode node = currentEvaluation.getNode();
-                        currentEvaluation.setSource(o);
-                        ognlContext.pushEvaluation(new Evaluation(node, o));
-
                         return value;
                     }
                 } catch (OgnlException e) {

File src/java/com/opensymphony/xwork/util/OgnlValueStack.java

 package com.opensymphony.xwork.util;
 
 import com.opensymphony.xwork.DefaultTextProvider;
-import ognl.Ognl;
-import ognl.OgnlContext;
-import ognl.OgnlException;
-import ognl.OgnlRuntime;
+import ognl.*;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import java.io.Serializable;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
 
 
 /**
     static {
         accessor = new CompoundRootAccessor();
         OgnlRuntime.setPropertyAccessor(CompoundRoot.class, accessor);
+        OgnlRuntime.setPropertyAccessor(Object.class, new ObjectAccessor());
         OgnlRuntime.setPropertyAccessor(Iterator.class, new XWorkIteratorPropertyAccessor());
         OgnlRuntime.setPropertyAccessor(Enumeration.class, new XWorkEnumerationAcccessor());
         OgnlRuntime.setMethodAccessor(Object.class, new XWorkMethodAccessor());
         OgnlRuntime.setNullHandler(Object.class, new InstantiatingNullHandler());
     }
 
+    public static class ObjectAccessor extends ObjectPropertyAccessor {
+        public Object getProperty(Map map, Object o, Object o1) throws OgnlException {
+            Object obj = super.getProperty(map, o, o1);
+            link(map, o.getClass(), (String) o1);
+            return obj;
+        }
+
+        public void setProperty(Map map, Object o, Object o1, Object o2) throws OgnlException {
+            super.setProperty(map, o, o1, o2);
+        }
+    }
+
+    public static void link(Map context, Class clazz, String name) {
+        List link = (List) context.get("__link");
+        if (link == null) {
+            link = new ArrayList(3);
+            context.put("__link", link);
+        }
+
+        link.add(new Object[] { clazz, name });
+    }
+
     //~ Instance fields ////////////////////////////////////////////////////////
 
     CompoundRoot root;
         this.context = Ognl.createDefaultContext(this.root, accessor, XWorkConverter.getInstance());
         context.put(VALUE_STACK, this);
         Ognl.setClassResolver(context, accessor);
-        ((OgnlContext) context).setTraceEvaluations(true);
-        ((OgnlContext) context).setKeepLastEvaluation(true);
+        ((OgnlContext) context).setTraceEvaluations(false);
+        ((OgnlContext) context).setKeepLastEvaluation(false);
     }
 
     private Object readResolve() {

File src/java/com/opensymphony/xwork/util/XWorkConverter.java

     }
 
     private Object[] getClassProperty(Map context) {
-        Object[] classProp = null;
-        OgnlContext ognlContext = (OgnlContext) context;
-        Evaluation eval = ognlContext.getCurrentEvaluation();
-
-        if (eval == null) {
-            eval = ognlContext.getLastEvaluation();
-        }
-
-        if ((eval != null) && (eval.getLastChild() != null)) {
-            classProp = new Object[2];
-
-            // since we changed what the source was (tricked Ognl essentially)
-            if ((eval.getLastChild().getLastChild() != null) && (eval.getLastChild().getLastChild().getSource() != null) && (eval.getLastChild().getLastChild().getSource().getClass() != CompoundRoot.class)) {
-                classProp[0] = eval.getLastChild().getLastChild().getSource().getClass();
-            } else {
-                classProp[0] = eval.getLastChild().getSource().getClass();
-            }
-
-            // ugly hack getting the property, but it works
-            String property = eval.getNode().jjtGetChild(eval.getNode().jjtGetNumChildren() - 1).toString();
-
-            if (property.startsWith("\"") && property.endsWith("\"")) {
-                property = property.substring(1, property.length() - 1);
-            }
-
-            classProp[1] = property;
+        List link = (List) context.get("__link");
+        if (link == null || link.isEmpty()) {
+            return null;
         }
 
-        return classProp;
+        return (Object[]) link.get(link.size() - 1);
     }
 
     private Object acceptableErrorValue(Class toClass) {