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;
007:
008: import java.util.LinkedHashSet;
009: import java.util.Set;
010:
011: /**
012: * The LeftJoin operator, as defined in <a
013: * href="http://www.w3.org/TR/rdf-sparql-query/#algLeftJoin">SPARQL Query
014: * Language for RDF</a>.
015: *
016: * @author Arjohn Kampman
017: */
018: public class LeftJoin extends BinaryTupleOperator {
019:
020: /*-----------*
021: * Variables *
022: *-----------*/
023:
024: private ValueExpr condition;
025:
026: /*--------------*
027: * Constructors *
028: *--------------*/
029:
030: public LeftJoin() {
031: }
032:
033: public LeftJoin(TupleExpr leftArg, TupleExpr rightArg) {
034: super (leftArg, rightArg);
035: }
036:
037: public LeftJoin(TupleExpr leftArg, TupleExpr rightArg,
038: ValueExpr condition) {
039: this (leftArg, rightArg);
040: setCondition(condition);
041: }
042:
043: /*---------*
044: * Methods *
045: *---------*/
046:
047: public ValueExpr getCondition() {
048: return condition;
049: }
050:
051: public void setCondition(ValueExpr condition) {
052: if (condition != null) {
053: condition.setParentNode(this );
054: }
055: this .condition = condition;
056: }
057:
058: public boolean hasCondition() {
059: return condition != null;
060: }
061:
062: public Set<String> getBindingNames() {
063: Set<String> bindingNames = new LinkedHashSet<String>(16);
064: bindingNames.addAll(getLeftArg().getBindingNames());
065: bindingNames.addAll(getRightArg().getBindingNames());
066: return bindingNames;
067: }
068:
069: public <X extends Exception> void visit(QueryModelVisitor<X> visitor)
070: throws X {
071: visitor.meet(this );
072: }
073:
074: @Override
075: public <X extends Exception> void visitChildren(
076: QueryModelVisitor<X> visitor) throws X {
077: if (condition != null) {
078: condition.visit(visitor);
079: }
080:
081: super .visitChildren(visitor);
082: }
083:
084: @Override
085: public void replaceChildNode(QueryModelNode current,
086: QueryModelNode replacement) {
087: if (condition == current) {
088: setCondition((ValueExpr) replacement);
089: } else {
090: super .replaceChildNode(current, replacement);
091: }
092: }
093:
094: @Override
095: public LeftJoin clone() {
096: LeftJoin clone = (LeftJoin) super.clone();
097: if (hasCondition()) {
098: clone.setCondition(getCondition().clone());
099: }
100: return clone;
101: }
102: }
|