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