KickJava   Java API By Example, From Geeks To Geeks.

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


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

45 public class EnumeratedClassImpl
46     extends OntClassImpl
47     implements EnumeratedClass
48 {
49     // Constants
50
//////////////////////////////////
51

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

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

60     public static Implementation factory = new Implementation() {
61         public EnhNode wrap( Node n, EnhGraph eg ) {
62             if (canWrap( n, eg )) {
63                 return new EnumeratedClassImpl( n, eg );
64             }
65             else {
66                 throw new ConversionException( "Cannot convert node " + n + " to EnumeratedClass");
67             }
68         }
69             
70         public boolean canWrap( Node node, EnhGraph eg ) {
71             // node will support being an EnumeratedClass facet if it has rdf:type owl:Class and an owl:oneOf statement (or equivalents)
72
Profile profile = (eg instanceof OntModel) ? ((OntModel) eg).getProfile() : null;
73             return (profile != null) &&
74                    profile.isSupported( node, eg, OntClass.class ) &&
75                    eg.asGraph().contains( node, profile.ONE_OF().asNode(), Node.ANY );
76         }
77     };
78
79
80     // Instance variables
81
//////////////////////////////////
82

83     // Constructors
84
//////////////////////////////////
85

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

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

102     // oneOf
103

104     /**
105      * <p>Assert that this class is exactly the enumeration of the given individuals. Any existing
106      * statements for <code>oneOf</code> will be removed.</p>
107      * @param en A list of individuals that defines the class extension for this class
108      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
109      */

110     public void setOneOf( RDFList en ) {
111         setPropertyValue( getProfile().ONE_OF(), "ONE_OF", en );
112     }
113
114     /**
115      * <p>Add an individual to the enumeration that defines the class extension of this class.</p>
116      * @param res An individual to add to the enumeration
117      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
118      */

119     public void addOneOf( Resource res ) {
120         addListPropertyValue( getProfile().ONE_OF(), "ONE_OF", res );
121     }
122
123     /**
124      * <p>Add each individual from the given iteratation to the
125      * enumeration that defines the class extension of this class.</p>
126      * @param individuals An iterator over individuals
127      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
128      */

129     public void addOneOf( Iterator JavaDoc individuals ) {
130         while( individuals.hasNext() ) {
131             addOneOf( (Resource) individuals.next() );
132         }
133     }
134
135     /**
136      * <p>Answer a list of individuals that defines the extension of this class.</p>
137      * @return A list of individuals that is the class extension
138      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
139      */

140     public RDFList getOneOf() {
141         return (RDFList) objectAs( getProfile().ONE_OF(), "ONE_OF", RDFList.class );
142     }
143
144     /**
145      * <p>Answer an iterator over all of the individuals that are declared to be the class extension for
146      * this class. Each element of the iterator will be an {@link OntResource}.</p>
147      * @return An iterator over the individuals in the class extension
148      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
149      */

150     public ExtendedIterator listOneOf() {
151         return getOneOf().iterator().mapWith( new AsMapper( OntResource.class ) );
152     }
153
154     /**
155      * <p>Answer true if the given individual is one of the enumerated individuals in the class extension
156      * of this class.</p>
157      * @param res An individual to test
158      * @return True if the given individual is in the class extension for this class.
159      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
160      */

161     public boolean hasOneOf( Resource res ) {
162         return getOneOf().contains( res );
163     }
164     
165     /**
166      * <p>Remove the statement that this enumeration includes <code>res</code> among its members. If this statement
167      * is not true of the current model, nothing happens.</p>
168      * @param res A resource that may be declared to be part of this enumeration, and which is
169      * no longer one of the enumeration values.
170      */

171     public void removeOneOf( Resource res ) {
172         setOneOf( getOneOf().remove( res ) );
173     }
174     
175
176
177     // Internal implementation methods
178
//////////////////////////////////
179

180     //==============================================================================
181
// Inner class definitions
182
//==============================================================================
183

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

216
217
218
Popular Tags