PrefixNode propagates sort keys.
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLPrefixNode.java
index 4e603b7..dd01d85 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: CQLPrefixNode.java,v 1.3 2002-11-20 01:15:15 mike Exp $
+// $Id: CQLPrefixNode.java,v 1.10 2007-07-03 16:40:11 mike Exp $
 
 package org.z3950.zing.cql;
 import java.lang.String;
@@ -9,7 +9,7 @@ import java.util.Vector;
 /**
  * Represents a prefix node in a CQL parse-tree.
  *
- * @version    $Id: CQLPrefixNode.java,v 1.3 2002-11-20 01:15:15 mike Exp $
+ * @version    $Id: CQLPrefixNode.java,v 1.10 2007-07-03 16:40:11 mike Exp $
  */
 public class CQLPrefixNode extends CQLNode {
     /**
@@ -25,7 +25,7 @@ public class CQLPrefixNode extends CQLNode {
 
     /**
      * Creates a new CQLPrefixNode inducing a mapping from the
-     * specified qualifier-set name to the specified identifier across
+     * specified index-set name to the specified identifier across
      * the specified subtree.
      */
     public CQLPrefixNode(String name, String identifier, CQLNode subtree) {
@@ -33,32 +33,36 @@ public class CQLPrefixNode extends CQLNode {
        this.subtree = subtree;
     }
 
-    public String toXCQL(int level, Vector prefixes) {
-//     String maybeName = "";
-//     if (prefix.name != null)
-//         maybeName = indent(level+1) + "<name>" + prefix.name + "</name>\n";
-//
-//     return (indent(level) + "<prefix>\n" + maybeName +
-//             indent(level+1) +
-//                 "<identifier>" + prefix.identifier + "</identifier>\n" +
-//             subtree.toXCQL(level+1, prefixes) +
-//             indent(level) + "</prefix>\n");
-       Vector tmp = new Vector(prefixes);
+    public String toXCQL(int level, Vector<CQLPrefix> prefixes,
+                        Vector<ModifierSet> sortkeys) {
+       Vector<CQLPrefix> tmp = (prefixes == null ?
+                                new Vector<CQLPrefix>() :
+                                new Vector<CQLPrefix>(prefixes));
        tmp.add(prefix);
-       return subtree.toXCQL(level, tmp);
+       return subtree.toXCQL(level, tmp, sortkeys);
     }
 
     public String toCQL() {
-       // ### We don't always need parens around the operand
-       return ">" + prefix.name + "=\"" + prefix.identifier + "\" " +
-           "(" + subtree.toCQL() + ")";
+       // ### We don't always need parens around the subtree
+       if (prefix.name == null) {
+           return ">\"" + prefix.identifier + "\" " +
+               "(" + subtree.toCQL() + ")";
+       } else {
+           return ">" + prefix.name + "=\"" + prefix.identifier + "\" " +
+               "(" + subtree.toCQL() + ")";
+       }
     }
 
     public String toPQF(Properties config) throws PQFTranslationException {
        // Prefixes and their identifiers don't actually play any role
-       // in PQF translation, since the meanings of the qualifiers,
+       // in PQF translation, since the meanings of the indexes,
        // including their prefixes if any, are instead wired into
        // `config'.
        return subtree.toPQF(config);
     }
+
+    public byte[] toType1BER(Properties config) throws PQFTranslationException {
+       // See comment on toPQF()
+       return subtree.toType1BER(config);
+    }
 }