commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1220681 [2/2] - in /commons/proper/jexl/trunk: ./ src/main/java/org/apache/commons/jexl3/ src/main/java/org/apache/commons/jexl3/internal/ src/main/java/org/apache/commons/jexl3/internal/introspection/ src/main/java/org/apache/commons/jexl...
Date Mon, 19 Dec 2011 10:43:36 GMT
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java Mon Dec 19 10:43:35 2011
@@ -19,9 +19,9 @@ package org.apache.commons.jexl3.interna
 
 import java.util.Map;
 
- /**
+/**
  * Specialized executor to get a property from a Map.
-  * @since 2.0
+ * @since 2.0
  */
 public final class MapGetExecutor extends AbstractExecutor.Get {
     /** The java.util.map.get method used as an active marker in MapGet. */
@@ -31,53 +31,54 @@ public final class MapGetExecutor extend
     private final Object property;
 
     /**
-     * Creates an instance checking for the Map interface.
+     * Attempts to discover a MapGetExecutor.
+     * 
      * @param is the introspector
-     * @param clazz the class that might implement the map interface
-     * @param key the key to use in map.get(key)
+     * @param clazz the class to find the get method from
+     * @param identifier the key to use as an argument to the get method
+     * @return the executor if found, null otherwise
      */
-    public MapGetExecutor(Introspector is, Class<?> clazz, Object key) {
-        super(clazz, discover(clazz));
+    public static MapGetExecutor discover(Introspector is, Class<?> clazz, Object identifier) {
+        if (Map.class.isAssignableFrom(clazz)) {
+            return new MapGetExecutor(clazz, MAP_GET, identifier);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Creates an instance.
+     * @param clazz he class the get method applies to
+     * @param method the method held by this executor
+     * @param key the property to get
+     */
+    private MapGetExecutor(Class<?> clazz, java.lang.reflect.Method method, Object key) {
+        super(clazz, method);
         property = key;
     }
 
-    /** {@inheritDoc} */
     @Override
     public Object getTargetProperty() {
         return property;
     }
-    
-    /**
-     * Get the property from the map.
-     * @param obj the map.
-     * @return map.get(property)
-     */
+
+
     @Override
-    public Object execute(final Object obj) {
+    public Object invoke(final Object obj) {
         @SuppressWarnings("unchecked") // ctor only allows Map instances - see discover() method
-        final Map<Object,?> map = (Map<Object, ?>) obj;
+        final Map<Object, ?> map = (Map<Object, ?>) obj;
         return map.get(property);
     }
 
-    /** {@inheritDoc} */
     @Override
-    public Object tryExecute(final Object obj, Object key) {
-        if (obj != null &&  method != null
-            && objectClass.equals(obj.getClass())
-            && (key == null || property.getClass().equals(key.getClass()))) {
+    public Object tryInvoke(final Object obj, Object key) {
+        if (obj != null && method != null
+                && objectClass.equals(obj.getClass())
+                && (key == null || property.getClass().equals(key.getClass()))) {
             @SuppressWarnings("unchecked") // ctor only allows Map instances - see discover() method
-            final Map<Object,?> map = (Map<Object, ?>) obj;
+            final Map<Object, ?> map = (Map<Object, ?>) obj;
             return map.get(key);
         }
         return TRY_FAILED;
     }
-
-    /**
-     * Finds the method to perform 'get' on a map.
-     * @param clazz the class to introspect
-     * @return a marker method, map.get
-     */
-    static java.lang.reflect.Method discover(Class<?> clazz) {
-        return (Map.class.isAssignableFrom(clazz))? MAP_GET : null;
-    }
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java Mon Dec 19 10:43:35 2011
@@ -30,36 +30,48 @@ public final class MapSetExecutor extend
     private final Object property;
 
     /**
-     * Creates an instance checking for the Map interface.
-     *@param is the introspector
-     *@param clazz the class that might implement the map interface
-     *@param key the key to use as argument in map.put(key,value)
-     *@param value the value to use as argument in map.put(key,value)
-    */
-    public MapSetExecutor(Introspector is, Class<?> clazz, Object key, Object value) {
-        super(clazz, discover(clazz));
+     * Attempts to discover a MapSetExecutor.
+     * 
+     * @param is the introspector
+     * @param clazz the class to find the set method from
+     * @param identifier the key to use as an argument to the get method
+     * @param value the value to use as argument in map.put(key,value)
+     * @return the executor if found, null otherwise
+     */
+    public static MapSetExecutor discover(Introspector is, Class<?> clazz, Object identifier, Object value) {
+        if (Map.class.isAssignableFrom(clazz)) {
+            return new MapSetExecutor(clazz, MAP_SET, identifier);
+        } else {
+            return null;
+        }
+    }
+    
+    /**
+     * Creates an instance.
+     * @param clazz the class the set method applies to
+     * @param method the method called through this executor
+     * @param key the key to use as 1st argument to the set method
+     */
+    private MapSetExecutor(Class<?> clazz, java.lang.reflect.Method method, Object key) {
+        super(clazz, method);
         property = key;
     }
 
-    /** {@inheritDoc} */
     @Override
     public Object getTargetProperty() {
         return property;
     }
     
-    /** {@inheritDoc} */
     @Override
-    public Object execute(final Object obj, Object value)
-    throws IllegalAccessException, InvocationTargetException {
+    public Object invoke(final Object obj, Object value) throws IllegalAccessException, InvocationTargetException {
         @SuppressWarnings("unchecked") // ctor only allows Map instances - see discover() method
         final Map<Object,Object> map = ((Map<Object, Object>) obj);
         map.put(property, value);
         return value;
     }
 
-    /** {@inheritDoc} */
     @Override
-    public Object tryExecute(final Object obj, Object key, Object value) {
+    public Object tryInvoke(final Object obj, Object key, Object value) {
         if (obj != null && method != null
             && objectClass.equals(obj.getClass())
             && (key == null || property.getClass().equals(key.getClass()))) {
@@ -70,13 +82,4 @@ public final class MapSetExecutor extend
         }
         return TRY_FAILED;
     }
-
-    /**
-     * Finds the method to perform 'set' on a map.
-     * @param clazz the class to introspect
-     * @return a marker method, map.get
-     */
-    static java.lang.reflect.Method discover(Class<?> clazz) {
-        return (Map.class.isAssignableFrom(clazz))? MAP_SET : null;
-    }
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java Mon Dec 19 10:43:35 2011
@@ -26,29 +26,51 @@ import java.lang.reflect.InvocationTarge
 public final class MethodExecutor extends AbstractExecutor.Method {
     /** Whether this method handles varargs. */
     private final boolean isVarArgs;
+    
+    
     /**
-     * Creates a new instance.
+     * Discovers a {@link MethodExecutor}.
+     * <p>
+     * If the object is an array, an attempt will be made to find the
+     * method in a List (see {@link ArrayListWrapper})
+     * </p>
+     * <p>
+     * If the object is a class, an attempt will be made to find the
+     * method as a static method of that class.
+     * </p>
      * @param is the introspector used to discover the method
-     * @param obj the object to find the method in
-     * @param name the method name
+     * @param obj the object to introspect
+     * @param method the name of the method to find
      * @param args the method arguments
+     * @return a filled up parameter (may contain a null method)
      */
-    public MethodExecutor(Introspector is, Object obj, String name, Object[] args) {
-        super(obj.getClass(), discover(is, obj, name, args));
-        isVarArgs = method != null && isVarArgMethod(method);
+    public static MethodExecutor discover(Introspector is, Object obj, String method, Object[] args) {
+        final Class<?> clazz = obj.getClass();
+        final MethodKey key = new MethodKey(method, args);
+        java.lang.reflect.Method m = is.getMethod(clazz, key);
+        if (m == null && clazz.isArray()) {
+            // check for support via our array->list wrapper
+            m = is.getMethod(ArrayListWrapper.class, key);
+        }
+        if (m == null && obj instanceof Class<?>) {
+            m = is.getMethod((Class<?>) obj, key);
+        }
+        return m == null? null : new MethodExecutor(clazz, m, key);
     }
 
     /**
-     * Invokes the method to be executed.
-     * @param o the object to invoke the method upon
-     * @param args the method arguments
-     * @return the result of the method invocation
-     * @throws IllegalAccessException Method is inaccessible.
-     * @throws InvocationTargetException Method body throws an exception.
+     * Creates a new instance.
+     * @param c the class this executor applies to
+     * @param m the method
+     * @param k the MethodKey
      */
+    private MethodExecutor(Class<?> c, java.lang.reflect.Method m, MethodKey k) {
+        super(c, m, k);
+        isVarArgs = method != null && isVarArgMethod(method);
+    }
+
     @Override
-    public Object execute(Object o, Object[] args)
-        throws IllegalAccessException, InvocationTargetException  {
+    public Object invoke(Object o, Object[] args) throws IllegalAccessException, InvocationTargetException  {
         if (isVarArgs) {
             Class<?>[] formal = method.getParameterTypes();
             int index = formal.length - 1;
@@ -64,15 +86,14 @@ public final class MethodExecutor extend
         }
     }
 
-    /** {@inheritDoc} */
     @Override
-    public Object tryExecute(String name, Object obj, Object[] args) {
+    public Object tryInvoke(String name, Object obj, Object[] args) {
         MethodKey tkey = new MethodKey(name, args);
         // let's assume that invocation will fly if the declaring class is the
         // same and arguments have the same type
         if (objectClass.equals(obj.getClass()) && tkey.equals(key)) {
             try {
-                return execute(obj, args);
+                return invoke(obj, args);
             } catch (InvocationTargetException xinvoke) {
                 return TRY_FAILED; // fail
             } catch (IllegalAccessException xill) {
@@ -84,37 +105,6 @@ public final class MethodExecutor extend
 
 
     /**
-     * Discovers a method for a {@link MethodExecutor}.
-     * <p>
-     * If the object is an array, an attempt will be made to find the
-     * method in a List (see {@link ArrayListWrapper})
-     * </p>
-     * <p>
-     * If the object is a class, an attempt will be made to find the
-     * method as a static method of that class.
-     * </p>
-     * @param is the introspector used to discover the method
-     * @param obj the object to introspect
-     * @param method the name of the method to find
-     * @param args the method arguments
-     * @return a filled up parameter (may contain a null method)
-     */
-    private static Parameter discover(Introspector is,
-            Object obj, String method, Object[] args) {
-        final Class<?> clazz = obj.getClass();
-        final MethodKey key = new MethodKey(method, args);
-        java.lang.reflect.Method m = is.getMethod(clazz, key);
-        if (m == null && clazz.isArray()) {
-            // check for support via our array->list wrapper
-            m = is.getMethod(ArrayListWrapper.class, key);
-        }
-        if (m == null && obj instanceof Class<?>) {
-            m = is.getMethod((Class<?>) obj, key);
-        }
-        return new Parameter(m, key);
-    }
-
-    /**
      * Reassembles arguments if the method is a vararg method.
      * @param type   The vararg class type (aka component type
      *               of the expected array arg)
@@ -125,7 +115,7 @@ public final class MethodExecutor extend
      * @return The actual parameters adjusted for the varargs in order
      * to fit the method declaration.
      */
-    protected Object[] handleVarArg(Class<?> type, int index, Object[] actual) {
+    private Object[] handleVarArg(Class<?> type, int index, Object[] actual) {
         final int size = actual.length - index;
         // if no values are being passed into the vararg, size == 0
         if (size == 1) {

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java Mon Dec 19 10:43:35 2011
@@ -23,7 +23,6 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -224,7 +223,7 @@ public final class MethodKey {
      * @return the most specific method.
      * @throws MethodKey.AmbiguousException if there is more than one.
      */
-    public Method getMostSpecificMethod(List<Method> methods) {
+    public Method getMostSpecificMethod(Method[] methods) {
         return METHODS.getMostSpecific(methods, params);
     }
 
@@ -234,7 +233,7 @@ public final class MethodKey {
      * @return the most specific constructor.
      * @throws MethodKey.AmbiguousException if there is more than one.
      */
-    public Constructor<?> getMostSpecificConstructor(List<Constructor<?>> methods) {
+    public Constructor<?> getMostSpecificConstructor(Constructor<?>[] methods) {
         return CONSTRUCTORS.getMostSpecific(methods, params);
     }
 
@@ -445,7 +444,7 @@ public final class MethodKey {
          * @return the most specific method.
          * @throws MethodKey.AmbiguousException if there is more than one.
          */
-        private T getMostSpecific(List<T> methods, Class<?>[] classes) {
+        private T getMostSpecific(T[] methods, Class<?>[] classes) {
             LinkedList<T> applicables = getApplicables(methods, classes);
 
             if (applicables.isEmpty()) {
@@ -583,11 +582,9 @@ public final class MethodKey {
          *         formal and actual arguments matches, and argument types are assignable
          *         to formal types through a method invocation conversion).
          */
-        private LinkedList<T> getApplicables(List<T> methods, Class<?>[] classes) {
+        private LinkedList<T> getApplicables(T[] methods, Class<?>[] classes) {
             LinkedList<T> list = new LinkedList<T>();
-
-            for (Iterator<T> imethod = methods.iterator(); imethod.hasNext();) {
-                T method = imethod.next();
+            for (T method : methods) {
                 if (isApplicable(method, classes)) {
                     list.add(method);
                 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertyGetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertyGetExecutor.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertyGetExecutor.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertyGetExecutor.java Mon Dec 19 10:43:35 2011
@@ -29,34 +29,45 @@ public final class PropertyGetExecutor e
     private final String property;
     
     /**
-     * Creates an instance by attempting discovery of the get method.
+     * Discovers a PropertyGetExecutor.
+     * <p>The method to be found should be named "get{P,p}property.</p>
+     * 
      * @param is the introspector
-     * @param clazz the class to introspect
+     * @param clazz the class to find the get method from
+     * @param property the property name to find
+     * @return the executor if found, null otherwise
+     */
+    public static PropertyGetExecutor discover(Introspector is, Class<?> clazz, String property) {
+        java.lang.reflect.Method method = discoverGet(is, "get", clazz, property);
+        return method == null? null : new PropertyGetExecutor(clazz, method, property);
+    }
+    
+    /**
+     * Creates an instance.
+     * @param clazz he class the get method applies to
+     * @param method the method held by this executor
      * @param identifier the property to get
      */
-    public PropertyGetExecutor(Introspector is, Class<?> clazz, String identifier) {
-        super(clazz, discover(is, clazz, identifier));
+    private PropertyGetExecutor(Class<?> clazz, java.lang.reflect.Method method, String identifier) {
+        super(clazz, method);
         property = identifier;
     }
 
-    /** {@inheritDoc} */
     @Override
     public Object getTargetProperty() {
         return property;
     }
     
-    /** {@inheritDoc} */
     @Override
-    public Object execute(Object o)
+    public Object invoke(Object o)
         throws IllegalAccessException, InvocationTargetException {
         return method == null ? null : method.invoke(o, (Object[]) null);
     }
 
-    /** {@inheritDoc} */
     @Override
-    public Object tryExecute(Object o, Object identifier) {
+    public Object tryInvoke(Object o, Object identifier) {
         if (o != null && method !=  null
-            && property.equals(identifier)
+            && property.equals(toString(identifier))
             && objectClass.equals(o.getClass())) {
             try {
                 return method.invoke(o, (Object[]) null);
@@ -70,20 +81,6 @@ public final class PropertyGetExecutor e
     }
 
     /**
-     * Discovers the method for a {@link PropertyGet}.
-     * <p>The method to be found should be named "get{P,p}property.</p>
-     *@param is the introspector
-     *@param clazz the class to find the get method from
-     *@param property the property name to find
-     *@return the method if found, null otherwise
-     */
-    static java.lang.reflect.Method discover(Introspector is,
-            final Class<?> clazz, String property) {
-        return discoverGet(is, "get", clazz, property);
-    }
-
-
-    /**
      * Base method for boolean & object property get.
      * @param is the introspector
      * @param which "is" or "get" for boolean or object
@@ -91,8 +88,7 @@ public final class PropertyGetExecutor e
      * @param property The property being addressed.
      * @return The {get,is}{p,P}roperty method if one exists, null otherwise.
      */
-    static java.lang.reflect.Method discoverGet(Introspector is,
-            String which, Class<?> clazz, String property) {
+    static java.lang.reflect.Method discoverGet(Introspector is, String which, Class<?> clazz, String property) {
         //  this is gross and linear, but it keeps it straightforward.
         java.lang.reflect.Method method = null;
         final int start = which.length(); // "get" or "is" so 3 or 2 for char case switch

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java Mon Dec 19 10:43:35 2011
@@ -27,30 +27,41 @@ public final class PropertySetExecutor e
     private static final int SET_START_INDEX = 3;
     /** The property. */
     private final String property;
-
+    
     /**
-     * Creates an instance by attempting discovery of the set method.
+     * Discovers a PropertySetExecutor.
+     * <p>The method to be found should be named "set{P,p}property.</p>
+     * 
      * @param is the introspector
-     * @param clazz the class to introspect
-     * @param identifier the property to set
-     * @param arg the value to set into the property
+     * @param clazz the class to find the get method from
+     * @param property the property name to find
+     * @param arg the value to assign to the property
+     * @return the executor if found, null otherwise
      */
-    public PropertySetExecutor(Introspector is, Class<?> clazz, String identifier, Object arg) {
-        super(clazz, discover(is, clazz, identifier, arg));
-        property = identifier;
+    public static PropertySetExecutor discover(Introspector is, Class<?> clazz, String property, Object arg) {
+        java.lang.reflect.Method method = discoverSet(is, clazz, property, arg);
+        return method == null? null : new PropertySetExecutor(clazz, method, property);
+    }
+    
+    /**
+     * Creates an instance.
+     * @param clazz the class the set method applies to
+     * @param method the method called through this executor
+     * @param key the key to use as 1st argument to the set method
+     */
+    private PropertySetExecutor(Class<?> clazz, java.lang.reflect.Method method, String key) {
+        super(clazz, method);
+        property = key;
 
     }
 
-    /** {@inheritDoc} */
     @Override
     public Object getTargetProperty() {
         return property;
     }
 
-    /** {@inheritDoc} */
     @Override
-    public Object execute(Object o, Object arg)
-            throws IllegalAccessException, InvocationTargetException {
+    public Object invoke(Object o, Object arg) throws IllegalAccessException, InvocationTargetException {
         Object[] pargs = {arg};
         if (method != null) {
             method.invoke(o, pargs);
@@ -58,18 +69,17 @@ public final class PropertySetExecutor e
         return arg;
     }
 
-    /** {@inheritDoc} */
     @Override
-    public Object tryExecute(Object o, Object identifier, Object arg) {
+    public Object tryInvoke(Object o, Object identifier, Object arg) {
         if (o != null && method != null
             // ensure method name matches the property name
-            && property.equals(identifier)
+            && property.equals(toString(identifier))
             // object class should be same as executor's method declaring class
             && objectClass.equals(o.getClass())
             // we are guaranteed the method has one parameter since it is a set(x)
             && (arg == null || method.getParameterTypes()[0].equals(arg.getClass()))) {
             try {
-                return execute(o, arg);
+                return invoke(o, arg);
             } catch (InvocationTargetException xinvoke) {
                 return TRY_FAILED; // fail
             } catch (IllegalAccessException xill) {
@@ -83,14 +93,14 @@ public final class PropertySetExecutor e
     /**
      * Discovers the method for a {@link PropertySet}.
      * <p>The method to be found should be named "set{P,p}property.</p>
-     *@param is the introspector
-     *@param clazz the class to find the get method from
-     *@param property the name of the property to set
-     *@param arg the value to assign to the property
-     *@return the method if found, null otherwise
+     * 
+     * @param is the introspector
+     * @param clazz the class to find the get method from
+     * @param property the name of the property to set
+     * @param arg the value to assign to the property
+     * @return the method if found, null otherwise
      */
-    private static java.lang.reflect.Method discover(Introspector is,
-            final Class<?> clazz, String property, Object arg) {
+    private static java.lang.reflect.Method discoverSet(Introspector is, Class<?> clazz, String property, Object arg) {
         // first, we introspect for the set<identifier> setter method
         Object[] params = {arg};
         StringBuilder sb = new StringBuilder("set");
@@ -104,7 +114,6 @@ public final class PropertySetExecutor e
             sb.setCharAt(SET_START_INDEX, Character.toLowerCase(c));
             method = is.getMethod(clazz, sb.toString(), params);
         }
-
         return method;
     }
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java Mon Dec 19 10:43:35 2011
@@ -17,7 +17,6 @@
 package org.apache.commons.jexl3.internal.introspection;
 
 import java.util.Iterator;
-import org.apache.commons.jexl3.JexlInfoHandle;
 import org.apache.commons.jexl3.introspection.JexlMethod;
 import org.apache.commons.jexl3.introspection.JexlPropertyGet;
 import org.apache.commons.jexl3.introspection.JexlPropertySet;
@@ -54,7 +53,7 @@ public final class SandboxUberspect impl
      * {@inheritDoc}
      */
     @Override
-    public JexlMethod getConstructor(Object ctorHandle, Object[] args, JexlInfoHandle info) {
+    public JexlMethod getConstructor(Object ctorHandle, Object[] args) {
         final String className;
         if (ctorHandle instanceof Class<?>) {
             Class<?> clazz = (Class<?>) ctorHandle;
@@ -65,7 +64,7 @@ public final class SandboxUberspect impl
             return null;
         }
         if (sandbox.execute(className, "") != null) {
-            return uberspect.getConstructor(className, args, info);
+            return uberspect.getConstructor(className, args);
         }
         return null;
     }
@@ -74,11 +73,11 @@ public final class SandboxUberspect impl
      * {@inheritDoc}
      */
     @Override
-    public JexlMethod getMethod(Object obj, String method, Object[] args, JexlInfoHandle info) {
+    public JexlMethod getMethod(Object obj, String method, Object[] args) {
         if (obj != null && method != null) {
             String actual = sandbox.execute(obj.getClass().getName(), method);
             if (actual != null) {
-                return uberspect.getMethod(obj, actual, args, info);
+                return uberspect.getMethod(obj, actual, args);
             }
         }
         return null;
@@ -88,11 +87,11 @@ public final class SandboxUberspect impl
      * {@inheritDoc}
      */
     @Override
-    public JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfoHandle info) {
+    public JexlPropertyGet getPropertyGet(Object obj, Object identifier) {
         if (obj != null && identifier != null) {
             String actual = sandbox.read(obj.getClass().getName(), identifier.toString());
             if (actual != null) {
-                return uberspect.getPropertyGet(obj, actual, info);
+                return uberspect.getPropertyGet(obj, actual);
             }
         }
         return null;
@@ -102,11 +101,11 @@ public final class SandboxUberspect impl
      * {@inheritDoc}
      */
     @Override
-    public JexlPropertySet getPropertySet(final Object obj, final Object identifier, Object arg, JexlInfoHandle info) {
+    public JexlPropertySet getPropertySet(final Object obj, final Object identifier, Object arg) {
         if (obj != null && identifier != null) {
             String actual = sandbox.write(obj.getClass().getName(), identifier.toString());
             if (actual != null) {
-                return uberspect.getPropertySet(obj, actual, arg, info);
+                return uberspect.getPropertySet(obj, actual, arg);
             }
         }
         return null;
@@ -119,7 +118,7 @@ public final class SandboxUberspect impl
     }
 
     @Override
-    public Iterator<?> getIterator(Object obj, JexlInfoHandle info) {
-        return uberspect.getIterator(obj, info);
+    public Iterator<?> getIterator(Object obj) {
+        return uberspect.getIterator(obj);
     }
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java Mon Dec 19 10:43:35 2011
@@ -16,26 +16,19 @@
  */
 package org.apache.commons.jexl3.internal.introspection;
 
-import java.beans.IntrospectionException;
 import java.lang.ref.SoftReference;
-import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.InvocationTargetException;
 
 import java.lang.reflect.Method;
-import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.Map;
 
-import org.apache.commons.jexl3.JexlInfo;
-import org.apache.commons.jexl3.JexlException;
-import org.apache.commons.jexl3.JexlInfoHandle;
 import org.apache.commons.jexl3.introspection.JexlMethod;
 import org.apache.commons.jexl3.introspection.JexlPropertyGet;
 import org.apache.commons.jexl3.introspection.JexlPropertySet;
 import org.apache.commons.jexl3.introspection.JexlUberspect;
+
 import org.apache.commons.logging.Log;
 
 /**
@@ -50,39 +43,20 @@ public class Uberspect implements JexlUb
      * Publicly exposed special failure object returned by tryInvoke.
      */
     public static final Object TRY_FAILED = AbstractExecutor.TRY_FAILED;
-/** The logger to use for all warnings & errors. */
+    /** The logger to use for all warnings & errors. */
     protected final Log rlog;
     /** The soft reference to the introspector currently in use. */
     private volatile SoftReference<Introspector> ref;
 
     /**
-     * Coerce an Object  to an Integer.
-     * @param arg the Object to coerce
-     * @return an Integer if it can be converted, null otherwise
-     */
-    protected Integer toInteger(Object arg) {
-        if (arg == null) {
-            return null;
-        }
-        if (arg instanceof Number) {
-            return Integer.valueOf(((Number) arg).intValue());
-        }
-        try {
-            return Integer.valueOf(arg.toString());
-        } catch (NumberFormatException xnumber) {
-            return null;
-        }
-    }
-
-    /**
-     * Coerce an Object to a String.
-     * @param arg the Object to coerce
-     * @return a String if it can be converted, null otherwise
+     * Creates a new Uberspect.
+     * @param runtimeLogger the logger used for all logging needs
      */
-    protected String toString(Object arg) {
-        return arg == null ? null : arg.toString();
+    public Uberspect(Log runtimeLogger) {
+        rlog = runtimeLogger;
+        ref = new SoftReference<Introspector>(null);
     }
-
+    
     /**
      * Gets the current introspector base.
      * <p>If the reference has been collected, this method will recreate the underlying introspector.</p>
@@ -93,7 +67,7 @@ public class Uberspect implements JexlUb
         Introspector intro = ref.get();
         if (intro == null) {
             // double checked locking is ok (fixed by Java 5 memory model).
-            synchronized(this) {
+            synchronized (this) {
                 intro = ref.get();
                 if (intro == null) {
                     intro = new Introspector(rlog);
@@ -118,7 +92,7 @@ public class Uberspect implements JexlUb
     public final Class<?> getClassByName(String className) {
         return base().getClassByName(className);
     }
-    
+
     /**
      * Gets the field named by <code>key</code> for the class <code>c</code>.
      *
@@ -168,7 +142,6 @@ public class Uberspect implements JexlUb
         return base().getMethod(c, key);
     }
 
-
     /**
      * Gets the accessible methods names known for a given class.
      * @param c the class
@@ -177,7 +150,7 @@ public class Uberspect implements JexlUb
     public final String[] getMethodNames(Class<?> c) {
         return base().getMethodNames(c);
     }
-            
+
     /**
      * Gets all the methods with a given name from this map.
      * @param c the class
@@ -187,158 +160,113 @@ public class Uberspect implements JexlUb
     public final Method[] getMethods(Class<?> c, final String methodName) {
         return base().getMethods(c, methodName);
     }
-    /**
-     * Creates a new UberspectImpl.
-     * @param runtimeLogger the logger used for all logging needs
-     */
-    public Uberspect(Log runtimeLogger) {
-        rlog = runtimeLogger;
-        ref = new SoftReference<Introspector>(null);
-    }
-
-    /**
-     * Resets this Uberspect class loader.
-     * @param cloader the class loader to use
-     */
-    public void setLoader(ClassLoader cloader) {
-        base().setLoader(cloader);
-    }
-
 
-    /**
-     * Returns a general constructor.
-     * @param ctorHandle the object
-     * @param args contructor arguments
-     * @return a {@link java.lang.reflect.Constructor}
-     *  or null if no unambiguous contructor could be found through introspection.
-     */
-    protected final Constructor<?> getConstructor(Object ctorHandle, Object[] args) {
-        String className = null;
-        Class<?> clazz = null;
-        if (ctorHandle instanceof Class<?>) {
-            clazz = (Class<?>) ctorHandle;
-            className = clazz.getName();
-        } else if (ctorHandle != null) {
-            className = ctorHandle.toString();
-        } else {
-            return null;
-        }
-        return base().getConstructor(clazz, new MethodKey(className, args));
-    }
-
-    /**
-     * Returns a general method.
-     * @param obj the object
-     * @param name the method name
-     * @param args method arguments
-     * @return a {@link AbstractExecutor.Method}.
-     */
-    protected final AbstractExecutor.Method getMethodExecutor(Object obj, String name, Object[] args) {
-        AbstractExecutor.Method me = new MethodExecutor(base(), obj, name, args);
-        return me.isAlive() ? me : null;
+    @Override
+    public JexlMethod getMethod(Object obj, String method, Object[] args) {
+        return MethodExecutor.discover(base(), obj, method, args);
     }
 
-    /**
-     * Return a property getter.
-     * @param obj the object to base the property from.
-     * @param identifier property name
-     * @return a {@link AbstractExecutor.Get}.
-     */
-    protected final AbstractExecutor.Get getGetExecutor(Object obj, Object identifier) {
+    @Override
+    public JexlPropertyGet getPropertyGet(Object obj, Object identifier) {
         final Class<?> claz = obj.getClass();
-        final String property = toString(identifier);
+        final String property = AbstractExecutor.toString(identifier);
         final Introspector is = base();
-        AbstractExecutor.Get executor;
+        JexlPropertyGet executor;
         // first try for a getFoo() type of property (also getfoo() )
         if (property != null) {
-            executor = new PropertyGetExecutor(is, claz, property);
-            if (executor.isAlive()) {
+            executor = PropertyGetExecutor.discover(is, claz, property);
+            if (executor != null) {
                 return executor;
             }
-        //}
-        // look for boolean isFoo()
-        //if (property != null) {
-            executor = new BooleanGetExecutor(is, claz, property);
-            if (executor.isAlive()) {
+            // look for boolean isFoo()
+            executor = BooleanGetExecutor.discover(is, claz, property);
+            if (executor != null) {
                 return executor;
             }
         }
         // let's see if we are a map...
-        executor = new MapGetExecutor(is, claz, identifier);
-        if (executor.isAlive()) {
+        executor = MapGetExecutor.discover(is, claz, identifier);
+        if (executor != null) {
             return executor;
         }
-        // let's see if we can convert the identifier to an int,
-        // if obj is an array or a list, we can still do something
-        Integer index = toInteger(identifier);
-        if (index != null) {
-            executor = new ListGetExecutor(is, claz, index);
-            if (executor.isAlive()) {
+        // let's see if this is a list or array
+        executor = ListGetExecutor.discover(is, claz, identifier);
+        if (executor != null) {
+            return executor;
+        }
+        // if that didn't work, look for get(foo)
+        executor = DuckGetExecutor.discover(is, claz, identifier);
+        if (executor != null) {
+            return executor;
+        }
+        // last, look for get("foo") if we did not try yet
+        if (property != null && !(identifier instanceof String)) {
+            // if that didn't work, look for set("foo")
+            executor = DuckGetExecutor.discover(is, claz, property);
+            if (executor != null) {
                 return executor;
             }
         }
-        // if that didn't work, look for set("foo")
-        executor = new DuckGetExecutor(is, claz, identifier);
-        if (executor.isAlive()) {
+        // a field may be?
+        executor = FieldGetExecutor.discover(is, claz, property);
+        if (executor != null) {
             return executor;
         }
-        // if that didn't work, look for set("foo")
-        executor = new DuckGetExecutor(is, claz, property);
-        if (executor.isAlive()) {
+        // or an indexed property?
+        executor = IndexedType.discover(is, obj, property);
+        if (executor != null) {
             return executor;
         }
         return null;
     }
 
-    /**
-     * Return a property setter.
-     * @param obj the object to base the property from.
-     * @param identifier property name (or identifier)
-     * @param arg value to set
-     * @return a {@link AbstractExecutor.Set}.
-     */
-    public final AbstractExecutor.Set getSetExecutor(final Object obj, final Object identifier, Object arg) {
+    @Override
+    public JexlPropertySet getPropertySet(final Object obj, final Object identifier, Object arg) {
         final Class<?> claz = obj.getClass();
-        final String property = toString(identifier);
+        final String property = AbstractExecutor.toString(identifier);
         final Introspector is = base();
-        AbstractExecutor.Set executor;
+        JexlPropertySet executor;
         // first try for a setFoo() type of property (also setfoo() )
         if (property != null) {
-            executor = new PropertySetExecutor(is, claz, property, arg);
-            if (executor.isAlive()) {
+            executor = PropertySetExecutor.discover(is, claz, property, arg);
+            if (executor != null) {
                 return executor;
             }
         }
         // let's see if we are a map...
-        executor = new MapSetExecutor(is, claz, identifier, arg);
-        if (executor.isAlive()) {
+        executor = MapSetExecutor.discover(is, claz, identifier, arg);
+        if (executor != null) {
             return executor;
         }
         // let's see if we can convert the identifier to an int,
         // if obj is an array or a list, we can still do something
-        Integer index = toInteger(identifier);
-        if (index != null) {
-            executor = new ListSetExecutor(is, claz, index, arg);
-            if (executor.isAlive()) {
-                return executor;
-            }
+        executor = ListSetExecutor.discover(is, claz, identifier, arg);
+        if (executor != null) {
+            return executor;
         }
         // if that didn't work, look for set(foo)
-        executor = new DuckSetExecutor(is, claz, identifier, arg);
-        if (executor.isAlive()) {
+        executor = DuckSetExecutor.discover(is, claz, identifier, arg);
+        if (executor != null) {
             return executor;
         }
-        // if that didn't work, look for set("foo")
-        executor = new DuckSetExecutor(is, claz, property, arg);
-        if (executor.isAlive()) {
+        // last, look for set("foo") if we did not try yet
+        if (property != null && !(identifier instanceof String)) {
+            executor = DuckSetExecutor.discover(is, claz, property, arg);
+            if (executor != null) {
+                return executor;
+            }
+        }
+        // a field may be?
+        executor = FieldSetExecutor.discover(is, claz, property, arg);
+        if (executor != null) {
             return executor;
         }
         return null;
     }
-    
+
     @Override
     @SuppressWarnings("unchecked")
-    public Iterator<?> getIterator(Object obj, JexlInfoHandle info) {
+    public Iterator<?> getIterator(Object obj) {
         if (obj instanceof Iterator<?>) {
             return ((Iterator<?>) obj);
         }
@@ -358,417 +286,20 @@ public class Uberspect implements JexlUb
             // look for an iterator() method to support the JDK5 Iterable
             // interface or any user tools/DTOs that want to work in
             // foreach without implementing the Collection interface
-            AbstractExecutor.Method it = getMethodExecutor(obj, "iterator", null);
+            JexlMethod it = getMethod(obj, "iterator", null);
             if (it != null && Iterator.class.isAssignableFrom(it.getReturnType())) {
-                return (Iterator<Object>) it.execute(obj, null);
+                return (Iterator<Object>) it.invoke(obj, (Object[]) null);
             }
         } catch (Exception xany) {
-            throw new JexlException(info.jexlInfo(), "unable to generate iterator()", xany);
-        }
-        return null;
-    }
-    
-    @Override
-    public JexlMethod getMethod(Object obj, String method, Object[] args, JexlInfoHandle info) {
-        return getMethodExecutor(obj, method, args);
-    }
-
-    @Override
-    public JexlMethod getConstructor(Object ctorHandle, Object[] args, JexlInfoHandle info) {
-        final Constructor<?> ctor = getConstructor(ctorHandle, args);
-        if (ctor != null) {
-            return new ConstructorMethod(ctor);
-        } else {
-            return null;
-        }
-    }
-
-    @Override
-    public JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfoHandle info) {
-        JexlPropertyGet get = getGetExecutor(obj, identifier);
-        if (get == null && obj != null && identifier != null) {
-            get = getIndexedGet(obj, identifier.toString());
-            if (get == null) {
-                Field field = getField(obj, identifier.toString(), info.jexlInfo());
-                if (field != null) {
-                    return new FieldPropertyGet(field);
-                }
-            }
-        }
-        return get;
-    }
-
-    @Override
-    public JexlPropertySet getPropertySet(final Object obj, final Object identifier, Object arg, JexlInfoHandle info) {
-        JexlPropertySet set = getSetExecutor(obj, identifier, arg);
-        if (set == null && obj != null && identifier != null) {
-            Field field = getField(obj, identifier.toString(), info.jexlInfo());
-            if (field != null
-                    && !Modifier.isFinal(field.getModifiers())
-                    && (arg == null || MethodKey.isInvocationConvertible(field.getType(), arg.getClass(), false))) {
-                return new FieldPropertySet(field);
-            }
-        }
-        return set;
-    }
-
-    /**
-     * Returns a class field.
-     * @param obj the object
-     * @param name the field name
-     * @param info debug info
-     * @return a {@link Field}.
-     */
-    protected Field getField(Object obj, String name, JexlInfo info) {
-        final Class<?> clazz = obj instanceof Class<?> ? (Class<?>) obj : obj.getClass();
-        return getField(clazz, name);
-    }
-
-    /**
-     * Attempts to find an indexed-property getter in an object.
-     * The code attempts to find the list of methods getXXX() and setXXX().
-     * Note that this is not equivalent to the strict bean definition of indexed properties; the type of the key
-     * is not necessarily an int and the set/get arrays are not resolved.
-     * @param object the object
-     * @param name the container name
-     * @return a JexlPropertyGet is successfull, null otherwise
-     */
-    protected JexlPropertyGet getIndexedGet(Object object, String name) {
-        if (object != null && name != null) {
-            String base = name.substring(0, 1).toUpperCase() + name.substring(1);
-            final String container = name;
-            final Class<?> clazz = object.getClass();
-            final Method[] getters = getMethods(object.getClass(), "get" + base);
-            final Method[] setters = getMethods(object.getClass(), "set" + base);
-            if (getters != null) {
-                return new IndexedType(container, clazz, getters, setters);
+            if (rlog != null && rlog.isDebugEnabled()) {
+                rlog.info("unable to solve iterator()", xany);
             }
         }
         return null;
     }
 
-    /**
-     * Abstract an indexed property container.
-     * This stores the container name and owning class as well as the list of available getter and setter methods.
-     * It implements JexlPropertyGet since such a container can only be accessed from its owning instance (not set).
-     */
-    protected static final class IndexedType implements JexlPropertyGet {
-        /** The container name. */
-        private final String container;
-        /** The owning class. */
-        private final Class<?> clazz;
-        /** The array of getter methods. */
-        private final Method[] getters;
-        /** The array of setter methods. */
-        private final Method[] setters;
-
-        /**
-         * Creates a new indexed type.
-         * @param name the container name
-         * @param c the owning class
-         * @param gets the array of getter methods
-         * @param sets the array of setter methods
-         */
-        protected IndexedType(String name, Class<?> c, Method[] gets, Method[] sets) {
-            this.container = name;
-            this.clazz = c;
-            this.getters = gets;
-            this.setters = sets;
-        }
-
-        @Override
-        public Object invoke(Object obj) throws Exception {
-            if (obj != null && clazz.equals(obj.getClass())) {
-                return new IndexedContainer(this, obj);
-            } else {
-                throw new IntrospectionException("property resolution error");
-            }
-        }
-
-        @Override
-        public Object tryInvoke(Object obj, Object key) {
-            if (obj != null && key != null && clazz.equals(obj.getClass()) && container.equals(key.toString())) {
-                return new IndexedContainer(this, obj);
-            } else {
-                return TRY_FAILED;
-            }
-        }
-
-        @Override
-        public boolean tryFailed(Object rval) {
-            return rval == TRY_FAILED;
-        }
-
-        @Override
-        public boolean isCacheable() {
-            return true;
-        }
-
-        /**
-         * Gets the value of a property from a container.
-         * @param object the instance owning the container (not null)
-         * @param key the property key (not null)
-         * @return the property value
-         * @throws Exception if invocation failed; IntrospectionException if a property getter could not be found
-         */
-        public Object invokeGet(Object object, Object key) throws Exception {
-            if (getters != null) {
-                final Object[] args = {key};
-                final Method jm;
-                if (getters.length == 1) {
-                    jm = getters[0];
-                } else {
-                    jm = new MethodKey(getters[0].getName(), args).getMostSpecificMethod(Arrays.asList(getters));
-                }
-                if (jm != null) {
-                    return jm.invoke(object, args);
-                }
-            }
-            throw new IntrospectionException("property get error: "
-                    + object.getClass().toString() + "@" + key.toString());
-        }
-
-        /**
-         * Sets the value of a property in a container.
-         * @param object the instance owning the container (not null)
-         * @param key the property key (not null)
-         * @param value the property value (not null)
-         * @return the result of the method invocation (frequently null)
-         * @throws Exception if invocation failed; IntrospectionException if a property setter could not be found
-         */
-        public Object invokeSet(Object object, Object key, Object value) throws Exception {
-            if (setters != null) {
-                final Object[] args = {key, value};
-                final Method jm;
-                if (setters.length == 1) {
-                    jm = setters[0];
-                } else {
-                    jm = new MethodKey(setters[0].getName(), args).getMostSpecificMethod(Arrays.asList(setters));
-                }
-                if (jm != null) {
-                    return jm.invoke(object, args);
-                }
-            }
-            throw new IntrospectionException("property set error: "
-                    + object.getClass().toString() + "@" + key.toString());
-        }
-    }
-
-    /**
-     * A generic indexed property container, exposes get(key) and set(key, value) and solves method call dynamically
-     * based on arguments.
-     * <p>Must remain public for introspection purpose.</p>
-     */
-    public static final class IndexedContainer {
-        /** The instance owning the container. */
-        private final Object object;
-        /** The container type instance. */
-        private final IndexedType type;
-
-        /**
-         * Creates a new duck container.
-         * @param theType the container type
-         * @param theObject the instance owning the container
-         */
-        private IndexedContainer(IndexedType theType, Object theObject) {
-            this.type = theType;
-            this.object = theObject;
-        }
-
-        /**
-         * Gets a property from a container.
-         * @param key the property key
-         * @return the property value
-         * @throws Exception if inner invocation fails
-         */
-        public Object get(Object key) throws Exception {
-            return type.invokeGet(object, key);
-        }
-
-        /**
-         * Sets a property in a container.
-         * @param key the property key
-         * @param value the property value
-         * @return the invocation result (frequently null)
-         * @throws Exception if inner invocation fails
-         */
-        public Object set(Object key, Object value) throws Exception {
-            return type.invokeSet(object, key, value);
-        }
-    }
-
-    /**
-     * A JexlMethod that wraps constructor.
-     */
-    protected final class ConstructorMethod implements JexlMethod {
-        /** The wrapped constructor. */
-        private final Constructor<?> ctor;
-
-        /**
-         * Creates a constructor method.
-         * @param theCtor the constructor to wrap
-         */
-        protected ConstructorMethod(Constructor<?> theCtor) {
-            this.ctor = theCtor;
-        }
-
-        @Override
-        public Object invoke(Object obj, Object[] params) throws Exception {
-            Class<?> clazz = null;
-            if (obj instanceof Class<?>) {
-                clazz = (Class<?>) obj;
-            } else if (obj != null) {
-                clazz = getClassByName(obj.toString());
-            } else {
-                clazz = ctor.getDeclaringClass();
-            }
-            if (clazz.equals(ctor.getDeclaringClass())) {
-                return ctor.newInstance(params);
-            } else {
-                throw new IntrospectionException("constructor resolution error");
-            }
-        }
-
-        @Override
-        public Object tryInvoke(String name, Object obj, Object[] params) {
-            Class<?> clazz = null;
-            if (obj instanceof Class<?>) {
-                clazz = (Class<?>) obj;
-            } else if (obj != null) {
-                clazz = getClassByName(obj.toString());
-            } else {
-                clazz = ctor.getDeclaringClass();
-            }
-            if (clazz.equals(ctor.getDeclaringClass())
-                    && (name == null || name.equals(clazz.getName()))) {
-                try {
-                    return ctor.newInstance(params);
-                } catch (InstantiationException xinstance) {
-                    return TRY_FAILED;
-                } catch (IllegalAccessException xaccess) {
-                    return TRY_FAILED;
-                } catch (IllegalArgumentException xargument) {
-                    return TRY_FAILED;
-                } catch (InvocationTargetException xinvoke) {
-                    return TRY_FAILED;
-                }
-            }
-            return TRY_FAILED;
-        }
-
-        @Override
-        public boolean tryFailed(Object rval) {
-            return rval == TRY_FAILED;
-        }
-
-        @Override
-        public boolean isCacheable() {
-            return true;
-        }
-
-        @Override
-        public Class<?> getReturnType() {
-            return ctor.getDeclaringClass();
-        }
-    }
-
-    /**
-     * A JexlPropertyGet for public fields.
-     */
-    protected static final class FieldPropertyGet implements JexlPropertyGet {
-        /**
-         * The public field.
-         */
-        private final Field field;
-
-        /**
-         * Creates a new instance of FieldPropertyGet.
-         * @param theField the class public field
-         */
-        protected FieldPropertyGet(Field theField) {
-            field = theField;
-        }
-
-        @Override
-        public Object invoke(Object obj) throws Exception {
-            return field.get(obj);
-        }
-
-        @Override
-        public Object tryInvoke(Object obj, Object key) {
-            if (obj.getClass().equals(field.getDeclaringClass()) && key.equals(field.getName())) {
-                try {
-                    return field.get(obj);
-                } catch (IllegalAccessException xill) {
-                    return TRY_FAILED;
-                }
-            }
-            return TRY_FAILED;
-        }
-
-        @Override
-        public boolean tryFailed(Object rval) {
-            return rval == TRY_FAILED;
-        }
-
-        @Override
-        public boolean isCacheable() {
-            return true;
-        }
-    }
-
-    /**
-     * A JexlPropertySet for public fields.
-     */
-    protected static final class FieldPropertySet implements JexlPropertySet {
-        /**
-         * The public field.
-         */
-        private final Field field;
-
-        /**
-         * Creates a new instance of FieldPropertySet.
-         * @param theField the class public field
-         */
-        protected FieldPropertySet(Field theField) {
-            field = theField;
-        }
-
-        @Override
-        public Object invoke(Object obj, Object arg) throws Exception {
-            field.set(obj, arg);
-            return arg;
-        }
-
-        @Override
-        public Object tryInvoke(Object obj, Object key, Object value) {
-            if (obj.getClass().equals(field.getDeclaringClass())
-                    && key.equals(field.getName())
-                    && (value == null || MethodKey.isInvocationConvertible(field.getType(), value.getClass(), false))) {
-                try {
-                    field.set(obj, value);
-                    return value;
-                } catch (IllegalAccessException xill) {
-                    return TRY_FAILED;
-                }
-            }
-            return TRY_FAILED;
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        @Override
-        public boolean tryFailed(Object rval) {
-            return rval == TRY_FAILED;
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        @Override
-        public boolean isCacheable() {
-            return true;
-        }
+    @Override
+    public JexlMethod getConstructor(Object ctorHandle, Object[] args) {
+        return ConstructorMethod.discover(base(), ctorHandle, args);
     }
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java Mon Dec 19 10:43:35 2011
@@ -18,7 +18,6 @@
 package org.apache.commons.jexl3.introspection;
 
 import java.util.Iterator;
-import org.apache.commons.jexl3.JexlInfoHandle;
 
 /**
  * 'Federated' introspection/reflection interface to allow the introspection
@@ -37,30 +36,28 @@ public interface JexlUberspect {
      * Returns a class constructor.
      * @param ctorHandle a class or class name
      * @param args constructor arguments
-     * @param info contextual information
      * @return a {@link JexlMethod}
      * @since 3.0
      */
-    JexlMethod getConstructor(Object ctorHandle, Object[] args, JexlInfoHandle info);
+    JexlMethod getConstructor(Object ctorHandle, Object[] args);
+    
     /**
      * Returns a JexlMethod.
      * @param obj the object
      * @param method the method name
      * @param args method arguments
-     * @param info contextual information
      * @return a {@link JexlMethod}
      */
-    JexlMethod getMethod(Object obj, String method, Object[] args, JexlInfoHandle info);
+    JexlMethod getMethod(Object obj, String method, Object[] args);
 
     /**
      * Property getter.
      * <p>Returns JexlPropertyGet appropos for ${bar.woogie}.
      * @param obj the object to get the property from
      * @param identifier property name
-     * @param info contextual information
      * @return a {@link JexlPropertyGet}
      */
-    JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfoHandle info);
+    JexlPropertyGet getPropertyGet(Object obj, Object identifier);
 
     /**
      * Property setter.
@@ -68,17 +65,15 @@ public interface JexlUberspect {
      * @param obj the object to get the property from.
      * @param identifier property name
      * @param arg value to set
-     * @param info contextual information
      * @return a {@link JexlPropertySet}.
      */
-    JexlPropertySet getPropertySet(Object obj, Object identifier, Object arg, JexlInfoHandle info);
+    JexlPropertySet getPropertySet(Object obj, Object identifier, Object arg);
 
     /**
      * Gets an iterator from an object.
-     * @param obj to get the iterator for
-     * @param info contextual information
+     * @param obj to get the iterator from
      * @return an iterator over obj
      */
-    Iterator<?> getIterator(Object obj, JexlInfoHandle info);
+    Iterator<?> getIterator(Object obj);
 
 }
\ No newline at end of file

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java Mon Dec 19 10:43:35 2011
@@ -17,14 +17,13 @@
 package org.apache.commons.jexl3.parser;
 
 import org.apache.commons.jexl3.JexlInfo;
-import org.apache.commons.jexl3.JexlInfoHandle;
 
 /**
  * Base class for parser nodes - holds an 'image' of the token for later use.
  *
  * @since 2.0
  */
-public abstract class JexlNode extends SimpleNode implements JexlInfoHandle {
+public abstract class JexlNode extends SimpleNode {
     /** A marker interface for literals.
      * @param <T> the literal type
      */
@@ -42,7 +41,10 @@ public abstract class JexlNode extends S
         super(p, id);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Gets the associated JexlInfo instance.
+     * @return the info
+     */
     public JexlInfo jexlInfo() {
         JexlNode node = this;
         while (node != null) {

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java Mon Dec 19 10:43:35 2011
@@ -82,7 +82,6 @@ public class MethodTest extends JexlTest
             } else {
                 return "";
             }
-            
         }
     }
 

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java?rev=1220681&r1=1220680&r2=1220681&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java Mon Dec 19 10:43:35 2011
@@ -16,25 +16,16 @@
  */
 package org.apache.commons.jexl3.internal.introspection;
 
-import org.apache.commons.jexl3.internal.introspection.Uberspect;
+
+import org.apache.commons.jexl3.JexlTestCase;
+import org.apache.commons.jexl3.internal.Engine;
+import org.apache.commons.jexl3.introspection.JexlPropertyGet;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
-
-import org.apache.commons.jexl3.internal.Engine;
-import org.apache.commons.jexl3.JexlTestCase;
-
-import org.apache.commons.jexl3.internal.introspection.AbstractExecutor;
-import org.apache.commons.jexl3.internal.introspection.PropertyGetExecutor;
-import org.apache.commons.jexl3.internal.introspection.PropertySetExecutor;
-import org.apache.commons.jexl3.internal.introspection.DuckGetExecutor;
-import org.apache.commons.jexl3.internal.introspection.DuckSetExecutor;
-import org.apache.commons.jexl3.internal.introspection.ListGetExecutor;
-import org.apache.commons.jexl3.internal.introspection.MapGetExecutor;
-import org.apache.commons.jexl3.internal.introspection.MapSetExecutor;
-import org.apache.commons.jexl3.internal.introspection.ListSetExecutor;
+import org.apache.commons.jexl3.introspection.JexlPropertySet;
 
 /**
  * Tests for checking introspection discovery.
@@ -105,27 +96,27 @@ public class DiscoveryTest extends JexlT
         Uberspect uber = Engine.getUberspect(null);
         Bean bean = new Bean("JEXL", "LXEJ");
 
-        AbstractExecutor.Get get = uber.getGetExecutor(bean, "value");
-        AbstractExecutor.Set set  = uber.getSetExecutor(bean, "value", "foo");
+        JexlPropertyGet get = uber.getPropertyGet(bean, "value");
+        JexlPropertySet set  = uber.getPropertySet(bean, "value", "foo");
         assertTrue("bean property getter", get instanceof PropertyGetExecutor);
         assertTrue("bean property setter", set instanceof PropertySetExecutor);
         // introspector and uberspect should return same result
-        assertEquals(get, uber.getPropertyGet(bean, "value", null));
-        assertEquals(set, uber.getPropertySet(bean, "value", "foo", null));
+        assertEquals(get, uber.getPropertyGet(bean, "value"));
+        assertEquals(set, uber.getPropertySet(bean, "value", "foo"));
         // different property should return different setter/getter
-        assertFalse(get.equals(uber.getGetExecutor(bean, "eulav")));
-        assertFalse(set.equals(uber.getSetExecutor(bean, "eulav", "foo")));
+        assertFalse(get.equals(uber.getPropertyGet(bean, "eulav")));
+        assertFalse(set.equals(uber.getPropertySet(bean, "eulav", "foo")));
         // setter returns argument
-        Object bar = set.execute(bean, "bar");
+        Object bar = set.invoke(bean, "bar");
         assertEquals("bar", bar);
         // getter should return last value
-        assertEquals("bar", get.execute(bean));
+        assertEquals("bar", get.invoke(bean));
         // tryExecute should succeed on same property
-        Object quux = set.tryExecute(bean, "value", "quux");
+        Object quux = set.tryInvoke(bean, "value", "quux");
         assertEquals("quux", quux);
-        assertEquals("quux", get.execute(bean));
+        assertEquals("quux", get.invoke(bean));
         // tryExecute should fail on different property
-        assertEquals(AbstractExecutor.TRY_FAILED, set.tryExecute(bean, "eulav", "nope"));
+        assertEquals(AbstractExecutor.TRY_FAILED, set.tryInvoke(bean, "eulav", "nope"));
 
     }
 
@@ -133,27 +124,27 @@ public class DiscoveryTest extends JexlT
         Uberspect uber = Engine.getUberspect(null);
         Duck duck = new Duck("JEXL", "LXEJ");
 
-        AbstractExecutor.Get get = uber.getGetExecutor(duck, "value");
-        AbstractExecutor.Set set  = uber.getSetExecutor(duck, "value", "foo");
+        JexlPropertyGet get = uber.getPropertyGet(duck, "value");
+        JexlPropertySet set  = uber.getPropertySet(duck, "value", "foo");
         assertTrue("duck property getter", get instanceof DuckGetExecutor);
         assertTrue("duck property setter", set instanceof DuckSetExecutor);
         // introspector and uberspect should return same result
-        assertEquals(get, uber.getPropertyGet(duck, "value", null));
-        assertEquals(set, uber.getPropertySet(duck, "value", "foo", null));
+        assertEquals(get, uber.getPropertyGet(duck, "value"));
+        assertEquals(set, uber.getPropertySet(duck, "value", "foo"));
         // different property should return different setter/getter
-        assertFalse(get.equals(uber.getGetExecutor(duck, "eulav")));
-        assertFalse(set.equals(uber.getSetExecutor(duck, "eulav", "foo")));
+        assertFalse(get.equals(uber.getPropertyGet(duck, "eulav")));
+        assertFalse(set.equals(uber.getPropertySet(duck, "eulav", "foo")));
         // setter returns argument
-        Object bar = set.execute(duck, "bar");
+        Object bar = set.invoke(duck, "bar");
         assertEquals("bar", bar);
         // getter should return last value
-        assertEquals("bar", get.execute(duck));
+        assertEquals("bar", get.invoke(duck));
         // tryExecute should succeed on same property
-        Object quux = set.tryExecute(duck, "value", "quux");
+        Object quux = set.tryInvoke(duck, "value", "quux");
         assertEquals("quux", quux);
-        assertEquals("quux", get.execute(duck));
+        assertEquals("quux", get.invoke(duck));
         // tryExecute should fail on different property
-        assertEquals(AbstractExecutor.TRY_FAILED, set.tryExecute(duck, "eulav", "nope"));
+        assertEquals(AbstractExecutor.TRY_FAILED, set.tryInvoke(duck, "eulav", "nope"));
     }
 
     public void testListIntrospection() throws Exception {
@@ -162,28 +153,28 @@ public class DiscoveryTest extends JexlT
         list.add("LIST");
         list.add("TSIL");
 
-        AbstractExecutor.Get get = uber.getGetExecutor(list, Integer.valueOf(1));
-        AbstractExecutor.Set set  = uber.getSetExecutor(list, Integer.valueOf(1), "foo");
+        JexlPropertyGet get = uber.getPropertyGet(list, Integer.valueOf(1));
+        JexlPropertySet set  = uber.getPropertySet(list, Integer.valueOf(1), "foo");
         assertTrue("list property getter", get instanceof ListGetExecutor);
         assertTrue("list property setter", set instanceof ListSetExecutor);
         // introspector and uberspect should return same result
-        assertEquals(get, uber.getPropertyGet(list, Integer.valueOf(1), null));
-        assertEquals(set, uber.getPropertySet(list, Integer.valueOf(1), "foo", null));
+        assertEquals(get, uber.getPropertyGet(list, Integer.valueOf(1)));
+        assertEquals(set, uber.getPropertySet(list, Integer.valueOf(1), "foo"));
         // different property should return different setter/getter
-        assertFalse(get.equals(uber.getGetExecutor(list, Integer.valueOf(0))));
-        assertFalse(get.equals(uber.getSetExecutor(list, Integer.valueOf(0), "foo")));
+        assertFalse(get.equals(uber.getPropertyGet(list, Integer.valueOf(0))));
+        assertFalse(get.equals(uber.getPropertySet(list, Integer.valueOf(0), "foo")));
         // setter returns argument
-        Object bar = set.execute(list, "bar");
+        Object bar = set.invoke(list, "bar");
         assertEquals("bar", bar);
         // getter should return last value
-        assertEquals("bar", get.execute(list));
+        assertEquals("bar", get.invoke(list));
         // tryExecute should succeed on integer property
-        Object quux = set.tryExecute(list, Integer.valueOf(1), "quux");
+        Object quux = set.tryInvoke(list, Integer.valueOf(1), "quux");
         assertEquals("quux", quux);
         // getter should return last value
-        assertEquals("quux", get.execute(list));
+        assertEquals("quux", get.invoke(list));
         // tryExecute should fail on non-integer property class
-        assertEquals(AbstractExecutor.TRY_FAILED, set.tryExecute(list, "eulav", "nope"));
+        assertEquals(AbstractExecutor.TRY_FAILED, set.tryInvoke(list, "eulav", "nope"));
     }
 
     public void testMapIntrospection() throws Exception {
@@ -192,28 +183,28 @@ public class DiscoveryTest extends JexlT
         map.put("value", "MAP");
         map.put("eulav", "PAM");
 
-        AbstractExecutor.Get get = uber.getGetExecutor(map, "value");
-        AbstractExecutor.Set set  = uber.getSetExecutor(map, "value", "foo");
+        JexlPropertyGet get = uber.getPropertyGet(map, "value");
+        JexlPropertySet set  = uber.getPropertySet(map, "value", "foo");
         assertTrue("map property getter", get instanceof MapGetExecutor);
         assertTrue("map property setter", set instanceof MapSetExecutor);
         // introspector and uberspect should return same result
-        assertEquals(get, uber.getPropertyGet(map, "value", null));
-        assertEquals(set, uber.getPropertySet(map, "value", "foo", null));
+        assertEquals(get, uber.getPropertyGet(map, "value"));
+        assertEquals(set, uber.getPropertySet(map, "value", "foo"));
         // different property should return different setter/getter
-        assertFalse(get.equals(uber.getGetExecutor(map, "eulav")));
-        assertFalse(get.equals(uber.getSetExecutor(map, "eulav", "foo")));
+        assertFalse(get.equals(uber.getPropertyGet(map, "eulav")));
+        assertFalse(get.equals(uber.getPropertySet(map, "eulav", "foo")));
         // setter returns argument
-        Object bar = set.execute(map, "bar");
+        Object bar = set.invoke(map, "bar");
         assertEquals("bar", bar);
         // getter should return last value
-        assertEquals("bar", get.execute(map));
+        assertEquals("bar", get.invoke(map));
         // tryExecute should succeed on same property class
-        Object quux = set.tryExecute(map, "value", "quux");
+        Object quux = set.tryInvoke(map, "value", "quux");
         assertEquals("quux", quux);
         // getter should return last value
-        assertEquals("quux", get.execute(map));
+        assertEquals("quux", get.invoke(map));
         // tryExecute should fail on different property class
-        assertEquals(AbstractExecutor.TRY_FAILED, set.tryExecute(map, Integer.valueOf(1), "nope"));
+        assertEquals(AbstractExecutor.TRY_FAILED, set.tryInvoke(map, Integer.valueOf(1), "nope"));
     }
 
 }



Mime
View raw message