001    package railo.runtime.type;
002    
003    import railo.runtime.PageContext;
004    import railo.runtime.dump.DumpData;
005    import railo.runtime.dump.DumpProperties;
006    import railo.runtime.dump.DumpUtil;
007    import railo.runtime.dump.Dumpable;
008    import railo.runtime.exp.ExpressionException;
009    import railo.runtime.exp.PageException;
010    import railo.runtime.op.Castable;
011    import railo.runtime.type.dt.DateTime;
012    
013    /**
014     * Custom Null Type
015     */
016    public final class Null implements Castable,Dumpable {
017        private static final Null nulls=new Null();
018        private Null() {}
019        /**
020         * @return returns custom null Type
021         */
022        public static Null getInstance() {
023            return nulls;
024        }
025    
026        /**
027         * @see railo.runtime.op.Castable#castToString()
028         */
029        public String castToString() throws ExpressionException {
030            throw new ExpressionException("can't convert null to a String");
031        }
032    
033            /**
034             * @see railo.runtime.op.Castable#castToString(java.lang.String)
035             */
036            public String castToString(String defaultValue) {
037                    return defaultValue;
038            }
039            
040        /**
041         * @see railo.runtime.op.Castable#castToBooleanValue()
042         */
043        public boolean castToBooleanValue() throws ExpressionException {
044            throw new ExpressionException("can't convert null to a boolean");
045        }
046        
047        /**
048         * @see railo.runtime.op.Castable#castToBoolean(java.lang.Boolean)
049         */
050        public Boolean castToBoolean(Boolean defaultValue) {
051            return defaultValue;
052        }
053        
054        /**
055         * @see railo.runtime.op.Castable#castToDoubleValue()
056         */
057        public double castToDoubleValue() throws ExpressionException {
058            throw new ExpressionException("can't convert null to a numberic value");
059        }
060        
061        /**
062         * @see railo.runtime.op.Castable#castToDoubleValue(double)
063         */
064        public double castToDoubleValue(double defaultValue) {
065            return defaultValue;
066        }
067        
068        /**
069         * @see railo.runtime.op.Castable#castToDateTime()
070         */
071        public DateTime castToDateTime() throws ExpressionException {
072            throw new ExpressionException("can't convert null to a date object");
073        }
074        
075        /**
076         * @see railo.runtime.op.Castable#castToDateTime(railo.runtime.type.dt.DateTime)
077         */
078        public DateTime castToDateTime(DateTime defaultValue) {
079            return defaultValue;
080        }
081        
082        /**
083         *
084         * @see railo.runtime.dump.Dumpable#toDumpData(railo.runtime.PageContext, int)
085         */
086        public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
087            return DumpUtil.toDumpData(null,pageContext,maxlevel,dp);
088        }
089        /**
090         * @see java.lang.Object#toString()
091         */
092        public String toString() {
093            return null;
094        }
095            public int compareTo(String str) throws PageException {
096            throw new ExpressionException("can't compare null with a string value");
097            }
098            public int compareTo(boolean b) throws PageException {
099            throw new ExpressionException("can't compare null with a boolean value");
100            }
101            public int compareTo(double d) throws PageException {
102            throw new ExpressionException("can't compare null with a numeric value");
103            }
104            public int compareTo(DateTime dt) throws PageException {
105            throw new ExpressionException("can't compare null with a date object");
106            }
107    }