001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.type; 020 021import lucee.runtime.PageContext; 022import lucee.runtime.dump.DumpData; 023import lucee.runtime.dump.DumpProperties; 024import lucee.runtime.dump.DumpUtil; 025import lucee.runtime.dump.Dumpable; 026import lucee.runtime.exp.ExpressionException; 027import lucee.runtime.exp.PageException; 028import lucee.runtime.op.Castable; 029import lucee.runtime.type.dt.DateTime; 030 031/** 032 * Custom Null Type 033 */ 034public final class Null implements Castable,Dumpable { 035 public static final Null NULL=new Null(); 036 private Null() {} 037 038 @Override 039 public String castToString() throws ExpressionException { 040 return ""; 041 } 042 043 @Override 044 public String castToString(String defaultValue) { 045 return ""; 046 } 047 048 @Override 049 public boolean castToBooleanValue() throws ExpressionException { 050 throw new ExpressionException("can't convert null to a boolean"); 051 } 052 053 @Override 054 public Boolean castToBoolean(Boolean defaultValue) { 055 return defaultValue; 056 } 057 058 @Override 059 public double castToDoubleValue() throws ExpressionException { 060 throw new ExpressionException("can't convert null to a numberic value"); 061 } 062 063 @Override 064 public double castToDoubleValue(double defaultValue) { 065 return defaultValue; 066 } 067 068 @Override 069 public DateTime castToDateTime() throws ExpressionException { 070 throw new ExpressionException("can't convert null to a date object"); 071 } 072 073 @Override 074 public DateTime castToDateTime(DateTime defaultValue) { 075 return defaultValue; 076 } 077 078 @Override 079 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 080 return DumpUtil.toDumpData(null,pageContext,maxlevel,dp); 081 } 082 @Override 083 public String toString() { 084 return null; 085 } 086 public int compareTo(String str) throws PageException { 087 return "".compareTo(str); 088 //throw new ExpressionException("can't compare null with a string value"); 089 } 090 public int compareTo(boolean b) throws PageException { 091 throw new ExpressionException("can't compare null with a boolean value"); 092 } 093 public int compareTo(double d) throws PageException { 094 throw new ExpressionException("can't compare null with a numeric value"); 095 } 096 public int compareTo(DateTime dt) throws PageException { 097 throw new ExpressionException("can't compare null with a date object"); 098 } 099}