KickJava   Java API By Example, From Geeks To Geeks.

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


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: DAMLClassImpl.java,v $
9  * Revision $Revision: 1.15 $
10  * Release status Preview-release $State: Exp $
11  *
12  * Last modified on $Date: 2005/04/08 17:38:52 $
13  * by $Author: ian_dickinson $
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.vocabulary.*;
35 import com.hp.hpl.jena.util.iterator.*;
36
37
38
39 /**
40  * <p>Java representation of a DAML ontology Class. Note that the ontology classes are
41  * not the same as Java classes: think of classifications rather than active data structures.</p>
42  *
43  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
44  * @version CVS info: $Id: DAMLClassImpl.java,v 1.15 2005/04/08 17:38:52 ian_dickinson Exp $
45  */

46 public class DAMLClassImpl
47     extends OntClassImpl
48     implements DAMLClass
49 {
50     // Constants
51
//////////////////////////////////
52

53
54
55     // Static variables
56
//////////////////////////////////
57

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

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

84     /** Property accessor for onProperty */
85     private PropertyAccessor m_propSubClassOf = new PropertyAccessorImpl( getProfile().SUB_CLASS_OF(), this );
86
87     /** Property accessor for disjointWith */
88     private PropertyAccessor m_propDisjointWith = new PropertyAccessorImpl( getProfile().DISJOINT_WITH(), this );
89
90     /** Property accessor for disjointUnionOf */
91     private PropertyAccessor m_propDisjointUnionOf = new PropertyAccessorImpl( DAML_OIL.disjointUnionOf, this );
92
93     /** Property accessor for sameClassAs */
94     private PropertyAccessor m_propSameClassAs = new PropertyAccessorImpl( getProfile().EQUIVALENT_CLASS(), this );
95
96     /** Property accessor for oneOf */
97     private PropertyAccessor m_propOneOf = new PropertyAccessorImpl( getProfile().ONE_OF(), this );
98
99     /** Property accessor for unionOf */
100     private PropertyAccessor m_propUnionOf = new PropertyAccessorImpl( getProfile().UNION_OF(), this );
101
102     /** Property accessor for intersectionOf */
103     private PropertyAccessor m_propIntersectionOf = new PropertyAccessorImpl( getProfile().INTERSECTION_OF(), this );
104
105     /** Property accessor for complementOf */
106     private PropertyAccessor m_propComplementOf = new PropertyAccessorImpl( getProfile().COMPLEMENT_OF(), this );
107
108     /** DAML common delegate */
109     protected DAMLCommon m_common = null;
110
111     /** Vocabulary - this is really obsoleted by the profile mechanism */
112     protected DAMLVocabulary m_vocabulary = VocabularyManager.getDefaultVocabulary();
113
114
115     // Constructors
116
//////////////////////////////////
117

118     /**
119      * <p>
120      * Construct a DAML class represented by the given node in the given graph.
121      * </p>
122      *
123      * @param n The node that represents the resource
124      * @param g The enh graph that contains n
125      */

126     public DAMLClassImpl( Node n, EnhGraph g ) {
127         super( n, g );
128         m_common = new DAMLCommonImpl( n, g );
129     }
130
131
132
133     // External signature methods
134
//////////////////////////////////
135

136     // delegate to DAMLCommon what we can
137
/** @deprecated */
138     public void setRDFType( Resource rdfClass, boolean replace ) { m_common.setRDFType( rdfClass, replace ); }
139     public DAMLModel getDAMLModel() { return m_common.getDAMLModel(); }
140     public ExtendedIterator getRDFTypes( boolean complete ) { return m_common.getRDFTypes( complete ); }
141     public DAMLVocabulary getVocabulary() { return m_vocabulary; }
142     public LiteralAccessor prop_label() { return m_common.prop_label(); }
143     public LiteralAccessor prop_comment() { return m_common.prop_comment(); }
144     public PropertyAccessor prop_equivalentTo() { return m_common.prop_equivalentTo(); }
145     public PropertyAccessor prop_type() { return m_common.prop_type(); }
146
147     /**
148      * <p>Answer an iterator over all of the DAML objects that are equivalent to this
149      * class, which will be the union of <code>daml:equivalentTo</code> and
150      * <code>daml:sameClassAs</code>.</p>
151      *
152      * @return an iterator ranging over every equivalent DAML class
153      */

154     public ExtendedIterator getEquivalentValues() {
155         ConcatenatedIterator i = new ConcatenatedIterator(
156                        // first the iterator over the equivalentTo values
157
m_common.getEquivalentValues(),
158                        // followed by the sameClassAs values
159
getSameClasses() );
160
161         return UniqueExtendedIterator.create( i ).mapWith( new AsMapper( DAMLClass.class ) );
162     }
163
164
165     /**
166      * Answer the set of equivalent values to this value, but not including the
167      * value itself. The iterator will range over a set: each element occurs only
168      * once.
169      *
170      * @return An iteration ranging over the set of values that are equivalent to this
171      * value, but not itself.
172      */

173     public ExtendedIterator getEquivalenceSet() {
174         Set s = new HashSet();
175
176         s.add( this );
177         for (Iterator i = getEquivalentValues(); i.hasNext(); s.add( i.next() ) );
178         s.remove( this );
179
180         return WrappedIterator.create( s.iterator() );
181     }
182
183
184
185     /**
186      * <p>Property accessor for the <code>daml:subClassOf</code> property of a class. This
187      * denotes a class that is a super-class of this class.
188      *
189      * @return Property accessor for <code>daml:subClassOf</code>.
190      */

191     public PropertyAccessor prop_subClassOf() {
192         return m_propSubClassOf;
193     }
194
195
196     /**
197      * <p>Property accessor for the <code>daml:disjointWith</code> property of a class. This
198      * denotes a class with which this class has no instances in common.</p>
199      *
200      * @return Property accessor for <code>daml:disjointWith</code>.
201      */

202     public PropertyAccessor prop_disjointWith() {
203         return m_propDisjointWith;
204     }
205
206
207     /**
208      * <p>Property accessor for the <code>daml:disjointUnionOf</code> property of a class. This
209      * denotes a list of classes that are each pair-wise disjoint, and whose
210      * union describes this class.</p>
211      *
212      * @return Property accessor for <code>daml:disjointUnionOf</code>.
213      */

214     public PropertyAccessor prop_disjointUnionOf() {
215         return m_propDisjointUnionOf;
216     }
217
218
219     /**
220      * <p>Property accessor for the <code>daml:sameClassAs</code> property of a DAML class. This
221      * denotes a class whose instances are the same those of this class.</p>
222      *
223      * @return Property accessor for <code>daml:sameClassAs</code>.
224      */

225     public PropertyAccessor prop_sameClassAs() {
226         return m_propSameClassAs;
227     }
228
229
230     /**
231      * <p>Property accessor for the property <code>daml:unionOf</code>, which denotes a class
232      * expression consisting of the union (disjunction) of a list of classes.</p>
233      *
234      * @return Property accessor for <code>daml:unionOf</code>.
235      */

236     public PropertyAccessor prop_unionOf() {
237         return m_propUnionOf;
238     }
239
240
241     /**
242      * <p>Property accessor for the property <code>daml:intersectionOf</code>, which denotes an
243      * intersection (conjunction) of a list of classes.</p>
244      *
245      * @return Property accessor for <code>daml:intersectionOf</code>.
246      */

247     public PropertyAccessor prop_intersectionOf() {
248         return m_propIntersectionOf;
249     }
250
251
252     /**
253      * <p>Property accessor for the property <code>daml:compelementOf</code>, which denotes the
254      * class whose members are the individuals not in the given class.</p>
255      *
256      * @return Property accessor for <code>daml:compelementOf</code>.
257      */

258     public PropertyAccessor prop_complementOf() {
259         return m_propComplementOf;
260     }
261
262
263     /**
264      * <p>Property accessor for the <code>daml:oneOf</code> property, which defines a class expression
265      * denoting that the class is exactly one of the given list of classes.</p>
266      *
267      * @return Property accessor for <code>daml:oneOf</code>.
268      */

269     public PropertyAccessor prop_oneOf() {
270         return m_propOneOf;
271     }
272
273
274     /**
275      * Answer true if this class expression is an enumeration (i&#046;e&#046; has a property
276      * 'oneOf' with a list of values). This is not an exclusive property, a class
277      * expression can be an enumeration at the same time as one of the other kinds
278      * of class expression, though the conjunction of these may produce the Nothing
279      * class.
280      *
281      * @return true if this class expression is an enumeration.
282      */

283     public boolean isEnumeration() {
284         return hasProperty( getVocabulary().oneOf() );
285     }
286
287
288     /**
289      * Answer true if this class expression is an named class (i&#046;e&#046; is not an anonymous
290      * class expression). This is not an exclusive property, a class
291      * expression can be named at the same time as one of the other kinds
292      * of class expression, though the conjunction of these may produce the Nothing
293      * class.
294      *
295      * @return true if this class expression is a named class.
296      */

297     public boolean isNamedClass() {
298         return !isAnon();
299     }
300
301
302     /**
303      * Answer true if this class expression is an property restriction (i&#046;e&#046; is a
304      * Restriction value). This is not an exclusive property, a class
305      * expression can be a property restriction at the same time as one of the other kinds
306      * of class expression, though the conjunction of these may produce the Nothing
307      * class.
308      *
309      * @return necessarily false, since restrictions are represented by a different Java class (see
310      * {@link com.hp.hpl.jena.ontology.daml.DAMLRestriction}).
311      */

312     public boolean isRestriction() {
313         return hasProperty( RDF.type, getProfile().RESTRICTION() );
314     }
315
316
317     /**
318      * Answer true if this class expression is an boolean intersection of a list
319      * of class expressions. This is not an exclusive property, a class
320      * expression can be an intersection at the same time as one of the other kinds
321      * of class expression, though the conjunction of these may produce the Nothing
322      * class.
323      *
324      * @return true if this class expression is an intersection.
325      */

326     public boolean isIntersection() {
327         return hasProperty( getVocabulary().intersectionOf() );
328     }
329
330
331     /**
332      * Answer true if this class expression is an boolean union of a list
333      * of class expressions. This is not an exclusive property, a class
334      * expression can be an union at the same time as one of the other kinds
335      * of class expression, though the conjunction of these may produce the Nothing
336      * class.
337      *
338      * @return true if this class expression is a union.
339      */

340     public boolean isUnion() {
341         return hasProperty( getVocabulary().unionOf() );
342     }
343
344
345     /**
346      * Answer true if this class expression is a disjoint union of a list
347      * of class expressions. This is not an exclusive property, a class
348      * expression can be a disjoint union at the same time as one of the other kinds
349      * of class expression, though the conjunction of these may produce the Nothing
350      * class.
351      *
352      * @return true if this class expression is a disjoint union.
353      */

354     public boolean isDisjointUnion() {
355         return hasProperty( getVocabulary().disjointUnionOf() );
356     }
357
358
359     /**
360      * Answer true if this class expression is an boolean complement of a list
361      * of class expressions. This is not an exclusive property, a class
362      * expression can be an complement at the same time as one of the other kinds
363      * of class expression, though the conjunction of these may produce the Nothing
364      * class.
365      *
366      * @return true if this class expression is a complement.
367      */

368     public boolean isComplement() {
369         return hasProperty( getVocabulary().complementOf() );
370     }
371
372
373     /**
374      * <p>Answer an iterator over the DAML classes
375      * that mention this class as one of its super-classes. Will return
376      * all available sub-classes (see {@link #getSubClasses(boolean)} for
377      * more details). The elements
378      * of the iterator will be {@link DAMLClass} objects.</p>
379      * @return An iterator over all available sub-classes of this class
380      */

381     public ExtendedIterator getSubClasses() {
382         return getSubClasses( true );
383     }
384
385
386     /**
387      * <p>Answer an iterator over the DAML classes
388      * that mention this class as one of its super-classes.
389      * The members of the iterator will be {@link DAMLClass} objects
390      * </p>
391      * <p><strong>Note:</strong> In a change to the Jena 1 DAML API, whether
392      * this iterator includes <em>inferred</em> sub-classes is determined
393      * not by a flag at the API level, but by the construction of the DAML
394      * model itself. See {@link ModelFactory} for details. The boolean parameter
395      * <code>closed</code> is now re-interpreted to mean the inverse of <code>
396      * direct</code>, see {@link OntClass#listSubClasses(boolean)} for more details.
397      * </p>
398      *
399      * @param closed If true, return all available values; otherwise, return
400      * only local (direct) sub-classes. See note for details.
401      * @return An iterator over this class's sub-classes.
402      */

403     public ExtendedIterator getSubClasses( boolean closed ) {
404         return WrappedIterator.create( super.listSubClasses( !closed ) ).mapWith( new AsMapper( DAMLClass.class ) );
405     }
406
407
408     /**
409      * <p>Answer an iterator over the DAML classes
410      * that are super-classes of this class. Will return
411      * all available super-classes (see {@link #getSuperClasses(boolean)} for
412      * more details). The elements
413      * of the iterator will be {@link DAMLClass} objects.</p>
414      * @return An iterator over all available super-classes of this class
415      */

416     public ExtendedIterator getSuperClasses() {
417         return getSuperClasses( true );
418     }
419
420
421     /**
422      * <p>Answer an iterator over the DAML classes
423      * that are super-classes of this class.
424      * The members of the iterator will be {@link DAMLClass} objects
425      * </p>
426      * <p><strong>Note:</strong> In a change to the Jena 1 DAML API, whether
427      * this iterator includes <em>inferred</em> super-classes is determined
428      * not by a flag at the API level, but by the construction of the DAML
429      * model itself. See {@link ModelFactory} for details. The boolean parameter
430      * <code>closed</code> is now re-interpreted to mean the inverse of <code>
431      * direct</code>, see {@link OntClass#listSubClasses(boolean)} for more details.
432      * </p>
433      *
434      * @param closed If true, return all available values; otherwise, return
435      * only local (direct) super-classes. See note for details.
436      * @return an iterator over this class's super-classes.
437      */

438     public ExtendedIterator getSuperClasses( boolean closed ) {
439         return WrappedIterator.create( super.listSuperClasses( !closed ) ).mapWith( new AsMapper( DAMLClass.class ) );
440     }
441
442
443     /**
444      * <p>Answer an iterator over all of the DAML classes that are equivalent to this
445      * value under the <code>daml:sameClassAs</code> relation. Note: only considers
446      * <code>daml:sameClassAs</code>, for general equivalence, see
447      * {@link #getEquivalentValues}. Note also that the first member of the iteration is
448      * always the DAMLClass on which the method is invoked: trivially, a DAMLClass is
449      * a member of the set of DAMLClasses equivalent to itself. If the caller wants
450      * the set of classes equivalent to this one, not including itself, simply ignore
451      * the first element of the iteration.</p>
452      *
453      * @return an iterator ranging over every equivalent DAML classes
454      */

455     public ExtendedIterator getSameClasses() {
456         return WrappedIterator.create( super.listEquivalentClasses() ).mapWith( new AsMapper( DAMLClass.class ) );
457     }
458
459
460
461     /**
462      * <p>Answer an iterator over the instances of this class that currently exist
463      * in the model.<p>
464      *
465      * @return An iterator over those instances that have this class as one of
466      * the classes to which they belong
467      * @see com.hp.hpl.jena.ontology.daml.DAMLCommon#getRDFTypes
468      */

469     public ExtendedIterator getInstances() {
470         return WrappedIterator.create( listInstances() ).mapWith( new AsMapper( DAMLInstance.class ) );
471     }
472
473
474     /**
475      * <p>Answer an iteration of the properties that may be used for
476      * instances of this class: i&#046;e&#046; the properties that have this class,
477      * or one of its super-classes, as domain.<p>
478      *
479      * @return An iteration of the properties that have this class in the domain
480      */

481     public ExtendedIterator getDefinedProperties() {
482         return getDefinedProperties( true );
483     }
484
485
486     /**
487      * <p>Answer an iteration of the properties that may be used for
488      * instances of this class: i&#046;e&#046; the properties that have this class,
489      * or optionally one of its super-classes, as domain.</p>
490      * <p><strong>Note:</strong> In a change to the Jena 1 DAML API, whether
491      * this iterator includes the defined properties for <em>inferred</em>
492      * super-classes is determined
493      * not by a flag at the API level, but by the construction of the DAML
494      * model itself. See {@link ModelFactory} for details. The boolean parameter
495      * <code>closed</code> is now re-interpreted to mean the inverse of <code>
496      * direct</code>, see {@link OntClass#listSubClasses(boolean)} for more details.
497      * </p>
498      *
499      * @param closed If true, use all available information from the class hierarchy;
500      * if false, only use local properties.
501      * @return An iteration of the properties that have this class as domain
502      */

503     public ExtendedIterator getDefinedProperties( boolean closed ) {
504         return WrappedIterator.create( listDeclaredProperties( !closed ) ).mapWith( new AsMapper( DAMLProperty.class ) );
505     }
506
507
508     // Internal implementation methods
509
//////////////////////////////////
510

511
512     //==============================================================================
513
// Inner class definitions
514
//==============================================================================
515

516 }
517
518 /*
519     (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
520     All rights reserved.
521
522     Redistribution and use in source and binary forms, with or without
523     modification, are permitted provided that the following conditions
524     are met:
525
526     1. Redistributions of source code must retain the above copyright
527        notice, this list of conditions and the following disclaimer.
528
529     2. Redistributions in binary form must reproduce the above copyright
530        notice, this list of conditions and the following disclaimer in the
531        documentation and/or other materials provided with the distribution.
532
533     3. The name of the author may not be used to endorse or promote products
534        derived from this software without specific prior written permission.
535
536     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
537     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
538     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
539     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
540     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
541     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
542     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
543     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
544     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
545     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
546 */

547
548
Popular Tags