KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > Resource


1 /*
2  * (c) Copyright 2000, 2001, 2002, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * Resource.java
28  *
29  * Created on 25 July 2000, 13:14
30  */

31
32 package com.hp.hpl.jena.rdf.model;
33
34 import com.hp.hpl.jena.graph.Node;
35
36
37 /** An RDF Resource.
38  *
39  * <p>Resource instances when created are associated with a specific model.
40  * They support a range of methods, such as <CODE>getProperty()</CODE> and
41  * <CODE>addProperty()</CODE> which will access or modify that model. This
42  * enables the programmer to write code in a compact and easy style.</p>
43  *
44  * <p>This interface provides methods supporting typed literals. This means
45  * that methods are provided which will translate a built in type, or an
46  * object to an RDF Literal. This translation is done by invoking the
47  * <CODE>toString()</CODE> method of the object, or its built in equivalent.
48  * The reverse translation is also supported. This is built in for built
49  * in types. Factory objects, provided by the application, are used
50  * for application objects.</p>
51  * <p>This interface provides methods for supporting enhanced resources. An
52  * enhanced resource is a resource to which the application has added
53  * behaviour. RDF containers are examples of enhanced resources built in
54  * to this package. Enhanced resources are supported by encapsulating a
55  * resource created by an implementation in another class which adds
56  * the extra behaviour. Factory objects are used to construct such
57  * enhanced resources.</p>
58  * @author bwm
59  * @version Release='$Name: $' Revision='$Revision: 1.14 $' Date='$Date: 2005/02/21 12:14:23 $'
60  */

61 public interface Resource extends RDFNode {
62       
63     /** Returns an a unique identifier for anonymous resources.
64      *
65      * <p>The id is unique within the scope of a particular implementation. All
66      * models within an implementation will use the same id for the same anonymous
67      * resource.</p>
68      *
69      * <p>This method is undefined if called on resources which are not anonymous
70      * and may raise an exception.</p>
71      * @return A unique id for an anonymous resource.
72      */

73     public AnonId getId() ;
74
75   /**
76     every Resource overlays a Node; fetch that Node.
77   */

78   public Node getNode();
79   
80   /**
81         Answer true iff this Resource is a URI resource with the given URI; otherwise
82         answer false. Using this is preferred to using getURI() and .equals().
83   */

84   public boolean hasURI( String JavaDoc uri );
85   
86   /** Return the URI of the resource, or null if it's a bnode.
87    * @return The URI of the resource, or null if it's a bnode.
88    */

89     public String JavaDoc getURI();
90     
91     /** Returns the namespace associated with this resource.
92      * @return The namespace for this property.
93      */

94   public String JavaDoc getNameSpace();
95   
96     /** Returns the name of this resource within its namespace.
97      * @return The name of this property within its namespace.
98      */

99   public String JavaDoc getLocalName();
100     
101     /** Return a string representation of the resource.
102      *
103      * Returns the URI of the resource unless the resource is anonymous
104      * in which case it returns the id of the resource enclosed in square
105      * brackets.
106      * @return Return a string representation of the resource.
107      * if it is anonymous.
108      */

109     public String JavaDoc toString();
110     
111     /** Determine whether two objects represent the same resource.
112      *
113      * <p>A resource can only be equal to another resource.
114      * If both resources are not anonymous, then they are equal if the URI's are
115      * equal. If both resources are anonymous, they are equal only if there Id's
116      * are the same. If one resource is anonymous and the other is not, then they
117      * are not equal.</p>
118      * @param o The object to be compared.
119      * @return true if and only if both objects are equal
120      */

121     public boolean equals(Object JavaDoc o);
122     /** Determine whether this resource is anonymous.
123      * @return Return true if and only if this resource is anonymous.
124      */

125     public boolean isAnon();
126     
127     /** Get a property value of this resource.
128      *
129      * <p>The model associated with the resource instance is searched for statements
130      * whose subject is this resource and whose predicate is p. If such a statement
131      * is found, it is returned. If several such statements are found, any one may
132      * be returned. If no such statements are found, an exception is thrown.</p>
133      * @param p The property sought.
134      * @return some (this, p, ?O) statement if one exists
135      * @throws PropertyNotFoundException if no such statement found
136      */

137     public Statement getRequiredProperty(Property p) ;
138     
139     /**
140         Answer some statement (this, p, O) in the associated model. If there are several
141         such statements, any one of them may be returned. If no such statements exist,
142         null is returned - in this is differs from getRequiredProperty.
143         @param p the property sought
144         @return a statement (this, p, O), or null if no such statements exist here
145     */

146     public Statement getProperty( Property p );
147     
148     /** List all the values of the property p.
149      *
150      * <p>Returns an iterator over all the statements in the associated model whose
151      * subject is this resource and whose predicate is p.</p>
152      * @param p The predicate sought.
153      * @return An iterator over the statements.
154      */

155     public StmtIterator listProperties(Property p) ;
156     /** Return an iterator over all the properties of this resource.
157      *
158      * <p>The model associated with this resource is search and an iterator is
159      * returned which iterates over all the statements which have this resource
160      * as a subject.</p>
161      * @return An iterator over all the statements about this object.
162      */

163     public StmtIterator listProperties() ;
164     
165     /** Add a property to this resource.
166      *
167      * <p>A statement with this resource as the subject, p as the predicate and o
168      * as the object is added to the model associated with this resource.</p>
169      * <p> o is converted to a string by calling its <CODE>toString()</CODE>
170      * method.</p>
171      * @param p The property to be added.
172      * @param o The value of the property to be added.
173      * @return This resource to allow cascading calls.
174      */

175     public Resource addProperty(Property p, boolean o) ;
176     
177     /** Add a property to this resource.
178      *
179      * <p>A statement with this resource as the subject, p as the predicate and o
180      * as the object is added to the model associated with this resource.</p>
181      * <p> o is converted to a string by calling its <CODE>toString()</CODE>
182      * method.</p>
183      * @param p The property to be added.
184      * @param o The value of the property to be added.
185      * @return This resource to allow cascading calls.
186      */

187     public Resource addProperty(Property p, long o) ;
188     
189     /** Add a property to this resource.
190      *
191      * <p>A statement with this resource as the subject, p as the predicate and o
192      * as the object is added to the model associated with this resource.</p>
193      * <p> o is converted to a string by calling its <CODE>toString()</CODE>
194      * method.</p>
195      * @param p The property to be added.
196      * @param o The value of the property to be added.
197      * @return This resource to allow cascading calls.
198      */

199     public Resource addProperty(Property p, char o) ;
200     
201     /** Add a property to this resource.
202      *
203      * <p>A statement with this resource as the subject, p as the predicate and o
204      * as the object is added to the model associated with this resource.</p>
205      * <p> o is converted to a string by calling its <CODE>toString()</CODE>
206      * method.</p>
207      * @param p The property to be added.
208      * @param o The value of the property to be added.
209      * @return This resource to allow cascading calls.
210      */

211     public Resource addProperty(Property p, float o) ;
212     
213     /** Add a property to this resource.
214      *
215      * <p>A statement with this resource as the subject, p as the predicate and o
216      * as the object is added to the model associated with this resource.</p>
217      * <p> o is converted to a string by calling its <CODE>toString()</CODE>
218      * method.</p>
219      * @param p The property to be added.
220      * @param o The value of the property to be added.
221      * @return This resource to allow cascading calls.
222      */

223     public Resource addProperty(Property p, double o) ;
224     
225     /** Add a property to this resource.
226      *
227      * <p>A statement with this resource as the subject, p as the predicate and o
228      * as the object is added to the model associated with this resource.</p>
229      * @param p The property to be added.
230      * @param o The value of the property to be added.
231      * @return This resource to allow cascading calls.
232      */

233     public Resource addProperty(Property p, String JavaDoc o) ;
234     
235     /** Add a property to this resource.
236      *
237      * <p>A statement with this resource as the subject, p as the predicate and o
238      * as the object is added to the model associated with this resource.</p>
239      * @param p The property to be added.
240      * @param o The value of the property to be added.
241      * @param l the language of the property
242      * @return This resource to allow cascading calls.
243      */

244     public Resource addProperty(Property p, String JavaDoc o, String JavaDoc l) ;
245     
246     /** Add a property to this resource.
247      *
248      * <p>A statement with this resource as the subject, p as the predicate and o
249      * as the object is added to the model associated with this resource.</p>
250      * <p> o is converted to a string by calling its <CODE>toString()</CODE>
251      * method.</p>
252      * @param p The property to be added.
253      * @param o The value of the property to be added.
254      * @return This resource to allow cascading calls.
255      */

256     public Resource addProperty(Property p, Object JavaDoc o) ;
257     
258     /** Add a property to this resource.
259      *
260      * <p>A statement with this resource as the subject, p as the predicate and o
261      * as the object is added to the model associated with this resource.</p>
262      * @param p The property to be added.
263      * @param o The value of the property to be added.
264      * @return This resource to allow cascading calls.
265      */

266     public Resource addProperty(Property p, RDFNode o);
267     
268     /** Determine whether this resource has any values for a given property.
269      * @param p The property sought.
270      * @return true if and only if this resource has at least one
271      * value for the property.
272      */

273     public boolean hasProperty(Property p) ;
274     
275     /** Test if this resource has a given property with a given value.
276      * @param p The property sought.
277      * @param o The value of the property sought.
278      * @return true if and only if this resource has property p with
279      * value o.
280      */

281     public boolean hasProperty(Property p, boolean o) ;
282     
283     /** Test if this resource has a given property with a given value.
284      * @param p The property sought.
285      * @param o The value of the property sought.
286      * @return true if and only if this resource has property p with
287      * value o.
288      */

289     public boolean hasProperty(Property p, long o) ;
290     
291     /** Test if this resource has a given property with a given value.
292      * @param p The property sought.
293      * @param o The value of the property sought.
294      * @return true if and only if this resource has property p with
295      * value o.
296      */

297     public boolean hasProperty(Property p, char o) ;
298     
299     /** Test if this resource has a given property with a given value.
300      * @param p The property sought.
301      * @param o The value of the property sought.
302      * @return true if and only if this resource has property p with
303      * value o.
304      */

305     public boolean hasProperty(Property p, float o) ;
306     
307     /** Test if this resource has a given property with a given value.
308      * @param p The property sought.
309      * @param o The value of the property sought.
310      * @return true if and only if this resource has property p with
311      * value o.
312      */

313     public boolean hasProperty(Property p, double o) ;
314     
315     /** Test if this resource has a given property with a given value.
316      * @param p The property sought.
317      * @param o The value of the property sought.
318      * @return true if and only if this resource has property p with
319      * value o.
320      */

321     public boolean hasProperty(Property p, String JavaDoc o) ;
322     
323     /** Test if this resource has a given property with a given value.
324      * @param p The property sought.
325      * @param o The value of the property sought.
326      * @param l The language of the property sought.
327      * @return true if and only if this resource has property p with
328      * value o.
329      */

330     public boolean hasProperty(Property p, String JavaDoc o, String JavaDoc l) ;
331     
332     /** Test if this resource has a given property with a given value.
333      * @param p The property sought.
334      * @param o The value of the property sought.
335      * @return true if and only if this resource has property p with
336      * value o.
337      */

338     public boolean hasProperty(Property p, Object JavaDoc o) ;
339     
340     /** Test if this resource has a given property with a given value.
341      * @param p The property sought.
342      * @param o The value of the property sought.
343      * @return true if and only if this resource has property p with
344      * value o.
345      */

346     public boolean hasProperty(Property p, RDFNode o) ;
347     
348     /** Delete all the properties for this resource from the associated model.
349      * @return This resource to permit cascading.
350      */

351     public Resource removeProperties() ;
352     
353     /**
354         Delete all the statements with predicate <code>p</code> for this resource
355         from its associated model.
356         
357         @param p the property to remove
358         @return this resource, to permit cascading
359     */

360     public Resource removeAll( Property p );
361     
362     /** Begin a transaction in the associated model.
363      * @return This resource to permit cascading.
364      */

365     public Resource begin() ;
366     
367     /** Abort the transaction in the associated model.
368      * @return This resource to permit cascading.
369      */

370     public Resource abort() ;
371     
372     /** Commit the transaction in the associated model.
373      * @return This resource to permit cascading.
374      */

375     public Resource commit() ;
376     
377     /** Return the model associated with this resource.
378      * @return The model associated with this resource.
379      */

380     public Model getModel();
381 }
382
383
Popular Tags