1 // $Id: CQLBooleanNode.java,v 1.1 2002-12-04 16:54: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.1 2002-12-04 16:54: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 return (indent(level) + "<triple>\n" +
28 renderPrefixes(level+1, prefixes) +
30 indent(level+1) + "<leftOperand>\n" +
31 left.toXCQL(level+2, new Vector()) +
32 indent(level+1) + "</leftOperand>\n" +
33 indent(level+1) + "<rightOperand>\n" +
34 right.toXCQL(level+2, new Vector()) +
35 indent(level+1) + "</rightOperand>\n" +
36 indent(level) + "</triple>\n");
39 // Represents the boolean operation itself: overridden for CQLProxNode
40 String opXCQL(int level) {
41 return(indent(level) + "<boolean>\n" +
42 indent(level+1) + "<value>" + op() + "</value>\n" +
43 indent(level) + "</boolean>\n");
46 public String toCQL() {
47 // ### We don't always need parens around the operands
48 return "(" + left.toCQL() + ") " + op() + " (" + right.toCQL() + ")";
51 public String toPQF(Properties config) throws PQFTranslationException {
52 return ("@" + opPQF() +
53 " " + left.toPQF(config) +
54 " " + right.toPQF(config));
57 public byte[] toType1(Properties config) throws PQFTranslationException {
58 System.out.println("in CQLBooleanNode.toType101(): PQF="+toPQF(config));
59 byte[] rpn1=left.toType1(config);
60 byte[] rpn2=right.toType1(config);
62 byte[] rpnStructure=new byte[rpn1.length+rpn2.length+op.length+4];
64 int offset=putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0); // rpnRpnOp
65 rpnStructure[offset++]=(byte)(0x80&0xff); // indefinite length
66 System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
68 System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
70 System.arraycopy(op, 0, rpnStructure, offset, op.length);
72 rpnStructure[offset++]=0x00; // end rpnRpnOp
73 rpnStructure[offset++]=0x00;
77 // represents the operation for PQF: overridden for CQLProxNode
78 String opPQF() { return op(); }
81 abstract byte[] opType1();