KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdql > Slot


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

5
6 /** Internal class - used by the old, external-to-model query system.
7  *
8  * @author Andy Seaborne
9  * @version $Id: Slot.java,v 1.8 2005/02/21 12:15:27 andy_seaborne Exp $
10  */

11
12 package com.hp.hpl.jena.rdql;
13
14 // A slot holds one of a value (A typed RDF value), a resource, a property, or a variable.
15
import com.hp.hpl.jena.rdf.model.* ;
16
17 class Slot
18 {
19     Value value ;
20     Var variable ;
21     // Can we just use an RDFNode here?
22
Resource resource ;
23     Property property ;
24     Literal literal ;
25
26
27     private void unset()
28     {
29         value = null ;
30         variable = null ;
31         resource = null ;
32         property = null ;
33         literal = null ;
34     }
35
36     public Slot()
37     {
38         unset() ;
39     }
40
41     public Slot(Slot slot)
42     {
43         value = slot.value ;
44         variable = slot.variable ;
45         property = slot.property ;
46         resource = slot.resource ;
47     }
48
49     public void set(Value v)
50     {
51         unset() ;
52         value = v ;
53     }
54
55     public void set(Var v)
56     {
57         unset() ;
58         variable = v ;
59     }
60
61     public void set(Resource r)
62     {
63         unset() ;
64         resource = r ;
65     }
66
67     public void set(Property p)
68     {
69         unset() ;
70         property = p;
71     }
72
73     public void set(Literal l)
74     {
75         unset() ;
76         literal = l ;
77     }
78
79     public boolean isValue() { return value != null ; }
80     public boolean isVar() { return variable != null ; }
81     public boolean isResource() { return resource != null ; }
82     public boolean isProperty() { return property != null ; }
83     public boolean isLiteral () { return literal != null ; }
84
85     public Value getValue() { return value ; }
86     public Var getVar() { return variable ; }
87     public Resource getResource() { return resource ; }
88     public Property getProperty() { return property ; }
89     public Literal getLiteral() { return literal ; }
90
91     public String JavaDoc getVarName()
92     {
93         if ( variable == null )
94             return null ;
95         return variable.getVarName() ;
96     }
97
98     // This is a printable/parseable value - it is not called
99
// during filter evaluation so we can quote things.
100
public String JavaDoc toString()
101     {
102         if ( value != null )
103             return value.asInfixString() ;
104         if ( variable != null )
105             return variable.toString() ;
106         if ( property != null )
107             return "<"+property.toString()+">" ;
108         if ( resource != null )
109             return "<"+resource.toString()+">" ;
110         if ( literal != null )
111         {
112             String JavaDoc s = literal.toString() ;
113             if ( literal.getLanguage().equals("") && literal.getDatatype() == null )
114                 return s ;
115             
116             StringBuffer JavaDoc sb = new StringBuffer JavaDoc(s) ;
117             if ( !literal.getLanguage().equals("") )
118                 sb.append("@").append(literal.getLanguage()) ;
119             if ( literal.getDatatype() != null)
120                 sb.append("^^").append(literal.getDatatypeURI()) ;
121             return sb.toString() ;
122         }
123
124         return "slot:unset" ;
125     }
126 }
127
128 /*
129  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
130  * All rights reserved.
131  *
132  * Redistribution and use in source and binary forms, with or without
133  * modification, are permitted provided that the following conditions
134  * are met:
135  * 1. Redistributions of source code must retain the above copyright
136  * notice, this list of conditions and the following disclaimer.
137  * 2. Redistributions in binary form must reproduce the above copyright
138  * notice, this list of conditions and the following disclaimer in the
139  * documentation and/or other materials provided with the distribution.
140  * 3. The name of the author may not be used to endorse or promote products
141  * derived from this software without specific prior written permission.
142  *
143  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
144  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
145  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
146  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
147  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
148  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
149  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
150  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
151  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
152  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
153  */

154
Popular Tags