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 @Override 063 public Collection.Key getKey() { 064 return KeyImpl.init(Caster.toString(position)); 065 } 066 067 @Override 068 public String getKeyAsString() { 069 return Caster.toString(position); 070 } 071 072 @Override 073 public Object get(PageContext pc) throws PageException { 074 return getE(position); 075 } 076 077 @Override 078 public Object get(PageContext pc, Object defaultValue) { 079 return get(position,defaultValue); 080 } 081 082 @Override 083 public Object touch(PageContext pc) throws PageException { 084 Object o=get(position,null); 085 if(o!=null) return o; 086 return setE(position,new StructImpl()); 087 } 088 089 @Override 090 public Object touchEL(PageContext pc) { 091 Object o=get(position,null); 092 if(o!=null) return o; 093 return setEL(position,new StructImpl()); 094 } 095 096 @Override 097 public Object set(PageContext pc, Object value) throws PageException { 098 return setE(position,value); 099 } 100 101 @Override 102 public Object setEL(PageContext pc, Object value) { 103 return setEL(position,value); 104 } 105 106 @Override 107 public Object remove(PageContext pc) throws PageException { 108 return removeE(position); 109 } 110 111 @Override 112 public Object removeEL(PageContext pc) { 113 return removeEL(position); 114 } 115 116 @Override 117 public Object getParent() { 118 return this; 119 } 120 121 @Override 122 public String castToString() throws PageException { 123 return Caster.toString(getE(position)); 124 } 125 126 @Override 127 public String castToString(String defaultValue) { 128 Object value = get(position,null); 129 if(value==null) return defaultValue; 130 return Caster.toString(value,defaultValue); 131 } 132 133 @Override 134 public boolean castToBooleanValue() throws PageException { 135 return Caster.toBooleanValue(getE(position)); 136 } 137 138 @Override 139 public Boolean castToBoolean(Boolean defaultValue) { 140 Object value = get(position,defaultValue); 141 if(value==null)return defaultValue; 142 return Caster.toBoolean(value,defaultValue); 143 } 144 145 @Override 146 public double castToDoubleValue() throws PageException { 147 return Caster.toDoubleValue(getE(position)); 148 } 149 150 @Override 151 public double castToDoubleValue(double defaultValue) { 152 Object value = get(position,null); 153 if(value==null)return defaultValue; 154 return Caster.toDoubleValue(value,defaultValue); 155 } 156 157 @Override 158 public DateTime castToDateTime() throws PageException { 159 return Caster.toDate(getE(position),null); 160 } 161 162 @Override 163 public DateTime castToDateTime(DateTime defaultValue) { 164 Object value = get(position,defaultValue); 165 if(value==null)return defaultValue; 166 return DateCaster.toDateAdvanced(value, true, null, defaultValue); 167 } 168 169 170 @Override 171 public int compareTo(boolean b) throws PageException { 172 return Operator.compare(castToBooleanValue(), b); 173 } 174 175 @Override 176 public int compareTo(DateTime dt) throws PageException { 177 return Operator.compare((Date)castToDateTime(), (Date)dt); 178 } 179 180 @Override 181 public int compareTo(double d) throws PageException { 182 return Operator.compare(castToDoubleValue(), d); 183 } 184 185 @Override 186 public int compareTo(String str) throws PageException { 187 return Operator.compare(castToString(), str); 188 } 189 190 @Override 191 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 192 DumpTable table= (DumpTable) super.toDumpData(pageContext, maxlevel,dp); 193 table.setTitle("SV Array"); 194 return table; 195 } 196 197 @Override 198 public synchronized Object clone() { 199 return duplicate(true); 200 } 201 202 @Override 203 public synchronized Collection duplicate(boolean deepCopy) { 204 SVArray sva = new SVArray(); 205 duplicate(sva,deepCopy); 206 sva.position=position; 207 return sva; 208 } 209 }