Add override annotations
[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.util.ArrayList;
5 import java.util.List;
6 import java.util.Properties;
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     private CQLPrefix prefix;
19
20     public CQLPrefix getPrefix() {
21         return prefix;
22     }
23
24     /**
25      * The root of a parse-tree representing the part of the query
26      * that is governed by this prefix definition.
27      */ 
28     private CQLNode subtree;
29
30     public CQLNode getSubtree() {
31       return subtree;
32     }
33
34     /**
35      * Creates a new CQLPrefixNode inducing a mapping from the
36      * specified index-set name to the specified identifier across
37      * the specified subtree.
38      */
39     public CQLPrefixNode(String name, String identifier, CQLNode subtree) {
40         this.prefix = new CQLPrefix(name, identifier);
41         this.subtree = subtree;
42     }
43
44     @Override
45     public String toXCQL(int level, List<CQLPrefix> prefixes,
46                          List<ModifierSet> sortkeys) {
47         List<CQLPrefix> tmp = (prefixes == null ?
48                                  new ArrayList<CQLPrefix>() :
49                                  new ArrayList<CQLPrefix>(prefixes));
50         tmp.add(prefix);
51         return subtree.toXCQL(level, tmp, sortkeys);
52     }
53
54     @Override
55     public String toCQL() {
56         // ### We don't always need parens around the subtree
57         if (prefix.name == null) {
58             return ">\"" + prefix.identifier + "\" " +
59                 "(" + subtree.toCQL() + ")";
60         } else {
61             return ">" + prefix.name + "=\"" + prefix.identifier + "\" " +
62                 "(" + subtree.toCQL() + ")";
63         }
64     }
65
66     @Override
67     public String toPQF(Properties config) throws PQFTranslationException {
68         // Prefixes and their identifiers don't actually play any role
69         // in PQF translation, since the meanings of the indexes,
70         // including their prefixes if any, are instead wired into
71         // `config'.
72         return subtree.toPQF(config);
73     }
74
75     @Override
76     public byte[] toType1BER(Properties config) throws PQFTranslationException {
77         // See comment on toPQF()
78         return subtree.toType1BER(config);
79     }
80 }