info.sswap.http.rest
Class PropertyFactory

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

public class PropertyFactory
extends DefinitionFactoryBase

Creates property definitions based on their description in JSON.

Author:
Blazej Bulka

Nested Class Summary
private static class PropertyFactory.PropertyType
          An enumeration for a type of a property: object property vs.
 
Field Summary
private static PropertyFactory instance
          The single instance of this factory.
 
Constructor Summary
private PropertyFactory()
          Private constructor for a singleton
 
Method Summary
private  info.sswap.api.model.SSWAPDatatype createComplexDatatype(info.sswap.api.model.SSWAPDocument document, Entity value)
           
private  info.sswap.api.model.SSWAPDatatype createDatatype(info.sswap.api.model.SSWAPDocument document, Value value)
           
private  java.util.Collection<info.sswap.api.model.SSWAPDatatype> createDatatypes(info.sswap.api.model.SSWAPDocument document, Value value)
           
private  java.util.Collection<info.sswap.api.model.SSWAPPredicate> createEmptyProperties(info.sswap.api.model.SSWAPDocument document, Value value)
           
private  info.sswap.api.model.SSWAPPredicate createEmptyProperty(info.sswap.api.model.SSWAPDocument document, Value value)
          Creates an empty SSWAPPredicate object with the given URI.
 info.sswap.api.model.SSWAPPredicate createPredicate(info.sswap.api.model.SSWAPDocument document, Entity jsonProperty)
          Creates a property definition in the specified model and based on the JSON description
private  PropertyFactory.PropertyType determinePropertyType(info.sswap.api.model.SSWAPPredicate predicate, Entity jsonPredicate)
          Determines the type of the property (object or datatype property).
static PropertyFactory get()
          The static getter for the singleton
private  void initializeProperty(info.sswap.api.model.SSWAPPredicate predicate, Entity jsonPredicate)
          Initializes an empty SSWAPPredicate during its creation process.
private  void initializePropertyTypes(info.sswap.api.model.SSWAPPredicate predicate, Entity jsonPredicate, PropertyFactory.PropertyType propertyType)
          Initializes property definition with type information (via rdf:type statements) based on the information explicitly declared in the JSON definition and type information guessed from the heuristics.
private  PropertyFactory.PropertyType processAnonymousRangeDefinition(Entity rangeDef)
          Processes an anonymous range definition in an attempt to detect the type of the property.
private  PropertyFactory.PropertyType processRangeAssertions(Entity jsonPredicate, PropertyFactory.PropertyType propertyType)
          Processes the rdfs:range definitions in JSON in order to determine whether the property is a datatype or an object property.
private  PropertyFactory.PropertyType processSubPropertyOfAssertions(info.sswap.api.model.SSWAPPredicate predicate, Entity jsonPredicate, PropertyFactory.PropertyType propertyType)
           
private  PropertyFactory.PropertyType processTypeAssertions(Entity jsonPredicate)
          Processes the rdf:type definitions in JSON in order to determine whether the property is a datatype or an object property
 
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

instance

private static PropertyFactory instance
The single instance of this factory.

Constructor Detail

PropertyFactory

private PropertyFactory()
Private constructor for a singleton

Method Detail

get

public static PropertyFactory get()
The static getter for the singleton

Returns:
the single instance

createPredicate

public info.sswap.api.model.SSWAPPredicate createPredicate(info.sswap.api.model.SSWAPDocument document,
                                                           Entity jsonProperty)
                                                    throws java.lang.IllegalArgumentException
Creates a property definition in the specified model and based on the JSON description

Parameters:
document - the SSWAPDocument where the definition should be created
jsonProperty - the JSON entity intermediate representation that describes the property
Returns:
the created property definition
Throws:
java.lang.IllegalArgumentException - on "anonymous" properties and invalid URIs

initializeProperty

private void initializeProperty(info.sswap.api.model.SSWAPPredicate predicate,
                                Entity jsonPredicate)
                         throws java.lang.IllegalArgumentException
Initializes an empty SSWAPPredicate during its creation process.

Parameters:
predicate - the property definition being intialized
jsonPredicate - the JSON description of the property
Throws:
java.lang.IllegalArgumentException

initializePropertyTypes

private void initializePropertyTypes(info.sswap.api.model.SSWAPPredicate predicate,
                                     Entity jsonPredicate,
                                     PropertyFactory.PropertyType propertyType)
                              throws java.lang.IllegalArgumentException
Initializes property definition with type information (via rdf:type statements) based on the information explicitly declared in the JSON definition and type information guessed from the heuristics.

Parameters:
predicate - the property definition to be initialized with type information
jsonPredicate - the JSON definition of the property
propertyType - the determined property type (either by analyzing explicit type information or by applying heuristics)
Throws:
java.lang.IllegalArgumentException

determinePropertyType

private PropertyFactory.PropertyType determinePropertyType(info.sswap.api.model.SSWAPPredicate predicate,
                                                           Entity jsonPredicate)
Determines the type of the property (object or datatype property). The determination is first based on explicitly provided types (via rdf:type). However, if there is no explicit type information, the method will analyze rdfs:range assertions to make a guess, and if that fails it will arbitrarily declare the property as a datatype property

Parameters:
jsonPredicate - the JSON definition of the property
Returns:
the determined property type

processTypeAssertions

private PropertyFactory.PropertyType processTypeAssertions(Entity jsonPredicate)
Processes the rdf:type definitions in JSON in order to determine whether the property is a datatype or an object property

Parameters:
jsonPredicate - the JSON property definition
Returns:
the determined property type or null (if there was not enough information to determine the type).
Throws:
java.lang.IllegalArgumentException - if the JSON description declares the property to be both Object and Datatype property

processSubPropertyOfAssertions

private PropertyFactory.PropertyType processSubPropertyOfAssertions(info.sswap.api.model.SSWAPPredicate predicate,
                                                                    Entity jsonPredicate,
                                                                    PropertyFactory.PropertyType propertyType)

processRangeAssertions

private PropertyFactory.PropertyType processRangeAssertions(Entity jsonPredicate,
                                                            PropertyFactory.PropertyType propertyType)
Processes the rdfs:range definitions in JSON in order to determine whether the property is a datatype or an object property.

Parameters:
jsonPredicate - the JSON property definition
Returns:
the determined property type or null (if there was not enough information to determine the type)

processAnonymousRangeDefinition

private PropertyFactory.PropertyType processAnonymousRangeDefinition(Entity rangeDef)
Processes an anonymous range definition in an attempt to detect the type of the property. Currently, we support detecting via analyzing values for owl:oneOf (i.e., ranges that are enumeration of allowed values). If one of the elements is an entity URI marked using the syntax with triangle brackets (< and >), we can safely assume that this is an object property. In all other cases, there is not enough information to accurately detect type. (Note: even if all values are parsable and valid URIs but they are not marked using the triangle bracket syntax, we still cannot tell anything about the type of the property -- the URIs may still be literals (either untyped literals or literals typed as xsd:anyURI), and then the property could be a datatype property).

Parameters:
rangeDef - the anonymous range definition
Returns:
null if property type cannot be determined

createEmptyProperties

private java.util.Collection<info.sswap.api.model.SSWAPPredicate> createEmptyProperties(info.sswap.api.model.SSWAPDocument document,
                                                                                        Value value)
                                                                                 throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

createEmptyProperty

private info.sswap.api.model.SSWAPPredicate createEmptyProperty(info.sswap.api.model.SSWAPDocument document,
                                                                Value value)
                                                         throws java.lang.IllegalArgumentException
Creates an empty SSWAPPredicate object with the given URI. (Used mostly to create objects to which rdfs:subPropertyOf, owl:equivalentProperty and owl:inverseOf could point.)

Parameters:
document - the SSWAPDocument which should contain the property definition
value - the value describing the URI (must be a literal)
Returns:
empty SSWAPPredicate
Throws:
java.lang.IllegalArgumentException - on "anonymous" properties and invalid URIs

createDatatypes

private java.util.Collection<info.sswap.api.model.SSWAPDatatype> createDatatypes(info.sswap.api.model.SSWAPDocument document,
                                                                                 Value value)
                                                                          throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

createDatatype

private info.sswap.api.model.SSWAPDatatype createDatatype(info.sswap.api.model.SSWAPDocument document,
                                                          Value value)
                                                   throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

createComplexDatatype

private info.sswap.api.model.SSWAPDatatype createComplexDatatype(info.sswap.api.model.SSWAPDocument document,
                                                                 Entity value)
                                                          throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException


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