Remove CVS expansions
[cql-java-moved-to-github.git] / src / main / java / org / z3950 / zing / cql / CQLBooleanNode.java
1
2 package org.z3950.zing.cql;
3 import java.util.List;
4 import java.util.Properties;
5
6 /**
7  * Represents a boolean node in a CQL parse-tree.
8  *
9  */
10 public abstract class CQLBooleanNode extends CQLNode {
11
12     private CQLNode left;
13
14     /**
15      * The root of a parse-tree representing the left-hand side.
16      */
17     public CQLNode getLeftOperand() {
18         return left;
19     }
20
21     private CQLNode right;
22
23     /**
24      * The root of a parse-tree representing the right-hand side.
25      */
26     public CQLNode getRightOperand() {
27         return right;
28     }
29
30     ModifierSet ms;
31
32     /**
33      * The set of modifiers that are applied to this boolean.
34      */
35     public List<Modifier> getModifiers() {
36         return ms.getModifiers();
37     }
38
39     protected CQLBooleanNode(CQLNode left, CQLNode right, ModifierSet ms) {
40         this.left = left;
41         this.right = right;
42         this.ms = ms;
43     }
44
45     @Override
46     void toXCQLInternal(XCQLBuilder b, int level,
47         List<CQLPrefix> prefixes, List<ModifierSet> sortkeys) {
48         b.indent(level).append("<triple>\n");
49         renderPrefixes(b, level + 1, prefixes);
50         ms.toXCQLInternal(b, level + 1, "boolean", "value");
51         b.indent(level + 1).append("<leftOperand>\n");
52         left.toXCQLInternal(b, level + 2);
53         b.indent(level + 1).append("</leftOperand>\n");
54         b.indent(level + 1).append("<rightOperand>\n");
55         right.toXCQLInternal(b, level + 2);
56         b.indent(level + 1).append("</rightOperand>\n");
57         renderSortKeys(b, level + 1, sortkeys);
58         b.indent(level).append("</triple>\n");
59     }
60
61     @Override
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     @Override
70     public String toPQF(Properties config) throws PQFTranslationException {
71         return ("@" + opPQF() +
72                 " " + left.toPQF(config) +
73                 " " + right.toPQF(config));
74     }
75
76     // represents the operation for PQF: overridden for CQLProxNode
77     String opPQF() { return ms.getBase(); }
78
79     @Override
80     public byte[] toType1BER(Properties config) throws PQFTranslationException {
81         System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
82                            toPQF(config));
83         byte[] rpn1 = left.toType1BER(config);
84         byte[] rpn2 = right.toType1BER(config);
85         byte[] op = opType1();
86         byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
87         
88         // rpnRpnOp
89         int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
90
91         rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
92         System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
93         offset += rpn1.length;
94         System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
95         offset += rpn2.length;
96         System.arraycopy(op, 0, rpnStructure, offset, op.length);
97         offset += op.length;
98         rpnStructure[offset++] = 0x00; // end rpnRpnOp
99         rpnStructure[offset++] = 0x00;
100         return rpnStructure;
101     }
102
103     abstract byte[] opType1();
104 }