1 23 24 package org.apache.slide.search.basic; 25 26 import java.util.Collection ; 27 28 import org.apache.slide.content.NodeProperty.NamespaceCache; 29 import org.apache.slide.search.BadQueryException; 30 import org.apache.slide.search.InvalidQueryException; 31 import org.apache.slide.search.PropertyProvider; 32 import org.apache.slide.search.basic.expression.AndExpression; 33 import org.apache.slide.search.basic.expression.ContainsExpression; 34 import org.apache.slide.search.basic.expression.EQExpression; 35 import org.apache.slide.search.basic.expression.EmptyExpression; 36 import org.apache.slide.search.basic.expression.GTEExpression; 37 import org.apache.slide.search.basic.expression.GTExpression; 38 import org.apache.slide.search.basic.expression.GenericBasicExpression; 39 import org.apache.slide.search.basic.expression.IsCollectionExpression; 40 import org.apache.slide.search.basic.expression.IsDefinedExpression; 41 import org.apache.slide.search.basic.expression.IsPrincipalExpression; 42 import org.apache.slide.search.basic.expression.LTEExpression; 43 import org.apache.slide.search.basic.expression.LTExpression; 44 import org.apache.slide.search.basic.expression.NotContainsExpression; 45 import org.apache.slide.search.basic.expression.NotEQExpression; 46 import org.apache.slide.search.basic.expression.NotGTEExpression; 47 import org.apache.slide.search.basic.expression.NotGTExpression; 48 import org.apache.slide.search.basic.expression.NotIsCollectionExpression; 49 import org.apache.slide.search.basic.expression.NotIsDefinedExpression; 50 import org.apache.slide.search.basic.expression.NotIsPrincipalExpression; 51 import org.apache.slide.search.basic.expression.NotLTEExpression; 52 import org.apache.slide.search.basic.expression.NotLTExpression; 53 import org.apache.slide.search.basic.expression.NotPropContainsExpression; 54 import org.apache.slide.search.basic.expression.OrExpression; 55 import org.apache.slide.search.basic.expression.PropContainsExpression; 56 import org.jdom.Element; 57 58 62 public class BasicExpressionFactory implements IBasicExpressionFactory { 63 64 66 69 protected ComparableResourcesPool requestedResourcePool = null; 70 71 74 protected IBasicQuery query = null; 75 76 79 protected PropertyProvider propertyProvider = null; 80 81 82 83 86 public BasicExpressionFactory() { 87 this(null); 88 } 89 90 96 public BasicExpressionFactory(ComparableResourcesPool requestedResourcePool) { 97 this.requestedResourcePool = requestedResourcePool; 98 } 99 100 110 public void init (IBasicQuery query, PropertyProvider propertyProvider) throws BadQueryException { 111 this.query = query; 112 this.propertyProvider = propertyProvider; 113 } 114 115 120 public IBasicQuery getQuery() { 121 return query; 122 } 123 124 129 public PropertyProvider getPropertyProvider() { 130 return propertyProvider; 131 } 132 133 134 146 public IBasicExpression createMergeExpression (String name, String namespace, Collection expressionsToMerge) throws BadQueryException { 147 148 IBasicExpression result = null; 149 if (name == null) { 150 result = new EmptyExpression(getRequestedResourcePool()); 151 } 152 else { 153 if (NamespaceCache.DEFAULT_URI.equals(namespace)) { 154 if (name.equals (Literals.AND)) 155 result = new AndExpression (new Element(name, NamespaceCache.getNamespace(namespace)), 156 expressionsToMerge); 157 158 else if (name.equals (Literals.OR)) 159 result = new OrExpression (new Element(name, NamespaceCache.getNamespace(namespace)), 160 expressionsToMerge); 161 } 162 if (result == null) { 163 throw new InvalidQueryException 164 ("operator <" + NamespaceCache.DEFAULT_URI + ":" + name + "> is an unprocessable entity"); 165 166 } 167 } 168 if (result != null) result.setFactory(this); 169 return result; 170 } 171 172 182 public IBasicExpression createExpression (Element element) throws BadQueryException { 183 184 IBasicExpression result = null; 185 if (element == null) { 186 result = new EmptyExpression(getRequestedResourcePool()); 187 } 188 else { 189 String namespace = element.getNamespace().getURI(); 190 String name = element.getName(); 191 if (namespace.equals (NamespaceCache.DEFAULT_URI)) { 192 result = createDAVExpression(element); 193 } 194 else if (namespace.equals (NamespaceCache.SLIDE_URI)) { 195 result = createNonDAVExpression(element, namespace); 196 } 197 else { 198 throw new InvalidQueryException 199 ("operator <" + namespace + ":" + name + "> is an unprocessable entity"); 200 201 } 202 } 203 204 if (result != null) result.setFactory(this); 205 return result; 206 } 207 208 209 private GenericBasicExpression createDAVExpression 210 (Element e) throws BadQueryException 211 { 212 String name = e.getName(); 213 GenericBasicExpression result = null; 214 215 216 if (name.equals (Literals.GT)) 217 result = new GTExpression (e, getRequestedResourcePool()); 218 219 else if (name.equals (Literals.NOT_GT)) 220 result = new NotGTExpression (e, getRequestedResourcePool()); 221 222 else if (name.equals (Literals.GTE)) 223 result = new GTEExpression (e, getRequestedResourcePool()); 224 225 else if (name.equals (Literals.NOT_GTE)) 226 result = new NotGTEExpression (e, getRequestedResourcePool()); 227 228 else if (name.equals (Literals.LT)) 229 result = new LTExpression (e, getRequestedResourcePool()); 230 231 else if (name.equals (Literals.NOT_LT)) 232 result = new NotLTExpression (e, getRequestedResourcePool()); 233 234 else if (name.equals (Literals.LTE)) 235 result = new LTEExpression (e, getRequestedResourcePool()); 236 237 else if (name.equals (Literals.NOT_LTE)) 238 result = new NotLTEExpression (e, getRequestedResourcePool()); 239 240 else if (name.equals (Literals.EQ)) 241 result = new EQExpression (e, getRequestedResourcePool()); 242 243 else if (name.equals (Literals.NOT_EQ)) 244 result = new NotEQExpression (e, getRequestedResourcePool()); 245 246 else if (name.equals (Literals.CONTAINS)) 247 result = new ContainsExpression (e, getRequestedResourcePool()); 248 249 else if (name.equals (Literals.NOT_CONTAINS)) 250 result = new NotContainsExpression (e, getRequestedResourcePool()); 251 252 else if (name.equals (Literals.ISCOLLECTION)) 253 result = new IsCollectionExpression (e, getRequestedResourcePool()); 254 255 else if (name.equals (Literals.NOT_ISCOLLECTION)) 256 result = new NotIsCollectionExpression (e, getRequestedResourcePool()); 257 258 else if (name.equals (Literals.ISDEFINED)) 259 result = new IsDefinedExpression (e, getRequestedResourcePool()); 260 261 else if (name.equals (Literals.NOT_ISDEFINED)) 262 result = new NotIsDefinedExpression (e, getRequestedResourcePool()); 263 264 else 265 throw new InvalidQueryException 266 ("operator <" + NamespaceCache.DEFAULT_URI + ":" + name + "> is an unprocessable entity"); 267 268 return result; 269 } 270 271 private GenericBasicExpression createNonDAVExpression 272 (Element e, String namespace) throws BadQueryException 273 { 274 275 String name = e.getName(); 276 GenericBasicExpression result = null; 277 278 if (namespace.equals (NamespaceCache.SLIDE_URI) 279 && name.equals (Literals.ISPRINCIPAL)) 280 281 result = new IsPrincipalExpression (e, getRequestedResourcePool()); 282 283 else if (namespace.equals (NamespaceCache.SLIDE_URI) 284 && name.equals (Literals.NOT_ISPRINCIPAL)) 285 286 result = new NotIsPrincipalExpression (e, getRequestedResourcePool()); 287 288 else if (namespace.equals (NamespaceCache.SLIDE_URI) 289 && name.equals (Literals.PROPCONTAINS)) 290 291 result = new PropContainsExpression (e, getRequestedResourcePool()); 292 293 else if (namespace.equals (NamespaceCache.SLIDE_URI) 294 && name.equals (Literals.NOT_PROPCONTAINS)) 295 296 result = new NotPropContainsExpression (e, getRequestedResourcePool()); 297 298 else 299 throw new InvalidQueryException 300 ("operator <" + namespace + ":" + name + "> is an unprocessable entity"); 301 302 return result; 303 } 304 305 306 315 protected ComparableResourcesPool getRequestedResourcePool() throws BadQueryException { 316 317 if (requestedResourcePool == null) { 318 requestedResourcePool = 319 new ComparableResourcesPoolImpl(query.getSearchToken(), query.getScope(), getPropertyProvider()); 320 } 321 return requestedResourcePool; 322 } 323 } 324 325 | Popular Tags |