X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLBooleanNode.java;h=ec0608c8fe18bbd671d145da91cf1bf16825f44b;hb=af9fc1ccd0a8d9048d0b469a72b11bead020b719;hp=9908395ada666d023322bcad48d2aa3b2630fc54;hpb=953117d805ff5f53b2b3c541eff5ecd6461eba29;p=cql-java-moved-to-github.git diff --git a/src/org/z3950/zing/cql/CQLBooleanNode.java b/src/org/z3950/zing/cql/CQLBooleanNode.java index 9908395..ec0608c 100644 --- a/src/org/z3950/zing/cql/CQLBooleanNode.java +++ b/src/org/z3950/zing/cql/CQLBooleanNode.java @@ -1,29 +1,90 @@ -// $Id: CQLBooleanNode.java,v 1.3 2002-10-25 16:56:43 mike Exp $ +// $Id: CQLBooleanNode.java,v 1.18 2007-07-03 16:03:00 mike Exp $ package org.z3950.zing.cql; +import java.util.Properties; +import java.util.Vector; /** - * Represents a boolean node in a CQL parse-tree ... - * ### + * Represents a boolean node in a CQL parse-tree. * - * @version $Id: CQLBooleanNode.java,v 1.3 2002-10-25 16:56:43 mike Exp $ + * @version $Id: CQLBooleanNode.java,v 1.18 2007-07-03 16:03:00 mike Exp $ */ public abstract class CQLBooleanNode extends CQLNode { - protected CQLNode left; - protected CQLNode right; + /** + * The root of a parse-tree representing the left-hand side. + */ + public CQLNode left; - abstract String op(); + /** + * The root of a parse-tree representing the right-hand side. + */ + public CQLNode right; - String toXCQL(int level) { - return(indent(level) + "\n" + - indent(level+1) + "" + op() + "\n" + - left.toXCQL(level+1) + - right.toXCQL(level+1) + - indent(level) + "\n"); + /** + * The set of modifiers that are applied to this boolean. + */ + public ModifierSet ms; + + protected CQLBooleanNode(CQLNode left, CQLNode right, ModifierSet ms) { + this.left = left; + this.right = right; + this.ms = ms; + } + + public String toXCQL(int level, Vector prefixes, + Vector sortkeys) { + return (indent(level) + "\n" + + renderPrefixes(level+1, prefixes) + + ms.toXCQL(level+1, "boolean") + + indent(level+1) + "\n" + + left.toXCQL(level+2) + + indent(level+1) + "\n" + + indent(level+1) + "\n" + + right.toXCQL(level+2) + + indent(level+1) + "\n" + + renderSortKeys(level+1, sortkeys) + + indent(level) + "\n"); + } + + public String toCQL() { + // ### We don't always need parens around the operands + return ("(" + left.toCQL() + ")" + + " " + ms.toCQL() + " " + + "(" + right.toCQL() + ")"); } - String toCQL() { - return "(" + left.toCQL() + ") " + op() + " (" + right.toCQL() + ")"; + public String toPQF(Properties config) throws PQFTranslationException { + return ("@" + opPQF() + + " " + left.toPQF(config) + + " " + right.toPQF(config)); } + + // represents the operation for PQF: overridden for CQLProxNode + String opPQF() { return ms.getBase(); } + + public byte[] toType1BER(Properties config) throws PQFTranslationException { + System.out.println("in CQLBooleanNode.toType1BER(): PQF=" + + toPQF(config)); + byte[] rpn1 = left.toType1BER(config); + byte[] rpn2 = right.toType1BER(config); + byte[] op = opType1(); + byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4]; + + // rpnRpnOp + int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0); + + rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length + System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length); + offset += rpn1.length; + System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length); + offset += rpn2.length; + System.arraycopy(op, 0, rpnStructure, offset, op.length); + offset += op.length; + rpnStructure[offset++] = 0x00; // end rpnRpnOp + rpnStructure[offset++] = 0x00; + return rpnStructure; + } + + abstract byte[] opType1(); }