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: /**
09: * An abstract superclass for unary value operators which, by definition, has
10: * one argument.
11: */
12: public abstract class UnaryValueOperator extends QueryModelNodeBase
13: implements ValueExpr {
14:
15: /*-----------*
16: * Variables *
17: *-----------*/
18:
19: /**
20: * The operator's argument.
21: */
22: protected ValueExpr arg;
23:
24: /*--------------*
25: * Constructors *
26: *--------------*/
27:
28: public UnaryValueOperator() {
29: }
30:
31: /**
32: * Creates a new unary value operator.
33: *
34: * @param arg
35: * The operator's argument, must not be <tt>null</tt>.
36: */
37: public UnaryValueOperator(ValueExpr arg) {
38: setArg(arg);
39: }
40:
41: /*---------*
42: * Methods *
43: *---------*/
44:
45: /**
46: * Gets the argument of this unary value operator.
47: *
48: * @return The operator's argument.
49: */
50: public ValueExpr getArg() {
51: return arg;
52: }
53:
54: /**
55: * Sets the argument of this unary value operator.
56: *
57: * @param arg
58: * The (new) argument for this operator, must not be <tt>null</tt>.
59: */
60: public void setArg(ValueExpr arg) {
61: assert arg != null : "arg must not be null";
62: arg.setParentNode(this );
63: this .arg = arg;
64: }
65:
66: @Override
67: public <X extends Exception> void visitChildren(
68: QueryModelVisitor<X> visitor) throws X {
69: arg.visit(visitor);
70: }
71:
72: @Override
73: public void replaceChildNode(QueryModelNode current,
74: QueryModelNode replacement) {
75: if (arg == current) {
76: setArg((ValueExpr) replacement);
77: } else {
78: super .replaceChildNode(current, replacement);
79: }
80: }
81:
82: @Override
83: public UnaryValueOperator clone() {
84: UnaryValueOperator clone = (UnaryValueOperator) super.clone();
85: clone.setArg(getArg().clone());
86: return clone;
87: }
88: }
|