1 15 package org.josql.expressions; 16 17 import org.josql.Query; 18 import org.josql.QueryExecutionException; 19 import org.josql.QueryParseException; 20 21 29 public class ConstantExpression extends ValueExpression 30 { 31 32 private Object val = null; 33 34 42 public Class getExpectedReturnType (Query q) 43 { 44 45 if (this.val == null) 46 { 47 48 return null; 49 50 } 51 52 return this.val.getClass (); 53 54 } 55 56 61 public void init (Query q) 62 { 63 64 66 } 67 68 public void setValue (Object v) 69 { 70 71 this.val = v; 72 73 } 74 75 84 public boolean isTrue (Object o, 85 Query q) 86 { 87 88 if (this.val == null) 89 { 90 91 return false; 92 93 } 94 95 if (this.val instanceof Number ) 96 { 97 98 return ((Number ) this.val).doubleValue () > 0; 99 100 } 101 102 return true; 103 104 } 105 106 113 public Object getValue (Object o, 114 Query q) 115 { 116 117 return this.val; 118 119 } 120 121 128 public Object evaluate (Object o, 129 Query q) 130 { 131 132 return this.val; 133 134 } 135 136 142 public boolean hasFixedResult (Query q) 143 { 144 145 return true; 147 148 } 149 150 160 public String toString () 161 { 162 163 String v = null; 164 165 if (this.val == null) 166 { 167 168 v = val + ""; 169 170 } else { 171 172 if (this.val instanceof String ) 173 { 174 175 v = "'" + val + "'"; 176 177 } else { 178 179 v = this.val.toString (); 180 181 } 182 183 } 184 185 if (this.isBracketed ()) 186 { 187 188 v = "(" + v + ")"; 189 190 } 191 192 return v; 193 194 } 195 196 } 197
| Popular Tags
|