1 // $Id: CQLBooleanNode.java,v 1.14 2007-06-06 12:22:01 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.14 2007-06-06 12:22:01 mike Exp $
13 public abstract class CQLBooleanNode extends CQLNode {
14 CQLBooleanNode() {} // prevent javadoc from documenting this
17 * The root of a parse-tree representing the left-hand side.
22 * The root of a parse-tree representing the right-hand side.
26 public String toXCQL(int level, Vector prefixes) {
27 // ### Should this use CQLNode.toXCQL(level+2, prefixes)?
28 return (indent(level) + "<triple>\n" +
29 renderPrefixes(level+1, prefixes) +
31 indent(level+1) + "<leftOperand>\n" +
32 left.toXCQL(level+2) +
33 indent(level+1) + "</leftOperand>\n" +
34 indent(level+1) + "<rightOperand>\n" +
35 right.toXCQL(level+2) +
36 indent(level+1) + "</rightOperand>\n" +
37 indent(level) + "</triple>\n");
40 // Represents the boolean operation itself: overridden for CQLProxNode
41 String opXCQL(int level) {
42 return(indent(level) + "<boolean>\n" +
43 indent(level+1) + "<value>" + op() + "</value>\n" +
44 indent(level) + "</boolean>\n");
47 public String toCQL() {
48 // ### We don't always need parens around the operands
49 return "(" + left.toCQL() + ") " + op() + " (" + right.toCQL() + ")";
52 public String toPQF(Properties config) throws PQFTranslationException {
53 return ("@" + opPQF() +
54 " " + left.toPQF(config) +
55 " " + right.toPQF(config));
58 // represents the operation for PQF: overridden for CQLProxNode
59 String opPQF() { return op(); }
63 public byte[] toType1BER(Properties config) throws PQFTranslationException {
64 System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
66 byte[] rpn1 = left.toType1BER(config);
67 byte[] rpn2 = right.toType1BER(config);
68 byte[] op = opType1();
69 byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
72 int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
74 rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
75 System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
76 offset += rpn1.length;
77 System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
78 offset += rpn2.length;
79 System.arraycopy(op, 0, rpnStructure, offset, op.length);
81 rpnStructure[offset++] = 0x00; // end rpnRpnOp
82 rpnStructure[offset++] = 0x00;
86 abstract byte[] opType1();