Anonymous avatar Anonymous committed 4195bf9

Issue number: XW-179
Submitted by: Craig Raw
Reviewed by: Mark Woon

Patch applied.

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

Comments (0)

Files changed (1)

src/java/com/opensymphony/xwork/util/OgnlUtil.java

  * Utility class that provides common access to the Ognl APIs for
  * setting and getting properties from objects (usually Actions).
  *
- * @author $Author$
- * @version $Revision$
+ * @author Jason Carreira
  */
 public class OgnlUtil {
     //~ Static fields/initializers /////////////////////////////////////////////
     }
 
     public static Object compile(String expression) throws OgnlException {
-        Object o = null;
-
-        o = expressions.get(expression);
+        Object o = expressions.get(expression);
 
         if (o == null) {
             o = Ognl.parseExpression(expression);
         Map contextTo = Ognl.createDefaultContext(to);
         Ognl.setTypeConverter(contextTo, XWorkConverter.getInstance());
 
-        BeanInfo beanInfoFrom = null;
+        BeanInfo beanInfoFrom;
+        BeanInfo beanInfoTo;
 
         try {
             beanInfoFrom = Introspector.getBeanInfo(from.getClass(), Object.class);
+            beanInfoTo = Introspector.getBeanInfo(to.getClass(), Object.class);
         } catch (IntrospectionException e) {
             log.error("An error occured", e);
 
             return;
         }
 
-        PropertyDescriptor[] pds = beanInfoFrom.getPropertyDescriptors();
+        PropertyDescriptor[] fromPds = beanInfoFrom.getPropertyDescriptors();
+        PropertyDescriptor[] toPds = beanInfoTo.getPropertyDescriptors();
+        Map toPdHash = new HashMap();
 
-        for (int i = 0; i < pds.length; i++) {
-            PropertyDescriptor pd = pds[i];
+        for (int i = 0; i < toPds.length; i++) {
+            PropertyDescriptor toPd = toPds[i];
+            toPdHash.put(toPd.getName(), toPd);
+        }
 
-            try {
-                Object expr = compile(pd.getName());
-                Object value = Ognl.getValue(expr, contextFrom, from);
-                Ognl.setValue(expr, contextTo, to, value);
-            } catch (OgnlException e) {
-                // ignore, this is OK
+        for (int i = 0; i < fromPds.length; i++) {
+            PropertyDescriptor fromPd = fromPds[i];
+
+            if (fromPd.getReadMethod() != null) {
+                PropertyDescriptor toPd = (PropertyDescriptor) toPdHash.get(fromPd.getName());
+
+                if ((toPd != null) && (toPd.getWriteMethod() != null)) {
+                    try {
+                        Object expr = OgnlUtil.compile(fromPd.getName());
+                        Object value = Ognl.getValue(expr, contextFrom, from);
+                        Ognl.setValue(expr, contextTo, to, value);
+                    } catch (OgnlException e) {
+                        // ignore, this is OK
+                    }
+                }
             }
         }
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.