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