KickJava   Java API By Example, From Geeks To Geeks.

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


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: DAMLInstanceImpl.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:21 $
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 com.hp.hpl.jena.rdf.model.*;
27 import com.hp.hpl.jena.util.iterator.*;
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.vocabulary.*;
33
34
35
36 /**
37  * Java representation of a DAML Instance.
38  *
39  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
40  * @version CVS info: $Id: DAMLInstanceImpl.java,v 1.9 2005/02/21 12:05:21 andy_seaborne Exp $
41  */

42 public class DAMLInstanceImpl
43     extends DAMLCommonImpl
44     implements DAMLInstance
45 {
46     // Constants
47
//////////////////////////////////
48

49
50     // Static variables
51
//////////////////////////////////
52

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

58     public static Implementation factory = new Implementation() {
59         public EnhNode wrap( Node n, EnhGraph eg ) {
60             if (canWrap( n, eg )) {
61                 return new DAMLInstanceImpl( n, eg );
62             }
63             else {
64                 throw new ConversionException( "Cannot convert node " + n.toString() + " to DAMLDatatype" );
65             }
66         }
67             
68         public boolean canWrap( Node node, EnhGraph eg ) {
69             Profile profile = (eg instanceof OntModel) ? ((OntModel) eg).getProfile() : null;
70             return (profile != null) && profile.isSupported( node, eg, DAMLInstance.class );
71         }
72     };
73
74     // Instance variables
75
//////////////////////////////////
76

77     /** Property accessor for sameIndividualAs */
78     protected PropertyAccessor m_propsameIndividualAs = null;
79
80
81
82     // Constructors
83
//////////////////////////////////
84

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

103
104     /**
105      * Answer a key that can be used to index collections of this DAML instance for
106      * easy access by iterators. Package access only.
107      *
108      * @return a key object.
109      */

110     Object JavaDoc getKey() {
111         return DAML_OIL.Thing.getURI();
112     }
113
114
115     /**
116      * Property accessor for <code>daml:sameIndividualAs</code> property on a DAML instance.
117      *
118      * @return a property accessor
119      */

120     public PropertyAccessor prop_sameIndividualAs() {
121         if (m_propsameIndividualAs == null) {
122             m_propsameIndividualAs = new PropertyAccessorImpl( getVocabulary().sameIndividualAs(), this );
123         }
124
125         return m_propsameIndividualAs;
126     }
127
128
129     /**
130      * Return an iterator over all of the instances that are the same as this one,
131      * by generating the transitive closure over the <code>daml:samePropertyAs</code>
132      * property.
133      *
134      * @return an iterator whose values will all be DAMLInstance objects
135      */

136     public ExtendedIterator getSameInstances() {
137         return listAs( getProfile().SAME_INDIVIDUAL_AS(), "SAME_INDIVIDUAL_AS", DAMLInstance.class );
138     }
139
140
141
142     /**
143      * Answer an iterator over all of the DAML objects that are equivalent to this
144      * instance, which will be the union of <code>daml:equivalentTo</code> and
145      * <code>daml:sameIndividualAs</code>.
146      *
147      * @return an iterator ranging over every equivalent DAML instance - each value of
148      * the iteration should be a DAMLInstance object.
149      */

150     public ExtendedIterator getEquivalentValues() {
151         return UniqueExtendedIterator.create( listAs( getProfile().SAME_AS(), "SAME_AS", DAMLInstance.class ).andThen( getSameInstances() ) );
152     }
153
154
155     /**
156      * Answer a property accessor for a user defined property.
157      *
158      * @param property An RDF or DAML property
159      * @return a property accessor, that simplifies some of the basic operations
160      * of a given property on a given object
161      */

162     public PropertyAccessor accessProperty( Property property ) {
163         return new PropertyAccessorImpl( property, this );
164     }
165
166
167     // Internal implementation methods
168
//////////////////////////////////
169

170     /**
171      * Answer a value that will be a default type to include in an iteration of
172      * the value's rdf types. Typically there is no default (null), but for an
173      * instance we want to ensure that the default type is daml:Thing.
174      *
175      * @return The default type: <code>daml:Thing</code>
176      */

177     protected Resource getDefaultType() {
178         return getVocabulary().Thing();
179     }
180
181
182
183     //==============================================================================
184
// Inner class definitions
185
//==============================================================================
186

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

221
222
Popular Tags