1 23 24 25 26 package org.apache.slide.search.basic.sample; 27 28 import org.apache.slide.search.basic.*; 29 30 import java.util.Collection ; 31 import java.util.Iterator ; 32 import org.apache.slide.common.SlideException; 33 import org.apache.slide.search.BadQueryException; 34 import org.apache.slide.search.RequestedResource; 35 import org.apache.slide.search.SearchException; 36 import org.apache.slide.structure.ObjectNode; 37 import org.apache.slide.structure.SubjectNode; 38 39 47 public class BasicExpressionSample implements IBasicExpression { 48 49 50 51 String theExecutableCommand; 52 53 54 IBasicExpressionFactory factory; 55 56 61 BasicExpressionSample (String command, IBasicExpressionFactory factory){ 62 theExecutableCommand = command; 63 this.factory = factory; 64 } 65 66 69 BasicExpressionSample (String mergeOperator, 70 Collection children, 71 IBasicExpressionFactory factory) 72 throws BadQueryException 73 { 74 this.factory = factory; 75 Iterator it = children.iterator(); 76 BasicExpressionSample firstChild = (BasicExpressionSample)it.next(); 77 78 if (firstChild == null) 79 throw new BadQueryException (mergeOperator + " needs at least one nested element"); 80 81 theExecutableCommand = firstChild.theExecutableCommand; 82 83 while (it.hasNext()) { 85 BasicExpressionSample exp = (BasicExpressionSample)it.next(); 86 theExecutableCommand += " " + mergeOperator + " " + exp.theExecutableCommand; 87 } 88 } 89 90 98 public IBasicResultSet execute() throws SearchException { 99 100 IBasicResultSet result = new BasicResultSetImpl (true); 101 102 System.out.println("now execute: " + theExecutableCommand); 105 106 ObjectNode node = new SubjectNode("/"); RequestedResource resource = null; 111 IBasicQuery query = factory.getQuery(); 112 113 try { 114 resource = new ComparableResourceImpl 115 (node, query.getSearchToken(), query.getScope(), 116 factory.getPropertyProvider()); 117 } 118 catch (SlideException e) { 119 throw new SearchException (e); 120 } 121 122 result.add (resource); 123 124 125 return result; 126 } 127 128 public void setFactory (IBasicExpressionFactory factory) { 129 this.factory = factory; 130 } 131 132 public IBasicExpressionFactory getFactory() { 133 return this.factory; 134 } 135 136 137 } 138 139 | Popular Tags |