Package org.jpox.store.mapped.mapping

Source Code of org.jpox.store.mapped.mapping.MappingFactory

/**********************************************************************
Copyright (c) 2003 Erik Bengtson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributors:
2003 Andy Jefferson - converted to use Reflection
2004 Andy Jefferson - output targetException when Invocation error
    ...
**********************************************************************/
package org.jpox.store.mapped.mapping;

import org.jpox.ClassLoaderResolver;
import org.jpox.ObjectManagerFactoryImpl;
import org.jpox.exceptions.JPOXException;
import org.jpox.metadata.AbstractMemberMetaData;
import org.jpox.store.mapped.DatastoreAdapter;
import org.jpox.store.mapped.DatastoreContainerObject;
import org.jpox.util.Localiser;

/**
* Factory class for creating Mapping instances.
* This is called to generate field mappings for the classes to be persisted.
*
* @version $Revision: 1.18 $
*/
public final class MappingFactory
{
    private static final Localiser LOCALISER = Localiser.getInstance("org.jpox.store.Localisation",
        ObjectManagerFactoryImpl.class.getClassLoader());

    /** Private constructor to prevent instantiation. */
    private MappingFactory()
    {
    }

    /**
     * Get a new instance of the Mapping using the DBA and type.
     * @param mappingClass the Mapping class to be created
     * @param dba The Database Adapter
     * @param type The type
     * @return The Mapping
     */
    public static JavaTypeMapping createMapping(Class mappingClass, DatastoreAdapter dba, String type)
    {
      JavaTypeMapping mapping = null;
        try
        {
          mapping = (JavaTypeMapping)mappingClass.newInstance();
        }
        catch (Exception e)
        {
            throw new JPOXException(LOCALISER.msg("041009", mappingClass.getName(), e), e).setFatal();
        }
        mapping.initialize(dba, type);
        return mapping;
    }

    /**
     * Get a new instance of the Mapping using the the DBA, field metadata, and the table managing the field.
     * @param mappingClass the Mapping class to be created
     * @param dba Datastore Adapter
     * @param fmd FieldMetaData for the field to be mapped
     * @param datastoreContainer The Table
     * @param clr The ClassLoaderResolver
     * @return The Mapping
     */
    public static JavaTypeMapping createMapping(Class mappingClass, DatastoreAdapter dba, AbstractMemberMetaData fmd,
            int roleForField, DatastoreContainerObject datastoreContainer, ClassLoaderResolver clr)
    {
        JavaTypeMapping mapping = null;
        try
        {
          mapping = (JavaTypeMapping)mappingClass.newInstance();
        }
        catch (Exception e)
        {
            throw new JPOXException(LOCALISER.msg("041009", mappingClass.getName(), e), e).setFatal();
        }

        if (roleForField >= 0)
        {
            mapping.setRoleForField(roleForField);
        }
        mapping.initialize(dba, fmd, datastoreContainer, clr);

        return mapping;
    }
}
TOP

Related Classes of org.jpox.store.mapped.mapping.MappingFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.