1 23 24 package org.apache.slide.search.basic.sample; 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.PropertyProvider; 31 import org.apache.slide.search.basic.IBasicExpression; 32 import org.apache.slide.search.basic.IBasicExpressionFactory; 33 import org.apache.slide.search.basic.IBasicQuery; 34 import org.jdom.Element; 35 36 42 public class BasicExpressionFactorySample implements IBasicExpressionFactory { 43 44 45 private IBasicQuery query; 46 protected PropertyProvider propertyProvider; 47 48 60 public IBasicExpression createMergeExpression (String mergeOperator, 61 String namespace, 62 Collection expressionsToMerge) 63 throws BadQueryException 64 { 65 BasicExpressionSample result = null; 67 try { 68 result = new BasicExpressionSample (mergeOperator, expressionsToMerge, this); 69 } 70 71 catch (ClassCastException e) { 74 System.out.println("one of the the expressions is not an ExpressionSample"); 75 } 76 77 return result; 78 } 79 80 90 public IBasicExpression createExpression (Element element) 91 throws BadQueryException 92 { 93 BasicExpressionSample result = null; 94 95 if (element == null) { 96 result = new BasicExpressionSample ("(no WHERE specified)", this); 97 } 98 else { 99 String namespace = element.getNamespace().getURI(); 100 if (namespace.equals (NamespaceCache.DEFAULT_URI)) 101 result = createDAVExpression (element); 102 103 } 107 108 return result; 109 } 110 111 112 121 private BasicExpressionSample createDAVExpression (Element e) { 122 String name = e.getName(); 123 BasicExpressionSample result = null; 124 125 if (name.equals ("eq")) { 126 String prop = propName (e); 127 String literal = e.getChild ("literal", e.getNamespace()).getText(); 128 result = new BasicExpressionSample ("(" + prop + " equals " + literal + ")", this); 129 } 130 131 else if (name.equals ("lt")) { 132 String prop = propName (e); 133 String literal = e.getChildText ("literal", e.getNamespace()); 134 135 result = new BasicExpressionSample ("(" + prop + " lower_than " + literal + ")", this); 136 } 137 139 return result; 140 } 141 142 151 public void init(IBasicQuery query, PropertyProvider propertyProvider) 152 throws BadQueryException 153 { 154 this.query = (IBasicQuery) query; 155 this.propertyProvider = propertyProvider; 156 } 157 158 164 public PropertyProvider getPropertyProvider() { 165 return propertyProvider; 166 } 167 168 174 public IBasicQuery getQuery() { 175 return query; 176 } 177 178 179 private String propName (Element e) { 180 Element propElem = e.getChild ("prop", e.getNamespace()); 181 Element el = (Element) propElem.getChildren().get(0); 182 return el.getName(); 183 } 184 } 185 186 | Popular Tags |