2 package org.z3950.zing.cql;
3 import java.util.ArrayList;
5 import java.util.Properties;
9 * Represents a sort node in a CQL parse-tree.
12 public class CQLSortNode extends CQLNode {
14 * The root of a subtree representing the query whose result is to
17 private CQLNode subtree;
20 * The set of sort keys by which results are to be sorted,
21 * each expressed as an index together with zero or more
24 List<ModifierSet> keys;
26 public CQLNode getSubtree() {
30 public CQLSortNode(CQLNode subtree) {
31 this.subtree = subtree;
32 keys = new ArrayList<ModifierSet>();
35 public void addSortIndex(ModifierSet key) {
39 public List<ModifierSet> getSortIndexes() {
44 void toXCQLInternal(XCQLBuilder b, int level, List<CQLPrefix> prefixes,
45 List<ModifierSet> sortkeys) {
47 throw new Error("CQLSortNode.toXCQL() called with sortkeys");
48 subtree.toXCQLInternal(b, level, prefixes, keys);
52 public String toCQL() {
53 StringBuilder buf = new StringBuilder(subtree.toCQL());
56 buf.append(" sortby");
57 for (int i = 0; i < keys.size(); i++) {
58 ModifierSet key = keys.get(i);
59 buf.append(" ").append(key.toCQL());
63 return buf.toString();
67 public String toPQF(Properties config) throws PQFTranslationException {
68 return "@attr 1=oops \"###\"";
72 public byte[] toType1BER(Properties config)
73 throws PQFTranslationException {
74 // There is no way to represent sorting in a standard Z39.50
75 // Type-1 query, so the best we can do is return the
76 // underlying query and ignore the sort-specification.
77 return subtree.toType1BER(config);