1 15 package org.josql.expressions; 16 17 import java.util.Map ; 18 import java.util.Collection ; 19 20 import org.josql.Query; 21 import org.josql.QueryExecutionException; 22 import org.josql.QueryParseException; 23 24 import org.josql.internal.Utilities; 25 26 public class SelectItemExpression extends Expression 27 { 28 29 public static final String KEY = "key"; 30 public static final String VALUE = "value"; 31 32 private Expression exp = null; 33 private boolean fixedResult = false; 34 private Class addItemsType = null; 35 private String addItemsMapType = null; 36 private String alias = null; 37 38 public String getAlias () 39 { 40 41 return this.alias; 42 43 } 44 45 public void setAlias (String a) 46 { 47 48 this.alias = Utilities.stripQuotes (a); 49 50 } 51 52 public boolean hasFixedResult (Query q) 53 { 54 55 return this.fixedResult; 56 57 } 58 59 public Class getExpectedReturnType (Query q) 60 throws QueryParseException 61 { 62 63 return this.exp.getExpectedReturnType (q); 64 65 } 66 67 public void init (Query q) 68 throws QueryParseException 69 { 70 71 this.exp.init (q); 72 73 this.fixedResult = this.exp.hasFixedResult (q); 74 75 102 103 } 104 105 public void setAddMapType (String t) 106 { 107 108 this.addItemsMapType = t; 109 110 } 111 112 public Collection getAddItems (Object v) 113 { 114 115 if (Map .class.isAssignableFrom (this.addItemsType)) 116 { 117 118 boolean k = this.addItemsMapType.equals (SelectItemExpression.KEY); 119 120 Map m = (Map ) v; 121 122 if (k) 123 { 124 125 return m.keySet (); 126 127 } 128 129 return m.values (); 130 131 } 132 133 if (v instanceof Collection ) 134 { 135 136 return (Collection ) v; 137 138 } 139 140 java.util.List l = new java.util.ArrayList (); 142 l.add (v); 143 144 return l; 145 146 } 147 148 public boolean isAddItemsFromCollectionOrMap () 149 { 150 151 return this.addItemsType != null; 152 153 } 154 155 public void setAddItemsType (Class c) 156 { 157 158 this.addItemsType = c; 159 160 } 161 162 public Expression getExpression () 163 { 164 165 return this.exp; 166 167 } 168 169 public void setExpression (Expression exp) 170 { 171 172 this.exp = exp; 173 174 } 175 176 public boolean isTrue (Object o, 177 Query q) 178 throws QueryExecutionException 179 { 180 181 return this.exp.isTrue (o, 182 q); 183 184 } 185 186 public Object getValue (Object o, 187 Query q) 188 throws QueryExecutionException 189 { 190 191 return this.exp.getValue (o, 192 q); 193 194 } 195 196 public String toString () 197 { 198 199 StringBuffer b = new StringBuffer (); 200 201 if (this.isAddItemsFromCollectionOrMap ()) 202 { 203 204 b.append ("[*"); 205 206 if (this.addItemsMapType != null) 207 { 208 209 b.append (", "); 210 b.append (this.addItemsMapType); 211 212 } 213 214 b.append ("] "); 215 216 } 217 218 b.append (this.exp); 219 220 if (this.alias != null) 221 { 222 223 b.append (" "); 224 b.append (this.alias); 225 226 } 227 228 return b.toString (); 229 230 } 231 232 } 233
| Popular Tags
|