e0fc2e5f331921f653b2f137bf1a86aeb5a45646
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLNode.java
1 // $Id: CQLNode.java,v 1.14 2002-11-17 23:29:02 mike Exp $
2
3 package org.z3950.zing.cql;
4 import java.util.Properties;
5
6
7 /**
8  * Represents a node in a CQL parse-tree.
9  *
10  * @version     $Id: CQLNode.java,v 1.14 2002-11-17 23:29:02 mike Exp $
11  */
12 public abstract class CQLNode {
13     CQLNode() {}                // prevent javadoc from documenting this
14
15     /**
16      * Translates a parse-tree into an XCQL document.
17      * <P>
18      * @param level
19      *  The number of levels to indent the top element of the XCQL
20      *  document.  This will typically be 0 when invoked by an
21      *  application; it takes higher values when this method is
22      *  invoked recursively for nodes further down the tree.
23      * @return
24      *  A String containing an XCQL document equivalent to the
25      *  parse-tree whose root is this node.
26      */
27     abstract public String toXCQL(int level);
28
29     /**
30      * Decompiles a parse-tree into a CQL query.
31      * <P>
32      * @return
33      *  A String containing a CQL query equivalent to the parse-tree
34      *  whose root is this node, so that compiling that query will
35      *  yield an identical tree.
36      */
37     abstract public String toCQL();
38
39     /**
40      * Renders a parse-tree into a Yaz-style PQF string.
41      * PQF, or Prefix Query Format, is a cryptic but powerful notation
42      * that can be trivially mapped, one-to-one, int Z39.50 Type-1 and
43      * Type-101 queries.  A specification for the format can be found
44      * in
45      * <A href="http://indexdata.dk/yaz/doc/tools.php#PQF"
46      *  >Chapter 7 (Supporting Tools)</A> of the
47      * <A href="http://indexdata.dk/yaz/">YAZ</A> manual.
48      * <P>
49      * @param config
50      *  A <TT>Properties</TT> object containing configuration
51      *  information that specifies the mapping from CQL qualifiers,
52      *  relations, etc. to Type-1 attributes.  The mapping
53      *  specification is described in the cql-java distribution's
54      *  sample PQF-mapping configuration file,
55      *  <TT>etc/pqf.properties</TT>, which see.
56      * @return
57      *  A String containing a PQF query equivalent to the parse-tree
58      *  whose root is this node.  This may be fed into the tool of
59      *  your choice to obtain a BER-encoded packet.
60      */
61     abstract public String toPQF(Properties config)
62         throws PQFTranslationException;
63
64     /**
65      * Returns a String of spaces for indenting to the specified level.
66      */
67     protected static String indent(int level) { return Utils.indent(level); }
68
69     /**
70      * Returns the argument String quoted for XML.
71      * For example, each occurrence of <TT>&lt;</TT> is translated to
72      * <TT>&amp;lt;</TT>.
73      */
74     protected static String xq(String str) { return Utils.xq(str); }
75 }