Rename the toType1() method to the more explicit toType1BER()
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLBooleanNode.java
index a3c3749..7064784 100644 (file)
@@ -1,12 +1,14 @@
-// $Id: CQLBooleanNode.java,v 1.7 2002-11-06 00:05:58 mike Exp $
+// $Id: CQLBooleanNode.java,v 1.13 2002-12-11 17:14:20 mike Exp $
 
 package org.z3950.zing.cql;
+import java.util.Properties;
+import java.util.Vector;
 
 
 /**
  * Represents a boolean node in a CQL parse-tree.
  *
- * @version    $Id: CQLBooleanNode.java,v 1.7 2002-11-06 00:05:58 mike Exp $
+ * @version    $Id: CQLBooleanNode.java,v 1.13 2002-12-11 17:14:20 mike Exp $
  */
 public abstract class CQLBooleanNode extends CQLNode {
     CQLBooleanNode() {}                // prevent javadoc from documenting this
@@ -21,18 +23,21 @@ public abstract class CQLBooleanNode extends CQLNode {
      */ 
     public CQLNode right;
 
-    abstract String op();
-
-    public String toXCQL(int level) {
+    public String toXCQL(int level, Vector prefixes) {
        return (indent(level) + "<triple>\n" +
-               booleanXQL(level+1) +
-               left.toXCQL(level+1) +
-               right.toXCQL(level+1) +
+               renderPrefixes(level+1, prefixes) +
+               opXCQL(level+1) +
+               indent(level+1) + "<leftOperand>\n" +
+               left.toXCQL(level+2, new Vector()) +
+               indent(level+1) + "</leftOperand>\n" +
+               indent(level+1) + "<rightOperand>\n" +
+               right.toXCQL(level+2, new Vector()) +
+               indent(level+1) + "</rightOperand>\n" +
                indent(level) + "</triple>\n");
     }
 
     // Represents the boolean operation itself: overridden for CQLProxNode
-    String booleanXQL(int level) {
+    String opXCQL(int level) {
        return(indent(level) + "<boolean>\n" +
               indent(level+1) + "<value>" + op() + "</value>\n" +
               indent(level) + "</boolean>\n");
@@ -42,4 +47,40 @@ public abstract class CQLBooleanNode extends CQLNode {
        // ### We don't always need parens around the operands
        return "(" + left.toCQL() + ") " + op() + " (" + right.toCQL() + ")";
     }
+
+    public String toPQF(Properties config) throws PQFTranslationException {
+       return ("@" + opPQF() +
+               " " + left.toPQF(config) +
+               " " + right.toPQF(config));
+    }
+
+    // represents the operation for PQF: overridden for CQLProxNode
+    String opPQF() { return op(); }
+
+    abstract String op();
+
+    public byte[] toType1BER(Properties config) throws PQFTranslationException {
+        System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
+                          toPQF(config));
+        byte[] rpn1 = left.toType1BER(config);
+        byte[] rpn2 = right.toType1BER(config);
+        byte[] op = opType1();
+        byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
+        
+       // rpnRpnOp
+        int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
+
+        rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
+        System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
+        offset += rpn1.length;
+        System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
+        offset += rpn2.length;
+        System.arraycopy(op, 0, rpnStructure, offset, op.length);
+        offset += op.length;
+        rpnStructure[offset++] = 0x00; // end rpnRpnOp
+        rpnStructure[offset++] = 0x00;
+        return rpnStructure;
+    }
+
+    abstract byte[] opType1();
 }