2 package org.z3950.zing.cql;
4 import java.util.Properties;
7 * Represents a boolean node in a CQL parse-tree.
10 public abstract class CQLBooleanNode extends CQLNode {
15 * The root of a parse-tree representing the left-hand side.
17 public CQLNode getLeftOperand() {
21 private CQLNode right;
24 * The root of a parse-tree representing the right-hand side.
26 public CQLNode getRightOperand() {
33 * The set of modifiers that are applied to this boolean.
35 public List<Modifier> getModifiers() {
36 return ms.getModifiers();
39 protected CQLBooleanNode(CQLNode left, CQLNode right, ModifierSet ms) {
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");
62 public String toCQL() {
63 // ### We don't always need parens around the operands
64 return ("(" + left.toCQL() + ")" +
65 " " + ms.toCQL() + " " +
66 "(" + right.toCQL() + ")");
70 public String toPQF(Properties config) throws PQFTranslationException {
71 return ("@" + opPQF() +
72 " " + left.toPQF(config) +
73 " " + right.toPQF(config));
76 // represents the operation for PQF: overridden for CQLProxNode
77 String opPQF() { return ms.getBase(); }
80 public byte[] toType1BER(Properties config) throws PQFTranslationException {
81 System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
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];
89 int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
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);
98 rpnStructure[offset++] = 0x00; // end rpnRpnOp
99 rpnStructure[offset++] = 0x00;
103 abstract byte[] opType1();