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() {
45 public String toXCQL(int level, List<CQLPrefix> prefixes,
46 List<ModifierSet> sortkeys) {
48 throw new Error("CQLSortNode.toXCQL() called with sortkeys");
49 return subtree.toXCQL(level, prefixes, keys);
52 public String toCQL() {
53 StringBuffer buf = new StringBuffer(subtree.toCQL());
56 buf.append(" sortby");
57 for (int i = 0; i < keys.size(); i++) {
58 ModifierSet key = keys.get(i);
59 buf.append(" " + key.toCQL());
63 return buf.toString();
66 public String toPQF(Properties config) throws PQFTranslationException {
67 return "@attr 1=oops \"###\"";
70 public byte[] toType1BER(Properties config)
71 throws PQFTranslationException {
72 // There is no way to represent sorting in a standard Z39.50
73 // Type-1 query, so the best we can do is return the
74 // underlying query and ignore the sort-specification.
75 return subtree.toType1BER(config);