1 // $Id: CQLBooleanNode.java,v 1.15 2007-06-29 10:21:30 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.15 2007-06-29 10:21:30 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) {
36 // ### Should this use CQLNode.toXCQL(level+2, prefixes)?
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 indent(level) + "</triple>\n");
49 public String toCQL() {
50 // ### We don't always need parens around the operands
51 return "(" + left.toCQL() + ") " + op() + " (" + right.toCQL() + ")";
54 public String toPQF(Properties config) throws PQFTranslationException {
55 return ("@" + opPQF() +
56 " " + left.toPQF(config) +
57 " " + right.toPQF(config));
60 // represents the operation for PQF: overridden for CQLProxNode
61 String opPQF() { return op(); }
65 public byte[] toType1BER(Properties config) throws PQFTranslationException {
66 System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
68 byte[] rpn1 = left.toType1BER(config);
69 byte[] rpn2 = right.toType1BER(config);
70 byte[] op = opType1();
71 byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
74 int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
76 rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
77 System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
78 offset += rpn1.length;
79 System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
80 offset += rpn2.length;
81 System.arraycopy(op, 0, rpnStructure, offset, op.length);
83 rpnStructure[offset++] = 0x00; // end rpnRpnOp
84 rpnStructure[offset++] = 0x00;
88 abstract byte[] opType1();