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.ExpressionException; 010 import railo.runtime.exp.PageException; 011 import railo.runtime.op.Caster; 012 import railo.runtime.op.Operator; 013 import railo.runtime.op.date.DateCaster; 014 import railo.runtime.type.dt.DateTime; 015 import railo.runtime.type.ref.Reference; 016 017 /** 018 * Simple Value Array, a Array that can't cast to a Simple Value 019 */ 020 public final class SVArray extends ArrayImpl implements Reference { 021 022 private int position=1; 023 024 /** 025 * Constructor of the class 026 */ 027 public SVArray() { 028 super(); 029 } 030 031 /** 032 * Constructor of the class 033 * @param dimension 034 * @throws ExpressionException 035 */ 036 public SVArray(int dimension) throws ExpressionException { 037 super(dimension); 038 } 039 040 /** 041 * Constructor of the class 042 * @param objects 043 */ 044 public SVArray(Object[] objects) { 045 super(objects); 046 } 047 048 /** 049 * @return Returns the position. 050 */ 051 public int getPosition() { 052 return position; 053 } 054 055 /** 056 * @param position The position to set. 057 */ 058 public void setPosition(int position) { 059 this.position = position; 060 } 061 062 /** 063 * @see railo.runtime.type.ref.Reference#getKey() 064 */ 065 public Collection.Key getKey() { 066 return KeyImpl.init(Caster.toString(position)); 067 } 068 069 /** 070 * 071 * @see railo.runtime.type.ref.Reference#getKeyAsString() 072 */ 073 public String getKeyAsString() { 074 return Caster.toString(position); 075 } 076 077 /** 078 * @see railo.runtime.type.ref.Reference#get(railo.runtime.PageContext) 079 */ 080 public Object get(PageContext pc) throws PageException { 081 return getE(position); 082 } 083 084 /** 085 * 086 * @see railo.runtime.type.ref.Reference#get(railo.runtime.PageContext, java.lang.Object) 087 */ 088 public Object get(PageContext pc, Object defaultValue) { 089 return get(position,defaultValue); 090 } 091 092 /** 093 * @see railo.runtime.type.ref.Reference#touch(railo.runtime.PageContext) 094 */ 095 public Object touch(PageContext pc) throws PageException { 096 Object o=get(position,null); 097 if(o!=null) return o; 098 return setE(position,new StructImpl()); 099 } 100 101 /** 102 * @see railo.runtime.type.ref.Reference#touchEL(railo.runtime.PageContext) 103 */ 104 public Object touchEL(PageContext pc) { 105 Object o=get(position,null); 106 if(o!=null) return o; 107 return setEL(position,new StructImpl()); 108 } 109 110 /** 111 * @see railo.runtime.type.ref.Reference#set(railo.runtime.PageContext, java.lang.Object) 112 */ 113 public Object set(PageContext pc, Object value) throws PageException { 114 return setE(position,value); 115 } 116 117 /** 118 * @see railo.runtime.type.ref.Reference#setEL(railo.runtime.PageContext, java.lang.Object) 119 */ 120 public Object setEL(PageContext pc, Object value) { 121 return setEL(position,value); 122 } 123 124 /** 125 * @see railo.runtime.type.ref.Reference#remove(railo.runtime.PageContext) 126 */ 127 public Object remove(PageContext pc) throws PageException { 128 return removeE(position); 129 } 130 131 /** 132 * @see railo.runtime.type.ref.Reference#removeEL(railo.runtime.PageContext) 133 */ 134 public Object removeEL(PageContext pc) { 135 return removeEL(position); 136 } 137 138 /** 139 * @see railo.runtime.type.ref.Reference#getParent() 140 */ 141 public Object getParent() { 142 return this; 143 } 144 145 /** 146 * @see railo.runtime.op.Castable#castToString() 147 */ 148 public String castToString() throws PageException { 149 return Caster.toString(getE(position)); 150 } 151 152 /** 153 * @see railo.runtime.type.util.StructSupport#castToString(java.lang.String) 154 */ 155 public String castToString(String defaultValue) { 156 Object value = get(position,null); 157 if(value==null) return defaultValue; 158 return Caster.toString(value,defaultValue); 159 } 160 161 /** 162 * @see railo.runtime.op.Castable#castToBooleanValue() 163 */ 164 public boolean castToBooleanValue() throws PageException { 165 return Caster.toBooleanValue(getE(position)); 166 } 167 168 /** 169 * @see railo.runtime.op.Castable#castToBoolean(java.lang.Boolean) 170 */ 171 public Boolean castToBoolean(Boolean defaultValue) { 172 Object value = get(position,defaultValue); 173 if(value==null)return defaultValue; 174 return Caster.toBoolean(value,defaultValue); 175 } 176 177 /** 178 * @see railo.runtime.op.Castable#castToDoubleValue() 179 */ 180 public double castToDoubleValue() throws PageException { 181 return Caster.toDoubleValue(getE(position)); 182 } 183 184 /** 185 * @see railo.runtime.op.Castable#castToDoubleValue(double) 186 */ 187 public double castToDoubleValue(double defaultValue) { 188 Object value = get(position,null); 189 if(value==null)return defaultValue; 190 return Caster.toDoubleValue(value,defaultValue); 191 } 192 193 /** 194 * @see railo.runtime.op.Castable#castToDateTime() 195 */ 196 public DateTime castToDateTime() throws PageException { 197 return Caster.toDate(getE(position),null); 198 } 199 200 /** 201 * @see railo.runtime.op.Castable#castToDateTime(railo.runtime.type.dt.DateTime) 202 */ 203 public DateTime castToDateTime(DateTime defaultValue) { 204 Object value = get(position,defaultValue); 205 if(value==null)return defaultValue; 206 return DateCaster.toDateAdvanced(value, true, null, defaultValue); 207 } 208 209 210 /** 211 * @see railo.runtime.op.Castable#compare(boolean) 212 */ 213 public int compareTo(boolean b) throws PageException { 214 return Operator.compare(castToBooleanValue(), b); 215 } 216 217 /** 218 * @see railo.runtime.op.Castable#compareTo(railo.runtime.type.dt.DateTime) 219 */ 220 public int compareTo(DateTime dt) throws PageException { 221 return Operator.compare((Date)castToDateTime(), (Date)dt); 222 } 223 224 /** 225 * @see railo.runtime.op.Castable#compareTo(double) 226 */ 227 public int compareTo(double d) throws PageException { 228 return Operator.compare(castToDoubleValue(), d); 229 } 230 231 /** 232 * @see railo.runtime.op.Castable#compareTo(java.lang.String) 233 */ 234 public int compareTo(String str) throws PageException { 235 return Operator.compare(castToString(), str); 236 } 237 238 /** 239 * 240 * @see railo.runtime.type.ArrayImpl#toDumpData(railo.runtime.PageContext, int) 241 */ 242 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 243 DumpTable table= (DumpTable) super.toDumpData(pageContext, maxlevel,dp); 244 table.setTitle("SV Array"); 245 return table; 246 } 247 248 /** 249 * 250 * @see railo.runtime.type.ArrayImpl#clone() 251 */ 252 public synchronized Object clone() { 253 return duplicate(true); 254 } 255 256 /** 257 * 258 * @see railo.runtime.type.ArrayImpl#duplicate(boolean) 259 */ 260 public synchronized Collection duplicate(boolean deepCopy) { 261 SVArray sva = new SVArray(); 262 duplicate(sva,deepCopy); 263 sva.position=position; 264 return sva; 265 } 266 }