super(left, right, ms);
}
+ @Override
+ public void traverse(CQLNodeVisitor visitor) {
+ visitor.onAndNode(this);
+ super.traverse(visitor);
+ }
+
+
// ### Too much code duplication here with OR and NOT
@Override
byte[] opType1() {
}
@Override
+ public void traverse(CQLNodeVisitor visitor) {
+ visitor.onBooleanNode(this);
+ left.traverse(visitor);
+ right.traverse(visitor);
+ }
+
+
+ @Override
void toXCQLInternal(XCQLBuilder b, int level,
List<CQLPrefix> prefixes, List<ModifierSet> sortkeys) {
b.indent(level).append("<triple>\n");
--- /dev/null
+/*
+ * Copyright (c) 1995-2014, Index Data
+ * All rights reserved.
+ * See the file LICENSE for details.
+ */
+
+package org.z3950.zing.cql;
+
+/**
+ * Query tree visitor with default (no-op) implementation
+ * @author jakub
+ */
+public class CQLDefaultNodeVisitor implements CQLNodeVisitor {
+
+ @Override
+ public void onSortNode(CQLSortNode node) {
+ }
+
+ @Override
+ public void onPrfixNode(CQLPrefixNode node) {
+ }
+
+ @Override
+ public void onBooleanNode(CQLBooleanNode node) {
+ }
+
+ @Override
+ public void onProxNode(CQLProxNode node) {
+ }
+
+ @Override
+ public void onAndNode(CQLAndNode node) {
+ }
+
+ @Override
+ public void onOrNode(CQLOrNode node) {
+ }
+
+ @Override
+ public void onNotNode(CQLNotNode node) {
+ }
+
+ @Override
+ public void onTermNode(CQLTermNode node) {
+ }
+
+ @Override
+ public void onRelation(CQLRelation relation) {
+ }
+
+}
*
*/
public abstract class CQLNode {
+
+ public abstract void traverse(CQLNodeVisitor visitor);
/**
* Returns the name of the result-set to which this query is a
--- /dev/null
+/*
+ * Copyright (c) 1995-2014, Index Data
+ * All rights reserved.
+ * See the file LICENSE for details.
+ */
+
+package org.z3950.zing.cql;
+
+/**
+ * Allows to visit different types of nodes in the query tree.
+ * @author jakub
+ */
+public interface CQLNodeVisitor {
+
+ public void onSortNode(CQLSortNode node);
+
+ public void onPrfixNode(CQLPrefixNode node);
+
+ public void onBooleanNode(CQLBooleanNode node);
+
+ public void onProxNode(CQLProxNode node);
+
+ public void onAndNode(CQLAndNode node);
+
+ public void onOrNode(CQLOrNode node);
+
+ public void onNotNode(CQLNotNode node);
+
+ public void onTermNode(CQLTermNode node);
+
+ public void onRelation(CQLRelation relation);
+
+}
}
@Override
+ public void traverse(CQLNodeVisitor visitor) {
+ visitor.onNotNode(this);
+ super.traverse(visitor);
+ }
+
+ @Override
byte[] opType1() {
byte[] op = new byte[5];
putTag(CONTEXT, 46, CONSTRUCTED, op, 0); // Operator
}
@Override
+ public void traverse(CQLNodeVisitor visitor) {
+ visitor.onOrNode(this);
+ super.traverse(visitor);
+ }
+
+ @Override
byte[] opType1() {
byte[] op = new byte[5];
putTag(CONTEXT, 46, CONSTRUCTED, op, 0); // Operator
}
@Override
+ public void traverse(CQLNodeVisitor visitor) {
+ visitor.onPrfixNode(this);
+ subtree.traverse(visitor);
+ }
+
+ @Override
void toXCQLInternal(XCQLBuilder b, int level, List<CQLPrefix> prefixes,
List<ModifierSet> sortkeys) {
List<CQLPrefix> tmp = (prefixes == null ?
super(left, right, ms);
}
+ @Override
+ public void traverse(CQLNodeVisitor visitor) {
+ visitor.onProxNode(this);
+ }
+
/*
* proximity ::= exclusion distance ordered relation which-code unit-code.
* exclusion ::= '1' | '0' | 'void'.
}
@Override
+ public void traverse(CQLNodeVisitor visitor) {
+ visitor.onRelation(this);
+ }
+
+ @Override
void toXCQLInternal(XCQLBuilder b, int level, List<CQLPrefix> prefixes,
List<ModifierSet> sortkeys) {
if (sortkeys != null)
}
@Override
+ public void traverse(CQLNodeVisitor visitor) {
+ visitor.onSortNode(this);
+ subtree.traverse(visitor);
+ }
+
+ @Override
void toXCQLInternal(XCQLBuilder b, int level, List<CQLPrefix> prefixes,
List<ModifierSet> sortkeys) {
if (sortkeys != null)
}
@Override
+ public void traverse(CQLNodeVisitor visitor) {
+ //we visit relation first to allow filtering on relation type in the visitor
+ relation.traverse(visitor);
+ visitor.onTermNode(this);
+ }
+
+ @Override
public String getResultSetName() {
if (isResultSetIndex(index))
return term;