info.sswap.impl.empire.model
Class ModelImpl

java.lang.Object
  extended by info.sswap.impl.empire.model.ModelImpl
All Implemented Interfaces:
com.clarkparsia.empire.SupportsRdfId, SSWAPModel
Direct Known Subclasses:
ElementImpl, SourceModelImpl

public abstract class ModelImpl
extends java.lang.Object
implements SSWAPModel, com.clarkparsia.empire.SupportsRdfId

Implements SSWAPModel. The base class of all implementations of objects in SSWAP API. This class also implements SupportsRdfId, which is required for all Empire-managed classes. While actual Empire-managed classes are only few, and low in the hierarchy (e.g., PDG, Protocol Graphs, and Individuals), this interface provides an ability to relate this object with its definition in the RDF document (either via its URI or BNode Id). In general, the instances of this class will be a part of a SourceModel (aggregation). Since this object is (potentially) populated by data coming from an RDF graph, it has to be somehow related to that graph. SourceModel object is responsible for holding such a graph. Therefore, any dereferenced ModelImpl needs to have a reference to its SourceModel (and since the link between ModelImpl and SourceModel is bi-directional, the SourceModel also has a reference to the ModelImpl, as one of its dependent models). Note: the only current implementation of SourceModel interface is SourceModelImpl, and it inherits from ModelImpl. (For SourceModelImpl, the source model is the same as the object itself!)

Author:
Blazej Bulka

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.clarkparsia.empire.SupportsRdfId
com.clarkparsia.empire.SupportsRdfId.BNodeKey, com.clarkparsia.empire.SupportsRdfId.RdfKey<T>, com.clarkparsia.empire.SupportsRdfId.URIKey
 
Field Summary
private  boolean dereferenced
          Flag indicating whether the object has been dereferenced (true).
private  SourceModel sourceModel
          The reference to the source model; that is, the object that manages the Jena model containing the RDF data for this object.
 
Constructor Summary
protected ModelImpl()
          Initializes this object.
 
Method Summary
 void addImport(java.net.URI uri)
          Adds an import to the list of OWL imports of this model.
private  void addTermToSignature(java.util.Collection<java.net.URI> terms, java.lang.String uri)
           
protected  com.hp.hpl.jena.rdf.model.Model assertModel()
           
protected  SourceModel assertSourceModel()
          Gets the source model of a dereferenced ModelImpl
private  boolean belongs2RDForOWLVocabulary(java.lang.String term)
           
 boolean checkProfile(Expressivity expressivity)
          Checks whether the model fits a particular expressivity profile (e.g., OWL2 DL)
 void dereference()
          If the object is not dereferenced, it dereferences it.
 void dereference(java.io.InputStream is)
          Dereferences the object (if it is not yet dereferenced) but it reads the data from the given stream, rather than trying to to retrieve the URI of this object.
 int doClosure()
          For every URI in the model, do successive HTTP GETs and read in the model.
protected
<T extends ModelImpl>
java.util.Collection<T>
getAllDependentObjects(java.lang.Class<T> clazz)
           
protected
<T extends ModelImpl>
T
getDependentObject(java.lang.Class<T> clazz)
          Creates an object based on the data from the same data source as this one (e.g., if this object represents a PDG, it allows to get a SSWAPProvider from this data source; or a SSWAPResource from RDG).
 SSWAPDocument getDocument()
          Retrieves the document that contains this SSWAPModel
 Expressivity getExpressivity()
           
 java.util.Collection<java.lang.String> getImports()
          Gets the list of OWL imports in this model (the top-level only).
 java.io.InputStream getInputStream()
          Get input stream suitable for reading the serialized model.
 java.util.Map<java.lang.String,java.lang.String> getNsPrefixMap()
          Gets the map of currently defined namespace prefixes.
 ReasoningService getReasoningService()
          Gets the reasoning service associated with the underlying RDF data
 SourceModel getSourceModel()
          Gets a reference to the current source model of this object (i.e., the object that holds the RDF graph that is the source of data for this object).
 java.util.Collection<java.net.URI> getTypeSignature(java.net.URI type)
          Get the terms that comprise the definition of a URI term.
 java.net.URI getURI()
          Get the URI.
protected  boolean hasSourceModel()
          Checks whether this model has a source model associated with it
protected  boolean hasSourceModelWithEntityManager()
          Checks whether this model has a source model associated with it that has an entity manager.
 boolean isDereferenced()
          Returns whether this object represents a dereferenced content stored under the URI, or is it just the URI.
 void persist()
          Writes back the changes to the underlying RDF graph.
protected  boolean rdfIdEquals(ModelImpl other)
           
protected  int rdfIdHashCode()
           
 void refresh()
          Refreshes the data of this object (should be called, if the underlying RDF graph changed).
protected  void refreshSiblings()
          Refreshes SSWAPModels that are considered siblings of this one (i.e., models that have the same URI).
 void removeImport(java.net.URI uri)
          Removes an import from the list of imports
 void removeNsPrefix(java.lang.String prefix)
          Removes a namespace prefix.
 void serialize(java.io.OutputStream os)
          Serializes the contents of this object to the specified stream as RDF/XML.
 void serialize(java.io.OutputStream os, RDFRepresentation representation, boolean commentedOutput)
          Serializes the contents of this object to the specified stream.
protected  void setDereferenced(boolean dereferenced)
          Sets the dereference flag.
 void setNsPrefix(java.lang.String prefix, java.net.URI uri)
          Sets a namespace prefix that will be used in serialization of this model.
 void setSourceModel(SourceModel sourceModel)
          Sets the source model for this object (i.e., the object that actually holds the Jena model with RDF data).
 void setURI(java.net.URI uri)
          Sets the URI of this object.
 void validate()
          Verifies whether the underlying RDF data conforms to SSWAP syntax and requirements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.clarkparsia.empire.SupportsRdfId
getRdfId, setRdfId
 

Field Detail

dereferenced

private boolean dereferenced
Flag indicating whether the object has been dereferenced (true). TODO: Verify whether this flag is really necessary, and maybe the information about the dereferencing should be taken from the source model, if one exist. (In the case, it does not exist, it is obvious that an object has not been dereferenced).


sourceModel

private SourceModel sourceModel
The reference to the source model; that is, the object that manages the Jena model containing the RDF data for this object. Note: if this object is a source model, this reference may be identical with "this" reference. (Keep this in mind to avoid infinite calls.)

Constructor Detail

ModelImpl

protected ModelImpl()
Initializes this object. Since this is an abstract class, this constructor is protected -- this constructor should only be called when an actual implementation is created.

Method Detail

dereference

public void dereference()
Description copied from interface: SSWAPModel
If the object is not dereferenced, it dereferences it. This involves retrieving the underlying RDF data, and may result in a network connection.

Specified by:
dereference in interface SSWAPModel

dereference

public void dereference(java.io.InputStream is)
Description copied from interface: SSWAPModel
Dereferences the object (if it is not yet dereferenced) but it reads the data from the given stream, rather than trying to to retrieve the URI of this object. (Avoids network connectivity.)

Specified by:
dereference in interface SSWAPModel
Parameters:
is - the input stream from which the data should be read instead of establishing a network connection

doClosure

public int doClosure()
Description copied from interface: SSWAPModel
For every URI in the model, do successive HTTP GETs and read in the model. Assume RDF/XML. Closure obeys rules of self-definition. Dereferencing is limited by depth and response time, such that performing a closure results in many HTTP GET calls; the result of which may differ depending on network conditions and third-party server response.

Specified by:
doClosure in interface SSWAPModel
Returns:
the highest (deepest) level of closure achieved.

getExpressivity

public Expressivity getExpressivity()

checkProfile

public boolean checkProfile(Expressivity expressivity)
Description copied from interface: SSWAPModel
Checks whether the model fits a particular expressivity profile (e.g., OWL2 DL)

Specified by:
checkProfile in interface SSWAPModel
Parameters:
expressivity - expressivity profile
Returns:
true if the model fits the specified expressivity

getInputStream

public java.io.InputStream getInputStream()
Description copied from interface: SSWAPModel
Get input stream suitable for reading the serialized model.

Specified by:
getInputStream in interface SSWAPModel
Returns:
An input stream suitable for reading

getURI

public java.net.URI getURI()
Description copied from interface: SSWAPModel
Get the URI. For RDGs, RIGs, and RRGs, return the URI of the sswapResource (for RQGs, leave undefined for now). For PDGs return the URI of the sswapProvider. Return null on failure.

Specified by:
getURI in interface SSWAPModel
Returns:
the URI, such that if the model is serialized and hosted on the web, when dereferenced retrieves the model

setURI

public void setURI(java.net.URI uri)
Sets the URI of this object. This method should be called only once in the lifetime of the object.

Parameters:
uri - the new uri of the object

isDereferenced

public boolean isDereferenced()
Description copied from interface: SSWAPModel
Returns whether this object represents a dereferenced content stored under the URI, or is it just the URI. For objects that have not been dereferenced, the only valid methods are getURI(), isDereferenced(), and dereference().

Specified by:
isDereferenced in interface SSWAPModel
Returns:
true if the object has already been dereferenced

setDereferenced

protected void setDereferenced(boolean dereferenced)
Sets the dereference flag. This method will be called by the more concrete classes.

Parameters:
dereferenced - true if the object has been dereference, false otherwise

serialize

public void serialize(java.io.OutputStream os)
Description copied from interface: SSWAPModel
Serializes the contents of this object to the specified stream as RDF/XML.

Specified by:
serialize in interface SSWAPModel
Parameters:
os - output stream

serialize

public void serialize(java.io.OutputStream os,
                      RDFRepresentation representation,
                      boolean commentedOutput)
Description copied from interface: SSWAPModel
Serializes the contents of this object to the specified stream.

Specified by:
serialize in interface SSWAPModel
Parameters:
os - output stream
representation - the representation, in which the contents should be written (e.g., RDF/XML).
commentedOutput - true, if the output should contain comments about various standard sections of an RDG (valid only for RDF/XML)

validate

public void validate()
              throws ValidationException
Description copied from interface: SSWAPModel
Verifies whether the underlying RDF data conforms to SSWAP syntax and requirements.

Specified by:
validate in interface SSWAPModel
Throws:
ValidationException - if the data violates SSWAP syntax or requirements

setSourceModel

public void setSourceModel(SourceModel sourceModel)
Sets the source model for this object (i.e., the object that actually holds the Jena model with RDF data). If this object has currently a model, it will be removed from it.

Parameters:
sourceModel - the new source model

getSourceModel

public SourceModel getSourceModel()
Gets a reference to the current source model of this object (i.e., the object that holds the RDF graph that is the source of data for this object). If this object is the source model for itself, this method will return "this".

Returns:
source model for this object. (Will be null for non-dereferenced objects.)

getDependentObject

protected <T extends ModelImpl> T getDependentObject(java.lang.Class<T> clazz)
Creates an object based on the data from the same data source as this one (e.g., if this object represents a PDG, it allows to get a SSWAPProvider from this data source; or a SSWAPResource from RDG). This method assumes that there is only one suitable object of the given type (in case there is more, it will return the first one).

Type Parameters:
T - parameterized type of an Empire-annotated class to define what kind of data has to be retrieved
Parameters:
clazz - the Empire-annotated class
Returns:
an object retrieved from the underlying RDF graph or null if there is no data in the RDF (or RDF at all, because the object is not dereferenced or connected to any SourceModel).

getAllDependentObjects

protected <T extends ModelImpl> java.util.Collection<T> getAllDependentObjects(java.lang.Class<T> clazz)

refresh

public void refresh()
Refreshes the data of this object (should be called, if the underlying RDF graph changed). The current implementation does nothing, and it is expected to be overriden by the more concrete implementations of this class.


persist

public void persist()
Writes back the changes to the underlying RDF graph. The current implementation does nothing


refreshSiblings

protected void refreshSiblings()
Refreshes SSWAPModels that are considered siblings of this one (i.e., models that have the same URI). Calling this method will not cause refresh of this object.


getReasoningService

public ReasoningService getReasoningService()
Description copied from interface: SSWAPModel
Gets the reasoning service associated with the underlying RDF data

Specified by:
getReasoningService in interface SSWAPModel
Returns:
the reasoning service

rdfIdEquals

protected boolean rdfIdEquals(ModelImpl other)

rdfIdHashCode

protected int rdfIdHashCode()

setNsPrefix

public void setNsPrefix(java.lang.String prefix,
                        java.net.URI uri)
Description copied from interface: SSWAPModel
Sets a namespace prefix that will be used in serialization of this model.

Specified by:
setNsPrefix in interface SSWAPModel
Parameters:
prefix - the prefix
uri - the corresponding URI

removeNsPrefix

public void removeNsPrefix(java.lang.String prefix)
Description copied from interface: SSWAPModel
Removes a namespace prefix. (The prefixes are used in serialization of this model.)

Specified by:
removeNsPrefix in interface SSWAPModel
Parameters:
prefix - the prefix to be removed.

getNsPrefixMap

public java.util.Map<java.lang.String,java.lang.String> getNsPrefixMap()
Description copied from interface: SSWAPModel
Gets the map of currently defined namespace prefixes. (These prefixes are used in serialization of this model.)

Specified by:
getNsPrefixMap in interface SSWAPModel
Returns:
the map mapping prefixes to corresponding URIs

getImports

public java.util.Collection<java.lang.String> getImports()
Gets the list of OWL imports in this model (the top-level only).

Specified by:
getImports in interface SSWAPModel
Returns:
a collection of uris of the imports

addImport

public void addImport(java.net.URI uri)
Adds an import to the list of OWL imports of this model. Adding a URI to the list of imports does not trigger the import itself (use doClosure()) for that purpose.

Specified by:
addImport in interface SSWAPModel
Parameters:
uri - the URI of the import to be added

removeImport

public void removeImport(java.net.URI uri)
Removes an import from the list of imports

Specified by:
removeImport in interface SSWAPModel
Parameters:
uri - the import to be removed

hasSourceModel

protected boolean hasSourceModel()
Checks whether this model has a source model associated with it

Returns:
true if the model has a source model associated with it

hasSourceModelWithEntityManager

protected boolean hasSourceModelWithEntityManager()
Checks whether this model has a source model associated with it that has an entity manager.

Returns:
true if the model has a source model associated with it, and that source model has an entity manager.

assertSourceModel

protected SourceModel assertSourceModel()
                                 throws java.lang.IllegalArgumentException
Gets the source model of a dereferenced ModelImpl

Returns:
a source model of the passed model (never null)
Throws:
java.lang.IllegalArgumentException - if the model has not been dereferenced, and therefore does not have a source model

assertModel

protected com.hp.hpl.jena.rdf.model.Model assertModel()
                                               throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

getDocument

public SSWAPDocument getDocument()
Description copied from interface: SSWAPModel
Retrieves the document that contains this SSWAPModel

Specified by:
getDocument in interface SSWAPModel
Returns:
SSWAPDocument

getTypeSignature

public java.util.Collection<java.net.URI> getTypeSignature(java.net.URI type)
Description copied from interface: SSWAPModel
Get the terms that comprise the definition of a URI term. Results may be returned for any URI, but expected use is for cases where the URI is an OWL class (or type).

Specified by:
getTypeSignature in interface SSWAPModel
Parameters:
type - URI to a resource or subject of RDF statements
Returns:
For named (non-anonymous) types, return a Collection of solely the type itself; for anonymous types, return a Collection of all terms used to define the type (.e.g, terms used within owl:Restriction, etc.).

addTermToSignature

private void addTermToSignature(java.util.Collection<java.net.URI> terms,
                                java.lang.String uri)

belongs2RDForOWLVocabulary

private boolean belongs2RDForOWLVocabulary(java.lang.String term)


Copyright (c) 2011, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.