KickJava   Java API By Example, From Geeks To Geeks.

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


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_Var.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.Node ;
13 import com.hp.hpl.jena.graph.query.*;
14 import com.hp.hpl.jena.rdql.*;
15
16 public class Q_Var extends ExprNode implements Var, Expr
17 {
18     String JavaDoc varName ;
19     int index ;
20     VariableIndexes varIndexes ;
21
22     public Q_Var(int id) { super(id); }
23     public Q_Var(RDQLParser p, int id) { super(p, id); }
24
25     public void jjtClose()
26     {
27         if ( jjtGetNumChildren() != 1 )
28             throw new RDQL_InternalErrorException("Q_Var: expected 1 child: got "+jjtGetNumChildren()) ;
29         varName = ((Q_Identifier)jjtGetChild(0)).id ;
30     }
31
32     public String JavaDoc getVarName() { return varName ; }
33     public void setVarName(String JavaDoc vn) { varName = vn ; }
34
35     public NodeValue eval(com.hp.hpl.jena.rdql.Query q, IndexValues env)
36     {
37         // Result is a copy as a bound variable.
38
com.hp.hpl.jena.graph.Node v = (Node)env.get(index) ;
39         if ( v == null )
40         {
41             System.err.println("Oh dear: variable: "+varName) ;
42             WorkingVar tmp = new WorkingVar() ;
43             tmp.setString("unset: "+varName+"/"+index) ;
44             return tmp ;
45         }
46         WorkingVar var = new WorkingVar() ;
47         var.setNode(v) ;
48         return var ;
49     }
50
51     public String JavaDoc toString() { return "?"+varName ; }
52
53     public String JavaDoc asInfixString() { return toString() ; }
54     public String JavaDoc asPrefixString() { return toString() ; }
55
56     // Print prefix notation (multiline) for debugging
57
public void print(PrintWriter JavaDoc pw, int level)
58     {
59         QueryPrintUtils.indent(pw, level) ;
60         pw.println(this.asPrefixString()) ;
61     }
62
63     // graph.query.Expression
64
public Valuator prepare(VariableIndexes vi)
65     {
66         super.prepare(vi) ;
67         varIndexes = vi ;
68         index = vi.indexOf(varName) ;
69         return this ;
70     }
71     
72     public boolean isVariable() { return true ; }
73     public String JavaDoc getName() { return varName ; } // For variables only
74

75
76 }
77
78 /*
79  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
80  * All rights reserved.
81  *
82  * Redistribution and use in source and binary forms, with or without
83  * modification, are permitted provided that the following conditions
84  * are met:
85  * 1. Redistributions of source code must retain the above copyright
86  * notice, this list of conditions and the following disclaimer.
87  * 2. Redistributions in binary form must reproduce the above copyright
88  * notice, this list of conditions and the following disclaimer in the
89  * documentation and/or other materials provided with the distribution.
90  * 3. The name of the author may not be used to endorse or promote products
91  * derived from this software without specific prior written permission.
92  *
93  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
94  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
95  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
96  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
97  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
99  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
100  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
101  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
102  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103  */

104
Popular Tags