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.helpers;
07:
08: import java.util.LinkedHashSet;
09: import java.util.Set;
10:
11: import org.openrdf.query.algebra.QueryModelNode;
12: import org.openrdf.query.algebra.Var;
13:
14: /**
15: * A QueryModelVisitor that collects the names of (unbound) variables that are
16: * used in a query model.
17: */
18: public class VarNameCollector extends
19: QueryModelVisitorBase<RuntimeException> {
20:
21: public static Set<String> process(QueryModelNode node) {
22: VarNameCollector collector = new VarNameCollector();
23: node.visit(collector);
24: return collector.getVarNames();
25: }
26:
27: private Set<String> varNames = new LinkedHashSet<String>();
28:
29: public Set<String> getVarNames() {
30: return varNames;
31: }
32:
33: @Override
34: public void meet(Var var) {
35: if (!var.hasValue()) {
36: varNames.add(var.getName());
37: }
38: }
39: }
|