KickJava   Java API By Example, From Geeks To Geeks.

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


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 10 Jan 2001
8  * Filename $RCSfile: DAMLLoader.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:23 $
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.ontology.daml.*;
29 import com.hp.hpl.jena.vocabulary.*;
30
31
32
33
34 /**
35  * <p>Obsolete. In Jena 1, this class was used to load
36  * DAML ontologies from either input readers or named files, and map the DAML resources
37  * to their corresponding DAML abstractions. Using the new polymorphism support in
38  * Jena 2, this is no longer necessary. DAMLLoader is kept as the means of controlling
39  * some of the behaviours of the DAML model, such as processing imports.</p>
40  *
41  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
42  * @version CVS info: $Id: DAMLLoader.java,v 1.9 2005/02/21 12:05:23 andy_seaborne Exp $
43  */

44 public class DAMLLoader
45 {
46     // Constants
47
//////////////////////////////////
48

49
50     /* Misc constants */
51
52     /** Prefix for a URI to a file */
53     public static final String JavaDoc FILE_URI_PREFIX = "file://";
54
55     /* Status flags */
56
57     /** {@link #getStatus Status} flag: OK */
58     public static final long STATUS_OK = 0L;
59
60     /** {@link #getStatus Status} flag: input source is not available (e&#046;g&#046; a file cannot be opened) */
61     public static final long STATUS_INPUT_UNAVAILABLE = 1L;
62
63     /** {@link #getStatus Status} flag: an I/O error occurred - details will be in log file. */
64     public static final long STATUS_IO_ERROR = 2L;
65
66     /** {@link #getStatus Status} flag: a syntax error occurred in the DAML file- details will be in log file. */
67     public static final long STATUS_SYNTAX_ERROR = 4L;
68
69     /** {@link #getStatus Status} flag: a misc error occurred - report a bug to the maintainer! */
70     public static final long STATUS_MISC_ERROR = 8L;
71
72
73     // Static variables
74
//////////////////////////////////
75

76
77
78     // Instance variables
79
//////////////////////////////////
80

81     /** A status flag we can use to inform callers what just happened */
82     private long m_status = STATUS_OK;
83
84     /** A reference to the storage service this class is using */
85     private DAMLModel m_damlModel = null;
86
87     /** List of ontologies that are not automatically fetched when loading containing ontologies */
88     private List m_importBlockList = new ArrayList();
89
90     /** Flag used to control the import blocking behaviour */
91     private boolean m_useImportBlocking = true;
92
93
94     // Constructors
95
//////////////////////////////////
96

97     /**
98      * Construct a new DAMLLoader that will load definitions into the given DAML model.
99      *
100      * @param m The DAML model that will contain the loaded definitions.
101      */

102     DAMLLoader( DAMLModel m ) {
103         m_damlModel = m;
104
105         // initialise the list of blocked imports (for efficiency, nothing more)
106
initialiseImportBlockList();
107     }
108
109
110     // External signature methods
111
//////////////////////////////////
112

113
114     /**
115      * Answer the DAML model that this loader is using to store the loaded definitions.
116      *
117      * @return A reference to a knowledge store.
118      */

119     public DAMLModel getDAMLModel() {
120         return m_damlModel;
121     }
122
123
124     /**
125      * <p>
126      * Initialise the list of well-known ontologies that we don't bother
127      * to load in we detect an import statement. Currently, the default value
128      * for this list is:
129      * <ul>
130      * <li> The DAML 2000/12 release </li>
131      * <li> The DAML 2001/3 release </li>
132      * <li> The RDF Schema 2000/01 release </li>
133      * </ul>
134      * </p><p>
135      * This list can be modified in several ways: use {@link #getImportBlockList}
136      * to get reference to the list and add/remove elements as required, override
137      * this method in a sub-class, or turn off all automatic importing with
138      * {@link #setLoadImportedOntologies}.
139      */

140     protected void initialiseImportBlockList() {
141         m_importBlockList.add( DAMLVocabulary.NAMESPACE_DAML_2000_12_URI );
142         m_importBlockList.add( DAMLVocabulary.NAMESPACE_DAML_2001_03_URI );
143         m_importBlockList.add( RDFS.getURI() );
144     }
145
146
147     /**
148      * Answer an iterator over the set of URI strings that <b>will not</b>
149      * be loaded if encountered in an import statement, even if autoloading of
150      * ontologies (see {@link #getLoadImportedOntologies()}) is on.
151      *
152      * @return iterator over the set of blocked imports, as URI strings.
153      */

154     public Iterator getImportBlockList() {
155         return m_importBlockList.iterator();
156     }
157
158
159     /**
160      * Answer true if a given URI is blocked from being imported: that is, it is
161      * assumed to be well-known and will not be automatically imported. Will
162      * answer false if import blocking is switched off altogether
163      * (see {@link #setUseImportBlocking}).
164      *
165      * @param uri The uri to be tested
166      * @return true if the URI should not be loaded.
167      */

168     public boolean isBlockedImport( String JavaDoc uri ) {
169         return m_useImportBlocking && m_importBlockList.contains( uri );
170     }
171
172
173     /**
174      * Add the given URI to the list of ontology urls that will not be loaded
175      * if encountered in an imports statement in the loaded ontology.
176      *
177      * @param uri The URI of the ontology to block from autoloading, as a String.
178      */

179     public void addImportBlock( String JavaDoc uri ) {
180         // maintain the invariant that there is only copy of each entry
181
if (!m_importBlockList.contains( uri )) {
182             m_importBlockList.add( uri );
183         }
184     }
185
186
187     /**
188      * Remove the given URI from the list of ontology urls that will not be loaded
189      * if encountered in an imports statement in the loaded ontology. Has no effect
190      * if the URI is not in the list.
191      *
192      * @param uri The URI of the ontology to no longer block from autoloading, as a String.
193      */

194     public void removeImportBlock( String JavaDoc uri ) {
195         m_importBlockList.remove( uri );
196     }
197
198
199     /**
200      * Answer true if the loader is to process imported ontologies (except for the
201      * ones on the don't load list). Default true.
202      *
203      * @return True if imported ontologies should be loaded as they are encountered.
204      */

205     public boolean getLoadImportedOntologies() {
206         return m_damlModel.getDocumentManager().getProcessImports();
207     }
208
209
210     /**
211      * Set the flag to control whether imported ontologies are to be loaded. Default
212      * true.
213      *
214      * @param loadImports If true, ontologies that are included in this one, via
215      * the &lt;imports&gt; element are loaded as they are discovered.
216      */

217     public void setLoadImportedOntologies( boolean loadImports ) {
218         m_damlModel.getDocumentManager().setProcessImports( loadImports );
219     }
220
221
222     /**
223      * Set the flag to control whether certain well-known imports are blocked
224      * from being automatically loaded if they encountered in an <code>imports</code>
225      * statement. Note that automatic loading of all imports can be switched of
226      * with {@link #setLoadImportedOntologies}.
227      *
228      * @param useBlocking If true, well-known URI's will be blocked from being
229      * autoloaded, even if autoloading is on
230      */

231     public void setUseImportBlocking( boolean useBlocking ) {
232         m_useImportBlocking = useBlocking;
233     }
234
235
236     /**
237      * Answer true if well-known URI's will be blocked from being autoloaded.
238      *
239      * @return True if imports are blocked.
240      * @see #setUseImportBlocking
241      */

242     public boolean getUseImportBlocking() {
243         return m_useImportBlocking;
244     }
245
246
247     /**
248      * Answer true if the ontology identified by the given URI has been loaded.
249      *
250      * @param uri The URI of the ontology
251      * @return true if the ontology has already been loaded by the knowledge store.
252      */

253     public boolean isLoadedOntology( String JavaDoc uri ) {
254         return m_damlModel.hasLoadedImport( uri );
255     }
256
257
258
259     /**
260      * Answer the status of the last operation. Returns a set of status flags
261      * (or'ed together) from all operations since the last {@link #resetStatus}.
262      *
263      * @return The current status, as a set of flags or'ed together into a long.
264      */

265     public long getStatus() {
266         return m_status;
267     }
268
269
270     /**
271      * Clear the status flags. Resets the status to {@link #STATUS_OK}.
272      */

273     public void resetStatus() {
274         m_status = STATUS_OK;
275     }
276
277
278
279     // Internal implementation methods
280
//////////////////////////////////
281

282
283
284     //==============================================================================
285
// Inner class definitions
286
//==============================================================================
287

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

317
318
Popular Tags