KickJava   Java API By Example, From Geeks To Geeks.

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


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

5
6 package com.hp.hpl.jena.rdql.parser;
7
8
9 import java.io.PrintWriter JavaDoc;
10 import com.hp.hpl.jena.graph.query.IndexValues;
11 import com.hp.hpl.jena.graph.query.Expression ;
12 import com.hp.hpl.jena.rdql.*;
13
14 /* This file is automatically generated - do not edit.
15  * Arguments:
16  * Name = LogicalOr
17  * Operator = ||
18  * Print Name = or
19  * Template = ExprBooleanBLANK2.java
20  */

21
22 /**
23  * @author Automatically generated class: Operator: LogicalOr
24  * @version $Id: Q_LogicalOr.java,v 1.8 2005/02/21 12:15:44 andy_seaborne Exp $
25  */

26
27 public class Q_LogicalOr extends ExprNode implements Expr, ExprBoolean
28 {
29     Expr left ;
30     Expr right ;
31
32     private String JavaDoc printName = "or" ;
33     private String JavaDoc opSymbol = "||" ;
34
35     Q_LogicalOr(int id) { super(id); }
36
37     Q_LogicalOr(RDQLParser p, int id) { super(p, id); }
38
39     public NodeValue eval(Query q, IndexValues env)
40     {
41         NodeValue x = left.eval(q, env) ;
42         NodeValue y = right.eval(q, env) ;
43         
44         if ( ! x.isBoolean() )
45             throw new EvalTypeException("Q_LogicalOr: Wanted a boolean: "+x) ;
46         if ( ! y.isBoolean() )
47             throw new EvalTypeException("Q_LogicalOr: Wanted a boolean: "+y) ;
48
49         NodeValueSettable result ;
50         if ( x instanceof NodeValueSettable )
51             result = (NodeValueSettable)x ;
52         else if ( y instanceof NodeValueSettable )
53             result = (NodeValueSettable)y ;
54         else
55             result = new WorkingVar() ;
56
57         boolean b = (x.getBoolean() || y.getBoolean()) ;
58         result.setBoolean(b) ;
59         return result ;
60     }
61
62     public void jjtClose()
63     {
64         int n = jjtGetNumChildren() ;
65         if ( n != 2 )
66             throw new QueryException("Q_LogicalOr: Wrong number of children: "+n) ;
67         
68         left = (Expr)jjtGetChild(0) ;
69         right = (Expr)jjtGetChild(1) ;
70     }
71
72     // -----------
73
// graph.query.Expression
74

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

134
Popular Tags