dd01d8560cde514829def49567c5bc9c7abfc5d1
[cql-java-moved-to-github.git] / src / main / java / org / z3950 / zing / cql / CQLPrefixNode.java
1 // $Id: CQLPrefixNode.java,v 1.10 2007-07-03 16:40:11 mike Exp $
2
3 package org.z3950.zing.cql;
4 import java.lang.String;
5 import java.util.Properties;
6 import java.util.Vector;
7
8
9 /**
10  * Represents a prefix node in a CQL parse-tree.
11  *
12  * @version     $Id: CQLPrefixNode.java,v 1.10 2007-07-03 16:40:11 mike Exp $
13  */
14 public class CQLPrefixNode extends CQLNode {
15     /**
16      * The prefix definition that governs the subtree.
17      */
18     public CQLPrefix prefix;
19
20     /**
21      * The root of a parse-tree representing the part of the query
22      * that is governed by this prefix definition.
23      */ 
24     public CQLNode subtree;
25
26     /**
27      * Creates a new CQLPrefixNode inducing a mapping from the
28      * specified index-set name to the specified identifier across
29      * the specified subtree.
30      */
31     public CQLPrefixNode(String name, String identifier, CQLNode subtree) {
32         this.prefix = new CQLPrefix(name, identifier);
33         this.subtree = subtree;
34     }
35
36     public String toXCQL(int level, Vector<CQLPrefix> prefixes,
37                          Vector<ModifierSet> sortkeys) {
38         Vector<CQLPrefix> tmp = (prefixes == null ?
39                                  new Vector<CQLPrefix>() :
40                                  new Vector<CQLPrefix>(prefixes));
41         tmp.add(prefix);
42         return subtree.toXCQL(level, tmp, sortkeys);
43     }
44
45     public String toCQL() {
46         // ### We don't always need parens around the subtree
47         if (prefix.name == null) {
48             return ">\"" + prefix.identifier + "\" " +
49                 "(" + subtree.toCQL() + ")";
50         } else {
51             return ">" + prefix.name + "=\"" + prefix.identifier + "\" " +
52                 "(" + subtree.toCQL() + ")";
53         }
54     }
55
56     public String toPQF(Properties config) throws PQFTranslationException {
57         // Prefixes and their identifiers don't actually play any role
58         // in PQF translation, since the meanings of the indexes,
59         // including their prefixes if any, are instead wired into
60         // `config'.
61         return subtree.toPQF(config);
62     }
63
64     public byte[] toType1BER(Properties config) throws PQFTranslationException {
65         // See comment on toPQF()
66         return subtree.toType1BER(config);
67     }
68 }