Remove CVS expansions
[cql-java-moved-to-github.git] / src / main / java / org / z3950 / zing / cql / CQLSortNode.java
1
2 package org.z3950.zing.cql;
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Properties;
6
7
8 /**
9  * Represents a sort node in a CQL parse-tree.
10  *
11  */
12 public class CQLSortNode extends CQLNode {
13     /**
14      * The root of a subtree representing the query whose result is to
15      * be sorted.
16      */ 
17     private CQLNode subtree;
18
19     /**
20      * The set of sort keys by which results are to be sorted,
21      * each expressed as an index together with zero or more
22      * modifiers.
23      */ 
24     List<ModifierSet> keys;
25
26     public CQLNode getSubtree() {
27         return subtree;
28     }
29
30     public CQLSortNode(CQLNode subtree) {
31         this.subtree = subtree;
32         keys = new ArrayList<ModifierSet>();
33     }
34
35     public void addSortIndex(ModifierSet key) {
36         keys.add(key);
37     }
38
39     public List<ModifierSet> getSortIndexes() {
40         return keys;
41     }
42
43     @Override
44     void toXCQLInternal(XCQLBuilder b, int level, List<CQLPrefix> prefixes,
45                          List<ModifierSet> sortkeys) {
46         if (sortkeys != null)
47             throw new Error("CQLSortNode.toXCQL() called with sortkeys");
48         subtree.toXCQLInternal(b, level, prefixes, keys);
49     }
50
51     @Override
52     public String toCQL() {
53         StringBuilder buf = new StringBuilder(subtree.toCQL());
54
55         if (keys != null) {
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());
60             }
61         }
62
63         return buf.toString();
64     }
65
66     @Override
67     public String toPQF(Properties config) throws PQFTranslationException {
68         return "@attr 1=oops \"###\"";
69     }
70
71     @Override
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);
78     }
79 }