1 // $Id: CQLPrefixNode.java,v 1.10 2007-07-03 16:40:11 mike Exp $
3 package org.z3950.zing.cql;
4 import java.util.ArrayList;
6 import java.util.Properties;
10 * Represents a prefix node in a CQL parse-tree.
12 * @version $Id: CQLPrefixNode.java,v 1.10 2007-07-03 16:40:11 mike Exp $
14 public class CQLPrefixNode extends CQLNode {
16 * The prefix definition that governs the subtree.
18 private CQLPrefix prefix;
20 public CQLPrefix getPrefix() {
25 * The root of a parse-tree representing the part of the query
26 * that is governed by this prefix definition.
28 private CQLNode subtree;
30 public CQLNode getSubtree() {
35 * Creates a new CQLPrefixNode inducing a mapping from the
36 * specified index-set name to the specified identifier across
37 * the specified subtree.
39 public CQLPrefixNode(String name, String identifier, CQLNode subtree) {
40 this.prefix = new CQLPrefix(name, identifier);
41 this.subtree = subtree;
44 public String toXCQL(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 return subtree.toXCQL(level, tmp, sortkeys);
53 public String toCQL() {
54 // ### We don't always need parens around the subtree
55 if (prefix.name == null) {
56 return ">\"" + prefix.identifier + "\" " +
57 "(" + subtree.toCQL() + ")";
59 return ">" + prefix.name + "=\"" + prefix.identifier + "\" " +
60 "(" + subtree.toCQL() + ")";
64 public String toPQF(Properties config) throws PQFTranslationException {
65 // Prefixes and their identifiers don't actually play any role
66 // in PQF translation, since the meanings of the indexes,
67 // including their prefixes if any, are instead wired into
69 return subtree.toPQF(config);
72 public byte[] toType1BER(Properties config) throws PQFTranslationException {
73 // See comment on toPQF()
74 return subtree.toType1BER(config);