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 {
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<CQLPrefix> prefixes,
36 Vector<ModifierSet> sortkeys) {
37 return (indent(level) + "<triple>\n" +
38 renderPrefixes(level+1, prefixes) +
39 ms.toXCQL(level+1, "boolean") +
40 indent(level+1) + "<leftOperand>\n" +
41 left.toXCQL(level+2) +
42 indent(level+1) + "</leftOperand>\n" +
43 indent(level+1) + "<rightOperand>\n" +
44 right.toXCQL(level+2) +
45 indent(level+1) + "</rightOperand>\n" +
46 renderSortKeys(level+1, sortkeys) +
47 indent(level) + "</triple>\n");
50 public String toCQL() {
51 // ### We don't always need parens around the operands
52 return ("(" + left.toCQL() + ")" +
53 " " + ms.toCQL() + " " +
54 "(" + right.toCQL() + ")");
57 public String toPQF(Properties config) throws PQFTranslationException {
58 return ("@" + opPQF() +
59 " " + left.toPQF(config) +
60 " " + right.toPQF(config));
63 // represents the operation for PQF: overridden for CQLProxNode
64 String opPQF() { return ms.getBase(); }
66 public byte[] toType1BER(Properties config) throws PQFTranslationException {
67 System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
69 byte[] rpn1 = left.toType1BER(config);
70 byte[] rpn2 = right.toType1BER(config);
71 byte[] op = opType1();
72 byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
75 int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
77 rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
78 System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
79 offset += rpn1.length;
80 System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
81 offset += rpn2.length;
82 System.arraycopy(op, 0, rpnStructure, offset, op.length);
84 rpnStructure[offset++] = 0x00; // end rpnRpnOp
85 rpnStructure[offset++] = 0x00;
89 abstract byte[] opType1();