Package org.apache.commons.jexl2.internal

Examples of org.apache.commons.jexl2.internal.Introspector


        assertEquals(AbstractExecutor.TRY_FAILED, set.tryExecute(duck, "eulav", "nope"));
    }

    public void testListIntrospection() throws Exception {
        Uberspect uber = JexlEngine.getUberspect(null);
        Introspector intro = (Introspector) uber;
        List<Object> list = new ArrayList<Object>();
        list.add("LIST");
        list.add("TSIL");

        AbstractExecutor.Get get = intro.getGetExecutor(list, Integer.valueOf(1));
        AbstractExecutor.Set set  = intro.getSetExecutor(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));
        // different property should return different setter/getter
        assertFalse(get.equals(intro.getGetExecutor(list, Integer.valueOf(0))));
        assertFalse(get.equals(intro.getSetExecutor(list, Integer.valueOf(0), "foo")));
        // setter returns argument
        Object bar = set.execute(list, "bar");
        assertEquals("bar", bar);
        // getter should return last value
        assertEquals("bar", get.execute(list));
View Full Code Here


        assertEquals(AbstractExecutor.TRY_FAILED, set.tryExecute(list, "eulav", "nope"));
    }

    public void testMapIntrospection() throws Exception {
        Uberspect uber = JexlEngine.getUberspect(null);
        Introspector intro = (Introspector) uber;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("value", "MAP");
        map.put("eulav", "PAM");

        AbstractExecutor.Get get = intro.getGetExecutor(map, "value");
        AbstractExecutor.Set set  = intro.getSetExecutor(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));
        // different property should return different setter/getter
        assertFalse(get.equals(intro.getGetExecutor(map, "eulav")));
        assertFalse(get.equals(intro.getSetExecutor(map, "eulav", "foo")));
        // setter returns argument
        Object bar = set.execute(map, "bar");
        assertEquals("bar", bar);
        // getter should return last value
        assertEquals("bar", get.execute(map));
View Full Code Here

    }


    public void testBeanIntrospection() throws Exception {
        Uberspect uber = JexlEngine.getUberspect(null);
        Introspector intro = (Introspector) uber;
        Bean bean = new Bean("JEXL", "LXEJ");

        AbstractExecutor.Get get = intro.getGetExecutor(bean, "value");
        AbstractExecutor.Set set  = intro.getSetExecutor(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));
        // different property should return different setter/getter
        assertFalse(get.equals(intro.getGetExecutor(bean, "eulav")));
        assertFalse(set.equals(intro.getSetExecutor(bean, "eulav", "foo")));
        // setter returns argument
        Object bar = set.execute(bean, "bar");
        assertEquals("bar", bar);
        // getter should return last value
        assertEquals("bar", get.execute(bean));
View Full Code Here

    }

    public void testDuckIntrospection() throws Exception {
        Uberspect uber = JexlEngine.getUberspect(null);
        Introspector intro = (Introspector) uber;
        Duck duck = new Duck("JEXL", "LXEJ");

        AbstractExecutor.Get get = intro.getGetExecutor(duck, "value");
        AbstractExecutor.Set set  = intro.getSetExecutor(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));
        // different property should return different setter/getter
        assertFalse(get.equals(intro.getGetExecutor(duck, "eulav")));
        assertFalse(set.equals(intro.getSetExecutor(duck, "eulav", "foo")));
        // setter returns argument
        Object bar = set.execute(duck, "bar");
        assertEquals("bar", bar);
        // getter should return last value
        assertEquals("bar", get.execute(duck));
View Full Code Here

        try {
            // attempt to reuse last executor cached in volatile JexlNode.value
            if (cache) {
                Object cached = node.jjtGetValue();
                if (cached instanceof JexlMethod) {
                    JexlMethod me = (JexlMethod) cached;
                    Object eval = me.tryInvoke(methodName, data, argv);
                    if (!me.tryFailed(eval)) {
                        return eval;
                    }
                }
            }
            JexlMethod vm = uberspect.getMethod(data, methodName, argv, node);
            // DG: If we can't find an exact match, narrow the parameters and try again!
            if (vm == null) {
                if (arithmetic.narrowArguments(argv)) {
                    vm = uberspect.getMethod(data, methodName, argv, node);
                }
                if (vm == null) {
                    xjexl = new JexlException(node, "unknown or ambiguous method", null);
                }
            }
            if (xjexl == null) {
                Object eval = vm.invoke(data, argv); // vm cannot be null if xjexl is null
                // cache executor in volatile JexlNode.value
                if (cache && vm.isCacheable()) {
                    node.jjtSetValue(vm);
                }
                return eval;
            }
        } catch (InvocationTargetException e) {
View Full Code Here

        try {
            // attempt to reuse last executor cached in volatile JexlNode.value
            if (cache) {
                Object cached = node.jjtGetValue();
                if (cached instanceof JexlMethod) {
                    JexlMethod me = (JexlMethod) cached;
                    Object eval = me.tryInvoke(function, namespace, argv);
                    if (!me.tryFailed(eval)) {
                        return eval;
                    }
                }
            }
            JexlMethod vm = uberspect.getMethod(namespace, function, argv, node);
            // DG: If we can't find an exact match, narrow the parameters and
            // try again!
            if (vm == null) {
                // replace all numbers with the smallest type that will fit
                if (arithmetic.narrowArguments(argv)) {
                    vm = uberspect.getMethod(namespace, function, argv, node);
                }
                if (vm == null) {
                    xjexl = new JexlException(node, "unknown function", null);
                }
            }
            if (xjexl == null) {
                Object eval = vm.invoke(namespace, argv); // vm cannot be null if xjexl is null
                // cache executor in volatile JexlNode.value
                if (cache && vm.isCacheable()) {
                    node.jjtSetValue(vm);
                }
                return eval;
            }
        } catch (InvocationTargetException e) {
View Full Code Here

            return ((String) val).length();
        } else {
            // check if there is a size method on the object that returns an
            // integer and if so, just use it
            Object[] params = new Object[0];
            JexlMethod vm = uberspect.getMethod(val, "size", EMPTY_PARAMS, node);
            if (vm != null && vm.getReturnType() == Integer.TYPE) {
                Integer result;
                try {
                    result = (Integer) vm.invoke(val, params);
                } catch (Exception e) {
                    throw new JexlException(node, "size() : error executing", e);
                }
                return result.intValue();
            }
View Full Code Here

    public Object invokeMethod(Object obj, String meth, Object... args) {
        JexlException xjexl = null;
        Object result = null;
        JexlInfo info = debugInfo();
        try {
            JexlMethod method = uberspect.getMethod(obj, meth, args, info);
            if (method == null && arithmetic.narrowArguments(args)) {
                method = uberspect.getMethod(obj, meth, args, info);
            }
            if (method != null) {
                result = method.invoke(obj, args);
            } else {
                xjexl = new JexlException(info, "failed finding method " + meth);
            }
        } catch (Exception xany) {
            xjexl = new JexlException(info, "failed executing method " + meth, xany);
View Full Code Here

        }
        // attempt to reuse last executor cached in volatile JexlNode.value
        if (node != null && cache) {
            Object cached = node.jjtGetValue();
            if (cached instanceof JexlPropertyGet) {
                JexlPropertyGet vg = (JexlPropertyGet) cached;
                Object value = vg.tryInvoke(object, attribute);
                if (!vg.tryFailed(value)) {
                    return value;
                }
            }
        }
        JexlPropertyGet vg = uberspect.getPropertyGet(object, attribute, node);
        if (vg != null) {
            try {
                Object value = vg.invoke(object);
                // cache executor in volatile JexlNode.value
                if (node != null && cache && vg.isCacheable()) {
                    node.jjtSetValue(vg);
                }
                return value;
            } catch (Exception xany) {
                if (node == null) {
View Full Code Here

    protected void setAttribute(Object object, Object attribute, Object value, JexlNode node) {
        // attempt to reuse last executor cached in volatile JexlNode.value
        if (node != null && cache) {
            Object cached = node.jjtGetValue();
            if (cached instanceof JexlPropertySet) {
                JexlPropertySet setter = (JexlPropertySet) cached;
                Object eval = setter.tryInvoke(object, attribute, value);
                if (!setter.tryFailed(eval)) {
                    return;
                }
            }
        }
        JexlException xjexl = null;
        JexlPropertySet vs = uberspect.getPropertySet(object, attribute, value, node);
        if (vs != null) {
            try {
                // cache executor in volatile JexlNode.value
                vs.invoke(object, value);
                if (node != null && cache && vs.isCacheable()) {
                    node.jjtSetValue(vs);
                }
                return;
            } catch (RuntimeException xrt) {
                if (node == null) {
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl2.internal.Introspector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.