net.java.ao
Interface PolymorphicTypeMapper

All Known Implementing Classes:
DefaultPolymorphicTypeMapper

public interface PolymorphicTypeMapper

Represents a strategy for bi-directional mapping between entity types and their corresponding polymorphic type flag value (if any). The mappings represented by this strategy will usually be similar, though not necessarily identical to the values returned by the mono-directional mapping of entity type to table names (TableNameConverter). A passable description of polymorphic type flags and relationships is available in the javadoc for the FieldNameConverter interface.

An example set of mappings follows (assuming these are all polymorphic types):

Classname Polymorphic Type Flag
com.company.db.Employee employee
com.company.db.Manager manager
com.company.db.CEO ceo

Mappings need not be entirely unique, as long as the mappings for all subtypes of a specific supertype are internally unique. For example, the above example implies that all three entities are subtypes of a single supertype (probably Person). Thus, all of the mapping values must be uniquely paired. However, a fourth entity could just as easily be represented which extends an entirely separate supertype. Such an entity would not be constrained to uniqueness with the other, unrelated entities. However, if the hierarchy for a single supertype does not have fully-defined and unique mappings, unexpected behavior may result (such as retrieving references to invalid entities).

A sane implementation (using manually-specified mappings) is implemented within the DefaultPolymorphicTypeMapper class. Very few use-cases call for a custom implementation of this interface directly.

Author:
Daniel Spiewak

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.
 

Method Detail

convert

String convert(Class<? extends RawEntity<?>> type)
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.

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:
invert(Class, String)

invert

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. Logically the inverse of the convert(Class) method.

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.