001    package railo.runtime.op;
002    
003    import java.awt.Color;
004    import java.io.File;
005    import java.io.Serializable;
006    import java.util.Iterator;
007    import java.util.List;
008    import java.util.Locale;
009    import java.util.Map;
010    import java.util.TimeZone;
011    
012    import org.w3c.dom.Node;
013    import org.w3c.dom.NodeList;
014    
015    import railo.commons.color.ColorCaster;
016    import railo.commons.io.res.Resource;
017    import railo.commons.io.res.util.ResourceUtil;
018    import railo.runtime.PageContext;
019    import railo.runtime.engine.ThreadLocalPageContext;
020    import railo.runtime.exp.CasterException;
021    import railo.runtime.exp.PageException;
022    import railo.runtime.type.Array;
023    import railo.runtime.type.Collection;
024    import railo.runtime.type.Query;
025    import railo.runtime.type.Struct;
026    import railo.runtime.type.dt.DateTime;
027    import railo.runtime.type.dt.TimeSpan;
028    import railo.runtime.util.Cast;
029    
030    /**
031     * Implementation of the cast interface
032     */
033    public final class CastImpl implements Cast {
034    
035        private static CastImpl singelton;
036    
037        /**
038         * @see railo.runtime.util.Cast#castTo(railo.runtime.PageContext, short, java.lang.Object)
039         */
040        public Object castTo(PageContext pc, short type, Object o) throws PageException {
041            return Caster.castTo(pc,type,o);
042        }
043    
044        /**
045         * @see railo.runtime.util.Cast#castTo(railo.runtime.PageContext, short, java.lang.String, java.lang.Object)
046         */
047        public Object castTo(PageContext pc, short type, String strType, Object o) throws PageException {
048            return Caster.castTo(pc,type,strType,o);
049        }
050    
051        /**
052         * @see railo.runtime.util.Cast#castTo(railo.runtime.PageContext, java.lang.String, java.lang.Object)
053         */
054        public Object castTo(PageContext pc, String type, Object o) throws PageException {
055            return Caster.castTo(pc,type,o,false);
056        }
057        public Object castTo(PageContext pc, String type, Object o, boolean alsoPattern) throws PageException {
058            return Caster.castTo(pc,type,o,alsoPattern);
059        }
060    
061        /**
062         * @see railo.runtime.util.Cast#toArray(java.lang.Object, railo.runtime.type.Array)
063         */
064        public Array toArray(Object obj, Array defaultValue) {
065            return Caster.toArray(obj,defaultValue);
066        }
067    
068        /**
069         * @see railo.runtime.util.Cast#toArray(java.lang.Object)
070         */
071        public Array toArray(Object obj) throws PageException {
072            return Caster.toArray(obj);
073        }
074    
075        /**
076         * @see railo.runtime.util.Cast#toBase64(java.lang.Object, java.lang.String)
077         */
078        public String toBase64(Object o, String defaultValue) {
079            return Caster.toBase64(o,null,defaultValue);
080        }
081    
082        /**
083         * @see railo.runtime.util.Cast#toBase64(java.lang.Object)
084         */
085        public String toBase64(Object o) throws PageException {
086            return Caster.toBase64(o,null);
087        }
088    
089        /**
090         * @see railo.runtime.util.Cast#toBinary(java.lang.Object, byte[])
091         */
092        public byte[] toBinary(Object obj, byte[] defaultValue) {
093            return Caster.toBinary(obj,defaultValue);
094        }
095    
096        /**
097         * @see railo.runtime.util.Cast#toBinary(java.lang.Object)
098         */
099        public byte[] toBinary(Object obj) throws PageException {
100            return Caster.toBinary(obj);
101        }
102    
103        /**
104         * @see railo.runtime.util.Cast#toBoolean(boolean)
105         */
106        public Boolean toBoolean(boolean b) {
107            return Caster.toBoolean(b);
108        }
109    
110        /**
111         * @see railo.runtime.util.Cast#toBoolean(char)
112         */
113        public Boolean toBoolean(char c) {
114            return Caster.toBoolean(c);
115        }
116    
117        /**
118         * @see railo.runtime.util.Cast#toBoolean(double)
119         */
120        public Boolean toBoolean(double d) {
121            return Caster.toBoolean(d);
122        }
123    
124        /**
125         * @see railo.runtime.util.Cast#toBoolean(java.lang.Object, java.lang.Boolean)
126         */
127        public Boolean toBoolean(Object o, Boolean defaultValue) {
128            return Caster.toBoolean(o,defaultValue);
129        }
130    
131        /**
132         * @see railo.runtime.util.Cast#toBoolean(java.lang.Object)
133         */
134        public Boolean toBoolean(Object o) throws PageException {
135            return Caster.toBoolean(o);
136        }
137    
138        /**
139         * @see railo.runtime.util.Cast#toBoolean(java.lang.String, java.lang.Boolean)
140         */
141        public Boolean toBoolean(String str, Boolean defaultValue) {
142            return Caster.toBoolean(str,defaultValue);
143        }
144    
145        /**
146         * @see railo.runtime.util.Cast#toBoolean(java.lang.String)
147         */
148        public Boolean toBoolean(String str) throws PageException {
149            return Caster.toBoolean(str);
150        }
151    
152        /**
153         * @see railo.runtime.util.Cast#toBooleanValue(boolean)
154         */
155        public boolean toBooleanValue(boolean b) {
156            return Caster.toBooleanValue(b);
157        }
158    
159        /**
160         * @see railo.runtime.util.Cast#toBooleanValue(char)
161         */
162        public boolean toBooleanValue(char c) {
163            return Caster.toBooleanValue(c);
164        }
165    
166        /**
167         * @see railo.runtime.util.Cast#toBooleanValue(double)
168         */
169        public boolean toBooleanValue(double d) {
170            return Caster.toBooleanValue(d);
171        }
172    
173        /**
174         * @see railo.runtime.util.Cast#toBooleanValue(java.lang.Object, boolean)
175         */
176        public boolean toBooleanValue(Object o, boolean defaultValue) {
177            return Caster.toBooleanValue(o,defaultValue);
178        }
179    
180        /**
181         * @see railo.runtime.util.Cast#toBooleanValue(java.lang.Object)
182         */
183        public boolean toBooleanValue(Object o) throws PageException {
184            return Caster.toBooleanValue(o);
185        }
186    
187        /**
188         * @see railo.runtime.util.Cast#toBooleanValue(java.lang.String, boolean)
189         */
190        public boolean toBooleanValue(String str, boolean defaultValue) {
191            return Caster.toBooleanValue(str,defaultValue);
192        }
193    
194        /**
195         * @see railo.runtime.util.Cast#toBooleanValue(java.lang.String)
196         */
197        public boolean toBooleanValue(String str) throws PageException {
198            return Caster.toBooleanValue(str);
199        }
200    
201        /**
202         * @see railo.runtime.util.Cast#toByte(boolean)
203         */
204        public Byte toByte(boolean b) {
205            return Caster.toByte(b);
206        }
207    
208        /**
209         * @see railo.runtime.util.Cast#toByte(char)
210         */
211        public Byte toByte(char c) {
212            return Caster.toByte(c);
213        }
214    
215        /**
216         * @see railo.runtime.util.Cast#toByte(double)
217         */
218        public Byte toByte(double d) {
219            return Caster.toByte(d);
220        }
221    
222        /**
223         * @see railo.runtime.util.Cast#toByte(java.lang.Object, java.lang.Byte)
224         */
225        public Byte toByte(Object o, Byte defaultValue) {
226            return Caster.toByte(o,defaultValue);
227        }
228    
229        /**
230         * @see railo.runtime.util.Cast#toByte(java.lang.Object)
231         */
232        public Byte toByte(Object o) throws PageException {
233            return Caster.toByte(o);
234        }
235    
236        /**
237         * @see railo.runtime.util.Cast#toByteValue(boolean)
238         */
239        public byte toByteValue(boolean b) {
240            return Caster.toByteValue(b);
241        }
242    
243        /**
244         * @see railo.runtime.util.Cast#toByteValue(char)
245         */
246        public byte toByteValue(char c) {
247            return Caster.toByteValue(c);
248        }
249    
250        /**
251         * @see railo.runtime.util.Cast#toByteValue(double)
252         */
253        public byte toByteValue(double d) {
254            return Caster.toByteValue(d);
255        }
256    
257        /**
258         * @see railo.runtime.util.Cast#toByteValue(java.lang.Object, byte)
259         */
260        public byte toByteValue(Object o, byte defaultValue) {
261            return Caster.toByteValue(o,defaultValue);
262        }
263    
264        /**
265         * @see railo.runtime.util.Cast#toByteValue(java.lang.Object)
266         */
267        public byte toByteValue(Object o) throws PageException {
268            return Caster.toByteValue(o);
269        }
270    
271        /**
272         * @see railo.runtime.util.Cast#toCharacter(boolean)
273         */
274        public Character toCharacter(boolean b) {
275            return Caster.toCharacter(b);
276        }
277    
278        /**
279         * @see railo.runtime.util.Cast#toCharacter(char)
280         */
281        public Character toCharacter(char c) {
282            return Caster.toCharacter(c);
283        }
284    
285        /**
286         * @see railo.runtime.util.Cast#toCharacter(double)
287         */
288        public Character toCharacter(double d) {
289            return Caster.toCharacter(d);
290        }
291    
292        /**
293         * @see railo.runtime.util.Cast#toCharacter(java.lang.Object, java.lang.Character)
294         */
295        public Character toCharacter(Object o, Character defaultValue) {
296            return Caster.toCharacter(o,defaultValue);
297        }
298    
299        /**
300         * @see railo.runtime.util.Cast#toCharacter(java.lang.Object)
301         */
302        public Character toCharacter(Object o) throws PageException {
303            return Caster.toCharacter(o);
304        }
305    
306        /**
307         * @see railo.runtime.util.Cast#toCharValue(boolean)
308         */
309        public char toCharValue(boolean b) {
310            return Caster.toCharValue(b);
311        }
312    
313        /**
314         * @see railo.runtime.util.Cast#toCharValue(char)
315         */
316        public char toCharValue(char c) {
317            return Caster.toCharValue(c);
318        }
319    
320        /**
321         * @see railo.runtime.util.Cast#toCharValue(double)
322         */
323        public char toCharValue(double d) {
324            return Caster.toCharValue(d);
325        }
326    
327        /**
328         * @see railo.runtime.util.Cast#toCharValue(java.lang.Object, char)
329         */
330        public char toCharValue(Object o, char defaultValue) {
331            return Caster.toCharValue(o,defaultValue);
332        }
333    
334        /**
335         * @see railo.runtime.util.Cast#toCharValue(java.lang.Object)
336         */
337        public char toCharValue(Object o) throws PageException {
338            return Caster.toCharValue(o);
339        }
340    
341        /**
342         * @see railo.runtime.util.Cast#toCollection(java.lang.Object, railo.runtime.type.Collection)
343         */
344        public Collection toCollection(Object o, Collection defaultValue) {
345            return Caster.toCollection(o,defaultValue);
346        }
347    
348        /**
349         * @see railo.runtime.util.Cast#toCollection(java.lang.Object)
350         */
351        public Collection toCollection(Object o) throws PageException {
352            return Caster.toCollection(o);
353        }
354        
355        /**
356         * @see railo.runtime.util.Cast#toColor(java.lang.Object)
357         */
358        public Color toColor(Object o) throws PageException {
359            if(o instanceof Color) return (Color) o;
360            else if (o instanceof String)ColorCaster.toColor((String)o);
361            else if (o instanceof Number)ColorCaster.toColor(Integer.toHexString(((Number)o).intValue()));
362            throw new CasterException(o,Color.class);
363        }
364    
365        
366        /**
367         * @see railo.runtime.util.Cast#toDate(boolean, java.util.TimeZone)
368         */
369        public DateTime toDate(boolean b, TimeZone tz) {
370            return Caster.toDate(b,tz);
371        }
372    
373        /**
374         * @see railo.runtime.util.Cast#toDate(char, java.util.TimeZone)
375         */
376        public DateTime toDate(char c, TimeZone tz) {
377            return Caster.toDate(c,tz);
378        }
379    
380        /**
381         * @see railo.runtime.util.Cast#toDate(double, java.util.TimeZone)
382         */
383        public DateTime toDate(double d, TimeZone tz) {
384            return Caster.toDate(d,tz);
385        }
386    
387        /**
388         * @see railo.runtime.util.Cast#toDate(java.util.Locale, java.lang.String, java.util.TimeZone, railo.runtime.type.dt.DateTime)
389         */
390        public DateTime toDate(Locale locale, String str, TimeZone tz, DateTime defaultValue) {
391            return Caster.toDateTime(locale,str,tz,defaultValue,true);
392        }
393    
394        /**
395         * @see railo.runtime.util.Cast#toDate(java.util.Locale, java.lang.String, java.util.TimeZone)
396         */
397        public DateTime toDate(Locale locale, String str, TimeZone tz) throws PageException {
398            return Caster.toDateTime(locale,str,tz,true);
399        }
400    
401        /**
402         * @see railo.runtime.util.Cast#toDate(java.lang.Object, boolean, java.util.TimeZone, railo.runtime.type.dt.DateTime)
403         */
404        public DateTime toDate(Object o, boolean alsoNumbers, TimeZone tz, DateTime defaultValue) {
405            return Caster.toDate(o,alsoNumbers,tz,defaultValue);
406        }
407    
408        /**
409         * @see railo.runtime.util.Cast#toDate(java.lang.Object, java.util.TimeZone)
410         */
411        public DateTime toDate(Object o, TimeZone tz) throws PageException {
412            return Caster.toDate(o,tz);
413        }
414    
415        /**
416         * @see railo.runtime.util.Cast#toDate(java.lang.String, boolean, java.util.TimeZone, railo.runtime.type.dt.DateTime)
417         */
418        public DateTime toDate(String str, boolean alsoNumbers, TimeZone tz, DateTime defaultValue) {
419            return Caster.toDate(str,alsoNumbers,tz,defaultValue);
420        }
421    
422        /**
423         * @see railo.runtime.util.Cast#toDate(java.lang.String, java.util.TimeZone)
424         */
425        public DateTime toDate(String str, TimeZone tz) throws PageException {
426            return Caster.toDate(str,tz);
427        }
428    
429        /**
430         * @see railo.runtime.util.Cast#toDatetime(java.lang.Object, java.util.TimeZone)
431         */
432        public DateTime toDatetime(Object o, TimeZone tz) throws PageException {
433            return Caster.toDate(o,tz);
434        }
435    
436        /**
437         * @see railo.runtime.util.Cast#toDateTime(java.lang.Object, java.util.TimeZone)
438         */
439        public DateTime toDateTime(Object o, TimeZone tz) throws PageException {
440            return Caster.toDate(o,tz);
441        }
442    
443        /**
444         * @see railo.runtime.util.Cast#toDecimal(boolean)
445         */
446        public String toDecimal(boolean b) {
447            return Caster.toDecimal(b);
448        }
449    
450        /**
451         * @see railo.runtime.util.Cast#toDecimal(char)
452         */
453        public String toDecimal(char c) {
454            return Caster.toDecimal(c);
455        }
456    
457        /**
458         * @see railo.runtime.util.Cast#toDecimal(double)
459         */
460        public String toDecimal(double d) {
461            return Caster.toDecimal(d);
462        }
463    
464        /**
465         * @see railo.runtime.util.Cast#toDecimal(java.lang.Object, java.lang.String)
466         */
467        public String toDecimal(Object value, String defaultValue) {
468            return Caster.toDecimal(value,defaultValue);
469        }
470    
471        /**
472         * @see railo.runtime.util.Cast#toDecimal(java.lang.Object)
473         */
474        public String toDecimal(Object value) throws PageException {
475            return Caster.toDecimal(value);
476        }
477    
478        /**
479         * @see railo.runtime.util.Cast#toDouble(boolean)
480         */
481        public Double toDouble(boolean b) {
482            return Caster.toDouble(b);
483        }
484    
485        /**
486         * @see railo.runtime.util.Cast#toDouble(char)
487         */
488        public Double toDouble(char c) {
489            return Caster.toDouble(c);
490        }
491    
492        /**
493         * @see railo.runtime.util.Cast#toDouble(double)
494         */
495        public Double toDouble(double d) {
496            return Caster.toDouble(d);
497        }
498    
499        /**
500         * @see railo.runtime.util.Cast#toDouble(java.lang.Object, java.lang.Double)
501         */
502        public Double toDouble(Object o, Double defaultValue) {
503            return Caster.toDouble(o,defaultValue);
504        }
505    
506        /**
507         * @see railo.runtime.util.Cast#toDouble(java.lang.Object)
508         */
509        public Double toDouble(Object o) throws PageException {
510            return Caster.toDouble(o);
511        }
512    
513        /**
514         * @see railo.runtime.util.Cast#toDouble(java.lang.String, java.lang.Double)
515         */
516        public Double toDouble(String str, Double defaultValue) {
517            return Caster.toDouble(str,defaultValue);
518        }
519    
520        /**
521         * @see railo.runtime.util.Cast#toDouble(java.lang.String)
522         */
523        public Double toDouble(String str) throws PageException {
524            return Caster.toDouble(str);
525        }
526    
527        /**
528         * @see railo.runtime.util.Cast#toDoubleValue(boolean)
529         */
530        public double toDoubleValue(boolean b) {
531            return Caster.toDoubleValue(b);
532        }
533    
534        /**
535         * @see railo.runtime.util.Cast#toDoubleValue(char)
536         */
537        public double toDoubleValue(char c) {
538            return Caster.toDoubleValue(c);
539        }
540    
541        /**
542         * @see railo.runtime.util.Cast#toDoubleValue(double)
543         */
544        public double toDoubleValue(double d) {
545            return Caster.toDoubleValue(d);
546        }
547    
548        /**
549         * @see railo.runtime.util.Cast#toDoubleValue(java.lang.Object, double)
550         */
551        public double toDoubleValue(Object o, double defaultValue) {
552            return Caster.toDoubleValue(o,defaultValue);
553        }
554    
555        /**
556         * @see railo.runtime.util.Cast#toDoubleValue(java.lang.Object)
557         */
558        public double toDoubleValue(Object o) throws PageException {
559            return Caster.toDoubleValue(o);
560        }
561    
562        /**
563         * @see railo.runtime.util.Cast#toDoubleValue(java.lang.String, double)
564         */
565        public double toDoubleValue(String str, double defaultValue) {
566            return Caster.toDoubleValue(str,defaultValue);
567        }
568    
569        /**
570         * @see railo.runtime.util.Cast#toDoubleValue(java.lang.String)
571         */
572        public double toDoubleValue(String str) throws PageException {
573            return Caster.toDoubleValue(str);
574        }
575    
576        /**
577         * @see railo.runtime.util.Cast#toFile(java.lang.Object, java.io.File)
578         */
579        public File toFile(Object obj, File defaultValue) {
580            return Caster.toFile(obj,defaultValue);
581        }
582    
583        /**
584         * @see railo.runtime.util.Cast#toFile(java.lang.Object)
585         */
586        public File toFile(Object obj) throws PageException {
587            return Caster.toFile(obj);
588        }
589    
590        /**
591         * @see railo.runtime.util.Cast#toInteger(boolean)
592         */
593        public Integer toInteger(boolean b) {
594            return Caster.toInteger(b);
595        }
596    
597        /**
598         * @see railo.runtime.util.Cast#toInteger(char)
599         */
600        public Integer toInteger(char c) {
601            return Caster.toInteger(c);
602        }
603    
604        /**
605         * @see railo.runtime.util.Cast#toInteger(double)
606         */
607        public Integer toInteger(double d) {
608            return Caster.toInteger(d);
609        }
610    
611        /**
612         * @see railo.runtime.util.Cast#toInteger(java.lang.Object, java.lang.Integer)
613         */
614        public Integer toInteger(Object o, Integer defaultValue) {
615            return Caster.toInteger(o,defaultValue);
616        }
617    
618        /**
619         * @see railo.runtime.util.Cast#toInteger(java.lang.Object)
620         */
621        public Integer toInteger(Object o) throws PageException {
622            return Caster.toInteger(o);
623        }
624    
625        /**
626         * @see railo.runtime.util.Cast#toIntValue(boolean)
627         */
628        public int toIntValue(boolean b) {
629            return Caster.toIntValue(b);
630        }
631    
632        /**
633         * @see railo.runtime.util.Cast#toIntValue(char)
634         */
635        public int toIntValue(char c) {
636            return Caster.toIntValue(c);
637        }
638    
639        /**
640         * @see railo.runtime.util.Cast#toIntValue(double)
641         */
642        public int toIntValue(double d) {
643            return Caster.toIntValue(d);
644        }
645    
646        /**
647         * @see railo.runtime.util.Cast#toIntValue(java.lang.Object, int)
648         */
649        public int toIntValue(Object o, int defaultValue) {
650            return Caster.toIntValue(o,defaultValue);
651        }
652    
653        /**
654         * @see railo.runtime.util.Cast#toIntValue(java.lang.Object)
655         */
656        public int toIntValue(Object o) throws PageException {
657            return Caster.toIntValue(o);
658        }
659    
660        /**
661         * @see railo.runtime.util.Cast#toIntValue(java.lang.String, int)
662         */
663        public int toIntValue(String str, int defaultValue) {
664            return Caster.toIntValue(str,defaultValue);
665        }
666    
667        /**
668         * @see railo.runtime.util.Cast#toIntValue(java.lang.String)
669         */
670        public int toIntValue(String str) throws PageException {
671            return Caster.toIntValue(str);
672        }
673    
674        /**
675         * @see railo.runtime.util.Cast#toIterator(java.lang.Object)
676         */
677        public Iterator toIterator(Object o) throws PageException {
678            return Caster.toIterator(o);
679        }
680    
681        /**
682         * @see railo.runtime.util.Cast#toList(java.lang.Object, boolean, java.util.List)
683         */
684        public List toList(Object o, boolean duplicate, List defaultValue) {
685            return Caster.toList(o,duplicate,defaultValue);
686        }
687    
688        /**
689         * @see railo.runtime.util.Cast#toList(java.lang.Object, boolean)
690         */
691        public List toList(Object o, boolean duplicate) throws PageException {
692            return Caster.toList(o,duplicate);
693        }
694    
695        /**
696         * @see railo.runtime.util.Cast#toList(java.lang.Object, java.util.List)
697         */
698        public List toList(Object o, List defaultValue) {
699            return Caster.toList(o,defaultValue);
700        }
701    
702        /**
703         * @see railo.runtime.util.Cast#toList(java.lang.Object)
704         */
705        public List toList(Object o) throws PageException {
706            return Caster.toList(o);
707        }
708    
709        /**
710         * @see railo.runtime.util.Cast#toLocale(java.lang.String, java.util.Locale)
711         */
712        public Locale toLocale(String strLocale, Locale defaultValue) {
713            return Caster.toLocale(strLocale,defaultValue);
714        }
715    
716        /**
717         * @see railo.runtime.util.Cast#toLocale(java.lang.String)
718         */
719        public Locale toLocale(String strLocale) throws PageException {
720            return Caster.toLocale(strLocale);
721        }
722    
723        /**
724         * @see railo.runtime.util.Cast#toLong(boolean)
725         */
726        public Long toLong(boolean b) {
727            return Caster.toLong(b);
728        }
729    
730        /**
731         * @see railo.runtime.util.Cast#toLong(char)
732         */
733        public Long toLong(char c) {
734            return Caster.toLong(c);
735        }
736    
737        /**
738         * @see railo.runtime.util.Cast#toLong(double)
739         */
740        public Long toLong(double d) {
741            return Caster.toLong(d);
742        }
743    
744        /**
745         * @see railo.runtime.util.Cast#toLong(java.lang.Object, java.lang.Long)
746         */
747        public Long toLong(Object o, Long defaultValue) {
748            return Caster.toLong(o,defaultValue);
749        }
750    
751        /**
752         * @see railo.runtime.util.Cast#toLong(java.lang.Object)
753         */
754        public Long toLong(Object o) throws PageException {
755            return Caster.toLong(o);
756        }
757    
758        /**
759         * @see railo.runtime.util.Cast#toLongValue(boolean)
760         */
761        public long toLongValue(boolean b) {
762            return Caster.toLongValue(b);
763        }
764    
765        /**
766         * @see railo.runtime.util.Cast#toLongValue(char)
767         */
768        public long toLongValue(char c) {
769            return Caster.toLongValue(c);
770        }
771    
772        /**
773         * @see railo.runtime.util.Cast#toLongValue(double)
774         */
775        public long toLongValue(double d) {
776            return Caster.toLongValue(d);
777        }
778    
779        /**
780         * @see railo.runtime.util.Cast#toLongValue(java.lang.Object, long)
781         */
782        public long toLongValue(Object o, long defaultValue) {
783            return Caster.toLongValue(o,defaultValue);
784        }
785    
786        /**
787         * @see railo.runtime.util.Cast#toLongValue(java.lang.Object)
788         */
789        public long toLongValue(Object o) throws PageException {
790            return Caster.toLongValue(o);
791        }
792    
793        /**
794         * @see railo.runtime.util.Cast#toMap(java.lang.Object, boolean, java.util.Map)
795         */
796        public Map toMap(Object o, boolean duplicate, Map defaultValue) {
797            return Caster.toMap(o,duplicate,defaultValue);
798        }
799    
800        /**
801         * @see railo.runtime.util.Cast#toMap(java.lang.Object, boolean)
802         */
803        public Map toMap(Object o, boolean duplicate) throws PageException {
804            return Caster.toMap(o,duplicate);
805        }
806    
807        /**
808         * @see railo.runtime.util.Cast#toMap(java.lang.Object, java.util.Map)
809         */
810        public Map toMap(Object o, Map defaultValue) {
811            return Caster.toMap(o,defaultValue);
812        }
813    
814        /**
815         * @see railo.runtime.util.Cast#toMap(java.lang.Object)
816         */
817        public Map toMap(Object o) throws PageException {
818            return Caster.toMap(o);
819        }
820    
821        /**
822         * @see railo.runtime.util.Cast#toNode(java.lang.Object, org.w3c.dom.Node)
823         */
824        public Node toNode(Object o, Node defaultValue) {
825            return Caster.toNode(o,defaultValue);
826        }
827    
828        /**
829         * @see railo.runtime.util.Cast#toNode(java.lang.Object)
830         */
831        public Node toNode(Object o) throws PageException {
832            return Caster.toNode(o);
833        }
834    
835        /**
836         * @see railo.runtime.util.Cast#toNodeList(java.lang.Object, org.w3c.dom.NodeList)
837         */
838        public NodeList toNodeList(Object o, NodeList defaultValue) {
839            return Caster.toNodeList(o,defaultValue);
840        }
841    
842        /**
843         * @see railo.runtime.util.Cast#toNodeList(java.lang.Object)
844         */
845        public NodeList toNodeList(Object o) throws PageException {
846            return Caster.toNodeList(o);
847        }
848    
849        /**
850         * @see railo.runtime.util.Cast#toNull(java.lang.Object, java.lang.Object)
851         */
852        public Object toNull(Object value, Object defaultValue) {
853            return Caster.toNull(value,defaultValue);
854        }
855    
856        /**
857         * @see railo.runtime.util.Cast#toNull(java.lang.Object)
858         */
859        public Object toNull(Object value) throws PageException {
860            return Caster.toNull(value);
861        }
862    
863        /**
864         * @see railo.runtime.util.Cast#toPageException(java.lang.Throwable)
865         */
866        public PageException toPageException(Throwable t) {
867            return Caster.toPageException(t);
868        }
869    
870        /**
871         * @see railo.runtime.util.Cast#toQuery(java.lang.Object, boolean, railo.runtime.type.Query)
872         */
873        public Query toQuery(Object o, boolean duplicate, Query defaultValue) {
874            return Caster.toQuery(o,duplicate,defaultValue);
875        }
876    
877        /**
878         * @see railo.runtime.util.Cast#toQuery(java.lang.Object, boolean)
879         */
880        public Query toQuery(Object o, boolean duplicate) throws PageException {
881            return Caster.toQuery(o,duplicate);
882        }
883    
884        /**
885         * @see railo.runtime.util.Cast#toQuery(java.lang.Object, railo.runtime.type.Query)
886         */
887        public Query toQuery(Object o, Query defaultValue) {
888            return Caster.toQuery(o,defaultValue);
889        }
890    
891        /**
892         * @see railo.runtime.util.Cast#toQuery(java.lang.Object)
893         */
894        public Query toQuery(Object o) throws PageException {
895            return Caster.toQuery(o);
896        }
897    
898        /**
899         * @see railo.runtime.util.Cast#toRef(boolean)
900         */
901        public Boolean toRef(boolean b) {
902            return Caster.toRef(b);
903        }
904    
905        /**
906         * @see railo.runtime.util.Cast#toRef(byte)
907         */
908        public Byte toRef(byte b) {
909            return Caster.toRef(b);
910        }
911    
912        /**
913         * @see railo.runtime.util.Cast#toRef(char)
914         */
915        public String toRef(char c) {
916            return Caster.toRef(c);
917        }
918    
919        /**
920         * @see railo.runtime.util.Cast#toRef(railo.runtime.type.Collection)
921         */
922        public Collection toRef(Collection o) {
923            return Caster.toRef(o);
924        }
925    
926        /**
927         * @see railo.runtime.util.Cast#toRef(double)
928         */
929        public Double toRef(double d) {
930            return Caster.toRef(d);
931        }
932    
933        /**
934         * @see railo.runtime.util.Cast#toRef(float)
935         */
936        public Float toRef(float f) {
937            return Caster.toRef(f);
938        }
939    
940        /**
941         * @see railo.runtime.util.Cast#toRef(int)
942         */
943        public Integer toRef(int i) {
944            return Caster.toRef(i);
945        }
946    
947        /**
948         * @see railo.runtime.util.Cast#toRef(long)
949         */
950        public Long toRef(long l) {
951            return Caster.toRef(l);
952        }
953    
954        /**
955         * @see railo.runtime.util.Cast#toRef(java.lang.Object)
956         */
957        public Object toRef(Object o) {
958            return Caster.toRef(o);
959        }
960    
961        /**
962         * @see railo.runtime.util.Cast#toRef(short)
963         */
964        public Short toRef(short s) {
965            return Caster.toRef(s);
966        }
967    
968        /**
969         * @see railo.runtime.util.Cast#toRef(java.lang.String)
970         */
971        public String toRef(String str) {
972            return Caster.toRef(str);
973        }
974    
975        /**
976         * @see railo.runtime.util.Cast#toShort(boolean)
977         */
978        public Short toShort(boolean b) {
979            return Caster.toShort(b);
980        }
981    
982        /**
983         * @see railo.runtime.util.Cast#toShort(char)
984         */
985        public Short toShort(char c) {
986            return Caster.toShort(c);
987        }
988    
989        /**
990         * @see railo.runtime.util.Cast#toShort(double)
991         */
992        public Short toShort(double d) {
993            return Caster.toShort(d);
994        }
995    
996        /**
997         * @see railo.runtime.util.Cast#toShort(java.lang.Object, java.lang.Short)
998         */
999        public Short toShort(Object o, Short defaultValue) {
1000            return Caster.toShort(o,defaultValue);
1001        }
1002    
1003        /**
1004         * @see railo.runtime.util.Cast#toShort(java.lang.Object)
1005         */
1006        public Short toShort(Object o) throws PageException {
1007            return Caster.toShort(o);
1008        }
1009    
1010        /**
1011         * @see railo.runtime.util.Cast#toShortValue(boolean)
1012         */
1013        public short toShortValue(boolean b) {
1014            return Caster.toShortValue(b);
1015        }
1016    
1017        /**
1018         * @see railo.runtime.util.Cast#toShortValue(char)
1019         */
1020        public short toShortValue(char c) {
1021            return Caster.toShortValue(c);
1022        }
1023    
1024        /**
1025         * @see railo.runtime.util.Cast#toShortValue(double)
1026         */
1027        public short toShortValue(double d) {
1028            return Caster.toShortValue(d);
1029        }
1030    
1031        /**
1032         * @see railo.runtime.util.Cast#toShortValue(java.lang.Object, short)
1033         */
1034        public short toShortValue(Object o, short defaultValue) {
1035            return Caster.toShortValue(o,defaultValue);
1036        }
1037    
1038        /**
1039         * @see railo.runtime.util.Cast#toShortValue(java.lang.Object)
1040         */
1041        public short toShortValue(Object o) throws PageException {
1042            return Caster.toShortValue(o);
1043        }
1044    
1045        /**
1046         * @see railo.runtime.util.Cast#toString(boolean)
1047         */
1048        public String toString(boolean b) {
1049            return Caster.toString(b);
1050        }
1051    
1052        /**
1053         * @see railo.runtime.util.Cast#toString(double)
1054         */
1055        public String toString(double d) {
1056            return Caster.toString(d);
1057        }
1058    
1059        /**
1060         * @see railo.runtime.util.Cast#toString(int)
1061         */
1062        public String toString(int i) {
1063            return Caster.toString(i);
1064        }
1065    
1066        /**
1067         * @see railo.runtime.util.Cast#toString(long)
1068         */
1069        public String toString(long l) {
1070            return Caster.toString(l);
1071        }
1072    
1073        /**
1074         * @see railo.runtime.util.Cast#toString(java.lang.Object, java.lang.String)
1075         */
1076        public String toString(Object o, String defaultValue) {
1077            return Caster.toString(o,defaultValue);
1078        }
1079    
1080        /**
1081         * @see railo.runtime.util.Cast#toString(java.lang.Object)
1082         */
1083        public String toString(Object o) throws PageException {
1084            return Caster.toString(o);
1085        }
1086        
1087        /**
1088         * @see railo.runtime.util.Cast#toStruct(java.lang.Object, railo.runtime.type.Struct, boolean)
1089         */
1090        public Struct toStruct(Object o, Struct defaultValue,boolean caseSensitive) {
1091            return Caster.toStruct(o,defaultValue,caseSensitive);
1092        }
1093    
1094        /**
1095         * @see railo.runtime.util.Cast#toStruct(java.lang.Object, railo.runtime.type.Struct)
1096         */
1097        public Struct toStruct(Object o, Struct defaultValue) {
1098            return Caster.toStruct(o,defaultValue,true);
1099        }
1100    
1101        /**
1102         * @see railo.runtime.util.Cast#toStruct(java.lang.Object)
1103         */
1104        public Struct toStruct(Object o) throws PageException {
1105            return Caster.toStruct(o);
1106        }
1107    
1108        /**
1109         * @see railo.runtime.util.Cast#toTimespan(java.lang.Object, railo.runtime.type.dt.TimeSpan)
1110         */
1111        public TimeSpan toTimespan(Object o, TimeSpan defaultValue) {
1112            return Caster.toTimespan(o,defaultValue);
1113        }
1114    
1115        /**
1116         * @see railo.runtime.util.Cast#toTimespan(java.lang.Object)
1117         */
1118        public TimeSpan toTimespan(Object o) throws PageException {
1119            return Caster.toTimespan(o);
1120        }
1121    
1122        /**
1123         * @see railo.runtime.util.Cast#toTypeName(java.lang.Object)
1124         */
1125        public String toTypeName(Object o) {
1126            return Caster.toTypeName(o);
1127        }
1128    
1129        /**
1130         * @see railo.runtime.util.Cast#toUUId(java.lang.Object, java.lang.Object)
1131         */
1132        public Object toUUId(Object o, Object defaultValue) {
1133            return Caster.toUUId(o,defaultValue);
1134        }
1135    
1136        /**
1137         * @see railo.runtime.util.Cast#toUUId(java.lang.Object)
1138         */
1139        public Object toUUId(Object o) throws PageException {
1140            return Caster.toUUId(o);
1141        }
1142    
1143        /**
1144         * @see railo.runtime.util.Cast#toVariableName(java.lang.Object, java.lang.Object)
1145         */
1146        public Object toVariableName(Object obj, Object defaultValue) {
1147            return Caster.toVariableName(obj,defaultValue);
1148        }
1149    
1150        /**
1151         * @see railo.runtime.util.Cast#toVariableName(java.lang.Object)
1152         */
1153        public Object toVariableName(Object o) throws PageException {
1154            return Caster.toVariableName(o);
1155        }
1156    
1157        /**
1158         * @see railo.runtime.util.Cast#toVoid(java.lang.Object, java.lang.Object)
1159         */
1160        public Object toVoid(Object o, Object defaultValue) {
1161            return Caster.toVoid(o,defaultValue);
1162        }
1163    
1164        /**
1165         * @see railo.runtime.util.Cast#toVoid(java.lang.Object)
1166         */
1167        public Object toVoid(Object o) throws PageException {
1168            return Caster.toVoid(o);
1169        }
1170    
1171        /**
1172         * @see railo.runtime.util.Cast#toXML(java.lang.Object, org.w3c.dom.Node)
1173         */
1174        public Node toXML(Object value, Node defaultValue) {
1175            return Caster.toXML(value,defaultValue);
1176        }
1177    
1178        /**
1179         * @see railo.runtime.util.Cast#toXML(java.lang.Object)
1180         */
1181        public Node toXML(Object value) throws PageException {
1182            return Caster.toXML(value);
1183        }
1184    
1185        public static Cast getInstance() {
1186            if(singelton==null)singelton=new CastImpl();
1187            return singelton;
1188        }
1189    
1190            /**
1191             *
1192             * @see railo.runtime.util.Cast#toResource(java.lang.Object)
1193             */
1194            public Resource toResource(Object obj) throws PageException {
1195                    if(obj instanceof Resource) return (Resource) obj;
1196                    if(obj instanceof File) return ResourceUtil.toResource((File) obj);
1197                    return ResourceUtil.toResourceNotExisting(ThreadLocalPageContext.get(), toString(obj));
1198            }
1199    
1200            /**
1201             *
1202             * @see railo.runtime.util.Cast#toResource(java.lang.Object, railo.commons.io.res.Resource)
1203             */
1204            public Resource toResource(Object obj, Resource defaultValue) {
1205                    if(obj instanceof Resource) return (Resource) obj;
1206                    String path=toString(obj,null);
1207                    if(path==null)return defaultValue;
1208                    return ResourceUtil.toResourceNotExisting(ThreadLocalPageContext.get(), path);
1209            }
1210    
1211            /**
1212             * @see railo.runtime.util.Cast#to(java.lang.String, java.lang.Object, boolean)
1213             */
1214            public Object to(String type, Object o,boolean alsoPattern) throws PageException {
1215                    return Caster.castTo(ThreadLocalPageContext.get(), type, o,alsoPattern);
1216            }
1217    
1218            /**
1219             * @see railo.runtime.util.Cast#toSerializable(java.lang.Object)
1220             */
1221            public Serializable toSerializable(Object obj) throws PageException {
1222                    return Caster.toSerializable(obj);
1223            }
1224    
1225            /**
1226             * @see railo.runtime.util.Cast#toSerializable(java.lang.Object, java.io.Serializable)
1227             */
1228            public Serializable toSerializable(Object object, Serializable defaultValue) {
1229                    return Caster.toSerializable(object, defaultValue);
1230            }
1231    
1232    }