001    package railo.runtime.type.scope;
002    
003    import java.util.Iterator;
004    import java.util.List;
005    import java.util.Map;
006    import java.util.Set;
007    
008    import railo.runtime.PageContext;
009    import railo.runtime.dump.DumpData;
010    import railo.runtime.dump.DumpProperties;
011    import railo.runtime.exp.CasterException;
012    import railo.runtime.exp.PageException;
013    import railo.runtime.exp.PageRuntimeException;
014    import railo.runtime.op.Caster;
015    import railo.runtime.type.Collection;
016    import railo.runtime.type.KeyImpl;
017    import railo.runtime.type.Sizeable;
018    import railo.runtime.type.Struct;
019    import railo.runtime.type.dt.DateTime;
020    import railo.runtime.type.util.StructUtil;
021    
022    public final class ArgumentThreadImpl implements ArgumentPro,Sizeable {
023    
024            private final Struct sct;
025    
026            public ArgumentThreadImpl(Struct sct){
027                    this.sct=sct;
028            }
029            
030            /**
031             * @see railo.runtime.type.scope.ArgumentPro#getFunctionArgument(java.lang.String, java.lang.Object)
032             */
033            public Object getFunctionArgument(String key, Object defaultValue) {
034                    return sct.get(key,defaultValue);
035            }
036    
037            /**
038             * @see railo.runtime.type.scope.ArgumentPro#getFunctionArgument(railo.runtime.type.Collection.Key, java.lang.Object)
039             */
040            public Object getFunctionArgument(Key key, Object defaultValue) {
041                    return sct.get(key,defaultValue);
042            }
043            
044    
045    
046            /**
047             * @see railo.runtime.type.scope.ArgumentPro#containsFunctionArgumentKey(railo.runtime.type.Collection.Key)
048             */
049            public boolean containsFunctionArgumentKey(Key key) {
050                    return sct.containsKey(key);
051            }
052    
053            public Object setArgument(Object obj) throws PageException {
054                    // TODO Auto-generated method stub
055                    return null;
056            }
057    
058            /**
059             * @see railo.runtime.type.scope.ArgumentPro#setFunctionArgumentNames(java.util.Set)
060             */
061            public void setFunctionArgumentNames(Set functionArgumentNames) {
062                    
063            }
064    
065            public boolean insert(int index, String key, Object value) throws PageException {
066                    // TODO Auto-generated method stub
067                    return false;
068            }
069    
070            /**
071             * @see railo.runtime.type.scope.Argument#isBind()
072             */
073            public boolean isBind() {
074                    return true;
075            }
076    
077            /**
078             * @see railo.runtime.type.scope.Argument#setBind(boolean)
079             */
080            public void setBind(boolean bind) {
081                    
082            }
083    
084            /**
085             * @see railo.runtime.type.Scope#getType()
086             */
087            public int getType() {
088                    return SCOPE_ARGUMENTS;
089            }
090    
091            /**
092             * @see railo.runtime.type.Scope#getTypeAsString()
093             */
094            public String getTypeAsString() {
095                    return "arguments";
096            }
097    
098            /**
099             * @see railo.runtime.type.Scope#initialize(railo.runtime.PageContext)
100             */
101            public void initialize(PageContext pc) {
102            }
103    
104            /**
105             * @see railo.runtime.type.Scope#isInitalized()
106             */
107            public boolean isInitalized() {
108                    return true;
109            }
110    
111            /**
112             * @see railo.runtime.type.Scope#release()
113             */
114            public void release() {}
115    
116            /**
117             * @see railo.runtime.type.Collection#clear()
118             */
119            public void clear() {
120                    sct.clear();
121            }
122    
123            /**
124             * @see railo.runtime.type.Collection#containsKey(java.lang.String)
125             */
126            public boolean containsKey(String key) {
127                    return sct.containsKey(key);
128            }
129    
130            /**
131             * @see railo.runtime.type.Collection#containsKey(railo.runtime.type.Collection.Key)
132             */
133            public boolean containsKey(Key key) {
134                    return sct.containsKey(key);
135            }
136    
137            /**
138             * @see railo.runtime.type.Collection#duplicate(boolean)
139             */
140            public Collection duplicate(boolean deepCopy) {
141                    return new ArgumentThreadImpl((Struct)sct.duplicate(deepCopy));
142            }
143    
144            /**
145             * @see railo.runtime.type.Collection#get(java.lang.String)
146             */
147            public Object get(String key) throws PageException {
148                    return sct.get(key);
149            }
150    
151            /**
152             * @see railo.runtime.type.Collection#get(railo.runtime.type.Collection.Key)
153             */
154            public Object get(Key key) throws PageException {
155                    return sct.get(key);
156            }
157    
158            /**
159             * @see railo.runtime.type.Collection#get(java.lang.String, java.lang.Object)
160             */
161            public Object get(String key, Object defaultValue) {
162                    return sct.get(key, defaultValue);
163            }
164    
165            /**
166             * @see railo.runtime.type.Collection#get(railo.runtime.type.Collection.Key, java.lang.Object)
167             */
168            public Object get(Key key, Object defaultValue) {
169                    return sct.get(key, defaultValue);
170            }
171    
172            /**
173             * @see railo.runtime.type.Collection#keys()
174             */
175            public Key[] keys() {
176                    return sct.keys();
177            }
178    
179            /**
180             * @see railo.runtime.type.Collection#keysAsString()
181             */
182            public String[] keysAsString() {
183                    return sct.keysAsString();
184            }
185    
186            /**
187             * @see railo.runtime.type.Collection#remove(railo.runtime.type.Collection.Key)
188             */
189            public Object remove(Key key) throws PageException {
190                    return sct.remove(key);
191            }
192    
193            /**
194             * @see railo.runtime.type.Collection#removeEL(railo.runtime.type.Collection.Key)
195             */
196            public Object removeEL(Key key) {
197                    return sct.removeEL(key);
198            }
199    
200            /**
201             * @see railo.runtime.type.Collection#set(java.lang.String, java.lang.Object)
202             */
203            public Object set(String key, Object value) throws PageException {
204                    return sct.set(key, value);
205            }
206    
207            /**
208             * @see railo.runtime.type.Collection#set(railo.runtime.type.Collection.Key, java.lang.Object)
209             */
210            public Object set(Key key, Object value) throws PageException {
211                    return sct.set(key, value);
212            }
213    
214            /**
215             * @see railo.runtime.type.Collection#setEL(java.lang.String, java.lang.Object)
216             */
217            public Object setEL(String key, Object value) {
218                    return sct.setEL(key, value);
219            }
220    
221            /**
222             * @see railo.runtime.type.Collection#setEL(railo.runtime.type.Collection.Key, java.lang.Object)
223             */
224            public Object setEL(Key key, Object value) {
225                    return sct.setEL(key, value);
226            }
227    
228            /**
229             * @see railo.runtime.type.Collection#size()
230             */
231            public int size() {
232                    return sct.size();
233            }
234    
235            /**
236             * @see railo.runtime.dump.Dumpable#toDumpData(railo.runtime.PageContext, int, railo.runtime.dump.DumpProperties)
237             */
238            public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties properties) {
239                    return sct.toDumpData(pageContext, maxlevel, properties);
240            }
241    
242            /**
243             * @see railo.runtime.type.Iteratorable#iterator()
244             */
245            public Iterator iterator() {
246                    return sct.iterator();
247            }
248    
249            /**
250             * @see railo.runtime.type.Iteratorable#keyIterator()
251             */
252            public Iterator keyIterator() {
253                    return sct.keyIterator();
254            }
255    
256            /**
257             * @see railo.runtime.type.Iteratorable#valueIterator()
258             */
259            public Iterator valueIterator() {
260                    return sct.valueIterator();
261            }
262    
263            public Boolean castToBoolean(Boolean defaultValue) {
264                    return sct.castToBoolean(defaultValue);
265            }
266    
267            /**
268             * @see railo.runtime.op.Castable#castToBooleanValue()
269             */
270            public boolean castToBooleanValue() throws PageException {
271                    return sct.castToBooleanValue();
272            }
273    
274            /**
275             * @see railo.runtime.op.Castable#castToDateTime()
276             */
277            public DateTime castToDateTime() throws PageException {
278                    return sct.castToDateTime();
279            }
280    
281            /**
282             * @see railo.runtime.op.Castable#castToDateTime(railo.runtime.type.dt.DateTime)
283             */
284            public DateTime castToDateTime(DateTime defaultValue) {
285                    return sct.castToDateTime(defaultValue);
286            }
287    
288            /**
289             * @see railo.runtime.op.Castable#castToDoubleValue()
290             */
291            public double castToDoubleValue() throws PageException {
292                    return sct.castToDoubleValue();
293            }
294    
295            /**
296             * @see railo.runtime.op.Castable#castToDoubleValue(double)
297             */
298            public double castToDoubleValue(double defaultValue) {
299                    return sct.castToDoubleValue(defaultValue);
300            }
301    
302            /**
303             * @see railo.runtime.op.Castable#castToString()
304             */
305            public String castToString() throws PageException {
306                    return sct.castToString();
307            }
308    
309            /**
310             * @see railo.runtime.op.Castable#castToString(java.lang.String)
311             */
312            public String castToString(String defaultValue) {
313                    return sct.castToString(defaultValue);
314            }
315    
316            /**
317             * @see railo.runtime.op.Castable#compareTo(java.lang.String)
318             */
319            public int compareTo(String str) throws PageException {
320                    return sct.compareTo(str);
321            }
322    
323            /**
324             * @see railo.runtime.op.Castable#compareTo(boolean)
325             */
326            public int compareTo(boolean b) throws PageException {
327                    return sct.compareTo(b);
328            }
329    
330            /**
331             * @see railo.runtime.op.Castable#compareTo(double)
332             */
333            public int compareTo(double d) throws PageException {
334                    return sct.compareTo(d);
335            }
336    
337            /**
338             * @see railo.runtime.op.Castable#compareTo(railo.runtime.type.dt.DateTime)
339             */
340            public int compareTo(DateTime dt) throws PageException {
341                    return sct.compareTo(dt);
342            }
343    
344            /**
345             * @see java.util.Map#containsKey(java.lang.Object)
346             */
347            public boolean containsKey(Object key) {
348                    return sct.containsKey(key);
349            }
350    
351            /**
352             * @see java.util.Map#containsValue(java.lang.Object)
353             */
354            public boolean containsValue(Object value) {
355                    return sct.containsValue(value);
356            }
357    
358            /**
359             * @see java.util.Map#entrySet()
360             */
361            public Set entrySet() {
362                    return sct.entrySet();
363            }
364    
365            /**
366             * @see java.util.Map#get(java.lang.Object)
367             */
368            public Object get(Object key) {
369                    return sct.get(key);
370            }
371    
372            /**
373             * @see java.util.Map#isEmpty()
374             */
375            public boolean isEmpty() {
376                    return sct.isEmpty();
377            }
378    
379            /**
380             * @see java.util.Map#keySet()
381             */
382            public Set keySet() {
383                    return sct.keySet();
384            }
385    
386            /**
387             * @see java.util.Map#put(java.lang.Object, java.lang.Object)
388             */
389            public Object put(Object key, Object value) {
390                    return sct.put(key, value);
391            }
392    
393            /**
394             * @see java.util.Map#putAll(java.util.Map)
395             */
396            public void putAll(Map m) {
397                    sct.putAll(m);
398            }
399    
400            /**
401             * @see java.util.Map#remove(java.lang.Object)
402             */
403            public Object remove(Object key) {
404                    return sct.remove(key);
405            }
406    
407            
408            /**
409             * @see java.util.Map#values()
410             */
411            public java.util.Collection values() {
412                    return sct.values();
413            }
414    
415            /**
416             * @see railo.runtime.type.Array#append(java.lang.Object)
417             */
418            public Object append(Object o) throws PageException {
419                    throw new CasterException(sct,"Array");
420            }
421    
422            /**
423             * @see railo.runtime.type.Array#appendEL(java.lang.Object)
424             */
425            public Object appendEL(Object o) {
426                    throw new PageRuntimeException(new CasterException(sct,"Array"));
427            }
428    
429            /**
430             * @see railo.runtime.type.Array#containsKey(int)
431             */
432            public boolean containsKey(int key) {
433                    return sct.containsKey(KeyImpl.init(Caster.toString(key)));
434            }
435    
436            /**
437             * @see railo.runtime.type.Array#get(int, java.lang.Object)
438             */
439            public Object get(int key, Object defaultValue) {
440                    return sct.get(KeyImpl.init(Caster.toString(key)),defaultValue);
441            }
442    
443            /**
444             * @see railo.runtime.type.Array#getDimension()
445             */
446            public int getDimension() {
447                    throw new PageRuntimeException(new CasterException(sct,"Array"));
448            }
449    
450            /**
451             * @see railo.runtime.type.Array#getE(int)
452             */
453            public Object getE(int key) throws PageException {
454                    return sct.get(KeyImpl.init(Caster.toString(key)));
455            }
456    
457            /**
458             * @see railo.runtime.type.Array#insert(int, java.lang.Object)
459             */
460            public boolean insert(int key, Object value) throws PageException {
461                    throw new CasterException(sct,"Array");
462            }
463    
464            /**
465             * @see railo.runtime.type.Array#intKeys()
466             */
467            public int[] intKeys() {
468                    throw new PageRuntimeException(new CasterException(sct,"Array"));
469            }
470    
471            /**
472             * @see railo.runtime.type.Array#prepend(java.lang.Object)
473             */
474            public Object prepend(Object o) throws PageException {
475                    throw new CasterException(sct,"Array");
476            }
477    
478            /**
479             * @see railo.runtime.type.Array#removeE(int)
480             */
481            public Object removeE(int key) throws PageException {
482                    return sct.remove(KeyImpl.init(Caster.toString(key)));
483            }
484    
485            /**
486             * @see railo.runtime.type.Array#removeEL(int)
487             */
488            public Object removeEL(int key) {
489                    return sct.removeEL(KeyImpl.init(Caster.toString(key)));
490            }
491    
492            /**
493             * @see railo.runtime.type.Array#resize(int)
494             */
495            public void resize(int to) throws PageException {
496                    throw new CasterException(sct,"Array");
497            }
498    
499            /**
500             * @param key
501             * @param value
502             * @return
503             * @throws PageException
504             */
505            public Object setE(int key, Object value) throws PageException {
506                    return sct.set(Caster.toString(key), value);
507            }
508    
509            /**
510             * @see railo.runtime.type.Array#setEL(int, java.lang.Object)
511             */
512            public Object setEL(int key, Object value) {
513                    return sct.setEL(Caster.toString(key), value);
514            }
515    
516            /**
517             * @see railo.runtime.type.Array#sort(java.lang.String, java.lang.String)
518             */
519            public void sort(String sortType, String sortOrder) throws PageException {
520                    throw new CasterException(sct,"Array");
521            }
522    
523            /**
524             * @see railo.runtime.type.Array#toArray()
525             */
526            public Object[] toArray() {
527                    try {
528                            return Caster.toArray(sct).toArray();
529                    } catch (PageException pe) {
530                            throw new PageRuntimeException(pe);
531                    }
532            }
533    
534            /**
535             * @see railo.runtime.type.Array#toList()
536             */
537            public List toList() {
538                    try {
539                            return Caster.toArray(sct).toList();
540                    } catch (PageException pe) {
541                            throw new PageRuntimeException(pe);
542                    }
543            }
544            
545            /**
546             * @see java.lang.Object#clone()
547             */
548            public Object clone(){
549                    return duplicate(true);
550            }
551    
552            /**
553             * @see railo.runtime.type.Sizeable#sizeOf()
554             */
555            public long sizeOf() {
556                    return StructUtil.sizeOf(this);
557            }
558    
559    }