Author: mcucchiara
Date: Sat Oct 29 05:44:09 2011
New Revision: 1190758

URL: http://svn.apache.org/viewvc?rev=1190758&view=rev
Log:
OGNL-31 - CPD fix to ASTProperty (contributed by Adrian Cumiskey)

Modified:
    
commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java

Modified: 
commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java
URL: 
http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java?rev=1190758&r1=1190757&r2=1190758&view=diff
==============================================================================
--- 
commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java
 (original)
+++ 
commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java
 Sat Oct 29 05:44:09 2011
@@ -254,32 +254,7 @@ public class ASTProperty
 
             String name = ( (ASTConst) _children[0] ).getValue().toString();
 
-            if ( !Iterator.class.isAssignableFrom( 
context.getCurrentObject().getClass() )
-                || ( Iterator.class.isAssignableFrom( 
context.getCurrentObject().getClass() ) 
-                     && name.indexOf( "next" ) < 0 ) )
-            {
-                Object currObj = target;
-
-                try
-                {
-                    target = getValue( context, context.getCurrentObject() );
-                }
-                catch ( NoSuchPropertyException e )
-                {
-                    try
-                    {
-                        target = getValue( context, context.getRoot() );
-                    }
-                    catch ( NoSuchPropertyException ex )
-                    {
-                        // ignore
-                    }
-                }
-                finally
-                {
-                    context.setCurrentObject( currObj );
-                }
-            }
+            target = getTarget( context, target, name );
 
             PropertyDescriptor pd = OgnlRuntime.getPropertyDescriptor( 
context.getCurrentObject().getClass(), name );
 
@@ -411,6 +386,39 @@ public class ASTProperty
         return result;
     }
 
+    Object getTarget( OgnlContext context, Object target, String name )
+        throws OgnlException
+    {
+        Class<? extends Object> clazz = context.getCurrentObject().getClass();
+        if ( !Iterator.class.isAssignableFrom(clazz)
+            || ( Iterator.class.isAssignableFrom(clazz)
+                 && name.indexOf( "next" ) < 0 ) )
+        {
+            Object currObj = target;
+
+            try
+            {
+                target = getValue( context, context.getCurrentObject() );
+            }
+            catch ( NoSuchPropertyException e )
+            {
+                try
+                {
+                    target = getValue( context, context.getRoot() );
+                }
+                catch ( NoSuchPropertyException ex )
+                {
+                    // ignore
+                }
+            }
+            finally
+            {
+                context.setCurrentObject( currObj );
+            }
+        }
+        return target;
+    }
+
     Method getIndexedWriteMethod( PropertyDescriptor pd )
     {
         if ( IndexedPropertyDescriptor.class.isInstance( pd ) )
@@ -565,36 +573,7 @@ public class ASTProperty
             // System.out.println(" astprop(setter) : trying to set " + name + 
" on object target " +
             // context.getCurrentObject().getClass().getName());
 
-            if ( !Iterator.class.isAssignableFrom( 
context.getCurrentObject().getClass() )
-                || ( Iterator.class.isAssignableFrom( 
context.getCurrentObject().getClass() ) 
-                     && name.indexOf( "next" ) < 0 ) )
-            {
-
-                Object currObj = target;
-
-                try
-                {
-                    target = getValue( context, context.getCurrentObject() );
-                }
-                catch ( NoSuchPropertyException e )
-                {
-                    try
-                    {
-
-                        target = getValue( context, context.getRoot() );
-
-                    }
-                    catch ( NoSuchPropertyException ex )
-                    {
-                        // TODO: how to handle this accordingly?
-                    }
-                }
-                finally
-                {
-
-                    context.setCurrentObject( currObj );
-                }
-            }
+            target = getTarget( context, target, name );
 
             PropertyDescriptor pd =
                 OgnlRuntime.getPropertyDescriptor( 


Reply via email to