KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > ontology > daml > impl > DAMLPropertyImpl


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email Ian.Dickinson@hp.com
6  * Package Jena
7  * Created 4 Jan 2001
8  * Filename $RCSfile: DAMLPropertyImpl.java,v $
9  * Revision $Revision: 1.9 $
10  * Release status Preview-release $State: Exp $
11  *
12  * Last modified on $Date: 2005/02/21 12:05:28 $
13  * by $Author: andy_seaborne $
14  *
15  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
16  * (see footer for full conditions)
17  *****************************************************************************/

18
19 // Package
20
///////////////
21
package com.hp.hpl.jena.ontology.daml.impl;
22
23
24 // Imports
25
///////////////
26
import java.util.*;
27
28 import com.hp.hpl.jena.enhanced.*;
29 import com.hp.hpl.jena.graph.*;
30 import com.hp.hpl.jena.ontology.*;
31 import com.hp.hpl.jena.ontology.daml.*;
32 import com.hp.hpl.jena.ontology.impl.*;
33 import com.hp.hpl.jena.rdf.model.*;
34 import com.hp.hpl.jena.util.iterator.*;
35 import com.hp.hpl.jena.vocabulary.*;
36
37
38 /**
39  * <p>Encapsulates a property in a DAML ontology. According to the specification,
40  * a daml:Property is an alias for rdf:Property. It also acts as the super-class for
41  * more semantically meaningful property classes: datatype properties and object properties.
42  * The DAML spec also allows any property to be unique (that is, it defines UniqueProperty
43  * as a sub-class of Property), so uniqueness is modelled here as an attribute of a DAMLProperty.</p>
44  *
45  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
46  * @version CVS info: $Id: DAMLPropertyImpl.java,v 1.9 2005/02/21 12:05:28 andy_seaborne Exp $
47  */

48 public class DAMLPropertyImpl
49     extends OntPropertyImpl
50     implements DAMLProperty
51 {
52     // Constants
53
//////////////////////////////////
54

55
56     // Static variables
57
//////////////////////////////////
58

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

64     public static Implementation factory = new Implementation() {
65         public EnhNode wrap( Node n, EnhGraph eg ) {
66             if (canWrap( n, eg )) {
67                 return new DAMLPropertyImpl( n, eg );
68             }
69             else {
70                 throw new ConversionException( "Cannot convert node " + n.toString() + " to DAMLProperty" );
71             }
72         }
73             
74         public boolean canWrap( Node node, EnhGraph eg ) {
75             return hasType( node, eg, DAML_OIL.Property ) ||
76                    hasType( node, eg, DAML_OIL.DatatypeProperty ) ||
77                    hasType( node, eg, DAML_OIL.ObjectProperty );
78         }
79     };
80
81
82     // Instance variables
83
//////////////////////////////////
84

85     /** Vocabulary */
86     private DAMLVocabulary m_vocabulary = VocabularyManager.getDefaultVocabulary();
87     
88     /** Property accessor for domain */
89     private PropertyAccessor m_propDomain = new PropertyAccessorImpl( getVocabulary().domain(), this );
90
91     /** Property accessor for range */
92     private PropertyAccessor m_propRange = new PropertyAccessorImpl( getVocabulary().range(), this );
93
94     /** Property accessor for subPropertyOf */
95     private PropertyAccessor m_propSubPropertyOf = new PropertyAccessorImpl( getVocabulary().subPropertyOf(), this );
96
97     /** Property accessor for samePropertyAs */
98     private PropertyAccessor m_propSamePropertyAs = new PropertyAccessorImpl( getVocabulary().samePropertyAs(), this );
99
100     /** DAMLCommon delegate */
101     private DAMLCommon m_common = null;
102     
103     
104     // Constructors
105
//////////////////////////////////
106

107     /**
108      * <p>
109      * Construct a DAML property represented by the given node in the given graph.
110      * </p>
111      *
112      * @param n The node that represents the resource
113      * @param g The enh graph that contains n
114      */

115     public DAMLPropertyImpl( Node n, EnhGraph g ) {
116         super( n, g );
117         m_common = new DAMLCommonImpl( n, g );
118     }
119
120
121
122     // External signature methods
123
//////////////////////////////////
124

125     // delegate to DAMLCommon what we can
126
/** @deprecated */
127     public void setRDFType( Resource rdfClass, boolean replace ) { m_common.setRDFType( rdfClass, replace ); }
128     public DAMLModel getDAMLModel() { return m_common.getDAMLModel(); }
129     public ExtendedIterator getRDFTypes( boolean complete ) { return m_common.getRDFTypes( complete ); }
130     public DAMLVocabulary getVocabulary() { return m_vocabulary; }
131     public LiteralAccessor prop_label() { return m_common.prop_label(); }
132     public LiteralAccessor prop_comment() { return m_common.prop_comment(); }
133     public PropertyAccessor prop_equivalentTo() { return m_common.prop_equivalentTo(); }
134     public PropertyAccessor prop_type() { return m_common.prop_type(); }
135     
136     /**
137      * <p>Answer an iterator over all of the DAML objects that are equivalent to this
138      * class, which will be the union of <code>daml:equivalentTo</code> and
139      * <code>daml:sameClassAs</code>.</p>
140      *
141      * @return an iterator ranging over every equivalent DAML class
142      */

143     public ExtendedIterator getEquivalentValues() {
144         ConcatenatedIterator i = new ConcatenatedIterator(
145                        // first the iterator over the equivalentTo values
146
m_common.getEquivalentValues(),
147                        // followed by the samePropertyAs values
148
getSameProperties() );
149
150         return UniqueExtendedIterator.create( i ).mapWith( new AsMapper( DAMLProperty.class ) );
151     }
152
153
154     /**
155      * Answer the set of equivalent values to this value, but not including the
156      * value itself. The iterator will range over a set: each element occurs only
157      * once.
158      *
159      * @return An iteration ranging over the set of values that are equivalent to this
160      * value, but not itself.
161      */

162     public ExtendedIterator getEquivalenceSet() {
163         Set s = new HashSet();
164
165         s.add( this );
166         for (Iterator i = getEquivalentValues(); i.hasNext(); s.add( i.next() ) );
167         s.remove( this );
168         
169         return WrappedIterator.create( s.iterator() );
170     }
171
172
173
174
175     /**
176      * Set the flag to indicate that this property is to be considered
177      * unique - that is, it is defined by the DAML class UniqueProperty.
178      *
179      * @param unique True for a unique property
180      */

181     public void setIsUnique( boolean unique ) {
182         if (unique) {
183             // add the unique type to this property
184
addRDFType( getVocabulary().UniqueProperty() );
185         }
186         else {
187             // remove the transitive type from this property
188
removeProperty( RDF.type, getVocabulary().UniqueProperty() );
189         }
190     }
191
192
193     /**
194      * Answer true if this property is to be considered unique, that is
195      * it is characterised by the DAML class UniqueProperty
196      *
197      * @return True if this property is unique
198      */

199     public boolean isUnique() {
200         return hasRDFType( getVocabulary().UniqueProperty() );
201     }
202
203
204     /**
205      * Property accessor for the 'domain' property of a property. This
206      * denotes the class that is the domain of the relation denoted by
207      * the property.
208      *
209      * @return Property accessor for 'domain'.
210      */

211     public PropertyAccessor prop_domain() {
212         return m_propDomain;
213     }
214
215
216     /**
217      * Property accessor for the 'subPropertyOf' property of a property. This
218      * denotes the property that is the super-property of this property
219      *
220      * @return Property accessor for 'subPropertyOf'.
221      */

222     public PropertyAccessor prop_subPropertyOf() {
223         return m_propSubPropertyOf;
224     }
225
226
227     /**
228      * Property accessor for the 'samePropertyAs' property of a property. This
229      * denotes that two properties should be considered equivalent.
230      *
231      * @return Property accessor for 'samePropertyAs'.
232      */

233     public PropertyAccessor prop_samePropertyAs() {
234         return m_propSamePropertyAs;
235     }
236
237
238     /**
239      * Property accessor for the 'range' property of a property. This
240      * denotes the class that is the range of the relation denoted by
241      * the property.
242      *
243      * @return Property accessor for 'range'.
244      */

245     public PropertyAccessor prop_range() {
246         return m_propRange;
247     }
248
249
250     /**
251      * <p>Answer an iterator over all of the DAML properties that are equivalent to this
252      * value under the <code>daml:samePropertyAs</code> relation. Note: only considers
253      * <code>daml:samePropertyAs</code>, for general equivalence, see
254      * {@link #getEquivalentValues}. Note also that the first member of the iteration is
255      * always the DAMLProperty on which the method is invoked: trivially, a property is
256      * a member of the set of properties equivalent to itself. If the caller wants
257      * the set of properties equivalent to this one, not including itself, simply ignore
258      * the first element of the iteration.</p>
259      *
260      * @return an iterator ranging over every equivalent DAML property.
261      */

262     public ExtendedIterator getSameProperties() {
263         return WrappedIterator.create( super.listEquivalentProperties() ).mapWith( new AsMapper( DAMLProperty.class ) );
264     }
265
266
267     /**
268      * Answer an iterator over all of the super-properties of this property, using the
269      * <code>rdfs:subPropertyOf</code> relation (or one of its aliases). The set of super-properties
270      * is transitively closed over the subPropertyOf relation.
271      *
272      * @return An iterator over the super-properties of this property,
273      * whose values will be DAMLProperties.
274      */

275     public ExtendedIterator getSuperProperties() {
276         return getSuperProperties( true );
277     }
278
279
280     /**
281      * <p>Answer an iterator over all of the super-properties of this property.</p>
282      * <p><strong>Note:</strong> In a change to the Jena 1 DAML API, whether
283      * this iterator includes <em>inferred</em> super-properties is determined
284      * not by a flag at the API level, but by the construction of the DAML
285      * model itself. See {@link ModelFactory} for details. The boolean parameter
286      * <code>closed</code> is now re-interpreted to mean the inverse of <code>
287      * direct</code>, see {@link OntClass#listSubClasses(boolean)} for more details.
288      * </p>
289      *
290      * @param closed If true, return all available values; otherwise, return
291      * only local (direct) super-properties. See note for details.
292      * @return An iterator over this property's super-properties.
293      */

294     public ExtendedIterator getSuperProperties( boolean closed ) {
295         return WrappedIterator.create( listSuperProperties( !closed ) ).mapWith( new AsMapper( DAMLProperty.class ) );
296     }
297
298
299     /**
300      * <p>Answer an iterator over all of the sub-properties of this property.</p>
301      *
302      * @return An iterator over the sub-properties of this property.
303      */

304     public ExtendedIterator getSubProperties() {
305         return getSubProperties( true );
306     }
307
308
309     /**
310      * <p>Answer an iterator over all of the sub-properties of this property.</p>
311      * <p><strong>Note:</strong> In a change to the Jena 1 DAML API, whether
312      * this iterator includes <em>inferred</em> sub-properties is determined
313      * not by a flag at the API level, but by the construction of the DAML
314      * model itself. See {@link ModelFactory} for details. The boolean parameter
315      * <code>closed</code> is now re-interpreted to mean the inverse of <code>
316      * direct</code>, see {@link OntClass#listSubClasses(boolean)} for more details.
317      * </p>
318      *
319      * @param closed If true, return all available values; otherwise, return
320      * only local (direct) sub-properties. See note for details.
321      * @return An iterator over this property's sub-properties.
322      */

323     public ExtendedIterator getSubProperties( boolean closed ) {
324         return WrappedIterator.create( listSubProperties( !closed ) ).mapWith( new AsMapper( DAMLProperty.class ) );
325     }
326
327
328     /**
329      * <p>Answer an iterator over all of the DAML classes that form the domain of this
330      * property. The actual domain of the relation denoted by this property is the
331      * conjunction of all of the classes mention by the RDFS:domain property of this
332      * DAML property and all of its super-properties.</p>
333      *
334      * @return an iterator whose values will be the DAML classes that define the domain
335      * of the relation
336      */

337     public ExtendedIterator getDomainClasses() {
338         return WrappedIterator.create( listPropertyValues( getProfile().DOMAIN() ) ).mapWith( new AsMapper( DAMLClass.class ) );
339     }
340
341
342     /**
343      * Answer an iterator over all of the DAML classes that form the range of this
344      * property. The actual range of the relation denoted by this property is the
345      * conjunction of all of the classes mention by the RDFS:range property of this
346      * DAML property and all of its super-properties.
347      *
348      * @return an iterator whose values will be the DAML classes that define the range
349      * of the relation
350      */

351     public ExtendedIterator getRangeClasses() {
352         return WrappedIterator.create( listPropertyValues( getProfile().RANGE() ) ).mapWith( new AsMapper( DAMLClass.class ) );
353     }
354
355      
356
357
358     // Internal implementation methods
359
//////////////////////////////////
360

361
362
363     //==============================================================================
364
// Inner class definitions
365
//==============================================================================
366

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

399
400
Popular Tags