001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.interpreter.ref.var; 020 021import lucee.runtime.PageContext; 022import lucee.runtime.exp.PageException; 023import lucee.runtime.interpreter.VariableInterpreter; 024import lucee.runtime.interpreter.ref.Ref; 025import lucee.runtime.interpreter.ref.RefSupport; 026import lucee.runtime.interpreter.ref.Set; 027import lucee.runtime.interpreter.ref.literal.LString; 028 029/** 030 * 031 */ 032public final class Scope extends RefSupport implements Set { 033 034 private int scope; 035 036 /** 037 * contructor of the class 038 * @param pc 039 * @param scope 040 */ 041 public Scope(int scope) { 042 this.scope=scope; 043 } 044 045 @Override 046 public Object getValue(PageContext pc) throws PageException { 047 return VariableInterpreter.scope(pc, scope, false); 048 } 049 050 @Override 051 public String getTypeName() { 052 return "scope"; 053 } 054 055 @Override 056 public Object touchValue(PageContext pc) throws PageException { 057 return VariableInterpreter.scope(pc, scope, true); 058 } 059 060 @Override 061 public Object setValue(PageContext pc,Object obj) throws PageException { 062 return pc.undefinedScope().set(getKeyAsString(pc),obj); 063 } 064 065 /** 066 * @return scope 067 */ 068 public int getScope() { 069 return scope; 070 } 071 072 @Override 073 public Ref getParent(PageContext pc) throws PageException { 074 return null; 075 } 076 077 @Override 078 public Ref getKey(PageContext pc) throws PageException { 079 return new LString(getKeyAsString(pc)); 080 } 081 082 @Override 083 public String getKeyAsString(PageContext pc) throws PageException { 084 //return ScopeFactory.toStringScope(scope,null); 085 return VariableInterpreter.scopeInt2String(scope); 086 } 087}