Rename the toType1() method to the more explicit toType1BER()
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLBooleanNode.java
1 // $Id: CQLBooleanNode.java,v 1.13 2002-12-11 17:14:20 mike Exp $
2
3 package org.z3950.zing.cql;
4 import java.util.Properties;
5 import java.util.Vector;
6
7
8 /**
9  * Represents a boolean node in a CQL parse-tree.
10  *
11  * @version     $Id: CQLBooleanNode.java,v 1.13 2002-12-11 17:14:20 mike Exp $
12  */
13 public abstract class CQLBooleanNode extends CQLNode {
14     CQLBooleanNode() {}         // prevent javadoc from documenting this
15
16     /**
17      * The root of a parse-tree representing the left-hand side.
18      */ 
19     public CQLNode left;
20
21     /**
22      * The root of a parse-tree representing the right-hand side.
23      */ 
24     public CQLNode right;
25
26     public String toXCQL(int level, Vector prefixes) {
27         return (indent(level) + "<triple>\n" +
28                 renderPrefixes(level+1, prefixes) +
29                 opXCQL(level+1) +
30                 indent(level+1) + "<leftOperand>\n" +
31                 left.toXCQL(level+2, new Vector()) +
32                 indent(level+1) + "</leftOperand>\n" +
33                 indent(level+1) + "<rightOperand>\n" +
34                 right.toXCQL(level+2, new Vector()) +
35                 indent(level+1) + "</rightOperand>\n" +
36                 indent(level) + "</triple>\n");
37     }
38
39     // Represents the boolean operation itself: overridden for CQLProxNode
40     String opXCQL(int level) {
41         return(indent(level) + "<boolean>\n" +
42                indent(level+1) + "<value>" + op() + "</value>\n" +
43                indent(level) + "</boolean>\n");
44     }
45
46     public String toCQL() {
47         // ### We don't always need parens around the operands
48         return "(" + left.toCQL() + ") " + op() + " (" + right.toCQL() + ")";
49     }
50
51     public String toPQF(Properties config) throws PQFTranslationException {
52         return ("@" + opPQF() +
53                 " " + left.toPQF(config) +
54                 " " + right.toPQF(config));
55     }
56
57     // represents the operation for PQF: overridden for CQLProxNode
58     String opPQF() { return op(); }
59
60     abstract String op();
61
62     public byte[] toType1BER(Properties config) throws PQFTranslationException {
63         System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
64                            toPQF(config));
65         byte[] rpn1 = left.toType1BER(config);
66         byte[] rpn2 = right.toType1BER(config);
67         byte[] op = opType1();
68         byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
69         
70         // rpnRpnOp
71         int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
72
73         rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
74         System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
75         offset += rpn1.length;
76         System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
77         offset += rpn2.length;
78         System.arraycopy(op, 0, rpnStructure, offset, op.length);
79         offset += op.length;
80         rpnStructure[offset++] = 0x00; // end rpnRpnOp
81         rpnStructure[offset++] = 0x00;
82         return rpnStructure;
83     }
84
85     abstract byte[] opType1();
86 }