Пример #1
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            if (indexedAccess && children [0] is ASTSequence)
            {
                // As property [index1, index2]...
                // Use Indexer.
                object [] indexParameters = ((ASTSequence)children [0]).getValues(context, context.getRoot());

                /* return IndexerAccessor.getIndexerValue (source, indexParameters) ; */
                return(OgnlRuntime.getIndxerValue(context, source, "Indexer", indexParameters));
            }
            object result;

            object property = getProperty(context, source);
            Node   indexSibling;

            result = OgnlRuntime.getProperty(context, source, property);
            if (result == null)
            {
                result = OgnlRuntime.getNullHandler(OgnlRuntime.getTargetClass(source)).nullPropertyValue(context, source, property);
            }
            return(result);
        }
Пример #2
0
        protected override void setValueBody(OgnlContext context, object target, object value) // throws OgnlException
        {
            if (indexedAccess && children [0] is ASTSequence)
            {
                // As property [index1, index2]...
                // Use Indexer.
                object [] indexParameters = ((ASTSequence)children [0]).getValues(context, context.getRoot());

                /*IndexerAccessor.setIndexerValue (target, value ,indexParameters) ;*/
                OgnlRuntime.setIndxerValue(context, target, "Indexer", value, indexParameters);
                return;
            }

            OgnlRuntime.setProperty(context, target, getProperty(context, target), value);
        }
Пример #3
0
 public object getProperty(OgnlContext context, object source)   // throws OgnlException
 {
     return(children[0].getValue(context, context.getRoot()));
 }
Пример #4
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);
            }
        }