KickJava   Java API By Example, From Geeks To Geeks.

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


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 5 Jan 2001
8  * Filename $RCSfile: DAMLCommonImpl.java,v $
9  * Revision $Revision: 1.13 $
10  * Release status Preview-release $State: Exp $
11  *
12  * Last modified on $Date: 2005/02/21 12:05:08 $
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.rdf.model.*;
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.ontology.daml.*;
33 import com.hp.hpl.jena.ontology.impl.*;
34 import com.hp.hpl.jena.util.iterator.*;
35 import com.hp.hpl.jena.vocabulary.*;
36
37
38 /**
39  * <p>Abstract super-class for all DAML resources (including properties). Defines shared
40  * implementations and common services, such as property manipulation, vocabulary
41  * management and <code>rdf:type</code> management. Also defines accessors for common
42  * properties, including <code>comment</code>, <code>label</code>, and <code>equivalentTo</code>.
43  * </p>
44  *
45  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
46  * @version CVS info: $Id: DAMLCommonImpl.java,v 1.13 2005/02/21 12:05:08 andy_seaborne Exp $
47  */

48 public class DAMLCommonImpl
49     extends OntResourceImpl
50     implements DAMLCommon
51 {
52     // Constants
53
//////////////////////////////////
54

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

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

65     public static Implementation factory = new Implementation() {
66         public EnhNode wrap( Node n, EnhGraph eg ) {
67             if (canWrap( n, eg )) {
68                 return new DAMLCommonImpl( n, eg );
69             }
70             else {
71                 throw new ConversionException( "Cannot convert node " + n.toString() + " to DAMLCommon");
72             }
73         }
74             
75         public boolean canWrap( Node node, EnhGraph eg ) {
76             // node will support being an OntResource facet if it is a uri or bnode
77
return node.isURI() || node.isBlank();
78         }
79     };
80
81
82     // Instance variables
83
//////////////////////////////////
84

85     /** Literal accessor for label property */
86     private LiteralAccessor m_propLabel = new LiteralAccessorImpl( getVocabulary().label(), this );
87
88     /** Literal accessor for comment property */
89     private LiteralAccessor m_propComment = new LiteralAccessorImpl( getVocabulary().comment(), this );
90
91     /** Property accessor for equivalentTo */
92     private PropertyAccessor m_propEquivalentTo = null;
93
94     /** The vocabulary that corresponds to the namespace this DAML value was declared in */
95     private DAMLVocabulary m_vocabulary = null;
96
97     /** Property accessor for RDF:type */
98     private PropertyAccessor m_propType = null;
99
100
101
102     // Constructors
103
//////////////////////////////////
104

105
106     /**
107      * <p>Constructor, takes the URI this value, and the underlying
108      * model it will be attached to.</p>
109      *
110      * @param n The node that is being presented as a DAMLCommonImpl
111      * @param g Reference to the enhanced graph that will contain statements about this DAML value.
112      */

113     public DAMLCommonImpl( Node n, EnhGraph g )
114     {
115         super( n, g );
116     }
117
118
119
120     // External signature methods
121
//////////////////////////////////
122

123     /**
124      * <p>Answer the underlying model</p>
125      *
126      * @return A DAML model
127      */

128     public DAMLModel getDAMLModel() {
129         return (DAMLModel) getModel();
130     }
131
132
133     /**
134      * <p>Add an RDF type property for this node in the underlying model. If the replace flag
135      * is true, this type will replace any current type property for the node. Otherwise,
136      * the type will be in addition to any existing type property.</p>
137      * <p>Deprecated in favour of {@link OntResource#addRDFType} for add, or
138      * {@link OntResource#setRDFType} for replace.</p>
139      *
140      * @param rdfClass The RDF resource denoting the class that will be new value for the rdf:type property.
141      * @param replace If true, the given class will replace any existing type property for this
142      * value, otherwise it will be added as an extra type statement.
143      * @deprecated Use {@link OntResource#addRDFType} or {@link OntResource#setRDFType}.
144      */

145     public void setRDFType( Resource rdfClass, boolean replace ) {
146         if (replace) {
147             setRDFType( rdfClass );
148         }
149         else {
150             addRDFType( rdfClass );
151         }
152     }
153
154
155     /**
156      * <p>Answer an iterator over all of the types to which this resource belongs. Optionally,
157      * restrict the results to the most specific types, so that any class that is subsumed by
158      * another class in this resource's set of types is not reported.</p>
159      * <p><strong>Note:</strong> that the interpretation of the <code>complete</code> flag has
160      * changed since Jena 1.x. Previously, the boolean flag was to generated the transitive
161      * closure of the class hierarchy; this is now handled by the underlyin inference graph
162      * (if specified). Now the flag is used to restrict the returned values to the most-specific
163      * types for this resource.</p>
164      *
165      * @param complete If true, return all known types; if false, return only the most-specific
166      * types.
167      * @return an iterator over the set of this value's classes
168      */

169     public ExtendedIterator getRDFTypes( boolean complete ) {
170         return listRDFTypes( !complete );
171     }
172
173
174     /**
175      * <p>Answer the DAML+OIL vocabulary that corresponds to the namespace that this value
176      * was declared in.</p>
177      *
178      * @return A vocabulary object
179      */

180     public DAMLVocabulary getVocabulary() {
181         if (m_vocabulary == null) {
182             // need to establish the vocabulary for this object
183
m_vocabulary = VocabularyManager.getVocabulary( this );
184         }
185
186         return m_vocabulary;
187     }
188
189
190     /**
191      * <p>Answer an iterator over all of the DAML objects that are equivalent to this
192      * value under the <code>daml:equivalentTo</code> relation.
193      * Note that the first member of the iteration is
194      * always the DAML value on which the method is invoked: trivially, a value is
195      * a member of the set of values equivalent to itself. If the caller wants
196      * the set of values equivalent to this one, not including itself, simply ignore
197      * the first element of the iteration.</p>
198      *
199      * @return An iterator ranging over every equivalent DAML value
200      */

201     public ExtendedIterator getEquivalentValues() {
202         // iterator of myself
203
List me = new LinkedList();
204         me.add( this );
205         
206         return UniqueExtendedIterator.create( WrappedIterator.create( me.iterator() )
207                    .andThen( listPropertyValues( getProfile().SAME_AS() ) ) );
208     }
209
210
211     /**
212      * Answer the set of equivalent values to this value, but not including the
213      * value itself. The iterator will range over a set: each element occurs only
214      * once.
215      *
216      * @return An iteration ranging over the set of values that are equivalent to this
217      * value, but not itself.
218      */

219     public ExtendedIterator getEquivalenceSet() {
220         Set s = new HashSet();
221
222         s.add( this );
223         for (Iterator i = getEquivalentValues(); i.hasNext(); s.add( i.next() ) );
224         s.remove( this );
225         
226         return WrappedIterator.create( s.iterator() );
227     }
228
229
230     // Properties
231
/////////////
232

233     /**
234      * Accessor for the property of the label on the value, whose value
235      * is a literal (string).
236      *
237      * @return Literal accessor for the label property
238      */

239     public LiteralAccessor prop_label() {
240         return m_propLabel;
241     }
242
243
244     /**
245      * Accessor for the property of the comment on the value, whose value
246      * is a literal (string).
247      *
248      * @return Literal accessor for the comment property
249      */

250     public LiteralAccessor prop_comment() {
251         return m_propComment;
252     }
253
254
255     /**
256      * Property accessor for the 'equivalentTo' property of a DAML value. This
257      * denotes that two terms have the same meaning. The spec helpfully
258      * says: <i>for equivalentTo(X, Y), read X is an equivalent term to Y</i>.
259      *
260      * @return Property accessor for 'equivalentTo'.
261      */

262     public PropertyAccessor prop_equivalentTo() {
263         if (m_propEquivalentTo == null) {
264             m_propEquivalentTo = new PropertyAccessorImpl( getVocabulary().equivalentTo(), this );
265         }
266
267         return m_propEquivalentTo;
268     }
269
270
271
272     /**
273      * Property accessor for the 'rdf:type' property of a DAML value.
274      *
275      * @return Property accessor for 'rdf:type'.
276      */

277     public PropertyAccessor prop_type() {
278         if (m_propType == null) {
279             m_propType = new PropertyAccessorImpl( RDF.type, this );
280         }
281
282         return m_propType;
283     }
284
285
286
287     // Internal implementation methods
288
//////////////////////////////////
289

290
291
292     //==============================================================================
293
// Inner class definitions
294
//==============================================================================
295

296
297
298 }
299
300
301
302 /*
303     (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
304     All rights reserved.
305
306     Redistribution and use in source and binary forms, with or without
307     modification, are permitted provided that the following conditions
308     are met:
309
310     1. Redistributions of source code must retain the above copyright
311        notice, this list of conditions and the following disclaimer.
312
313     2. Redistributions in binary form must reproduce the above copyright
314        notice, this list of conditions and the following disclaimer in the
315        documentation and/or other materials provided with the distribution.
316
317     3. The name of the author may not be used to endorse or promote products
318        derived from this software without specific prior written permission.
319
320     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
321     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
322     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
323     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
324     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
325     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
326     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
327     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
328     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
329     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
330 */

331
332
Popular Tags