Ejemplo n.º 1
0
        /// <summary> The Context interface which goes out and gets values from the session
        /// Expressions use this interface as a means of evaluation.
        ///
        /// We also use this to create a reference to internal variables.
        /// </summary>
        public virtual Object lookup(Object o)
        {
            Object result = null;

            try
            {
                // first see if it is an internal property (avoids player calls)
                if (o is String && ((String)o)[0] == '$')
                {
                    String key   = (String)o;
                    Object value = null;

                    try
                    {
                        value = m_cache.get_Renamed(key);
                    }
                    catch (Exception)
                    {
                    }
                    result = new InternalProperty(key, value);
                }
                // attempt to resolve to a player variable
                else if ((result = resolveToVariable(o)) != null)
                {
                }
                // or value
                else if ((result = resolveToValue(o)) != null)
                {
                }
                else
                {
                    throw new NoSuchVariableException(o);
                }

                // take on the path to the variable; so 'what' command prints something nice
                if ((result != null) && result is VariableFacade)
                {
                    ((VariableFacade)result).Path = getName();
                }

                // if the attempt to get the variable's value threw an exception inside the
                // player (most likely because the variable is actually a getter, and the
                // getter threw something), then throw something here
                Value resultValue = null;
                if (result is Variable)
                {
                    resultValue = ((Variable)result).getValue();
                }
                else if (result is Value)
                {
                    resultValue = (Value)result;
                }
                if (resultValue != null)
                {
                    if (resultValue.isAttributeSet(ValueAttribute.IS_EXCEPTION))
                    {
                        String value = resultValue.ValueAsString;
                        throw new PlayerFaultException(new ExceptionFault(value));
                    }
                }
            }
            catch (PlayerDebugException)
            {
                result = null;                 // null object
            }
            return(result);
        }