1 // $Id: CQLBooleanNode.java,v 1.18 2007-07-03 16:03:00 mike Exp $
3 package org.z3950.zing.cql;
5 import java.util.Properties;
7 import static org.z3950.zing.cql.Utils.*;
11 * Represents a boolean node in a CQL parse-tree.
13 * @version $Id: CQLBooleanNode.java,v 1.18 2007-07-03 16:03:00 mike Exp $
15 public abstract class CQLBooleanNode extends CQLNode {
20 * The root of a parse-tree representing the left-hand side.
22 public CQLNode getLeft() {
26 private CQLNode right;
29 * The root of a parse-tree representing the right-hand side.
31 public CQLNode getRight() {
37 * The set of modifiers that are applied to this boolean.
39 public List<Modifier> getModifiers() {
40 return ms.getModifiers();
43 protected CQLBooleanNode(CQLNode left, CQLNode right, ModifierSet ms) {
50 public String toXCQL(int level, List<CQLPrefix> prefixes,
51 List<ModifierSet> sortkeys) {
52 return (indent(level) + "<triple>\n" +
53 renderPrefixes(level+1, prefixes) +
54 ms.toXCQL(level+1, "boolean") +
55 indent(level+1) + "<leftOperand>\n" +
56 left.toXCQL(level+2) +
57 indent(level+1) + "</leftOperand>\n" +
58 indent(level+1) + "<rightOperand>\n" +
59 right.toXCQL(level+2) +
60 indent(level+1) + "</rightOperand>\n" +
61 renderSortKeys(level+1, sortkeys) +
62 indent(level) + "</triple>\n");
66 public String toCQL() {
67 // ### We don't always need parens around the operands
68 return ("(" + left.toCQL() + ")" +
69 " " + ms.toCQL() + " " +
70 "(" + right.toCQL() + ")");
74 public String toPQF(Properties config) throws PQFTranslationException {
75 return ("@" + opPQF() +
76 " " + left.toPQF(config) +
77 " " + right.toPQF(config));
80 // represents the operation for PQF: overridden for CQLProxNode
81 String opPQF() { return ms.getBase(); }
84 public byte[] toType1BER(Properties config) throws PQFTranslationException {
85 System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
87 byte[] rpn1 = left.toType1BER(config);
88 byte[] rpn2 = right.toType1BER(config);
89 byte[] op = opType1();
90 byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
93 int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
95 rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
96 System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
97 offset += rpn1.length;
98 System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
99 offset += rpn2.length;
100 System.arraycopy(op, 0, rpnStructure, offset, op.length);
102 rpnStructure[offset++] = 0x00; // end rpnRpnOp
103 rpnStructure[offset++] = 0x00;
107 abstract byte[] opType1();