1 // $Id: CQLBooleanNode.java,v 1.18 2007-07-03 16:03:00 mike Exp $
3 package org.z3950.zing.cql;
4 import java.util.Properties;
5 import java.util.Vector;
9 * Represents a boolean node in a CQL parse-tree.
11 * @version $Id: CQLBooleanNode.java,v 1.18 2007-07-03 16:03:00 mike Exp $
13 public abstract class CQLBooleanNode extends CQLNode {
18 * The root of a parse-tree representing the left-hand side.
20 public CQLNode getLeft() {
24 private CQLNode right;
27 * The root of a parse-tree representing the right-hand side.
29 public CQLNode getRight() {
35 * The set of modifiers that are applied to this boolean.
37 public Vector<Modifier> getModifiers() {
38 return ms.getModifiers();
41 protected CQLBooleanNode(CQLNode left, CQLNode right, ModifierSet ms) {
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");
62 public String toCQL() {
63 // ### We don't always need parens around the operands
64 return ("(" + left.toCQL() + ")" +
65 " " + ms.toCQL() + " " +
66 "(" + right.toCQL() + ")");
69 public String toPQF(Properties config) throws PQFTranslationException {
70 return ("@" + opPQF() +
71 " " + left.toPQF(config) +
72 " " + right.toPQF(config));
75 // represents the operation for PQF: overridden for CQLProxNode
76 String opPQF() { return ms.getBase(); }
78 public byte[] toType1BER(Properties config) throws PQFTranslationException {
79 System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
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];
87 int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
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);
96 rpnStructure[offset++] = 0x00; // end rpnRpnOp
97 rpnStructure[offset++] = 0x00;
101 abstract byte[] opType1();