Release 0.7 -- understands profiles relations and modifiers.
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLRelation.java
1 // $Id: CQLRelation.java,v 1.11 2003-09-04 21:56:46 mike Exp $
2
3 package org.z3950.zing.cql;
4 import java.util.Vector;
5 import java.util.Properties;
6 import java.lang.StringBuffer;
7
8 /**
9  * Represents a relation between a CQL qualifier and term.
10  *
11  * @version     $Id: CQLRelation.java,v 1.11 2003-09-04 21:56:46 mike Exp $
12  */
13 public class CQLRelation extends CQLNode {
14     ModifierSet ms;
15
16     /**
17      * Creates a new CQLRelation with the specified base relation.
18      * Typical base relations include the usual six ordering relations
19      * (<TT>&lt;=</TT>, <TT>&gt</TT>, <I>etc.</I>), the text
20      * relations <TT>any</TT>, <TT>all</TT> and <TT>exact</TT>, the
21      * server-choice relation <TT>scr</TT> and profiled relations of
22      * the form <TT><I>prefix</I>.<I>name</I></TT>.
23      */
24     public CQLRelation(String base) {
25         ms = new ModifierSet(base);
26     }
27
28     /**
29      * Returns the base relation with which the CQLRelation was
30      * originally created.
31      */
32     public String getBase() {
33         return ms.getBase();
34     }
35
36     /**
37      * Adds a new relation modifier to the specified CQLRelation.
38      * Typical relation modifiers include <TT>relevant</TT>,
39      * <TT>fuzzy</TT>, <TT>stem</TT> and <TT>phonetic</TT>.  On the
40      * whole, these modifiers have a meaningful interpretation only
41      * for the text relations.
42      */
43     public void addModifier(String modifier) {
44         ms.addModifier(null, modifier);
45     }
46
47     /**
48      * Returns an array of the modifiers associated with a CQLRelation.
49      * @return
50      *  An array of zero or more <TT>String</TT>s, each representing a
51      *  modifier associated with the specified CQLRelation.
52      */
53     public String[] getModifiers() {
54         Vector[] v = ms.getModifiers();
55         int n = v.length;
56         String[] s = new String[n];
57         for (int i = 0; i < n; i++) {
58             s[i] = (String) v[i].get(1);
59         }
60         return s;
61     }
62
63     public String toXCQL(int level, Vector prefixes) {
64         return ms.toXCQL(level, "relation");
65     }
66
67     public String toCQL() {
68         return ms.toCQL();
69     }
70
71     public String toPQF(Properties config) throws PQFTranslationException {
72         throw new Error("CQLRelation.toPQF() can never be called");
73     }
74
75     public byte[] toType1BER(Properties config) {
76         throw new Error("CQLRelation.toType1BER() can never be called");
77     }
78 }