X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLBooleanNode.java;h=6e772eb812ddb3cb84ca733323c804cec065750d;hb=57b8aeb26a6aacaa478e6886ade3e40ca6eae2bb;hp=c56aac40cb31f5f6ad71a58c32c6176d32cad051;hpb=069f263b3422968c95d2b2a74291f04dfcdb15ac;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 c56aac4..6e772eb 100644 --- a/src/org/z3950/zing/cql/CQLBooleanNode.java +++ b/src/org/z3950/zing/cql/CQLBooleanNode.java @@ -1,15 +1,86 @@ -// $Id: CQLBooleanNode.java,v 1.2 2002-10-25 16:11:05 mike Exp $ +// $Id: CQLBooleanNode.java,v 1.12 2002-12-05 17:14:52 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.2 2002-10-25 16:11:05 mike Exp $ + * @version $Id: CQLBooleanNode.java,v 1.12 2002-12-05 17:14:52 mike Exp $ */ public abstract class CQLBooleanNode extends CQLNode { - protected CQLNode left; - protected CQLNode right; + CQLBooleanNode() {} // prevent javadoc from documenting this + + /** + * The root of a parse-tree representing the left-hand side. + */ + public CQLNode left; + + /** + * The root of a parse-tree representing the right-hand side. + */ + public CQLNode right; + + public String toXCQL(int level, Vector prefixes) { + return (indent(level) + "\n" + + renderPrefixes(level+1, prefixes) + + opXCQL(level+1) + + indent(level+1) + "\n" + + left.toXCQL(level+2, new Vector()) + + indent(level+1) + "\n" + + indent(level+1) + "\n" + + right.toXCQL(level+2, new Vector()) + + indent(level+1) + "\n" + + indent(level) + "\n"); + } + + // Represents the boolean operation itself: overridden for CQLProxNode + String opXCQL(int level) { + return(indent(level) + "\n" + + indent(level+1) + "" + op() + "\n" + + indent(level) + "\n"); + } + + public String toCQL() { + // ### We don't always need parens around the operands + 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 op(); } + + abstract String op(); + + public byte[] toType1(Properties config) throws PQFTranslationException { + System.out.println("in CQLBooleanNode.toType101(): PQF=" + + toPQF(config)); + byte[] rpn1 = left.toType1(config); + byte[] rpn2 = right.toType1(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(); }