org.jrdf.graph.datatype
Interface DatatypeFactory

All Known Implementing Classes:
DatatypeFactoryImpl

public interface DatatypeFactory

Creates data types. Maps URIs to creators - which can take either a string or native object. For a given URI there is a signle string parser object and one or more native objects.


Method Summary
 void addSecondaryValueCreator(Class<?> aClass, URI datatypeURI, ValueCreator creator)
          If you want to bind more than one Java type to a given URI use this for alternative bindings.
 void addValueCreator(URI datatypeURI, Class<?> aClass, ValueCreator creator)
          Add a value create for a given URI.
 void addValueCreator(URI datatypeURI, ValueCreator creator)
          Add a value create for a given URI.
 boolean correctValueType(DatatypeValue value, URI datatypeURI)
          Allows the user to verify that the Value created is the correct type for the given URI.
 DatatypeValue createValue(Object object)
          Create a datatyped literal from a Java class.
 DatatypeValue createValue(String lexicalForm)
          Create an untyped/plain datatype from the lexical form.
 DatatypeValue createValue(URI dataTypeURI, String lexicalForm)
          Create a new datatype value based on a given lexical form and datatype.
 URI getObjectDatatypeURI(Object object)
          Returns the URI bound to a given Java class.
 boolean hasClassRegistered(Class<?> aClass)
          Returns true if the class is registered.
 boolean hasRegisteredValueCreator(URI datatypeURI)
          Returns true if a value creator has been registered for a given URI.
 boolean removeValueCreator(Class<?> aClass, URI datatypeURI)
          Remove creator for a given class and URI.
 boolean removeValueCreator(URI datatypeURI)
          Remove creator for a given URI.
 

Method Detail

addValueCreator

void addValueCreator(URI datatypeURI,
                     ValueCreator creator)
                     throws IllegalArgumentException
Add a value create for a given URI. Enforces one value creator per data type - check with hasRegisteredValueCreator.

Parameters:
datatypeURI - unique datatype uri.
creator - creates datatypes based on string.
Throws:
IllegalArgumentException - if datatype uri already registered with another creator.

addValueCreator

void addValueCreator(URI datatypeURI,
                     Class<?> aClass,
                     ValueCreator creator)
                     throws IllegalArgumentException
Add a value create for a given URI. Enforces one value creator per data type - check with hasRegisteredValueCreator.

Parameters:
datatypeURI - unique datatype uri.
aClass - the Java class.
creator - creates datatypes based on string.
Throws:
IllegalArgumentException - if datatype uri already registered with another creator.

addSecondaryValueCreator

void addSecondaryValueCreator(Class<?> aClass,
                              URI datatypeURI,
                              ValueCreator creator)
If you want to bind more than one Java type to a given URI use this for alternative bindings. For example, XSD Date can be bound to java.util.GregorianCalendar, java.util.Date or java.sql.Date. The secondary types are java.util.Date and java.sql.Date.

Parameters:
aClass - the Java class to bind to a given URI and ValueCreator.
datatypeURI - the URI to bind.
creator - the creator to use to convert the class to a Value.

hasRegisteredValueCreator

boolean hasRegisteredValueCreator(URI datatypeURI)
Returns true if a value creator has been registered for a given URI.

Parameters:
datatypeURI - the URI to check.
Returns:
true if a value creator has been registered for a given URI.

removeValueCreator

boolean removeValueCreator(URI datatypeURI)
Remove creator for a given URI.

Parameters:
datatypeURI - the URI to check.
Returns:
true if the item was removed or no value creator was found.

removeValueCreator

boolean removeValueCreator(Class<?> aClass,
                           URI datatypeURI)
Remove creator for a given class and URI.

Parameters:
aClass - the class that's registered.
datatypeURI - the URI to check.
Returns:
true if the item was removed or no value creator was found.

createValue

DatatypeValue createValue(String lexicalForm)
Create an untyped/plain datatype from the lexical form.

Parameters:
lexicalForm - lexical form to use.
Returns:
new datatype value.

createValue

DatatypeValue createValue(Object object)
                          throws IllegalArgumentException
Create a datatyped literal from a Java class.

Parameters:
object - Java class to use.
Returns:
new datatype value.
Throws:
IllegalArgumentException - if to creator is registered for the Java class.

createValue

DatatypeValue createValue(URI dataTypeURI,
                          String lexicalForm)
Create a new datatype value based on a given lexical form and datatype. Returns a string datatype if no creator is registered for the given URI.

Parameters:
dataTypeURI - datatype to use.
lexicalForm - lexical form to use.
Returns:
new datatype value.

getObjectDatatypeURI

URI getObjectDatatypeURI(Object object)
Returns the URI bound to a given Java class.

Parameters:
object - the object to use.
Returns:
the URI.
Throws:
IllegalArgumentException - if there is no creator bound for the Java class.

hasClassRegistered

boolean hasClassRegistered(Class<?> aClass)
Returns true if the class is registered.

Parameters:
aClass - the class to check.
Returns:
true if the class is registered.

correctValueType

boolean correctValueType(DatatypeValue value,
                         URI datatypeURI)
Allows the user to verify that the Value created is the correct type for the given URI. The default behaviour of the factory is to create untyped strings if there is an error parsing the string. For example, trying to parse and XSD.Date with the string "abc" will result in a Value with the lexical form "abc" but be a StringValue. This allows you to check that the Value returned is what is expected.

Parameters:
value - the value to check.
datatypeURI - the URI to use to see if the value is the expected type.
Returns:
true if the value is the correctly bound type of the given URI.