X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLNode.java;h=3e42e1e101bf35163cf343b4eb721b2cc2999399;hb=af9fc1ccd0a8d9048d0b469a72b11bead020b719;hp=200776fdf1f93de5326eb26a6cffd95c4dae5f41;hpb=136cb9d5cc54a9be6ea3c7240257b80c7da96f18;p=cql-java-moved-to-github.git diff --git a/src/org/z3950/zing/cql/CQLNode.java b/src/org/z3950/zing/cql/CQLNode.java index 200776f..3e42e1e 100644 --- a/src/org/z3950/zing/cql/CQLNode.java +++ b/src/org/z3950/zing/cql/CQLNode.java @@ -1,4 +1,4 @@ -// $Id: CQLNode.java,v 1.16 2002-12-04 16:56:06 mike Exp $ +// $Id: CQLNode.java,v 1.26 2007-07-03 13:36:03 mike Exp $ package org.z3950.zing.cql; import java.util.Properties; @@ -8,12 +8,24 @@ import java.util.Vector; /** * Represents a node in a CQL parse-tree. * - * @version $Id: CQLNode.java,v 1.16 2002-12-04 16:56:06 mike Exp $ + * @version $Id: CQLNode.java,v 1.26 2007-07-03 13:36:03 mike Exp $ */ public abstract class CQLNode { CQLNode() {} // prevent javadoc from documenting this /** + * Returns the name of the result-set to which this query is a + * reference, if and only if the entire query consists only of a + * result-set reference. If it's anything else, including a + * boolean combination of a result-set reference with something + * else, then null is returned instead. + * @return the name of the referenced result-set + */ + public String getResultSetName() { + return null; + } + + /** * Translates a parse-tree into an XCQL document. *

* @param level @@ -26,13 +38,18 @@ public abstract class CQLNode { * parse-tree whose root is this node. */ public String toXCQL(int level) { - return toXCQL(level, new Vector()); + return toXCQL(level, null); } - abstract public String toXCQL(int level, Vector prefixes); + public String toXCQL(int level, Vector prefixes) { + return toXCQL(level, prefixes, null); + } + + abstract public String toXCQL(int level, Vector prefixes, + Vector sortkeys); protected static String renderPrefixes(int level, Vector prefixes) { - if (prefixes.size() == 0) + if (prefixes == null || prefixes.size() == 0) return ""; String res = indent(level) + "\n"; for (int i = 0; i < prefixes.size(); i++) { @@ -47,6 +64,18 @@ public abstract class CQLNode { return res + indent(level) + "\n"; } + protected static String renderSortKeys(int level, + Vector sortkeys) { + if (sortkeys == null || sortkeys.size() == 0) + return ""; + String res = indent(level) + "\n"; + for (int i = 0; i < sortkeys.size(); i++) { + ModifierSet key = sortkeys.get(i); + res += key.sortKeyToXCQL(level+1); + } + return res + indent(level) + "\n"; + } + /** * Decompiles a parse-tree into a CQL query. *

@@ -69,15 +98,14 @@ public abstract class CQLNode { *

* @param config * A Properties object containing configuration - * information that specifies the mapping from CQL qualifiers, + * information that specifies the mapping from CQL indexes, * relations, etc. to Type-1 attributes. The mapping - * specification is described in the cql-java distribution's + * specification is described in the CQL-Java distribution's * sample PQF-mapping configuration file, * etc/pqf.properties, which see. * @return * A String containing a PQF query equivalent to the parse-tree - * whose root is this node. This may be fed into the tool of - * your choice to obtain a BER-encoded packet. + * whose root is this node. */ abstract public String toPQF(Properties config) throws PQFTranslationException; @@ -95,9 +123,25 @@ public abstract class CQLNode { protected static String xq(String str) { return Utils.xq(str); } /** - * ### Document this! + * Renders a parser-tree into a BER-endoded packet representing an + * equivalent Z39.50 Type-1 query. If you don't know what that + * means, then you don't need this method :-) This is useful + * primarily for SRW-to-Z39.50 gateways. + * + * @param config + * A Properties object containing configuration + * information that specifies the mapping from CQL indexes, + * relations, etc. to Type-1 attributes. The mapping + * specification is described in the CQL-Java distribution's + * sample PQF-mapping configuration file, + * etc/pqf.properties, which see. + * @return + * A byte array containing the BER packet. + * @see + * ftp://ftp.rsasecurity.com/pub/pkcs/ascii/layman.asc */ - abstract public byte[] toType1(Properties config) + abstract public byte[] toType1BER(Properties config) throws PQFTranslationException; // ANS.1 classes @@ -144,7 +188,7 @@ public abstract class CQLNode { /** * Put a length directly into a BER record. * - * @param length length to put into record + * @param len length to put into record * @return the new, incremented value of the offset parameter. */ public // ### shouldn't this be protected? @@ -183,7 +227,7 @@ public abstract class CQLNode { /** * Get the length needed to represent the given number. * - * @param number determine length needed to encode this + * @param num determine length needed to encode this * @return length needed to encode given number */ protected static final int numLen(long num) { @@ -218,8 +262,8 @@ public abstract class CQLNode { } // Used only by the makeOID() method - private static final java.util.Hashtable madeOIDs = - new java.util.Hashtable(10); + private static final java.util.Hashtable madeOIDs = + new java.util.Hashtable(10); protected static final byte[] makeOID(String oid) { byte[] o; @@ -289,7 +333,7 @@ public abstract class CQLNode { public static final byte[] makeQuery(CQLNode root, Properties properties) throws PQFTranslationException { - byte[] rpnStructure = root.toType1(properties); + byte[] rpnStructure = root.toType1BER(properties); byte[] qry = new byte[rpnStructure.length+100]; int offset = 0; offset = putTag(CONTEXT, 1, CONSTRUCTED, qry, offset);