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 void toXCQLInternal(XCQLBuilder b, int level, List<CQLPrefix> prefixes,
45 List<ModifierSet> sortkeys) {
46 List<CQLPrefix> tmp = (prefixes == null ?
47 new ArrayList<CQLPrefix>() :
48 new ArrayList<CQLPrefix>(prefixes));
50 subtree.toXCQLInternal(b, level, tmp, sortkeys);
54 public String toCQL() {
55 // ### We don't always need parens around the subtree
56 if (prefix.name == null) {
57 return ">\"" + prefix.identifier + "\" " +
58 "(" + subtree.toCQL() + ")";
60 return ">" + prefix.name + "=\"" + prefix.identifier + "\" " +
61 "(" + subtree.toCQL() + ")";
66 public String toPQF(Properties config) throws PQFTranslationException {
67 // Prefixes and their identifiers don't actually play any role
68 // in PQF translation, since the meanings of the indexes,
69 // including their prefixes if any, are instead wired into
71 return subtree.toPQF(config);
75 public byte[] toType1BER(Properties config) throws PQFTranslationException {
76 // See comment on toPQF()
77 return subtree.toType1BER(config);