001    package railo.runtime.interpreter.ref.var;
002    
003    import railo.runtime.PageContext;
004    import railo.runtime.exp.PageException;
005    import railo.runtime.interpreter.VariableInterpreter;
006    import railo.runtime.interpreter.ref.Ref;
007    import railo.runtime.interpreter.ref.RefSupport;
008    import railo.runtime.interpreter.ref.Set;
009    import railo.runtime.interpreter.ref.literal.LString;
010    
011    /**
012     * 
013     */
014    public final class Scope extends RefSupport implements Set {
015            
016            private PageContext pc;
017            private int scope;
018    
019            /**
020         * contructor of the class
021             * @param pc
022             * @param scope
023             */
024            public Scope(PageContext pc, int scope) {
025                    this.pc=pc;
026                    this.scope=scope;
027            }
028            
029            /**
030             * @see railo.runtime.interpreter.ref.Ref#getValue()
031             */
032            public Object getValue() throws PageException {
033                    return VariableInterpreter.scope(pc, scope, false);
034            }
035    
036            /**
037             * @see railo.runtime.interpreter.ref.Ref#getTypeName()
038             */
039            public String getTypeName() {
040                    return "scope";
041            }
042    
043        /**
044         * @see railo.runtime.interpreter.ref.Ref#touchValue()
045         */
046        public Object touchValue() throws PageException {
047            return VariableInterpreter.scope(pc, scope, true);
048        }
049    
050        /**
051         * @see railo.runtime.interpreter.ref.Set#setValue(java.lang.Object)
052         */
053        public Object setValue(Object obj) throws PageException {
054            return pc.undefinedScope().set(getKeyAsString(),obj);
055        }
056    
057        /**
058         * @return scope
059         */
060        public int getScope() {
061            return scope;
062        }
063    
064        /**
065         * @see railo.runtime.interpreter.ref.Set#getParent()
066         */
067        public Ref getParent() throws PageException {
068            return null;
069        }
070    
071        /**
072         * @see railo.runtime.interpreter.ref.Set#getKey()
073         */
074        public Ref getKey() throws PageException {
075            return new LString(getKeyAsString());
076        }
077    
078        /**
079         * @see railo.runtime.interpreter.ref.Set#getKey()
080         */
081        public String getKeyAsString() throws PageException {
082            //return ScopeFactory.toStringScope(scope,null);
083            return VariableInterpreter.scopeInt2String(scope);
084        }
085    }