001 package railo.runtime.dump; 002 003 import java.util.Date; 004 005 import railo.runtime.exp.ExpressionException; 006 import railo.runtime.exp.PageException; 007 import railo.runtime.op.Castable; 008 import railo.runtime.op.Caster; 009 import railo.runtime.op.Operator; 010 import railo.runtime.op.date.DateCaster; 011 import railo.runtime.type.dt.DateTime; 012 013 public class SimpleDumpData implements DumpData,Castable { 014 015 private String data; 016 017 public SimpleDumpData(String data) { 018 this.data=data; 019 } 020 public SimpleDumpData(double data) { 021 this.data=Caster.toString(data); 022 } 023 024 public SimpleDumpData(boolean data) { 025 this.data=Caster.toString(data); 026 } 027 /** 028 * @see java.lang.Object#toString() 029 */ 030 public String toString() { 031 return data; 032 } 033 034 /** 035 * 036 * @see railo.runtime.op.Castable#castToBooleanValue() 037 */ 038 public boolean castToBooleanValue() throws PageException { 039 return Caster.toBooleanValue(data); 040 } 041 042 /** 043 * @see railo.runtime.op.Castable#castToBoolean(java.lang.Boolean) 044 */ 045 public Boolean castToBoolean(Boolean defaultValue) { 046 return Caster.toBoolean(data,defaultValue); 047 } 048 049 /** 050 * 051 * @see railo.runtime.op.Castable#castToDateTime() 052 */ 053 public DateTime castToDateTime() throws PageException { 054 return Caster.toDatetime(data, null); 055 } 056 057 /** 058 * @see railo.runtime.op.Castable#castToDateTime(railo.runtime.type.dt.DateTime) 059 */ 060 public DateTime castToDateTime(DateTime defaultValue) { 061 return DateCaster.toDateAdvanced(data,true,null,defaultValue); 062 } 063 064 /** 065 * 066 * @see railo.runtime.op.Castable#castToDoubleValue() 067 */ 068 public double castToDoubleValue() throws PageException { 069 return Caster.toDoubleValue(data); 070 } 071 072 /** 073 * @see railo.runtime.op.Castable#castToDoubleValue(double) 074 */ 075 public double castToDoubleValue(double defaultValue) { 076 return Caster.toDoubleValue(data,defaultValue); 077 } 078 079 /** 080 * 081 * @see railo.runtime.op.Castable#castToString() 082 */ 083 public String castToString() throws PageException { 084 return Caster.toString(data); 085 } 086 087 /** 088 * @see railo.runtime.op.Castable#castToString(java.lang.String) 089 */ 090 public String castToString(String defaultValue) { 091 return Caster.toString(data,defaultValue); 092 } 093 094 /** 095 * @see railo.runtime.op.Castable#compare(boolean) 096 */ 097 public int compareTo(boolean b) throws ExpressionException { 098 return Operator.compare(data, b); 099 } 100 101 /** 102 * @see railo.runtime.op.Castable#compareTo(railo.runtime.type.dt.DateTime) 103 */ 104 public int compareTo(DateTime dt) throws PageException { 105 return Operator.compare(data, (Date)dt); 106 } 107 108 /** 109 * @see railo.runtime.op.Castable#compareTo(double) 110 */ 111 public int compareTo(double d) throws PageException { 112 return Operator.compare(data, d); 113 } 114 115 /** 116 * @see railo.runtime.op.Castable#compareTo(java.lang.String) 117 */ 118 public int compareTo(String str) throws PageException { 119 return Operator.compare(data, str); 120 } 121 }