Package org.exolab.castor.mapping.loader
Class AbstractMappingLoader
java.lang.Object
org.exolab.castor.mapping.loader.AbstractMappingLoader2
org.exolab.castor.mapping.loader.AbstractMappingLoader
- All Implemented Interfaces:
MappingLoader
- Direct Known Subclasses:
XMLMappingLoader
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.
- Version:
- $Revision$ $Date: 2006-04-10 16:39:24 -0600 (Mon, 10 Apr 2006) $
- Author:
- Assaf Arkin, Keith Visco
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
A class used to by the createFieldHandler method in order to save the reference of the TypeInfo that was used. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Class<?>[]
Empty array of class types used for reflection.protected static final String
Method name to get string value of a type-safe enumerations.protected static final Class<?>[]
The string argument for the valueOf method, used for introspection when searching for type-safe enumeration style classes.protected static final String
Factory method name for type-safe enumerations. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractMappingLoader
(ClassLoader loader) Constructs a new mapping helper. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
checkFieldNameDuplicates
(FieldDescriptor[] fields, Class<?> cls) Checks all given fields for name equality and throws a MappingException if at least two fields have the same name.protected abstract ClassDescriptor
createClassDescriptor
(ClassMapping clsMap) protected final void
createClassDescriptors
(MappingRoot mapping) protected FieldDescriptorImpl
createFieldDesc
(Class<?> javaClass, FieldMapping fieldMap) Creates a single field descriptor.protected final FieldDescriptorImpl[]
createFieldDescriptors
(ClassMapping clsMap, Class<?> javaClass) Create field descriptors.protected final FieldHandler
createFieldHandler
(Class<?> javaClass, Class<?> fldType, FieldMapping fldMap, AbstractMappingLoader.TypeInfoReference typeInfoRef) Creates the FieldHandler for the given FieldMapping.protected void
createFieldHandlers
(MappingRoot mapping) Load field handler definitions, check for duplicate definitions and instantiate the appropriate FieldHandler implementations.protected final FieldDescriptor[]
divideFieldDescriptors
(FieldDescriptor[] fields, String[] ids, FieldDescriptor[] identities) static final Method
findAccessor
(Class<?> javaClass, String methodName, Class<?> fieldType, boolean getMethod) Returns the named accessor.protected final ClassDescriptor
getDepended
(ClassMapping clsMap, Class<?> javaClass) Gets the ClassDescriptor the givenclassMapping
depends on.protected final ClassDescriptor
getExtended
(ClassMapping clsMap, Class<?> javaClass) Gets the ClassDescriptor the givenclassMapping
extends.protected int
getIdColumnIndex
(FieldDescriptor field, String[] ids) Finds the index in the givenidColumnNames
that has the same name as the givenfield
.static final String[]
getIdentityColumnNames
(String[] ids, ClassMapping clsMap) Returns a list of column names that are part of the identity.protected final ClassMapping
getOrigin
(ClassMapping clsMap) Gets the top-most (i.e.final String
protected TypeInfo
getTypeInfo
(Class fieldType, CollectionHandler colHandler, FieldMapping fieldMap) protected static final boolean
isPrimitive
(Class<?> type) Returns true if the given class should be treated as a primitive typeabstract void
loadMapping
(MappingRoot mapping, Object param) Loads the mapping from the specified mapping object if not loaded previously.protected abstract void
resolveRelations
(ClassDescriptor clsDesc) protected final Class
<?> resolveType
(String typeName) Returns the Java class for the named type.void
setInternalContext
(InternalContext internalContext) Methods inherited from class org.exolab.castor.mapping.loader.AbstractMappingLoader2
addDescriptor, clear, getClassLoader, getDescriptor, getDescriptors, isAllowRedefinition, loadMapping, setAllowRedefinitions, setClassLoader
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.exolab.castor.mapping.MappingLoader
getBindingType
-
Field Details
-
EMPTY_ARGS
Empty array of class types used for reflection. -
STRING_ARG
The string argument for the valueOf method, used for introspection when searching for type-safe enumeration style classes. -
VALUE_OF
-
NAME
Method name to get string value of a type-safe enumerations.- See Also:
-
-
Constructor Details
-
AbstractMappingLoader
Constructs a new mapping helper. This constructor is used by a derived class.- Parameters:
loader
- The class loader to use, null for the default
-
-
Method Details
-
getSourceType
-
loadMapping
Loads the mapping from the specified mapping object if not loaded previously.- Parameters:
mapping
- The mapping information.param
- Arbitrary parameter that can be used by subclasses.- Throws:
MappingException
- The mapping file is invalid.
-
createFieldHandlers
Load field handler definitions, check for duplicate definitions and instantiate the appropriate FieldHandler implementations.- Parameters:
mapping
- Mapping to load field handler definitions from.- Throws:
MappingException
- If mapping contains more then one field handler definition with same name.
-
createClassDescriptors
- Throws:
MappingException
-
createClassDescriptor
protected abstract ClassDescriptor createClassDescriptor(ClassMapping clsMap) throws MappingException - Throws:
MappingException
-
getExtended
protected final ClassDescriptor getExtended(ClassMapping clsMap, Class<?> javaClass) throws MappingException Gets the ClassDescriptor the givenclassMapping
extends.- Parameters:
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).- Returns:
- The ClassDescriptor the given ClassMapping extends or
null
if the given ClassMapping does not extend any. - Throws:
MappingException
- If the given ClassMapping extends another ClassMapping but its descriptor could not be found.
-
getDepended
protected final ClassDescriptor getDepended(ClassMapping clsMap, Class<?> javaClass) throws MappingException Gets the ClassDescriptor the givenclassMapping
depends on.- Parameters:
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).- Returns:
- The ClassDescriptor the given ClassMapping depends on or
null
if the given ClassMapping does not depend on any. - Throws:
MappingException
- If the given ClassMapping depends on another ClassMapping but its descriptor could not be found.
-
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.- Parameters:
fields
- The fields to be checked.cls
- Class that is checked (this is used for generating the exception).- Throws:
MappingException
- If at least two fields have the same name.
-
resolveRelations
-
resolveType
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.- Throws:
MappingException
-
createFieldDescriptors
protected final FieldDescriptorImpl[] 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.- Parameters:
clsMap
- The class to which the fields belong.javaClass
- The field mappings.- Throws:
MappingException
- An exception indicating why mapping for the class cannot be created.
-
getOrigin
Gets the top-most (i.e. without any further 'extends') extends of the givenclassMapping
.- Parameters:
clsMap
- The ClassMapping to get the origin for.- Returns:
- The top-most extends of the given ClassMapping or the ClassMapping itself if it does not extend any other ClassMapping.
-
divideFieldDescriptors
protected final FieldDescriptor[] divideFieldDescriptors(FieldDescriptor[] fields, String[] ids, FieldDescriptor[] identities) -
getIdColumnIndex
Finds the index in the givenidColumnNames
that has the same name as the givenfield
.- Parameters:
field
- The FieldDescriptor to find the column index for.ids
- The id columnNames available.- Returns:
- The index of the id column name that matches the given field's name or
-1
if no such id column name exists.
-
createFieldDesc
protected FieldDescriptorImpl createFieldDesc(Class<?> javaClass, FieldMapping fieldMap) throws MappingException Creates a single field descriptor. The field mapping is used to create a new stockFieldDescriptor
. Implementations may extend this class to create a more suitable descriptor.- Parameters:
javaClass
- The class to which the field belongs.fieldMap
- The field mapping information.- Returns:
- The field descriptor.
- Throws:
MappingException
- The field or its accessor methods are not found, not accessible, not of the specified type, etc.
-
createFieldHandler
protected final FieldHandler createFieldHandler(Class<?> javaClass, Class<?> fldType, FieldMapping fldMap, AbstractMappingLoader.TypeInfoReference typeInfoRef) throws MappingException Creates the FieldHandler for the given FieldMapping.- Parameters:
javaClass
- the class type of the parent of the field.fldType
- the Java class type for the field.fldMap
- the field mapping.- Returns:
- the newly created FieldHandler.
- Throws:
MappingException
-
getTypeInfo
protected TypeInfo getTypeInfo(Class fieldType, CollectionHandler colHandler, FieldMapping fieldMap) throws MappingException - Throws:
MappingException
-
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.- Parameters:
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.- Returns:
- The method, null if not found.
- Throws:
MappingException
- The method is not accessible or is not of the specified type.
-
getIdentityColumnNames
Returns a list of column names that are part of the identity.- Parameters:
ids
- Known identity names.clsMap
- The class mapping.- Returns:
- List of identity column names.
-
isPrimitive
Returns true if the given class should be treated as a primitive type- Returns:
- true if the given class should be treated as a primitive type
-
setInternalContext
-
getInternalContext
-