001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.query.algebra.helpers;
007:
008: import org.openrdf.query.algebra.And;
009: import org.openrdf.query.algebra.BNodeGenerator;
010: import org.openrdf.query.algebra.BinaryTupleOperator;
011: import org.openrdf.query.algebra.BinaryValueOperator;
012: import org.openrdf.query.algebra.Bound;
013: import org.openrdf.query.algebra.Compare;
014: import org.openrdf.query.algebra.CompareAll;
015: import org.openrdf.query.algebra.CompareAny;
016: import org.openrdf.query.algebra.CompareSubQueryValueOperator;
017: import org.openrdf.query.algebra.Count;
018: import org.openrdf.query.algebra.Datatype;
019: import org.openrdf.query.algebra.Difference;
020: import org.openrdf.query.algebra.Distinct;
021: import org.openrdf.query.algebra.EmptySet;
022: import org.openrdf.query.algebra.Exists;
023: import org.openrdf.query.algebra.Extension;
024: import org.openrdf.query.algebra.ExtensionElem;
025: import org.openrdf.query.algebra.Filter;
026: import org.openrdf.query.algebra.FunctionCall;
027: import org.openrdf.query.algebra.Group;
028: import org.openrdf.query.algebra.GroupElem;
029: import org.openrdf.query.algebra.In;
030: import org.openrdf.query.algebra.Intersection;
031: import org.openrdf.query.algebra.IsBNode;
032: import org.openrdf.query.algebra.IsLiteral;
033: import org.openrdf.query.algebra.IsResource;
034: import org.openrdf.query.algebra.IsURI;
035: import org.openrdf.query.algebra.Join;
036: import org.openrdf.query.algebra.Label;
037: import org.openrdf.query.algebra.Lang;
038: import org.openrdf.query.algebra.LangMatches;
039: import org.openrdf.query.algebra.LeftJoin;
040: import org.openrdf.query.algebra.Like;
041: import org.openrdf.query.algebra.LocalName;
042: import org.openrdf.query.algebra.MathExpr;
043: import org.openrdf.query.algebra.Max;
044: import org.openrdf.query.algebra.Min;
045: import org.openrdf.query.algebra.MultiProjection;
046: import org.openrdf.query.algebra.Namespace;
047: import org.openrdf.query.algebra.Not;
048: import org.openrdf.query.algebra.Or;
049: import org.openrdf.query.algebra.Order;
050: import org.openrdf.query.algebra.OrderElem;
051: import org.openrdf.query.algebra.Projection;
052: import org.openrdf.query.algebra.ProjectionElem;
053: import org.openrdf.query.algebra.ProjectionElemList;
054: import org.openrdf.query.algebra.QueryModelNode;
055: import org.openrdf.query.algebra.QueryModelVisitor;
056: import org.openrdf.query.algebra.QueryRoot;
057: import org.openrdf.query.algebra.Regex;
058: import org.openrdf.query.algebra.SameTerm;
059: import org.openrdf.query.algebra.SingletonSet;
060: import org.openrdf.query.algebra.Slice;
061: import org.openrdf.query.algebra.StatementPattern;
062: import org.openrdf.query.algebra.Str;
063: import org.openrdf.query.algebra.SubQueryValueOperator;
064: import org.openrdf.query.algebra.UnaryTupleOperator;
065: import org.openrdf.query.algebra.UnaryValueOperator;
066: import org.openrdf.query.algebra.Union;
067: import org.openrdf.query.algebra.ValueConstant;
068: import org.openrdf.query.algebra.Var;
069:
070: /**
071: * Base class for {@link QueryModelVisitor}s. This class implements all
072: * <tt>meet(... node)</tt> methods from the visitor interface, forwarding the
073: * call to a method for the node's supertype. This is done recursively until
074: * {@link #meetNode} is reached. This allows subclasses to easily define default
075: * behaviour for visited nodes of a certain type. The default implementation of
076: * {@link #meetDefault} is to visit the node's children.
077: */
078: public abstract class QueryModelVisitorBase<X extends Exception>
079: implements QueryModelVisitor<X> {
080:
081: public void meet(And node) throws X {
082: meetBinaryValueOperator(node);
083: }
084:
085: public void meet(BNodeGenerator node) throws X {
086: meetNode(node);
087: }
088:
089: public void meet(Bound node) throws X {
090: meetNode(node);
091: }
092:
093: public void meet(Compare node) throws X {
094: meetBinaryValueOperator(node);
095: }
096:
097: public void meet(CompareAll node) throws X {
098: meetCompareSubQueryValueOperator(node);
099: }
100:
101: public void meet(CompareAny node) throws X {
102: meetCompareSubQueryValueOperator(node);
103: }
104:
105: public void meet(Count node) throws X {
106: meetUnaryValueOperator(node);
107: }
108:
109: public void meet(Datatype node) throws X {
110: meetUnaryValueOperator(node);
111: }
112:
113: public void meet(Difference node) throws X {
114: meetBinaryTupleOperator(node);
115: }
116:
117: public void meet(Distinct node) throws X {
118: meetUnaryTupleOperator(node);
119: }
120:
121: public void meet(EmptySet node) throws X {
122: meetNode(node);
123: }
124:
125: public void meet(Exists node) throws X {
126: meetSubQueryValueOperator(node);
127: }
128:
129: public void meet(Extension node) throws X {
130: meetUnaryTupleOperator(node);
131: }
132:
133: public void meet(ExtensionElem node) throws X {
134: meetNode(node);
135: }
136:
137: public void meet(Filter node) throws X {
138: meetUnaryTupleOperator(node);
139: }
140:
141: public void meet(FunctionCall node) throws X {
142: meetNode(node);
143: }
144:
145: public void meet(Group node) throws X {
146: meetUnaryTupleOperator(node);
147: }
148:
149: public void meet(GroupElem node) throws X {
150: meetNode(node);
151: }
152:
153: public void meet(In node) throws X {
154: meetCompareSubQueryValueOperator(node);
155: }
156:
157: public void meet(Intersection node) throws X {
158: meetBinaryTupleOperator(node);
159: }
160:
161: public void meet(IsBNode node) throws X {
162: meetUnaryValueOperator(node);
163: }
164:
165: public void meet(IsLiteral node) throws X {
166: meetUnaryValueOperator(node);
167: }
168:
169: public void meet(IsResource node) throws X {
170: meetUnaryValueOperator(node);
171: }
172:
173: public void meet(IsURI node) throws X {
174: meetUnaryValueOperator(node);
175: }
176:
177: public void meet(Join node) throws X {
178: meetBinaryTupleOperator(node);
179: }
180:
181: public void meet(Label node) throws X {
182: meetUnaryValueOperator(node);
183: }
184:
185: public void meet(Lang node) throws X {
186: meetUnaryValueOperator(node);
187: }
188:
189: public void meet(LangMatches node) throws X {
190: meetBinaryValueOperator(node);
191: }
192:
193: public void meet(LeftJoin node) throws X {
194: meetBinaryTupleOperator(node);
195: }
196:
197: public void meet(LocalName node) throws X {
198: meetUnaryValueOperator(node);
199: }
200:
201: public void meet(Like node) throws X {
202: meetUnaryValueOperator(node);
203: }
204:
205: public void meet(MathExpr node) throws X {
206: meetBinaryValueOperator(node);
207: }
208:
209: public void meet(Max node) throws X {
210: meetUnaryValueOperator(node);
211: }
212:
213: public void meet(Min node) throws X {
214: meetUnaryValueOperator(node);
215: }
216:
217: public void meet(MultiProjection node) throws X {
218: meetUnaryTupleOperator(node);
219: }
220:
221: public void meet(Namespace node) throws X {
222: meetUnaryValueOperator(node);
223: }
224:
225: public void meet(Not node) throws X {
226: meetUnaryValueOperator(node);
227: }
228:
229: public void meet(Or node) throws X {
230: meetBinaryValueOperator(node);
231: }
232:
233: public void meet(Order node) throws X {
234: meetUnaryTupleOperator(node);
235: }
236:
237: public void meet(OrderElem node) throws X {
238: meetNode(node);
239: }
240:
241: public void meet(Projection node) throws X {
242: meetUnaryTupleOperator(node);
243: }
244:
245: public void meet(ProjectionElem node) throws X {
246: meetNode(node);
247: }
248:
249: public void meet(ProjectionElemList node) throws X {
250: meetNode(node);
251: }
252:
253: public void meet(QueryRoot node) throws X {
254: meetNode(node);
255: }
256:
257: public void meet(Regex node) throws X {
258: meetBinaryValueOperator(node);
259: }
260:
261: public void meet(Slice node) throws X {
262: meetUnaryTupleOperator(node);
263: }
264:
265: public void meet(SameTerm node) throws X {
266: meetBinaryValueOperator(node);
267: }
268:
269: public void meet(SingletonSet node) throws X {
270: meetNode(node);
271: }
272:
273: public void meet(StatementPattern node) throws X {
274: meetNode(node);
275: }
276:
277: public void meet(Str node) throws X {
278: meetUnaryValueOperator(node);
279: }
280:
281: public void meet(Union node) throws X {
282: meetBinaryTupleOperator(node);
283: }
284:
285: public void meet(ValueConstant node) throws X {
286: meetNode(node);
287: }
288:
289: public void meet(Var node) throws X {
290: meetNode(node);
291: }
292:
293: public void meetOther(QueryModelNode node) throws X {
294: if (node instanceof UnaryTupleOperator) {
295: meetUnaryTupleOperator((UnaryTupleOperator) node);
296: } else if (node instanceof BinaryTupleOperator) {
297: meetBinaryTupleOperator((BinaryTupleOperator) node);
298: } else if (node instanceof CompareSubQueryValueOperator) {
299: meetCompareSubQueryValueOperator((CompareSubQueryValueOperator) node);
300: } else if (node instanceof SubQueryValueOperator) {
301: meetSubQueryValueOperator((SubQueryValueOperator) node);
302: } else if (node instanceof UnaryValueOperator) {
303: meetUnaryValueOperator((UnaryValueOperator) node);
304: } else if (node instanceof BinaryValueOperator) {
305: meetBinaryValueOperator((BinaryValueOperator) node);
306: } else {
307: meetNode(node);
308: }
309: }
310:
311: /**
312: * Method called by all <tt>meet</tt> methods with a
313: * {@link UnaryTupleOperator} node as argument. Forwards the call to
314: * {@link #meetTupleExpr} by default.
315: *
316: * @param node
317: * The node that is being visited.
318: */
319: protected void meetUnaryTupleOperator(UnaryTupleOperator node)
320: throws X {
321: meetNode(node);
322: }
323:
324: /**
325: * Method called by all <tt>meet</tt> methods with a
326: * {@link BinaryTupleOperator} node as argument. Forwards the call to
327: * {@link #meetTupleExpr} by default.
328: *
329: * @param node
330: * The node that is being visited.
331: */
332: protected void meetBinaryTupleOperator(BinaryTupleOperator node)
333: throws X {
334: meetNode(node);
335: }
336:
337: /**
338: * Method called by all <tt>meet</tt> methods with a
339: * {@link CompareSubQueryValueOperator} node as argument. Forwards the call
340: * to {@link #meetSubQueryValueOperator} by default.
341: *
342: * @param node
343: * The node that is being visited.
344: */
345: protected void meetCompareSubQueryValueOperator(
346: CompareSubQueryValueOperator node) throws X {
347: meetSubQueryValueOperator(node);
348: }
349:
350: /**
351: * Method called by all <tt>meet</tt> methods with a
352: * {@link SubQueryValueOperator} node as argument. Forwards the call to
353: * {@link #meetValueExpr} by default.
354: *
355: * @param node
356: * The node that is being visited.
357: */
358: protected void meetSubQueryValueOperator(SubQueryValueOperator node)
359: throws X {
360: meetNode(node);
361: }
362:
363: /**
364: * Method called by all <tt>meet</tt> methods with a
365: * {@link UnaryValueOperator} node as argument. Forwards the call to
366: * {@link #meetValueExpr} by default.
367: *
368: * @param node
369: * The node that is being visited.
370: */
371: protected void meetUnaryValueOperator(UnaryValueOperator node)
372: throws X {
373: meetNode(node);
374: }
375:
376: /**
377: * Method called by all <tt>meet</tt> methods with a
378: * {@link BinaryValueOperator} node as argument. Forwards the call to
379: * {@link #meetValueExpr} by default.
380: *
381: * @param node
382: * The node that is being visited.
383: * @throws
384: */
385: protected void meetBinaryValueOperator(BinaryValueOperator node)
386: throws X {
387: meetNode(node);
388: }
389:
390: /**
391: * Method called by all of the other <tt>meet</tt> methods that are not
392: * overridden in subclasses. This method can be overridden in subclasses to
393: * define default behaviour when visiting nodes. The default behaviour of
394: * this method is to visit the node's children.
395: *
396: * @param node
397: * The node that is being visited.
398: */
399: protected void meetNode(QueryModelNode node) throws X {
400: node.visitChildren(this);
401: }
402: }
|