- Add support for the new "phonetic" relation modifier,
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLRelation.java
index 3de9f57..36fae4a 100644 (file)
@@ -1,76 +1,73 @@
-// $Id: CQLRelation.java,v 1.1 2002-10-30 09:19:26 mike Exp $
+// $Id: CQLRelation.java,v 1.6 2002-11-17 23:29:02 mike Exp $
 
 package org.z3950.zing.cql;
 import java.util.Vector;
+import java.util.Properties;
 import java.lang.StringBuffer;
 
 /**
  * Represents a relation between a CQL qualifier and term.
- * ###
  *
- * @version    $Id: CQLRelation.java,v 1.1 2002-10-30 09:19:26 mike Exp $
+ * @version    $Id: CQLRelation.java,v 1.6 2002-11-17 23:29:02 mike Exp $
  */
 public class CQLRelation extends CQLNode {
-    String base;
-    Vector modifiers;
+    ModifierSet ms;
 
+    /**
+     * Creates a new CQLRelation with the specified base relation.
+     * Typical base relations include the usual six ordering relations
+     * (<TT>&lt;=</TT>, <TT>&gt</TT>, <I>etc.</I>), the text
+     * relations <TT>any</TT>, <TT>all</TT> and <TT>exact</TT> and the
+     * server-choice relation <TT>scr</TT>.
+     */
     public CQLRelation(String base) {
-       this.base = base;
-       modifiers = new Vector();
+       ms = new ModifierSet(base);
     }
 
+    /**
+     * Returns the base relation with which the CQLRelation was
+     * originally created.
+     */
+    public String getBase() {
+       return ms.getBase();
+    }
+
+    /**
+     * Adds a new relation modifier to the specified CQLRelation.
+     * Typical relation modifiers include <TT>relevant</TT>,
+     * <TT>fuzzy</TT>, <TT>stem</TT> and <TT>phonetic</TT>.  On the
+     * whole, these modifiers have a meaningful interpretation only
+     * for the text relations.
+     */
     public void addModifier(String modifier) {
-       modifiers.add(modifier);
+       ms.addModifier(null, modifier);
     }
 
+    /**
+     * Returns an array of the modifiers associated with a CQLRelation.
+     * @return
+     * An array of zero or more <TT>String</TT>s, each representing a
+     * modifier associated with the specified CQLRelation.
+     */
     public String[] getModifiers() {
-       int n = modifiers.size();
-       String[] res = new String[n];
+       Vector[] v = ms.getModifiers();
+       int n = v.length;
+       String[] s = new String[n];
        for (int i = 0; i < n; i++) {
-           res[i] = (String) modifiers.get(i);
+           s[i] = (String) v[i].get(1);
        }
-
-       return res;
+       return s;
     }
 
     public String toXCQL(int level) {
-       StringBuffer buf = new StringBuffer();
-       buf.append (indent(level) + "<relation>\n" +
-                   indent(level+1) + "<value>" + xq(base) + "</value>\n");
-       String[] mods = getModifiers();
-       if (mods.length > 0) {
-           buf.append(indent(level+1) + "<modifiers>\n");
-           for (int i = 0; i < mods.length; i++)
-               buf.append(indent(level+2)).
-                   append("<modifier><value>"). append(mods[i]).
-                   append("</value></modifier>\n");
-           buf.append(indent(level+1) + "</modifiers>\n");
-       }
-       buf.append(indent(level) + "</relation>\n");
-       return buf.toString();
+       return ms.toXCQL(level, "relation");
     }
 
     public String toCQL() {
-       StringBuffer buf = new StringBuffer(base);
-       String[] mods = getModifiers();
-       for (int i = 0; i < mods.length; i++) {
-           buf.append("/").append(mods[i]);
-       }
-
-       return buf.toString();
+       return ms.toCQL();
     }
 
-    public static void main(String[] args) {
-       if (args.length < 1) {
-           System.err.println("Usage: CQLRelation <base> <modifier>...");
-           System.exit(1);
-       }
-
-       CQLRelation res = new CQLRelation(args[0]);
-       for (int i = 1; i < args.length; i++) {
-           res.addModifier(args[i]);
-       }
-
-       System.out.println(res.toCQL());
+    public String toPQF(Properties config) throws PQFTranslationException {
+       throw new Error("CQLRelation.toPQF() can never be called");
     }
 }