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.helpers;
07:
08: import java.util.ArrayList;
09: import java.util.List;
10:
11: import org.openrdf.query.algebra.Filter;
12: import org.openrdf.query.algebra.QueryModelNode;
13: import org.openrdf.query.algebra.StatementPattern;
14: import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
15:
16: /**
17: * A QueryModelVisitor that collects StatementPattern's from a query model.
18: * StatementPatterns thet are part of filters/constraints are not included in
19: * the result.
20: */
21: public class StatementPatternCollector extends
22: QueryModelVisitorBase<RuntimeException> {
23:
24: public static List<StatementPattern> process(QueryModelNode node) {
25: StatementPatternCollector collector = new StatementPatternCollector();
26: node.visit(collector);
27: return collector.getStatementPatterns();
28: }
29:
30: private List<StatementPattern> stPatterns = new ArrayList<StatementPattern>();
31:
32: public List<StatementPattern> getStatementPatterns() {
33: return stPatterns;
34: }
35:
36: @Override
37: public void meet(Filter node) {
38: // Skip boolean constraints
39: node.getArg().visit(this );
40: }
41:
42: @Override
43: public void meet(StatementPattern node) {
44: stPatterns.add(node);
45: }
46: }
|