| /******************************************************************************* |
| * Copyright (c) 2008, 2010 Oracle. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v1.0, which accompanies this distribution |
| * and is available at http://www.eclipse.org/legal/epl-v10.html. |
| * |
| * Contributors: |
| * Oracle - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.jpt.jpa.core.tests.extension.resource; |
| |
| import java.util.ArrayList; |
| import org.eclipse.core.runtime.content.IContentType; |
| import org.eclipse.jpt.common.core.JptCommonCorePlugin; |
| import org.eclipse.jpt.common.core.JptResourceType; |
| import org.eclipse.jpt.common.utility.internal.CollectionTools; |
| import org.eclipse.jpt.jpa.core.JpaPlatformProvider; |
| import org.eclipse.jpt.jpa.core.JpaResourceModelProvider; |
| import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; |
| import org.eclipse.jpt.jpa.core.ResourceDefinition; |
| import org.eclipse.jpt.jpa.core.context.java.DefaultJavaAttributeMappingDefinition; |
| import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMappingDefinition; |
| import org.eclipse.jpt.jpa.core.context.java.JavaTypeMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.AbstractJpaPlatformProvider; |
| import org.eclipse.jpt.jpa.core.internal.JarResourceModelProvider; |
| import org.eclipse.jpt.jpa.core.internal.JavaResourceModelProvider; |
| import org.eclipse.jpt.jpa.core.internal.OrmResourceModelProvider; |
| import org.eclipse.jpt.jpa.core.internal.PersistenceResourceModelProvider; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaBasicMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaEmbeddableDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaEmbeddedIdMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaEmbeddedMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaEntityDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaIdMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaManyToManyMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaManyToOneMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaMappedSuperclassDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaOneToManyMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaOneToOneMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaTransientMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.context.java.JavaVersionMappingDefinition; |
| import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmXmlDefinition; |
| import org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericPersistenceXmlDefinition; |
| |
| public class TestJpaPlatformProvider extends AbstractJpaPlatformProvider |
| { |
| public static final String ID = "core.testJpaPlatform"; //$NON-NLS-1$ |
| |
| // singleton |
| private static final JpaPlatformProvider INSTANCE = new TestJpaPlatformProvider(); |
| |
| |
| /** |
| * Return the singleton. |
| */ |
| public static JpaPlatformProvider instance() { |
| return INSTANCE; |
| } |
| |
| |
| /** |
| * Enforce singleton usage |
| */ |
| private TestJpaPlatformProvider() { |
| super(); |
| } |
| |
| |
| // ********** resource models ********** |
| |
| public JptResourceType getMostRecentSupportedResourceType(IContentType contentType) { |
| if (contentType.equals(JptCommonCorePlugin.JAVA_SOURCE_CONTENT_TYPE)) { |
| return JptCommonCorePlugin.JAVA_SOURCE_RESOURCE_TYPE; |
| } |
| else if (contentType.equals(JptCommonCorePlugin.JAR_CONTENT_TYPE)) { |
| return JptCommonCorePlugin.JAR_RESOURCE_TYPE; |
| } |
| else if (contentType.equals(JptJpaCorePlugin.PERSISTENCE_XML_CONTENT_TYPE)) { |
| return JptJpaCorePlugin.PERSISTENCE_XML_1_0_RESOURCE_TYPE; |
| } |
| else if (contentType.equals(JptJpaCorePlugin.ORM_XML_CONTENT_TYPE)) { |
| return JptJpaCorePlugin.ORM_XML_1_0_RESOURCE_TYPE; |
| } |
| else { |
| throw new IllegalArgumentException(contentType.toString()); |
| } |
| } |
| |
| @Override |
| protected void addResourceModelProvidersTo(ArrayList<JpaResourceModelProvider> providers) { |
| CollectionTools.addAll(providers, RESOURCE_MODEL_PROVIDERS); |
| } |
| |
| // order should not be important here |
| protected static final JpaResourceModelProvider[] RESOURCE_MODEL_PROVIDERS = new JpaResourceModelProvider[] { |
| JavaResourceModelProvider.instance(), |
| JarResourceModelProvider.instance(), |
| PersistenceResourceModelProvider.instance(), |
| OrmResourceModelProvider.instance() |
| }; |
| |
| |
| // ********** Java type mappings ********** |
| |
| @Override |
| protected void addJavaTypeMappingDefinitionsTo(ArrayList<JavaTypeMappingDefinition> definitions) { |
| CollectionTools.addAll(definitions, JAVA_TYPE_MAPPING_DEFINITIONS); |
| } |
| |
| // order matches that used by the Reference Implementation (EclipseLink) |
| protected static final JavaTypeMappingDefinition[] JAVA_TYPE_MAPPING_DEFINITIONS = new JavaTypeMappingDefinition[] { |
| JavaEntityDefinition.instance(), |
| JavaEmbeddableDefinition.instance(), |
| JavaMappedSuperclassDefinition.instance(), |
| JavaTestTypeMappingDefinition.instance() // added |
| }; |
| |
| |
| // ********** Java attribute mappings ********** |
| |
| @Override |
| protected void addDefaultJavaAttributeMappingDefinitionsTo(ArrayList<DefaultJavaAttributeMappingDefinition> definitions) { |
| CollectionTools.addAll(definitions, DEFAULT_JAVA_ATTRIBUTE_MAPPING_DEFINITIONS); |
| } |
| |
| // order matches that used by the Reference Implementation (EclipseLink) |
| protected static final DefaultJavaAttributeMappingDefinition[] DEFAULT_JAVA_ATTRIBUTE_MAPPING_DEFINITIONS = new DefaultJavaAttributeMappingDefinition[] { |
| JavaEmbeddedMappingDefinition.instance(), |
| JavaBasicMappingDefinition.instance() |
| }; |
| @Override |
| protected void addSpecifiedJavaAttributeMappingDefinitionsTo(ArrayList<JavaAttributeMappingDefinition> definitions) { |
| CollectionTools.addAll(definitions, SPECIFIED_JAVA_ATTRIBUTE_MAPPING_DEFINITIONS); |
| } |
| |
| // order matches that used by the Reference Implementation (EclipseLink) |
| protected static final JavaAttributeMappingDefinition[] SPECIFIED_JAVA_ATTRIBUTE_MAPPING_DEFINITIONS = new JavaAttributeMappingDefinition[] { |
| JavaTransientMappingDefinition.instance(), |
| JavaIdMappingDefinition.instance(), |
| JavaVersionMappingDefinition.instance(), |
| JavaBasicMappingDefinition.instance(), |
| JavaEmbeddedMappingDefinition.instance(), |
| JavaEmbeddedIdMappingDefinition.instance(), |
| JavaManyToManyMappingDefinition.instance(), |
| JavaManyToOneMappingDefinition.instance(), |
| JavaOneToManyMappingDefinition.instance(), |
| JavaOneToOneMappingDefinition.instance(), |
| JavaTestAttributeMappingDefinition.instance() // added |
| }; |
| |
| |
| // ********** resource definitions ********** |
| |
| @Override |
| protected void addResourceDefinitionsTo(ArrayList<ResourceDefinition> definitions) { |
| CollectionTools.addAll(definitions, RESOURCE_DEFINITIONS); |
| } |
| |
| protected static final ResourceDefinition[] RESOURCE_DEFINITIONS = new ResourceDefinition[] { |
| GenericPersistenceXmlDefinition.instance(), |
| GenericOrmXmlDefinition.instance() |
| }; |
| } |