Exemplo n.º 1
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            Node              expr             = children[0];
            IList             answer           = new ArrayList();
            IElementsAccessor elementsAccessor = OgnlRuntime.getElementsAccessor(OgnlRuntime.getTargetClass(source));

            for (IEnumerator e = elementsAccessor.getElements(source); e.MoveNext();)
            {
                object next = e.Current;

                if (OgnlOps.booleanValue(expr.getValue(context, next)))
                {
                    answer.Add(next);
                }
            }
            return(answer);
        }
Exemplo n.º 2
0
        public object this [object key]
        {
            get
            {
                object result;

                if (RESERVED_KEYS.Contains(key))
                {
                    if (key.Equals(OgnlContext.THIS_CONTEXT_KEY))
                    {
                        result = getCurrentObject();
                    }
                    else
                    {
                        if (key.Equals(OgnlContext.ROOT_CONTEXT_KEY))
                        {
                            result = getRoot();
                        }
                        else
                        {
                            if (key.Equals(OgnlContext.CONTEXT_CONTEXT_KEY))
                            {
                                result = this;
                            }
                            else
                            {
                                if (key.Equals(OgnlContext.TRACE_EVALUATIONS_CONTEXT_KEY))
                                {
                                    result = getTraceEvaluations() ? true : false;
                                }
                                else
                                {
                                    if (key.Equals(OgnlContext.LAST_EVALUATION_CONTEXT_KEY))
                                    {
                                        result = getLastEvaluation();
                                    }
                                    else
                                    {
                                        if (key.Equals(OgnlContext.KEEP_LAST_EVALUATION_CONTEXT_KEY))
                                        {
                                            result = getKeepLastEvaluation() ? true : false;
                                        }
                                        else
                                        {
                                            if (key.Equals(OgnlContext.CLASS_RESOLVER_CONTEXT_KEY))
                                            {
                                                result = getClassResolver();
                                            }
                                            else
                                            {
                                                if (key.Equals(OgnlContext.TYPE_CONVERTER_CONTEXT_KEY))
                                                {
                                                    result = getTypeConverter();
                                                }
                                                else
                                                {
                                                    if (key.Equals(OgnlContext.MEMBER_ACCESS_CONTEXT_KEY))
                                                    {
                                                        result = getMemberAccess();
                                                    }
                                                    else
                                                    {
                                                        throw new ArgumentException("unknown reserved key '" + key + "'");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    result = values [key];
                }
                return(result);
            }
            set
            {
                object result;

                if (RESERVED_KEYS.Contains(key))
                {
                    if (key.Equals(OgnlContext.THIS_CONTEXT_KEY))
                    {
                        result = getCurrentObject();
                        setCurrentObject(value);
                    }
                    else
                    {
                        if (key.Equals(OgnlContext.ROOT_CONTEXT_KEY))
                        {
                            result = getRoot();
                            setRoot(value);
                        }
                        else
                        {
                            if (key.Equals(OgnlContext.CONTEXT_CONTEXT_KEY))
                            {
                                throw new ArgumentException("can't change " + OgnlContext.CONTEXT_CONTEXT_KEY + " in context");
                            }
                            else
                            {
                                if (key.Equals(OgnlContext.TRACE_EVALUATIONS_CONTEXT_KEY))
                                {
                                    result = getTraceEvaluations() ? true : false;
                                    setTraceEvaluations(OgnlOps.booleanValue(value));
                                }
                                else
                                {
                                    if (key.Equals(OgnlContext.LAST_EVALUATION_CONTEXT_KEY))
                                    {
                                        result         = getLastEvaluation();
                                        lastEvaluation = (Evaluation)value;
                                    }
                                    else
                                    {
                                        if (key.Equals(OgnlContext.KEEP_LAST_EVALUATION_CONTEXT_KEY))
                                        {
                                            result = getKeepLastEvaluation() ? true : false;
                                            setKeepLastEvaluation(OgnlOps.booleanValue(value));
                                        }
                                        else
                                        {
                                            if (key.Equals(OgnlContext.CLASS_RESOLVER_CONTEXT_KEY))
                                            {
                                                result = getClassResolver();
                                                setClassResolver((ClassResolver)value);
                                            }
                                            else
                                            {
                                                if (key.Equals(OgnlContext.TYPE_CONVERTER_CONTEXT_KEY))
                                                {
                                                    result = getTypeConverter();
                                                    setTypeConverter((TypeConverter)value);
                                                }
                                                else
                                                {
                                                    if (key.Equals(OgnlContext.MEMBER_ACCESS_CONTEXT_KEY))
                                                    {
                                                        result = getMemberAccess();
                                                        setMemberAccess((MemberAccess)value);
                                                    }
                                                    else
                                                    {
                                                        throw new ArgumentException("unknown reserved key '" + key + "'");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    // result =
                    values.Add(key, value);
                }
                // return result;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Use <see cref="OgnlOps.convertValue"/>.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="value"></param>
 /// <param name="toType"></param>
 /// <returns></returns>
 public virtual object convertValue(IDictionary context, object value, Type toType)
 {
     return(OgnlOps.convertValue(value, toType));
 }
Exemplo n.º 4
0
 public NumberEnumerator(object target)
 {
     type   = OgnlOps.getNumericType(target);
     finish = OgnlOps.longValue(target);
 }
Exemplo n.º 5
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object result,
                   root = context.getRoot();
            int count   = jjtGetNumChildren();

            object[] args = OgnlRuntime.getObjectArrayPool().create(count);

            try {
                for (int i = 0; i < count; ++i)
                {
                    args[i] = children[i].getValue(context, root);
                }
                if (isArray)
                {
                    if (args.Length == 1)
                    {
                        try {
                            Type  componentClass = OgnlRuntime.classForName(context, className);
                            IList sourceList     = null;
                            int   size;

                            if (args[0] is IList)
                            {
                                sourceList = (IList)args[0];
                                size       = sourceList.Count;
                            }
                            else
                            {
                                size = (int)OgnlOps.longValue(args[0]);
                            }
                            result = Array.CreateInstance(componentClass, size);
                            if (sourceList != null)
                            {
                                TypeConverter converter = context.getTypeConverter();

                                for (int i = 0, icount = sourceList.Count; i < icount; i++)
                                {
                                    object o = sourceList [i];

                                    if ((o == null) || componentClass.IsInstanceOfType(o))
                                    {
                                        ((Array)result).SetValue(o, i);
                                    }
                                    else
                                    {
                                        ((Array)result).SetValue(converter.convertValue(context, null, null, null, o, componentClass), i);
                                    }
                                }
                            }
                        } catch (TypeLoadException ex) {
                            throw new OgnlException("array component class '" + className + "' not found", ex);
                        }
                    }
                    else
                    {
                        throw new OgnlException("only expect array size or fixed initializer list");
                    }
                }
                else
                {
                    result = OgnlRuntime.callConstructor(context, className, args);
                }

                return(result);
            } finally {
                OgnlRuntime.getObjectArrayPool().recycle(args);
            }
        }