org.apache.cayenne.access.types

## Class ExtendedTypeMap

- java.lang.Object
- - org.apache.cayenne.access.types.ExtendedTypeMap

-     public class ExtendedTypeMap
      extends Object

  Stores ExtendedTypes, implementing an algorithm to determine the right type for a given Java class. See `getRegisteredType(String)` documentation for lookup algorithm details.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ExtendedType` | `defaultType`
    `protected Map<String,String>` | `typeAliases`
    `protected Map<String,ExtendedType>` | `typeMap`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExtendedTypeMap()` Creates new ExtendedTypeMap, populating it with default JDBC-compatible types.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addFactory(ExtendedTypeFactory factory)` Adds an ExtendedTypeFactory that will be consulted if no direct mapping for a given class exists.
    `protected String` | `canonicalizedTypeName(String className)` For the class name returns a name "canonicalized" for the purpose of ExtendedType lookup.
    `protected ExtendedType` | `createType(String className)` Returns an ExtendedType for specific Java classes.
    `ExtendedType` | `getDefaultType()` Returns a default ExtendedType that is used to handle unmapped types.
    `ExtendedType` | `getRegisteredType(Class<?> javaClass)` Returns a type registered for the class name.
    `ExtendedType` | `getRegisteredType(String javaClassName)` Returns a guaranteed non-null ExtendedType instance for a given Java class name.
    `String[]` | `getRegisteredTypeNames()` Returns array of Java class names supported by Cayenne for JDBC mapping.
    `protected void` | `initDefaultFactories()` Registers default factories for creating enum types and serializable types.
    `void` | `registerType(ExtendedType type)` Adds a new type to the list of registered types.
    `void` | `removeFactory(ExtendedTypeFactory factory)` Removes a factory from the registered factories if it was previously added.
    `void` | `unregisterType(String javaClassName)` Removes registered ExtendedType object corresponding to `javaClassName` parameter.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### typeAliases

          protected Map<String,String> typeAliases

    - #### typeMap

          protected final Map<String,ExtendedType> typeMap

    - #### defaultType

          protected ExtendedType defaultType

  - ### Constructor Detail

    - #### ExtendedTypeMap

          public ExtendedTypeMap()

      Creates new ExtendedTypeMap, populating it with default JDBC-compatible types. If JDK version is at least 1.5, also loads support for enumerated types.

  - ### Method Detail

    - #### initDefaultFactories

          protected void initDefaultFactories()

      Registers default factories for creating enum types and serializable types. Note that user-defined factories are consulted before any default factory.
      Since:
        3.0

    - #### addFactory

          public void addFactory(ExtendedTypeFactory factory)

      Adds an ExtendedTypeFactory that will be consulted if no direct mapping for a given class exists. This feature can be used to map interfaces.

      Note that the order in which factories are added is important, as factories are consulted in turn when an ExtendedType is looked up, and lookup is stopped when any factory provides a non-null type.

      Since:
        1.2

    - #### removeFactory

          public void removeFactory(ExtendedTypeFactory factory)

      Removes a factory from the registered factories if it was previously added.
      Since:
        1.2

    - #### registerType

          public void registerType(ExtendedType type)

      Adds a new type to the list of registered types. If there is another type registered for a class described by the `type` argument, the old handler is overridden by the new one.

    - #### getDefaultType

          public ExtendedType getDefaultType()

      Returns a default ExtendedType that is used to handle unmapped types.

    - #### getRegisteredType

          public ExtendedType getRegisteredType(String javaClassName)

      Returns a guaranteed non-null ExtendedType instance for a given Java class name. Primitive class names are internally replaced by the non-primitive counterparts. The following lookup sequence is used to determine the type:
      - First the methods checks for an ExtendedType explicitly registered with the map for a given class name (most common types are registered by Cayenne internally; users can register their own).
      - Second, the method tries to obtain a type by iterating through `ExtendedTypeFactory` instances registered by users. If a factory returns a non-null type, it is returned to the user and the rest of the factories are ignored.
      - Third, the method iterates through standard `ExtendedTypeFactory` instances that can dynamically construct extended types for serializable objects and JDK 1.5 enums.
      - If all the methods above failed, the default type is returned that relies on default JDBC driver mapping to set and get objects.
      Note that for array types class name must be in the form 'MyClass[]'.

    - #### getRegisteredType

          public ExtendedType getRegisteredType(Class<?> javaClass)

      Returns a type registered for the class name. If no such type exists, returns the default type. It is guaranteed that this method returns a non-null ExtendedType instance.

    - #### unregisterType

          public void unregisterType(String javaClassName)

      Removes registered ExtendedType object corresponding to `javaClassName` parameter.

    - #### getRegisteredTypeNames

          public String[] getRegisteredTypeNames()

      Returns array of Java class names supported by Cayenne for JDBC mapping.

    - #### createType

          protected ExtendedType createType(String className)

      Returns an ExtendedType for specific Java classes. Uses user-provided and Cayenne-provided `ExtendedTypeFactory` factories to instantiate the ExtendedType. All primitive classes must be converted to the corresponding Java classes by the callers.
      Returns:
        a default type for a given class or null if a class has no default type mapping.
      Since:
        1.2

    - #### canonicalizedTypeName

          protected String canonicalizedTypeName(String className)

      For the class name returns a name "canonicalized" for the purpose of ExtendedType lookup.
      Since:
        3.1.1

Copyright © 2001–2017 Apache Cayenne. All rights reserved.