You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2017/07/14 13:03:36 UTC

svn commit: r1801955 - /commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ObjectContext.java

Author: henrib
Date: Fri Jul 14 13:03:36 2017
New Revision: 1801955

URL: http://svn.apache.org/viewvc?rev=1801955&view=rev
Log:
JEXL-224: ObjectContext rewrite based on lower level calls

Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ObjectContext.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ObjectContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ObjectContext.java?rev=1801955&r1=1801954&r2=1801955&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ObjectContext.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ObjectContext.java Fri Jul 14 13:03:36 2017
@@ -14,12 +14,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.commons.jexl3;
 
+import org.apache.commons.jexl3.introspection.JexlPropertyGet;
+import org.apache.commons.jexl3.introspection.JexlPropertySet;
+
 /**
  * Wraps an Object as a JEXL context and NamespaceResolver.
- * 
+ *
  * @param <T> the wrapped object type to use
  * @since 3.0
  */
@@ -32,9 +34,23 @@ public class ObjectContext<T> implements
     private final T object;
 
     /**
+     * @return the Jexl engine
+     */
+    protected JexlEngine getJexl() {
+        return jexl;
+    }
+
+    /**
+     * @return the object exposed by this context
+     */
+    protected T getObject() {
+        return object;
+    }
+
+    /**
      * Creates a new ObjectContext.
-     * 
-     * @param engine the jexl engine to use to solve properties
+     *
+     * @param engine  the jexl engine to use to solve properties
      * @param wrapped the object to wrap in this context
      */
     public ObjectContext(JexlEngine engine, T wrapped) {
@@ -44,17 +60,42 @@ public class ObjectContext<T> implements
 
     @Override
     public Object get(String name) {
-        return jexl.getProperty(object, name);
+        JexlPropertyGet jget = jexl.getUberspect().getPropertyGet(object, name);
+        if (jget != null) {
+            try {
+                return jget.invoke(object);
+            } catch (Exception xany) {
+                if (jexl.isStrict()) {
+                    throw new JexlException.Property(null, name, xany);
+                }
+            }
+        }
+        return null;
     }
 
     @Override
     public void set(String name, Object value) {
-        jexl.setProperty(object, name, value);
+        JexlPropertySet jset = jexl.getUberspect().getPropertySet(object, name, value);
+        if (jset != null) {
+            try {
+                jset.invoke(object, value);
+            } catch (Exception xany) {
+                // ignore
+                if (jexl.isStrict()) {
+                    throw new JexlException.Property(null, name, xany);
+                }
+            }
+        }
     }
 
     @Override
     public boolean has(String name) {
-        return jexl.getUberspect().getPropertyGet(object, name) != null;
+        JexlPropertyGet jget = jexl.getUberspect().getPropertyGet(object, name);
+        try {
+            return jget != null && jget.invoke(object) != null;
+        } catch (Exception xany) {
+            return false;
+        }
     }
 
     @Override