예제 #1
0
        /// <summary>  returns the value of the reference.  Generally, this is only
        /// called for dynamic proxies, as the static ones should have
        /// been stored in the VMContext's localContext store
        /// *
        /// </summary>
        /// <param name="context">Context to use for getting current value
        /// </param>
        /// <returns>Object value
        /// *
        ///
        /// </returns>
        public Object getObject(IInternalContextAdapter context)
        {
            try
            {
                /*
                 *  we need to output based on our type
                 */

                Object retObject = null;

                if (type == ParserTreeConstants.REFERENCE)
                {
                    /*
                     *  two cases :  scalar reference ($foo) or multi-level ($foo.bar....)
                     */

                    if (numTreeChildren == 0)
                    {
                        /*
                         *  if I am a single-level reference, can I not get get it out of my context?
                         */

                        retObject = context.Get(singleLevelRef);
                    }
                    else
                    {
                        /*
                         *  I need to let the AST produce it for me.
                         */

                        retObject = nodeTree.Execute(null, context);
                    }
                }
                else if (type == ParserTreeConstants.OBJECT_ARRAY)
                {
                    retObject = nodeTree.Value(context);
                }
                else if (type == ParserTreeConstants.INTEGER_RANGE)
                {
                    retObject = nodeTree.Value(context);
                }
                else if (type == ParserTreeConstants.TRUE)
                {
                    retObject = staticObject;
                }
                else if (type == ParserTreeConstants.FALSE)
                {
                    retObject = staticObject;
                }
                else if (type == ParserTreeConstants.STRING_LITERAL)
                {
                    retObject = nodeTree.Value(context);
                }
                else if (type == ParserTreeConstants.NUMBER_LITERAL)
                {
                    retObject = staticObject;
                }
                else if (type == ParserTreeConstants.TEXT)
                {
                    /*
                     *  this really shouldn't happen.  text is just a throwaway arg for #foreach()
                     */

                    try
                    {
                        StringWriter writer = new StringWriter();
                        nodeTree.Render(context, writer);

                        retObject = writer;
                    }
                    catch (System.Exception e)
                    {
                        runtimeServices.Error(string.Format("VMProxyArg.getObject() : error rendering reference : {0}", e));
                    }
                }
                else if (type == GENERALSTATIC)
                {
                    retObject = staticObject;
                }
                else
                {
                    runtimeServices.Error(
                        string.Format("Unsupported VM arg type : VM arg = {0} type = {1}( VMProxyArg.getObject() )", callerReference, type));
                }

                return(retObject);
            }
            catch (MethodInvocationException mie)
            {
                /*
                 *  not ideal, but otherwise we propagate out to the
                 *  VMContext, and the Context interface's put/get
                 *  don't throw. So this is a the best compromise
                 *  I can think of
                 */

                runtimeServices.Error(string.Format("VMProxyArg.getObject() : method invocation error getting value : {0}", mie));

                return(null);
            }
        }