KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdql > parser > Q_UnaryNot


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 /* Generated By:JJTree: Do not edit this line. Q_UnaryNot.java */
7
8 package com.hp.hpl.jena.rdql.parser;
9
10
11 import java.io.PrintWriter JavaDoc;
12 import com.hp.hpl.jena.graph.query.IndexValues;
13 import com.hp.hpl.jena.graph.query.Expression;
14 import com.hp.hpl.jena.rdql.*;
15
16 public class Q_UnaryNot extends ExprNode implements Expr, ExprBoolean
17 {
18     private String JavaDoc printName = "unaryminus";
19     private String JavaDoc opSymbol = "!";
20     Expr expr;
21
22     Q_UnaryNot(int id)
23     {
24         super(id);
25     }
26
27     Q_UnaryNot(RDQLParser p, int id)
28     {
29         super(p, id);
30     }
31
32     public void jjtClose()
33     {
34         int n = jjtGetNumChildren();
35         if (n != 1) throw new QueryException("Q_UnaryNot: Wrong number of children: " + n);
36         expr = (Expr) jjtGetChild(0);
37     }
38
39     public NodeValue eval(Query q, IndexValues env)
40     {
41         NodeValue v = expr.eval(q, env);
42
43         if (!v.isBoolean()) throw new EvalTypeException("Q_UnaryNot: Wanted a number: got " + expr);
44
45         NodeValueSettable result;
46
47         result = new WorkingVar();
48         result.setBoolean(!v.getBoolean());
49         return result;
50     }
51
52     // -----------
53
// graph.query.Expression
54

55     public boolean isApply() { return true ; }
56     public String JavaDoc getFun() { return super.constructURI(this.getClass().getName()) ; }
57     public int argCount() { return 1; }
58     public Expression getArg(int i)
59     {
60         if ( i == 0 && expr instanceof Expression )
61             return (Expression)expr ;
62         return null;
63     }
64
65     public String JavaDoc asInfixString()
66     {
67         return QueryPrintUtils.asInfixString1(expr, printName, opSymbol);
68     }
69
70     public String JavaDoc asPrefixString()
71     {
72         return QueryPrintUtils.asPrefixString(expr, null, printName, opSymbol);
73     }
74
75     public void print(PrintWriter JavaDoc pw, int level)
76     {
77         QueryPrintUtils.print(pw, expr, null, printName, opSymbol, level);
78     }
79
80     public String JavaDoc toString()
81     {
82         return asInfixString();
83     }
84
85 }
86
87 /*
88  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
89  * All rights reserved.
90  *
91  * Redistribution and use in source and binary forms, with or without
92  * modification, are permitted provided that the following conditions are met: 1.
93  * Redistributions of source code must retain the above copyright notice, this
94  * list of conditions and the following disclaimer. 2. Redistributions in
95  * binary form must reproduce the above copyright notice, this list of
96  * conditions and the following disclaimer in the documentation and/or other
97  * materials provided with the distribution. 3. The name of the author may not
98  * be used to endorse or promote products derived from this software without
99  * specific prior written permission.
100  *
101  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
102  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
103  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
104  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
105  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
106  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
107  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
108  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
109  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
110  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
111  */

112
Popular Tags