1 // $Id: CQLSortNode.java,v 1.2 2008-04-11 12:05:15 mike Exp $
3 package org.z3950.zing.cql;
4 import java.util.ArrayList;
6 import java.util.Properties;
10 * Represents a sort node in a CQL parse-tree.
12 * @version $Id: CQLSortNode.java,v 1.2 2008-04-11 12:05:15 mike Exp $
14 public class CQLSortNode extends CQLNode {
16 * The root of a subtree representing the query whose result is to
19 private CQLNode subtree;
22 * The set of sort keys by which results are to be sorted,
23 * each expressed as an index together with zero or more
26 List<ModifierSet> keys;
28 public CQLNode getSubtree() {
32 public CQLSortNode(CQLNode subtree) {
33 this.subtree = subtree;
34 keys = new ArrayList<ModifierSet>();
37 public void addSortIndex(ModifierSet key) {
41 public List<ModifierSet> getSortIndexes() {
46 public String toXCQL(int level, List<CQLPrefix> prefixes,
47 List<ModifierSet> sortkeys) {
49 throw new Error("CQLSortNode.toXCQL() called with sortkeys");
50 return subtree.toXCQL(level, prefixes, keys);
54 public String toCQL() {
55 StringBuffer buf = new StringBuffer(subtree.toCQL());
58 buf.append(" sortby");
59 for (int i = 0; i < keys.size(); i++) {
60 ModifierSet key = keys.get(i);
61 buf.append(" " + key.toCQL());
65 return buf.toString();
69 public String toPQF(Properties config) throws PQFTranslationException {
70 return "@attr 1=oops \"###\"";
74 public byte[] toType1BER(Properties config)
75 throws PQFTranslationException {
76 // There is no way to represent sorting in a standard Z39.50
77 // Type-1 query, so the best we can do is return the
78 // underlying query and ignore the sort-specification.
79 return subtree.toType1BER(config);