001 package railo.runtime; 002 003 import java.util.Iterator; 004 import java.util.Set; 005 006 import railo.runtime.component.Member; 007 import railo.runtime.dump.DumpData; 008 import railo.runtime.dump.DumpProperties; 009 import railo.runtime.exp.PageException; 010 import railo.runtime.type.Collection; 011 import railo.runtime.type.Struct; 012 import railo.runtime.type.StructImpl; 013 import railo.runtime.type.UDF; 014 import railo.runtime.type.dt.DateTime; 015 import railo.runtime.type.util.ComponentUtil; 016 import railo.runtime.type.util.KeyConstants; 017 import railo.runtime.type.util.StructSupport; 018 import railo.runtime.type.util.StructUtil; 019 020 /** 021 * 022 */ 023 public final class ComponentScopeThis extends StructSupport implements ComponentScope { 024 025 private final ComponentImpl component; 026 private static final int access=Component.ACCESS_PRIVATE; 027 028 /** 029 * constructor of the class 030 * @param component 031 */ 032 public ComponentScopeThis(ComponentImpl component) { 033 this.component=component; 034 } 035 036 @Override 037 public void initialize(PageContext pc) { 038 039 } 040 041 @Override 042 public void release() {} 043 044 @Override 045 public void release(PageContext pc) {} 046 047 @Override 048 public int getType() { 049 return SCOPE_VARIABLES; 050 } 051 052 @Override 053 public String getTypeAsString() { 054 return "variables"; 055 } 056 057 @Override 058 public int size() { 059 return component.size(access)+1; 060 } 061 062 @Override 063 public Collection.Key[] keys() { 064 Set<Key> keySet = component.keySet(access); 065 keySet.add(KeyConstants._this); 066 Collection.Key[] arr = new Collection.Key[keySet.size()]; 067 Iterator<Key> it = keySet.iterator(); 068 069 int index=0; 070 while(it.hasNext()){ 071 arr[index++]=it.next(); 072 } 073 return arr; 074 } 075 076 @Override 077 public Object remove(Collection.Key key) throws PageException { 078 return component.remove(key); 079 } 080 081 @Override 082 public Object removeEL(Collection.Key key) { 083 return component.removeEL(key); 084 } 085 086 @Override 087 public void clear() { 088 component.clear(); 089 } 090 091 @Override 092 public Object get(Key key) throws PageException { 093 if(key.equalsIgnoreCase(KeyConstants._THIS)){ 094 return component.top; 095 } 096 return component.get(access,key); 097 } 098 099 @Override 100 public Object get(Collection.Key key, Object defaultValue) { 101 if(key.equalsIgnoreCase(KeyConstants._THIS)){ 102 return component.top; 103 } 104 return component.get(access,key,defaultValue); 105 } 106 107 @Override 108 public Object set(Collection.Key key, Object value) throws PageException { 109 return component.set(key,value); 110 } 111 112 @Override 113 public Object setEL(Collection.Key key, Object value) { 114 return component.setEL(key,value); 115 } 116 117 @Override 118 public Iterator<Collection.Key> keyIterator() { 119 return component.keyIterator(access); 120 } 121 122 @Override 123 public Iterator<String> keysAsStringIterator() { 124 return component.keysAsStringIterator(access); 125 } 126 127 @Override 128 public Iterator<Entry<Key, Object>> entryIterator() { 129 return component.entryIterator(access); 130 } 131 132 @Override 133 public Iterator<Object> valueIterator() { 134 return component.valueIterator(access); 135 } 136 137 @Override 138 public boolean containsKey(Key key) { 139 return get(key,null)!=null; 140 } 141 142 @Override 143 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 144 return StructUtil.toDumpTable(this, "Variable Scope (of Component)", pageContext, maxlevel, dp); 145 } 146 147 @Override 148 public String castToString() throws PageException { 149 return component.castToString(); 150 } 151 152 @Override 153 public String castToString(String defaultValue) { 154 return component.castToString(defaultValue); 155 } 156 157 @Override 158 public boolean castToBooleanValue() throws PageException { 159 return component.castToBooleanValue(); 160 } 161 162 @Override 163 public Boolean castToBoolean(Boolean defaultValue) { 164 return component.castToBoolean(defaultValue); 165 } 166 167 @Override 168 public double castToDoubleValue() throws PageException { 169 return component.castToDoubleValue(); 170 } 171 172 @Override 173 public double castToDoubleValue(double defaultValue) { 174 return component.castToDoubleValue(defaultValue); 175 } 176 177 @Override 178 public DateTime castToDateTime() throws PageException { 179 return component.castToDateTime(); 180 } 181 182 @Override 183 public DateTime castToDateTime(DateTime defaultValue) { 184 return component.castToDateTime(defaultValue); 185 } 186 187 188 @Override 189 public int compareTo(boolean b) throws PageException { 190 return component.compareTo(b); 191 } 192 193 @Override 194 public int compareTo(DateTime dt) throws PageException { 195 return component.compareTo(dt); 196 } 197 198 @Override 199 public int compareTo(double d) throws PageException { 200 return component.compareTo(d); 201 } 202 203 @Override 204 public int compareTo(String str) throws PageException { 205 return component.compareTo(str); 206 } 207 208 @Override 209 public Collection duplicate(boolean deepCopy) { 210 211 StructImpl sct = new StructImpl(); 212 StructImpl.copy(this, sct, deepCopy); 213 return sct; 214 } 215 216 /** 217 * Returns the value of component. 218 * @return value component 219 */ 220 public Component getComponent() { 221 return component; 222 } 223 224 /*public Object get(PageContext pc, String key, Object defaultValue) { 225 return component.get(access,key,defaultValue); 226 }*/ 227 228 @Override 229 public Object get(PageContext pc, Collection.Key key, Object defaultValue) { 230 return component.get(access,key,defaultValue); 231 } 232 233 /*public Object get(PageContext pc, String key) throws PageException { 234 return component.get(access,key); 235 }*/ 236 237 @Override 238 public Object get(PageContext pc, Collection.Key key) throws PageException { 239 return component.get(access,key); 240 } 241 242 /*public Object set(PageContext pc, String propertyName, Object value) throws PageException { 243 return component.set(propertyName,value); 244 }*/ 245 246 @Override 247 public Object set(PageContext pc, Collection.Key propertyName, Object value) throws PageException { 248 return component.set(propertyName,value); 249 } 250 251 /*public Object setEL(PageContext pc, String propertyName, Object value) { 252 return component.setEL(propertyName,value); 253 }*/ 254 255 @Override 256 public Object setEL(PageContext pc, Collection.Key propertyName, Object value) { 257 return component.setEL(propertyName,value); 258 } 259 260 /*public Object call(PageContext pc, String key, Object[] arguments) throws PageException { 261 return call(pc, KeyImpl.init(key), arguments); 262 }*/ 263 264 public Object call(PageContext pc, Collection.Key key, Object[] arguments) throws PageException { 265 Member m = component.getMember(access, key, false,false); 266 if(m!=null) { 267 if(m instanceof UDF) return ((UDF)m).call(pc, arguments, false); 268 throw ComponentUtil.notFunction(component, key, m.getValue(),access); 269 } 270 throw ComponentUtil.notFunction(component, key, null,access); 271 } 272 273 /*public Object callWithNamedValues(PageContext pc, String key, Struct args) throws PageException { 274 return callWithNamedValues(pc, KeyImpl.init(key), args); 275 }*/ 276 277 public Object callWithNamedValues(PageContext pc, Collection.Key key, Struct args) throws PageException { 278 Member m = component.getMember(access, key, false,false); 279 if(m!=null) { 280 if(m instanceof UDF) return ((UDF)m).callWithNamedValues(pc, args, false); 281 throw ComponentUtil.notFunction(component, key, m.getValue(),access); 282 } 283 throw ComponentUtil.notFunction(component, key, null,access); 284 } 285 286 @Override 287 public boolean isInitalized() { 288 return component.isInitalized(); 289 } 290 291 @Override 292 public void setBind(boolean bind) {} 293 294 @Override 295 public boolean isBind() { 296 return true; 297 } 298 }