001 package railo.runtime.type; 002 003 import java.util.Date; 004 005 import railo.runtime.PageContext; 006 import railo.runtime.dump.DumpData; 007 import railo.runtime.dump.DumpProperties; 008 import railo.runtime.dump.DumpTable; 009 import railo.runtime.exp.PageException; 010 import railo.runtime.op.Caster; 011 import railo.runtime.op.Operator; 012 import railo.runtime.op.date.DateCaster; 013 import railo.runtime.type.dt.DateTime; 014 015 public final class CastableArray extends ArrayImpl { 016 017 private final Object value; 018 019 /** 020 * Constructor of the class 021 * generates as string list of the array 022 */ 023 public CastableArray(){value=null;} 024 025 public CastableArray(Object value){ 026 this.value=value; 027 } 028 029 /** 030 * @see railo.runtime.type.ArrayImpl#duplicate(boolean) 031 */ 032 public synchronized Collection duplicate(boolean deepCopy) { 033 return duplicate(new CastableArray(value),deepCopy); 034 } 035 036 037 038 /** 039 * @see railo.runtime.type.util.ArraySupport#castToBooleanValue() 040 */ 041 public boolean castToBooleanValue() throws PageException { 042 return Caster.toBooleanValue(getValue()); 043 044 } 045 046 /** 047 * @see railo.runtime.op.Castable#castToBoolean(java.lang.Boolean) 048 */ 049 public Boolean castToBoolean(Boolean defaultValue) { 050 try { 051 return Caster.toBoolean(getValue(),defaultValue); 052 } catch (PageException e) { 053 return defaultValue; 054 } 055 } 056 057 /** 058 * @see railo.runtime.type.util.ArraySupport#castToDateTime() 059 */ 060 public DateTime castToDateTime() throws PageException { 061 return Caster.toDate(getValue(),null); 062 } 063 064 /** 065 * @see railo.runtime.op.Castable#castToDateTime(railo.runtime.type.dt.DateTime) 066 */ 067 public DateTime castToDateTime(DateTime defaultValue) { 068 try { 069 return DateCaster.toDateAdvanced(getValue(), true, null,defaultValue); 070 } catch (PageException e) { 071 return defaultValue; 072 } 073 } 074 075 /** 076 * @see railo.runtime.type.util.ArraySupport#castToDoubleValue() 077 */ 078 public double castToDoubleValue() throws PageException { 079 return Caster.toDoubleValue(getValue()); 080 } 081 082 /** 083 * @see railo.runtime.op.Castable#castToDoubleValue(double) 084 */ 085 public double castToDoubleValue(double defaultValue) { 086 try { 087 return Caster.toDoubleValue(getValue(),defaultValue); 088 } catch (PageException e) { 089 return defaultValue; 090 } 091 } 092 093 /** 094 * @see railo.runtime.type.util.ArraySupport#castToString() 095 */ 096 public String castToString() throws PageException { 097 return Caster.toString(getValue()); 098 } 099 100 /** 101 * @see railo.runtime.type.util.StructSupport#castToString(java.lang.String) 102 */ 103 public String castToString(String defaultValue) { 104 try { 105 return Caster.toString(getValue(),defaultValue); 106 } catch (PageException e) { 107 return defaultValue; 108 } 109 } 110 111 /** 112 * @see railo.runtime.type.util.ArraySupport#compareTo(boolean) 113 */ 114 public int compareTo(boolean b) throws PageException { 115 return Operator.compare(getValue(), b); 116 } 117 118 /** 119 * @see railo.runtime.type.util.ArraySupport#compareTo(railo.runtime.type.dt.DateTime) 120 */ 121 public int compareTo(DateTime dt) throws PageException { 122 return Operator.compare(getValue(), (Date)dt); 123 } 124 125 /** 126 * @see railo.runtime.type.util.ArraySupport#compareTo(double) 127 */ 128 public int compareTo(double d) throws PageException { 129 return Operator.compare(getValue(),d); 130 } 131 132 /** 133 * @see railo.runtime.type.util.ArraySupport#compareTo(java.lang.String) 134 */ 135 public int compareTo(String str) throws PageException { 136 return Operator.compare(getValue(), str); 137 } 138 139 140 private Object getValue() throws PageException { 141 if(value!=null)return value; 142 return List.arrayToList(this, ","); 143 } 144 145 /** 146 * @see railo.runtime.type.ArrayImpl#toDumpData(railo.runtime.PageContext, int, railo.runtime.dump.DumpProperties) 147 */ 148 public DumpData toDumpData(PageContext pageContext, int maxlevel,DumpProperties dp) { 149 DumpTable dt= (DumpTable) super.toDumpData(pageContext, maxlevel, dp); 150 dt.setTitle("Castable Array"); 151 return dt; 152 } 153 154 }