- Change the XCQL output to include the nasty and redundant
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLPrefixNode.java
1 // $Id: CQLPrefixNode.java,v 1.3 2002-11-20 01:15:15 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.3 2002-11-20 01:15:15 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 qualifier-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 prefixes) {
37 //      String maybeName = "";
38 //      if (prefix.name != null)
39 //          maybeName = indent(level+1) + "<name>" + prefix.name + "</name>\n";
40 //
41 //      return (indent(level) + "<prefix>\n" + maybeName +
42 //              indent(level+1) +
43 //                  "<identifier>" + prefix.identifier + "</identifier>\n" +
44 //              subtree.toXCQL(level+1, prefixes) +
45 //              indent(level) + "</prefix>\n");
46         Vector tmp = new Vector(prefixes);
47         tmp.add(prefix);
48         return subtree.toXCQL(level, tmp);
49     }
50
51     public String toCQL() {
52         // ### We don't always need parens around the operand
53         return ">" + prefix.name + "=\"" + prefix.identifier + "\" " +
54             "(" + subtree.toCQL() + ")";
55     }
56
57     public String toPQF(Properties config) throws PQFTranslationException {
58         // Prefixes and their identifiers don't actually play any role
59         // in PQF translation, since the meanings of the qualifiers,
60         // including their prefixes if any, are instead wired into
61         // `config'.
62         return subtree.toPQF(config);
63     }
64 }