2 package org.z3950.zing.cql;
3 import java.util.ArrayList;
5 import java.util.Properties;
9 * Represents a prefix node in a CQL parse-tree.
12 public class CQLPrefixNode extends CQLNode {
14 private CQLPrefix prefix;
17 * The prefix definition that governs the subtree.
19 public CQLPrefix getPrefix() {
23 private CQLNode subtree;
26 * The root of a parse-tree representing the part of the query
27 * that is governed by this prefix definition.
29 public CQLNode getSubtree() {
34 * Creates a new CQLPrefixNode inducing a mapping from the
35 * specified index-set name to the specified identifier across
36 * the specified subtree.
38 public CQLPrefixNode(String name, String identifier, CQLNode subtree) {
39 this.prefix = new CQLPrefix(name, identifier);
40 this.subtree = subtree;
44 public void traverse(CQLNodeVisitor visitor) {
45 visitor.onPrfixNode(this);
46 subtree.traverse(visitor);
50 void toXCQLInternal(XCQLBuilder b, int level, List<CQLPrefix> prefixes,
51 List<ModifierSet> sortkeys) {
52 List<CQLPrefix> tmp = (prefixes == null ?
53 new ArrayList<CQLPrefix>() :
54 new ArrayList<CQLPrefix>(prefixes));
56 subtree.toXCQLInternal(b, level, tmp, sortkeys);
60 public String toCQL() {
61 // ### We don't always need parens around the subtree
62 if (prefix.name == null) {
63 return ">\"" + prefix.identifier + "\" " +
64 "(" + subtree.toCQL() + ")";
66 return ">" + prefix.name + "=\"" + prefix.identifier + "\" " +
67 "(" + subtree.toCQL() + ")";
72 public String toPQF(Properties config) throws PQFTranslationException {
73 // Prefixes and their identifiers don't actually play any role
74 // in PQF translation, since the meanings of the indexes,
75 // including their prefixes if any, are instead wired into
77 return subtree.toPQF(config);
81 public byte[] toType1BER(Properties config) throws PQFTranslationException {
82 // See comment on toPQF()
83 return subtree.toType1BER(config);