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;
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 {
18 * The root of a parse-tree representing the left-hand side.
20 public CQLNode getLeft() {
24 private CQLNode right;
27 * The root of a parse-tree representing the right-hand side.
29 public CQLNode getRight() {
35 * The set of modifiers that are applied to this boolean.
37 public List<Modifier> getModifiers() {
38 return ms.getModifiers();
41 protected CQLBooleanNode(CQLNode left, CQLNode right, ModifierSet ms) {
48 public String toXCQL(int level, List<CQLPrefix> prefixes,
49 List<ModifierSet> sortkeys) {
50 return (indent(level) + "<triple>\n" +
51 renderPrefixes(level+1, prefixes) +
52 ms.toXCQL(level+1, "boolean") +
53 indent(level+1) + "<leftOperand>\n" +
54 left.toXCQL(level+2) +
55 indent(level+1) + "</leftOperand>\n" +
56 indent(level+1) + "<rightOperand>\n" +
57 right.toXCQL(level+2) +
58 indent(level+1) + "</rightOperand>\n" +
59 renderSortKeys(level+1, sortkeys) +
60 indent(level) + "</triple>\n");
64 public String toCQL() {
65 // ### We don't always need parens around the operands
66 return ("(" + left.toCQL() + ")" +
67 " " + ms.toCQL() + " " +
68 "(" + right.toCQL() + ")");
72 public String toPQF(Properties config) throws PQFTranslationException {
73 return ("@" + opPQF() +
74 " " + left.toPQF(config) +
75 " " + right.toPQF(config));
78 // represents the operation for PQF: overridden for CQLProxNode
79 String opPQF() { return ms.getBase(); }
82 public byte[] toType1BER(Properties config) throws PQFTranslationException {
83 System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
85 byte[] rpn1 = left.toType1BER(config);
86 byte[] rpn2 = right.toType1BER(config);
87 byte[] op = opType1();
88 byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
91 int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);
93 rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
94 System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
95 offset += rpn1.length;
96 System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
97 offset += rpn2.length;
98 System.arraycopy(op, 0, rpnStructure, offset, op.length);
100 rpnStructure[offset++] = 0x00; // end rpnRpnOp
101 rpnStructure[offset++] = 0x00;
105 abstract byte[] opType1();