org.exolab.castor.mapping.loader

Class AbstractMappingLoader

Implemented Interfaces:
MappingLoader
Known Direct Subclasses:
JDOMappingLoader, MappingToolMappingLoader, XMLMappingLoader

public abstract class AbstractMappingLoader
extends AbstractMappingLoader2

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: 6385 $ $Date: 2006-04-10 16:39:24 -0600 (Mon, 10 Apr 2006) $
Authors:
Assaf Arkin
Keith Visco

Nested Class Summary

class
AbstractMappingLoader.TypeInfoReference
A class used to by the createFieldHandler method in order to save the reference of the TypeInfo that was used.

Field Summary

protected static Class[]
EMPTY_ARGS
Empty array of class types used for reflection.
protected static ClassDescriptor
NO_DESCRIPTOR
protected static Class[]
STRING_ARG
The string argument for the valueOf method, used for introspection when searching for type-safe enumeration style classes.
protected static String
VALUE_OF
Factory method name for type-safe enumerations.

Constructor Summary

AbstractMappingLoader(ClassLoader loader)
Constructs a new mapping helper.

Method Summary

protected ClassDescriptor
createDescriptor(ClassMapping clsMap)
Creates a new descriptor.
protected FieldDescriptor
createFieldDesc(Class javaClass, FieldMapping fieldMap)
Creates a single field descriptor.
protected FieldHandler
createFieldHandler(Class javaClass, Class fldType, FieldMapping fldMap, AbstractMappingLoader.TypeInfoReference typeInfoRef)
Creates the FieldHandler for the given FieldMapping.
protected static Method
findAccessor(Class javaClass, String methodName, Class fieldType, boolean getMethod)
Returns the named accessor.
static String[]
getIdentityColumnNames(String[] ids, ClassMapping clsMap)
Returns a list of column names that are part of the identity.
String
getSourceType()
protected TypeInfo
getTypeInfo(Class fieldType, CollectionHandler colHandler, FieldMapping fieldMap)
protected static boolean
isPrimitive(Class type)
Returns true if the given class should be treated as a primitive type
protected void
loadMappingInternal(MappingRoot mapping, Object param)
protected void
resolveRelations(ClassDescriptor clsDesc)
protected Class
resolveType(String typeName)
Returns the Java class for the named type.

Methods inherited from class org.exolab.castor.mapping.loader.AbstractMappingLoader2

addDescriptor, clear, descriptorIterator, getClassLoader, getDescriptor, isAllowRedefinition, loadMapping, loadMappingInternal, setAllowRedefinitions, setClassLoader

Field Details

EMPTY_ARGS

protected static final Class[] EMPTY_ARGS
Empty array of class types used for reflection.

NO_DESCRIPTOR

protected static final ClassDescriptor NO_DESCRIPTOR

STRING_ARG

protected static final Class[] STRING_ARG
The string argument for the valueOf method, used for introspection when searching for type-safe enumeration style classes.

VALUE_OF

protected static final String VALUE_OF
Factory method name for type-safe enumerations.

Constructor Details

AbstractMappingLoader

protected AbstractMappingLoader(ClassLoader loader)
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

createDescriptor

protected ClassDescriptor createDescriptor(ClassMapping clsMap)
            throws MappingException
Creates a new descriptor. The class mapping information is used to create a new stock ClassDescriptor. Implementations may extend this class to create a more suitable descriptor.
Parameters:
clsMap - The class mapping information.
Throws:
MappingException - An exception indicating why mapping for the class cannot be created.

createFieldDesc

protected FieldDescriptor 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.
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.

findAccessor

protected 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

public static final String[] getIdentityColumnNames(String[] ids,
                                                    ClassMapping clsMap)
Returns a list of column names that are part of the identity.
Parameters:
ids - Known identity names.
clsMap - Class mapping.
Returns:
List of identity column names.

getSourceType

public final String getSourceType()
Specified by:
getSourceType in interface MappingLoader

getTypeInfo

protected TypeInfo getTypeInfo(Class fieldType,
                               CollectionHandler colHandler,
                               FieldMapping fieldMap)
            throws MappingException

isPrimitive

protected static final boolean isPrimitive(Class type)
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

loadMappingInternal

protected void loadMappingInternal(MappingRoot mapping,
                                   Object param)
            throws MappingException
Overrides:
loadMappingInternal in interface AbstractMappingLoader2

resolveRelations

protected void resolveRelations(ClassDescriptor clsDesc)

resolveType

protected final Class resolveType(String typeName)
            throws ClassNotFoundException
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.

Intalio Inc. (C) 1999-2006. All rights reserved http://www.intalio.com