Class TypeMapper


  • public class TypeMapper
    extends java.lang.Object
    The TypeMapper provides a global registry of known datatypes. The datatypes can be retrieved by their URI or from the java class that is used to represent them.
    • Constructor Detail

      • TypeMapper

        public TypeMapper()
    • Method Detail

      • getInstance

        public static TypeMapper getInstance()
        Return the single global instance of the TypeMapper. Done this way rather than simply making the static field directly accessible to allow us to dynamically replace the entire mapper table if needed.
      • setInstance

        public static void setInstance​(TypeMapper typeMapper)
      • reset

        public static void reset()
      • getSafeTypeByName

        public RDFDatatype getSafeTypeByName​(java.lang.String uri)
        Version of getTypeByName which will treat unknown URIs as typed literals but with just the default implementation

        RDF 1.1: null for uri returns null and it will mean xsd:string because plain literals (no lang tag) and xsd:strings are now the same.

        Parameters:
        uri - the URI of the desired datatype
        Returns:
        Datatype the datatype definition registered at uri, if there is no such registered type it returns a new instance of the default datatype implementation, if the uri is null it returns null (indicating a plain RDF literal).
      • getTypeByName

        public RDFDatatype getTypeByName​(java.lang.String uri)
        Lookup a known datatype. An unknown datatype or a datatype with uri null will return null will mean that the value will be treated as a old-style plain literal.
        Parameters:
        uri - the URI of the desired datatype
        Returns:
        Datatype the datatype definition of null if not known.
      • getTypeByValue

        public RDFDatatype getTypeByValue​(java.lang.Object value)
        Method getTypeByValue. Look up a datatype suitable for representing the given java value object.
        Parameters:
        value - a value instance to be represented
        Returns:
        Datatype a datatype whose value space matches the java class of value
      • listTypes

        public java.util.Iterator<RDFDatatype> listTypes()
        List all the known datatypes
      • getTypeByClass

        public RDFDatatype getTypeByClass​(java.lang.Class<?> clazz)
        Look up a datatype suitable for representing instances of the given Java class.
        Parameters:
        clazz - a Java class to be represented
        Returns:
        a datatype whose value space matches the given java class
      • registerDatatype

        public void registerDatatype​(RDFDatatype type)
        Register a new datatype
      • unregisterDatatype

        public void unregisterDatatype​(RDFDatatype type)
        Remove a datatype registration.