KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > ontology > impl > OntologyImpl


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email Ian.Dickinson@hp.com
6  * Package Jena 2
7  * Web http://sourceforge.net/projects/jena/
8  * Created 25-Mar-2003
9  * Filename $RCSfile: OntologyImpl.java,v $
10  * Revision $Revision: 1.12 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:06:52 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * (see footer for full conditions)
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.ontology.impl;
23
24
25 // Imports
26
///////////////
27
import com.hp.hpl.jena.enhanced.*;
28 import com.hp.hpl.jena.graph.Node;
29 import com.hp.hpl.jena.ontology.*;
30 import com.hp.hpl.jena.rdf.model.*;
31 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
32
33
34 /**
35  * <p>
36  * Implementation of the Ontology interface, encapsulating nodes that hold the
37  * meta-data about whole ontologies.
38  * </p>
39  *
40  * @author Ian Dickinson, HP Labs
41  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
42  * @version CVS $Id: OntologyImpl.java,v 1.12 2005/02/21 12:06:52 andy_seaborne Exp $
43  */

44 public class OntologyImpl
45     extends OntResourceImpl
46     implements Ontology
47 {
48     // Constants
49
//////////////////////////////////
50

51
52     // Static variables
53
//////////////////////////////////
54

55     /**
56      * A factory for generating Ontology facets from nodes in enhanced graphs.
57      */

58     public static Implementation factory = new Implementation() {
59         public EnhNode wrap( Node n, EnhGraph eg ) {
60             if (canWrap( n, eg )) {
61                 return new OntologyImpl( n, eg );
62             }
63             else {
64                 throw new ConversionException( "Cannot convert node " + n + " to Ontology");
65             }
66         }
67             
68         public boolean canWrap( Node node, EnhGraph eg ) {
69             // node will support being an Ontology facet if it has rdf:type owl:Ontology or equivalent
70
Profile profile = (eg instanceof OntModel) ? ((OntModel) eg).getProfile() : null;
71             return (profile != null) && profile.isSupported( node, eg, Ontology.class );
72         }
73     };
74
75
76
77     // Instance variables
78
//////////////////////////////////
79

80     // Constructors
81
//////////////////////////////////
82

83     /**
84      * <p>
85      * Construct an ontology metadata node represented by the given node in the given graph.
86      * </p>
87      *
88      * @param n The node that represents the resource
89      * @param g The enh graph that contains n
90      */

91     public OntologyImpl( Node n, EnhGraph g ) {
92         super( n, g );
93     }
94
95
96     // External signature methods
97
//////////////////////////////////
98

99     // imports
100

101     /**
102      * <p>Assert that this ontology imports only the given ontology. Any existing
103      * statements for <code>sameAs</code> will be removed.</p>
104      * @param res Represents a resource that this ontology imports.
105      * @exception OntProfileException If the {@link Profile#IMPORTS()()} property is not supported in the current language profile.
106      */

107     public void setImport( Resource res ) {
108         setPropertyValue( getProfile().IMPORTS(), "IMPORTS", res );
109     }
110
111     /**
112      * <p>Add a resource representing an ontology that this ontology
113      * (strictly, the ontology reprsented by this node) imports.</p>
114      * @param res Represents a resource that this ontology imports.
115      * @exception OntProfileException If the {@link Profile#IMPORTS()()} property is not supported in the current language profile.
116      */

117     public void addImport( Resource res ) {
118         addPropertyValue( getProfile().IMPORTS(), "IMPORTS", res );
119     }
120
121     /**
122      * <p>Answer a resource that represents an ontology imported by this ontology. If there is
123      * more than one such resource, an arbitrary selection is made.</p>
124      * @return An ont resource representing a resource that this ontology imports
125      * @exception OntProfileException If the {@link Profile#IMPORTS()()} property is not supported in the current language profile.
126      */

127     public OntResource getImport() {
128         return objectAsResource( getProfile().IMPORTS(), "IMPORTS" );
129     }
130
131     /**
132      * <p>Answer an iterator over all of the resources representing ontologies imported by this ontology.
133      * Each elemeent of the iterator will be an {@link OntResource}.</p>
134      * @return An iterator over the ontology import resources
135      * @exception OntProfileException If the {@link Profile#IMPORTS()()} property is not supported in the current language profile.
136      */

137     public ExtendedIterator listImports() {
138         return listAs( getProfile().IMPORTS(), "IMPORTS", OntResource.class );
139     }
140
141     /**
142      * <p>Answer true if this ontology (the ontology represented by this
143      * resource) imports the given resource.</p>
144      * @param res A resource to test against
145      * @return True if this ontology imports the ontology represented by <code>res</code>
146      */

147     public boolean imports( Resource res ) {
148         return hasPropertyValue( getProfile().IMPORTS(), "IMPORTS", res );
149     }
150     
151     /**
152      * <p>Remove the statement that this ontology imports the ontology represented by the given resource. If this statement
153      * is not true of the current model, nothing happens.</p>
154      * @param res A resource that represents an ontology that is no longer to be imported
155      */

156     public void removeImport( Resource res ) {
157         removePropertyValue( getProfile().IMPORTS(), "IMPORTS", res );
158     }
159     
160
161     // backwardCompatibleWith
162

163     /**
164      * <p>Assert that this ontology is backward compatible with the given ontology. Any existing
165      * statements for <code>sameAs</code> will be removed.</p>
166      * @param res Represents a resource that this ontology is compatible with.
167      * @exception OntProfileException If the {@link Profile#BACKWARD_COMPATIBLE_WITH} property is not supported in the current language profile.
168      */

169     public void setBackwardCompatibleWith( Resource res ) {
170         setPropertyValue( getProfile().BACKWARD_COMPATIBLE_WITH(), "BACKWARD_COMPATIBLE_WITH", res );
171     }
172
173     /**
174      * <p>Add a resource representing an ontology that this ontology
175      * (strictly, the ontology reprsented by this node) is backwards compatible with.</p>
176      * @param res Represents a resource that this ontology is compatible with.
177      * @exception OntProfileException If the {@link Profile#BACKWARD_COMPATIBLE_WITH} property is not supported in the current language profile.
178      */

179     public void addBackwardCompatibleWith( Resource res ) {
180         addPropertyValue( getProfile().BACKWARD_COMPATIBLE_WITH(), "BACKWARD_COMPATIBLE_WITH", res );
181     }
182
183     /**
184      * <p>Answer a resource that represents an ontology that is backwards compatible with this ontology. If there is
185      * more than one such resource, an arbitrary selection is made.</p>
186      * @return An ont resource representing an ontology that this ontology is compatible with
187      * @exception OntProfileException If the {@link Profile#BACKWARD_COMPATIBLE_WITH} property is not supported in the current language profile.
188      */

189     public OntResource getBackwardCompatibleWith() {
190         return objectAsResource( getProfile().BACKWARD_COMPATIBLE_WITH(), "BACKWARD_COMPATIBLE_WITH" );
191     }
192
193     /**
194      * <p>Answer an iterator over all of the resources representing
195      * ontologies that this ontology is backwards compatible with.
196      * Each element of the iterator will be an {@link OntResource}.</p>
197      * @return An iterator over the ontology resources compatible with this ontology
198      * @exception OntProfileException If the {@link Profile#BACKWARD_COMPATIBLE_WITH} property is not supported in the current language profile.
199      */

200     public ExtendedIterator listBackwardCompatibleWith() {
201         return listAs( getProfile().BACKWARD_COMPATIBLE_WITH(), "BACKWARD_COMPATIBLE_WITH", OntResource.class );
202     }
203
204     /**
205      * <p>Answer true if this ontology (the ontology represented by this
206      * resource) is backward compatible with the given resource.</p>
207      * @param res A resource to test against
208      * @return True if this ontology is compatible with the ontology represented by <code>res</code>
209      */

210     public boolean isBackwardCompatibleWith( Resource res ) {
211         return hasPropertyValue( getProfile().BACKWARD_COMPATIBLE_WITH(), "BACKWARD_COMPATIBLE_WITH", res );
212     }
213     
214     /**
215      * <p>Remove the statement that this ontology is backwards compatible with
216      * the ontology represented by the given resource. If this statement
217      * is not true of the current model, nothing happens.</p>
218      * @param res A resource that represents an ontology that is no longer to be imported
219      */

220     public void removeBackwardCompatibleWith( Resource res ) {
221         removePropertyValue( getProfile().BACKWARD_COMPATIBLE_WITH(), "BACKWARD_COMPATIBLE_WITH", res );
222     }
223     
224
225     // priorVersion
226

227     /**
228      * <p>Assert that this ontology is a new version of the given ontology. Any existing
229      * statements for <code>priorVersion</code> will be removed.</p>
230      * @param res Represents a resource that this ontology supercedes.
231      * @exception OntProfileException If the {@link Profile#PRIOR_VERSION} property is not supported in the current language profile.
232      */

233     public void setPriorVersion( Resource res ) {
234         setPropertyValue( getProfile().PRIOR_VERSION(), "PRIOR_VERSION", res );
235     }
236
237     /**
238      * <p>Add a resource representing an ontology that this ontology
239      * (strictly, the ontology reprsented by this node) supercedes.</p>
240      * @param res Represents a resource that this ontology supercedes.
241      * @exception OntProfileException If the {@link Profile#PRIOR_VERSION} property is not supported in the current language profile.
242      */

243     public void addPriorVersion( Resource res ) {
244         addPropertyValue( getProfile().PRIOR_VERSION(), "PRIOR_VERSION", res );
245     }
246
247     /**
248      * <p>Answer a resource that represents an ontology that is superceded by this ontology. If there is
249      * more than one such resource, an arbitrary selection is made.</p>
250      * @return An ont resource representing an ontology that this ontology supercedes
251      * @exception OntProfileException If the {@link Profile#PRIOR_VERSION} property is not supported in the current language profile.
252      */

253     public OntResource getPriorVersion() {
254         return objectAsResource( getProfile().PRIOR_VERSION(), "PRIOR_VERSION" );
255     }
256
257     /**
258      * <p>Answer an iterator over all of the resources representing
259      * ontologies that this ontology supercedes.
260      * Each element of the iterator will be an {@link OntResource}.</p>
261      * @return An iterator over the ontology resources superceded by this ontology
262      * @exception OntProfileException If the {@link Profile#PRIOR_VERSION} property is not supported in the current language profile.
263      */

264     public ExtendedIterator listPriorVersion() {
265         return listAs( getProfile().PRIOR_VERSION(), "PRIOR_VERSION", OntResource.class );
266     }
267
268     /**
269      * <p>Answer true if this ontology (the ontology represented by this
270      * resource) supercedes the given resource.</p>
271      * @param res A resource to test against
272      * @return True if this ontology supercedes the ontology represented by <code>res</code>
273      */

274     public boolean hasPriorVersion( Resource res ) {
275         return hasPropertyValue( getProfile().PRIOR_VERSION(), "PRIOR_VERSION", res );
276     }
277     
278     /**
279      * <p>Remove the statement that the given ontology is a prior version of this ontology. If this statement
280      * is not true of the current model, nothing happens.</p>
281      * @param res A resource that represents an ontology that is no longer a prior version of this ontology
282      */

283     public void removePriorVersion( Resource res ) {
284         removePropertyValue( getProfile().PRIOR_VERSION(), "PRIOR_VERSION", res );
285     }
286     
287
288     // incompatibleWith
289

290     /**
291      * <p>Assert that this ontology is incompatible with the given ontology. Any existing
292      * statements for <code>incompatibleWith</code> will be removed.</p>
293      * @param res Represents a resource that this ontology is incompatible with.
294      * @exception OntProfileException If the {@link Profile#INCOMPATIBLE_WITH} property is not supported in the current language profile.
295      */

296     public void setIncompatibleWith( Resource res ) {
297         setPropertyValue( getProfile().INCOMPATIBLE_WITH(), "INCOMPATIBLE_WITH", res );
298     }
299
300     /**
301      * <p>Add a resource representing an ontology that this ontology
302      * (strictly, the ontology reprsented by this node) is incompatible with.</p>
303      * @param res Represents a resource that this ontology is incompatible with.
304      * @exception OntProfileException If the {@link Profile#INCOMPATIBLE_WITH} property is not supported in the current language profile.
305      */

306     public void addIncompatibleWith( Resource res ) {
307         addPropertyValue( getProfile().INCOMPATIBLE_WITH(), "INCOMPATIBLE_WITH", res );
308     }
309
310     /**
311      * <p>Answer a resource that represents an ontology that is is incompatible with this ontology. If there is
312      * more than one such resource, an arbitrary selection is made.</p>
313      * @return An ont resource representing an ontology that this ontology is incompatible with
314      * @exception OntProfileException If the {@link Profile#INCOMPATIBLE_WITH} property is not supported in the current language profile.
315      */

316     public OntResource getIncompatibleWith() {
317         return objectAsResource( getProfile().INCOMPATIBLE_WITH(), "INCOMPATIBLE_WITH" );
318     }
319
320     /**
321      * <p>Answer an iterator over all of the resources representing
322      * ontologies that this ontology is incompatible with.
323      * Each element of the iterator will be an {@link OntResource}.</p>
324      * @return An iterator over the ontology resources that this ontology is incompatible with
325      * @exception OntProfileException If the {@link Profile#INCOMPATIBLE_WITH} property is not supported in the current language profile.
326      */

327     public ExtendedIterator listIncompatibleWith() {
328         return listAs( getProfile().INCOMPATIBLE_WITH(), "INCOMPATIBLE_WITH", OntResource.class );
329     }
330
331     /**
332      * <p>Answer true if this ontology (the ontology represented by this
333      * resource) is incompatible with the given resource.</p>
334      * @param res A resource to test against
335      * @return True if this ontology is incompatible with the ontology represented by <code>res</code>
336      */

337     public boolean isIncompatibleWith( Resource res ) {
338         return hasPropertyValue( getProfile().INCOMPATIBLE_WITH(), "INCOMPATIBLE_WITH", res );
339     }
340     
341     /**
342      * <p>Remove the statement that the given ontology is incompatible with this ontology. If this statement
343      * is not true of the current model, nothing happens.</p>
344      * @param res A resource that represents an ontology that is no longer incompatible with this ontology
345      */

346     public void removeIncompatibleWith( Resource res ) {
347         removePropertyValue( getProfile().INCOMPATIBLE_WITH(), "INCOMPATIBLE_WITH", res );
348     }
349     
350     
351     // Internal implementation methods
352
//////////////////////////////////
353

354     //==============================================================================
355
// Inner class definitions
356
//==============================================================================
357

358 }
359
360
361 /*
362     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
363     All rights reserved.
364
365     Redistribution and use in source and binary forms, with or without
366     modification, are permitted provided that the following conditions
367     are met:
368
369     1. Redistributions of source code must retain the above copyright
370        notice, this list of conditions and the following disclaimer.
371
372     2. Redistributions in binary form must reproduce the above copyright
373        notice, this list of conditions and the following disclaimer in the
374        documentation and/or other materials provided with the distribution.
375
376     3. The name of the author may not be used to endorse or promote products
377        derived from this software without specific prior written permission.
378
379     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
380     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
381     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
382     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
383     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
384     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
385     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
386     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
387     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
388     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
389 */

390
Popular Tags