Examples of Uberspect


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

        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

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

        // 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

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

        }
    }


    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

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

        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

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

        // 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

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

        // 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

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

            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

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

        return null;
      }
    };

    // uberspect that prevents access to .class and .getClass()
    Uberspect uberspect = new UberspectImpl(LogFactory.getLog(JexlEngine.class)) {
      @Override
      public JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfo info) {
        if ("class".equals(identifier)) {
          return null;
        }
View Full Code Here

Examples of org.apache.velocity.util.introspection.Uberspect

                log.error(err);
                throw new Exception(err);
            }

            Uberspect u = (Uberspect)o;

            if (u instanceof UberspectLoggable)
            {
                ((UberspectLoggable)u).setLog(getLog());
            }
View Full Code Here

Examples of org.apache.velocity.util.introspection.Uberspect

                log.error(err);
                throw new Exception(err);
            }

            Uberspect u = (Uberspect)o;

            if (u instanceof UberspectLoggable)
            {
                ((UberspectLoggable)u).setLog(getLog());
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.