Hide some memebers as private, add getters
[cql-java-moved-to-github.git] / src / main / java / org / z3950 / zing / cql / CQLBooleanNode.java
1 // $Id: CQLBooleanNode.java,v 1.18 2007-07-03 16:03:00 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.18 2007-07-03 16:03:00 mike Exp $
12  */
13 public abstract class CQLBooleanNode extends CQLNode {
14
15     private CQLNode left;
16
17     /**
18      * The root of a parse-tree representing the left-hand side.
19      */
20     public CQLNode getLeft() {
21         return left;
22     }
23
24     private CQLNode right;
25
26     /**
27      * The root of a parse-tree representing the right-hand side.
28      */
29     public CQLNode getRight() {
30         return right;
31     }
32
33     ModifierSet ms;
34     /**
35      * The set of modifiers that are applied to this boolean.
36      */
37     public Vector<Modifier> getModifiers() {
38         return ms.getModifiers();
39     }
40
41     protected CQLBooleanNode(CQLNode left, CQLNode right, ModifierSet ms) {
42         this.left = left;
43         this.right = right;
44         this.ms = ms;
45     }
46
47     public String toXCQL(int level, Vector<CQLPrefix> prefixes,
48                          Vector<ModifierSet> sortkeys) {
49         return (indent(level) + "<triple>\n" +
50                 renderPrefixes(level+1, prefixes) +
51                 ms.toXCQL(level+1, "boolean") +
52                 indent(level+1) + "<leftOperand>\n" +
53                 left.toXCQL(level+2) +
54                 indent(level+1) + "</leftOperand>\n" +
55                 indent(level+1) + "<rightOperand>\n" +
56                 right.toXCQL(level+2) +
57                 indent(level+1) + "</rightOperand>\n" +
58                 renderSortKeys(level+1, sortkeys) +
59                 indent(level) + "</triple>\n");
60     }
61
62     public String toCQL() {
63         // ### We don't always need parens around the operands
64         return ("(" + left.toCQL() + ")" +
65                 " " + ms.toCQL() + " " +
66                 "(" + right.toCQL() + ")");
67     }
68
69     public String toPQF(Properties config) throws PQFTranslationException {
70         return ("@" + opPQF() +
71                 " " + left.toPQF(config) +
72                 " " + right.toPQF(config));
73     }
74
75     // represents the operation for PQF: overridden for CQLProxNode
76     String opPQF() { return ms.getBase(); }
77
78     public byte[] toType1BER(Properties config) throws PQFTranslationException {
79         System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
80                            toPQF(config));
81         byte[] rpn1 = left.toType1BER(config);
82         byte[] rpn2 = right.toType1BER(config);
83         byte[] op = opType1();
84         byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
85         
86         // rpnRpnOp
87         int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
88
89         rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
90         System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
91         offset += rpn1.length;
92         System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
93         offset += rpn2.length;
94         System.arraycopy(op, 0, rpnStructure, offset, op.length);
95         offset += op.length;
96         rpnStructure[offset++] = 0x00; // end rpnRpnOp
97         rpnStructure[offset++] = 0x00;
98         return rpnStructure;
99     }
100
101     abstract byte[] opType1();
102 }