📄 ontdocumentmanager.java
字号:
* new path is searched. Otherwise, existing data will only be replaced if
* it is clobbered by keys loaded from the metadata loaded from the new path.
* </p>
*
* @param path The new metadata search path (see {@link #getMetadataSearchPath} for format)
* @param replace If true, clear existing mappings first
*/
public void setMetadataSearchPath( String path, boolean replace ) {
if (replace) {
reset();
}
m_searchPath = path;
m_policyURL = null;
initialiseMetadata( path );
}
/**
* Set the handler for read failures, overwriting any existing value.
* @param rfHandler The new handler for failed document read attempts.
*/
public void setReadFailureHandler( ReadFailureHandler rfHandler ) {
m_rfHandler = rfHandler;
}
/**
* Answer the handler object that handles failed document read attempts,
* or null if not defined.
* @return The current read failure handler, or null
*/
public ReadFailureHandler getReadFailureHandler() {
return m_rfHandler;
}
/**
* <p>Configure this document manager using the given configuration information, after
* first resetting the model back to all default values.</p>
* @param config Document manager configuration as an RDF model
* @see #configure( Model, boolean )
*/
public void configure( Model config ) {
configure( config, true );
}
/**
* <p>Configure this document manager according to the configuration options
* supplied by the given configuration model. If <code>reset</code> is true, the
* document manager is first reset back to all default values.</p>
* @param config Document manager configuration as an RDF model
* @param reset If true, reset the document manager to default values, before
* attempting to configure the document manager using the given model.
* @see #reset
*/
public void configure( Model config, boolean reset ) {
if (reset) {
reset( false );
}
processMetadata( config );
}
/**
* <p>Reset all state in this document manager back to the default
* values it would have had when the object was created. Optionally
* reload the profile metadata from the search path. <strong>Note</strong>
* that the metadata search path is not changed by this reset.</p>
* @param reload If true, reload the configuration file from the
* search path.
*/
public void reset( boolean reload ) {
// first check if we are using the global file manager, or a local one
if (m_usingGlobalFileMgr) {
// we can do a general reset by throwing away the old FM and creating a new one
setFileManager();
}
else {
// not using the global default FM, so we reset to best effort
getFileManager().resetCache();
}
setDefaults();
m_languageMap.clear();
m_ignoreImports.clear();
// copy the standard prefixes
m_prefixMap = new PrefixMappingImpl();
m_prefixMap.setNsPrefixes( PrefixMapping.Standard );
if (reload) {
initialiseMetadata( m_searchPath );
}
}
/**
* <p>Reset all state in this document manager back to the default
* values it would have had when the object was created. This does
* <strong>not</strong> reload the configuration information from
* the search path. Note also that the metadata search path is one
* of the values that is reset back to its default value.</p>
* @see #reset( boolean )
*/
public void reset() {
reset( false );
}
/**
* <p>
* Answer an iterator over the ontology document URI's that this document manager
* knows to re-direct to other URL's. <strong>Note</strong> that being in this
* iteration does <em>not</em> mean that a document with the given name is in
* the set of cached models held by this document manager.
* </p>
*
* @return An Iterator ranging over the public URI strings for the known
* document URI's.
*/
public Iterator listDocuments() {
return getFileManager().getLocationMapper().listAltEntries();
}
/**
* <p>
* Answer the URL of the alternative copy of the ontology document with the given URI, if known,
* or the URI unchanged if no alternative is known.
* </p>
*
* @param uri The ontology document to lookup
* @return The resolvable location of the alternative copy, if known, or <code>uri</code> otherwise
*/
public String doAltURLMapping( String uri ) {
return getFileManager().mapURI( uri );
}
/**
* <p>
* Answer the representation of the ontology document with the given URI, if known.
* </p>
*
* @param uri The ontology document to lookup
* @return The URI of the representation language, or null.
* @deprecated Language determination via the ODM will be removed from Jena 2.4 onwards
*/
public String getLanguage( String uri ) {
return (String) m_languageMap.get( uri );
}
/**
* <p>
* Answer the prefix for the qnames in the given document, if known.
* </p>
*
* @param uri The ontology document to lookup
* @return The string to use as a prefix when serialising qnames in the
* given document's namespace, or null if not known
* @deprecated Prefix management via the ODM is very likely to be removed from Jena 2.4 onwards
*/
public String getPrefixForURI( String uri ) {
return m_prefixMap.getNsURIPrefix( uri );
}
/**
* <p>
* Answer the base URI for qnames with the given prefix, if known.
* </p>
*
* @param prefix A prefix string
* @return The basename that the prefix expands to, or null
* @deprecated Prefix management via the ODM is very likely to be removed from Jena 2.4 onwards
*/
public String getURIForPrefix( String prefix ) {
return m_prefixMap.getNsPrefixURI( prefix );
}
/**
* <p>
* Answer the cached model corresponding to the given document, if known.
* </p>
*
* @param uri The ontology document to lookup
* @return The model for the document, or null if the model is not known.
* @see #getOntology
*/
public Model getModel( String uri ) {
Model m = getFileManager().getFromCache( uri );
// if a previously cached model has been closed, we ignore it
if (m != null && m.isClosed()) {
getFileManager().removeCacheModel( uri );
m = null;
}
return m;
}
/**
* <p>Answer true if, according to the policy expressed by this document manager, newly
* generated ontology models should include the pre-declared namespace prefixes.
* </p>
*
* @return True if pre-declared prefixes should be added to the models
* @deprecated Prefix management via the ODM is very likely to be removed from Jena 2.4 onwards
*/
public boolean useDeclaredPrefixes() {
return m_useDeclaredPrefixes;
}
/**
* <p>Set the flag that determines whether pre-declared namespace prefixes will be added to newly
* generated ontology models.</p>
*
* @param useDeclaredPrefixes If true, new models will include the pre-declared prefixes set held
* by this document manager.
* @deprecated Prefix management via the ODM is very likely to be removed from Jena 2.4 onwards
*/
public void setUseDeclaredPrefixes( boolean useDeclaredPrefixes ) {
m_useDeclaredPrefixes = useDeclaredPrefixes;
}
/**
* <p>Answer the namespace prefix map that contains the shared prefixes managed by this
* document manager.</p>
*
* @return The namespace prefix mapping
* @deprecated Prefix management via the ODM is very likely to be removed from Jena 2.4 onwards
*/
public PrefixMapping getDeclaredPrefixMapping() {
return m_prefixMap;
}
/**
* <p>
* Add a prefix mapping between the given public base URI and the
* given prefix.
* </p>
*
* @param uri The base URI that <code>prefix</code> expands to
* @param prefix A qname prefix
* @deprecated Prefix management via the ODM is very likely to be removed from Jena 2.4 onwards
*/
public void addPrefixMapping( String uri, String prefix ) {
m_prefixMap.setNsPrefix( prefix, uri );
}
/**
* <p>
* Add an entry for an alternative copy of the document with the given document
* URI.
* </p>
*
* @param docURI The public URI of the ontology document
* @param locationURL A locally resolvable URL where an alternative copy of the
* ontology document can be found
*/
public void addAltEntry( String docURI, String locationURL ) {
getFileManager().getLocationMapper().addAltEntry( docURI, locationURL );
}
/**
* <p>
* Add an entry that <code>model</code> is the appropriate model to use
* for the given ontology document. Will not replace any existing
* model that is cached for this URI (see
* {@link #addModel(String, Model, boolean)} for an alternative
* that can replace existing models).
* </p>
*
* @param docURI The public URI of the ontology document
* @param model A model containing the triples from the document
*/
public void addModel( String docURI, Model model ) {
addModel( docURI, model, false );
}
/**
* <p>
* Add an entry that <code>model</code> is the appropriate model to use
* for the given ontology document
* </p>
*
* @param docURI The public URI of the ontology document
* @param model A model containing the triples from the document
* @param replace If true, replace any existing entry with this one.
*/
public void addModel( String docURI, Model model, boolean replace ) {
if (getFileManager().getCachingModels() &&
(replace || !getFileManager().hasCachedModel( docURI )))
{
getFileManager().addCacheModel( docURI, model );
}
}
/**
* <p>
* Add an entry that <code>language</code> is the URI defining the
* representation language for the given document
* </p>
*
* @param docURI The public URI of the ontology document
* @param language A string defining the URI of the language
* @deprecated Language determination via the ODM will be removed from Jena 2.4 onwards
*/
public void addLanguageEntry( String docURI, String language ) {
m_languageMap.put( docURI, language );
}
/**
* <p>
* Remove all managed entries for the given document. Note does not side-effect
* the prefixes table: this will have to be done separately.
* </p>
*
* @param docURI The public URI for an ontology document
*/
public void forget( String docURI ) {
getFileManager().getLocationMapper().removeAltEntry( docURI );
getFileManager().removeCacheModel( docURI );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -