From: mike Date: Tue, 3 Jul 2007 12:55:56 +0000 (+0000) Subject: New X-Git-Tag: v1.5~62 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=80775d57e36e997ab0a4889153a4e366e4a050ce;p=cql-java-moved-to-github.git New --- diff --git a/src/org/z3950/zing/cql/CQLSortNode.java b/src/org/z3950/zing/cql/CQLSortNode.java new file mode 100644 index 0000000..bdcc7d2 --- /dev/null +++ b/src/org/z3950/zing/cql/CQLSortNode.java @@ -0,0 +1,68 @@ +// $Id: CQLSortNode.java,v 1.1 2007-07-03 12:55:56 mike Exp $ + +package org.z3950.zing.cql; +import java.util.Properties; +import java.util.Vector; + + +/** + * Represents a sort node in a CQL parse-tree. + * + * @version $Id: CQLSortNode.java,v 1.1 2007-07-03 12:55:56 mike Exp $ + */ +public class CQLSortNode extends CQLNode { + /** + * The root of a subtree representing the query whose result is to + * be sorted. + */ + public CQLNode subtree; + + /** + * The set of sort keys by which results are to be sorted, + * each expressed as an index together with zero or more + * modifiers. + */ + Vector keys; + + public CQLSortNode(CQLNode subtree) { + this.subtree = subtree; + keys = new Vector(); + } + + public void addSortIndex(ModifierSet key) { + keys.add(key); + } + + public String toXCQL(int level, Vector prefixes, + Vector sortkeys) { + if (sortkeys != null) + throw new Error("CQLSortNode.toXCQL() called with sortkeys"); + return subtree.toXCQL(level, prefixes, keys); + } + + public String toCQL() { + StringBuffer buf = new StringBuffer(subtree.toCQL()); + + if (keys != null) { + buf.append(" sortby"); + for (int i = 0; i < keys.size(); i++) { + ModifierSet key = keys.get(i); + buf.append(" " + key.toCQL()); + } + } + + return buf.toString(); + } + + public String toPQF(Properties config) throws PQFTranslationException { + return "@attr 1=oops \"###\""; + } + + public byte[] toType1BER(Properties config) + throws PQFTranslationException { + // There is no way to represent sorting in a standard Z39.50 + // Type-1 query, so the best we can do is return the + // underlying query and ignore the sort-specification. + return subtree.toType1BER(config); + } +}