KickJava   Java API By Example, From Geeks To Geeks.

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


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 19-Aug-2003
9  * Filename $RCSfile: DataRangeImpl.java,v $
10  * Revision $Revision: 1.5 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:06:18 $
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.*;
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  * Default implementation of the interface that defines a closed enumeration
39  * of concrete values for the range of a property.
40  * </p>
41  *
42  * @author Ian Dickinson, HP Labs
43  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
44  * @version CVS $Id: DataRangeImpl.java,v 1.5 2005/02/21 12:06:18 andy_seaborne Exp $
45  */

46 public class DataRangeImpl
47     extends OntResourceImpl
48     implements DataRange
49 {
50     // Constants
51
//////////////////////////////////
52

53     // Static variables
54
//////////////////////////////////
55

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

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

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

85     /**
86      * <p>
87      * Construct a data range node 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 DataRangeImpl( Node n, EnhGraph g ) {
94         super( n, g );
95     }
96
97
98     // External signature methods
99
//////////////////////////////////
100

101     // External signature methods
102
//////////////////////////////////
103

104     // oneOf
105

106     /**
107      * <p>Assert that this data range is exactly the enumeration of the given individuals. Any existing
108      * statements for <code>oneOf</code> will be removed.</p>
109      * @param enum A list of literals that defines the permissible values for this datarange
110      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
111      */

112     public void setOneOf( RDFList en ) {
113         setPropertyValue( getProfile().ONE_OF(), "ONE_OF", en );
114     }
115
116     /**
117      * <p>Add a literal to the enumeration that defines the permissible values of this class.</p>
118      * @param lit A literal to add to the enumeration
119      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
120      */

121     public void addOneOf( Literal lit ) {
122         addListPropertyValue( getProfile().ONE_OF(), "ONE_OF", lit );
123     }
124
125     /**
126      * <p>Add each literal from the given iteratation to the
127      * enumeration that defines the permissible values of this datarange.</p>
128      * @param literals An iterator over literals
129      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
130      */

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

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

152     public ExtendedIterator listOneOf() {
153         return getOneOf().iterator().mapWith( new AsMapper( Literal.class ) );
154     }
155
156     /**
157      * <p>Answer true if the given literal is one of the enumerated literals that are the permissible values
158      * of this datarange.</p>
159      * @param lit A literal to test
160      * @return True if the given literal is in the permissible values for this class.
161      * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
162      */

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

173     public void removeOneOf( Literal lit ) {
174         setOneOf( getOneOf().remove( lit ) );
175     }
176     
177
178     // Internal implementation methods
179
//////////////////////////////////
180

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

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

217
218
Popular Tags