org.jrdf.graph.datatype
Class DatatypeFactoryImpl

java.lang.Object
  extended by org.jrdf.graph.datatype.DatatypeFactoryImpl
All Implemented Interfaces:
DatatypeFactory

public class DatatypeFactoryImpl
extends Object
implements DatatypeFactory


Constructor Summary
DatatypeFactoryImpl(Map<URI,ValueCreator> newCreatorMap)
           
 
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 newObject)
          Create a datatyped literal from a Java class.
 DatatypeValue createValue(String newLexicalForm)
          Create an untyped/plain datatype from the lexical form.
 DatatypeValue createValue(URI dataTypeURI, String newLexicalForm)
          Create a new datatype value based on a given lexical form and datatype.
static DatatypeFactory getInstance()
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatatypeFactoryImpl

public DatatypeFactoryImpl(Map<URI,ValueCreator> newCreatorMap)
Method Detail

getInstance

public static DatatypeFactory getInstance()

hasRegisteredValueCreator

public boolean hasRegisteredValueCreator(URI datatypeURI)
Description copied from interface: DatatypeFactory
Returns true if a value creator has been registered for a given URI.

Specified by:
hasRegisteredValueCreator in interface DatatypeFactory
Parameters:
datatypeURI - the URI to check.
Returns:
true if a value creator has been registered for a given URI.

correctValueType

public boolean correctValueType(DatatypeValue value,
                                URI datatypeURI)
Description copied from interface: DatatypeFactory
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.

Specified by:
correctValueType in interface DatatypeFactory
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.

hasClassRegistered

public boolean hasClassRegistered(Class<?> aClass)
Description copied from interface: DatatypeFactory
Returns true if the class is registered.

Specified by:
hasClassRegistered in interface DatatypeFactory
Parameters:
aClass - the class to check.
Returns:
true if the class is registered.

addValueCreator

public void addValueCreator(URI datatypeURI,
                            ValueCreator creator)
                     throws IllegalArgumentException
Description copied from interface: DatatypeFactory
Add a value create for a given URI. Enforces one value creator per data type - check with hasRegisteredValueCreator.

Specified by:
addValueCreator in interface DatatypeFactory
Parameters:
datatypeURI - unique datatype uri.
creator - creates datatypes based on string.
Throws:
IllegalArgumentException - if datatype uri already registered with another creator.

addValueCreator

public void addValueCreator(URI datatypeURI,
                            Class<?> aClass,
                            ValueCreator creator)
Description copied from interface: DatatypeFactory
Add a value create for a given URI. Enforces one value creator per data type - check with hasRegisteredValueCreator.

Specified by:
addValueCreator in interface DatatypeFactory
Parameters:
datatypeURI - unique datatype uri.
aClass - the Java class.
creator - creates datatypes based on string.

addSecondaryValueCreator

public void addSecondaryValueCreator(Class<?> aClass,
                                     URI datatypeURI,
                                     ValueCreator creator)
Description copied from interface: DatatypeFactory
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.

Specified by:
addSecondaryValueCreator in interface DatatypeFactory
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.

removeValueCreator

public boolean removeValueCreator(URI datatypeURI)
Description copied from interface: DatatypeFactory
Remove creator for a given URI.

Specified by:
removeValueCreator in interface DatatypeFactory
Parameters:
datatypeURI - the URI to check.
Returns:
true if the item was removed or no value creator was found.

removeValueCreator

public boolean removeValueCreator(Class<?> aClass,
                                  URI datatypeURI)
Description copied from interface: DatatypeFactory
Remove creator for a given class and URI.

Specified by:
removeValueCreator in interface DatatypeFactory
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

public DatatypeValue createValue(String newLexicalForm)
Description copied from interface: DatatypeFactory
Create an untyped/plain datatype from the lexical form.

Specified by:
createValue in interface DatatypeFactory
Parameters:
newLexicalForm - lexical form to use.
Returns:
new datatype value.

createValue

public DatatypeValue createValue(Object newObject)
Description copied from interface: DatatypeFactory
Create a datatyped literal from a Java class.

Specified by:
createValue in interface DatatypeFactory
Parameters:
newObject - Java class to use.
Returns:
new datatype value.

createValue

public DatatypeValue createValue(URI dataTypeURI,
                                 String newLexicalForm)
Description copied from interface: DatatypeFactory
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.

Specified by:
createValue in interface DatatypeFactory
Parameters:
dataTypeURI - datatype to use.
newLexicalForm - lexical form to use.
Returns:
new datatype value.

getObjectDatatypeURI

public URI getObjectDatatypeURI(Object object)
Description copied from interface: DatatypeFactory
Returns the URI bound to a given Java class.

Specified by:
getObjectDatatypeURI in interface DatatypeFactory
Parameters:
object - the object to use.
Returns:
the URI.