1 22 23 package org.xquark.mediator.plan ; 24 25 import java.util.ArrayList ; 26 27 import org.xquark.mediator.decomposer.Utils; 28 import org.xquark.mediator.runtime.MediatorException; 29 import org.xquark.xquery.parser.XQueryExpression; 30 31 public abstract class OpUn extends Operator { 32 private static final String RCSRevision = "$Revision: 1.5 $"; 36 private static final String RCSName = "$Name: $"; 37 protected Operator childOperator = null ; 41 42 48 public OpUn(ExecutionPlan plan, XQueryExpression expression, Operator childOperator) throws MediatorException { 49 super(plan, expression) ; 50 this.childOperator = childOperator ; 51 if (childOperator != null) { 52 childOperator.setParentOperator(this); 53 addPaths(childOperator.getPaths()); 54 } 55 } 56 57 61 public void accept(OperatorVisitor visitor) throws MediatorException { 62 visitor.visit(this); 63 } 64 65 71 public ResultSet executeQuery(DynamicContext context) throws MediatorException { 72 if (childOperator != null) { 73 OperatorRunnable or = childOperator.getOperatorRunnable(context); 74 or.run() ; 75 return getResultSet(context, or); 76 } 77 return getResultSet(context, null); 78 } 79 80 84 protected abstract ResultSet getResultSet(DynamicContext context, OperatorRunnable or) throws MediatorException; 85 86 92 public Operator getChildOperator() { return childOperator ; } 93 94 105 118 127 131 137 141 142 148 152 156 public boolean isSource() { 157 return false ; 158 } 159 160 163 public ArrayList getSources() { 164 if (sources == null) 165 sources = childOperator.getSources() ; 166 return sources ; 167 } 168 169 public void terminate() { 170 if (childOperator != null) 171 childOperator.terminate(); 172 } 173 174 public void setPrepared() throws MediatorException { 175 if (prepared) return; 176 prepared = true; 177 if (childOperator != null) 178 childOperator.setPrepared(); 179 } 180 181 public String toCompleteString(int indent) { 182 StringBuffer buf = new StringBuffer () ; 183 buf.append(Utils.makeIndent(indent) + "<" + getClass().getName() + " size=" + size + " id size=" + idsize + " isLet=\"" + islet + "\" valueDepends=\"" + valueDepends + "\" whereDepends=\"" + whereDepends + "\">\n") ; 184 buf.append(Utils.makeIndent(indent + 1) + "<Expression>\n") ; 185 buf.append(Utils.makeIndent(indent + 2) + expression + "\n") ; 186 buf.append(Utils.makeIndent(indent + 1) + "</Expression>\n") ; 187 if (paths != null) { 195 buf.append(Utils.makeIndent(indent + 1) + "<Paths>\n") ; 196 for (int i = 0 ; i < paths.size() ; i ++) { 197 buf.append(Utils.makeIndent(indent + 2) + "<Path>" + paths.get(i) + "</Path>\n") ; 198 } 199 buf.append(Utils.makeIndent(indent + 1) + "</Paths>\n") ; 200 } 201 buf.append(Utils.makeIndent(indent + 1) + "<Element>\n") ; 202 if (this.childOperator != null) buf.append(this.childOperator.toCompleteString(indent + 2)) ; 203 buf.append(Utils.makeIndent(indent + 1) + "</Element>\n") ; 204 buf.append(Utils.makeIndent(indent) + "</" + getClass().getName() + ">\n") ; 205 return buf.toString() ; 206 } 207 } 208 | Popular Tags |