commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1693604 - in /commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3: annotations/ internal/ internal/introspection/ introspection/
Date Fri, 31 Jul 2015 14:11:29 GMT
Author: henrib
Date: Fri Jul 31 14:11:28 2015
New Revision: 1693604

URL: http://svn.apache.org/r1693604
Log:
JEXL:
JEXL-171: added a JexlUberspect.getStrategy(...) method

Removed:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/JexlSet.java
Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java?rev=1693604&r1=1693603&r2=1693604&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
Fri Jul 31 14:11:28 2015
@@ -1286,8 +1286,7 @@ public class Interpreter extends ParserV
             if (object != null) {
                 // disallow mixing antish variable & bean with same root; avoid ambiguity
                 antish = false;
-            }
-            else if (antish) {
+            } else if (antish) {
                 if (ant == null) {
                     JexlNode first = left.jjtGetChild(0);
                     if (first instanceof ASTIdentifier && ((ASTIdentifier) first).getSymbol()
< 0) {
@@ -1629,8 +1628,9 @@ public class Interpreter extends ParserV
         }
         // resolve that property
         Exception xcause = null;
-        List<JexlUberspect.ResolverType> strategy = (node == null) || !(node.jjtGetParent()instanceof
ASTArrayAccess)
-                                                     ? JexlUberspect.POJO : JexlUberspect.MAP;
+        List<JexlUberspect.ResolverType> strategy = uberspect.getStrategy(
+                                                    !(node != null && node.jjtGetParent()
instanceof ASTArrayAccess),
+                                                    object.getClass());
         JexlPropertyGet vg = uberspect.getPropertyGet(strategy, object, attribute);
         if (vg != null) {
             try {
@@ -1692,15 +1692,16 @@ public class Interpreter extends ParserV
             }
         }
         Exception xcause = null;
-        List<JexlUberspect.ResolverType> strategy = (node == null) || !(node.jjtGetParent()instanceof
ASTArrayAccess)
-                                                     ? JexlUberspect.POJO : JexlUberspect.MAP;
+        List<JexlUberspect.ResolverType> strategy = uberspect.getStrategy(
+                                                    !(node != null && node.jjtGetParent()
instanceof ASTArrayAccess),
+                                                    object.getClass());
         JexlPropertySet vs = uberspect.getPropertySet(strategy, object, attribute, value);
         // if we can't find an exact match, narrow the value argument and try again
         if (vs == null) {
             // replace all numbers with the smallest type that will fit
             Object[] narrow = {value};
             if (arithmetic.narrowArguments(narrow)) {
-                vs = uberspect.getPropertySet(object, attribute, narrow[0]);
+                vs = uberspect.getPropertySet(strategy, object, attribute, narrow[0]);
             }
         }
         if (vs != null) {

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java?rev=1693604&r1=1693603&r2=1693604&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java
Fri Jul 31 14:11:28 2015
@@ -46,7 +46,7 @@ public class Operators {
     }
 
     /**
-     * Checks whether a method returns a boolean or a Boolean
+     * Checks whether a method returns a boolean or a Boolean.
      * @param vm the JexlMethod (may be null)
      * @return true of false
      */

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=1693604&r1=1693603&r2=1693604&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
Fri Jul 31 14:11:28 2015
@@ -107,6 +107,14 @@ public final class SandboxUberspect impl
      * {@inheritDoc}
      */
     @Override
+    public List<ResolverType> getStrategy(boolean db, Class<?> clazz) {
+        return db ? JexlUberspect.POJO : JexlUberspect.MAP;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public JexlPropertyGet getPropertyGet(Object obj, Object identifier) {
         return getPropertyGet(POJO, obj, identifier);
     }

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=1693604&r1=1693603&r2=1693604&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
Fri Jul 31 14:11:28 2015
@@ -217,12 +217,22 @@ public class Uberspect implements JexlUb
     }
 
     @Override
+    public List<ResolverType> getStrategy(boolean db, Class<?> clazz) {
+        //return Map.class.isAssignableFrom(clazz)? JexlUberspect.MAP : JexlUberspect.POJO;
+        return db ? JexlUberspect.POJO : JexlUberspect.MAP;
+    }
+
+    @Override
     public JexlPropertyGet getPropertyGet(Object obj, Object identifier) {
         return getPropertyGet(POJO, obj, identifier);
     }
 
     @Override
-    public JexlPropertyGet getPropertyGet(final List<ResolverType> strategy, final
Object obj, final Object identifier) {
+    public JexlPropertyGet getPropertyGet(
+            final List<ResolverType> strategy, final Object obj, final Object identifier)
{
+        if (strategy == null) {
+            throw new NullPointerException("null property resolver strategy");
+        }
         final Class<?> claz = obj.getClass();
         final String property = AbstractExecutor.castString(identifier);
         final Introspector is = base();
@@ -279,7 +289,11 @@ public class Uberspect implements JexlUb
     }
 
     @Override
-    public JexlPropertySet getPropertySet(final List<ResolverType> strategy, final
Object obj, final Object identifier, final Object arg) {
+    public JexlPropertySet getPropertySet(
+            final List<ResolverType> strategy, final Object obj, final Object identifier,
final Object arg) {
+        if (strategy == null) {
+            throw new NullPointerException("null property resolver strategy");
+        }
         final Class<?> claz = obj.getClass();
         final String property = AbstractExecutor.castString(identifier);
         final Introspector is = base();

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=1693604&r1=1693603&r2=1693604&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
Fri Jul 31 14:11:28 2015
@@ -71,7 +71,7 @@ public interface JexlUberspect {
      * @see JexlUberspect#getPropertyGet
      * @see JexlUberspect#getPropertySet
      */
-    static final List<ResolverType> POJO = Collections.unmodifiableList(Arrays.asList(
+    List<ResolverType> POJO = Collections.unmodifiableList(Arrays.asList(
         ResolverType.PROPERTY,
         ResolverType.MAP,
         ResolverType.LIST,
@@ -83,7 +83,7 @@ public interface JexlUberspect {
     /**
      * A resolver strategy tailored for Maps, favors '[]' over '.'.
      */
-    static final  List<ResolverType> MAP = Collections.unmodifiableList(Arrays.asList(
+    List<ResolverType> MAP = Collections.unmodifiableList(Arrays.asList(
         ResolverType.MAP,
         ResolverType.LIST,
         ResolverType.DUCK,
@@ -133,9 +133,18 @@ public interface JexlUberspect {
     JexlPropertyGet getPropertyGet(Object obj, Object identifier);
 
     /**
+     * Gets the strategy to apply for resolving properties.
+     * <p>Default behavior is to use POJO if db is true, MAP if db is false.
+     * @param db access operator flag, true for dot ('.' ) or false for bracket ('[]')
+     * @param clazz the property owner class
+     * @return the strategy
+     */
+    List<ResolverType> getStrategy(boolean db, Class<?> clazz);
+
+    /**
      * Property getter.
      * <p>Seeks a JexlPropertyGet apropos to an expression like <code>bar.woogie</code>.</p>
-     * @param strategy  the ordered list of resolver types
+     * @param strategy  the ordered list of resolver types, must not be null
      * @param obj the object to get the property from
      * @param identifier property name
      * @return a {@link JexlPropertyGet} or null
@@ -156,7 +165,7 @@ public interface JexlUberspect {
     /**
      * Property setter.
      * <p>Seeks a JelPropertySet apropos to an expression like <code>foo.bar
= "geir"</code>.</p>
-     * @param strategy the ordered list of resolver types
+     * @param strategy the ordered list of resolver types, must not be null
      * @param obj the object to get the property from
      * @param identifier property name
      * @param arg value to set
@@ -180,5 +189,4 @@ public interface JexlUberspect {
      */
     JexlArithmetic.Uberspect getArithmetic(JexlArithmetic arithmetic);
 
-
 }
\ No newline at end of file



Mime
View raw message