info.sswap.http.rest
Class EntityFactory

java.lang.Object
  extended by info.sswap.http.rest.EntityFactory

public class EntityFactory
extends java.lang.Object

A class for creating SSWAPEntities based on their JSON description.

Author:
Blazej Bulka

Field Summary
private  java.util.Map<java.lang.String,java.net.URI> anonURIMapping
           
private  java.util.Set<java.lang.String> initializedEntities
           
 
Constructor Summary
private EntityFactory()
          Private constructor for a singleton
 
Method Summary
private  info.sswap.api.model.SSWAPElement createDefaultLiteralValue(info.sswap.api.model.SSWAPDocument document, java.lang.String typeURI)
          Creates a literal SSWAPElement that holds a default value for its type
private
<T extends info.sswap.api.model.SSWAPIndividual>
T
createEmptyEntity(info.sswap.api.model.SSWAPDocument document, java.lang.String uri, java.lang.Class<T> entityClass)
          Creates an entity with no properties initialized yet.
<T extends info.sswap.api.model.SSWAPIndividual>
T
createEntity(info.sswap.api.model.SSWAPDocument document, Entity jsonEntity, java.lang.Class<T> entityClass)
          Creates a SSWAPIndividual in the given model based on its definition in JSON
private  info.sswap.api.model.SSWAPIndividual createEntityValue(info.sswap.api.model.SSWAPDocument document, java.lang.String uri, java.lang.String typeURI)
          Creates a SSWAP Entity for a property value
private  info.sswap.api.model.SSWAPIndividual createPropertyEntityValue(info.sswap.api.model.SSWAPModel entity, info.sswap.api.model.SSWAPPredicate predicate, Value jsonValue)
          Creates a anonymous entity value for a property (object property)
private  info.sswap.api.model.SSWAPElement createPropertyLiteralValue(info.sswap.api.model.SSWAPModel entity, info.sswap.api.model.SSWAPPredicate predicate, Value jsonValue)
          Creates a literal value for a property (a datatype property)
 info.sswap.api.model.SSWAPElement createPropertyValue(info.sswap.api.model.SSWAPModel entity, info.sswap.api.model.SSWAPPredicate predicate, Value jsonValue)
          Creates a value for a property.
static EntityFactory get()
          The access method to the singleton instance.
private  java.net.URI getAnonURI(java.lang.String anonQName)
           
private  void initializeProperties(info.sswap.api.model.SSWAPIndividual entity, Entity jsonEntity)
          Initializes SSWAPProperties/SSWAPTypes for the entity
 void initializeProperties(info.sswap.api.model.SSWAPIndividual entity, Entity jsonEntity, java.util.Collection<java.lang.String> excludedProperties)
           
private  void initializePropertyValue(info.sswap.api.model.SSWAPIndividual entity, Property jsonProperty, Value jsonValue)
           
private  void initializeTypeProperty(info.sswap.api.model.SSWAPIndividual entity, Value typeValue)
          Initializes rdf:type property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

anonURIMapping

private java.util.Map<java.lang.String,java.net.URI> anonURIMapping

initializedEntities

private java.util.Set<java.lang.String> initializedEntities
Constructor Detail

EntityFactory

private EntityFactory()
Private constructor for a singleton

Method Detail

get

public static EntityFactory get()
The access method to the singleton instance.

Returns:
the EntityFactory instance

createEntity

public <T extends info.sswap.api.model.SSWAPIndividual> T createEntity(info.sswap.api.model.SSWAPDocument document,
                                                                       Entity jsonEntity,
                                                                       java.lang.Class<T> entityClass)
                                                            throws java.lang.IllegalArgumentException
Creates a SSWAPIndividual in the given model based on its definition in JSON

Parameters:
document - SSWAPModel within which the entities should be created
jsonEntity - the JSON description of the entity
entityClass - the subclass of the SSWAPIndividual that should be created (e.g., SSWAPSubject.class, SSWAPObject.class or just SSWAPIndividual.class)
Returns:
the created entity
Throws:
java.lang.IllegalArgumentException - if one of the URIs in JSON was not a syntactically valid URI

getAnonURI

private java.net.URI getAnonURI(java.lang.String anonQName)

createEmptyEntity

private <T extends info.sswap.api.model.SSWAPIndividual> T createEmptyEntity(info.sswap.api.model.SSWAPDocument document,
                                                                             java.lang.String uri,
                                                                             java.lang.Class<T> entityClass)
                                                                  throws java.lang.IllegalArgumentException
Creates an entity with no properties initialized yet.

Type Parameters:
T -
Parameters:
document - the model within which the entity should be created
uri - the URI of the entity (may be null for anonymous entities)
entityClass - the subclass of the SSWAPIndividual that should be created (e.g., SSWAPSubject.class, SSWAPObject.class or just SSWAPIndividual.class)
Returns:
the created entity
Throws:
java.lang.IllegalArgumentException - if the URI is not a syntactically valid URI

initializeProperties

public void initializeProperties(info.sswap.api.model.SSWAPIndividual entity,
                                 Entity jsonEntity,
                                 java.util.Collection<java.lang.String> excludedProperties)

initializeProperties

private void initializeProperties(info.sswap.api.model.SSWAPIndividual entity,
                                  Entity jsonEntity)
                           throws java.lang.IllegalArgumentException
Initializes SSWAPProperties/SSWAPTypes for the entity

Parameters:
entity - the entity for which the properties should be initialized
jsonEntity - the JSON data describing the entity
Throws:
java.lang.IllegalArgumentException - if one of the URIs in JSON was not a syntactically valid URI

initializeTypeProperty

private void initializeTypeProperty(info.sswap.api.model.SSWAPIndividual entity,
                                    Value typeValue)
                             throws java.lang.IllegalArgumentException
Initializes rdf:type property. This method handles a variety of cases: (1) just a literal value: "rdf:type" : "ns:mytype" (2) an array value: "rdf:type" : [ "ns:mytype1", "ns:mytype2" ] (3) an anonymous type "rdf:type" : { "owl:unionOf" : [ "ns:mytype1", "ns:mytype2" ] } (4) Any mix of the above "rdf:type" : [ "ns:mytype1", { "owl:complementOf" : "ns:mytype2" } ]

Parameters:
entity - the entity whose type should be initialized
typeValue - the json intermediate representation for the type value
Throws:
java.lang.IllegalArgumentException - if the data is not syntactically valid

initializePropertyValue

private void initializePropertyValue(info.sswap.api.model.SSWAPIndividual entity,
                                     Property jsonProperty,
                                     Value jsonValue)
                              throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

createPropertyValue

public info.sswap.api.model.SSWAPElement createPropertyValue(info.sswap.api.model.SSWAPModel entity,
                                                             info.sswap.api.model.SSWAPPredicate predicate,
                                                             Value jsonValue)
                                                      throws java.lang.IllegalArgumentException
Creates a value for a property. This method determines (using the underlying ontology) whether the property is a datatype property or an object property, and delegates the actual value creation to an appropriate method for creating literals (datatype property) or entities (object property)

Parameters:
entity - the entity for which the value is created
predicate - the predicate for which the value is created
jsonValue - the JSON data describing the value
Returns:
the created value
Throws:
java.lang.IllegalArgumentException - if JSON data is not syntactically valid

createPropertyLiteralValue

private info.sswap.api.model.SSWAPElement createPropertyLiteralValue(info.sswap.api.model.SSWAPModel entity,
                                                                     info.sswap.api.model.SSWAPPredicate predicate,
                                                                     Value jsonValue)
                                                              throws java.lang.IllegalArgumentException
Creates a literal value for a property (a datatype property)

Parameters:
entity - the entity for which the value is created
predicate - the predicate for which the value is created (this should be a datatype property)
jsonValue - the JSON data describing the the value
Returns:
the created value
Throws:
java.lang.IllegalArgumentException - if the value encoded in JSON is not a literal (e.g., an entity or an array), or the literal is not a valid value for the inferred range of the datatype property

createPropertyEntityValue

private info.sswap.api.model.SSWAPIndividual createPropertyEntityValue(info.sswap.api.model.SSWAPModel entity,
                                                                       info.sswap.api.model.SSWAPPredicate predicate,
                                                                       Value jsonValue)
                                                                throws java.lang.IllegalArgumentException
Creates a anonymous entity value for a property (object property)

Parameters:
entity - the entity for which the value should be created (the subject of the property)
predicate - the predicate for which the value should be created
jsonValue - the JSON data describing the value. This can either be an actual entity or a literal containing the URI to the entity.
Returns:
the created entity
Throws:
java.lang.IllegalArgumentException - if the data encoded in JSON cannot be represented as an entity (e.g., it is an array)

createEntityValue

private info.sswap.api.model.SSWAPIndividual createEntityValue(info.sswap.api.model.SSWAPDocument document,
                                                               java.lang.String uri,
                                                               java.lang.String typeURI)
                                                        throws java.lang.IllegalArgumentException
Creates a SSWAP Entity for a property value

Parameters:
document - the model where the entity should be created
uri - the URI for the entity (may be null, which will result in an anonymous entity)
typeURI - the type of the entity (may be null)
Returns:
the created entity
Throws:
java.lang.IllegalArgumentException - if any of the passed non-null URIs is not syntactically valid

createDefaultLiteralValue

private info.sswap.api.model.SSWAPElement createDefaultLiteralValue(info.sswap.api.model.SSWAPDocument document,
                                                                    java.lang.String typeURI)
                                                             throws java.lang.IllegalArgumentException
Creates a literal SSWAPElement that holds a default value for its type

Parameters:
document - the model where SSWAPElement should be created
typeURI - the type of the element (may be null, which will return null value)
Returns:
the created SSWAPElement or null (nulls are returned for strings and untyped elements, since they do not require a default value for a property in a Subject or Object)
Throws:
java.lang.IllegalArgumentException - if the passed typeURI is not a syntactically valid URI


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