Package org.apache.commons.jexl2.introspection

Examples of org.apache.commons.jexl2.introspection.Uberspect


        Script script;
        Object result;

        Sandbox sandbox = new Sandbox();
        sandbox.white(Foo.class.getName()).execute("");
        Uberspect uber = new SandboxUberspectImpl(null, sandbox);
        JexlEngine sjexl = new JexlEngine(uber, null, null, null);
        sjexl.setStrict(true);

        script = sjexl.createScript(expr);
        result = script.execute(null);
View Full Code Here


        Script script;
        Object result;

        Sandbox sandbox = new Sandbox();
        sandbox.white(Foo.class.getName()).execute("Quux");
        Uberspect uber = new SandboxUberspectImpl(null, sandbox);
        JexlEngine sjexl = new JexlEngine(uber, null, null, null);
        sjexl.setStrict(true);

        script = sjexl.createScript(expr, "foo");
        result = script.execute(null, foo);
View Full Code Here

        Object result;

        Sandbox sandbox = new Sandbox();
        sandbox.white(Foo.class.getName()).read("alias");
        sandbox.get(Foo.class.getName()).read().alias("alias", "ALIAS");
        Uberspect uber = new SandboxUberspectImpl(null, sandbox);
        JexlEngine sjexl = new JexlEngine(uber, null, null, null);
        sjexl.setStrict(true);

        script = sjexl.createScript(expr, "foo");
        result = script.execute(null, foo);
View Full Code Here

        Script script;
        Object result;

        Sandbox sandbox = new Sandbox();
        sandbox.white(Foo.class.getName()).write("alias");
        Uberspect uber = new SandboxUberspectImpl(null, sandbox);
        JexlEngine sjexl = new JexlEngine(uber, null, null, null);
        sjexl.setStrict(true);

        script = sjexl.createScript(expr, "foo", "$0");
        result = script.execute(null, foo, "43");
View Full Code Here

        // only allow call to currentTimeMillis (avoid exit, gc, loadLibrary, etc)
        sandbox.white(System.class.getName()).execute("currentTimeMillis");
        // can not create a new file
        sandbox.black(java.io.File.class.getName()).execute("");

        Uberspect uber = new SandboxUberspectImpl(null, sandbox);
        JexlEngine sjexl = new JexlEngine(uber, null, null, null);
        sjexl.setStrict(true);

        String expr;
        Script script;
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");
View Full Code Here

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

    }

    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");
View Full Code Here

        // tryExecute should fail on different property
        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");
View Full Code Here

        // tryExecute should fail on non-integer property class
        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");
View Full Code Here

            try {
                if (arg instanceof CharSequence) {
                    writer.write(arg.toString());
                } else if (arg != null) {
                    Object[] value = {arg};
                    Uberspect uber = getEngine().getUberspect();
                    JexlMethod method = uber.getMethod(writer, "print", value, null);
                    if (method != null) {
                        method.invoke(writer, value);
                    } else {
                        writer.write(arg.toString());
                    }
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl2.introspection.Uberspect

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.