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.parser.serql.ast;
07:
08: import java.util.List;
09:
10: import info.aduna.collections.CastingList;
11:
12: public class ASTOptPathExpr extends ASTPathExpr {
13:
14: public ASTOptPathExpr(int id) {
15: super (id);
16: }
17:
18: public ASTOptPathExpr(SyntaxTreeBuilder p, int id) {
19: super (p, id);
20: }
21:
22: @Override
23: public Object jjtAccept(SyntaxTreeBuilderVisitor visitor,
24: Object data) throws VisitorException {
25: return visitor.visit(this , data);
26: }
27:
28: public List<ASTPathExpr> getPathExprList() {
29: if (this .hasConstraint()) {
30: // exlude the last child, which is a boolean constraint
31: return new CastingList<ASTPathExpr>(children.subList(0,
32: children.size() - 1));
33: } else {
34: return new CastingList<ASTPathExpr>(children);
35: }
36: }
37:
38: /**
39: * Checks if this optional path expression has a constraint.
40: */
41: public boolean hasConstraint() {
42: return getWhereClause() != null;
43: }
44:
45: /**
46: * Returns the where clause on the optional path expression, if present.
47: *
48: * @return The where clause, or <tt>null</tt> if no where clause was
49: * specified.
50: */
51: public ASTWhere getWhereClause() {
52: Node lastChildNode = children.get(children.size() - 1);
53:
54: if (lastChildNode instanceof ASTWhere) {
55: return (ASTWhere) lastChildNode;
56: }
57:
58: return null;
59: }
60: }
|