info.sswap.http.rest
Class TypeFactory

java.lang.Object
  extended by info.sswap.http.rest.DefinitionFactoryBase
      extended by info.sswap.http.rest.TypeFactory

public class TypeFactory
extends DefinitionFactoryBase

A factory for complex types based on their JSON representation

Author:
Blazej Bulka

Field Summary
private static TypeFactory instance
          The single instance of this class.
private static java.util.Set<java.lang.String> NON_RESTRICTION_PROPERTIES
          A set of URIs (as Strings) that represent all supported properties -- any other property occurrence, which not mentioned here is, will be treated as a restriction on that property.
private static java.util.Set<java.lang.String> OWL_TYPES
           
 
Constructor Summary
private TypeFactory()
          A private constructor (singleton implementation)
 
Method Summary
 void checkReservedVocabulary(java.lang.String typeURI)
           
 void checkReservedVocabularyRef(java.lang.String typeURI)
           
private  boolean containsOnlyRestrictions(Entity entity)
          Checks whether the given JSON object contains only properties that encode restrictions.
private  java.util.Collection<info.sswap.api.model.SSWAPType> createRestrictions(info.sswap.api.model.SSWAPDocument document, Entity jsonEntity)
          Creates owl:Restrictions from a JSON object
private  void createRestrictions(info.sswap.api.model.SSWAPDocument document, Entity jsonEntity, java.util.List<info.sswap.api.model.SSWAPType> regularRestrictions, java.util.List<info.sswap.api.model.SSWAPType> markerRestrictions)
           
private  void createRestrictions(info.sswap.api.model.SSWAPDocument document, info.sswap.api.model.SSWAPPredicate predicate, Entity jsonEntity, java.util.List<info.sswap.api.model.SSWAPType> regularRestrictions, java.util.List<info.sswap.api.model.SSWAPType> markerRestrictions)
          Creates restriction(s) for a single property, e.g., encoded as: "property" : { "owl:minCardinality" : 1^^"xsd:integer", "owl:allValuesFrom" : "map:Map", } (The example above will generate two restrictions)
 java.util.Collection<info.sswap.api.model.SSWAPType> createSubTypes(info.sswap.api.model.SSWAPDocument document, Value value)
          Creates types based on the JSON value description.
 info.sswap.api.model.SSWAPType createType(info.sswap.api.model.SSWAPDocument document, Entity jsonType)
          Creates a SSWAP type based on its JSON description
 info.sswap.api.model.SSWAPType createType(info.sswap.api.model.SSWAPDocument document, Value value)
          Creates a type based on its JSON value description.
static TypeFactory get()
          The getter for the singleton instance
private  void initializeAnonymousType(info.sswap.api.model.SSWAPType type, Entity jsonType)
          Initializes an anonymous type (that is not a restriction).
private  void initializeNamedType(info.sswap.api.model.SSWAPType type, Entity jsonType)
          Initializes a named type.
private  boolean isAnnotationPredicate(java.lang.String propertyName, info.sswap.api.model.SSWAPDocument document)
           
 
Methods inherited from class info.sswap.http.rest.DefinitionFactoryBase
createURICollection, getString, getValuesAsLiteralCollection, getValuesAsPropertyValues, getValuesAsStringCollection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NON_RESTRICTION_PROPERTIES

private static final java.util.Set<java.lang.String> NON_RESTRICTION_PROPERTIES
A set of URIs (as Strings) that represent all supported properties -- any other property occurrence, which not mentioned here is, will be treated as a restriction on that property.


OWL_TYPES

private static final java.util.Set<java.lang.String> OWL_TYPES

instance

private static TypeFactory instance
The single instance of this class.

Constructor Detail

TypeFactory

private TypeFactory()
A private constructor (singleton implementation)

Method Detail

get

public static TypeFactory get()
The getter for the singleton instance

Returns:
sole instance of this TypeFactory

createType

public info.sswap.api.model.SSWAPType createType(info.sswap.api.model.SSWAPDocument document,
                                                 Entity jsonType)
                                          throws java.lang.IllegalArgumentException
Creates a SSWAP type based on its JSON description

Parameters:
document - the SSWAPModel where the type should be created
jsonType - the JSON description of the type
Returns:
the created type
Throws:
java.lang.IllegalArgumentException

initializeNamedType

private void initializeNamedType(info.sswap.api.model.SSWAPType type,
                                 Entity jsonType)
                          throws java.lang.IllegalArgumentException
Initializes a named type. The named types have to be handled differently than unnamed ones because they can be OWL class expressions in their own right (as opposed to an unnamed type, which can be a class expression only if it e.g., represents an intersection or a restriction). Initialization processes all declared JSON properties and constructs appropriate SSWAP/OWL definitions.

Parameters:
type - the type to be initialized
jsonType - the JSON structure describing the named type
Throws:
java.lang.IllegalArgumentException

initializeAnonymousType

private void initializeAnonymousType(info.sswap.api.model.SSWAPType type,
                                     Entity jsonType)
                              throws java.lang.IllegalArgumentException
Initializes an anonymous type (that is not a restriction). In this method we do not allow such an anonymous type to participate in many relations (e.g., no rdfs:subClassOf in the subject position).

Parameters:
type - the anonymous type being initialized
jsonType - JSON describing the type
Throws:
java.lang.IllegalArgumentException

createRestrictions

private java.util.Collection<info.sswap.api.model.SSWAPType> createRestrictions(info.sswap.api.model.SSWAPDocument document,
                                                                                Entity jsonEntity)
                                                                         throws java.lang.IllegalArgumentException
Creates owl:Restrictions from a JSON object

Parameters:
document - the SSWAPDocument which will hold the created restrictions
jsonEntity - the JSON object
Returns:
the created restrictions
Throws:
java.lang.IllegalArgumentException

createRestrictions

private void createRestrictions(info.sswap.api.model.SSWAPDocument document,
                                Entity jsonEntity,
                                java.util.List<info.sswap.api.model.SSWAPType> regularRestrictions,
                                java.util.List<info.sswap.api.model.SSWAPType> markerRestrictions)
                         throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

createRestrictions

private void createRestrictions(info.sswap.api.model.SSWAPDocument document,
                                info.sswap.api.model.SSWAPPredicate predicate,
                                Entity jsonEntity,
                                java.util.List<info.sswap.api.model.SSWAPType> regularRestrictions,
                                java.util.List<info.sswap.api.model.SSWAPType> markerRestrictions)
                         throws java.lang.IllegalArgumentException
Creates restriction(s) for a single property, e.g., encoded as: "property" : { "owl:minCardinality" : 1^^"xsd:integer", "owl:allValuesFrom" : "map:Map", } (The example above will generate two restrictions)

Parameters:
document - the model where the restrictions will be stored
predicate - the property for which the restrictions are to be encoded
jsonEntity - the JSON object for that property
regularRestrictions - a list to which the regular restrictions will be added (i.e., the restrictions that actually restrict the type)
markerRestrictions - a list to which marker restrictions will be added (i.e., the restrictions that are essentially equivalent to owl:Thing, and therefore do not restrict the type at all; yet they mark certain properties as being optional.)
Throws:
java.lang.IllegalArgumentException

createType

public info.sswap.api.model.SSWAPType createType(info.sswap.api.model.SSWAPDocument document,
                                                 Value value)
                                          throws java.lang.IllegalArgumentException
Creates a type based on its JSON value description. This method should only be used if a single type is expected to be produced by the description. If the JSON value should generate different number of class expressions (0 or more than 1), an IllegalArgumentException will be thrown. (For example, a construct "owl:allValuesFrom" : { ... } should only construct a single type.)

Parameters:
document - the SSWAPDocument where the type should be created
value - a JSON value encoding a (hopefully) single type
Returns:
the created type
Throws:
java.lang.IllegalArgumentException - if either 0 or more than 1 result is found

createSubTypes

public java.util.Collection<info.sswap.api.model.SSWAPType> createSubTypes(info.sswap.api.model.SSWAPDocument document,
                                                                           Value value)
                                                                    throws java.lang.IllegalArgumentException
Creates types based on the JSON value description.

Parameters:
document - the SSWAPDocument where the types should be created
value - the value describing the types
Returns:
the created types
Throws:
java.lang.IllegalArgumentException - on an invalid URI

containsOnlyRestrictions

private boolean containsOnlyRestrictions(Entity entity)
Checks whether the given JSON object contains only properties that encode restrictions.

Parameters:
entity - the entity to be checked
Returns:
true if the only properties are encoding restrictions

checkReservedVocabularyRef

public void checkReservedVocabularyRef(java.lang.String typeURI)
                                throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

checkReservedVocabulary

public void checkReservedVocabulary(java.lang.String typeURI)
                             throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

isAnnotationPredicate

private boolean isAnnotationPredicate(java.lang.String propertyName,
                                      info.sswap.api.model.SSWAPDocument document)


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