Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## net.java.ao
Class DefaultPolymorphicTypeMapper

    java.lang.Object
      net.java.ao.DefaultPolymorphicTypeMapper

All Implemented Interfaces:
  PolymorphicTypeMapper

    public class DefaultPolymorphicTypeMapper

extends Object
implements PolymorphicTypeMapper

Boiler-plate implementation of `PolymorphicTypeMapper` which requires all mappings to be manually specified. This type mapper will not attempt to do anything clever like caching or storing of mapping results. Rather, it depends entirely upon the developer to explicitly specify the map values for every polymorphic type in use.

If a type which has not been explicitly specified, this converter will default to the fully qualified classname. Thus the inverse conversion will also default to a `Class.forName(String)` invocation in case of no valid mapping in the relevant class hierarchy.

You should not attempt to use the same instance of this class with more than one instance of `EntityManager`. This is because `EntityManager` performs some initialization on the mapper when it is set. While this initialization is in fact thread-safe, it may cause undesired behavior if using two separate entity managers with different table name converters.

Author:
  Daniel Spiewak

Constructor Summary
`DefaultPolymorphicTypeMapper(Class<? extends RawEntity<?>>... types)` Convenience constructor which will construct a set of mappings on the fly based on the specified entity types.
`DefaultPolymorphicTypeMapper(Map<Class<? extends RawEntity<?>>,String> mappings)` Creates a new instance with the specified {type => flag} mappings.

Method Summary
`String` | `convert(Class<? extends RawEntity<?>> type)` Retrieves the polymorphic type flag value which corresponds to the specified type.
`Class<? extends RawEntity<?>>` | `invert(Class<? extends RawEntity<?>> parent, String type)` Retrieves the entity type which corresponds to the given polymorphic type flag value as a subtype of the specified parent entity type.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### DefaultPolymorphicTypeMapper

    public DefaultPolymorphicTypeMapper(Class<? extends RawEntity<?>>... types)

  Convenience constructor which will construct a set of mappings on the fly based on the specified entity types. Actual construction of the mappings is delayed and invoked directly by the `EntityManager` instance which receives the instance of this class. This is to allow `EntityManager` to pass the relevant table name converter to be used in the initialization process.

  It is very important that an instance created using this constructor is not used with more than one `EntityManager`.

  Parameters:
    `types` - The polymorphic types which must be mapped.

### DefaultPolymorphicTypeMapper

    public DefaultPolymorphicTypeMapper(Map<Class<? extends RawEntity<?>>,String> mappings)

  Creates a new instance with the specified {type => flag} mappings.

  Parameters:
    `mappings` - The mappings from entity type to polymorphic flag value.

Method Detail

### convert

    public String convert(Class<? extends RawEntity<?>> type)

  Description copied from interface: `PolymorphicTypeMapper`
  Retrieves the polymorphic type flag value which corresponds to the specified type. Return value must be repeatable given the same type as well as uniquely defined within the hierarchy of the given type.

  Specified by:
    `convert` in interface `PolymorphicTypeMapper`
  Parameters:
    `type` - The type for which a polymorphic flag must be generated.
  Returns:
    The polymorphic flag type value which corresponds to the given type.
  See Also:
    `PolymorphicTypeMapper.invert(Class, String)`

### invert

    public Class<? extends RawEntity<?>> invert(Class<? extends RawEntity<?>> parent,
                                                String type)

  Description copied from interface: `PolymorphicTypeMapper`
  Retrieves the entity type which corresponds to the given polymorphic type flag value as a subtype of the specified parent entity type. Logically the inverse of the `PolymorphicTypeMapper.convert(Class)` method.

  Specified by:
    `invert` in interface `PolymorphicTypeMapper`
  Parameters:
    `parent` - The parent interface of the type which must be retrieved.
    `type` - The polymorphic type flag value which corresponds to the type which must be retrieved.
  Returns:
    The entity type corresponding uniquely to the supertype-flag pair.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2007-2011. All Rights Reserved.