01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.query.algebra;
07:
08: import java.util.Set;
09:
10: /**
11: * An abstract superclass for unary tuple operators which, by definition, has
12: * one argument.
13: */
14: public abstract class UnaryTupleOperator extends QueryModelNodeBase
15: implements TupleExpr {
16:
17: /*-----------*
18: * Variables *
19: *-----------*/
20:
21: /**
22: * The operator's argument.
23: */
24: protected TupleExpr arg;
25:
26: /*--------------*
27: * Constructors *
28: *--------------*/
29:
30: public UnaryTupleOperator() {
31: }
32:
33: /**
34: * Creates a new unary tuple operator.
35: *
36: * @param arg
37: * The operator's argument, must not be <tt>null</tt>.
38: */
39: public UnaryTupleOperator(TupleExpr arg) {
40: setArg(arg);
41: }
42:
43: /*---------*
44: * Methods *
45: *---------*/
46:
47: /**
48: * Gets the argument of this unary tuple operator.
49: *
50: * @return The operator's argument.
51: */
52: public TupleExpr getArg() {
53: return arg;
54: }
55:
56: /**
57: * Sets the argument of this unary tuple operator.
58: *
59: * @param arg
60: * The (new) argument for this operator, must not be <tt>null</tt>.
61: */
62: public void setArg(TupleExpr arg) {
63: assert arg != null : "arg must not be null";
64: arg.setParentNode(this );
65: this .arg = arg;
66: }
67:
68: public Set<String> getBindingNames() {
69: return getArg().getBindingNames();
70: }
71:
72: @Override
73: public <X extends Exception> void visitChildren(
74: QueryModelVisitor<X> visitor) throws X {
75: arg.visit(visitor);
76: }
77:
78: @Override
79: public void replaceChildNode(QueryModelNode current,
80: QueryModelNode replacement) {
81: if (arg == current) {
82: setArg((TupleExpr) replacement);
83: } else {
84: super .replaceChildNode(current, replacement);
85: }
86: }
87:
88: @Override
89: public UnaryTupleOperator clone() {
90: UnaryTupleOperator clone = (UnaryTupleOperator) super.clone();
91: clone.setArg(getArg().clone());
92: return clone;
93: }
94: }
|