1 // $Id: CQLBooleanNode.java,v 1.17 2007-07-03 13:40:13 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.17 2007-07-03 13:40:13 mike Exp $
13 public abstract class CQLBooleanNode extends CQLNode {
15 * The root of a parse-tree representing the left-hand side.
20 * The root of a parse-tree representing the right-hand side.
25 * The set of modifiers that are applied to this boolean.
27 public ModifierSet ms;
29 protected CQLBooleanNode(CQLNode left, CQLNode right, ModifierSet ms) {
35 public String toXCQL(int level, Vector prefixes, Vector sortkeys) {
37 throw new Error("CQLBooleanNode.toXCQL() called with sortkeys");
39 return (indent(level) + "<triple>\n" +
40 renderPrefixes(level+1, prefixes) +
41 ms.toXCQL(level+1, "boolean") +
42 indent(level+1) + "<leftOperand>\n" +
43 left.toXCQL(level+2) +
44 indent(level+1) + "</leftOperand>\n" +
45 indent(level+1) + "<rightOperand>\n" +
46 right.toXCQL(level+2) +
47 indent(level+1) + "</rightOperand>\n" +
48 indent(level) + "</triple>\n");
51 public String toCQL() {
52 // ### We don't always need parens around the operands
53 return ("(" + left.toCQL() + ")" +
54 " " + ms.toCQL() + " " +
55 "(" + right.toCQL() + ")");
58 public String toPQF(Properties config) throws PQFTranslationException {
59 return ("@" + opPQF() +
60 " " + left.toPQF(config) +
61 " " + right.toPQF(config));
64 // represents the operation for PQF: overridden for CQLProxNode
65 String opPQF() { return ms.getBase(); }
67 public byte[] toType1BER(Properties config) throws PQFTranslationException {
68 System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
70 byte[] rpn1 = left.toType1BER(config);
71 byte[] rpn2 = right.toType1BER(config);
72 byte[] op = opType1();
73 byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
76 int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
78 rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
79 System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
80 offset += rpn1.length;
81 System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
82 offset += rpn2.length;
83 System.arraycopy(op, 0, rpnStructure, offset, op.length);
85 rpnStructure[offset++] = 0x00; // end rpnRpnOp
86 rpnStructure[offset++] = 0x00;
90 abstract byte[] opType1();