コード例 #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
ファイル: ASTMultiply.cs プロジェクト: KidFashion/OGNL.Net
        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
ファイル: ASTOr.cs プロジェクト: KidFashion/OGNL.Net
        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
ファイル: ASTEval.cs プロジェクト: KidFashion/OGNL.Net
        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
ファイル: ASTOr.cs プロジェクト: KidFashion/OGNL.Net
        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
ファイル: ASTEval.cs プロジェクト: KidFashion/OGNL.Net
        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
ファイル: ASTMethod.cs プロジェクト: KidFashion/OGNL.Net
        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
ファイル: ASTNegate.cs プロジェクト: KidFashion/OGNL.Net
 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
ファイル: ASTRootVarRef.cs プロジェクト: KidFashion/OGNL.Net
 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
ファイル: ASTVarRef.cs プロジェクト: KidFashion/OGNL.Net
 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
ファイル: ASTRootVarRef.cs プロジェクト: KidFashion/OGNL.Net
 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);
        }