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        public static final Null NULL=new Null();
018        private Null() {}
019        
020        @Override
021        public String castToString() throws ExpressionException {
022            return "";
023        }
024    
025            @Override
026            public String castToString(String defaultValue) {
027                    return "";
028            }
029            
030        @Override
031        public boolean castToBooleanValue() throws ExpressionException {
032            throw new ExpressionException("can't convert null to a boolean");
033        }
034        
035        @Override
036        public Boolean castToBoolean(Boolean defaultValue) {
037            return defaultValue;
038        }
039        
040        @Override
041        public double castToDoubleValue() throws ExpressionException {
042            throw new ExpressionException("can't convert null to a numberic value");
043        }
044        
045        @Override
046        public double castToDoubleValue(double defaultValue) {
047            return defaultValue;
048        }
049        
050        @Override
051        public DateTime castToDateTime() throws ExpressionException {
052            throw new ExpressionException("can't convert null to a date object");
053        }
054        
055        @Override
056        public DateTime castToDateTime(DateTime defaultValue) {
057            return defaultValue;
058        }
059        
060        @Override
061        public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
062            return DumpUtil.toDumpData(null,pageContext,maxlevel,dp);
063        }
064        @Override
065        public String toString() {
066            return null;
067        }
068            public int compareTo(String str) throws PageException {
069                    return "".compareTo(str);
070            //throw new ExpressionException("can't compare null with a string value");
071            }
072            public int compareTo(boolean b) throws PageException {
073            throw new ExpressionException("can't compare null with a boolean value");
074            }
075            public int compareTo(double d) throws PageException {
076            throw new ExpressionException("can't compare null with a numeric value");
077            }
078            public int compareTo(DateTime dt) throws PageException {
079            throw new ExpressionException("can't compare null with a date object");
080            }
081    }