001    package railo.runtime.type.util;
002    
003    import java.util.Date;
004    
005    import railo.runtime.engine.ThreadLocalPageContext;
006    import railo.runtime.exp.PageException;
007    import railo.runtime.op.Castable;
008    import railo.runtime.op.Caster;
009    import railo.runtime.op.Decision;
010    import railo.runtime.op.Operator;
011    import railo.runtime.op.date.DateCaster;
012    import railo.runtime.type.ObjectWrap;
013    import railo.runtime.type.UDF;
014    import railo.runtime.type.dt.DateTime;
015    
016    /**
017     * @deprecated this class is no longer used with no replacment
018     */
019    public class UDFDefaultValue implements ObjectWrap,Castable {
020    
021    
022            private static final String COMPLEX_DEFAULT_TYPE="[runtime expression]";
023            
024            private UDF udf;
025            private int index;
026    
027            /**
028             * Constructor of the class
029             * @param udf
030             * @param index
031             */
032            public UDFDefaultValue(UDF udf, int index) {
033                    this.udf=udf;
034                    this.index=index;
035            }
036    
037    
038            /**
039             * @see railo.runtime.type.ObjectWrap#getEmbededObject()
040             */
041            public Object getEmbededObject() {
042                    try {
043                Object defaultValue = udf.getDefaultValue(ThreadLocalPageContext.get(), index);
044                
045                if(defaultValue==null || Decision.isSimpleValue(defaultValue)) {
046                    return defaultValue;
047                }
048            }
049            catch(Throwable e) {}
050                    
051                    return COMPLEX_DEFAULT_TYPE;
052            }
053            
054            /**
055             * @see railo.runtime.type.ObjectWrap#getEmbededObject(java.lang.Object)
056             */
057            public Object getEmbededObject(Object defaultValue) {
058                    return getEmbededObject();
059            }
060    
061            /**
062             * @see railo.runtime.op.Castable#castToBooleanValue()
063             */
064            public boolean castToBooleanValue() throws PageException {
065                    return Caster.toBooleanValue(getEmbededObject());
066            }
067        
068        /**
069         * @see railo.runtime.op.Castable#castToBoolean(java.lang.Boolean)
070         */
071        public Boolean castToBoolean(Boolean defaultValue) {
072            return Caster.toBoolean(getEmbededObject(),defaultValue);
073        }
074    
075            /**
076             * @see railo.runtime.op.Castable#castToDateTime()
077             */
078            public DateTime castToDateTime() throws PageException {
079                    return Caster.toDatetime(getEmbededObject(),null);
080            }
081        
082        /**
083         * @see railo.runtime.op.Castable#castToDateTime(railo.runtime.type.dt.DateTime)
084         */
085        public DateTime castToDateTime(DateTime defaultValue) {
086            return DateCaster.toDateAdvanced(getEmbededObject(),true,null,defaultValue);
087        }
088    
089            /**
090             * @see railo.runtime.op.Castable#castToDoubleValue()
091             */
092            public double castToDoubleValue() throws PageException {
093                    return Caster.toDoubleValue(getEmbededObject());
094            }
095        
096        /**
097         * @see railo.runtime.op.Castable#castToDoubleValue(double)
098         */
099        public double castToDoubleValue(double defaultValue) {
100            return Caster.toDoubleValue(getEmbededObject(),defaultValue);
101        }
102    
103            /**
104             * @see railo.runtime.op.Castable#castToString()
105             */
106            public String castToString() throws PageException {
107                    return Caster.toString(getEmbededObject());
108            }
109    
110            /**
111             * @see railo.runtime.op.Castable#castToString(java.lang.String)
112             */
113            public String castToString(String defaultValue) {
114                    return Caster.toString(getEmbededObject(),defaultValue);
115            }
116    
117            /**
118             * @see railo.runtime.op.Castable#compareTo(java.lang.String)
119             */
120            public int compareTo(String str) throws PageException {
121                    return Operator.compare(castToString(),str);
122            }
123    
124            /**
125             * @see railo.runtime.op.Castable#compareTo(boolean)
126             */
127            public int compareTo(boolean b) throws PageException {
128                    return Operator.compare(castToBooleanValue(),b);
129            }
130    
131            /**
132             * @see railo.runtime.op.Castable#compareTo(double)
133             */
134            public int compareTo(double d) throws PageException {
135                    return Operator.compare(castToDoubleValue(),d);
136            }
137    
138            /**
139             * @see railo.runtime.op.Castable#compareTo(railo.runtime.type.dt.DateTime)
140             */
141            public int compareTo(DateTime dt) throws PageException {
142                    return Operator.compare((Date)castToDateTime(), (Date)dt);
143            }
144    
145    }