- Change the XCQL output to include the nasty and redundant
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLBooleanNode.java
1 // $Id: CQLBooleanNode.java,v 1.9 2002-11-20 01:15:14 mike Exp $
2
3 package org.z3950.zing.cql;
4 import java.util.Properties;
5 import java.util.Vector;
6
7
8 /**
9  * Represents a boolean node in a CQL parse-tree.
10  *
11  * @version     $Id: CQLBooleanNode.java,v 1.9 2002-11-20 01:15:14 mike Exp $
12  */
13 public abstract class CQLBooleanNode extends CQLNode {
14     CQLBooleanNode() {}         // prevent javadoc from documenting this
15
16     /**
17      * The root of a parse-tree representing the left-hand side.
18      */ 
19     public CQLNode left;
20
21     /**
22      * The root of a parse-tree representing the right-hand side.
23      */ 
24     public CQLNode right;
25
26     public String toXCQL(int level, Vector prefixes) {
27         return (indent(level) + "<triple>\n" +
28                 renderPrefixes(level+1, prefixes) +
29                 opXQL(level+1) +
30                 indent(level+1) + "<leftOperand>\n" +
31                 left.toXCQL(level+2, new Vector()) +
32                 indent(level+1) + "</leftOperand>\n" +
33                 indent(level+1) + "<rightOperand>\n" +
34                 right.toXCQL(level+2, new Vector()) +
35                 indent(level+1) + "</rightOperand>\n" +
36                 indent(level) + "</triple>\n");
37     }
38
39     // Represents the boolean operation itself: overridden for CQLProxNode
40     String opXQL(int level) {
41         return(indent(level) + "<boolean>\n" +
42                indent(level+1) + "<value>" + op() + "</value>\n" +
43                indent(level) + "</boolean>\n");
44     }
45
46     public String toCQL() {
47         // ### We don't always need parens around the operands
48         return "(" + left.toCQL() + ") " + op() + " (" + right.toCQL() + ")";
49     }
50
51     public String toPQF(Properties config) throws PQFTranslationException {
52         return ("@" + opPQF() +
53                 " " + left.toPQF(config) +
54                 " " + right.toPQF(config));
55     }
56
57     // represents the operation for PQF: overridden for CQLProxNode
58     String opPQF() { return op(); }
59
60     abstract String op();
61 }