Class AbstractMappingLoader

  • All Implemented Interfaces:
    MappingLoader
    Direct Known Subclasses:
    JDOMappingLoader, 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: 8813 $ $Date: 2006-04-10 16:39:24 -0600 (Mon, 10 Apr 2006) $
    Author:
    Assaf Arkin, Keith Visco
    • Field Detail

      • EMPTY_ARGS

        protected static final java.lang.Class<?>[] EMPTY_ARGS
        Empty array of class types used for reflection.
      • STRING_ARG

        protected static final java.lang.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 java.lang.String VALUE_OF
        Factory method name for type-safe enumerations.
        See Also:
        Constant Field Values
      • NAME

        protected static final java.lang.String NAME
        Method name to get string value of a type-safe enumerations.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractMappingLoader

        protected AbstractMappingLoader​(java.lang.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 Detail

      • getSourceType

        public final java.lang.String getSourceType()
      • loadMapping

        public abstract void loadMapping​(MappingRoot mapping,
                                         java.lang.Object param)
                                  throws MappingException
        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

        protected void createFieldHandlers​(MappingRoot mapping)
                                    throws MappingException
        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.
      • getExtended

        protected final ClassDescriptor getExtended​(ClassMapping clsMap,
                                                    java.lang.Class<?> javaClass)
                                             throws MappingException
        Gets the ClassDescriptor the given classMapping 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,
                                                    java.lang.Class<?> javaClass)
                                             throws MappingException
        Gets the ClassDescriptor the given classMapping 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,
                                                      java.lang.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

        protected abstract void resolveRelations​(ClassDescriptor clsDesc)
      • resolveType

        protected final java.lang.Class<?> resolveType​(java.lang.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.
        Throws:
        MappingException
      • createFieldDescriptors

        protected final FieldDescriptorImpl[] createFieldDescriptors​(ClassMapping clsMap,
                                                                     java.lang.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

        protected final ClassMapping getOrigin​(ClassMapping clsMap)
        Gets the top-most (i.e. without any further 'extends') extends of the given classMapping.
        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.
      • getIdColumnIndex

        protected int getIdColumnIndex​(FieldDescriptor field,
                                       java.lang.String[] ids)
        Finds the index in the given idColumnNames that has the same name as the given field.
        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​(java.lang.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​(java.lang.Class<?> javaClass,
                                                        java.lang.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
      • findAccessor

        public static final java.lang.reflect.Method findAccessor​(java.lang.Class<?> javaClass,
                                                                  java.lang.String methodName,
                                                                  java.lang.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 java.lang.String[] getIdentityColumnNames​(java.lang.String[] ids,
                                                                      ClassMapping clsMap)
        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

        protected static final boolean isPrimitive​(java.lang.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
      • setInternalContext

        public void setInternalContext​(InternalContext internalContext)