org.exolab.castor.mapping.loader

Class MappingLoader

public abstract class MappingLoader extends Object implements MappingResolver

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: 1.4 $ $Date: 2003/04/23 08:50:51 $

Author: Assaf Arkin Keith Visco

Nested Class Summary
classMappingLoader.TypeInfoReference
A class used to by the createFieldHandler method in order to save the reference of the TypeInfo that was used.
Field Summary
static ClassDescriptorNoDescriptor
Constructor Summary
protected MappingLoader(ClassLoader loader, PrintWriter logWriter)
Constructs a new mapping helper.
Method Summary
protected voidaddDescriptor(ClassDescriptor clsDesc)
Adds a class descriptor.
protected ClassDescriptorcreateDescriptor(ClassMapping clsMap)
Creates a new descriptor.
protected FieldDescriptorcreateFieldDesc(Class javaClass, FieldMapping fieldMap)
Creates a single field descriptor.
protected FieldDescriptor[]createFieldDescs(Class javaClass, FieldMapping[] fieldMaps)
Create field descriptors.
protected FieldHandlercreateFieldHandler(Class javaClass, Class fieldType, FieldMapping fieldMap, MappingLoader.TypeInfoReference typeInfoRef)
Creates the FieldHandler for the given FieldMapping
protected static MethodfindAccessor(Class javaClass, String methodName, Class fieldType, boolean getMethod)
Returns the named accessor.
ClassLoadergetClassLoader()
ClassDescriptorgetDescriptor(Class type)
protected PrintWritergetLogWriter()
Returns the log writer.
protected TypeInfogetTypeInfo(Class fieldType, CollectionHandler colHandler, FieldMapping fieldMap)
EnumerationlistDescriptors()
EnumerationlistJavaClasses()
protected ClassDescriptorloadClassDescriptor(String clsName)
Loads a class descriptor from a compiled class.
voidloadMapping(MappingRoot mapping, Object param)
Loads the mapping from the specified mapping object.
protected voidresolveRelations(ClassDescriptor clsDesc)
protected ClassresolveType(String typeName)
Returns the Java class for the named type.
voidsetAllowRedefinitions(boolean allow)
Enables or disables the ability to allow the redefinition of class mappings.

Field Detail

NoDescriptor

public static final ClassDescriptor NoDescriptor

Constructor Detail

MappingLoader

protected MappingLoader(ClassLoader loader, PrintWriter logWriter)
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 Detail

addDescriptor

protected void addDescriptor(ClassDescriptor clsDesc)
Adds a class descriptor. Will throw a mapping exception if a descriptor for this class already exists.

Parameters: clsDesc The descriptor to add

Throws: MappingException A descriptor for this class already exists

createDescriptor

protected ClassDescriptor createDescriptor(ClassMapping clsMap)
Creates a new descriptor. The class mapping information is used to create a new stock {@link 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)
Creates a single field descriptor. The field mapping is used to create a new stock {@link 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

createFieldDescs

protected FieldDescriptor[] createFieldDescs(Class javaClass, FieldMapping[] fieldMaps)
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: javaClass The class to which the fields belong fieldMaps The field mappings

Throws: MappingException An exception indicating why mapping for the class cannot be created

createFieldHandler

protected FieldHandler createFieldHandler(Class javaClass, Class fieldType, FieldMapping fieldMap, MappingLoader.TypeInfoReference typeInfoRef)
Creates the FieldHandler for the given FieldMapping

Parameters: javaClass the class type of the parent of the field fieldType the Java class type for the field. fieldMap the field mapping

Returns: the newly created FieldHandler

findAccessor

protected static final Method findAccessor(Class javaClass, String methodName, Class fieldType, boolean getMethod)
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 isGetMethod 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

getClassLoader

public ClassLoader getClassLoader()

getDescriptor

public ClassDescriptor getDescriptor(Class type)

getLogWriter

protected PrintWriter getLogWriter()
Returns the log writer. If not null, errors and other messages should be directed to the log writer.

getTypeInfo

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

listDescriptors

public Enumeration listDescriptors()

listJavaClasses

public Enumeration listJavaClasses()

loadClassDescriptor

protected ClassDescriptor loadClassDescriptor(String clsName)
Loads a class descriptor from a compiled class.

Parameters: clsName The class for which the descriptor is loaded

Returns: An instance of the class descriptor or null if not found

loadMapping

public void loadMapping(MappingRoot mapping, Object param)
Loads the mapping from the specified mapping object. Calls {@link #createDescriptor} to create each descriptor and {@link #addDescriptor} to store it. Also loads all the included mapping files.

Parameters: mapping The mapping information param Arbitrary parameter that can be used by subclasses

Throws: MappingException The mapping file is invalid

resolveRelations

protected void resolveRelations(ClassDescriptor clsDesc)

resolveType

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

setAllowRedefinitions

public void setAllowRedefinitions(boolean allow)
Enables or disables the ability to allow the redefinition of class mappings.

Parameters: allow a boolean that when true enables redefinitions.

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