예제 #1
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object v1 = children[0].getValue(context, source);
            object v2 = children[1].getValue(context, source);

            return(OgnlOps.operin(v1, v2)? false : true);
        }
예제 #2
0
        protected override void setValueBody(OgnlContext context, object target, object value) // throws OgnlException
        {
            object test   = children[0].getValue(context, target);
            int    branch = OgnlOps.booleanValue(test)? 1 : 2;

            children[branch].setValue(context, target, value);
        }
예제 #3
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object test   = children[0].getValue(context, source);
            int    branch = OgnlOps.booleanValue(test)? 1 : 2;

            return(children[branch].getValue(context, source));
        }
예제 #4
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object v1 = children[0].getValue(context, source);
            object v2 = children[1].getValue(context, source);

            return(OgnlOps.remainder(v1, v2));
        }
예제 #5
0
        /**
         *      Returns OgnlRuntime.NotFound if the property does not exist.
         */
        public object getPossibleProperty(IDictionary context, object target, string name)          // throws OgnlException
        {
            object      result;
            OgnlContext ognlContext = (OgnlContext)context;

            if (context [("_compile")] != null)
            {
                Getter getter = getGetter(ognlContext, target, name);

                if (getter != NotFoundGetter)
                {
                    result = getter.get(ognlContext, target, name);
                }
                else
                {
                    try
                    {
                        result = OgnlRuntime.getFieldValue(ognlContext, target, name, true);
                    }
                    catch (Exception ex)
                    {
                        throw new OgnlException(name, ex);
                    }
                }
            }
            else
            {
                result = base.getPossibleProperty(context, target, name);
            }
            return(result);
        }
예제 #6
0
        protected override object getValueBody(OgnlContext context, object source)
        {
            object result = children[1].getValue(context, source);

            children[0].setValue(context, source, result);
            return(result);
        }
예제 #7
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object result = children[0].getValue(context, source);

            for (int i = 1; i < children.Length; ++i)
            {
                result = OgnlOps.multiply(result, children[i].getValue(context, source));
            }
            return(result);
        }
예제 #8
0
        protected override void setValueBody(OgnlContext context, object target, object value) // throws OgnlException
        {
            int last = children.Length - 1;

            for (int i = 0; i < last; ++i)
            {
                object v = children[i].getValue(context, target);
                if (OgnlOps.booleanValue(v))
                {
                    return;
                }
            }
            children[last].setValue(context, target, value);
        }
예제 #9
0
        protected override void setValueBody(OgnlContext context, object target, object value) // throws OgnlException
        {
            object expr         = children[0].getValue(context, target),
                   previousRoot = context.getRoot();
            Node node;

            target = children[1].getValue(context, target);
            node   = (expr is Node) ? (Node)expr : (Node)Ognl.parseExpression(expr.ToString());
            try {
                context.setRoot(target);
                node.setValue(context, target, value);
            } finally {
                context.setRoot(previousRoot);
            }
        }
예제 #10
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object result = null;
            int    last   = children.Length - 1;

            for (int i = 0; i <= last; ++i)
            {
                result = children[i].getValue(context, source);
                if (i != last && OgnlOps.booleanValue(result))
                {
                    break;
                }
            }
            return(result);
        }
예제 #11
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object[] args = OgnlRuntime.getObjectArrayPool().create(jjtGetNumChildren());
            object   root = context.getRoot();

            try {
                for (int i = 0, icount = args.Length; i < icount; ++i)
                {
                    args[i] = children[i].getValue(context, root);
                }

                return(OgnlRuntime.callStaticMethod(context, className, methodName, args));
            } finally {
                OgnlRuntime.getObjectArrayPool().recycle(args);
            }
        }
예제 #12
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object result,
                   expr         = children[0].getValue(context, source),
                   previousRoot = context.getRoot();
            Node node;

            source = children[1].getValue(context, source);
            node   = (expr is Node) ? (Node)expr : (Node)Ognl.parseExpression(expr.ToString());
            try {
                context.setRoot(source);
                result = node.getValue(context, source);
            } finally {
                context.setRoot(previousRoot);
            }
            return(result);
        }
예제 #13
0
        public static Getter generateGetter(OgnlContext context, string code)         // throws OgnlException
        {
            string className = NAME_FACTORY.getNewClassName();

            try
            {
                ClassPool           pool   = (ClassPool)pools [(context.getClassResolver())];
                EnhancedClassLoader loader = (EnhancedClassLoader)loaders [(context.getClassResolver())];
                CtClass             newClass;
                CtClass             ognlContextClass;
                CtClass             objectClass;
                CtClass             stringClass;
                CtMethod            method;
                byte[] byteCode;
                Type   compiledClass;

                if ((pool == null) || (loader == null))
                {
                    ClassLoader classLoader = new ContextClassLoader(typeof(OgnlContext).getClassLoader(), context);

                    pool = ClassPool.getDefault();
                    pool.insertClassPath(new LoaderClassPath(classLoader));
                    pools.Add(context.getClassResolver(), pool);

                    loader = new EnhancedClassLoader(classLoader);
                    loaders.Add(context.getClassResolver(), loader);
                }

                newClass         = pool.makeClass(className);
                ognlContextClass = pool.get(typeof(OgnlContext).Name);
                objectClass      = pool.get(typeof(object).Name);
                stringClass      = pool.get(typeof(string).Name);

                newClass.addInterface(pool.get(typeof(Getter).Name));
                method = new CtMethod(objectClass, "get", new CtClass[] { ognlContextClass, objectClass, stringClass }, newClass);
                method.setBody("{" + code + "}");
                newClass.addMethod(method);
                byteCode      = newClass.toBytecode();
                compiledClass = loader.defineClass(className, byteCode);
                return((Getter)compiledClass.newInstance());
            }
            catch (Exception ex)
            {
                throw new OgnlException("Cannot create class", ex);
            }
        }
예제 #14
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object[] args = OgnlRuntime.getObjectArrayPool().create(jjtGetNumChildren());

            try {
                object result,
                       root = context.getRoot();

                for (int i = 0, icount = args.Length; i < icount; ++i)
                {
                    args[i] = children[i].getValue(context, root);
                }
                result = OgnlRuntime.callMethod(context, source, methodName, null, args);
                if (result == null)
                {
                    NullHandler nh = OgnlRuntime.getNullHandler(OgnlRuntime.getTargetClass(source));

                    result = nh.nullMethodResult(context, source, methodName, args);
                }
                return(result);
            } finally {
                OgnlRuntime.getObjectArrayPool().recycle(args);
            }
        }
예제 #15
0
 protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
 {
     return(OgnlOps.negate(children[0].getValue(context, source)));
 }
예제 #16
0
        /*===================================================================
        *                                                                       Constructors
        *  ===================================================================*/

        public ContextClassLoader(ClassLoader parentClassLoader, OgnlContext context)
        {
            base(parentClassLoader);
            this.context = context;
        }
예제 #17
0
 public OgnlEvaluator(object fixture)
 {
     this.Fixture = fixture;
     this.OgnlContext = new OgnlContext();
 }
예제 #18
0
 public OgnlEvaluator(object fixture)
 {
     this.Fixture = fixture;
     this.OgnlContext = new OgnlContext();
 }
예제 #19
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object value = children[0].getValue(context, source);

            return(OgnlRuntime.isInstance(context, value, targetType)); // ? Boolean.TRUE : Boolean.FALSE;
        }
예제 #20
0
 protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
 {
     return(context.getRoot());
 }
예제 #21
0
 public virtual void setUp()
 {
     context = (OgnlContext)Ognl.createDefaultContext(null);
 }
예제 #22
0
 protected override void setValueBody(OgnlContext context, object target, object value) // throws OgnlException
 {
     context [name] = value;
 }
예제 #23
0
 public void setUp()
 {
     context = (OgnlContext)Ognl.createDefaultContext(null);
     context.setMemberAccess(new DefaultMemberAccess(true));
 }
예제 #24
0
 protected void setUp()
 {
     context = (OgnlContext)Ognl.createDefaultContext(null);
 }
예제 #25
0
 protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
 {
     return(OgnlOps.booleanValue(children[0].getValue(context, source))? false : true);
 }
예제 #26
0
 protected override void setValueBody(OgnlContext context, object target, object value) // throws OgnlException
 {
     context.setRoot(value);
 }
예제 #27
0
        private Getter getGetter(OgnlContext context, object target, string propertyName)         // throws OgnlException
        {
            Getter      result;
            Type        targetClass = target.GetType();
            IDictionary propertyMap;

            if ((propertyMap = (IDictionary)seenGetMethods.get(targetClass)) == null)
            {
                propertyMap = new HashMap(101);
                seenGetMethods.put(targetClass, propertyMap);
            }
            if ((result = (Getter)propertyMap.get(propertyName)) == null)
            {
                try
                {
                    MethodInfo method = OgnlRuntime.getGetMethod(context, targetClass, propertyName);

                    if (method != null)
                    {
                        if (method.IsPublic)
                        {
                            if (method.ReturnType.IsPrimitive)
                            {
                                propertyMap.Add(propertyName, result = generateGetter(context,
                                                                                      "java.lang.object\t\tresult;\n" +
                                                                                      targetClass.Name + "\t" + "t0 = (" + targetClass.Name + ")$2;\n" +
                                                                                      "\n" +
                                                                                      "try {\n" +
                                                                                      "   result = new " + getPrimitiveWrapperClass(method.ReturnType).Name + "(t0." + method.Name + "());\n" +
                                                                                      "} catch (java.lang.Exception ex) {\n" +
                                                                                      "    throw new java.lang.RuntimeException(ex);\n" +
                                                                                      "}\n" +
                                                                                      "return result;"
                                                                                      ));
                            }
                            else
                            {
                                propertyMap.Add(propertyName, result = generateGetter(context,
                                                                                      "java.lang.object\t\tresult;\n" +
                                                                                      targetClass.Name + "\t" + "t0 = (" + targetClass.Name + ")$2;\n" +
                                                                                      "\n" +
                                                                                      "try {\n" +
                                                                                      "   result = t0." + method.Name + "();\n" +
                                                                                      "} catch (java.lang.Exception ex) {\n" +
                                                                                      "    throw new java.lang.RuntimeException(ex);\n" +
                                                                                      "}\n" +
                                                                                      "return result;"
                                                                                      ));
                            }
                        }
                        else
                        {
                            propertyMap.Add(propertyName, result = DefaultGetter);
                        }
                    }
                    else
                    {
                        propertyMap.Add(propertyName, result = NotFoundGetter);
                    }
                }
                catch (Exception ex)
                {
                    throw new OgnlException("getting getter", ex);
                }
            }
            return(result);
        }