diff options
author | pfullbright | 2010-08-16 17:42:13 +0000 |
---|---|---|
committer | pfullbright | 2010-08-16 17:42:13 +0000 |
commit | 08101996b6d1bf7de7aa210990eefde9548f896d (patch) | |
tree | 742d36bc8d8fec28e2190a18edb9f36c99dd2596 /jpa/plugins/org.eclipse.jpt.core/src | |
parent | e80da5d1385f126d11c6838e26fb74ab61d5bc95 (diff) | |
download | webtools.dali-08101996b6d1bf7de7aa210990eefde9548f896d.tar.gz webtools.dali-08101996b6d1bf7de7aa210990eefde9548f896d.tar.xz webtools.dali-08101996b6d1bf7de7aa210990eefde9548f896d.zip |
refactored jpaPlatforms extension point, added jpaPlatformGroup
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src')
18 files changed, 676 insertions, 320 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/GenericJpaProjectManager.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/GenericJpaProjectManager.java index 4eaf9cb61e..3e280b51e5 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/GenericJpaProjectManager.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/GenericJpaProjectManager.java @@ -396,7 +396,7 @@ class GenericJpaProjectManager private JpaProject.Config buildJpaProjectConfig(IProject project) { SimpleJpaProjectConfig config = new SimpleJpaProjectConfig(); config.setProject(project); - config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project)); + config.setJpaPlatform(JptCorePlugin.getJpaPlatformManager().buildJpaPlatformImplementation(project)); config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project)); config.setUserOverrideDefaultCatalog(JptCorePlugin.getUserOverrideDefaultCatalog(project)); config.setUserOverrideDefaultSchema(JptCorePlugin.getUserOverrideDefaultSchema(project)); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java index a104200435..8b77fbaff3 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java @@ -29,18 +29,20 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.core.internal.GenericJpaPlatformProvider; -import org.eclipse.jpt.core.internal.JpaPlatformRegistry; import org.eclipse.jpt.core.internal.JptCoreMessages; -import org.eclipse.jpt.core.internal.jpa2.Generic2_0JpaPlatformProvider; +import org.eclipse.jpt.core.internal.platform.JpaPlatformManagerImpl; import org.eclipse.jpt.core.internal.prefs.JpaPreferenceInitializer; import org.eclipse.jpt.core.internal.resource.ResourceLocatorManager; +import org.eclipse.jpt.core.platform.GenericPlatform; +import org.eclipse.jpt.core.platform.JpaPlatformDescription; +import org.eclipse.jpt.core.platform.JpaPlatformManager; import org.eclipse.jpt.core.resource.ResourceLocator; import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.jst.j2ee.internal.J2EEConstants; import org.eclipse.osgi.util.NLS; import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; import org.osgi.framework.BundleContext; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; @@ -332,19 +334,21 @@ public class JptCorePlugin extends Plugin { IEclipsePreferences node = getDefaultPreferences(); // default JPA platforms - String defaultPlatformId_1_0 = JpaPlatformRegistry.instance().getDefaultJpaPlatformId(JpaFacet.VERSION_1_0.getVersionString()); - if (StringTools.stringIsEmpty(defaultPlatformId_1_0)) { - defaultPlatformId_1_0 = GenericJpaPlatformProvider.ID; + JpaPlatformDescription defaultPlatform_1_0 = + JpaPlatformManagerImpl.instance().getDefaultJpaPlatform(JpaFacet.VERSION_1_0); + if (defaultPlatform_1_0 == null) { + defaultPlatform_1_0 = GenericPlatform.VERSION_1_0; } - node.put(DEFAULT_JPA_PLATFORM_1_0_PREF_KEY, defaultPlatformId_1_0); + node.put(DEFAULT_JPA_PLATFORM_1_0_PREF_KEY, defaultPlatform_1_0.getId()); - String defaultPlatformId_2_0 = JpaPlatformRegistry.instance().getDefaultJpaPlatformId(JpaFacet.VERSION_2_0.getVersionString()); - if (StringTools.stringIsEmpty(defaultPlatformId_2_0)) { - defaultPlatformId_2_0 = Generic2_0JpaPlatformProvider.ID; + JpaPlatformDescription defaultPlatform_2_0 = + JpaPlatformManagerImpl.instance().getDefaultJpaPlatform(JpaFacet.VERSION_2_0); + if (defaultPlatform_2_0 == null) { + defaultPlatform_2_0 = GenericPlatform.VERSION_2_0; } - node.put(DEFAULT_JPA_PLATFORM_2_0_PREF_KEY, defaultPlatformId_2_0); + node.put(DEFAULT_JPA_PLATFORM_2_0_PREF_KEY, defaultPlatform_2_0.getId()); } - + /** * Return the default Dali preferences * @see JpaPreferenceInitializer @@ -375,56 +379,57 @@ public class JptCorePlugin extends Plugin { } /** - * Return the default JPA Platform ID for new JPA projects with the given JPA facet version. + * Return the default {@link JpaPlatformDescription} for new JPA projects with the given JPA facet version. */ - public static String getDefaultJpaPlatformId(String jpaFacetVersion) { - String defaultPlatformId = - getDefaultJpaPlatformId(jpaFacetVersion, getWorkspacePreferences(), getDefaultPreferences()); - if (defaultPlatformId == null) { + public static JpaPlatformDescription getDefaultJpaPlatform(IProjectFacetVersion jpaFacetVersion) { + JpaPlatformDescription defaultPlatform = + getDefaultJpaPlatform(jpaFacetVersion, getWorkspacePreferences(), getDefaultPreferences()); + if (defaultPlatform == null) { // if the platform ID stored in the workspace prefs is invalid (i.e. null), look in the default prefs - defaultPlatformId = getDefaultJpaPlatformId(jpaFacetVersion, getDefaultPreferences()); + defaultPlatform = getDefaultJpaPlatform(jpaFacetVersion, getDefaultPreferences()); } - return defaultPlatformId; + return defaultPlatform; } - private static String getDefaultJpaPlatformId(String jpaFacetVersion, Preferences ... nodes) { - String defaultDefaultPlatformId = - getDefaultJpaPlatformId(jpaFacetVersion, DEFAULT_JPA_PLATFORM_PREF_KEY, null, nodes); + private static JpaPlatformDescription getDefaultJpaPlatform(IProjectFacetVersion jpaFacetVersion, Preferences ... nodes) { + JpaPlatformDescription defaultDefaultPlatform = + getDefaultJpaPlatform(jpaFacetVersion, DEFAULT_JPA_PLATFORM_PREF_KEY, null, nodes); String preferenceKey = null; - if (jpaFacetVersion.equals(JpaFacet.VERSION_1_0.getVersionString())) { - if (defaultDefaultPlatformId == null) { - defaultDefaultPlatformId = GenericJpaPlatformProvider.ID; + if (jpaFacetVersion.equals(JpaFacet.VERSION_1_0)) { + if (defaultDefaultPlatform == null) { + defaultDefaultPlatform = GenericPlatform.VERSION_1_0; } preferenceKey = DEFAULT_JPA_PLATFORM_1_0_PREF_KEY; } - else if (jpaFacetVersion.equals(JpaFacet.VERSION_2_0.getVersionString())) { - if (defaultDefaultPlatformId == null) { - defaultDefaultPlatformId = Generic2_0JpaPlatformProvider.ID; + else if (jpaFacetVersion.equals(JpaFacet.VERSION_2_0)) { + if (defaultDefaultPlatform == null) { + defaultDefaultPlatform = GenericPlatform.VERSION_2_0; } preferenceKey = DEFAULT_JPA_PLATFORM_2_0_PREF_KEY; } else { throw new IllegalArgumentException("Illegal JPA facet version: " + jpaFacetVersion); //$NON-NLS-1$ } - return getDefaultJpaPlatformId(jpaFacetVersion, preferenceKey, defaultDefaultPlatformId, nodes); + return getDefaultJpaPlatform(jpaFacetVersion, preferenceKey, defaultDefaultPlatform, nodes); } - private static String getDefaultJpaPlatformId( - String jpaFacetVersion, String preferenceKey, String defaultDefault, Preferences ... nodes) { - String defaultPlatformId = Platform.getPreferencesService().get(preferenceKey, defaultDefault, nodes); - if (jpaPlatformIdIsValid(defaultPlatformId) - && JpaPlatformRegistry.instance().platformSupportsJpaFacetVersion(defaultPlatformId, jpaFacetVersion)) { - return defaultPlatformId; + private static JpaPlatformDescription getDefaultJpaPlatform( + IProjectFacetVersion jpaFacetVersion, String preferenceKey, JpaPlatformDescription defaultDefault, Preferences ... nodes) { + + String defaultDefaultId = (defaultDefault == null) ? null : defaultDefault.getId(); + String defaultPlatformId = Platform.getPreferencesService().get(preferenceKey, defaultDefaultId, nodes); + JpaPlatformDescription defaultPlatform = getJpaPlatformManager().getJpaPlatform(defaultPlatformId); + if (defaultPlatform != null && defaultPlatform.supportsJpaFacetVersion(jpaFacetVersion)) { + return defaultPlatform; } - else if (jpaPlatformIdIsValid(defaultDefault) - && JpaPlatformRegistry.instance().platformSupportsJpaFacetVersion(defaultDefault, jpaFacetVersion)) { + else if (defaultDefault != null && defaultDefault.supportsJpaFacetVersion(jpaFacetVersion)) { return defaultDefault; } return null; } - private static boolean jpaPlatformIdIsValid(String platformId) { - return JpaPlatformRegistry.instance().containsPlatform(platformId); + public static JpaPlatformManager getJpaPlatformManager() { + return JpaPlatformManagerImpl.instance(); } /** @@ -445,19 +450,12 @@ public class JptCorePlugin extends Plugin { prefs.put(preferenceKey, platformId); flush(prefs); } - - /** - * Return the JPA platform associated with the specified Eclipse project. - */ - public static JpaPlatform getJpaPlatform(IProject project) { - return JpaPlatformRegistry.instance().getJpaPlatform(project); - } - + /** * Return the JPA platform ID associated with the specified Eclipse project. */ public static String getJpaPlatformId(IProject project) { - return getProjectPreferences(project).get(JPA_PLATFORM_PREF_KEY, GenericJpaPlatformProvider.ID); + return getProjectPreferences(project).get(JPA_PLATFORM_PREF_KEY, GenericPlatform.VERSION_1_0.getId()); } /** diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformProvider.java index 751b62c1da..8d497d4e78 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. + * Copyright (c) 2007, 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. @@ -40,8 +40,6 @@ import org.eclipse.jpt.core.internal.jpa1.context.persistence.GenericPersistence public class GenericJpaPlatformProvider extends AbstractJpaPlatformProvider { - public static final String ID = "generic"; //$NON-NLS-1$ - // singleton private static final JpaPlatformProvider INSTANCE = new GenericJpaPlatformProvider(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java deleted file mode 100644 index 3bd1933857..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java +++ /dev/null @@ -1,241 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 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.core.internal; - -import static org.eclipse.jpt.core.internal.XPointUtil.*; -import java.util.HashMap; -import java.util.Map; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaPlatformFactory; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; - -/** - * Singleton registry for storing all the registered JPA platform configuration - * elements and instantiating JPA platforms from them. - */ -public class JpaPlatformRegistry { - - private final HashMap<String, IConfigurationElement> jpaPlatformConfigurationElements; - - - // singleton - private static final JpaPlatformRegistry INSTANCE = new JpaPlatformRegistry(); - - /** - * Return the singleton. - */ - public static JpaPlatformRegistry instance() { - return INSTANCE; - } - - private static final String EXTENSION_ID = "jpaPlatforms"; //$NON-NLS-1$ - private static final String QUALIFIED_EXTENSION_ID = JptCorePlugin.PLUGIN_ID_ + EXTENSION_ID; - private static final String PLATFORM_ELEMENT_NAME = "jpaPlatform"; //$NON-NLS-1$ - private static final String ID_ATTRIBUTE_NAME = "id"; //$NON-NLS-1$ - private static final String LABEL_ATTRIBUTE_NAME = "label"; //$NON-NLS-1$ - private static final String FACTORY_CLASS_ATTRIBUTE_NAME = "factoryClass"; //$NON-NLS-1$ - private static final String JPA_FACET_VERSION_ATTRIBUTE_NAME = "jpaFacetVersion"; //$NON-NLS-1$ - private static final String DEFAULT_ATTRIBUTE_NAME = "default"; //$NON-NLS-1$ - - - // ********** constructor/initialization ********** - - /** - * ensure single instance - */ - private JpaPlatformRegistry() { - super(); - this.jpaPlatformConfigurationElements = this.buildJpaPlatformConfigurationElements(); - } - - - private HashMap<String, IConfigurationElement> buildJpaPlatformConfigurationElements() { - HashMap<String, IConfigurationElement> configElements = new HashMap<String, IConfigurationElement>(); - for (IConfigurationElement configElement : this.getConfigElements()) { - this.addConfigElementTo(configElement, configElements); - } - return configElements; - } - - /** - * Return the configuration elements from the Eclipse platform extension - * registry. - */ - private Iterable<IConfigurationElement> getConfigElements() { - return new CompositeIterable<IConfigurationElement>( - new TransformationIterable<IExtension, Iterable<IConfigurationElement>>(this.getExtensions()) { - @Override - protected Iterable<IConfigurationElement> transform(IExtension extension) { - return CollectionTools.iterable(extension.getConfigurationElements()); - } - } - ); - } - - private Iterable<IExtension> getExtensions() { - return CollectionTools.iterable(this.getExtensionPoint().getExtensions()); - } - - private IExtensionPoint getExtensionPoint() { - return Platform.getExtensionRegistry().getExtensionPoint(JptCorePlugin.PLUGIN_ID, EXTENSION_ID); - } - - private void addConfigElementTo(IConfigurationElement configElement, HashMap<String, IConfigurationElement> configElements) { - if ( ! configElement.getName().equals(PLATFORM_ELEMENT_NAME)) { - return; - } - if ( ! this.configElementIsValid(configElement)) { - return; - } - - String id = configElement.getAttribute(ID_ATTRIBUTE_NAME); - if (configElements.containsKey(id)) { - logDuplicateExtension(QUALIFIED_EXTENSION_ID, id); - } - else { - configElements.put(id, configElement); - } - } - - /** - * check *all* attributes before returning - */ - private boolean configElementIsValid(IConfigurationElement configElement) { - boolean valid = true; - if (configElement.getAttribute(ID_ATTRIBUTE_NAME) == null) { - logMissingAttribute(configElement, ID_ATTRIBUTE_NAME); - valid = false; - } - if (configElement.getAttribute(LABEL_ATTRIBUTE_NAME) == null) { - logMissingAttribute(configElement, LABEL_ATTRIBUTE_NAME); - valid = false; - } - if (configElement.getAttribute(FACTORY_CLASS_ATTRIBUTE_NAME) == null) { - logMissingAttribute(configElement, FACTORY_CLASS_ATTRIBUTE_NAME); - valid = false; - } - return valid; - } - - - // ********** public methods ********** - - /** - * Return the IDs for the registered JPA platforms. - * This does not activate any of the JPA platforms' plug-ins. - */ - public Iterable<String> getJpaPlatformIds() { - return this.jpaPlatformConfigurationElements.keySet(); - } - - /** - * Return whether the platform id is registered - */ - public boolean containsPlatform(String platformId) { - return this.jpaPlatformConfigurationElements.containsKey(platformId); - } - - /** - * Return the label for the JPA platform with the specified ID. - * This does not activate the JPA platform's plug-in. - */ - public String getJpaPlatformLabel(String id) { - return this.jpaPlatformConfigurationElements.get(id).getAttribute(LABEL_ATTRIBUTE_NAME); - } - - /** - * Return whether the platform represented by the given id supports the specified JPA facet version. - * This does not active the JPA platform's plug-in. - */ - public boolean platformSupportsJpaFacetVersion(String platformId, String jpaFacetVersion) { - IConfigurationElement configElement = this.jpaPlatformConfigurationElements.get(platformId); - return configElementSupportsJpaFacetVersion(configElement, jpaFacetVersion); - } - - boolean configElementSupportsJpaFacetVersion(IConfigurationElement configElement, String jpaFacetVersion) { - - // config element supports version if it explicitly sets it to that version - // or if it specifies no version at all - String ver = configElement.getAttribute(JPA_FACET_VERSION_ATTRIBUTE_NAME); - return (ver == null) || ver.equals(jpaFacetVersion); - } - - /** - * Return the IDs for the registered JPA platforms that support the - * specified JPA facet version. - * This does not activate the JPA platforms' plug-in. - */ - public Iterable<String> getJpaPlatformIdsForJpaFacetVersion(final String jpaFacetVersion) { - return new TransformationIterable<IConfigurationElement, String>(this.getConfigurationElementsForJpaFacetVersion(jpaFacetVersion)) { - @Override - protected String transform(IConfigurationElement configElement) { - return configElement.getAttribute(ID_ATTRIBUTE_NAME); - } - }; - } - - private Iterable<IConfigurationElement> getConfigurationElementsForJpaFacetVersion(final String jpaFacetVersion) { - return new FilteringIterable<IConfigurationElement>(this.jpaPlatformConfigurationElements.values()) { - @Override - protected boolean accept(IConfigurationElement configElement) { - return configElementSupportsJpaFacetVersion(configElement, jpaFacetVersion); - } - }; - } - - /** - * Return the ID for a JPA platform registered as a default platform. - * Returns null if there are no such registered platforms. - * Returns the first platform ID if there are multiple such registered platforms. - */ - public String getDefaultJpaPlatformId(String jpaFacetVersion) { - for (Map.Entry<String, IConfigurationElement> entry: this.jpaPlatformConfigurationElements.entrySet()) { - String defaultFlag = entry.getValue().getAttribute(DEFAULT_ATTRIBUTE_NAME); - String platformId = entry.getKey(); - if ((defaultFlag != null) && defaultFlag.equals("true") - && platformSupportsJpaFacetVersion(platformId, jpaFacetVersion)) { //$NON-NLS-1$ - return platformId; - } - } - return null; - } - - /** - * Return a new JPA platform for the specified ID. - * NB: This should only be called when instantiating a JPA platform - * when building a new JPA project. - * Unlike other registry methods, invoking this method may activate - * the plug-in. - */ - public JpaPlatform getJpaPlatform(IProject project) { - String id = JptCorePlugin.getJpaPlatformId(project); - IConfigurationElement configElement = this.jpaPlatformConfigurationElements.get(id); - if (configElement == null) { - log(JptCoreMessages.PLATFORM_ID_DOES_NOT_EXIST, id, project.getName()); - return null; - } - JpaPlatformFactory platformFactory = instantiate( - configElement.getContributor().getName(), QUALIFIED_EXTENSION_ID, - configElement.getAttribute(FACTORY_CLASS_ATTRIBUTE_NAME), JpaPlatformFactory.class); - if (platformFactory == null) { - throw new IllegalArgumentException(id); - } - return platformFactory.buildJpaPlatform(id); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformTester.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformTester.java index cf4f51e897..3526e066af 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformTester.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformTester.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. This + * 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 @@ -13,28 +13,41 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jpt.core.JptCorePlugin; +import org.eclipse.jpt.core.platform.JpaPlatformDescription; +import org.eclipse.jpt.core.platform.JpaPlatformGroupDescription; public class JpaPlatformTester extends PropertyTester { public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (! property.equals("jpaPlatform")) { //$NON-NLS-1$ + if (! (property.equals("jpaPlatform") || property.equals("jpaPlatformGroup")) + || ! (expectedValue instanceof String)) { //$NON-NLS-1$ return false; } - String platformId = null; + JpaPlatformDescription platform = null; if (receiver instanceof IResource) { - platformId = platformId(((IResource) receiver).getProject()); + platform = platform(((IResource) receiver).getProject()); } else if (receiver instanceof IJavaElement) { - platformId = platformId(((IJavaElement) receiver).getResource().getProject()); + platform = platform(((IJavaElement) receiver).getResource().getProject()); } - - return platformId == null ? false : platformId.equals(expectedValue); + if (property.equals("jpaPlatform")) { + JpaPlatformDescription otherPlatform = JptCorePlugin.getJpaPlatformManager().getJpaPlatform((String) expectedValue); + return platform == null ? false : platform.equals(otherPlatform); + } + if (property.equals("jpaPlatformGroup")) { + JpaPlatformGroupDescription group = (platform == null) ? null : platform.getGroup(); + JpaPlatformGroupDescription otherGroup = JptCorePlugin.getJpaPlatformManager().getJpaPlatformGroup((String) expectedValue); + return group == null ? false : group.equals(otherGroup); + } + return false; } - private String platformId(IProject project) { - return (project == null) ? null : JptCorePlugin.getJpaPlatformId(project); + private JpaPlatformDescription platform(IProject project) { + return (project == null) + ? null + : JptCorePlugin.getJpaPlatformManager().getJpaPlatform(JptCorePlugin.getJpaPlatformId(project)); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java index 0af4d4fffb..558f2ef6a5 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java @@ -19,8 +19,8 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jpt.core.JpaFacet; import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.JpaPlatformRegistry; import org.eclipse.jpt.core.internal.JptCoreMessages; +import org.eclipse.jpt.core.platform.JpaPlatformDescription; import org.eclipse.jpt.db.Catalog; import org.eclipse.jpt.db.ConnectionProfile; import org.eclipse.jpt.db.ConnectionProfileFactory; @@ -31,6 +31,7 @@ import org.eclipse.jpt.db.SchemaContainer; import org.eclipse.jpt.utility.internal.ArrayTools; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterables.EmptyIterable; +import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; import org.eclipse.jst.common.project.facet.core.libprov.IPropertyChangeListener; import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; @@ -424,8 +425,18 @@ public abstract class JpaFacetDataModelProvider } protected Iterable<String> buildValidPlatformIds() { - String jpaFacetVersion = this.getProjectFacetVersion().getVersionString(); - return JpaPlatformRegistry.instance().getJpaPlatformIdsForJpaFacetVersion(jpaFacetVersion); + return new TransformationIterable<JpaPlatformDescription, String>( + new FilteringIterable<JpaPlatformDescription>(JptCorePlugin.getJpaPlatformManager().getJpaPlatforms()) { + @Override + protected boolean accept(JpaPlatformDescription o) { + return o.supportsJpaFacetVersion(getProjectFacetVersion()); + } + }) { + @Override + protected String transform(JpaPlatformDescription o) { + return o.getId(); + } + }; } protected static final Comparator<DataModelPropertyDescriptor> DESCRIPTOR_COMPARATOR = @@ -521,7 +532,7 @@ public abstract class JpaFacetDataModelProvider } protected String getPlatformLabel(String platformId) { - return JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId); + return JptCorePlugin.getJpaPlatformManager().getJpaPlatform(platformId).getLabel(); } protected DataModelPropertyDescriptor buildConnectionDescriptor(String connectionName) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDataModelProvider.java index 2832f2fdc3..70a12f93f9 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDataModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDataModelProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. + * Copyright (c) 2006, 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. @@ -84,7 +84,7 @@ public class JpaFacetInstallDataModelProvider @Override protected String getDefaultPlatformId() { - return JptCorePlugin.getDefaultJpaPlatformId(getProjectFacetVersion().getVersionString()); + return JptCorePlugin.getDefaultJpaPlatform(getProjectFacetVersion()).getId(); } @Override diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetVersionChangeDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetVersionChangeDataModelProvider.java index 17a394b0f2..3efb401b89 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetVersionChangeDataModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetVersionChangeDataModelProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Oracle. + * Copyright (c) 2009, 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 @@ -15,8 +15,8 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.JpaPlatformRegistry; import org.eclipse.jpt.core.internal.JptCoreMessages; +import org.eclipse.jpt.core.platform.JpaPlatformDescription; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterables.CompositeIterable; @@ -104,8 +104,8 @@ public class JpaFacetVersionChangeDataModelProvider IStatus status = super.validatePlatformId(); if (status.isOK()) { - if (! JpaPlatformRegistry.instance().platformSupportsJpaFacetVersion( - getPlatformId(), getProjectFacetVersion().getVersionString())) { + JpaPlatformDescription platform = JptCorePlugin.getJpaPlatformManager().getJpaPlatform(getPlatformId()); + if (! platform.supportsJpaFacetVersion(getProjectFacetVersion())) { status = PLATFORM_DOES_NOT_SUPPORT_FACET_VERSION_STATUS; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformProvider.java index 6247e02782..fba0cd6952 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. + * Copyright (c) 2009, 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. @@ -48,9 +48,6 @@ import org.eclipse.jpt.core.internal.jpa2.context.persistence.Generic2_0Persiste public class Generic2_0JpaPlatformProvider extends AbstractJpaPlatformProvider { - public static final String ID = "generic2_0"; //$NON-NLS-1$ - - // singleton private static final JpaPlatformProvider INSTANCE = new Generic2_0JpaPlatformProvider(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProvider.java index d13fb7b225..da685ab03f 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProvider.java @@ -15,6 +15,7 @@ import java.util.Set; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jpt.core.JpaFacet; +import org.eclipse.jpt.core.JpaPlatform; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.context.persistence.Persistence; @@ -96,8 +97,12 @@ public class OrmFileCreationDataModelProvider if (getProject() == null) { return null; } - return JptCorePlugin.getJpaPlatform(getProject()).getMostRecentSupportedResourceType( - JptCorePlugin.ORM_XML_CONTENT_TYPE).getVersion(); + JpaPlatform jpaPlatform; + JpaProject jpaProject = getJpaProject(); + jpaPlatform = (jpaProject == null) + ? JptCorePlugin.getJpaPlatformManager().buildJpaPlatformImplementation(getProject()) + : jpaProject.getJpaPlatform(); + return jpaPlatform.getMostRecentSupportedResourceType(JptCorePlugin.ORM_XML_CONTENT_TYPE).getVersion(); } protected PersistenceUnit getDefaultPersistenceUnit() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/PersistenceFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/PersistenceFileCreationDataModelProvider.java index e1b03beb40..ae267abef7 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/PersistenceFileCreationDataModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/PersistenceFileCreationDataModelProvider.java @@ -11,6 +11,8 @@ package org.eclipse.jpt.core.internal.operations; import org.eclipse.jpt.core.JpaFacet; +import org.eclipse.jpt.core.JpaPlatform; +import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.resource.persistence.JPA; import org.eclipse.jpt.core.resource.persistence.v2_0.JPA2_0; @@ -43,8 +45,12 @@ public class PersistenceFileCreationDataModelProvider if (getProject() == null) { return null; } - return JptCorePlugin.getJpaPlatform(getProject()).getMostRecentSupportedResourceType( - JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE).getVersion(); + JpaPlatform jpaPlatform; + JpaProject jpaProject = getJpaProject(); + jpaPlatform = (jpaProject == null) + ? JptCorePlugin.getJpaPlatformManager().buildJpaPlatformImplementation(getProject()) + : jpaProject.getJpaPlatform(); + return jpaPlatform.getMostRecentSupportedResourceType(JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE).getVersion(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformDescriptionImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformDescriptionImpl.java new file mode 100644 index 0000000000..2984b24577 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformDescriptionImpl.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 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.core.internal.platform; + +import org.eclipse.jpt.core.JpaPlatform; +import org.eclipse.jpt.core.JpaPlatformFactory; +import org.eclipse.jpt.core.internal.XPointUtil; +import org.eclipse.jpt.core.platform.JpaPlatformDescription; +import org.eclipse.jpt.core.platform.JpaPlatformGroupDescription; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; + +public class JpaPlatformDescriptionImpl + implements JpaPlatformDescription { + + private String id; + private String pluginId; + private String label; + private String factoryClassName; + private IProjectFacetVersion jpaFacetVersion; + private boolean default_ = false; + private JpaPlatformGroupDescriptionImpl group; + + + public String getId() { + return this.id; + } + + void setId(String id) { + this.id = id; + } + + public String getPluginId() { + return this.pluginId; + } + + void setPluginId(String pluginId) { + this.pluginId = pluginId; + } + + public String getLabel() { + return this.label; + } + + void setLabel(String label) { + this.label = label; + } + + public String getFactoryClassName() { + return this.factoryClassName; + } + + void setFactoryClassName(String className) { + this.factoryClassName = className; + } + + public IProjectFacetVersion getJpaFacetVersion() { + return this.jpaFacetVersion; + } + + void setJpaFacetVersion(IProjectFacetVersion jpaFacetVersion) { + this.jpaFacetVersion = jpaFacetVersion; + } + + public boolean supportsJpaFacetVersion(IProjectFacetVersion jpaFacetVersion) { + return (this.jpaFacetVersion != null) ? this.jpaFacetVersion.equals(jpaFacetVersion) : true; + } + + public boolean isDefault() { + return this.default_; + } + + void setDefault(boolean default_) { + this.default_ = default_; + } + + public JpaPlatformGroupDescription getGroup() { + return this.group; + } + + void setGroup(JpaPlatformGroupDescriptionImpl group) { + this.group = group; + } + + public JpaPlatform buildJpaPlatform() { + JpaPlatformFactory factory = (JpaPlatformFactory) XPointUtil.instantiate( + this.pluginId, JpaPlatformManagerImpl.QUALIFIED_EXTENSION_POINT_ID, + this.factoryClassName, JpaPlatformFactory.class); + return factory.buildJpaPlatform(getId()); + } + + @Override + public String toString() { + return this.label; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformGroupDescriptionImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformGroupDescriptionImpl.java new file mode 100644 index 0000000000..3a3de3d42b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformGroupDescriptionImpl.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 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.core.internal.platform; + +import java.util.HashMap; +import java.util.Map; +import org.eclipse.jpt.core.platform.JpaPlatformDescription; +import org.eclipse.jpt.core.platform.JpaPlatformGroupDescription; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.iterables.SuperIterableWrapper; + +public class JpaPlatformGroupDescriptionImpl + implements JpaPlatformGroupDescription { + + private String id; + private String pluginId; + private String label; + private Map<String, JpaPlatformDescriptionImpl> platforms; + + + JpaPlatformGroupDescriptionImpl() { + this.platforms = new HashMap<String, JpaPlatformDescriptionImpl>(); + } + + public String getId() { + return this.id; + } + + void setId(String id) { + this.id = id; + } + + public String getPluginId() { + return this.pluginId; + } + + void setPluginId(String pluginId) { + this.pluginId = pluginId; + } + + public String getLabel() { + return this.label; + } + + void setLabel(String label) { + this.label = label; + } + + void addPlatform(JpaPlatformDescriptionImpl platform) { + this.platforms.put(platform.getId(), platform); + } + + public Iterable<JpaPlatformDescription> getPlatforms() { + return new SuperIterableWrapper<JpaPlatformDescription>(CollectionTools.collection(this.platforms.values())); + } + + @Override + public String toString() { + return this.label; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformManagerImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformManagerImpl.java new file mode 100644 index 0000000000..967fcd97d5 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformManagerImpl.java @@ -0,0 +1,238 @@ +/******************************************************************************* + * Copyright (c) 2006, 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.core.internal.platform; + +import static org.eclipse.jpt.core.internal.XPointUtil.*; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jpt.core.JpaFacet; +import org.eclipse.jpt.core.JpaPlatform; +import org.eclipse.jpt.core.JptCorePlugin; +import org.eclipse.jpt.core.internal.XPointUtil.XPointException; +import org.eclipse.jpt.core.platform.JpaPlatformDescription; +import org.eclipse.jpt.core.platform.JpaPlatformGroupDescription; +import org.eclipse.jpt.core.platform.JpaPlatformManager; +import org.eclipse.jpt.utility.internal.KeyedSet; +import org.eclipse.jpt.utility.internal.iterables.SuperIterableWrapper; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; + +/** + * Singleton registry for storing all the registered JPA platform configuration + * elements and instantiating JPA platforms from them. + */ +public class JpaPlatformManagerImpl + implements JpaPlatformManager { + + static final String EXTENSION_POINT_ID = "jpaPlatforms"; //$NON-NLS-1$ + static final String QUALIFIED_EXTENSION_POINT_ID = JptCorePlugin.PLUGIN_ID_ + EXTENSION_POINT_ID; + static final String PLATFORM_GROUP_ELEMENT = "jpaPlatformGroup"; //$NON-NLS-1$ + static final String PLATFORM_ELEMENT = "jpaPlatform"; //$NON-NLS-1$ + static final String ID_ATTRIBUTE = "id"; //$NON-NLS-1$ + static final String LABEL_ATTRIBUTE = "label"; //$NON-NLS-1$ + static final String FACTORY_CLASS_ATTRIBUTE = "factoryClass"; //$NON-NLS-1$ + static final String JPA_FACET_VERSION_ATTRIBUTE = "jpaFacetVersion"; //$NON-NLS-1$ + static final String DEFAULT_ATTRIBUTE = "default"; //$NON-NLS-1$ + static final String GROUP_ELEMENT = "group"; //$NON-NLS-1$ + + + private static final JpaPlatformManagerImpl INSTANCE = new JpaPlatformManagerImpl(); + + + public static JpaPlatformManagerImpl instance() { + return INSTANCE; + } + + + private KeyedSet<String, JpaPlatformGroupDescriptionImpl> jpaPlatformGroupDescriptions; + private KeyedSet<String, JpaPlatformDescriptionImpl> jpaPlatformDescriptions; + + + // ********** constructor/initialization ********** + + private JpaPlatformManagerImpl() { + super(); + this.jpaPlatformGroupDescriptions = new KeyedSet<String, JpaPlatformGroupDescriptionImpl>(); + this.jpaPlatformDescriptions = new KeyedSet<String, JpaPlatformDescriptionImpl>(); + readExtensions(); + } + + + private void readExtensions() { + final IExtensionRegistry registry = Platform.getExtensionRegistry(); + + final IExtensionPoint xpoint + = registry.getExtensionPoint(JptCorePlugin.PLUGIN_ID, EXTENSION_POINT_ID); + + if (xpoint == null) { + throw new IllegalStateException(); + } + + List<IConfigurationElement> platformGroupConfigs = new ArrayList<IConfigurationElement>(); + List<IConfigurationElement> platformConfigs = new ArrayList<IConfigurationElement>(); + + for (IExtension extension : xpoint.getExtensions()) { + for (IConfigurationElement element : extension.getConfigurationElements()) { + if (element.getName().equals(PLATFORM_GROUP_ELEMENT)) { + platformGroupConfigs.add(element); + } + else if (element.getName().equals(PLATFORM_ELEMENT)) { + platformConfigs.add(element); + } + } + } + + for (IConfigurationElement element : platformGroupConfigs) { + readPlatformGroupExtension(element); + } + + for (IConfigurationElement element : platformConfigs) { + readPlatformExtension(element); + } + } + + private void readPlatformGroupExtension(IConfigurationElement element) { + try { + final JpaPlatformGroupDescriptionImpl desc = new JpaPlatformGroupDescriptionImpl(); + + // plug-in id + desc.setPluginId(element.getContributor().getName()); + + // id + desc.setId(findRequiredAttribute(element, ID_ATTRIBUTE)); + + if (this.jpaPlatformGroupDescriptions.containsKey(desc.getId())) { + logDuplicateExtension(QUALIFIED_EXTENSION_POINT_ID, desc.getId()); + throw new XPointException(); + } + + // label + desc.setLabel(findRequiredAttribute(element, LABEL_ATTRIBUTE)); + + this.jpaPlatformGroupDescriptions.addItem(desc.getId(), desc); + } + catch (XPointException e) { + // Ignore and continue. The problem has already been reported to the user + // in the log. + } + } + + private void readPlatformExtension(IConfigurationElement element) { + try { + final JpaPlatformDescriptionImpl desc = new JpaPlatformDescriptionImpl(); + + // plug-in id + desc.setPluginId(element.getContributor().getName()); + + // id + desc.setId(findRequiredAttribute(element, ID_ATTRIBUTE)); + + if (this.jpaPlatformDescriptions.containsKey(desc.getId())) { + logDuplicateExtension(QUALIFIED_EXTENSION_POINT_ID, desc.getId()); + throw new XPointException(); + } + + // label + desc.setLabel(findRequiredAttribute(element, LABEL_ATTRIBUTE)); + + // factory class + desc.setFactoryClassName(findRequiredAttribute(element, FACTORY_CLASS_ATTRIBUTE)); + + // JPA facet version + String jpaFacetVersionString = element.getAttribute(JPA_FACET_VERSION_ATTRIBUTE); + if (jpaFacetVersionString != null) { + IProjectFacetVersion jpaFacetVersion = JpaFacet.FACET.getVersion(jpaFacetVersionString); + if (jpaFacetVersion != null) { + desc.setJpaFacetVersion(jpaFacetVersion); + } + else { + logInvalidValue(element, JPA_FACET_VERSION_ATTRIBUTE, jpaFacetVersionString); + throw new XPointException(); + } + } + + // default + String defaultString = element.getAttribute(DEFAULT_ATTRIBUTE); + if (defaultString != null) { + if (defaultString.equals("true")) { + desc.setDefault(true); + } + else if (defaultString.equals("false")) { + desc.setDefault(false); + } + else { + logInvalidValue(element, DEFAULT_ATTRIBUTE, defaultString); + throw new XPointException(); + } + } + + // group + String groupId = element.getAttribute(GROUP_ELEMENT); + if (groupId != null) { + JpaPlatformGroupDescriptionImpl group = this.jpaPlatformGroupDescriptions.getItem(groupId); + if (group != null) { + desc.setGroup(group); + group.addPlatform(desc); + } + else { + logInvalidValue(element, GROUP_ELEMENT, groupId); + throw new XPointException(); + } + } + + this.jpaPlatformDescriptions.addItem(desc.getId(), desc); + } + catch (XPointException e) { + // Ignore and continue. The problem has already been reported to the user + // in the log. + } + } + + + // ********** public methods ********** + + public Iterable<JpaPlatformGroupDescription> getJpaPlatformGroups() { + return new SuperIterableWrapper<JpaPlatformGroupDescription>(this.jpaPlatformGroupDescriptions.getItemSet()); + } + + public JpaPlatformGroupDescription getJpaPlatformGroup(String groupId) { + return this.jpaPlatformGroupDescriptions.getItem(groupId); + } + + public Iterable<JpaPlatformDescription> getJpaPlatforms() { + return new SuperIterableWrapper<JpaPlatformDescription>(this.jpaPlatformDescriptions.getItemSet()); + } + + public JpaPlatformDescription getJpaPlatform(String platformId) { + return this.jpaPlatformDescriptions.getItem(platformId); + } + + public JpaPlatformDescription getDefaultJpaPlatform(IProjectFacetVersion jpaFacetVersion) { + for (JpaPlatformDescription platform : getJpaPlatforms()) { + if (platform.isDefault() && platform.supportsJpaFacetVersion(jpaFacetVersion)) { + return platform; + } + } + return null; + } + public JpaPlatform buildJpaPlatformImplementation(IProject project) { + String jpaPlatformId = JptCorePlugin.getJpaPlatformId(project); + JpaPlatformDescriptionImpl platformDesc = this.jpaPlatformDescriptions.getItem(jpaPlatformId); + if (platformDesc == null) { + throw new IllegalArgumentException("Project does not have a recognized JPA platform."); + } + return platformDesc.buildJpaPlatform(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/GenericPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/GenericPlatform.java new file mode 100644 index 0000000000..4d9ec12c39 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/GenericPlatform.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 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.core.platform; + +import org.eclipse.jpt.core.JptCorePlugin; + +/** + * Constants pertaining to the Generic JPA platforms and their group. + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 3.0 + * @since 3.0 + */ +public class GenericPlatform { + + public static final JpaPlatformGroupDescription GROUP + = JptCorePlugin.getJpaPlatformManager().getJpaPlatformGroup("generic"); //$NON-NLS-1$ + + public static final JpaPlatformDescription VERSION_1_0 + = JptCorePlugin.getJpaPlatformManager().getJpaPlatform("generic"); //$NON-NLS-1$ + + public static final JpaPlatformDescription VERSION_2_0 + = JptCorePlugin.getJpaPlatformManager().getJpaPlatform("generic2_0"); //$NON-NLS-1$ + + /** + * Not for instantiation + */ + private GenericPlatform() {} +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/JpaPlatformDescription.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/JpaPlatformDescription.java new file mode 100644 index 0000000000..e52a110409 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/JpaPlatformDescription.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 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.core.platform; + +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; + +/** + * Contains metadata that describes a JPA platform. Not intended to be implemented by clients. + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 3.0 + * @since 3.0 + */ +public interface JpaPlatformDescription { + + public String getId(); + + public String getPluginId(); + + public String getLabel(); + + public String getFactoryClassName(); + + public boolean supportsJpaFacetVersion(IProjectFacetVersion jpaFacetVersion); + + public boolean isDefault(); + + public JpaPlatformGroupDescription getGroup(); +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/JpaPlatformGroupDescription.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/JpaPlatformGroupDescription.java new file mode 100644 index 0000000000..f97f9cc96c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/JpaPlatformGroupDescription.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 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.core.platform; + +/** + * Contains metadata that describes a JPA platform group. Not intended to be implemented by clients. + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 3.0 + * @since 3.0 + */ +public interface JpaPlatformGroupDescription { + + public String getId(); + + public String getPluginId(); + + public String getLabel(); + + public Iterable<JpaPlatformDescription> getPlatforms(); +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/JpaPlatformManager.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/JpaPlatformManager.java new file mode 100644 index 0000000000..05c6fb10c3 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/platform/JpaPlatformManager.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 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.core.platform; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jpt.core.JpaPlatform; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; + +/** + * Entry point to the "jpaPlatforms" extension point + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 3.0 + * @since 3.0 + */ +public interface JpaPlatformManager { + + Iterable<JpaPlatformGroupDescription> getJpaPlatformGroups(); + + JpaPlatformGroupDescription getJpaPlatformGroup(String groupId); + + Iterable<JpaPlatformDescription> getJpaPlatforms(); + + JpaPlatformDescription getJpaPlatform(String platformId); + + /** + * Returns the first JPA platform registered as a default platform and which supports the given + * JPA facet version. + * Returns null if there are no such registered platforms. + */ + JpaPlatformDescription getDefaultJpaPlatform(IProjectFacetVersion jpaFacetVersion); + + JpaPlatform buildJpaPlatformImplementation(IProject project); +} |