01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.query.algebra;
07:
08: /**
09: * @author Arjohn Kampman
10: */
11: public class OrderElem extends QueryModelNodeBase {
12:
13: /*-----------*
14: * Variables *
15: *-----------*/
16:
17: private ValueExpr expr;
18:
19: private boolean ascending = true;
20:
21: /*--------------*
22: * Constructors *
23: *--------------*/
24:
25: public OrderElem() {
26: }
27:
28: public OrderElem(ValueExpr expr) {
29: this (expr, true);
30: }
31:
32: public OrderElem(ValueExpr expr, boolean ascending) {
33: setExpr(expr);
34: setAscending(ascending);
35: }
36:
37: /*---------*
38: * Methods *
39: *---------*/
40:
41: public ValueExpr getExpr() {
42: return expr;
43: }
44:
45: public void setExpr(ValueExpr expr) {
46: assert expr != null : "expr must not be null";
47: expr.setParentNode(this );
48: this .expr = expr;
49: }
50:
51: public boolean isAscending() {
52: return ascending;
53: }
54:
55: public void setAscending(boolean ascending) {
56: this .ascending = ascending;
57: }
58:
59: public <X extends Exception> void visit(QueryModelVisitor<X> visitor)
60: throws X {
61: visitor.meet(this );
62: }
63:
64: @Override
65: public <X extends Exception> void visitChildren(
66: QueryModelVisitor<X> visitor) throws X {
67: expr.visit(visitor);
68: }
69:
70: @Override
71: public void replaceChildNode(QueryModelNode current,
72: QueryModelNode replacement) {
73: if (expr == current) {
74: setExpr((ValueExpr) replacement);
75: } else {
76: super .replaceChildNode(current, replacement);
77: }
78: }
79:
80: @Override
81: public String getSignature() {
82: return super .getSignature() + " ("
83: + (ascending ? "ASC" : "DESC") + ")";
84: }
85:
86: @Override
87: public OrderElem clone() {
88: OrderElem clone = (OrderElem) super.clone();
89: clone.setExpr(getExpr().clone());
90: return clone;
91: }
92: }
|