001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email ian.dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created 19-Aug-2003
009: * Filename $RCSfile: DataRangeImpl.java,v $
010: * Revision $Revision: 1.9 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:08:03 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * (see footer for full conditions)
018: *****************************************************************************/package com.hp.hpl.jena.ontology.impl;
019:
020: // Imports
021: ///////////////
022: import java.util.Iterator;
023:
024: import com.hp.hpl.jena.enhanced.*;
025: import com.hp.hpl.jena.graph.*;
026: import com.hp.hpl.jena.ontology.*;
027: import com.hp.hpl.jena.rdf.model.*;
028: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
029:
030: /**
031: * <p>
032: * Default implementation of the interface that defines a closed enumeration
033: * of concrete values for the range of a property.
034: * </p>
035: *
036: * @author Ian Dickinson, HP Labs
037: * (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
038: * @version CVS $Id: DataRangeImpl.java,v 1.9 2008/01/02 12:08:03 andy_seaborne Exp $
039: */
040: public class DataRangeImpl extends OntResourceImpl implements DataRange {
041: // Constants
042: //////////////////////////////////
043:
044: // Static variables
045: //////////////////////////////////
046:
047: /**
048: * A factory for generating DataRange facets from nodes in enhanced graphs.
049: * Note: should not be invoked directly by user code: use
050: * {@link com.hp.hpl.jena.rdf.model.RDFNode#as as()} instead.
051: */
052: public static Implementation factory = new Implementation() {
053: public EnhNode wrap(Node n, EnhGraph eg) {
054: if (canWrap(n, eg)) {
055: return new DataRangeImpl(n, eg);
056: } else {
057: throw new ConversionException("Cannot convert node "
058: + n + " to DataRange");
059: }
060: }
061:
062: public boolean canWrap(Node node, EnhGraph eg) {
063: // node will support being an DataRange facet if it has rdf:type owl:Datarange and is a bNode
064: Profile profile = (eg instanceof OntModel) ? ((OntModel) eg)
065: .getProfile()
066: : null;
067: return (profile != null)
068: && profile.isSupported(node, eg, DataRange.class);
069: }
070: };
071:
072: // Instance variables
073: //////////////////////////////////
074:
075: // Constructors
076: //////////////////////////////////
077:
078: /**
079: * <p>
080: * Construct a data range node represented by the given node in the given graph.
081: * </p>
082: *
083: * @param n The node that represents the resource
084: * @param g The enh graph that contains n
085: */
086: public DataRangeImpl(Node n, EnhGraph g) {
087: super (n, g);
088: }
089:
090: // External signature methods
091: //////////////////////////////////
092:
093: // External signature methods
094: //////////////////////////////////
095:
096: // oneOf
097:
098: /**
099: * <p>Assert that this data range is exactly the enumeration of the given individuals. Any existing
100: * statements for <code>oneOf</code> will be removed.</p>
101: * @param en A list of literals that defines the permissible values for this datarange
102: * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
103: */
104: public void setOneOf(RDFList en) {
105: setPropertyValue(getProfile().ONE_OF(), "ONE_OF", en);
106: }
107:
108: /**
109: * <p>Add a literal to the enumeration that defines the permissible values of this class.</p>
110: * @param lit A literal to add to the enumeration
111: * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
112: */
113: public void addOneOf(Literal lit) {
114: addListPropertyValue(getProfile().ONE_OF(), "ONE_OF", lit);
115: }
116:
117: /**
118: * <p>Add each literal from the given iteratation to the
119: * enumeration that defines the permissible values of this datarange.</p>
120: * @param literals An iterator over literals
121: * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
122: */
123: public void addOneOf(Iterator literals) {
124: while (literals.hasNext()) {
125: addOneOf((Literal) literals.next());
126: }
127: }
128:
129: /**
130: * <p>Answer a list of literals that defines the extension of this datarange.</p>
131: * @return A list of literals that is the permissible values
132: * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
133: */
134: public RDFList getOneOf() {
135: return (RDFList) objectAs(getProfile().ONE_OF(), "ONE_OF",
136: RDFList.class);
137: }
138:
139: /**
140: * <p>Answer an iterator over all of the literals that are declared to be the permissible values for
141: * this class. Each element of the iterator will be an {@link Literal}.</p>
142: * @return An iterator over the literals that are the permissible values
143: * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
144: */
145: public ExtendedIterator listOneOf() {
146: return getOneOf().iterator().mapWith(
147: new AsMapper(Literal.class));
148: }
149:
150: /**
151: * <p>Answer true if the given literal is one of the enumerated literals that are the permissible values
152: * of this datarange.</p>
153: * @param lit A literal to test
154: * @return True if the given literal is in the permissible values for this class.
155: * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile.
156: */
157: public boolean hasOneOf(Literal lit) {
158: return getOneOf().contains(lit);
159: }
160:
161: /**
162: * <p>Remove the statement that this enumeration includes <code>lit</code> among its members. If this statement
163: * is not true of the current model, nothing happens.</p>
164: * @param lit A literal that may be declared to be part of this data range, and which is
165: * no longer to be one of the data range values.
166: */
167: public void removeOneOf(Literal lit) {
168: setOneOf(getOneOf().remove(lit));
169: }
170:
171: // Internal implementation methods
172: //////////////////////////////////
173:
174: //==============================================================================
175: // Inner class definitions
176: //==============================================================================
177:
178: }
179:
180: /*
181: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
182: All rights reserved.
183:
184: Redistribution and use in source and binary forms, with or without
185: modification, are permitted provided that the following conditions
186: are met:
187:
188: 1. Redistributions of source code must retain the above copyright
189: notice, this list of conditions and the following disclaimer.
190:
191: 2. Redistributions in binary form must reproduce the above copyright
192: notice, this list of conditions and the following disclaimer in the
193: documentation and/or other materials provided with the distribution.
194:
195: 3. The name of the author may not be used to endorse or promote products
196: derived from this software without specific prior written permission.
197:
198: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
199: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
200: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
201: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
202: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
203: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
204: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
205: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
206: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
207: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
208: */
|