Commits

Anonymous committed 68159f3

XW-534 (Updgrate Ognl dependency to 2.7 for XWork 1.2.3 release)
- fixed a compilation error due to using some method in OgnlRuntime that doesn't exists
- fixed a bug with special keywords eg. "top" "[1]" to get the top and cut the stack respectively
- added test case for those

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2/src@1681e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits ae9a3e3

Comments (0)

Files changed (2)

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

     private static Map invalidMethods = new HashMap();
 
     public Class getPropertyClass(OgnlContext ognlcontext, Object target, Object name) {
+        //System.out.println("getPropertyClass "+target+"\t"+name);
         CompoundRoot root = (CompoundRoot) target;
 
         if (name instanceof Integer) {
     }
 
     public String getSourceAccessor(OgnlContext ognlcontext, Object target, Object name) {
+        //System.out.println("getSourceAccessor "+target+"\t"+name);
         CompoundRoot root = (CompoundRoot) target;
 
         if (name instanceof Integer) {
                 // ignore, its not a number
             }
 
-            if ("top".equals(name)) {
+            if ("top".equals(beanName)) {
                 return ".get(0)";
             }
 
     }
 
     public String getSourceSetter(OgnlContext ognlcontext, Object target, Object name) {
+        //System.out.println("getSourceSetter "+target+"\t"+name);
         CompoundRoot root = (CompoundRoot) target;
         if (name instanceof String) {
             String beanName = ((String)name).replaceAll("\"", "");
      * @throws OgnlException
      */
     public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
+        //System.out.println("setProperty "+name+"\t"+value);
         CompoundRoot root = (CompoundRoot) target;
         OgnlContext ognlContext = (OgnlContext) context;
 
      * @throws OgnlException
      */
     public Object getProperty(Map context, Object target, Object name) throws OgnlException {
+        //System.out.println("getProperty "+name);
         CompoundRoot root = (CompoundRoot) target;
         OgnlContext ognlContext = (OgnlContext) context;
 
 
             if ((argTypes == null) || !invalidMethods.containsKey(mc)) {
                 try {
-                    Object value = OgnlRuntime.callMethod((OgnlContext) context, o, name, objects);
+                    Object value = OgnlRuntime.callMethod((OgnlContext) context, o, name, name, objects);
 
                     if (value != null) {
                         return value;

File test/com/opensymphony/xwork/util/CompoundRootPropertyAccessorTest.java

         }
     }
 
+
+    public void testSpecialExpression() throws Exception {
+        Person p1 = new Person();
+        p1.setName("tmjee");
+        p1.setAge(new Integer(28));
+
+        Address a1 = new Address();
+        a1.setStreet("High Street");
+        a1.setPobox("1111");
+
+        Person p2 = new Person();
+        p2.setName("phil");
+        p2.setAge(new Integer(40));
+
+        Address a2 = new Address();
+        a2.setStreet("Melbourne Street");
+        a2.setPobox("222");
+
+
+        CompoundRoot root = new CompoundRoot();
+        root.add(p1);
+        root.add(a1);
+        root.add(p2);
+        root.add(a2);
+
+        OgnlContext ognlContext = (OgnlContext) Ognl.createDefaultContext(root);
+
+        CompoundRootAccessor accessor = new CompoundRootAccessor();
+
+        OgnlRuntime.setPropertyAccessor(CompoundRoot.class, accessor);
+
+        {
+            Node node = Ognl.compileExpression(ognlContext, root, "top");
+            assertEquals(node.getAccessor().get(ognlContext, root), p1);
+        }
+
+        {
+            Node node = Ognl.compileExpression(ognlContext, root, "[1]");
+            assertEquals(node.getAccessor().get(ognlContext, root).getClass(), CompoundRoot.class);
+            assertEquals(((CompoundRoot)node.getAccessor().get(ognlContext, root)).size(), 3);
+            assertEquals(((CompoundRoot)node.getAccessor().get(ognlContext, root)).get(0), a1);
+            assertEquals(((CompoundRoot)node.getAccessor().get(ognlContext, root)).get(1), p2);
+            assertEquals(((CompoundRoot)node.getAccessor().get(ognlContext, root)).get(2), a2);
+        }
+
+
+    }
+
 }