KickJava   Java API By Example, From Geeks To Geeks.

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


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 31-Mar-2003
9  * Filename $RCSfile: IndividualImpl.java,v $
10  * Revision $Revision: 1.12 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:06:23 $
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.ontology.*;
28 import com.hp.hpl.jena.rdf.model.*;
29 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
30 import com.hp.hpl.jena.enhanced.*;
31 import com.hp.hpl.jena.graph.*;
32
33
34 /**
35  * <p>
36  * Implementation for the ontology abstraction representing ontology class descriptions.
37  * </p>
38  *
39  * @author Ian Dickinson, HP Labs
40  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
41  * @version CVS $Id: IndividualImpl.java,v 1.12 2005/02/21 12:06:23 andy_seaborne Exp $
42  */

43 public class IndividualImpl
44     extends OntResourceImpl
45     implements Individual
46 {
47     // Constants
48
//////////////////////////////////
49

50     // Static variables
51
//////////////////////////////////
52

53     /**
54      * A factory for generating Individual facets from nodes in enhanced graphs.
55      * Note: should not be invoked directly by user code: use
56      * {@link com.hp.hpl.jena.rdf.model.RDFNode#as as()} instead.
57      */

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

82     // Constructors
83
//////////////////////////////////
84

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

93     public IndividualImpl( Node n, EnhGraph g ) {
94         super( n, g );
95     }
96
97
98     // External signature methods
99
//////////////////////////////////
100

101     /**
102      * <p>Assert equivalence between the given individual and this individual. Any existing
103      * statements for <code>sameIndividualAs</code> will be removed.</p>
104      * <p>Note that <code>sameAs</code> and <code>sameIndividualAs</code> are aliases.</p>
105      * @param res The resource that declared to be the same as this individual
106      * @exception OntProfileException If the sameIndividualAs property is not supported in the current language profile.
107      */

108     public void setSameIndividualAs( Resource res ) {
109         setPropertyValue( getProfile().SAME_INDIVIDUAL_AS(), "SAME_INDIVIDUAL_AS", res );
110     }
111
112     /**
113      * <p>Add an individual that is declared to be equivalent to this individual.</p>
114      * <p>Note that <code>sameAs</code> and <code>sameIndividualAs</code> are aliases.</p>
115      * @param res A resource that declared to be the same as this individual
116      * @exception OntProfileException If the sameIndividualAs property is not supported in the current language profile.
117      */

118     public void addSameIndividualAs( Resource res ) {
119         addPropertyValue( getProfile().SAME_INDIVIDUAL_AS(), "SAME_INDIVIDUAL_AS", res );
120     }
121
122     /**
123      * <p>Answer a resource that is declared to be the same as this individual. If there are
124      * more than one such resource, an arbitrary selection is made.</p>
125      * <p>Note that <code>sameAs</code> and <code>sameIndividualAs</code> are aliases.</p>
126      * @return res An ont resource that declared to be the same as this individual
127      * @exception OntProfileException If the sameIndividualAs property is not supported in the current language profile.
128      */

129     public OntResource getSameIndividualAs() {
130         return objectAsResource( getProfile().SAME_INDIVIDUAL_AS(), "SAME_INDIVIDUAL_AS" );
131     }
132
133     /**
134      * <p>Answer an iterator over all of the resources that are declared to be equivalent to
135      * this individual. Each elemeent of the iterator will be an {@link OntResource}.</p>
136      * <p>Note that <code>sameAs</code> and <code>sameIndividualAs</code> are aliases.</p>
137      * @return An iterator over the resources equivalent to this individual.
138      * @exception OntProfileException If the sameIndividualAs property is not supported in the current language profile.
139      */

140     public ExtendedIterator listSameIndividualAs() {
141         return listAs( getProfile().SAME_INDIVIDUAL_AS(), "SAME_INDIVIDUAL_AS", OntResource.class );
142     }
143
144     /**
145      * <p>Answer true if this individual is the same as the given resource.</p>
146      * @param res A resource to test against
147      * @return True if the resources are declared the same via a <code>sameIndividualAs</code> statement.
148      */

149     public boolean isSameIndividualAs( Resource res ) {
150         return hasPropertyValue( getProfile().SAME_INDIVIDUAL_AS(), "SAME_INDIVIDUAL_AS", res );
151     }
152     
153     /**
154      * <p>Remove the statement that this individual is the same as the given individual. If this statement
155      * is not true of the current model, nothing happens.</p>
156      * @param res A resource that may be declared to be the sameIndividualAs this resource
157      */

158     public void removeSameIndividualAs( Resource res ) {
159         removePropertyValue( getProfile().SAME_INDIVIDUAL_AS(), "SAME_INDIVIDUAL_AS", res );
160     }
161     
162      
163     // Internal implementation methods
164
//////////////////////////////////
165

166     //==============================================================================
167
// Inner class definitions
168
//==============================================================================
169

170 }
171
172
173 /*
174     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
175     All rights reserved.
176
177     Redistribution and use in source and binary forms, with or without
178     modification, are permitted provided that the following conditions
179     are met:
180
181     1. Redistributions of source code must retain the above copyright
182        notice, this list of conditions and the following disclaimer.
183
184     2. Redistributions in binary form must reproduce the above copyright
185        notice, this list of conditions and the following disclaimer in the
186        documentation and/or other materials provided with the distribution.
187
188     3. The name of the author may not be used to endorse or promote products
189        derived from this software without specific prior written permission.
190
191     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
192     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
193     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
194     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
195     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
196     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
197     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
198     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
199     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
200     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
201 */

202
203
Popular Tags