Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2007 Daniel Spiewak
  * Licensed under the Apache License, Version 2.0 (the "License"); 
  * you may not use this file except in compliance with the License. 
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and
 * limitations under the License.

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 ( A passable description of polymorphic type flags and relationships is available in the javadoc for the interface.

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

ClassnamePolymorphic Type Flag

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.

Daniel Spiewak
public 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.

type The type for which a polymorphic flag must be generated.
The polymorphic flag type value which corresponds to the given type.
See also:
	public String convert(Class<? extends RawEntity<?>> 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(java.lang.Class) method.

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.
The entity type corresponding uniquely to the supertype-flag pair.
	public Class<? extends RawEntity<?>> invert(Class<? extends RawEntity<?>> parentString type);
New to GrepCode? Check out our FAQ X