Assists in the construction of descriptors. Can be used as a mapping
resolver to the engine. Engines will implement their own mapping
scheme typically by extending this class.
checkFieldNameDuplicates
protected final void checkFieldNameDuplicates(FieldDescriptor[] fields,
Class cls)
throws MappingException
Checks all given fields for name equality and throws a MappingException if at
least two fields have the same name.
fields
- The fields to be checked.cls
- Class that is checked (this is used for generating the exception).
createFieldDesc
protected AbstractFieldDescriptor createFieldDesc(Class javaClass,
FieldMapping fieldMap)
throws MappingException
Creates a single field descriptor. The field mapping is used to create a new stock
FieldDescriptor
. Implementations may extend this class to create a more
suitable descriptor.
javaClass
- The class to which the field belongs.fieldMap
- The field mapping information.
MappingException
- The field or its accessor methods are not
found, not accessible, not of the specified type, etc.
createFieldDescriptors
protected final AbstractFieldDescriptor[] createFieldDescriptors(ClassMapping clsMap,
Class javaClass)
throws MappingException
Create field descriptors. The class mapping information is used to create
descriptors for all the fields in the class, except for container fields.
Implementations may extend this method to create more suitable descriptors, or
create descriptors only for a subset of the fields.
clsMap
- The class to which the fields belong.javaClass
- The field mappings.
MappingException
- An exception indicating why mapping for the class cannot
be created.
createFieldHandler
protected final FieldHandler createFieldHandler(Class javaClass,
Class fldType,
FieldMapping fldMap,
AbstractMappingLoader.TypeInfoReference typeInfoRef)
throws MappingException
Creates the FieldHandler for the given FieldMapping.
javaClass
- the class type of the parent of the field.fldType
- the Java class type for the field.fldMap
- the field mapping.
- the newly created FieldHandler.
createFieldHandlers
protected void createFieldHandlers(MappingRoot mapping)
throws MappingException
Load field handler definitions, check for duplicate definitions and
instantiate the appropriate FieldHandler implementations.
mapping
- Mapping to load field handler definitions from.
MappingException
- If mapping contains more then one field handler
definition with same name.
findAccessor
public static final Method findAccessor(Class javaClass,
String methodName,
Class fieldType,
boolean getMethod)
throws MappingException
Returns the named accessor. Uses reflection to return the named accessor and
check the return value or parameter type, if specified.
javaClass
- The class to which the field belongs.methodName
- The name of the accessor method.fieldType
- The type of the field if known, or null.getMethod
- True if get method, false if set method.
- The method, null if not found.
MappingException
- The method is not accessible or is not of the
specified type.
getDepended
protected final ClassDescriptor getDepended(ClassMapping clsMap,
Class javaClass)
throws MappingException
Gets the ClassDescriptor the given classMapping
depends
on.
clsMap
- The ClassMapping to find the required ClassDescriptor for.javaClass
- The name of the class that is checked (this is used for
generating the exception).
- The ClassDescriptor the given ClassMapping depends on or
null
if the given ClassMapping does not depend on
any.
MappingException
- If the given ClassMapping depends on another
ClassMapping but its descriptor could not be found.
getExtended
protected final ClassDescriptor getExtended(ClassMapping clsMap,
Class javaClass)
throws MappingException
Gets the ClassDescriptor the given classMapping
extends.
clsMap
- The ClassMapping to find the required descriptor for.javaClass
- The name of the class that is checked (this is used for
generating the exception).
- The ClassDescriptor the given ClassMapping extends or
null
if the given ClassMapping does not extend
any.
MappingException
- If the given ClassMapping extends another
ClassMapping but its descriptor could not be found.
getIdColumnIndex
protected int getIdColumnIndex(FieldDescriptor field,
String[] ids)
Finds the index in the given idColumnNames
that has the same name as
the given field
.
field
- The FieldDescriptor to find the column index for.ids
- The id columnNames available.
- The index of the id column name that matches the given field's name or
-1
if no such id column name exists.
getIdentityColumnNames
public static final String[] getIdentityColumnNames(String[] ids,
ClassMapping clsMap)
Returns a list of column names that are part of the identity.
ids
- Known identity names.clsMap
- Class mapping.
- List of identity column names.
getOrigin
protected final ClassMapping getOrigin(ClassMapping clsMap)
Gets the top-most (i.e. without any further 'extends') extends of the given
classMapping
.
clsMap
- The ClassMapping to get the origin for.
- The top-most extends of the given ClassMapping or the ClassMapping itself
if it does not extend any other ClassMapping.
isPrimitive
protected static final boolean isPrimitive(Class type)
Returns true if the given class should be treated as a primitive
type
- true if the given class should be treated as a primitive
type
loadMapping
public abstract void loadMapping(MappingRoot mapping,
Object param)
throws MappingException
Loads the mapping from the specified mapping object if not loaded previously.
mapping
- The mapping information.param
- Arbitrary parameter that can be used by subclasses.
resolveRelations
protected abstract void resolveRelations(ClassDescriptor clsDesc)
resolveType
protected final Class resolveType(String typeName)
throws MappingException
Returns the Java class for the named type. The type name can be one of the
accepted short names (e.g. integer) or the full Java class name (e.g.
java.lang.Integer). If the short name is used, the primitive type might
be returned.
setInternalContext
public void setInternalContext(InternalContext internalContext)