Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2007-10-10 16:25:28 +0000
committerbvosburgh2007-10-10 16:25:28 +0000
commit4575fe951ae35c03d3b72756563ebcda9a77d656 (patch)
tree2f6fbf32056c4d0bc7ce4f6f6addfcfef370606a /jpa/plugins/org.eclipse.jpt.core
parentce78078caefe4a478e47e72e8d1fcdd768210ae2 (diff)
downloadwebtools.dali-4575fe951ae35c03d3b72756563ebcda9a77d656.tar.gz
webtools.dali-4575fe951ae35c03d3b72756563ebcda9a77d656.tar.xz
webtools.dali-4575fe951ae35c03d3b72756563ebcda9a77d656.zip
[201159] model rework
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core')
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/model/old_core.ecore41
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/model/old_coreModels.genmodel30
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/plugin.xml24
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaCoreConstants.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaDataSource.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaEObject.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFactory.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFile.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaModel.java47
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaNodeModel.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaPlatform.java22
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaProject.java198
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaRootContentNode.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCoreFactory.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCorePackage.java462
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaDataSource.java234
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaEObject.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaFile.java43
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModel.java403
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java1061
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaNodeModel.java139
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java233
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProject.java1073
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProjectAdapterFactory.java18
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCorePlugin.java309
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleJpaProjectConfig.java60
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaJpaFileContentProvider.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsAdapterFactory.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsSwitch.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaAdapterFactory.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaSwitch.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/EntityMappingsInternal.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPersistentType.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRootContentNode.java26
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmAdapterFactory.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmSwitch.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/PersistenceXmlRootContentNode.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceAdapterFactory.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceSwitch.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/IJpaFacetDataModelProperties.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java188
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java134
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetPostInstallDelegate.java128
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUninstallDelegate.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUtils.java134
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsAdapterFactory.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsSwitch.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaFactory.java27
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaPlatform.java76
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaProjectContext.java49
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java32
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericJpaFactory.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericPlatform.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceConstants.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceInitializer.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/synch/SynchronizeClassesJob.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreAdapterFactory.java102
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreSwitch.java131
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaHelper.java18
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidator.java37
63 files changed, 2726 insertions, 3201 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/model/old_core.ecore b/jpa/plugins/org.eclipse.jpt.core/model/old_core.ecore
index 9f78292dc4..95405b246e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/model/old_core.ecore
+++ b/jpa/plugins/org.eclipse.jpt.core/model/old_core.ecore
@@ -3,47 +3,8 @@
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="internal"
nsURI="jpt.core.xmi" nsPrefix="jpt.core">
- <eClassifiers xsi:type="ecore:EClass" name="IJpaModel" abstract="true" interface="true"/>
- <eClassifiers xsi:type="ecore:EClass" name="JpaModel" eSuperTypes="#//JpaEObject #//IJpaModel">
- <eStructuralFeatures xsi:type="ecore:EReference" name="projects" upperBound="-1"
- eType="#//IJpaProject" containment="true"/>
- </eClassifiers>
- <eClassifiers xsi:type="ecore:EClass" name="IJpaEObject" abstract="true" interface="true">
- <eOperations name="getJpaProject" eType="#//IJpaProject"/>
- </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="IJpaEObject" abstract="true" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="JpaEObject" abstract="true" eSuperTypes="#//IJpaEObject"/>
- <eClassifiers xsi:type="ecore:EClass" name="IJpaProject" abstract="true" interface="true"
- eSuperTypes="#//IJpaEObject">
- <eOperations name="getModel" lowerBound="1" eType="#//IJpaModel"/>
- <eOperations name="getPlatform" ordered="false" unique="false" lowerBound="1"
- eType="#//IJpaPlatform"/>
- <eOperations name="setPlatform">
- <eParameters name="platformId" ordered="false" lowerBound="1" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
- </eOperations>
- <eOperations name="getDataSource" lowerBound="1" eType="#//IJpaDataSource"/>
- <eOperations name="setDataSource" ordered="false" unique="false" lowerBound="1">
- <eParameters name="connectionProfileName" ordered="false" unique="false" lowerBound="1"
- eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
- </eOperations>
- <eOperations name="isDiscoverAnnotatedClasses" lowerBound="1" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EBoolean"/>
- <eOperations name="setDiscoverAnnotatedClasses" ordered="false" unique="false"
- lowerBound="1">
- <eParameters name="discoverAnnotatedClasses" ordered="false" unique="false"
- lowerBound="1" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EBoolean"/>
- </eOperations>
- </eClassifiers>
- <eClassifiers xsi:type="ecore:EClass" name="JpaProject" eSuperTypes="#//JpaEObject #//IJpaProject">
- <eStructuralFeatures xsi:type="ecore:EReference" name="platform" ordered="false"
- unique="false" lowerBound="1" eType="#//IJpaPlatform" resolveProxies="false"/>
- <eStructuralFeatures xsi:type="ecore:EReference" name="dataSource" ordered="false"
- unique="false" eType="#//IJpaDataSource" containment="true" resolveProxies="false"/>
- <eStructuralFeatures xsi:type="ecore:EAttribute" name="discoverAnnotatedClasses"
- ordered="false" unique="false" lowerBound="1" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EBoolean"
- defaultValueLiteral="false" unsettable="true"/>
- <eStructuralFeatures xsi:type="ecore:EReference" name="files" upperBound="-1"
- eType="#//IJpaFile" containment="true"/>
- </eClassifiers>
- <eClassifiers xsi:type="ecore:EClass" name="IJpaPlatform" abstract="true" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="IJpaDataSource" abstract="true" interface="true"
eSuperTypes="#//IJpaEObject">
<eOperations name="getConnectionProfileName" ordered="false" unique="false" lowerBound="1"
diff --git a/jpa/plugins/org.eclipse.jpt.core/model/old_coreModels.genmodel b/jpa/plugins/org.eclipse.jpt.core/model/old_coreModels.genmodel
index abf3828c28..ff43d52470 100644
--- a/jpa/plugins/org.eclipse.jpt.core/model/old_coreModels.genmodel
+++ b/jpa/plugins/org.eclipse.jpt.core/model/old_coreModels.genmodel
@@ -18,36 +18,8 @@
<genEnumLiterals ecoreEnumLiteral="old_core.ecore#//AccessType/PROPERTY"/>
<genEnumLiterals ecoreEnumLiteral="old_core.ecore#//AccessType/FIELD"/>
</genEnums>
- <genClasses ecoreClass="old_core.ecore#//IJpaModel"/>
- <genClasses ecoreClass="old_core.ecore#//JpaModel">
- <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference old_core.ecore#//JpaModel/projects"/>
- </genClasses>
- <genClasses ecoreClass="old_core.ecore#//IJpaEObject">
- <genOperations ecoreOperation="old_core.ecore#//IJpaEObject/getJpaProject"/>
- </genClasses>
+ <genClasses ecoreClass="old_core.ecore#//IJpaEObject"/>
<genClasses image="false" ecoreClass="old_core.ecore#//JpaEObject"/>
- <genClasses ecoreClass="old_core.ecore#//IJpaProject">
- <genOperations ecoreOperation="old_core.ecore#//IJpaProject/getModel"/>
- <genOperations ecoreOperation="old_core.ecore#//IJpaProject/getPlatform"/>
- <genOperations ecoreOperation="old_core.ecore#//IJpaProject/setPlatform">
- <genParameters ecoreParameter="old_core.ecore#//IJpaProject/setPlatform/platformId"/>
- </genOperations>
- <genOperations ecoreOperation="old_core.ecore#//IJpaProject/getDataSource"/>
- <genOperations ecoreOperation="old_core.ecore#//IJpaProject/setDataSource">
- <genParameters ecoreParameter="old_core.ecore#//IJpaProject/setDataSource/connectionProfileName"/>
- </genOperations>
- <genOperations ecoreOperation="old_core.ecore#//IJpaProject/isDiscoverAnnotatedClasses"/>
- <genOperations ecoreOperation="old_core.ecore#//IJpaProject/setDiscoverAnnotatedClasses">
- <genParameters ecoreParameter="old_core.ecore#//IJpaProject/setDiscoverAnnotatedClasses/discoverAnnotatedClasses"/>
- </genOperations>
- </genClasses>
- <genClasses ecoreClass="old_core.ecore#//JpaProject">
- <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference old_core.ecore#//JpaProject/platform"/>
- <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference old_core.ecore#//JpaProject/dataSource"/>
- <genFeatures createChild="false" ecoreFeature="ecore:EAttribute old_core.ecore#//JpaProject/discoverAnnotatedClasses"/>
- <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference old_core.ecore#//JpaProject/files"/>
- </genClasses>
- <genClasses ecoreClass="old_core.ecore#//IJpaPlatform"/>
<genClasses ecoreClass="old_core.ecore#//IJpaDataSource">
<genOperations ecoreOperation="old_core.ecore#//IJpaDataSource/getConnectionProfileName"/>
</genClasses>
diff --git a/jpa/plugins/org.eclipse.jpt.core/plugin.xml b/jpa/plugins/org.eclipse.jpt.core/plugin.xml
index a9363ed563..2a029d9b15 100644
--- a/jpa/plugins/org.eclipse.jpt.core/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.core/plugin.xml
@@ -129,13 +129,6 @@
</constraint>
</project-facet-version>
- <preset id="jpt.jpa.preset">
- <label>%JPA_PRESET_LABEL</label>
- <facet id="jst.java" version="5.0"/>
- <facet id="jst.utility" version="1.0"/>
- <facet id="jpt.jpa" version="1.0"/>
- </preset>
-
<template id="jpt.jpa.template">
<label>%JPA_TEMPLATE_LABEL</label>
<fixed facet="jst.java"/>
@@ -149,13 +142,18 @@
<delegate class="org.eclipse.jpt.core.internal.facet.JpaFacetInstallDelegate"/>
</action>
- <action facet="jpt.jpa" type="UNINSTALL" id="jpt.jpa.uninstall">
- <delegate class="org.eclipse.jpt.core.internal.facet.JpaFacetUninstallDelegate"/>
- </action>
+ </extension>
+
+
+ <extension
+ point="org.eclipse.wst.common.project.facet.core.presets">
- <event-handler facet="jpt.jpa" type="POST_INSTALL">
- <delegate class="org.eclipse.jpt.core.internal.facet.JpaFacetPostInstallDelegate"/>
- </event-handler>
+ <static-preset id="jpt.jpa.preset">
+ <label>%JPA_PRESET_LABEL</label>
+ <facet id="jst.java" version="5.0"/>
+ <facet id="jst.utility" version="1.0"/>
+ <facet id="jpt.jpa" version="1.0"/>
+ </static-preset>
</extension>
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaCoreConstants.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaCoreConstants.java
deleted file mode 100644
index 6d10115e7c..0000000000
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaCoreConstants.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2007 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;
-
-public interface IJpaCoreConstants
-{
- /**
- * Configuration option
- */
- public static final String JPA_PLATFORM = JptCorePlugin.PLUGIN_ID + ".platform"; //$NON-NLS-1$
-
- /**
- * Configuration option
- */
- public static final String DATA_SOURCE_CONNECTION_NAME = JptCorePlugin.PLUGIN_ID + ".dataSource.connectionName"; //$NON-NLS-1$
-
- /**
- * Configuration option
- */
- public static final String DISCOVER_ANNOTATED_CLASSES = JptCorePlugin.PLUGIN_ID + ".discoverAnnotatedClasses"; //$NON-NLS-1$
-}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaDataSource.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaDataSource.java
index 4aae51c938..60414702f7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaDataSource.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaDataSource.java
@@ -1,14 +1,16 @@
/*******************************************************************************
* Copyright (c) 2007 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.
+ * 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 org.eclipse.jpt.db.internal.ConnectionProfile;
+
/**
* <!-- begin-user-doc -->
* A representation of the model object '<em><b>IJpa Data Source</b></em>'.
@@ -34,4 +36,12 @@ public interface IJpaDataSource extends IJpaEObject
boolean isConnected();
boolean hasAConnection();
+
+ /**
+ * The data source's connection profile should never be null.
+ * If we do not have a connection, return a "null" connection profile.
+ */
+ ConnectionProfile getConnectionProfile();
+
+ void dispose();
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaEObject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaEObject.java
index ee0c81021f..1c1a5c22ad 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaEObject.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaEObject.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -24,12 +24,6 @@ import org.eclipse.emf.ecore.EObject;
*/
public interface IJpaEObject extends EObject
{
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @model kind="operation"
- * @generated
- */
IJpaProject getJpaProject();
/**
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFactory.java
index 57d388eebb..8c405d8dcb 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFactory.java
@@ -1,14 +1,16 @@
/*******************************************************************************
* Copyright (c) 2007 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.
+ * 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 org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jpt.core.internal.content.java.mappings.IJavaBasic;
import org.eclipse.jpt.core.internal.content.java.mappings.IJavaEmbeddable;
import org.eclipse.jpt.core.internal.content.java.mappings.IJavaEmbedded;
@@ -34,8 +36,14 @@ import org.eclipse.jpt.core.internal.platform.BaseJpaFactory;
* for creating new mappings types.
* @see BaseJpaFactory
*/
-public interface IJpaFactory
-{
+public interface IJpaFactory {
+
+ IJpaProject createJpaProject(IJpaProject.Config config) throws CoreException;
+
+ IJpaDataSource createDataSource(IJpaProject jpaProject, String connectionProfileName);
+
+ IJpaFile createJpaFile(IJpaProject jpaProject, IFile file, IJpaFileContentProvider provider);
+
IJavaEntity createJavaEntity(Type type);
IJavaEmbeddable createJavaEmbeddable(Type type);
@@ -61,4 +69,5 @@ public interface IJpaFactory
IJavaTransient createJavaTransient(Attribute attribute);
IJavaVersion createJavaVersion(Attribute attribute);
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFile.java
index f74845a566..cb27fe0861 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFile.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaFile.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.core.internal;
import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.ElementChangedEvent;
/**
* <!-- begin-user-doc -->
@@ -55,4 +56,15 @@ public interface IJpaFile extends IJpaEObject
* This may (and often will) be <code>null</code>.
*/
IJpaContentNode getContentNode(int offset);
+
+ /**
+ * Forward the Java element changed event to the JPA file's content.
+ */
+ void javaElementChanged(ElementChangedEvent event);
+
+ /**
+ * The JPA file has been removed from the JPA project. Clean up any
+ * hooks to external resources etc.
+ */
+ void dispose();
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaModel.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaModel.java
index 890d84a482..2d3790561b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaModel.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaModel.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -10,31 +10,38 @@
package org.eclipse.jpt.core.internal;
import java.util.Iterator;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jpt.utility.internal.model.Model;
/**
- * <!-- begin-user-doc -->
- * A representation of the model object '<em><b>IJpa Model</b></em>'.
- * <!-- end-user-doc -->
- *
- *
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaModel()
- * @model kind="class" interface="true" abstract="true"
- * @generated
+ * The JPA model holds all the JPA projects.
*/
-public interface IJpaModel extends EObject
-{
+public interface IJpaModel extends Model {
+
+ /**
+ * Return the JPA project corresponding to the specified Eclipse project.
+ * Return null if unable to associate the specified Eclipse project
+ * with a JPA project.
+ */
+ IJpaProject jpaProject(IProject project) throws CoreException;
+
/**
- * Returns the IJpaProject corresponding to the given IProject.
- * Returns <code>null</code> if unable to associate the given IProject
- * with an IJpaProject.
+ * Return whether the JPA model contains a JPA project corresponding
+ * to the specified Eclipse project.
*/
- IJpaProject getJpaProject(IProject project) throws CoreException;
+ boolean containsJpaProject(IProject project);
/**
- * Returns a (non-modifiable) Iterator on all the IJpaProjects in the model.
+ * Return the JPA model's JPA projects.
*/
- Iterator<IJpaProject> jpaProjects();
+ Iterator<IJpaProject> jpaProjects() throws CoreException;
+ public static final String JPA_PROJECTS_COLLECTION = "jpaProjects";
+
+ /**
+ * Return the size of the JPA model's list of JPA projects.
+ */
+ int jpaProjectsSize();
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaNodeModel.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaNodeModel.java
new file mode 100644
index 0000000000..4ef77bb6b1
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaNodeModel.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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 java.util.Iterator;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jpt.utility.internal.node.NodeModel;
+
+public interface IJpaNodeModel extends NodeModel {
+
+ /**
+ * Return the resource that most directly contains the object.
+ * This is used by JpaHelper.
+ */
+ IResource resource();
+
+ /**
+ * Return the JPA project the object belongs to.
+ */
+ IJpaProject jpaProject();
+
+
+ // ********** covariant overrides **********
+
+ IJpaNodeModel parent();
+
+ Iterator<? extends IJpaNodeModel> children();
+
+ IJpaProject root();
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaPlatform.java
index 17c4a1a310..4b2c6c2d0b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaPlatform.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaPlatform.java
@@ -1,8 +1,8 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 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.
+ * Copyright (c) 2006, 2007 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
@@ -12,6 +12,8 @@ package org.eclipse.jpt.core.internal;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jpt.core.internal.content.java.IDefaultJavaAttributeMappingProvider;
import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMapping;
@@ -20,7 +22,6 @@ import org.eclipse.jpt.core.internal.content.java.IJavaTypeMapping;
import org.eclipse.jpt.core.internal.content.java.IJavaTypeMappingProvider;
import org.eclipse.jpt.core.internal.content.persistence.PersistenceUnit;
import org.eclipse.jpt.core.internal.platform.IContext;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
/**
* This interface is to be implemented by a JPA vendor to provide extensions to
@@ -61,6 +62,13 @@ public interface IJpaPlatform
IJpaFactory getJpaFactory();
+ /**
+ * Construct a JPA file for the specified file, to be
+ * added to the specified JPA project. Return null if unable to create
+ * the JPA file (e.g. the content type is unrecognized).
+ */
+ IJpaFile createJpaFile(IJpaProject jpaProject, IFile file);
+
// ********** Persistence Unit ********************************************
boolean containsPersistenceUnitNamed(String name);
@@ -164,7 +172,9 @@ public interface IJpaPlatform
/**
* Adds validation messages to the growing list of messages
*/
- void addToMessages(List<IMessage> messages);
+ @SuppressWarnings("restriction")
+ void addToMessages(List<org.eclipse.wst.validation.internal.provisional.core.IMessage> messages);
+
/**
* Returns the IGeneratorRepository for the persistence unit of the
* given IPersistentType. A NullGeneratorRepository should be returned
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaProject.java
index c7ffb1dcee..571f550d36 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaProject.java
@@ -9,148 +9,198 @@
******************************************************************************/
package org.eclipse.jpt.core.internal;
-import java.util.Collection;
import java.util.Iterator;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.content.java.JavaPersistentType;
import org.eclipse.jpt.db.internal.ConnectionProfile;
import org.eclipse.jpt.utility.internal.CommandExecutor;
import org.eclipse.jpt.utility.internal.CommandExecutorProvider;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
/**
- * <!-- begin-user-doc -->
- * A representation of the model object '<em><b>IJpa Project</b></em>'.
- * <!-- end-user-doc -->
- *
- *
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaProject()
- * @model kind="class" interface="true" abstract="true"
- * @generated
+ *
*/
-public interface IJpaProject extends IJpaEObject
-{
+public interface IJpaProject extends IJpaNodeModel {
+
/**
- * Return the IProject associated with this JPA project
+ * Return the Eclipse project associated with the JPA project.
*/
- IProject getProject();
+ IProject project();
/**
- * Return the IJavaProject associated with the JPA project
+ * Return the JPA project's name, which is the Eclipse project's name.
*/
- IJavaProject getJavaProject();
+ String name();
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @model kind="operation" required="true"
- * @generated
+ * Return the Java project associated with the JPA project.
*/
- IJpaModel getModel();
+ IJavaProject javaProject();
- IJpaPlatform getPlatform();
+ /**
+ * Return the vendor-specific JPA platform that builds the JPA project
+ * and its contents.
+ */
+ IJpaPlatform jpaPlatform();
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @model platformIdRequired="true" platformIdOrdered="false"
- * @generated
+ * Return the project's connection
*/
- void setPlatform(String platformId);
+ ConnectionProfile connectionProfile();
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @model kind="operation" required="true"
- * @generated
+ * Return the data source the JPA project is mapped to.
*/
- IJpaDataSource getDataSource();
+ IJpaDataSource dataSource();
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @model connectionProfileNameUnique="false" connectionProfileNameRequired="true" connectionProfileNameOrdered="false"
- * @generated
+ * Return the JPA project's JPA files.
*/
- void setDataSource(String connectionProfileName);
+ Iterator<IJpaFile> jpaFiles();
+ public static final String JPA_FILES_COLLECTION = "jpaFiles";
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @model kind="operation" required="true"
- * @generated
+ * Return the JPA file corresponding to the specified file.
+ * Return null if unable to associate the given file
+ * with a JPA file.
*/
- boolean isDiscoverAnnotatedClasses();
+ IJpaFile jpaFile(IFile file);
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @model discoverAnnotatedClassesUnique="false" discoverAnnotatedClassesRequired="true" discoverAnnotatedClassesOrdered="false"
- * @generated
+ * Return the JPA project's JPA files for the specified content type ID.
+ * The content type ID should match that given in the
+ * JPA file content provider.
*/
- void setDiscoverAnnotatedClasses(boolean discoverAnnotatedClasses);
+ Iterator<IJpaFile> jpaFiles(String contentTypeId);
/**
- * Return the root "deploy path" for this project.
- *
- * Web projects return "WEB-INF/classes".
- * All other projects simply return "".
+ * Return the JPA project's Java JPA files.
*/
- String rootDeployLocation();
+ Iterator<IJpaFile> javaJpaFiles();
/**
- * Returns the IJpaFile corresponding to the given IFile.
- * Returns <code>null</code> if unable to associate the given IFile
- * with an IJpaFile.
+ * Return the JPA project's Java persistent types.
*/
- IJpaFile getJpaFile(IFile file) throws CoreException;
+ Iterator<JavaPersistentType> javaPersistentTypes();
/**
- * Return a Collection of IJpaFiles for the given contentType.
- * The contentType should match that given in the IJpaFileContentProvider
+ * Return the Java persistent type for the specified JDT type;
+ * null, if none exists.
*/
- Collection<IJpaFile> jpaFiles(String contentType);
+ JavaPersistentType javaPersistentType(IType type);
/**
- * Returns a (non-modifiable) Iterator on all the IJpaFiles in the project.
+ * Synchronize the JPA project's JPA files with the specified resource
+ * delta, watching for added and removed files.
*/
- Iterator<IJpaFile> jpaFiles();
+ void checkForAddedOrRemovedJpaFiles(IResourceDelta delta) throws CoreException;
/**
- * Return a JavaPersistentType for the IType, if it exists, null otherwise.
+ * Forward the Java element change event to the JPA project's JPA files.
*/
- JavaPersistentType findJavaPersistentType(IType type);
+ void javaElementChanged(ElementChangedEvent event);
/**
- * Reconnect the model together, recalculating default values as needed
+ * Return whether the JPA project will "discover" annotated classes
+ * automatically, as opposed to requiring the classes to be
+ * listed in persistence.xml.
*/
- void resynch();
+ boolean discoversAnnotatedClasses();
/**
- * Returns all the validation messages for this project
+ * Set whether the JPA project will "discover" annotated classes
+ * automatically, as opposed to requiring the classes to be
+ * listed in persistence.xml.
*/
- Iterator<IMessage> validationMessages();
+ void setDiscoversAnnotatedClasses(boolean discoversAnnotatedClasses);
- ConnectionProfile connectionProfile();
+ /**
+ * Return project's validation messages.
+ */
+ @SuppressWarnings("restriction")
+ Iterator<org.eclipse.wst.validation.internal.provisional.core.IMessage> validationMessages();
/**
- * Return a thread-specific implementation of the CommandExecutor
- * interface that will be used to execute a command to modify a shared
- * document.
+ * Return the JPA project's root "deploy path".
+ * JPA projects associated with Web projects return "WEB-INF/classes";
+ * all others simply return an empty string.
+ */
+ String rootDeployLocation();
+
+ /**
+ * The JPA project has been removed from the JPA model. Clean up any
+ * hooks to external resources etc.
*/
- CommandExecutor getThreadLocalModifySharedDocumentCommandExecutor();
+ void dispose();
+
+
+ // ********** support for modifying shared documents **********
/**
* Set a thread-specific implementation of the CommandExecutor
* interface that will be used to execute a command to modify a shared
- * document. This allows background clients to modify documents that are
- * already present in the UI.
+ * document. If necessary, the command executor can be cleared by
+ * setting it to null.
+ * This allows background clients to modify documents that are
+ * already present in the UI. See implementations of CommandExecutor.
*/
void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor);
+ /**
+ * Return the project-wide implementation of the CommandExecutorProvider
+ * interface.
+ */
CommandExecutorProvider modifySharedDocumentCommandExecutorProvider();
+
+
+ // ********** updating defaults etc. **********
+
+ /**
+ * Reconnect the model together, recalculating default values as needed
+ */
+ void update();
+
+ IStatus update(IProgressMonitor monitor);
+
+
+ // ********** config that can be used to construct a JPA project **********
+
+ /**
+ * The settings used to construct a JPA project.
+ */
+ interface Config {
+
+ /**
+ * Return the Eclipse project to be associated with the new JPA project.
+ */
+ IProject project();
+
+ /**
+ * Return the JPA platform to be associated with the new JPA project.
+ */
+ IJpaPlatform jpaPlatform();
+
+ /**
+ * Return the name of the connection profile to be associated
+ * with the new JPA project. (This connection profile wraps a DTP
+ * connection profile.)
+ */
+ String connectionProfileName();
+
+ /**
+ * Return whether the new JPA project is to "discover" annotated
+ * classes.
+ */
+ boolean discoverAnnotatedClasses();
+
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaRootContentNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaRootContentNode.java
index 00db1dbb4b..8688b2a04e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaRootContentNode.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IJpaRootContentNode.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 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
+ * Copyright (c) 2006, 2007 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
- *******************************************************************************/
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal;
import org.eclipse.jdt.core.ElementChangedEvent;
@@ -54,7 +55,7 @@ public interface IJpaRootContentNode extends IJpaContentNode
/**
* Handle java change as befits this file content
*/
- void handleJavaElementChangedEvent(ElementChangedEvent event);
+ void javaElementChanged(ElementChangedEvent event);
/**
* Dispose before removed from model
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCoreFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCoreFactory.java
index 35c47a1039..b476ae818c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCoreFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCoreFactory.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.core.internal;
-import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
@@ -72,10 +72,6 @@ public class JpaCoreFactory extends EFactoryImpl
@Override
public EObject create(EClass eClass) {
switch (eClass.getClassifierID()) {
- case JpaCorePackage.JPA_MODEL :
- return createJpaModel();
- case JpaCorePackage.JPA_PROJECT :
- return createJpaProject();
case JpaCorePackage.JPA_DATA_SOURCE :
return createJpaDataSource();
case JpaCorePackage.JPA_FILE :
@@ -122,36 +118,15 @@ public class JpaCoreFactory extends EFactoryImpl
* <!-- end-user-doc -->
* @generated
*/
- public JpaModel createJpaModel() {
- JpaModel jpaModel = new JpaModel();
- return jpaModel;
- }
-
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- public JpaProject createJpaProject() {
- JpaProject jpaProject = new JpaProject();
- return jpaProject;
- }
-
- public JpaProject createJpaProject(IProject project) {
- JpaProject jpaProject = new JpaProject(project);
- return jpaProject;
- }
-
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
public JpaDataSource createJpaDataSource() {
JpaDataSource jpaDataSource = new JpaDataSource();
return jpaDataSource;
}
+ public JpaDataSource createJpaDataSource(IJpaProject jpaProject, String connectionProfileName) {
+ return new JpaDataSource(jpaProject, connectionProfileName);
+ }
+
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -162,6 +137,10 @@ public class JpaCoreFactory extends EFactoryImpl
return jpaFile;
}
+ public IJpaFile createJpaFile(IJpaProject jpaProject, IFile file, IJpaFileContentProvider provider) {
+ return new JpaFile(jpaProject, file, provider);
+ }
+
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCorePackage.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCorePackage.java
index b0819139d6..058aeaa99e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCorePackage.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaCorePackage.java
@@ -73,25 +73,6 @@ public class JpaCorePackage extends EPackageImpl
public static final JpaCorePackage eINSTANCE = org.eclipse.jpt.core.internal.JpaCorePackage.init();
/**
- * The meta object id for the '{@link org.eclipse.jpt.core.internal.IJpaModel <em>IJpa Model</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.IJpaModel
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaModel()
- * @generated
- */
- public static final int IJPA_MODEL = 0;
-
- /**
- * The number of structural features of the '<em>IJpa Model</em>' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int IJPA_MODEL_FEATURE_COUNT = 0;
-
- /**
* The meta object id for the '{@link org.eclipse.jpt.core.internal.IJpaEObject <em>IJpa EObject</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -99,7 +80,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaEObject()
* @generated
*/
- public static final int IJPA_EOBJECT = 2;
+ public static final int IJPA_EOBJECT = 0;
/**
* The number of structural features of the '<em>IJpa EObject</em>' class.
@@ -118,7 +99,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaEObject()
* @generated
*/
- public static final int JPA_EOBJECT = 3;
+ public static final int JPA_EOBJECT = 1;
/**
* The number of structural features of the '<em>Jpa EObject</em>' class.
@@ -130,127 +111,6 @@ public class JpaCorePackage extends EPackageImpl
public static final int JPA_EOBJECT_FEATURE_COUNT = IJPA_EOBJECT_FEATURE_COUNT + 0;
/**
- * The meta object id for the '{@link org.eclipse.jpt.core.internal.JpaModel <em>Jpa Model</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.JpaModel
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaModel()
- * @generated
- */
- public static final int JPA_MODEL = 1;
-
- /**
- * The feature id for the '<em><b>Projects</b></em>' containment reference list.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int JPA_MODEL__PROJECTS = JPA_EOBJECT_FEATURE_COUNT + 0;
-
- /**
- * The number of structural features of the '<em>Jpa Model</em>' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int JPA_MODEL_FEATURE_COUNT = JPA_EOBJECT_FEATURE_COUNT + 1;
-
- /**
- * The meta object id for the '{@link org.eclipse.jpt.core.internal.IJpaProject <em>IJpa Project</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.IJpaProject
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaProject()
- * @generated
- */
- public static final int IJPA_PROJECT = 4;
-
- /**
- * The number of structural features of the '<em>IJpa Project</em>' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int IJPA_PROJECT_FEATURE_COUNT = IJPA_EOBJECT_FEATURE_COUNT + 0;
-
- /**
- * The meta object id for the '{@link org.eclipse.jpt.core.internal.JpaProject <em>Jpa Project</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.JpaProject
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaProject()
- * @generated
- */
- public static final int JPA_PROJECT = 5;
-
- /**
- * The feature id for the '<em><b>Platform</b></em>' reference.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int JPA_PROJECT__PLATFORM = JPA_EOBJECT_FEATURE_COUNT + 0;
-
- /**
- * The feature id for the '<em><b>Data Source</b></em>' containment reference.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int JPA_PROJECT__DATA_SOURCE = JPA_EOBJECT_FEATURE_COUNT + 1;
-
- /**
- * The feature id for the '<em><b>Discover Annotated Classes</b></em>' attribute.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int JPA_PROJECT__DISCOVER_ANNOTATED_CLASSES = JPA_EOBJECT_FEATURE_COUNT + 2;
-
- /**
- * The feature id for the '<em><b>Files</b></em>' containment reference list.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int JPA_PROJECT__FILES = JPA_EOBJECT_FEATURE_COUNT + 3;
-
- /**
- * The number of structural features of the '<em>Jpa Project</em>' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int JPA_PROJECT_FEATURE_COUNT = JPA_EOBJECT_FEATURE_COUNT + 4;
-
- /**
- * The meta object id for the '{@link org.eclipse.jpt.core.internal.IJpaPlatform <em>IJpa Platform</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.IJpaPlatform
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaPlatform()
- * @generated
- */
- public static final int IJPA_PLATFORM = 6;
-
- /**
- * The number of structural features of the '<em>IJpa Platform</em>' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
- */
- public static final int IJPA_PLATFORM_FEATURE_COUNT = 0;
-
- /**
* The meta object id for the '{@link org.eclipse.jpt.core.internal.IJpaDataSource <em>IJpa Data Source</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -258,7 +118,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaDataSource()
* @generated
*/
- public static final int IJPA_DATA_SOURCE = 7;
+ public static final int IJPA_DATA_SOURCE = 2;
/**
* The number of structural features of the '<em>IJpa Data Source</em>' class.
@@ -277,7 +137,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaDataSource()
* @generated
*/
- public static final int JPA_DATA_SOURCE = 8;
+ public static final int JPA_DATA_SOURCE = 3;
/**
* The feature id for the '<em><b>Connection Profile Name</b></em>' attribute.
@@ -305,7 +165,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaFile()
* @generated
*/
- public static final int IJPA_FILE = 9;
+ public static final int IJPA_FILE = 4;
/**
* The number of structural features of the '<em>IJpa File</em>' class.
@@ -324,7 +184,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaFile()
* @generated
*/
- public static final int JPA_FILE = 10;
+ public static final int JPA_FILE = 5;
/**
* The feature id for the '<em><b>Content Id</b></em>' attribute.
@@ -361,7 +221,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaSourceObject()
* @generated
*/
- public static final int IJPA_SOURCE_OBJECT = 11;
+ public static final int IJPA_SOURCE_OBJECT = 6;
/**
* The number of structural features of the '<em>IJpa Source Object</em>' class.
@@ -380,7 +240,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIXmlEObject()
* @generated
*/
- public static final int IXML_EOBJECT = 12;
+ public static final int IXML_EOBJECT = 7;
/**
* The number of structural features of the '<em>IXml EObject</em>' class.
@@ -399,7 +259,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getXmlEObject()
* @generated
*/
- public static final int XML_EOBJECT = 13;
+ public static final int XML_EOBJECT = 8;
/**
* The number of structural features of the '<em>Xml EObject</em>' class.
@@ -418,7 +278,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaContentNode()
* @generated
*/
- public static final int IJPA_CONTENT_NODE = 14;
+ public static final int IJPA_CONTENT_NODE = 9;
/**
* The number of structural features of the '<em>IJpa Content Node</em>' class.
@@ -437,7 +297,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaRootContentNode()
* @generated
*/
- public static final int IJPA_ROOT_CONTENT_NODE = 15;
+ public static final int IJPA_ROOT_CONTENT_NODE = 10;
/**
* The feature id for the '<em><b>Jpa File</b></em>' container reference.
@@ -465,7 +325,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIPersistentType()
* @generated
*/
- public static final int IPERSISTENT_TYPE = 16;
+ public static final int IPERSISTENT_TYPE = 11;
/**
* The feature id for the '<em><b>Mapping Key</b></em>' attribute.
@@ -493,7 +353,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getITypeMapping()
* @generated
*/
- public static final int ITYPE_MAPPING = 17;
+ public static final int ITYPE_MAPPING = 12;
/**
* The feature id for the '<em><b>Name</b></em>' attribute.
@@ -530,7 +390,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getNullTypeMapping()
* @generated
*/
- public static final int NULL_TYPE_MAPPING = 18;
+ public static final int NULL_TYPE_MAPPING = 13;
/**
* The feature id for the '<em><b>Name</b></em>' attribute.
@@ -567,7 +427,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIPersistentAttribute()
* @generated
*/
- public static final int IPERSISTENT_ATTRIBUTE = 19;
+ public static final int IPERSISTENT_ATTRIBUTE = 14;
/**
* The feature id for the '<em><b>Mapping</b></em>' reference.
@@ -595,7 +455,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getIAttributeMapping()
* @generated
*/
- public static final int IATTRIBUTE_MAPPING = 20;
+ public static final int IATTRIBUTE_MAPPING = 15;
/**
* The number of structural features of the '<em>IAttribute Mapping</em>' class.
@@ -614,21 +474,7 @@ public class JpaCorePackage extends EPackageImpl
* @see org.eclipse.jpt.core.internal.JpaCorePackage#getAccessType()
* @generated
*/
- public static final int ACCESS_TYPE = 21;
-
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- private EClass iJpaModelEClass = null;
-
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- private EClass jpaModelEClass = null;
+ public static final int ACCESS_TYPE = 16;
/**
* <!-- begin-user-doc -->
@@ -649,27 +495,6 @@ public class JpaCorePackage extends EPackageImpl
* <!-- end-user-doc -->
* @generated
*/
- private EClass iJpaProjectEClass = null;
-
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- private EClass jpaProjectEClass = null;
-
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- private EClass iJpaPlatformEClass = null;
-
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
private EClass iJpaDataSourceEClass = null;
/**
@@ -852,43 +677,6 @@ public class JpaCorePackage extends EPackageImpl
}
/**
- * Returns the meta object for class '{@link org.eclipse.jpt.core.internal.IJpaModel <em>IJpa Model</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for class '<em>IJpa Model</em>'.
- * @see org.eclipse.jpt.core.internal.IJpaModel
- * @generated
- */
- public EClass getIJpaModel() {
- return iJpaModelEClass;
- }
-
- /**
- * Returns the meta object for class '{@link org.eclipse.jpt.core.internal.JpaModel <em>Jpa Model</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for class '<em>Jpa Model</em>'.
- * @see org.eclipse.jpt.core.internal.JpaModel
- * @generated
- */
- public EClass getJpaModel() {
- return jpaModelEClass;
- }
-
- /**
- * Returns the meta object for the containment reference list '{@link org.eclipse.jpt.core.internal.JpaModel#getProjects <em>Projects</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for the containment reference list '<em>Projects</em>'.
- * @see org.eclipse.jpt.core.internal.JpaModel#getProjects()
- * @see #getJpaModel()
- * @generated
- */
- public EReference getJpaModel_Projects() {
- return (EReference) jpaModelEClass.getEStructuralFeatures().get(0);
- }
-
- /**
* Returns the meta object for class '{@link org.eclipse.jpt.core.internal.IJpaEObject <em>IJpa EObject</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -913,94 +701,6 @@ public class JpaCorePackage extends EPackageImpl
}
/**
- * Returns the meta object for class '{@link org.eclipse.jpt.core.internal.IJpaProject <em>IJpa Project</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for class '<em>IJpa Project</em>'.
- * @see org.eclipse.jpt.core.internal.IJpaProject
- * @generated
- */
- public EClass getIJpaProject() {
- return iJpaProjectEClass;
- }
-
- /**
- * Returns the meta object for class '{@link org.eclipse.jpt.core.internal.JpaProject <em>Jpa Project</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for class '<em>Jpa Project</em>'.
- * @see org.eclipse.jpt.core.internal.JpaProject
- * @generated
- */
- public EClass getJpaProject() {
- return jpaProjectEClass;
- }
-
- /**
- * Returns the meta object for the reference '{@link org.eclipse.jpt.core.internal.JpaProject#getPlatform <em>Platform</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for the reference '<em>Platform</em>'.
- * @see org.eclipse.jpt.core.internal.JpaProject#getPlatform()
- * @see #getJpaProject()
- * @generated
- */
- public EReference getJpaProject_Platform() {
- return (EReference) jpaProjectEClass.getEStructuralFeatures().get(0);
- }
-
- /**
- * Returns the meta object for the containment reference '{@link org.eclipse.jpt.core.internal.JpaProject#getDataSource <em>Data Source</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for the containment reference '<em>Data Source</em>'.
- * @see org.eclipse.jpt.core.internal.JpaProject#getDataSource()
- * @see #getJpaProject()
- * @generated
- */
- public EReference getJpaProject_DataSource() {
- return (EReference) jpaProjectEClass.getEStructuralFeatures().get(1);
- }
-
- /**
- * Returns the meta object for the attribute '{@link org.eclipse.jpt.core.internal.JpaProject#isDiscoverAnnotatedClasses <em>Discover Annotated Classes</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for the attribute '<em>Discover Annotated Classes</em>'.
- * @see org.eclipse.jpt.core.internal.JpaProject#isDiscoverAnnotatedClasses()
- * @see #getJpaProject()
- * @generated
- */
- public EAttribute getJpaProject_DiscoverAnnotatedClasses() {
- return (EAttribute) jpaProjectEClass.getEStructuralFeatures().get(2);
- }
-
- /**
- * Returns the meta object for the containment reference list '{@link org.eclipse.jpt.core.internal.JpaProject#getFiles <em>Files</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for the containment reference list '<em>Files</em>'.
- * @see org.eclipse.jpt.core.internal.JpaProject#getFiles()
- * @see #getJpaProject()
- * @generated
- */
- public EReference getJpaProject_Files() {
- return (EReference) jpaProjectEClass.getEStructuralFeatures().get(3);
- }
-
- /**
- * Returns the meta object for class '{@link org.eclipse.jpt.core.internal.IJpaPlatform <em>IJpa Platform</em>}'.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return the meta object for class '<em>IJpa Platform</em>'.
- * @see org.eclipse.jpt.core.internal.IJpaPlatform
- * @generated
- */
- public EClass getIJpaPlatform() {
- return iJpaPlatformEClass;
- }
-
- /**
* Returns the meta object for class '{@link org.eclipse.jpt.core.internal.IJpaDataSource <em>IJpa Data Source</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -1314,18 +1014,8 @@ public class JpaCorePackage extends EPackageImpl
return;
isCreated = true;
// Create classes and their features
- iJpaModelEClass = createEClass(IJPA_MODEL);
- jpaModelEClass = createEClass(JPA_MODEL);
- createEReference(jpaModelEClass, JPA_MODEL__PROJECTS);
iJpaEObjectEClass = createEClass(IJPA_EOBJECT);
jpaEObjectEClass = createEClass(JPA_EOBJECT);
- iJpaProjectEClass = createEClass(IJPA_PROJECT);
- jpaProjectEClass = createEClass(JPA_PROJECT);
- createEReference(jpaProjectEClass, JPA_PROJECT__PLATFORM);
- createEReference(jpaProjectEClass, JPA_PROJECT__DATA_SOURCE);
- createEAttribute(jpaProjectEClass, JPA_PROJECT__DISCOVER_ANNOTATED_CLASSES);
- createEReference(jpaProjectEClass, JPA_PROJECT__FILES);
- iJpaPlatformEClass = createEClass(IJPA_PLATFORM);
iJpaDataSourceEClass = createEClass(IJPA_DATA_SOURCE);
jpaDataSourceEClass = createEClass(JPA_DATA_SOURCE);
createEAttribute(jpaDataSourceEClass, JPA_DATA_SOURCE__CONNECTION_PROFILE_NAME);
@@ -1382,12 +1072,7 @@ public class JpaCorePackage extends EPackageImpl
// Create type parameters
// Set bounds for type parameters
// Add supertypes to classes
- jpaModelEClass.getESuperTypes().add(this.getJpaEObject());
- jpaModelEClass.getESuperTypes().add(this.getIJpaModel());
jpaEObjectEClass.getESuperTypes().add(this.getIJpaEObject());
- iJpaProjectEClass.getESuperTypes().add(this.getIJpaEObject());
- jpaProjectEClass.getESuperTypes().add(this.getJpaEObject());
- jpaProjectEClass.getESuperTypes().add(this.getIJpaProject());
iJpaDataSourceEClass.getESuperTypes().add(this.getIJpaEObject());
jpaDataSourceEClass.getESuperTypes().add(this.getJpaEObject());
jpaDataSourceEClass.getESuperTypes().add(this.getIJpaDataSource());
@@ -1409,29 +1094,8 @@ public class JpaCorePackage extends EPackageImpl
iPersistentAttributeEClass.getESuperTypes().add(this.getIJpaContentNode());
iAttributeMappingEClass.getESuperTypes().add(this.getIJpaSourceObject());
// Initialize classes and features; add operations and parameters
- initEClass(iJpaModelEClass, IJpaModel.class, "IJpaModel", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
- initEClass(jpaModelEClass, JpaModel.class, "JpaModel", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
- initEReference(getJpaModel_Projects(), this.getIJpaProject(), null, "projects", null, 0, -1, JpaModel.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEClass(iJpaEObjectEClass, IJpaEObject.class, "IJpaEObject", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
- addEOperation(iJpaEObjectEClass, this.getIJpaProject(), "getJpaProject", 0, 1, IS_UNIQUE, IS_ORDERED);
initEClass(jpaEObjectEClass, JpaEObject.class, "JpaEObject", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
- initEClass(iJpaProjectEClass, IJpaProject.class, "IJpaProject", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
- addEOperation(iJpaProjectEClass, this.getIJpaModel(), "getModel", 1, 1, IS_UNIQUE, IS_ORDERED);
- addEOperation(iJpaProjectEClass, this.getIJpaPlatform(), "getPlatform", 1, 1, !IS_UNIQUE, !IS_ORDERED);
- EOperation op = addEOperation(iJpaProjectEClass, null, "setPlatform", 0, 1, IS_UNIQUE, IS_ORDERED);
- addEParameter(op, theEcorePackage.getEString(), "platformId", 1, 1, IS_UNIQUE, !IS_ORDERED);
- addEOperation(iJpaProjectEClass, this.getIJpaDataSource(), "getDataSource", 1, 1, IS_UNIQUE, IS_ORDERED);
- op = addEOperation(iJpaProjectEClass, null, "setDataSource", 1, 1, !IS_UNIQUE, !IS_ORDERED);
- addEParameter(op, theEcorePackage.getEString(), "connectionProfileName", 1, 1, !IS_UNIQUE, !IS_ORDERED);
- addEOperation(iJpaProjectEClass, theEcorePackage.getEBoolean(), "isDiscoverAnnotatedClasses", 1, 1, IS_UNIQUE, IS_ORDERED);
- op = addEOperation(iJpaProjectEClass, null, "setDiscoverAnnotatedClasses", 1, 1, !IS_UNIQUE, !IS_ORDERED);
- addEParameter(op, theEcorePackage.getEBoolean(), "discoverAnnotatedClasses", 1, 1, !IS_UNIQUE, !IS_ORDERED);
- initEClass(jpaProjectEClass, JpaProject.class, "JpaProject", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
- initEReference(getJpaProject_Platform(), this.getIJpaPlatform(), null, "platform", null, 1, 1, JpaProject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, !IS_UNIQUE, !IS_DERIVED, !IS_ORDERED);
- initEReference(getJpaProject_DataSource(), this.getIJpaDataSource(), null, "dataSource", null, 0, 1, JpaProject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, !IS_UNIQUE, !IS_DERIVED, !IS_ORDERED);
- initEAttribute(getJpaProject_DiscoverAnnotatedClasses(), theEcorePackage.getEBoolean(), "discoverAnnotatedClasses", "false", 1, 1, JpaProject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, !IS_ORDERED);
- initEReference(getJpaProject_Files(), this.getIJpaFile(), null, "files", null, 0, -1, JpaProject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
- initEClass(iJpaPlatformEClass, IJpaPlatform.class, "IJpaPlatform", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEClass(iJpaDataSourceEClass, IJpaDataSource.class, "IJpaDataSource", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
addEOperation(iJpaDataSourceEClass, theEcorePackage.getEString(), "getConnectionProfileName", 1, 1, !IS_UNIQUE, !IS_ORDERED);
initEClass(jpaDataSourceEClass, JpaDataSource.class, "JpaDataSource", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
@@ -1476,8 +1140,6 @@ public class JpaCorePackage extends EPackageImpl
// Create resource
createResource(eNS_URI);
}
-
-
/**
* <!-- begin-user-doc -->
* Defines literals for the meta objects that represent
@@ -1493,34 +1155,6 @@ public class JpaCorePackage extends EPackageImpl
public interface Literals
{
/**
- * The meta object literal for the '{@link org.eclipse.jpt.core.internal.IJpaModel <em>IJpa Model</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.IJpaModel
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaModel()
- * @generated
- */
- public static final EClass IJPA_MODEL = eINSTANCE.getIJpaModel();
-
- /**
- * The meta object literal for the '{@link org.eclipse.jpt.core.internal.JpaModel <em>Jpa Model</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.JpaModel
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaModel()
- * @generated
- */
- public static final EClass JPA_MODEL = eINSTANCE.getJpaModel();
-
- /**
- * The meta object literal for the '<em><b>Projects</b></em>' containment reference list feature.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- public static final EReference JPA_MODEL__PROJECTS = eINSTANCE.getJpaModel_Projects();
-
- /**
* The meta object literal for the '{@link org.eclipse.jpt.core.internal.IJpaEObject <em>IJpa EObject</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -1541,68 +1175,6 @@ public class JpaCorePackage extends EPackageImpl
public static final EClass JPA_EOBJECT = eINSTANCE.getJpaEObject();
/**
- * The meta object literal for the '{@link org.eclipse.jpt.core.internal.IJpaProject <em>IJpa Project</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.IJpaProject
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaProject()
- * @generated
- */
- public static final EClass IJPA_PROJECT = eINSTANCE.getIJpaProject();
-
- /**
- * The meta object literal for the '{@link org.eclipse.jpt.core.internal.JpaProject <em>Jpa Project</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.JpaProject
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaProject()
- * @generated
- */
- public static final EClass JPA_PROJECT = eINSTANCE.getJpaProject();
-
- /**
- * The meta object literal for the '<em><b>Platform</b></em>' reference feature.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- public static final EReference JPA_PROJECT__PLATFORM = eINSTANCE.getJpaProject_Platform();
-
- /**
- * The meta object literal for the '<em><b>Data Source</b></em>' containment reference feature.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- public static final EReference JPA_PROJECT__DATA_SOURCE = eINSTANCE.getJpaProject_DataSource();
-
- /**
- * The meta object literal for the '<em><b>Discover Annotated Classes</b></em>' attribute feature.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- public static final EAttribute JPA_PROJECT__DISCOVER_ANNOTATED_CLASSES = eINSTANCE.getJpaProject_DiscoverAnnotatedClasses();
-
- /**
- * The meta object literal for the '<em><b>Files</b></em>' containment reference list feature.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- public static final EReference JPA_PROJECT__FILES = eINSTANCE.getJpaProject_Files();
-
- /**
- * The meta object literal for the '{@link org.eclipse.jpt.core.internal.IJpaPlatform <em>IJpa Platform</em>}' class.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see org.eclipse.jpt.core.internal.IJpaPlatform
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getIJpaPlatform()
- * @generated
- */
- public static final EClass IJPA_PLATFORM = eINSTANCE.getIJpaPlatform();
-
- /**
* The meta object literal for the '{@link org.eclipse.jpt.core.internal.IJpaDataSource <em>IJpa Data Source</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaDataSource.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaDataSource.java
index 0859ee2724..121f2a1dd4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaDataSource.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaDataSource.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2007 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.
+ * 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
@@ -38,6 +38,9 @@ import org.eclipse.jpt.db.internal.Table;
*/
public class JpaDataSource extends JpaEObject implements IJpaDataSource
{
+ // temporary bridge until we remove EMF stuff
+ private IJpaProject jpaProject;
+
/**
* The default value of the '{@link #getConnectionProfileName() <em>Connection Profile Name</em>}' attribute.
* <!-- begin-user-doc -->
@@ -57,73 +60,40 @@ public class JpaDataSource extends JpaEObject implements IJpaDataSource
* @ordered
*/
protected String connectionProfileName = CONNECTION_PROFILE_NAME_EDEFAULT;
+ // cache the connection profile name so we can detect when it changes and fire events
- private transient ConnectionProfile connectionProfile;
+ // this should never be null
+ protected transient ConnectionProfile connectionProfile;
- private ProfileListener profileListener;
+ protected final ProfileListener profileListener;
- private ConnectionListener connectionListener;
+ protected final ConnectionListener connectionListener;
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated NOT
- */
+ // ********** constructor/initialization **********
protected JpaDataSource() {
super();
- profileListener = buildProfileListener();
- ConnectionProfileRepository.instance().addProfileListener(profileListener);
- connectionListener = buildConnectionListener();
+ this.profileListener = this.buildProfileListener();
+ ConnectionProfileRepository.instance().addProfileListener(this.profileListener);
+ this.connectionListener = this.buildConnectionListener();
}
- private ProfileListener buildProfileListener() {
- return new ProfileListener() {
- public void profileAdded(ConnectionProfile profile) {
- if (profile.getName().equals(connectionProfileName)) {
- setConnectionProfile(profile);
- }
- }
-
- public void profileChanged(ConnectionProfile profile) {
- if (profile == connectionProfile && !profile.getName().equals(connectionProfileName)) {
- setConnectionProfileName(profile.getName());
- }
- }
-
- public void profileDeleted(String profileName) {
- if (profileName.equals(connectionProfileName)) {
- setConnectionProfile(null);
- }
- }
- };
+ protected JpaDataSource(IJpaProject jpaProject, String connectionProfileName) {
+ this();
+ this.jpaProject = jpaProject;
+ this.connectionProfileName = connectionProfileName;
+ this.connectionProfile = this.profileNamed(connectionProfileName);
+ this.connectionProfile.addConnectionListener(this.connectionListener);
}
- private ConnectionListener buildConnectionListener() {
- return new ConnectionListener() {
- public void opened(ConnectionProfile profile) {
- getProject().resynch();
- }
-
- public void aboutToClose(ConnectionProfile profile) {}
-
- public boolean okToClose(ConnectionProfile profile) {
- return true;
- }
-
- public void closed(ConnectionProfile profile) {
- getProject().resynch();
- }
-
- public void modified(ConnectionProfile profile) {}
-
- public void databaseChanged(ConnectionProfile profile, Database database) {}
-
- public void schemaChanged(ConnectionProfile profile, Schema schema) {}
+ protected ProfileListener buildProfileListener() {
+ return new LocalProfileListener();
+ }
- public void tableChanged(ConnectionProfile profile, Table table) {}
- };
+ protected ConnectionListener buildConnectionListener() {
+ return new LocalConnectionListener();
}
+ // ********** EMF stuff **********
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -134,10 +104,6 @@ public class JpaDataSource extends JpaEObject implements IJpaDataSource
return JpaCorePackage.Literals.JPA_DATA_SOURCE;
}
- public IJpaProject getProject() {
- return (IJpaProject) eContainer();
- }
-
/**
* Returns the value of the '<em><b>Connection Profile Name</b></em>' attribute.
* <!-- begin-user-doc -->
@@ -171,38 +137,14 @@ public class JpaDataSource extends JpaEObject implements IJpaDataSource
eNotify(new ENotificationImpl(this, Notification.SET, JpaCorePackage.JPA_DATA_SOURCE__CONNECTION_PROFILE_NAME, oldConnectionProfileName, connectionProfileName));
}
- public void setConnectionProfileName(String newConnectionProfileName) {
- ConnectionProfile oldConnectionProfile = connectionProfile;
- setConnectionProfileNameGen(newConnectionProfileName);
- ConnectionProfile newConnectionProfile = ConnectionProfileRepository.instance().profileNamed(newConnectionProfileName);
- if (oldConnectionProfile != newConnectionProfile) {
- setConnectionProfile(newConnectionProfile);
- }
- }
-
- public ConnectionProfile getConnectionProfile() {
- return connectionProfile;
- }
-
- private void setConnectionProfile(ConnectionProfile profile) {
- if (connectionProfile != null) {
- connectionProfile.removeConnectionListener(connectionListener);
- }
- connectionProfile = profile;
- if (connectionProfile != null) {
- connectionProfile.addConnectionListener(connectionListener);
+ /**
+ * set the connection profile when the name changes
+ */
+ public void setConnectionProfileName(String connectionProfileName) {
+ if (!connectionProfileName.equals(this.connectionProfileName)) {
+ this.setConnectionProfileNameGen(connectionProfileName);
+ this.setConnectionProfile(this.profileNamed(connectionProfileName));
}
- getProject().resynch();
- }
-
- public boolean isConnected() {
- ConnectionProfile profile = ConnectionProfileRepository.instance().profileNamed(getConnectionProfileName());
- return profile.isConnected();
- }
-
- public boolean hasAConnection() {
- ConnectionProfile profile = ConnectionProfileRepository.instance().profileNamed(getConnectionProfileName());
- return !profile.isNull();
}
/**
@@ -278,4 +220,110 @@ public class JpaDataSource extends JpaEObject implements IJpaDataSource
result.append(')');
return result.toString();
}
-} \ No newline at end of file
+
+ // ********** non-EMF stuff **********
+ public IJpaProject getProject() {
+ return this.jpaProject;
+ }
+
+ public ConnectionProfile getConnectionProfile() {
+ return this.connectionProfile;
+ }
+
+ private ConnectionProfile profileNamed(String name) {
+ return ConnectionProfileRepository.instance().profileNamed(name);
+ }
+
+ void setConnectionProfile(ConnectionProfile profile) {
+ if (this.connectionProfile != profile) {
+ this.connectionProfile.removeConnectionListener(this.connectionListener);
+ this.connectionProfile = profile;
+ this.connectionProfile.addConnectionListener(this.connectionListener);
+ this.getProject().update();
+ }
+ }
+
+ @Override
+ public boolean isConnected() {
+ return this.connectionProfile.isConnected();
+ }
+
+ public boolean hasAConnection() {
+ return this.connectionProfile.isNull();
+ }
+
+ public void dispose() {
+ this.connectionProfile.removeConnectionListener(this.connectionListener);
+ ConnectionProfileRepository.instance().removeProfileListener(this.profileListener);
+ }
+
+ // ********** member class **********
+
+ /**
+ * Listen for a connection profile with our name being added or removed.
+ * Also listen for our connection's name begin changed.
+ */
+ protected class LocalProfileListener implements ProfileListener {
+
+ protected LocalProfileListener() {
+ super();
+ }
+
+ public void profileChanged(ConnectionProfile profile) {
+ if (profile == JpaDataSource.this.connectionProfile) {
+ JpaDataSource.this.setConnectionProfileName(profile.getName());
+ }
+ }
+
+ public void profileReplaced(ConnectionProfile oldProfile, ConnectionProfile newProfile) {
+ if (oldProfile == JpaDataSource.this.connectionProfile) {
+ JpaDataSource.this.setConnectionProfile(newProfile);
+ }
+ }
+
+ }
+
+ /**
+ * Whenever the connection is opened or closed trigger a project update.
+ */
+ protected class LocalConnectionListener implements ConnectionListener {
+
+ protected LocalConnectionListener() {
+ super();
+ }
+
+ public void opened(ConnectionProfile profile) {
+ JpaDataSource.this.getProject().update();
+ }
+
+ public void aboutToClose(ConnectionProfile profile) {
+ // do nothing
+ }
+
+ public boolean okToClose(ConnectionProfile profile) {
+ return true;
+ }
+
+ public void closed(ConnectionProfile profile) {
+ JpaDataSource.this.getProject().update();
+ }
+
+ public void modified(ConnectionProfile profile) {
+ // do nothing
+ }
+
+ public void databaseChanged(ConnectionProfile profile, Database database) {
+ // do nothing
+ }
+
+ public void schemaChanged(ConnectionProfile profile, Schema schema) {
+ // do nothing
+ }
+
+ public void tableChanged(ConnectionProfile profile, Table table) {
+ // do nothing
+ }
+
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaEObject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaEObject.java
index d7822fec7f..b583525f41 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaEObject.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaEObject.java
@@ -62,11 +62,11 @@ public abstract class JpaEObject extends EObjectImpl implements IJpaEObject
}
public IResource getResource() {
- return this.getJpaProject().getProject();
+ return this.getJpaProject().project();
}
public IJpaPlatform jpaPlatform() {
- return getJpaProject().getPlatform();
+ return getJpaProject().jpaPlatform();
}
public IJpaFactory jpaFactory() {
@@ -103,7 +103,7 @@ public abstract class JpaEObject extends EObjectImpl implements IJpaEObject
IJpaProject project = this.getJpaProject();
// check that the model is fully initialized
if (project != null) {
- project.resynch();
+ project.update();
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaFile.java
index ef56460e30..31a1cc89f1 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaFile.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaFile.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -37,6 +37,9 @@ import org.eclipse.jdt.core.ElementChangedEvent;
*/
public class JpaFile extends JpaEObject implements IJpaFile
{
+ // temporary bridge until we remove EMF stuff
+ private IJpaProject jpaProject;
+
/**
* The default value of the '{@link #getContentId() <em>Content Id</em>}' attribute.
* <!-- begin-user-doc -->
@@ -81,6 +84,20 @@ public class JpaFile extends JpaEObject implements IJpaFile
super();
}
+ public JpaFile(IJpaProject jpaProject, IFile file, IJpaFileContentProvider provider) {
+ this();
+ this.jpaProject = jpaProject;
+ this.setFile(file);
+ this.setContentId(provider.contentType());
+ provider.buildRootContent(this);
+ }
+
+ // temporary bridge until we get rid of EMF stuff
+ @Override
+ public IJpaProject getJpaProject() {
+ return this.jpaProject;
+ }
+
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -185,9 +202,6 @@ public class JpaFile extends JpaEObject implements IJpaFile
eNotify(new ENotificationImpl(this, Notification.SET, JpaCorePackage.JPA_FILE__CONTENT, newContent, newContent));
}
- /**
- * @see IJpaFile#getFile()
- */
public IFile getFile() {
return file;
}
@@ -196,21 +210,12 @@ public class JpaFile extends JpaEObject implements IJpaFile
file = theFile;
}
- /**
- * INTERNAL ONLY
- * Dispose of file before it is removed
- */
- void dispose() {
- getContent().dispose();
- ((JpaProject) getJpaProject()).getFiles().remove(this);
+ public void dispose() {
+ this.content.dispose();
}
- /**
- * INTERNAL ONLY
- * Handle java element change event.
- */
- void handleEvent(ElementChangedEvent event) {
- getContent().handleJavaElementChangedEvent(event);
+ public void javaElementChanged(ElementChangedEvent event) {
+ this.content.javaElementChanged(event);
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModel.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModel.java
index b968016ec0..31de2f0c3e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModel.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModel.java
@@ -1,255 +1,306 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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 java.util.Collection;
+import java.util.ArrayList;
import java.util.Iterator;
+
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceProxy;
-import org.eclipse.core.resources.IResourceProxyVisitor;
-import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.common.notify.NotificationChain;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.util.EObjectContainmentEList;
-import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.jdt.core.ElementChangedEvent;
-import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
-import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator;
+import org.eclipse.jpt.core.internal.IJpaProject.Config;
+import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
/**
- * <!-- begin-user-doc -->
- * A representation of the model object '<em><b>Jpa Model</b></em>'.
- * <!-- end-user-doc -->
- *
- * <p>
- * The following features are supported:
- * <ul>
- * <li>{@link org.eclipse.jpt.core.internal.JpaModel#getProjects <em>Projects</em>}</li>
- * </ul>
- * </p>
- *
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaModel()
- * @model kind="class"
- * @generated
+ * The JPA model is synchronized so all changes to the list of JPA projects
+ * are thread-safe.
+ *
+ * The JPA model holds on to a list of JPA project configs and only instantiates
+ * their associated JPA projects when necessary. Other than performance,
+ * this should be transparent to clients.
*/
-public class JpaModel extends JpaEObject implements IJpaModel
-{
+public class JpaModel extends AbstractModel implements IJpaModel {
+
+ /** maintain a list of all the current JPA projects */
+ private ArrayList<IJpaProjectHolder> jpaProjectHolders = new ArrayList<IJpaProjectHolder>();
+
+
+ // ********** constructor **********
+
/**
- * The cached value of the '{@link #getProjects() <em>Projects</em>}' containment reference list.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see #getProjects()
- * @generated
- * @ordered
+ * Construct a JPA model and populate it with JPA projects to be built
+ * from the specified set of JPA project configs.
+ * The JPA model can only be instantiated by the JPA model manager.
*/
- protected EList<IJpaProject> projects;
+ JpaModel(Iterable<IJpaProject.Config> configs) {
+ super();
+ for (IJpaProject.Config config : configs) {
+ this.addJpaProject(config);
+ }
+ }
+
+
+ // ********** IJpaModel implementation **********
/**
- * Flag to indicate whether the model has been filled with projects
+ * This will trigger the instantiation of the JPA project associated with the
+ * specified Eclipse project.
*/
- private boolean filled = false;
+ public synchronized IJpaProject jpaProject(IProject project) throws CoreException {
+ return this.jpaProjectHolder(project).jpaProject();
+ }
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
+ * We can answer this question without instantiating the
+ * associated JPA project.
*/
- protected JpaModel() {
- super();
+ public synchronized boolean containsJpaProject(IProject project) {
+ return this.jpaProjectHolder(project).holdsJpaProjectFor(project);
}
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
+ * This will trigger the instantiation of all the JPA projects.
*/
- @Override
- protected EClass eStaticClass() {
- return JpaCorePackage.Literals.JPA_MODEL;
+ public synchronized Iterator<IJpaProject> jpaProjects() throws CoreException {
+ // force the CoreException to occur here (instead of later, in Iterator#next())
+ ArrayList<IJpaProject> jpaProjects = new ArrayList<IJpaProject>(this.jpaProjectHolders.size());
+ for (IJpaProjectHolder holder : this.jpaProjectHolders) {
+ jpaProjects.add(holder.jpaProject());
+ }
+ return jpaProjects.iterator();
}
/**
- * Returns the value of the '<em><b>Projects</b></em>' containment reference list.
- * The list contents are of type {@link org.eclipse.jpt.core.internal.IJpaProject}.
- * <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Projects</em>' containment reference list isn't clear,
- * there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- * @return the value of the '<em>Projects</em>' containment reference list.
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaModel_Projects()
- * @model containment="true"
- * @generated
+ * We can answer this question without instantiating any JPA projects.
*/
- public EList<IJpaProject> getProjects() {
- if (projects == null) {
- projects = new EObjectContainmentEList<IJpaProject>(IJpaProject.class, this, JpaCorePackage.JPA_MODEL__PROJECTS);
- }
- return projects;
+ public synchronized int jpaProjectsSize() {
+ return this.jpaProjectHolders.size();
}
+
+ // ********** internal methods **********
+
/**
- * @see IJpaModel#getJpaProject(IProject)
+ * never return null
*/
- public synchronized IJpaProject getJpaProject(IProject project) {
- for (IJpaProject jpaProject : getProjects()) {
- if (jpaProject.getProject().equals(project)) {
- return jpaProject;
+ private IJpaProjectHolder jpaProjectHolder(IProject project) {
+ for (IJpaProjectHolder holder : this.jpaProjectHolders) {
+ if (holder.holdsJpaProjectFor(project)) {
+ return holder;
}
}
- if (!this.filled) {
- try {
- return JpaModelManager.instance().createJpaProject(project);
- }
- catch (CoreException ce) {
- JptCorePlugin.log(ce.getStatus());
- return null;
- }
- }
- return null;
+ return NullJpaProjectHolder.instance();
}
/**
- * @see IJpaModel#jpaProjects()
+ * Add a JPA project to the JPA model for the specified Eclipse project.
+ * JPA projects can only be added by the JPA model manager.
+ * The JPA project will only be instantiated later, on demand.
*/
- public Iterator<IJpaProject> jpaProjects() {
- return new ReadOnlyIterator<IJpaProject>(getProjects().iterator());
- }
-
- @Override
- public IResource getResource() {
- return null;
+ synchronized void addJpaProject(IJpaProject.Config config) {
+ this.jpaProjectHolders.add(this.jpaProjectHolder(config.project()).buildJpaProjectHolder(this, config));
}
/**
- * INTERNAL ONLY
- * Initialize model with workspace resources
+ * Remove the JPA project corresponding to the specified Eclipse project
+ * from the JPA model. Return whether the removal actually happened.
+ * JPA projects can only be removed by the JPA model manager.
*/
- void fill() throws CoreException {
- if (filled)
- return;
- IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
- public boolean visit(IResourceProxy resourceProxy) throws CoreException {
- if (!resourceProxy.isAccessible()) {
- return false;
- }
- switch (resourceProxy.getType()) {
- case IResource.ROOT :
- return true;
- case IResource.PROJECT :
- JpaModelManager.instance().fillJpaProject((IProject) resourceProxy.requestResource());
- default :
- return false;
- }
- }
- };
- ResourcesPlugin.getWorkspace().getRoot().accept(visitor, IResource.NONE);
- filled = true;
+ synchronized boolean removeJpaProject(IProject project) {
+ return this.jpaProjectHolder(project).remove();
}
/**
- * INTERNAL ONLY
- * Dispose of model
+ * Dispose the JPA model by disposing and removing all its JPA projects.
+ * The JPA model can only be disposed by the JPA model manager.
*/
- void dispose() {
- for (Iterator<IJpaProject> stream = new CloneIterator<IJpaProject>(getProjects()); stream.hasNext();) {
- ((JpaProject) stream.next()).dispose();
+ synchronized void dispose() {
+ // clone the list to prevent concurrent modification exceptions
+ @SuppressWarnings("unchecked")
+ ArrayList<IJpaProjectHolder> holders = (ArrayList<IJpaProjectHolder>) this.jpaProjectHolders.clone();
+ for (IJpaProjectHolder holder : holders) {
+ holder.remove();
}
}
+ @Override
+ public void toString(StringBuffer sb) {
+ sb.append("JPA projects size: " + this.jpaProjectsSize());
+ }
+
+
+ // ********** events **********
+
/**
- * INTERNAL ONLY
- * Handle java element change event.
+ * Forward the specified resource delta to the JPA project corresponding
+ * to the specified Eclipse project.
*/
- void handleEvent(ElementChangedEvent event) {
- for (Iterator<IJpaProject> stream = getProjects().iterator(); stream.hasNext();) {
- ((JpaProject) stream.next()).handleEvent(event);
- }
+ synchronized void checkForAddedOrRemovedJpaFiles(IProject project, IResourceDelta delta) throws CoreException {
+ this.jpaProjectHolder(project).checkForAddedOrRemovedJpaFiles(delta);
}
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
+ * Forward the Java element changed event to all the JPA projects
+ * because the event could affect multiple projects.
*/
- @Override
- public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
- switch (featureID) {
- case JpaCorePackage.JPA_MODEL__PROJECTS :
- return ((InternalEList<?>) getProjects()).basicRemove(otherEnd, msgs);
+ synchronized void javaElementChanged(ElementChangedEvent event) {
+ for (IJpaProjectHolder jpaProjectHolder : this.jpaProjectHolders) {
+ jpaProjectHolder.javaElementChanged(event);
}
- return super.eInverseRemove(otherEnd, featureID, msgs);
}
+
+ // ********** holder callbacks **********
+
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
+ * called by the JPA project holder when the JPA project is actually
+ * instantiated
*/
- @Override
- public Object eGet(int featureID, boolean resolve, boolean coreType) {
- switch (featureID) {
- case JpaCorePackage.JPA_MODEL__PROJECTS :
- return getProjects();
- }
- return super.eGet(featureID, resolve, coreType);
+ /* private */ void jpaProjectBuilt(IJpaProject jpaProject) {
+ this.fireItemAdded(JPA_PROJECTS_COLLECTION, jpaProject);
}
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
+ * called by the JPA project holder if the JPA project has been
+ * instantiated and we need to remove it
*/
- @SuppressWarnings("unchecked")
- @Override
- public void eSet(int featureID, Object newValue) {
- switch (featureID) {
- case JpaCorePackage.JPA_MODEL__PROJECTS :
- getProjects().clear();
- getProjects().addAll((Collection<? extends IJpaProject>) newValue);
- return;
- }
- super.eSet(featureID, newValue);
+ /* private */ void jpaProjectRemoved(IJpaProject jpaProject) {
+ this.fireItemRemoved(JPA_PROJECTS_COLLECTION, jpaProject);
}
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
+ * called by the JPA project holder
*/
- @Override
- public void eUnset(int featureID) {
- switch (featureID) {
- case JpaCorePackage.JPA_MODEL__PROJECTS :
- getProjects().clear();
- return;
+ /* private */ void removeJpaProjectHolder(IJpaProjectHolder jpaProjectHolder) {
+ this.jpaProjectHolders.remove(jpaProjectHolder);
+ }
+
+
+ // ********** JPA project holder **********
+
+ private interface IJpaProjectHolder {
+
+ boolean holdsJpaProjectFor(IProject project);
+
+ IJpaProject jpaProject() throws CoreException;
+
+ void checkForAddedOrRemovedJpaFiles(IResourceDelta delta) throws CoreException;
+
+ void javaElementChanged(ElementChangedEvent event);
+
+ IJpaProjectHolder buildJpaProjectHolder(JpaModel jpaModel, IJpaProject.Config config);
+
+ boolean remove();
+
+ }
+
+ private static class NullJpaProjectHolder implements IJpaProjectHolder {
+ private static final IJpaProjectHolder INSTANCE = new NullJpaProjectHolder();
+
+ static IJpaProjectHolder instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private NullJpaProjectHolder() {
+ super();
+ }
+
+ public boolean holdsJpaProjectFor(IProject project) {
+ return false;
+ }
+
+ public IJpaProject jpaProject() throws CoreException {
+ return null;
+ }
+
+ public void checkForAddedOrRemovedJpaFiles(IResourceDelta delta) throws CoreException {
+ // do nothing
+ }
+
+ public void javaElementChanged(ElementChangedEvent event) {
+ // do nothing
+ }
+
+ public IJpaProjectHolder buildJpaProjectHolder(JpaModel jpaModel, Config config) {
+ return new JpaProjectHolder(jpaModel, config);
+ }
+
+ public boolean remove() {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return ClassTools.shortClassNameForObject(this);
}
- super.eUnset(featureID);
}
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
+ * Pair a JPA project config with its lazily-initialized JPA project.
*/
- @Override
- public boolean eIsSet(int featureID) {
- switch (featureID) {
- case JpaCorePackage.JPA_MODEL__PROJECTS :
- return projects != null && !projects.isEmpty();
+ private static class JpaProjectHolder implements IJpaProjectHolder {
+ private final JpaModel jpaModel;
+ private final IJpaProject.Config config;
+ private IJpaProject jpaProject;
+
+ JpaProjectHolder(JpaModel jpaModel, IJpaProject.Config config) {
+ super();
+ this.jpaModel = jpaModel;
+ this.config = config;
+ }
+
+ public boolean holdsJpaProjectFor(IProject project) {
+ return this.config.project().equals(project);
+ }
+
+ public IJpaProject jpaProject() throws CoreException {
+ if (this.jpaProject == null) {
+ this.jpaProject = this.buildJpaProject();
+ // notify listeners of the JPA model
+ this.jpaModel.jpaProjectBuilt(this.jpaProject);
+ }
+ return this.jpaProject;
+ }
+
+ private IJpaProject buildJpaProject() throws CoreException {
+ return this.config.jpaPlatform().getJpaFactory().createJpaProject(this.config);
+ }
+
+ public void checkForAddedOrRemovedJpaFiles(IResourceDelta delta) throws CoreException {
+ if (this.jpaProject != null) {
+ this.jpaProject.checkForAddedOrRemovedJpaFiles(delta);
+ }
+ }
+
+ public void javaElementChanged(ElementChangedEvent event) {
+ if (this.jpaProject != null) {
+ this.jpaProject.javaElementChanged(event);
+ }
+ }
+
+ public IJpaProjectHolder buildJpaProjectHolder(JpaModel jm, Config c) {
+ throw new IllegalArgumentException(c.project().getName());
}
- return super.eIsSet(featureID);
+
+ public boolean remove() {
+ this.jpaModel.removeJpaProjectHolder(this);
+ if (this.jpaProject != null) {
+ this.jpaModel.jpaProjectRemoved(this.jpaProject);
+ this.jpaProject.dispose();
+ }
+ return true;
+ }
+
}
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java
index 9a02709e11..d02fd5ded0 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.core.internal;
+import java.util.ArrayList;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -16,572 +18,731 @@ import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IElementChangedListener;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.core.internal.IJpaProject.Config;
+import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal;
+import org.eclipse.jpt.core.internal.content.orm.OrmFactory;
+import org.eclipse.jpt.core.internal.content.orm.OrmResource;
+import org.eclipse.jpt.core.internal.content.orm.resource.OrmArtifactEdit;
+import org.eclipse.jpt.core.internal.content.persistence.Persistence;
+import org.eclipse.jpt.core.internal.content.persistence.PersistenceFactory;
+import org.eclipse.jpt.core.internal.content.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.internal.content.persistence.resource.PersistenceArtifactEdit;
+import org.eclipse.jpt.core.internal.content.persistence.resource.PersistenceResource;
+import org.eclipse.jpt.core.internal.facet.IJpaFacetDataModelProperties;
import org.eclipse.jpt.core.internal.prefs.JpaPreferenceConstants;
+import org.eclipse.jpt.utility.internal.BitTools;
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
+import org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent;
+
+/**
+ * "Internal" global stuff.
+ * Provide access via a singleton.
+ * Hold and manage the JPA model (which holds all the JPA projects)
+ * and the various global listeners.
+ * All the methods that handle the events from the listeners are 'synchronized',
+ * effectively single-threading them and forcing the events to be queued up
+ * and handled one at a time.
+ */
+public class JpaModelManager {
+
+ /**
+ * The JPA model - null until the plug-in is started.
+ */
+ private JpaModel jpaModel;
-public class JpaModelManager
-{
- final JpaModel model;
-
+ /**
+ * Listen for changes to projects or files.
+ */
private final IResourceChangeListener resourceChangeListener;
-
+
+ /**
+ * Listen for the JPA facet being added or removed from a project.
+ */
private final IFacetedProjectListener facetedProjectListener;
-
- private final IElementChangedListener elementChangeListener;
-
+
+ /**
+ * Listen for Java changes and forward them to the JPA model,
+ * which will forward them to the JPA projects.
+ */
+ private final IElementChangedListener javaElementChangeListener;
+
+ /**
+ * Listen for changes to the "Default JPA Lib" preference
+ * so we can update the corresponding classpath variable.
+ */
private final IPropertyChangeListener preferencesListener;
-
- private static JpaModelManager INSTANCE;
-
+
+ // ********** singleton **********
+
+ private static JpaModelManager INSTANCE; // lazily-final
+
/**
- * Returns the singleton JpaModelManager
+ * Return the singleton JPA model manager.
*/
- public final static JpaModelManager instance() {
+ public static final synchronized JpaModelManager instance() {
if (INSTANCE == null) {
INSTANCE = new JpaModelManager();
}
return INSTANCE;
}
-
-
+
+
+ // ********** constructor **********
+
+ /**
+ * Private - ensure single instance.
+ */
private JpaModelManager() {
super();
- model = JpaCoreFactory.eINSTANCE.createJpaModel();
- resourceChangeListener = new ResourceChangeListener();
- facetedProjectListener = new FacetedProjectListener();
- elementChangeListener = new ElementChangeListener();
- preferencesListener = new PreferencesListener();
- }
-
- void start() {
+ this.resourceChangeListener = new ResourceChangeListener();
+ this.facetedProjectListener = new FacetedProjectListener();
+ this.javaElementChangeListener = new JavaElementChangeListener();
+ this.preferencesListener = new PreferencesListener();
+ }
+
+
+ // ********** life-cycle controlled by the plug-in **********
+
+ /**
+ * internal - called by JptCorePlugin
+ */
+ public synchronized void start() throws Exception {
try {
- this.buildWorkspace();
- ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener);
- FacetedProjectFramework.addListener(facetedProjectListener, IFacetedProjectEvent.Type.values());
- JavaCore.addElementChangedListener(elementChangeListener);
- JptCorePlugin.getPlugin().getPluginPreferences().addPropertyChangeListener(preferencesListener);
- }
- catch (RuntimeException ex) {
- JptCorePlugin.log(ex);
+ this.jpaModel = this.buildJpaModel();
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this.resourceChangeListener);
+ FacetedProjectFramework.addListener(this.facetedProjectListener, IFacetedProjectEvent.Type.values());
+ JavaCore.addElementChangedListener(this.javaElementChangeListener);
+ JptCorePlugin.instance().getPluginPreferences().addPropertyChangeListener(this.preferencesListener);
+ } catch (RuntimeException ex) {
+ this.log(ex);
this.stop();
}
}
-
- void stop() {
- JptCorePlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(preferencesListener);
- JavaCore.removeElementChangedListener(elementChangeListener);
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
- model.dispose();
- }
-
- private void buildWorkspace() {
- Job workspaceBuildJob = new WorkspaceBuildJob();
- workspaceBuildJob.schedule(5000L); //temporary delay for bundle init problem
+
+ private JpaModel buildJpaModel() throws CoreException {
+ ResourceProxyVisitor visitor = new ResourceProxyVisitor(this.buildJpaProjectConfigBuilder());
+ ResourcesPlugin.getWorkspace().getRoot().accept(visitor, IResource.NONE);
+ return new JpaModel(visitor.jpaProjectConfigs());
}
-
+
/**
- * Return the workspace-wide IJpaModel
- *
- * This IJpaProject may not be fully filled (it may not have all the correct
- * projects added) if retrieved soon after it is created (e.g. workspace opening,
- * project opening, facet installation ...) To ensure it is fully filled in
- * those cases, you may instead use getFilledJpaModel().
- * @see getFilledJpaModel()
+ * internal - called by JptCorePlugin
*/
- public IJpaModel getJpaModel() {
- return model;
+ public synchronized void stop() throws Exception {
+ JptCorePlugin.instance().getPluginPreferences().removePropertyChangeListener(this.preferencesListener);
+ JavaCore.removeElementChangedListener(this.javaElementChangeListener);
+ FacetedProjectFramework.removeListener(this.facetedProjectListener);
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this.resourceChangeListener);
+ this.jpaModel.dispose();
+ this.jpaModel = null;
}
-
+
+
+ // ********** API **********
+
/**
- * Return the workspace-wide IJpaModel
- *
- * This IJpaModel will be fully filled (it will have all the correct projects added).
- * @see getJpaProject(IProject)
+ * Return the workspace-wide JPA model.
*/
- public IJpaModel getFilledJpaModel()
- throws CoreException {
- model.fill();
- return model;
+ public IJpaModel jpaModel() {
+ return this.jpaModel;
}
-
+
/**
- * Returns the IJpaProject corresponding to the given IProject.
- * Returns <code>null</code> if unable to associate the given project
- * with an IJpaProject.
- *
- * This IJpaProject may not be fully filled (it may not have all the correct
- * files added) if retrieved soon after it is created (e.g. workspace opening,
- * project opening, facet installation ...) To ensure it is fully filled in
- * those cases, you may instead use getFilledJpaProject(IProject).
- * @see getFilledJpaProject(IProject)
- */
- public synchronized IJpaProject getJpaProject(IProject project) {
- if (project == null) {
- return null;
- }
-
- return this.model.getJpaProject(project);
+ * Return the JPA project corresponding to the specified Eclipse project,
+ * or null if unable to associate the specified project with a
+ * JPA project.
+ */
+ public IJpaProject jpaProject(IProject project) throws CoreException {
+ return this.jpaModel().jpaProject(project);
}
-
+
/**
- * Returns the IJpaProject corresponding to the given IProject.
- * Returns <code>null</code> if unable to associate the given project
- * with an IJpaProject.
- *
- * This IJpaProject will be fully filled (it will have all the correct files added).
- * @see getJpaProject(IProject)
+ * Return the JPA file corresponding to the specified Eclipse file,
+ * or null if unable to associate the specified file with a JPA file.
*/
- public synchronized IJpaProject getFilledJpaProject(IProject project)
- throws CoreException {
- JpaProject jpaProject = (JpaProject) getJpaProject(project);
-
- if (jpaProject != null) {
- jpaProject.fill();
- }
-
- return jpaProject;
+ public IJpaFile jpaFile(IFile file) throws CoreException {
+ IJpaProject jpaProject = this.jpaProject(file.getProject());
+ return (jpaProject == null) ? null : jpaProject.jpaFile(file);
}
-
+
/**
- * Determine whether project should be created, then create it if necessary
+ * The JPA settings associated with the specified Eclipse project
+ * have changed in such a way as to require the associated
+ * JPA project to be completely rebuilt.
*/
- private synchronized void processProject(IProject project) {
- JpaProject jpaProject = (JpaProject) model.getJpaProject(project);
- boolean jpaFacetExists = false;
- try {
- jpaFacetExists = FacetedProjectFramework.hasProjectFacet(project, JptCorePlugin.FACET_ID);
+ public void rebuildJpaProject(IProject project) {
+ this.removeJpaProject(project);
+ this.addJpaProject(project);
+ }
+
+ /**
+ * Log the specified status.
+ */
+ public void log(IStatus status) {
+ JptCorePlugin.log(status);
+ }
+
+ /**
+ * Log the specified message.
+ */
+ public void log(String msg) {
+ JptCorePlugin.log(msg);
+ }
+
+ /**
+ * Log the specified exception or error.
+ */
+ public void log(Throwable throwable) {
+ JptCorePlugin.log(throwable);
+ }
+
+
+ // ********** JPA project configs **********
+
+ private ResourceProxyVisitor.JpaProjectConfigBuilder buildJpaProjectConfigBuilder() {
+ return new ResourceProxyVisitor.JpaProjectConfigBuilder() {
+ public Iterable<Config> buildJpaProjectConfigs(Iterable<IProject> jpaFacetedProjects) {
+ return JpaModelManager.this.buildJpaProjectConfigs(jpaFacetedProjects);
+ }
+ };
+ }
+
+ Iterable<IJpaProject.Config> buildJpaProjectConfigs(Iterable<IProject> jpaFacetedProjects) {
+ ArrayList<IJpaProject.Config> configs = new ArrayList<IJpaProject.Config>();
+ for (IProject project : jpaFacetedProjects) {
+ configs.add(buildJpaProjectConfig(project));
}
- catch (CoreException ce) {
- // nothing to do, assume facet doesn't exist
- JptCorePlugin.log(ce);
+ return configs;
+ }
+
+ private IJpaProject.Config buildJpaProjectConfig(IProject project) {
+ SimpleJpaProjectConfig config = new SimpleJpaProjectConfig();
+ config.setProject(project);
+ config.setJpaPlatform(JptCorePlugin.jpaPlatform(project));
+ config.setConnectionProfileName(JptCorePlugin.connectionProfileName(project));
+ config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project));
+ return config;
+ }
+
+
+ // ********** resource proxy visitor **********
+
+ /**
+ * Visit the workspace resource tree, looking for open Eclipse projects
+ * with a JPA facet.
+ */
+ private static class ResourceProxyVisitor implements IResourceProxyVisitor {
+ private final JpaProjectConfigBuilder builder;
+ private final ArrayList<IProject> jpaFacetedProjects = new ArrayList<IProject>();
+
+ ResourceProxyVisitor(JpaProjectConfigBuilder builder) {
+ super();
+ this.builder = builder;
}
-
- if (jpaProject == null && jpaFacetExists) {
- try {
- JpaModelManager.instance().createFilledJpaProject(project);
+
+ public boolean visit(IResourceProxy resourceProxy) throws CoreException {
+ switch (resourceProxy.getType()) {
+ case IResource.ROOT :
+ return true; // all projects are in the "root"
+ case IResource.PROJECT :
+ this.checkProject(resourceProxy);
+ return false; // no nested projects
+ default :
+ return false;
}
- catch (CoreException ce) {
- JptCorePlugin.log(ce);
+ }
+
+ private void checkProject(IResourceProxy resourceProxy) {
+ if (resourceProxy.isAccessible()) { // the project exists and is open
+ IProject project = (IProject) resourceProxy.requestResource();
+ if (JptCorePlugin.projectHasJpaFacet(project)) {
+ this.jpaFacetedProjects.add(project);
+ }
}
}
- else if (jpaProject != null && ! jpaFacetExists) {
- jpaProject.dispose();
+
+ Iterable<IJpaProject.Config> jpaProjectConfigs() {
+ return this.builder.buildJpaProjectConfigs(this.jpaFacetedProjects);
+ }
+
+ interface JpaProjectConfigBuilder {
+ Iterable<IJpaProject.Config> buildJpaProjectConfigs(Iterable<IProject> jpaFacetedProjects);
}
+
+ }
+
+
+ // ********** internal **********
+
+ private void addJpaProject(IProject project) {
+ this.jpaModel.addJpaProject(this.buildJpaProjectConfig(project));
}
-
+
/**
- * INTERNAL ONLY
- *
- * Fills the IJpaProject associated with the IProject, if it exists
+ * Remove the JPA project corresponding to the specified Eclipse project.
+ * Do nothing if there is no corresponding JPA project.
*/
- public synchronized void fillJpaProject(IProject project)
- throws CoreException {
- JpaProject jpaProject = (JpaProject) getJpaProject(project);
-
- if (jpaProject != null) {
- jpaProject.fill();
+ private synchronized void removeJpaProject(IProject project) {
+ if (this.jpaModel.removeJpaProject(project)) {
+ try {
+ // TODO remove classpath items?
+ // TODO remove persistence.xml?
+ // TODO copy to dispose()? where were the markers added in the first place???
+ ResourcesPlugin.getWorkspace().deleteMarkers(project.findMarkers(JptCorePlugin.VALIDATION_MARKER_ID, true, IResource.DEPTH_INFINITE));
+ } catch (CoreException ex) {
+ this.log(ex); // not much we can do
+ }
}
}
-
+
+
+ // ********** resource changed **********
+
/**
- * INTERNAL ONLY
- * Create an IJpaProject without files filled in
+ * Check for project deletion/closing and file changes.
*/
- public synchronized IJpaProject createJpaProject(IProject project)
- throws CoreException {
- if (FacetedProjectFramework.hasProjectFacet(project, JptCorePlugin.FACET_ID)) {
- JpaProject jpaProject = JpaCoreFactory.eINSTANCE.createJpaProject(project);
- model.getProjects().add(jpaProject);
- return jpaProject;
+ synchronized void resourceChanged(IResourceChangeEvent event) {
+ if (! (event.getSource() instanceof IWorkspace)) {
+ return; // this probably shouldn't happen...
+ }
+ switch (event.getType()){
+ case IResourceChangeEvent.PRE_DELETE :
+ case IResourceChangeEvent.PRE_CLOSE :
+ this.projectPreDeleteOrClose(event);
+ break;
+ case IResourceChangeEvent.POST_CHANGE :
+ this.resourcePostChange(event);
+ break;
+ default :
+ break;
}
- return null;
}
-
+
/**
- * INTERNAL ONLY
- * Create an IJpaProject with files filled in
+ * A project is being deleted or closed. Remove its corresponding
+ * JPA project if appropriate.
*/
- public synchronized IJpaProject createFilledJpaProject(IProject project)
- throws CoreException {
- JpaProject jpaProject = (JpaProject) createJpaProject(project);
-
- if (jpaProject != null) {
- jpaProject.fill();
+ private void projectPreDeleteOrClose(IResourceChangeEvent event) {
+ IResource resource = event.getResource();
+ if (resource.getType() != IResource.PROJECT) {
+ return; // this probably shouldn't happen...
+ }
+ IProject project = (IProject) resource;
+ if (JptCorePlugin.projectHasJpaFacet(project)) {
+ this.removeJpaProject(project);
}
-
- return jpaProject;
}
-
+
/**
- * INTERNAL ONLY
- * Dispose the IJpaProject
+ * A resource has changed somehow.
*/
- public void disposeJpaProject(IJpaProject jpaProject) {
- ((JpaProject) jpaProject).dispose();
+ private void resourcePostChange(IResourceChangeEvent event) {
+ IResourceDelta delta = event.getDelta();
+ // TODO 3 passes through the delta might be a bit much... but it keeps our code simpler...
+ if (this.deltaIsRelevant(delta)) { // ignore SYNC and MARKER deltas
+ this.checkForAddedOrOpenedProjects(delta);
+ this.checkForAddedOrRemovedFiles(delta);
+ }
}
-
+
/**
- * Returns the IJpaFile corresponding to the given IFile.
- * Returns <code>null</code> if unable to associate the given file
- * with an IJpaFile.
+ * Return whether the specified change delta contains anything relevant to
+ * the JPA model.
*/
- public synchronized IJpaFile getJpaFile(IFile file) {
- if (file == null) {
- return null;
+ private boolean deltaIsRelevant(IResourceDelta rootDelta) {
+ if (rootDelta == null) {
+ return false;
}
-
- IProject project = file.getProject();
- JpaProject jpaProject = (JpaProject) this.getJpaProject(project);
- if (jpaProject == null) {
- return null;
+ try {
+ rootDelta.accept(RESOURCE_DELTA_VISITOR);
+ } catch (RelevantDeltaFoundException ex) {
+ return true; // the visitor found a relevant delta and threw an exception
+ } catch (CoreException ex) {
+ this.log(ex); // ignore delta if problems traversing - fall through and return false
}
-
- return jpaProject.getJpaFile(file);
- }
-
-
-
- private class WorkspaceBuildJob extends Job
- {
- WorkspaceBuildJob() {
- // TODO - Internationalize (? It *is* a system job ...)
- super("Initializing JPA Model ...");
- setSystem(true);
- setPriority(SHORT);
+ return false;
+ }
+
+ /**
+ * Process the given delta and look for projects being added, opened, or closed.
+ * Note that projects being deleted are checked in deletingProject(IProject).
+ */
+ private void checkForAddedOrOpenedProjects(IResourceDelta delta) {
+ IResource resource = delta.getResource();
+ switch (resource.getType()) {
+ case IResource.ROOT :
+ this.checkForAddedOrOpenedProjects(delta.getAffectedChildren()); // recurse
+ break;
+ case IResource.PROJECT :
+ this.checkForAddedOrOpenedProject((IProject) resource, delta);
+ break;
+ case IResource.FILE :
+ case IResource.FOLDER :
+ default :
+ break;
}
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- final IWorkspace workspace = ResourcesPlugin.getWorkspace();
-
- try {
- workspace.run(
- new IWorkspaceRunnable() {
- public void run(IProgressMonitor progress) throws CoreException {
- model.fill();
- }
- },
- monitor);
- }
- catch (CoreException ce) {
- return ce.getStatus();
- }
- return Status.OK_STATUS;
+ }
+
+ private void checkForAddedOrOpenedProjects(IResourceDelta[] deltas) {
+ for (int i = 0; i < deltas.length; i++) {
+ this.checkForAddedOrOpenedProjects(deltas[i]); // recurse
}
-
}
-
-
- private static class ResourceChangeListener
- implements IResourceChangeListener
- {
- ThreadLocal<ResourceChangeProcessor> resourceChangeProcessors = new ThreadLocal<ResourceChangeProcessor>();
-
- ResourceChangeListener() {
- super();
+
+ private void checkForAddedOrOpenedProject(IProject project, IResourceDelta delta) {
+ if (JptCorePlugin.projectHasJpaFacet(project)) {
+ this.checkForAddedOrOpenedJpaFacetedProject(project, delta);
}
-
- public void resourceChanged(IResourceChangeEvent event) {
- getResourceChangeProcessor().resourceChanged(event);
+ }
+
+ private void checkForAddedOrOpenedJpaFacetedProject(IProject project, IResourceDelta delta) {
+ switch (delta.getKind()) {
+ case IResourceDelta.REMOVED :
+ break; // already handled with the PRE_DELETE event
+ case IResourceDelta.ADDED : // adding and opening a project are treated alike
+ case IResourceDelta.CHANGED :
+ if (BitTools.flagIsSet(delta.getFlags(), IResourceDelta.OPEN) && project.isOpen()) {
+ this.addJpaProject(project);
+ }
+ break;
+ case IResourceDelta.ADDED_PHANTOM :
+ case IResourceDelta.REMOVED_PHANTOM :
+ default :
+ break;
}
-
- public ResourceChangeProcessor getResourceChangeProcessor() {
- ResourceChangeProcessor processor = this.resourceChangeProcessors.get();
- if (processor == null) {
- processor = new ResourceChangeProcessor();
- this.resourceChangeProcessors.set(processor);
- }
- return processor;
+ }
+
+ /**
+ * Check for files being added or removed.
+ * (The JPA project only handles added and removed files here, ignoring
+ * changed files.)
+ */
+ private void checkForAddedOrRemovedFiles(IResourceDelta delta) {
+ IResource resource = delta.getResource();
+ switch (resource.getType()) {
+ case IResource.ROOT :
+ this.checkForAddedOrRemovedFiles(delta.getAffectedChildren()); // recurse
+ break;
+ case IResource.PROJECT :
+ this.checkForAddedOrRemovedFiles((IProject) resource, delta);
+ break;
+ case IResource.FILE :
+ case IResource.FOLDER :
+ default :
+ break;
}
}
-
-
- private static class ResourceChangeProcessor
- {
- private JpaModel model;
-
- ResourceChangeProcessor() {
- model = JpaModelManager.instance().model;
+
+ private void checkForAddedOrRemovedFiles(IResourceDelta[] deltas) {
+ for (int i = 0; i < deltas.length; i++) {
+ this.checkForAddedOrRemovedFiles(deltas[i]); // recurse
}
-
- public void resourceChanged(IResourceChangeEvent event) {
- if (event.getSource() instanceof IWorkspace) {
- IResource resource = event.getResource();
- IResourceDelta delta = event.getDelta();
-
- switch (event.getType()){
- case IResourceChangeEvent.PRE_DELETE :
- case IResourceChangeEvent.PRE_CLOSE :
- try {
- if ((resource.getType() == IResource.PROJECT)
- && (FacetedProjectFramework.hasProjectFacet(
- (IProject) resource, JptCorePlugin.FACET_ID))) {
- projectBeingDeleted((IProject) resource);
- }
- }
- catch (CoreException e) {
- // project doesn't exist or is not open: ignore
- }
- return;
-
- case IResourceChangeEvent.POST_CHANGE :
- if (isApplicable(delta)) { // avoid changing due to SYNC or MARKER deltas
- checkForProjectsBeingAddedOrRemoved(delta);
- checkForFilesBeingAddedOrRemoved(delta);
- }
- return;
- }
- }
+ }
+
+ private void checkForAddedOrRemovedFiles(IProject project, IResourceDelta delta) {
+ if (JptCorePlugin.projectHasJpaFacet(project)) {
+ this.checkForAddedOrRemovedJpaFiles(project, delta);
}
-
- /**
- * Process the given delta and look for files being added, removed, or changed
- */
- private void checkForFilesBeingAddedOrRemoved(IResourceDelta delta) {
- IResource resource = delta.getResource();
- boolean processChildren = false;
-
- switch (resource.getType()) {
- case IResource.ROOT :
- processChildren = true;
- break;
-
- case IResource.PROJECT :
- IProject project = (IProject) resource;
-
- try {
- if (FacetedProjectFramework.hasProjectFacet(project, JptCorePlugin.FACET_ID)) {
- JpaProject jpaProject = (JpaProject) model.getJpaProject(project);
- if (jpaProject != null) {
- // sometimes we receive events before the project
- // has been fully initialized
- jpaProject.synchInternalResources(delta);
- }
- }
- }
- catch (CoreException ex) {
- // we can't do anything anyway
- }
- break;
- }
- if (processChildren) {
- IResourceDelta[] children = delta.getAffectedChildren();
- for (int i = 0; i < children.length; i++) {
- checkForFilesBeingAddedOrRemoved(children[i]);
- }
- }
-
+ }
+
+ /**
+ * Checked exceptions bite.
+ */
+ private void checkForAddedOrRemovedJpaFiles(IProject project, IResourceDelta delta) {
+ try {
+ this.jpaModel.checkForAddedOrRemovedJpaFiles(project, delta);
+ } catch (CoreException ex) {
+ this.log(ex); // problem traversing the project's resources - not much we can do
}
-
- /**
- * Process the given delta and look for projects being added, opened, or closed.
- * Note that projects being deleted are checked in deletingProject(IProject).
- */
- private void checkForProjectsBeingAddedOrRemoved(IResourceDelta delta) {
- IResource resource = delta.getResource();
- boolean processChildren = false;
-
- switch (resource.getType()) {
- case IResource.ROOT :
- processChildren = true;
- break;
-
- case IResource.PROJECT :
- // NB: No need to check project's facet as if the project is not a jpa project:
- // - if the project is added or changed this is a noop for projectsBeingDeleted
- // - if the project is closed, it has already lost its jpa facet
- IProject project = (IProject) resource;
-
- switch (delta.getKind()) {
- case IResourceDelta.REMOVED :
- // we should have already handled this in the PRE_DELETE event
- break;
-
- case IResourceDelta.ADDED :
- // if project is renamed (for instance, we should act as though it's been opened)
- // fall through
-
- case IResourceDelta.CHANGED :
- if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
- if (project.isOpen()) {
- JpaModelManager.instance().processProject(project);
- }
- }
- break;
+ }
+
+
+ // ********** resource delta visitor **********
+
+ /**
+ * The visitor is stateless, so we only need one.
+ */
+ private static final IResourceDeltaVisitor RESOURCE_DELTA_VISITOR = new ResourceDeltaVisitor();
+
+ /**
+ * Traverse the resource delta tree and throw a special exception if any
+ * relevant nodes are encountered.
+ */
+ private static class ResourceDeltaVisitor implements IResourceDeltaVisitor {
+ // the exception is only used to short-circuit the traversal, so we only need one
+ private static final RelevantDeltaFoundException EX = new RelevantDeltaFoundException();
+
+ ResourceDeltaVisitor() {
+ super();
+ }
+
+ public boolean visit(IResourceDelta delta) {
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED :
+ case IResourceDelta.REMOVED :
+ throw EX;
+ case IResourceDelta.CHANGED :
+ if (this.changedDeltaIsRelevant(delta)) {
+ throw EX;
}
break;
+ case IResourceDelta.ADDED_PHANTOM :
+ case IResourceDelta.REMOVED_PHANTOM :
+ default :
+ break;
}
- if (processChildren) {
- IResourceDelta[] children = delta.getAffectedChildren();
- for (int i = 0; i < children.length; i++) {
- checkForProjectsBeingAddedOrRemoved(children[i]);
- }
- }
+ return true; // continue visit to any children
}
-
+
/**
- * The platform project is being deleted. Remove jpa info.
+ * The specified "changed" delta is relevant if it is a leaf node
+ * (i.e. it has no children) and any flag, other than the SYNC or
+ * MARKERS flags, is set.
*/
- private void projectBeingDeleted(IProject project) {
- // could be problems here ...
- JpaProject jpaProject = (JpaProject) model.getJpaProject(project);
- jpaProject.dispose();
+ private boolean changedDeltaIsRelevant(IResourceDelta delta) {
+ return (delta.getAffectedChildren().length == 0)
+ && BitTools.anyFlagsAreSet(delta.getFlags(), RELEVANT_FLAGS);
}
-
- /**
- * Returns whether a given delta contains some information relevant to
- * the JPA model,
- * in particular it will not consider SYNC or MARKER only deltas.
- */
- private boolean isApplicable(IResourceDelta rootDelta) {
- if (rootDelta != null) {
- // use local exception to quickly escape from delta traversal
- class FoundRelevantDeltaException extends RuntimeException {
- private static final long serialVersionUID = 7137113252936111022L; // backward compatible
- // only the class name is used (to differentiate from other RuntimeExceptions)
- }
- try {
- rootDelta.accept(
- new IResourceDeltaVisitor() {
- public boolean visit(IResourceDelta delta) {
- switch (delta.getKind()) {
- case IResourceDelta.ADDED :
- case IResourceDelta.REMOVED :
- throw new FoundRelevantDeltaException();
- case IResourceDelta.CHANGED :
- // if any flag is set but SYNC or MARKER, this delta should be considered
- if (delta.getAffectedChildren().length == 0 // only check leaf delta nodes
- && (delta.getFlags() & ~(IResourceDelta.SYNC | IResourceDelta.MARKERS)) != 0) {
- throw new FoundRelevantDeltaException();
- }
- }
- return true;
- }
- }
- );
- }
- catch(FoundRelevantDeltaException e) {
- return true;
- }
- catch(CoreException e) { // ignore delta if not able to traverse
- }
- }
- return false;
+
+ private static final int IRRELEVANT_FLAGS = IResourceDelta.SYNC | IResourceDelta.MARKERS;
+ private static final int RELEVANT_FLAGS = ~IRRELEVANT_FLAGS;
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
}
}
-
-
- // **************** faceted project listener ******************************
-
- private static class FacetedProjectListener
- implements IFacetedProjectListener
- {
- ThreadLocal<FacetedProjectChangeProcessor> processors =
- new ThreadLocal<FacetedProjectChangeProcessor>();
-
- FacetedProjectListener() {
+
+ /**
+ * Internal exception to quickly escape from a delta traversal.
+ */
+ private static class RelevantDeltaFoundException extends RuntimeException {
+ RelevantDeltaFoundException() {
super();
}
-
- public void handleEvent(IFacetedProjectEvent event) {
- getProcessor().handleEvent(event);
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
}
-
- public FacetedProjectChangeProcessor getProcessor() {
- FacetedProjectChangeProcessor processor = processors.get();
- if (processor == null) {
- processor = new FacetedProjectChangeProcessor();
- processors.set(processor);
- }
- return processor;
+ }
+
+
+ // ********** faceted project changed **********
+
+ synchronized void facetedProjectChanged(IFacetedProjectEvent event) {
+ if (event.getType() == IFacetedProjectEvent.Type.POST_INSTALL) {
+ this.postInstall((IProjectFacetActionEvent) event);
+ } else if (event.getType() == IFacetedProjectEvent.Type.PRE_UNINSTALL) {
+ this.preUninstall((IProjectFacetActionEvent) event);
+ } else {
+ this.checkJpaFacet(event.getProject().getProject());
}
}
-
-
- private static class FacetedProjectChangeProcessor
- {
- private JpaModel model;
-
- FacetedProjectChangeProcessor() {
- model = JpaModelManager.instance().model;
+
+ private void postInstall(IProjectFacetActionEvent event) {
+ if (JptCorePlugin.projectHasJpaFacet(event.getProject().getProject())) {
+ this.postInstallJpaFacetedProject(event);
}
-
- protected void handleEvent(IFacetedProjectEvent event) {
- JpaModelManager.instance().processProject(event.getProject().getProject());
+ }
+
+ private void postInstallJpaFacetedProject(IProjectFacetActionEvent event) {
+ IProject project = event.getProject().getProject();
+ IDataModel dataModel = (IDataModel) event.getActionConfig();
+
+ this.createPersistenceXml(project);
+
+ if (dataModel.getBooleanProperty(IJpaFacetDataModelProperties.CREATE_ORM_XML)) {
+ this.createOrmXml(project);
}
+
+ this.addJpaProject(project);
}
-
-
- // **************** element change listener *******************************
- private static class ElementChangeListener
- implements IElementChangedListener
- {
- ThreadLocal<ElementChangeProcessor> elementChangeProcessor = new ThreadLocal<ElementChangeProcessor>();
-
- ElementChangeListener() {
- super();
+ private void preUninstall(IProjectFacetActionEvent event) {
+ if (JptCorePlugin.projectHasJpaFacet(event.getProject().getProject())) {
+ this.preUninstallJpaFacetedProject(event);
+ }
+ }
+
+ private void preUninstallJpaFacetedProject(IProjectFacetActionEvent event) {
+ this.removeJpaProject(event.getProject().getProject());
+ }
+
+ private void createPersistenceXml(IProject project) {
+ PersistenceArtifactEdit pae =
+ PersistenceArtifactEdit.getArtifactEditForWrite(project, JptCorePlugin.persistenceXmlDeploymentURI(project));
+ PersistenceResource resource = pae.getPersistenceResource();
+
+ // 202811 - do not add content if it is already present
+ if (resource.getPersistence() == null) {
+ Persistence persistence = PersistenceFactory.eINSTANCE.createPersistence();
+ persistence.setVersion("1.0");
+ PersistenceUnit pUnit = PersistenceFactory.eINSTANCE.createPersistenceUnit();
+ pUnit.setName(project.getName());
+ persistence.getPersistenceUnits().add(pUnit);
+ resource.getContents().add(persistence);
+ pae.save(null);
}
- public void elementChanged(ElementChangedEvent event) {
- this.getElementChangeProcessor().elementChanged(event);
+ pae.dispose();
+ }
+
+ private void createOrmXml(IProject project) {
+ OrmArtifactEdit oae =
+ OrmArtifactEdit.getArtifactEditForWrite(project, JptCorePlugin.ormXmlDeploymentURI(project));
+ OrmResource resource = oae.getOrmResource();
+
+ // 202811 - do not add content if it is already present
+ if (resource.getEntityMappings() == null) {
+ EntityMappingsInternal entityMappings = OrmFactory.eINSTANCE.createEntityMappingsInternal();
+ entityMappings.setVersion("1.0");
+ resource.getContents().add(entityMappings);
+ oae.save(null);
}
- public ElementChangeProcessor getElementChangeProcessor() {
- ElementChangeProcessor processor = this.elementChangeProcessor.get();
- if (processor == null) {
- processor = new ElementChangeProcessor();
- this.elementChangeProcessor.set(processor);
+ oae.dispose();
+ }
+
+ /**
+ * Add a JPA project if the Eclipse project has a JPA facet but the JPA
+ * model does not have a corresponding JPA project. Remove the JPA
+ * project if the Eclipse project does not have a JPA facet but the JPA
+ * model does have a corresponding JPA project.
+ */
+ private void checkJpaFacet(IProject project) {
+ boolean jpaFacet = JptCorePlugin.projectHasJpaFacet(project);
+ boolean jpaProject = this.jpaModel.containsJpaProject(project);
+
+ if (jpaFacet) {
+ if ( ! jpaProject) { // facet added?
+ this.addJpaProject(project);
+ }
+ } else { // facet removed?
+ if (jpaProject) {
+ this.removeJpaProject(project);
}
- return processor;
}
+ }
- private static class ElementChangeProcessor {
- ElementChangeProcessor() {
- super();
- }
- public void elementChanged(ElementChangedEvent event) {
- JpaModelManager.instance().model.handleEvent(event);
+
+ // ********** Java element changed **********
+
+ /**
+ * Forward the event to the JPA model.
+ */
+ synchronized void javaElementChanged(ElementChangedEvent event) {
+ this.jpaModel.javaElementChanged(event);
+ }
+
+
+ // ********** preference changed **********
+
+ /**
+ * When the "Default JPA Lib" preference changes,
+ * update the appropriate classpath variable.
+ * This method can probably get by without being synchronized.
+ */
+ void preferenceChanged(PropertyChangeEvent event) {
+ if (event.getProperty() == JpaPreferenceConstants.PREF_DEFAULT_JPA_LIB) {
+ try {
+ JavaCore.setClasspathVariable("DEFAULT_JPA_LIB", new Path((String) event.getNewValue()), null);
+ } catch (JavaModelException ex) {
+ this.log(ex); // not sure what would cause this...
}
}
}
-
-
- // ********** preferences listener **********
- private static class PreferencesListener
- implements IPropertyChangeListener
- {
+
+ // ********** resource change listener **********
+
+ /**
+ * Forward the Resource change event back to the JPA model manager.
+ */
+ private class ResourceChangeListener implements IResourceChangeListener {
+ ResourceChangeListener() {
+ super();
+ }
+ public void resourceChanged(IResourceChangeEvent event) {
+ JpaModelManager.this.resourceChanged(event);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
+
+ // ********** faceted project listener **********
+
+ /**
+ * Forward the Faceted project change event back to the JPA model manager.
+ */
+ private class FacetedProjectListener implements IFacetedProjectListener {
+ FacetedProjectListener() {
+ super();
+ }
+ public void handleEvent(IFacetedProjectEvent event) {
+ JpaModelManager.this.facetedProjectChanged(event);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
+
+ // ********** Java element change listener **********
+
+ /**
+ * Forward the Java element change event back to the JPA model manager.
+ */
+ private class JavaElementChangeListener implements IElementChangedListener {
+ JavaElementChangeListener() {
+ super();
+ }
+ public void elementChanged(ElementChangedEvent event) {
+ JpaModelManager.this.javaElementChanged(event);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
+
+ // ********** preferences listener **********
+
+ /**
+ * Forward the Preferences change event back to the JPA model manager.
+ */
+ private class PreferencesListener implements IPropertyChangeListener {
PreferencesListener() {
super();
}
public void propertyChange(PropertyChangeEvent event) {
- if (event.getProperty() == JpaPreferenceConstants.PREF_DEFAULT_JPA_LIB) {
- try {
- JavaCore.setClasspathVariable("DEFAULT_JPA_LIB", new Path((String) event.getNewValue()), null);
- }
- catch (JavaModelException ex) {
- JptCorePlugin.log(ex);
- }
- }
+ JpaModelManager.this.preferenceChanged(event);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaNodeModel.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaNodeModel.java
new file mode 100644
index 0000000000..57fc2a893a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaNodeModel.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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 java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jpt.db.internal.ConnectionProfile;
+import org.eclipse.jpt.db.internal.Database;
+import org.eclipse.jpt.utility.internal.node.AbstractNodeModel;
+
+/**
+ *
+ */
+public abstract class JpaNodeModel
+ extends AbstractNodeModel
+ implements IJpaNodeModel
+{
+
+
+ // ********** constructor **********
+
+ protected JpaNodeModel(IJpaNodeModel parent) {
+ super(parent);
+ }
+
+
+ // ********** IJpaNodeModel implementation **********
+
+ public IResource resource() {
+ return this.jpaProject().project();
+ }
+
+ public IJpaProject jpaProject() {
+ return this.root();
+ }
+
+ public String displayString() {
+ return this.toString();
+ }
+
+
+ // ********** overrides **********
+
+ @Override
+ public IJpaNodeModel parent() {
+ return (IJpaNodeModel) super.parent();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<? extends IJpaNodeModel> children() {
+ return (Iterator<? extends IJpaNodeModel>) super.children();
+ }
+
+ @Override
+ public IJpaProject root() {
+ return (IJpaProject) super.root();
+ }
+
+
+ // ********** convenience methods **********
+
+ protected IJpaPlatform jpaPlatform() {
+ return this.jpaProject().jpaPlatform();
+ }
+
+ protected IJpaFactory jpaFactory() {
+ return this.jpaPlatform().getJpaFactory();
+ }
+
+ protected ConnectionProfile connectionProfile() {
+ return this.jpaProject().connectionProfile();
+ }
+
+ protected Database database() {
+ return this.connectionProfile().getDatabase();
+ }
+
+ protected boolean isConnected() {
+ return this.connectionProfile().isConnected();
+ }
+
+
+ // TODO this stuff should go away when we rework "defaults"
+ // ********** recalculate defaults **********
+
+ private static final Map<Class<? extends AbstractNodeModel>, Set<String>> nonDefaultAspectNameSets = new Hashtable<Class<? extends AbstractNodeModel>, Set<String>>();
+
+ @Override
+ protected void aspectChanged(String aspectName) {
+ super.aspectChanged(aspectName);
+ if (this.aspectAffectsDefaults(aspectName)) {
+ // System.out.println(Thread.currentThread() + " defaults change: " + this + ": " + aspectName);
+ this.jpaProject().update();
+ }
+ }
+
+ private boolean aspectAffectsDefaults(String aspectName) {
+ return ! this.aspectDoesNotAffectDefaults(aspectName);
+ }
+
+ private boolean aspectDoesNotAffectDefaults(String aspectName) {
+ return this.nonDefaultAspectNames().contains(aspectName);
+ }
+
+ protected final Set<String> nonDefaultAspectNames() {
+ synchronized (nonDefaultAspectNameSets) {
+ Set<String> nonDefaultAspectNames = nonDefaultAspectNameSets.get(this.getClass());
+ if (nonDefaultAspectNames == null) {
+ nonDefaultAspectNames = new HashSet<String>();
+ this.addNonDefaultAspectNamesTo(nonDefaultAspectNames);
+ nonDefaultAspectNameSets.put(this.getClass(), nonDefaultAspectNames);
+ }
+ return nonDefaultAspectNames;
+ }
+ }
+
+ protected void addNonDefaultAspectNamesTo(Set<String> nonDefaultAspectNames) {
+ nonDefaultAspectNames.add(COMMENT_PROPERTY);
+ nonDefaultAspectNames.add(DIRTY_BRANCH_PROPERTY);
+ nonDefaultAspectNames.add(BRANCH_PROBLEMS_LIST);
+ nonDefaultAspectNames.add(HAS_BRANCH_PROBLEMS_PROPERTY);
+ // when you override this method, don't forget to include:
+ // super.addNonDefaultAspectNamesTo(nonDefaultAspectNames);
+ }
+
+}
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
index a0818cd23e..c812684c1b 100644
--- 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
@@ -9,25 +9,30 @@
******************************************************************************/
package org.eclipse.jpt.core.internal;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.Map;
import org.eclipse.core.runtime.CoreException;
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.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
+import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
-public class JpaPlatformRegistry
-{
+/**
+ * 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.
*/
@@ -35,130 +40,139 @@ public class JpaPlatformRegistry
return INSTANCE;
}
- private static final String EXTENSION_ID =
- "jpaPlatform"; //$NON-NLS-1$
-
- private static final String EL_PLATFORM =
- "jpaPlatform"; //$NON-NLS-1$
-
- private static final String AT_ID =
- "id"; //$NON-NLS-1$
-
- private static final String AT_LABEL =
- "label"; //$NON-NLS-1$
-
- private static final String AT_CLASS =
- "class"; //$NON-NLS-1$
-
- // key: String jpaPlatform id value: IConfigurationElement class descriptor
- private Map<String, IConfigurationElement> jpaPlatforms;
-
-
- /* (non Java doc)
- * restrict access
+ private static final String EXTENSION_ID = "jpaPlatform"; //$NON-NLS-1$
+ private static final String EL_PLATFORM = "jpaPlatform"; //$NON-NLS-1$
+ private static final String AT_ID = "id"; //$NON-NLS-1$
+ private static final String AT_LABEL = "label"; //$NON-NLS-1$
+ private static final String AT_CLASS = "class"; //$NON-NLS-1$
+
+
+ // ********** constructor/initialization **********
+
+ /**
+ * ensure single instance
*/
private JpaPlatformRegistry() {
- buildJpaPlatforms();
+ super();
+ this.jpaPlatformConfigurationElements = this.buildJpaPlatformConfigurationElements();
}
- private void buildJpaPlatforms() {
- this.jpaPlatforms = new HashMap<String, IConfigurationElement>();
-
- for (Iterator<IConfigurationElement> stream = allConfigElements(); stream.hasNext(); ) {
- buildJpaPlatform(stream.next());
+ private HashMap<String, IConfigurationElement> buildJpaPlatformConfigurationElements() {
+ HashMap<String, IConfigurationElement> configElements = new HashMap<String, IConfigurationElement>();
+ for (Iterator<IConfigurationElement> stream = this.configElements(); stream.hasNext(); ) {
+ this.addConfigElementTo(stream.next(), configElements);
}
+ return configElements;
}
-
- private void buildJpaPlatform(IConfigurationElement configElement) {
- if (! configElement.getName().equals(EL_PLATFORM)) {
+
+ /**
+ * Return the configuration elements from the Eclipse platform extension
+ * registry.
+ */
+ private Iterator<IConfigurationElement> configElements() {
+ return new CompositeIterator<IConfigurationElement>(
+ new TransformationIterator<IExtension, Iterator<IConfigurationElement>>(this.extensions()) {
+ @Override
+ protected Iterator<IConfigurationElement> transform(IExtension extension) {
+ return CollectionTools.iterator(extension.getConfigurationElements());
+ }
+ }
+ );
+ }
+
+ private Iterator<IExtension> extensions() {
+ return CollectionTools.iterator(this.extensionPoint().getExtensions());
+ }
+
+ private IExtensionPoint extensionPoint() {
+ return Platform.getExtensionRegistry().getExtensionPoint(JptCorePlugin.PLUGIN_ID, EXTENSION_ID);
+ }
+
+ private void addConfigElementTo(IConfigurationElement configElement, HashMap<String, IConfigurationElement> configElements) {
+ if ( ! configElement.getName().equals(EL_PLATFORM)) {
return;
}
-
- String platformId = configElement.getAttribute(AT_ID);
- String platformLabel = configElement.getAttribute(AT_LABEL);
- String platformClass = configElement.getAttribute(AT_CLASS);
-
- if ((platformId == null) || (platformLabel == null) || (platformClass == null)) {
- if (platformId == null) {
- reportMissingAttribute(configElement, AT_ID);
- }
- if (platformLabel == null) {
- reportMissingAttribute(configElement, AT_LABEL);
- }
- if (platformClass == null) {
- reportMissingAttribute(configElement, AT_CLASS);
- }
+ if ( ! this.configElementIsValid(configElement)) {
return;
}
-
- if (this.jpaPlatforms.containsKey(platformId)) {
- IConfigurationElement otherConfigElement = this.jpaPlatforms.get(platformId);
- reportDuplicatePlatform(configElement, otherConfigElement);
+
+ String id = configElement.getAttribute(AT_ID);
+ IConfigurationElement prev = configElements.get(id);
+ if (prev == null) {
+ configElements.put(id, configElement);
+ } else {
+ this.logDuplicatePlatform(prev, configElement);
}
-
- this.jpaPlatforms.put(platformId, configElement);
}
-
+
/**
- * Return a new IJpaPlatform for the given id.
- * NB: This should only be done when instantiating a platform for a given
- * IJpaProject, either when creating the project, or when changing the
- * platform.
+ * check *all* attributes before returning
*/
- public IJpaPlatform jpaPlatform(String id) {
- IConfigurationElement registeredConfigElement = this.jpaPlatforms.get(id);
-
- if (registeredConfigElement == null) {
- return null;
+ private boolean configElementIsValid(IConfigurationElement configElement) {
+ boolean valid = true;
+ if (configElement.getAttribute(AT_ID) == null) {
+ this.logMissingAttribute(configElement, AT_ID);
+ valid = false;
}
-
- try {
- IJpaPlatform platform =
- (IJpaPlatform) registeredConfigElement.createExecutableExtension(AT_CLASS);
- platform.setId(id);
- return platform;
+ if (configElement.getAttribute(AT_LABEL) == null) {
+ logMissingAttribute(configElement, AT_LABEL);
+ valid = false;
}
- catch (CoreException ce) {
- reportFailedInstantiation(registeredConfigElement);
- return null;
+ if (configElement.getAttribute(AT_CLASS) == null) {
+ logMissingAttribute(configElement, AT_CLASS);
+ valid = false;
}
+ return valid;
}
-
+
+
+ // ********** public methods **********
+
/**
- * Return an iterator of String ids for all registered JPA platforms.
- * This does not load any of the platforms' plugin classes.
+ * Return the IDs for the registered JPA platforms.
+ * This does not activate any of the JPA platforms' plug-ins.
*/
- public Iterator allJpaPlatformIds() {
- return Collections.unmodifiableMap(jpaPlatforms).keySet().iterator();
+ public Iterator<String> jpaPlatformIds() {
+ return new ReadOnlyIterator<String>(this.jpaPlatformConfigurationElements.keySet());
}
-
+
/**
- * Return the label for the platform with the given id.
- * This does not load the platform's plugin classes.
+ * Return the label for the JPA platform with the specified ID.
+ * This does not activate the JPA platform's plug-in.
*/
public String jpaPlatformLabel(String id) {
- return jpaPlatforms.get(id).getAttribute(AT_LABEL);
+ return this.jpaPlatformConfigurationElements.get(id).getAttribute(AT_LABEL);
}
-
- private Iterator<IConfigurationElement> allConfigElements() {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint extensionPoint =
- registry.getExtensionPoint(JptCorePlugin.PLUGIN_ID, EXTENSION_ID);
- IExtension[] extensions = extensionPoint.getExtensions();
-
- return new CompositeIterator<IConfigurationElement>(
- new TransformationIterator<IExtension, Iterator<IConfigurationElement>>(CollectionTools.iterator(extensions)) {
- @Override
- protected Iterator<IConfigurationElement> transform(IExtension next) {
- return CollectionTools.iterator(next.getConfigurationElements());
- }
- }
- );
+
+ /**
+ * 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 IJpaPlatform jpaPlatform(String id) {
+ IConfigurationElement configElement = this.jpaPlatformConfigurationElements.get(id);
+ if (configElement == null) {
+ throw new IllegalArgumentException(id);
+ }
+ IJpaPlatform platform;
+ try {
+ platform = (IJpaPlatform) configElement.createExecutableExtension(AT_CLASS);
+ } catch (CoreException ex) {
+ this.logFailedInstantiation(configElement, ex);
+ throw new IllegalArgumentException(id);
+ }
+ platform.setId(id);
+ return platform;
}
-
+
+
+ // ********** errors **********
+
// TODO externalize strings
- private void reportMissingAttribute(IConfigurationElement configElement, String attributeName) {
+ private void logMissingAttribute(IConfigurationElement configElement, String attributeName) {
String message =
"An extension element \""
+ configElement.getName()
@@ -169,22 +183,21 @@ public class JpaPlatformRegistry
+ "\".";
JptCorePlugin.log(message);
}
-
+
// TODO externalize strings
- private void reportDuplicatePlatform(
- IConfigurationElement oneConfigElement, IConfigurationElement otherConfigElement) {
+ private void logDuplicatePlatform(IConfigurationElement prevConfigElement, IConfigurationElement newConfigElement) {
String message =
"The plugins \""
- + oneConfigElement.getContributor().getName()
+ + prevConfigElement.getContributor().getName()
+ "\" and \""
- + otherConfigElement.getContributor().getName()
+ + newConfigElement.getContributor().getName()
+ "\" have registered a duplicate attribute \"id\" "
+ "for the extension element \"jpaPlatform\".";
JptCorePlugin.log(message);
}
-
+
// TODO externalize strings
- private void reportFailedInstantiation(IConfigurationElement configElement) {
+ private void logFailedInstantiation(IConfigurationElement configElement, CoreException ex) {
String message =
"Could not instantiate the class \""
+ configElement.getAttribute(AT_CLASS)
@@ -194,5 +207,7 @@ public class JpaPlatformRegistry
+ configElement.getContributor().getName()
+ "\".";
JptCorePlugin.log(message);
+ JptCorePlugin.log(ex);
}
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProject.java
index 87723ad370..8d40414819 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProject.java
@@ -9,11 +9,11 @@
******************************************************************************/
package org.eclipse.jpt.core.internal;
-import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Vector;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -25,834 +25,445 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.NotificationChain;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.impl.ENotificationImpl;
-import org.eclipse.emf.ecore.util.EObjectContainmentEList;
-import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jpt.core.internal.content.java.JavaPersistentType;
import org.eclipse.jpt.core.internal.content.java.JpaCompilationUnit;
-import org.eclipse.jpt.core.internal.facet.JpaFacetUtils;
import org.eclipse.jpt.core.internal.platform.IContext;
import org.eclipse.jpt.db.internal.ConnectionProfile;
-import org.eclipse.jpt.db.internal.JptDbPlugin;
-import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.CommandExecutor;
import org.eclipse.jpt.utility.internal.CommandExecutorProvider;
import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
-import org.eclipse.jst.j2ee.internal.J2EEConstants;
-import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
-import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
+import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
+import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
+import org.eclipse.jpt.utility.internal.model.ChangeEventDispatcher;
+import org.eclipse.jpt.utility.internal.model.DefaultChangeEventDispatcher;
+import org.eclipse.jpt.utility.internal.node.Node;
/**
- * <!-- begin-user-doc -->
- * A representation of the model object '<em><b>Jpa Project</b></em>'.
- * <!-- end-user-doc -->
- *
- * <p>
- * The following features are supported:
- * <ul>
- * <li>{@link org.eclipse.jpt.core.internal.JpaProject#getPlatform <em>Platform</em>}</li>
- * <li>{@link org.eclipse.jpt.core.internal.JpaProject#getDataSource <em>Data Source</em>}</li>
- * <li>{@link org.eclipse.jpt.core.internal.JpaProject#isDiscoverAnnotatedClasses <em>Discover Annotated Classes</em>}</li>
- * <li>{@link org.eclipse.jpt.core.internal.JpaProject#getFiles <em>Files</em>}</li>
- * </ul>
- * </p>
- *
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaProject()
- * @model kind="class"
- * @generated
+ *
*/
-public class JpaProject extends JpaEObject implements IJpaProject
-{
- /**
- * The IProject associated with this JPA project
- */
- protected IProject project;
+public class JpaProject extends JpaNodeModel implements IJpaProject {
/**
- * The IJpaPlatform associated with this JPA project
+ * The Eclipse project corresponding to the JPA project.
*/
- protected IJpaPlatform platform;
+ protected final IProject project;
/**
- * The cached value of the '{@link #getDataSource() <em>Data Source</em>}' containment reference.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see #getDataSource()
- * @generated
- * @ordered
+ * The vendor-specific JPA platform that builds the JPA project
+ * and all its contents.
*/
- protected IJpaDataSource dataSource;
+ protected final IJpaPlatform jpaPlatform;
/**
- * The default value of the '{@link #isDiscoverAnnotatedClasses() <em>Discover Annotated Classes</em>}' attribute.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see #isDiscoverAnnotatedClasses()
- * @generated
- * @ordered
+ * The data source that wraps the DTP model.
*/
- protected static final boolean DISCOVER_ANNOTATED_CLASSES_EDEFAULT = false;
+ protected final IJpaDataSource dataSource;
/**
- * The cached value of the '{@link #isDiscoverAnnotatedClasses() <em>Discover Annotated Classes</em>}' attribute.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see #isDiscoverAnnotatedClasses()
- * @generated
- * @ordered
+ * The JPA files associated with the JPA project.
*/
- protected boolean discoverAnnotatedClasses = DISCOVER_ANNOTATED_CLASSES_EDEFAULT;
+ protected final Vector<IJpaFile> jpaFiles;
/**
- * This is true if the Discover Annotated Classes attribute has been set.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- * @ordered
+ * Flag indicating whether the project should "discover" annotated
+ * classes automatically, as opposed to requiring the classes to be
+ * listed in persistence.xml.
*/
- protected boolean discoverAnnotatedClassesESet;
+ protected boolean discoversAnnotatedClasses;
+ public static final String DISCOVERS_ANNOTATED_CLASSES_PROPERTY = "discoversAnnotatedClasses";
/**
- * The cached value of the '{@link #getFiles() <em>Files</em>}' containment reference list.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see #getFiles()
- * @generated
- * @ordered
+ * The visitor passed to resource deltas.
*/
- protected EList<IJpaFile> files;
+ protected final IResourceDeltaVisitor resourceDeltaVisitor;
/**
- * Flag to indicate whether this project has been filled with files
+ * The dispatcher can be changed so it is UI-aware.
*/
- private boolean filled = false;
+ protected volatile ChangeEventDispatcher changeEventDispatcher;
/**
- * Flag to indicate that the resynchJob has been scheduled or is running.
- * This is set to false when that job is completed
+ * Support for modifying documents shared with the UI.
*/
- boolean resynching = false;
-
- /**
- * Flag to indicate that the disposing job has been scheduled or is running
- * (or has been run, in some cases)
- */
- boolean disposing = false;
+ protected final ThreadLocal<CommandExecutor> threadLocalModifySharedDocumentCommandExecutor;
+ protected final CommandExecutorProvider modifySharedDocumentCommandExecutorProvider;
/**
- * Flag to indicate that the resynchJob needs to be run. This is
- * set to true if resynching = true so that the next time the job completes
- * it will be run again.
+ * Scheduler that uses a job to update the JPA project when changes occur.
+ * @see #update()
*/
- boolean needsToResynch = false;
+ protected final UpdateJpaProjectJobScheduler updateJpaProjectJobScheduler;
+
+
+ // ********** constructor/initialization **********
/**
- * Job used to reconnect the model parts throughout the project containment hierarchy
- * @see IJpaProject#resynch()
+ * The project and JPA platform are required.
*/
- Job resynchJob;
-
- private CommandExecutorProvider modifySharedDocumentCommandExecutorProvider;
+ public JpaProject(IJpaProject.Config config) throws CoreException {
+ super(null); // JPA project is the root of the containment tree
+ if ((config.project() == null) || (config.jpaPlatform() == null)) {
+ throw new NullPointerException();
+ }
+ this.project = config.project();
+ this.jpaPlatform = config.jpaPlatform();
+ this.jpaPlatform.setProject(this); // TODO this must go
+ this.dataSource = this.jpaFactory().createDataSource(this, config.connectionProfileName());
+ this.discoversAnnotatedClasses = config.discoverAnnotatedClasses();
+ this.jpaFiles = this.buildJpaFiles();
- private ThreadLocal<CommandExecutor> threadLocalModifySharedDocumentCommandExecutor = new ThreadLocal<CommandExecutor>();
+ this.resourceDeltaVisitor = this.buildResourceDeltaVisitor();
+ this.changeEventDispatcher = this.buildChangeEventDispatcher();
+ this.threadLocalModifySharedDocumentCommandExecutor = this.buildThreadLocalModifySharedDocumentCommandExecutor();
+ this.modifySharedDocumentCommandExecutorProvider = this.buildModifySharedDocumentCommandExecutorProvider();
+ this.updateJpaProjectJobScheduler = this.buildUpdateJpaProjectJobScheduler();
+ // build the JPA files corresponding to the Eclipse project's files
+ this.project.accept(this.buildInitialResourceProxyVisitor(), IResource.NONE);
- JpaProject() {
- super();
+ this.update();
}
- protected JpaProject(IProject project) {
- this();
- this.project = project;
- this.resynchJob = buildResynchJob();
+ @Override
+ protected void checkParent(Node parentNode) {
+ if (parentNode != null) {
+ throw new IllegalArgumentException("The parent node must be null");
+ }
}
- private Job buildResynchJob() {
- Job job = new Job("Resynching JPA model ...") {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- return runResynch(monitor);
- }
- finally {
- JpaProject.this.resynching = false;
- if (JpaProject.this.needsToResynch) {
- resynch();
- }
- }
- }
-
- };
- if (this.project == null) {
- throw new IllegalStateException("Project can not be null when the Resynch Job is built");
- }
- job.setRule(this.project);
- return job;
+ protected Vector<IJpaFile> buildJpaFiles() {
+ return new Vector<IJpaFile>();
}
- private IStatus runResynch(IProgressMonitor monitor) {
- IContext contextHierarchy = getPlatform().buildProjectContext();
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- try {
- getPlatform().resynch(contextHierarchy, monitor);
- }
- catch (OperationCanceledException e) {
- return Status.CANCEL_STATUS;
- }
- catch (Throwable e) {
- //exceptions can occur when this thread is running and changes are
- //made to the java source. our model is not yet updated to the changed java source.
- //log these exceptions and assume they won't happen when the resynch runs again
- //as a result of the java source changes.
- JptCorePlugin.log(e);
- }
- return Status.OK_STATUS;
+ protected IResourceDeltaVisitor buildResourceDeltaVisitor() {
+ return new ResourceDeltaVisitor();
}
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- @Override
- protected EClass eStaticClass() {
- return JpaCorePackage.Literals.JPA_PROJECT;
+ protected ChangeEventDispatcher buildChangeEventDispatcher() {
+ return DefaultChangeEventDispatcher.instance();
}
- /**
- * @see IJpaProject#getProject()
- */
- public IProject getProject() {
- return project;
+ protected ThreadLocal<CommandExecutor> buildThreadLocalModifySharedDocumentCommandExecutor() {
+ return new ThreadLocal<CommandExecutor>();
}
- public IJavaProject getJavaProject() {
- return JavaCore.create(getProject());
+ protected CommandExecutorProvider buildModifySharedDocumentCommandExecutorProvider() {
+ return new ModifySharedDocumentCommandExecutorProvider();
}
- /**
- * @see IJpaProject#getModel()
- */
- public IJpaModel getModel() {
- return (IJpaModel) eContainer();
+ protected IResourceProxyVisitor buildInitialResourceProxyVisitor() {
+ return new InitialResourceProxyVisitor();
}
- /**
- * Returns the value of the '<em><b>Platform</b></em>' reference.
- * <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Platform</em>' reference isn't clear,
- * there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- * @return the value of the '<em>Platform</em>' reference.
- * @see #setPlatform(IJpaPlatform)
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaProject_Platform()
- * @model resolveProxies="false" required="true" ordered="false"
- * @generated
- */
- public IJpaPlatform getPlatformGen() {
- return platform;
+ protected UpdateJpaProjectJobScheduler buildUpdateJpaProjectJobScheduler() {
+ return new UpdateJpaProjectJobScheduler(this, this.project);
}
- public IJpaPlatform getPlatform() {
- if (platform == null) {
- setPlatform(JpaFacetUtils.getPlatform(project));
+ // ***** inner class
+ protected class InitialResourceProxyVisitor implements IResourceProxyVisitor {
+ protected InitialResourceProxyVisitor() {
+ super();
+ }
+ // add a JPA file for every [appropriate] file encountered by the visitor
+ public boolean visit(IResourceProxy resource) throws CoreException {
+ switch (resource.getType()) {
+ case IResource.ROOT : // shouldn't happen
+ case IResource.PROJECT :
+ case IResource.FOLDER :
+ return true; // visit children
+ case IResource.FILE :
+ JpaProject.this.addJpaFile((IFile) resource.requestResource());
+ return false; // no children
+ default :
+ return false; // no children
+ }
}
- return getPlatformGen();
}
- /**
- * Sets the value of the '{@link org.eclipse.jpt.core.internal.JpaProject#getPlatform <em>Platform</em>}' reference.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @param value the new value of the '<em>Platform</em>' reference.
- * @see #getPlatform()
- * @generated
- */
- public void setPlatformGen(IJpaPlatform newPlatform) {
- IJpaPlatform oldPlatform = platform;
- platform = newPlatform;
- if (eNotificationRequired())
- eNotify(new ENotificationImpl(this, Notification.SET, JpaCorePackage.JPA_PROJECT__PLATFORM, oldPlatform, platform));
- }
- public void setPlatform(IJpaPlatform jpaPlatform) {
- jpaPlatform.setProject(this);
- setPlatformGen(jpaPlatform);
- }
+ // ********** general queries **********
- /**
- * @see IJpaProject#setPlatform(String)
- */
- public void setPlatform(String platformId) {
- setPlatform(JpaPlatformRegistry.instance().jpaPlatform(platformId));
+ @Override
+ public IJpaProject root() {
+ return this;
}
- /**
- * Returns the value of the '<em><b>Data Source</b></em>' containment reference.
- * <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Data Source</em>' containment reference isn't clear,
- * there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- * @return the value of the '<em>Data Source</em>' containment reference.
- * @see #setDataSource(IJpaDataSource)
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaProject_DataSource()
- * @model containment="true" ordered="false"
- * @generated
- */
- public IJpaDataSource getDataSourceGen() {
- return dataSource;
+ public IProject project() {
+ return this.project;
}
- public synchronized IJpaDataSource getDataSource() {
- if (dataSource == null) {
- setDataSource(JpaFacetUtils.getConnectionName(project));
- }
- return getDataSourceGen();
+ public String name() {
+ return this.project.getName();
}
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- public NotificationChain basicSetDataSource(IJpaDataSource newDataSource, NotificationChain msgs) {
- IJpaDataSource oldDataSource = dataSource;
- dataSource = newDataSource;
- if (eNotificationRequired()) {
- ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, JpaCorePackage.JPA_PROJECT__DATA_SOURCE, oldDataSource, newDataSource);
- if (msgs == null)
- msgs = notification;
- else
- msgs.add(notification);
- }
- return msgs;
+ public IJavaProject javaProject() {
+ return JavaCore.create(this.project);
}
- /**
- * Sets the value of the '{@link org.eclipse.jpt.core.internal.JpaProject#getDataSource <em>Data Source</em>}' containment reference.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @param value the new value of the '<em>Data Source</em>' containment reference.
- * @see #getDataSource()
- * @generated
- */
- public void setDataSource(IJpaDataSource newDataSource) {
- if (newDataSource != dataSource) {
- NotificationChain msgs = null;
- if (dataSource != null)
- msgs = ((InternalEObject) dataSource).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - JpaCorePackage.JPA_PROJECT__DATA_SOURCE, null, msgs);
- if (newDataSource != null)
- msgs = ((InternalEObject) newDataSource).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - JpaCorePackage.JPA_PROJECT__DATA_SOURCE, null, msgs);
- msgs = basicSetDataSource(newDataSource, msgs);
- if (msgs != null)
- msgs.dispatch();
- }
- else if (eNotificationRequired())
- eNotify(new ENotificationImpl(this, Notification.SET, JpaCorePackage.JPA_PROJECT__DATA_SOURCE, newDataSource, newDataSource));
+ @Override
+ public IJpaPlatform jpaPlatform() {
+ return this.jpaPlatform;
}
- /**
- * @see IJpaProject#setDataSource(String)
- */
- public void setDataSource(String connectionProfileName) {
- if (dataSource == null) {
- JpaDataSource ds = JpaCoreFactory.eINSTANCE.createJpaDataSource();
- setDataSource(ds);
- }
- dataSource.setConnectionProfileName(connectionProfileName);
+ public IJpaDataSource dataSource() {
+ return this.dataSource;
}
- /**
- * Returns the value of the '<em><b>Discover Annotated Classes</b></em>' attribute.
- * The default value is <code>"false"</code>.
- * <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Discover Annotated Classes</em>' attribute isn't clear,
- * there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- * @return the value of the '<em>Discover Annotated Classes</em>' attribute.
- * @see #isSetDiscoverAnnotatedClasses()
- * @see #unsetDiscoverAnnotatedClasses()
- * @see #setDiscoverAnnotatedClasses(boolean)
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaProject_DiscoverAnnotatedClasses()
- * @model default="false" unique="false" unsettable="true" required="true" ordered="false"
- * @generated
- */
- public boolean isDiscoverAnnotatedClassesGen() {
- return discoverAnnotatedClasses;
+ @Override
+ public ConnectionProfile connectionProfile() {
+ return this.dataSource.getConnectionProfile();
}
- public boolean isDiscoverAnnotatedClasses() {
- if (!isSetDiscoverAnnotatedClasses()) {
- setDiscoverAnnotatedClasses(JpaFacetUtils.getDiscoverAnnotatedClasses(project));
- }
- return isDiscoverAnnotatedClassesGen();
+ @Override
+ public Validator validator() {
+ return NULL_VALIDATOR;
}
- /**
- * Sets the value of the '{@link org.eclipse.jpt.core.internal.JpaProject#isDiscoverAnnotatedClasses <em>Discover Annotated Classes</em>}' attribute.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @param value the new value of the '<em>Discover Annotated Classes</em>' attribute.
- * @see #isSetDiscoverAnnotatedClasses()
- * @see #unsetDiscoverAnnotatedClasses()
- * @see #isDiscoverAnnotatedClasses()
- * @generated
- */
- public void setDiscoverAnnotatedClasses(boolean newDiscoverAnnotatedClasses) {
- boolean oldDiscoverAnnotatedClasses = discoverAnnotatedClasses;
- discoverAnnotatedClasses = newDiscoverAnnotatedClasses;
- boolean oldDiscoverAnnotatedClassesESet = discoverAnnotatedClassesESet;
- discoverAnnotatedClassesESet = true;
- if (eNotificationRequired())
- eNotify(new ENotificationImpl(this, Notification.SET, JpaCorePackage.JPA_PROJECT__DISCOVER_ANNOTATED_CLASSES, oldDiscoverAnnotatedClasses, discoverAnnotatedClasses, !oldDiscoverAnnotatedClassesESet));
+ @Override
+ public void toString(StringBuffer sb) {
+ sb.append(this.name());
}
- /**
- * Unsets the value of the '{@link org.eclipse.jpt.core.internal.JpaProject#isDiscoverAnnotatedClasses <em>Discover Annotated Classes</em>}' attribute.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @see #isSetDiscoverAnnotatedClasses()
- * @see #isDiscoverAnnotatedClasses()
- * @see #setDiscoverAnnotatedClasses(boolean)
- * @generated
- */
- public void unsetDiscoverAnnotatedClasses() {
- boolean oldDiscoverAnnotatedClasses = discoverAnnotatedClasses;
- boolean oldDiscoverAnnotatedClassesESet = discoverAnnotatedClassesESet;
- discoverAnnotatedClasses = DISCOVER_ANNOTATED_CLASSES_EDEFAULT;
- discoverAnnotatedClassesESet = false;
- if (eNotificationRequired())
- eNotify(new ENotificationImpl(this, Notification.UNSET, JpaCorePackage.JPA_PROJECT__DISCOVER_ANNOTATED_CLASSES, oldDiscoverAnnotatedClasses, DISCOVER_ANNOTATED_CLASSES_EDEFAULT, oldDiscoverAnnotatedClassesESet));
- }
- /**
- * Returns whether the value of the '{@link org.eclipse.jpt.core.internal.JpaProject#isDiscoverAnnotatedClasses <em>Discover Annotated Classes</em>}' attribute is set.
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @return whether the value of the '<em>Discover Annotated Classes</em>' attribute is set.
- * @see #unsetDiscoverAnnotatedClasses()
- * @see #isDiscoverAnnotatedClasses()
- * @see #setDiscoverAnnotatedClasses(boolean)
- * @generated
- */
- public boolean isSetDiscoverAnnotatedClasses() {
- return discoverAnnotatedClassesESet;
+ // ********** JPA files **********
+
+ public Iterator<IJpaFile> jpaFiles() {
+ return new CloneIterator<IJpaFile>(this.jpaFiles); // read-only
}
- public String rootDeployLocation() {
- String metaInfLocation = "";
- try {
- if (FacetedProjectFramework.hasProjectFacet(project, IModuleConstants.JST_WEB_MODULE)) {
- metaInfLocation = J2EEConstants.WEB_INF_CLASSES;
+ public IJpaFile jpaFile(IFile file) {
+ synchronized (this.jpaFiles) {
+ for (IJpaFile jpaFile : this.jpaFiles) {
+ if (jpaFile.getFile().equals(file)) {
+ return jpaFile;
+ }
}
}
- catch (CoreException ce) {
- // if exception occurs, we'll take the default location
- JptCorePlugin.log(ce);
- }
- return metaInfLocation;
+ return null;
}
- @Override
- public IJpaProject getJpaProject() {
- return this;
+ public Iterator<IJpaFile> jpaFiles(final String contentTypeId) {
+ return new FilteringIterator<IJpaFile>(this.jpaFiles()) {
+ @Override
+ protected boolean accept(Object o) {
+ return ((IJpaFile) o).getContentId().equals(contentTypeId);
+ }
+ };
}
- /**
- * Returns the value of the '<em><b>Files</b></em>' containment reference list.
- * The list contents are of type {@link org.eclipse.jpt.core.internal.IJpaFile}.
- * <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Files</em>' containment reference list isn't clear,
- * there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- * @return the value of the '<em>Files</em>' containment reference list.
- * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaProject_Files()
- * @model containment="true"
- * @generated
- */
- public EList<IJpaFile> getFiles() {
- if (files == null) {
- files = new EObjectContainmentEList<IJpaFile>(IJpaFile.class, this, JpaCorePackage.JPA_PROJECT__FILES);
- }
- return files;
+ public Iterator<IJpaFile> javaJpaFiles() {
+ return this.jpaFiles(JavaCore.JAVA_SOURCE_CONTENT_TYPE);
}
/**
- * INTERNAL ONLY
- * Fill project with file resources
+ * Add a JPA file for the specified file, if appropriate.
*/
- void fill() throws CoreException {
- if (filled) {
- return;
+ protected void addJpaFile(IFile file) {
+ IJpaFile jpaFile = this.jpaPlatform.createJpaFile(this, file);
+ if (jpaFile != null) {
+ this.addItemToCollection(jpaFile, this.jpaFiles, JPA_FILES_COLLECTION);
}
- IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
- public boolean visit(IResourceProxy resource) throws CoreException {
- switch (resource.getType()) {
- case IResource.PROJECT :
- case IResource.FOLDER :
- return true;
- case IResource.FILE :
- IFile file = (IFile) resource.requestResource();
- if (getJpaFileInternal(file) == null) {
- createJpaFile(file);
- }
- default :
- return false;
- }
- }
- };
- getProject().accept(visitor, IResource.NONE);
- filled = true;
- resynch();
- }
-
- public boolean isFilled() {
- return filled;
}
/**
- * @see IJpaProject#getJpaFile(IFile)
+ * Remove the specified JPA file and dispose it.
*/
- public synchronized IJpaFile getJpaFile(IFile file) {
- IJpaFile jpaFile = this.getJpaFileInternal(file);
- if (this.filled) {
- return jpaFile;
+ protected void removeJpaFile(IJpaFile jpaFile) {
+ if ( ! this.removeItemFromCollection(jpaFile, this.jpaFiles, JPA_FILES_COLLECTION)) {
+ throw new IllegalArgumentException("JPA file: " + jpaFile.getFile().getName());
}
- return (jpaFile != null) ? jpaFile : this.createJpaFile(file);
+ jpaFile.dispose();
}
- synchronized IJpaFile getJpaFileInternal(IFile file) {
- for (IJpaFile next : this.getFiles()) {
- if (next.getFile().equals(file)) {
- return next;
- }
- }
- return null;
+ protected boolean containsJpaFile(IFile file) {
+ return (this.jpaFile(file) != null);
}
- public Iterator<IJpaFile> jpaFiles() {
- return new CloneIterator<IJpaFile>(getFiles());
+
+ // ********** change event dispatcher **********
+
+ @Override
+ public ChangeEventDispatcher changeEventDispatcher() {
+ return this.changeEventDispatcher;
}
- public Collection<IJpaFile> jpaFiles(String contentType) {
- Collection<IJpaFile> jpaFiles = new ArrayList<IJpaFile>();
- for (Iterator<IJpaFile> stream = jpaFiles(); stream.hasNext();) {
- IJpaFile next = stream.next();
- if (next.getContentId().equals(contentType)) {
- jpaFiles.add(next);
- }
- }
- return jpaFiles;
+ @Override
+ public void setChangeEventDispatcher(ChangeEventDispatcher changeEventDispatcher) {
+ this.changeEventDispatcher = changeEventDispatcher;
}
- public JavaPersistentType findJavaPersistentType(IType type) {
- if (type == null) {
- return null;
- }
- Collection<IJpaFile> persistenceFiles = jpaFiles(JptCorePlugin.JAVA_CONTENT_TYPE);
- for (IJpaFile jpaFile : persistenceFiles) {
- JpaCompilationUnit compilationUnit = (JpaCompilationUnit) jpaFile.getContent();
- for (JavaPersistentType persistentType : compilationUnit.getTypes()) {
- if (type.equals(persistentType.getType().getJdtMember())) {
- return persistentType;
- }
+
+ // ********** more queries **********
+
+ protected Iterator<JpaCompilationUnit> jpaCompilationUnits() {
+ return new TransformationIterator<IJpaFile, JpaCompilationUnit>(this.javaJpaFiles()) {
+ @Override
+ protected JpaCompilationUnit transform(IJpaFile jpaFile) {
+ return (JpaCompilationUnit) jpaFile.getContent();
}
- }
- return null;
+ };
}
/**
- * INTERNAL ONLY
- * Dispose and remove project
+ * Return an iterator of iterators on Java persistent types
*/
- void dispose() {
- if (disposing) return;
-
- disposing = true;
-
- Job job = new Job("Disposing JPA project ...") {
+ protected Iterator<Iterator<JavaPersistentType>> javaPersistentTypeIterators() {
+ return new TransformationIterator<JpaCompilationUnit, Iterator<JavaPersistentType>>(this.jpaCompilationUnits()) {
@Override
- protected IStatus run(IProgressMonitor monitor) {
- dispose_();
- return Status.OK_STATUS;
+ protected Iterator<JavaPersistentType> transform(JpaCompilationUnit jcu) {
+ return jcu.getTypes().iterator();
}
};
- job.setRule(project);
- job.schedule();
}
-
- private void dispose_() {
- for (IJpaFile jpaFile : CollectionTools.collection(getFiles())) {
- ((JpaFile) jpaFile).dispose();
- }
- ((JpaModel) getModel()).getProjects().remove(this);
+
+ public Iterator<JavaPersistentType> javaPersistentTypes() {
+ return new CompositeIterator<JavaPersistentType>(this.javaPersistentTypeIterators());
}
- /**
- * INTERNAL ONLY
- * Synch internal JPA resources.
- */
- void synchInternalResources(IResourceDelta delta) throws CoreException {
- delta.accept(this.buildResourceDeltaVisitor());
- }
-
- private IResourceDeltaVisitor buildResourceDeltaVisitor() {
- return new IResourceDeltaVisitor() {
- private IResource currentResource = getProject();
-
- public boolean visit(IResourceDelta delta) throws CoreException {
- IResource res = delta.getResource();
- if (res.equals(currentResource))
- return true;
- if (res.getType() == IResource.FILE) {
- IFile file = (IFile) res;
- switch (delta.getKind()) {
- case IResourceDelta.ADDED :
- if (getJpaFile(file) == null) {
- createJpaFile(file);
- JpaProject.this.resynch();//TODO different api for this?
- }
- break;
- case IResourceDelta.REMOVED :
- JpaFile jpaFile = (JpaFile) getJpaFile(file);
- if (jpaFile != null) {
- jpaFile.dispose();
- JpaProject.this.resynch();//TODO different api for this?
- }
- break;
- case IResourceDelta.CHANGED :
- // shouldn't have to worry, since all changes we're looking for have to do with file name
- }
- }
- return true;
+ public JavaPersistentType javaPersistentType(IType type) {
+ for (Iterator<JavaPersistentType> stream = this.javaPersistentTypes(); stream.hasNext(); ) {
+ JavaPersistentType jpt = stream.next();
+ if (jpt.getType().getJdtMember().equals(type)) {
+ return jpt;
}
- };
+ }
+ return null;
}
- // PWFTODO
- // Return a NullPersistenceFile if no content found?
- synchronized IJpaFile createJpaFile(IFile file) {
- if (!JavaCore.create(this.project).isOnClasspath(file)) {
- return null;
- }
- IContentType contentType = this.contentType(file);
- if (contentType == null) {
- return null;
- }
+ // ********** Java change **********
- String contentTypeId = contentType.getId();
- IJpaFileContentProvider provider = this.getPlatform().fileContentProvider(contentTypeId);
- if (provider == null) {
- return null;
+ public void javaElementChanged(ElementChangedEvent event) {
+ for (Iterator<IJpaFile> stream = this.jpaFiles(); stream.hasNext(); ) {
+ stream.next().javaElementChanged(event);
}
-
- JpaFile jpaFile = JpaCoreFactory.eINSTANCE.createJpaFile();
- this.getFiles().add(jpaFile);
- jpaFile.setFile(file);
- jpaFile.setContentId(contentTypeId);
- provider.buildRootContent(jpaFile);
- return jpaFile;
}
- //attempting to get the contentType based on the file contents.
- //have to check the file contents instead of just the file name
- //because for xml we base it on the rootElement name
- private IContentType contentType(IFile file) {
- try {
- return Platform.getContentTypeManager().findContentTypeFor(file.getContents(), file.getName());
- } catch (IOException ex) {
- JptCorePlugin.log(ex);
- } catch (CoreException ex) {
- JptCorePlugin.log(ex);
- }
- return null;
+
+ // ********** validation **********
+
+ @SuppressWarnings("restriction")
+ public Iterator<org.eclipse.wst.validation.internal.provisional.core.IMessage> validationMessages() {
+ List<org.eclipse.wst.validation.internal.provisional.core.IMessage> messages = new ArrayList<org.eclipse.wst.validation.internal.provisional.core.IMessage>();
+ this.jpaPlatform.addToMessages(messages);
+ return messages.iterator();
}
- /**
- * INTERNAL ONLY
- * Handle java element change event.
- */
- void handleEvent(ElementChangedEvent event) {
- if (filled) {
- for (Iterator<IJpaFile> stream = jpaFiles(); stream.hasNext();) {
- ((JpaFile) stream.next()).handleEvent(event);
- }
- resynch();
- }
+
+ // ********** root deploy location **********
+
+ @SuppressWarnings("restriction")
+ protected static final String WEB_PROJECT_ROOT_DEPLOY_LOCATION = org.eclipse.jst.j2ee.internal.J2EEConstants.WEB_INF_CLASSES;
+
+ public String rootDeployLocation() {
+ return this.isWebProject() ? WEB_PROJECT_ROOT_DEPLOY_LOCATION : "";
}
- public Iterator<IMessage> validationMessages() {
- List<IMessage> messages = new ArrayList<IMessage>();
- getPlatform().addToMessages(messages);
- return messages.iterator();
+ @SuppressWarnings("restriction")
+ protected static final String JST_WEB_MODULE = org.eclipse.wst.common.componentcore.internal.util.IModuleConstants.JST_WEB_MODULE;
+
+ protected boolean isWebProject() {
+ return JptCorePlugin.projectHasWebFacet(this.project);
}
- //leaving this at the JpaProject level for now instead of
- //passing it on to the JpaModel. We don't currently support
- //multiple projects having cross-references
- public void resynch() {
- if (disposing || ! filled) return;
-
- if (! this.resynching) {
- this.resynching = true;
- this.needsToResynch = false;
- this.resynchJob.schedule();
- }
- else {
- this.needsToResynch = true;
- if (this.resynchJob.getState() == Job.RUNNING) {
- this.resynchJob.cancel();
- }
- }
+
+ // ********** auto-discovery **********
+
+ public boolean discoversAnnotatedClasses() {
+ return this.discoversAnnotatedClasses;
}
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- @Override
- public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
- switch (featureID) {
- case JpaCorePackage.JPA_PROJECT__DATA_SOURCE :
- return basicSetDataSource(null, msgs);
- case JpaCorePackage.JPA_PROJECT__FILES :
- return ((InternalEList<?>) getFiles()).basicRemove(otherEnd, msgs);
- }
- return super.eInverseRemove(otherEnd, featureID, msgs);
+ public void setDiscoversAnnotatedClasses(boolean discoversAnnotatedClasses) {
+ boolean old = this.discoversAnnotatedClasses;
+ this.discoversAnnotatedClasses = discoversAnnotatedClasses;
+ this.firePropertyChanged(DISCOVERS_ANNOTATED_CLASSES_PROPERTY, old, discoversAnnotatedClasses);
}
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- @Override
- public Object eGet(int featureID, boolean resolve, boolean coreType) {
- switch (featureID) {
- case JpaCorePackage.JPA_PROJECT__PLATFORM :
- return getPlatform();
- case JpaCorePackage.JPA_PROJECT__DATA_SOURCE :
- return getDataSource();
- case JpaCorePackage.JPA_PROJECT__DISCOVER_ANNOTATED_CLASSES :
- return isDiscoverAnnotatedClasses() ? Boolean.TRUE : Boolean.FALSE;
- case JpaCorePackage.JPA_PROJECT__FILES :
- return getFiles();
+
+ // ********** dispose **********
+
+ public void dispose() {
+ this.updateJpaProjectJobScheduler.dispose();
+ // use clone iterator while deleting JPA files
+ for (Iterator<IJpaFile> stream = this.jpaFiles(); stream.hasNext(); ) {
+ this.removeJpaFile(stream.next());
}
- return super.eGet(featureID, resolve, coreType);
+ this.dataSource.dispose();
}
- /**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
- */
- @SuppressWarnings("unchecked")
- @Override
- public void eSet(int featureID, Object newValue) {
- switch (featureID) {
- case JpaCorePackage.JPA_PROJECT__PLATFORM :
- setPlatform((IJpaPlatform) newValue);
- return;
- case JpaCorePackage.JPA_PROJECT__DATA_SOURCE :
- setDataSource((IJpaDataSource) newValue);
- return;
- case JpaCorePackage.JPA_PROJECT__DISCOVER_ANNOTATED_CLASSES :
- setDiscoverAnnotatedClasses(((Boolean) newValue).booleanValue());
- return;
- case JpaCorePackage.JPA_PROJECT__FILES :
- getFiles().clear();
- getFiles().addAll((Collection<? extends IJpaFile>) newValue);
- return;
- }
- super.eSet(featureID, newValue);
+
+ // ********** handling resource deltas **********
+
+ public void checkForAddedOrRemovedJpaFiles(IResourceDelta delta) throws CoreException {
+ delta.accept(this.resourceDeltaVisitor);
}
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
+ * resource delta visitor callback
*/
- @Override
- public void eUnset(int featureID) {
- switch (featureID) {
- case JpaCorePackage.JPA_PROJECT__PLATFORM :
- setPlatform((IJpaPlatform) null);
- return;
- case JpaCorePackage.JPA_PROJECT__DATA_SOURCE :
- setDataSource((IJpaDataSource) null);
- return;
- case JpaCorePackage.JPA_PROJECT__DISCOVER_ANNOTATED_CLASSES :
- unsetDiscoverAnnotatedClasses();
- return;
- case JpaCorePackage.JPA_PROJECT__FILES :
- getFiles().clear();
- return;
+ protected void synchronizeJpaFiles(IFile file, int deltaKind) {
+ switch (deltaKind) {
+ case IResourceDelta.ADDED :
+ if ( ! this.containsJpaFile(file)) {
+ this.addJpaFile(file);
+ }
+ break;
+ case IResourceDelta.REMOVED :
+ IJpaFile jpaFile = this.jpaFile(file);
+ if (jpaFile != null) {
+ this.removeJpaFile(jpaFile);
+ }
+ break;
+ case IResourceDelta.CHANGED :
+ case IResourceDelta.ADDED_PHANTOM :
+ case IResourceDelta.REMOVED_PHANTOM :
+ default :
+ break; // only worried about added and removed files
}
- super.eUnset(featureID);
}
+ // ***** inner class
/**
- * <!-- begin-user-doc -->
- * <!-- end-user-doc -->
- * @generated
+ * add a JPA file for every [appropriate] file encountered by the visitor
*/
- @Override
- public boolean eIsSet(int featureID) {
- switch (featureID) {
- case JpaCorePackage.JPA_PROJECT__PLATFORM :
- return platform != null;
- case JpaCorePackage.JPA_PROJECT__DATA_SOURCE :
- return dataSource != null;
- case JpaCorePackage.JPA_PROJECT__DISCOVER_ANNOTATED_CLASSES :
- return isSetDiscoverAnnotatedClasses();
- case JpaCorePackage.JPA_PROJECT__FILES :
- return files != null && !files.isEmpty();
+ protected class ResourceDeltaVisitor implements IResourceDeltaVisitor {
+ protected ResourceDeltaVisitor() {
+ super();
+ }
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ IResource res = delta.getResource();
+ switch (res.getType()) {
+ case IResource.ROOT :
+ case IResource.PROJECT :
+ case IResource.FOLDER :
+ return true; // visit children
+ case IResource.FILE :
+ JpaProject.this.synchronizeJpaFiles((IFile) res, delta.getKind());
+ return false; // no children
+ default :
+ return false; // no children
+ }
}
- return super.eIsSet(featureID);
}
- @Override
- public String toString() {
- StringBuffer result = new StringBuffer(super.toString());
- result.append(" (" + getProject().toString() + ")");
- return result.toString();
- }
- @Override
- public ConnectionProfile connectionProfile() {
- String profileName = getDataSource().getConnectionProfileName();
- return JptDbPlugin.getDefault().getConnectionProfileRepository().profileNamed(profileName);
- }
+ // ********** support for modifying documents shared with the UI **********
- public CommandExecutor getThreadLocalModifySharedDocumentCommandExecutor() {
- CommandExecutor commandExecutor = this.threadLocalModifySharedDocumentCommandExecutor.get();
- return (commandExecutor != null) ? commandExecutor : CommandExecutor.Default.instance();
+ /**
+ * If there is no thread-specific command executor, use the default
+ * implementation, which simply executes the command directly.
+ */
+ protected CommandExecutor threadLocalModifySharedDocumentCommandExecutor() {
+ CommandExecutor ce = this.threadLocalModifySharedDocumentCommandExecutor.get();
+ return (ce != null) ? ce : CommandExecutor.Default.instance();
}
public void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor) {
@@ -860,24 +471,126 @@ public class JpaProject extends JpaEObject implements IJpaProject
}
public CommandExecutorProvider modifySharedDocumentCommandExecutorProvider() {
- if (this.modifySharedDocumentCommandExecutorProvider == null) {
- this.modifySharedDocumentCommandExecutorProvider = new ModifySharedDocumentCommandExecutorProvider();
- }
return this.modifySharedDocumentCommandExecutorProvider;
}
-
-
- // ********** member class **********
-
- private class ModifySharedDocumentCommandExecutorProvider
- implements CommandExecutorProvider
- {
- ModifySharedDocumentCommandExecutorProvider() {
+
+ // ***** inner class
+ protected class ModifySharedDocumentCommandExecutorProvider implements CommandExecutorProvider {
+ protected ModifySharedDocumentCommandExecutorProvider() {
super();
}
-
public CommandExecutor commandExecutor() {
- return JpaProject.this.getThreadLocalModifySharedDocumentCommandExecutor();
+ return JpaProject.this.threadLocalModifySharedDocumentCommandExecutor();
+ }
+ }
+
+
+
+ // ********** update project **********
+
+ public IStatus update(IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+
+ try {
+ IContext contextHierarchy = this.jpaPlatform.buildProjectContext();
+ this.jpaPlatform.resynch(contextHierarchy, monitor);
+ } catch (OperationCanceledException ex) {
+ return Status.CANCEL_STATUS;
+ } catch (Throwable ex) {
+ //exceptions can occur when this thread is running and changes are
+ //made to the java source. our model is not yet updated to the changed java source.
+ //log these exceptions and assume they won't happen when the resynch runs again
+ //as a result of the java source changes.
+ JptCorePlugin.log(ex);
+ }
+ return Status.OK_STATUS;
+ }
+
+ public void update() {
+ this.updateJpaProjectJobScheduler.schedule();
+ }
+
+ protected static class UpdateJpaProjectJobScheduler {
+ /**
+ * The job is built during construction and cleared out during dispose.
+ * All the "public" methods check to make sure the job is not null,
+ * doing nothing if it is (preventing anything from happening after
+ * dispose).
+ */
+ protected Job job;
+
+ protected UpdateJpaProjectJobScheduler(IJpaProject jpaProject, ISchedulingRule rule) {
+ super();
+ this.job = this.buildJob(jpaProject, rule);
+ }
+
+ protected Job buildJob(IJpaProject jpaProject, ISchedulingRule rule) {
+ Job j = new UpdateJpaProjectJob(jpaProject);
+ j.setRule(rule);
+ return j;
}
+
+ /**
+ * Stop the job if it is currently running, reschedule it to
+ * run again, and return without waiting.
+ */
+ protected synchronized void schedule() {
+ if (this.job != null) {
+ this.job.cancel();
+ this.job.schedule();
+ }
+ }
+
+ /**
+ * Stop the job if it is currently running, reschedule it to
+ * run again, and wait until it is finished.
+ */
+ protected synchronized void scheduleAndWait() {
+ if (this.job != null) {
+ this.job.cancel();
+ this.join();
+ this.job.schedule();
+ this.join();
+ }
+ }
+
+ /**
+ * Stop the job if it is currently running, wait until
+ * it is finished, then clear the job out so it cannot
+ * be scheduled again.
+ */
+ protected synchronized void dispose() {
+ if (this.job != null) {
+ this.job.cancel();
+ this.join();
+ this.job = null;
+ }
+ }
+
+ protected synchronized void join() {
+ try {
+ this.job.join();
+ } catch (InterruptedException ex) {
+ // the thread was interrupted while waiting, job must be finished
+ }
+ }
+
+ protected static class UpdateJpaProjectJob extends Job {
+ protected final IJpaProject jpaProject;
+
+ protected UpdateJpaProjectJob(IJpaProject jpaProject) {
+ super("Update JPA project"); // TODO i18n
+ this.jpaProject = jpaProject;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ return this.jpaProject.update(monitor);
+ }
+
+ }
+
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProjectAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProjectAdapterFactory.java
index 27713e4bcb..ae02bab4db 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProjectAdapterFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProjectAdapterFactory.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 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
- *******************************************************************************/
+ * Copyright (c) 2005, 2007 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 org.eclipse.core.resources.IProject;
@@ -37,6 +37,6 @@ public class JpaProjectAdapterFactory
return null;
}
- return JptCorePlugin.getJpaProject(project);
+ return JptCorePlugin.jpaProject(project);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCorePlugin.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCorePlugin.java
index eafe676c29..d42ed1232c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCorePlugin.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCorePlugin.java
@@ -11,106 +11,301 @@ package org.eclipse.jpt.core.internal;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.jpt.core.internal.platform.generic.GenericPlatform;
+import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
import org.osgi.framework.BundleContext;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * The JPT plug-in lifecycle implementation.
+ * A number of globally-available constants and methods.
+ */
+// TODO keep preferences in synch with the JPA project
+// (connection profile name, "discover" flag)
+// use listeners?
+public class JptCorePlugin extends Plugin {
+
+
+ // ********** public constants **********
-public class JptCorePlugin extends Plugin
-{
- private static JptCorePlugin INSTANCE;
-
/**
* The plug-in identifier of the persistence support
* (value <code>"org.eclipse.jpt.core"</code>).
*/
public static final String PLUGIN_ID = "org.eclipse.jpt.core"; //$NON-NLS-1$
-
+
/**
* The identifier for the JPA facet
* (value <code>"jpt.jpa"</code>).
*/
public static final String FACET_ID = "jpt.jpa"; //$NON-NLS-1$
-
+
+ /**
+ * The key for storing a JPA project's platform in the Eclipse
+ * project's preferences.
+ */
+ public static final String JPA_PLATFORM = PLUGIN_ID + ".platform"; //$NON-NLS-1$
+
+ /**
+ * The key for storing a JPA project's "discover" flag in the Eclipse
+ * project's preferences.
+ */
+ public static final String DISCOVER_ANNOTATED_CLASSES = PLUGIN_ID + ".discoverAnnotatedClasses"; //$NON-NLS-1$
+
+ /**
+ * The key for storing a JPA project's data source connection profile name
+ * in the Eclipse project's persistent property's.
+ */
+ public static final QualifiedName DATA_SOURCE_CONNECTION_PROFILE_NAME =
+ new QualifiedName(PLUGIN_ID, "dataSource.connectionProfileName"); //$NON-NLS-1$
+
/**
* The identifier for the JPA validation marker
* (value <code>"org.eclipse.jpt.core.jpaProblemMarker"</code>).
*/
- public static final String VALIDATION_MARKER_ID = PLUGIN_ID + ".jpaProblemMarker";
-
+ public static final String VALIDATION_MARKER_ID = PLUGIN_ID + ".jpaProblemMarker"; //$NON-NLS-1$
+
/**
* Value of the content-type for orm.xml mappings files. Use this value to retrieve
- * the ORM xml content type from the content type manager, and to add new
+ * the ORM xml content type from the content type manager and to add new
* orm.xml-like extensions to this content type.
*
* @see org.eclipse.core.runtime.content.IContentTypeManager#getContentType(String)
*/
public static final String ORM_XML_CONTENT_TYPE = PLUGIN_ID + ".content.orm"; //$NON-NLS-1$
-
+
+ /**
+ * Ditto for persistence.xml.
+ * @see #ORM_XML_CONTENT_TYPE
+ */
public static final String PERSISTENCE_XML_CONTENT_TYPE = PLUGIN_ID + ".content.persistence"; //$NON-NLS-1$
- public static final String JAVA_CONTENT_TYPE = JavaCore.JAVA_SOURCE_CONTENT_TYPE;
+ /**
+ * Web projects have some special exceptions.
+ */
+ @SuppressWarnings("restriction")
+ public static final String WEB_PROJECT_FACET_ID = org.eclipse.wst.common.componentcore.internal.util.IModuleConstants.JST_WEB_MODULE;
/**
- * Return the current workspace's model manager.
+ * Web projects have some special exceptions.
*/
- private static JpaModelManager modelManager() {
- return JpaModelManager.instance();
+ @SuppressWarnings("restriction")
+ public static final String WEB_PROJECT_DEPLOY_PREFIX = org.eclipse.jst.j2ee.internal.J2EEConstants.WEB_INF_CLASSES;
+
+ public static final String DEFAULT_PERSISTENCE_XML_FILE_PATH = "META-INF/persistence.xml";
+
+ public static final String DEFAULT_ORM_XML_FILE_PATH = "META-INF/orm.xml";
+
+
+ // ********** singleton **********
+
+ private static JptCorePlugin INSTANCE;
+
+ /**
+ * Return the singleton JPA plug-in.
+ */
+ public static JptCorePlugin instance() {
+ return INSTANCE;
}
-
+
+
+ // ********** public static methods **********
+
/**
- * Returns the singular IJpaModel corresponding to the current workspace.
- *
- * @return the singular IJpaModel corresponding to the current workspace.
+ * Return the singular JPA model corresponding to the current workspace.
*/
- public static IJpaModel getJpaModel() {
- return modelManager().getJpaModel();
+ public static IJpaModel jpaModel() {
+ return JpaModelManager.instance().jpaModel();
}
-
+
/**
- * Returns the IJpaProject corresponding to the given IProject,
- * or <code>null</code> if unable to associate the given project with an
- * IJpaProject.
- *
- * @param project the given project
- * @return the IJpaProject corresponding to the given project,
- * or <code>null</code> if unable to associate the given project with an
- * IJpaProject
+ * Return the JPA project corresponding to the specified Eclipse project,
+ * or null if unable to associate the specified project with a
+ * JPA project.
*/
- public static IJpaProject getJpaProject(IProject project) {
- return modelManager().getJpaProject(project);
+ public static IJpaProject jpaProject(IProject project) {
+ try {
+ return JpaModelManager.instance().jpaProject(project);
+ } catch (CoreException ex) {
+ log(ex);
+ return null;
+ }
}
-
+
/**
- * Returns the IJpaFile corresponding to the given IFile,
- * or <code>null</code> if unable to associate the given file with an
- * IJpaFile.
- *
- * @param file the given file
- * @return the IJpaFile corresponding to the given file,
- * or <code>null</code> if unable to associate the given file with an
- * IJpaFile
+ * Return the JPA file corresponding to the specified Eclipse file,
+ * or null if unable to associate the specified file with a JPA file.
*/
- public static IJpaFile getJpaFile(IFile file) {
- return modelManager().getJpaFile(file);
+ public static IJpaFile jpaFile(IFile file) {
+ try {
+ return JpaModelManager.instance().jpaFile(file);
+ } catch (CoreException ex) {
+ log(ex);
+ return null;
+ }
}
-
+
/**
- * Returns the singleton DaliPlugin
+ * Return whether the specified Eclipse project has a JPA facet.
*/
- public static JptCorePlugin getPlugin() {
- return INSTANCE;
+ public static boolean projectHasJpaFacet(IProject project) {
+ return projectHasFacet(project, FACET_ID);
+ }
+
+ /**
+ * Return whether the specified Eclipse project has a JPA facet.
+ */
+ public static boolean projectHasWebFacet(IProject project) {
+ return projectHasFacet(project, WEB_PROJECT_FACET_ID);
+ }
+
+ /**
+ * Checked exceptions bite.
+ */
+ private static boolean projectHasFacet(IProject project, String facetId) {
+ try {
+ return FacetedProjectFramework.hasProjectFacet(project, facetId);
+ } catch (CoreException ex) {
+ log(ex); // problems reading the project metadata - assume facet doesn't exist - return 'false'
+ return false;
+ }
+ }
+
+ /**
+ * Return the persistence.xml deployment URI for the specified project.
+ */
+ public static String persistenceXmlDeploymentURI(IProject project) {
+ return deploymentURI(project, DEFAULT_PERSISTENCE_XML_FILE_PATH);
+ }
+
+ /**
+ * Return the orm.xml deployment URI for the specified project.
+ */
+ public static String ormXmlDeploymentURI(IProject project) {
+ return deploymentURI(project, DEFAULT_ORM_XML_FILE_PATH);
+ }
+
+ /**
+ * Tweak the specified deployment URI if the specified project
+ * has a web facet.
+ */
+ private static String deploymentURI(IProject project, String defaultURI) {
+ return projectHasWebFacet(project) ?
+ WEB_PROJECT_DEPLOY_PREFIX + "/" + defaultURI
+ :
+ defaultURI;
+ }
+
+ /**
+ * Return the JPA preferences for the specified Eclipse project.
+ */
+ public static IEclipsePreferences preferences(IProject project) {
+ IScopeContext context = new ProjectScope(project);
+ return context.getNode(PLUGIN_ID);
+ }
+
+ /**
+ * Return the JPA platform associated with the specified Eclipse project.
+ */
+ public static IJpaPlatform jpaPlatform(IProject project) {
+ return JpaPlatformRegistry.instance().jpaPlatform(jpaPlatformId(project));
}
-
+
+ /**
+ * Return the JPA platform ID associated with the specified Eclipse project.
+ */
+ public static String jpaPlatformId(IProject project) {
+ return preferences(project).get(JPA_PLATFORM, GenericPlatform.ID);
+ }
+
+ /**
+ * Set the JPA platform ID associated with the specified Eclipse project.
+ */
+ public static void setJpaPlatformId(IProject project, String jpaPlatformId) {
+ IEclipsePreferences prefs = preferences(project);
+ prefs.put(JPA_PLATFORM, jpaPlatformId);
+ flush(prefs);
+ }
+
+ /**
+ * Return the JPA "discover" flag associated with the specified
+ * Eclipse project.
+ */
+ public static boolean discoverAnnotatedClasses(IProject project) {
+ return preferences(project).getBoolean(DISCOVER_ANNOTATED_CLASSES, false);
+ }
+
+ /**
+ * Set the JPA "discover" flag associated with the specified
+ * Eclipse project.
+ */
+ public static void setDiscoverAnnotatedClasses(IProject project, boolean discoverAnnotatedClasses) {
+ IEclipsePreferences prefs = preferences(project);
+ prefs.putBoolean(DISCOVER_ANNOTATED_CLASSES, discoverAnnotatedClasses);
+ flush(prefs);
+ }
+
+ /**
+ * checked exceptions bite
+ */
+ private static void flush(IEclipsePreferences prefs) {
+ try {
+ prefs.flush();
+ } catch(BackingStoreException ex) {
+ log(ex);
+ }
+ }
+
+ /**
+ * Return the name of the connection profile associated with the specified
+ * Eclipse project.
+ */
+ public static String connectionProfileName(IProject project) {
+ try {
+ return project.getPersistentProperty(DATA_SOURCE_CONNECTION_PROFILE_NAME);
+ } catch (CoreException ex) {
+ log(ex);
+ return null;
+ }
+ }
+
+ /**
+ * Set the name of the connection profile associated with the specified
+ * Eclipse project.
+ */
+ public static void setConnectionProfileName(IProject project, String connectionProfileName) {
+ try {
+ project.setPersistentProperty(DATA_SOURCE_CONNECTION_PROFILE_NAME, connectionProfileName);
+ } catch (CoreException ex) {
+ log(ex);
+ }
+ }
+
+ /**
+ * Log the specified status.
+ */
public static void log(IStatus status) {
INSTANCE.getLog().log(status);
}
-
+
+ /**
+ * Log the specified message.
+ */
public static void log(String msg) {
log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, null));
}
-
+
+ /**
+ * Log the specified exception or error.
+ */
public static void log(Throwable throwable) {
log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, throwable.getLocalizedMessage(), throwable));
}
@@ -123,22 +318,22 @@ public class JptCorePlugin extends Plugin
if (INSTANCE != null) {
throw new IllegalStateException();
}
+ // this convention is *wack*... ~bjv
INSTANCE = this;
}
-
-
+
+
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
- modelManager().start();
+ JpaModelManager.instance().start();
}
-
+
@Override
public void stop(BundleContext context) throws Exception {
try {
- modelManager().stop();
- }
- finally {
+ JpaModelManager.instance().stop();
+ } finally {
super.stop(context);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleJpaProjectConfig.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleJpaProjectConfig.java
new file mode 100644
index 0000000000..51bba1d242
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleJpaProjectConfig.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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 org.eclipse.core.resources.IProject;
+import org.eclipse.jpt.core.internal.IJpaProject;
+
+/**
+ * Straightforward implementation of the JPA project config.
+ */
+public class SimpleJpaProjectConfig implements IJpaProject.Config {
+ protected IProject project;
+ protected IJpaPlatform jpaPlatform;
+ protected String connectionProfileName;
+ protected boolean discoverAnnotatedClasses;
+
+ public SimpleJpaProjectConfig() {
+ super();
+ }
+
+ public IProject project() {
+ return this.project;
+ }
+
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+
+ public IJpaPlatform jpaPlatform() {
+ return this.jpaPlatform;
+ }
+
+ public void setJpaPlatform(IJpaPlatform jpaPlatform) {
+ this.jpaPlatform = jpaPlatform;
+ }
+
+ public String connectionProfileName() {
+ return this.connectionProfileName;
+ }
+
+ public void setConnectionProfileName(String connectionProfileName) {
+ this.connectionProfileName = connectionProfileName;
+ }
+
+ public boolean discoverAnnotatedClasses() {
+ return this.discoverAnnotatedClasses;
+ }
+
+ public void setDiscoverAnnotatedClasses(boolean discoverAnnotatedClasses) {
+ this.discoverAnnotatedClasses = discoverAnnotatedClasses;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaJpaFileContentProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaJpaFileContentProvider.java
index 3aaed9b6c1..a50fe76ecc 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaJpaFileContentProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaJpaFileContentProvider.java
@@ -9,10 +9,10 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.content.java;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jpt.core.internal.IJpaFile;
import org.eclipse.jpt.core.internal.IJpaFileContentProvider;
import org.eclipse.jpt.core.internal.IJpaRootContentNode;
-import org.eclipse.jpt.core.internal.JptCorePlugin;
public class JavaJpaFileContentProvider implements IJpaFileContentProvider
{
@@ -41,6 +41,6 @@ public class JavaJpaFileContentProvider implements IJpaFileContentProvider
}
public String contentType() {
- return JptCorePlugin.JAVA_CONTENT_TYPE;
+ return JavaCore.JAVA_SOURCE_CONTENT_TYPE;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java
index 85f5b9e758..99167b12c2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JpaCompilationUnit.java
@@ -332,7 +332,7 @@ public class JpaCompilationUnit extends JavaEObject
Type type = new Type(primaryType, this.modifySharedDocumentCommandExecutorProvider());
return JpaJavaFactory.eINSTANCE.createJavaPersistentType(type);
}
-
+
/**
* delegate to the type's project (there is one provider per project)
*/
@@ -353,8 +353,8 @@ public class JpaCompilationUnit extends JavaEObject
return this;
}
- public void handleJavaElementChangedEvent(ElementChangedEvent event) {
- synchWithJavaDelta(event.getDelta());
+ public void javaElementChanged(ElementChangedEvent event) {
+ this.synchWithJavaDelta(event.getDelta());
}
private void synchWithJavaDelta(IJavaElementDelta delta) {
@@ -363,7 +363,7 @@ public class JpaCompilationUnit extends JavaEObject
case IJavaElement.JAVA_PROJECT :
case IJavaElement.PACKAGE_FRAGMENT_ROOT :
case IJavaElement.PACKAGE_FRAGMENT :
- this.synchChildrenWithJavaDelta(delta);
+ this.synchWithJavaDelta(delta.getAffectedChildren()); // recurse
break;
case IJavaElement.COMPILATION_UNIT :
this.synchCompilationUnitWithJavaDelta(delta);
@@ -373,9 +373,9 @@ public class JpaCompilationUnit extends JavaEObject
}
}
- private void synchChildrenWithJavaDelta(IJavaElementDelta delta) {
- for (IJavaElementDelta child : delta.getAffectedChildren()) {
- this.synchWithJavaDelta(child); // recurse
+ private void synchWithJavaDelta(IJavaElementDelta[] deltas) {
+ for (IJavaElementDelta delta : deltas) {
+ this.synchWithJavaDelta(delta); // recurse
}
}
@@ -388,7 +388,7 @@ public class JpaCompilationUnit extends JavaEObject
}
// synchronize if the change is for this compilation unit
if (delta.getElement().equals(this.compilationUnit)) {
- this.synchronizePersistentTypes();
+ this.synchronizePersistentTypes(); // ignore the delta
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsAdapterFactory.java
index 5b7ceea44e..21f8a49103 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsAdapterFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsAdapterFactory.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -21,6 +21,7 @@ import org.eclipse.jpt.core.internal.JpaEObject;
import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMapping;
import org.eclipse.jpt.core.internal.content.java.IJavaTypeMapping;
import org.eclipse.jpt.core.internal.content.java.JavaEObject;
+import org.eclipse.jpt.core.internal.content.java.mappings.*;
import org.eclipse.jpt.core.internal.content.java.mappings.AbstractJavaColumn;
import org.eclipse.jpt.core.internal.content.java.mappings.AbstractJavaTable;
import org.eclipse.jpt.core.internal.content.java.mappings.IJavaBasic;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsSwitch.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsSwitch.java
index a0c485a2b8..b977fa63f0 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsSwitch.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/util/JpaJavaMappingsSwitch.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -20,6 +20,7 @@ import org.eclipse.jpt.core.internal.JpaEObject;
import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMapping;
import org.eclipse.jpt.core.internal.content.java.IJavaTypeMapping;
import org.eclipse.jpt.core.internal.content.java.JavaEObject;
+import org.eclipse.jpt.core.internal.content.java.mappings.*;
import org.eclipse.jpt.core.internal.content.java.mappings.AbstractJavaColumn;
import org.eclipse.jpt.core.internal.content.java.mappings.AbstractJavaTable;
import org.eclipse.jpt.core.internal.content.java.mappings.IJavaBasic;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaAdapterFactory.java
index 967ddb80f9..ad9e1f3d73 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaAdapterFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaAdapterFactory.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -22,6 +22,7 @@ import org.eclipse.jpt.core.internal.IPersistentAttribute;
import org.eclipse.jpt.core.internal.IPersistentType;
import org.eclipse.jpt.core.internal.ITypeMapping;
import org.eclipse.jpt.core.internal.JpaEObject;
+import org.eclipse.jpt.core.internal.content.java.*;
import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMapping;
import org.eclipse.jpt.core.internal.content.java.IJavaTypeMapping;
import org.eclipse.jpt.core.internal.content.java.JavaEObject;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaSwitch.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaSwitch.java
index a59d2f871d..ff7519cdd1 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaSwitch.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/util/JpaJavaSwitch.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -21,6 +21,7 @@ import org.eclipse.jpt.core.internal.IPersistentAttribute;
import org.eclipse.jpt.core.internal.IPersistentType;
import org.eclipse.jpt.core.internal.ITypeMapping;
import org.eclipse.jpt.core.internal.JpaEObject;
+import org.eclipse.jpt.core.internal.content.java.*;
import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMapping;
import org.eclipse.jpt.core.internal.content.java.IJavaTypeMapping;
import org.eclipse.jpt.core.internal.content.java.JavaEObject;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/EntityMappingsInternal.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/EntityMappingsInternal.java
index 7d9d5173fb..e121f32b02 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/EntityMappingsInternal.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/EntityMappingsInternal.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -1614,10 +1614,9 @@ public class EntityMappingsInternal extends XmlEObject
return this;
}
- public void handleJavaElementChangedEvent(ElementChangedEvent event) {
- for (Iterator i = getTypeMappings().iterator(); i.hasNext();) {
- XmlTypeMapping mapping = (XmlTypeMapping) i.next();
- //mapping.javaElementChanged(event);
+ public void javaElementChanged(ElementChangedEvent event) {
+ for (XmlTypeMapping typeMapping : this.getTypeMappings()) {
+ //typeMapping.javaElementChanged(event);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPersistentType.java
index 3ccedd5d5e..c5756c863d 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPersistentType.java
@@ -30,6 +30,7 @@ import org.eclipse.jpt.core.internal.IJpaContentNode;
import org.eclipse.jpt.core.internal.IJpaFile;
import org.eclipse.jpt.core.internal.IPersistentAttribute;
import org.eclipse.jpt.core.internal.IPersistentType;
+import org.eclipse.jpt.core.internal.ITypeMapping;
import org.eclipse.jpt.core.internal.ITextRange;
import org.eclipse.jpt.core.internal.JpaCorePackage;
import org.eclipse.jpt.core.internal.JptCorePlugin;
@@ -726,7 +727,7 @@ public class XmlPersistentType extends XmlEObject implements IPersistentType
};
while (name[0].length() != 0) {
name = moveDot(name);
- IType type = JDTTools.findType(name[0], name[1], getJpaProject().getJavaProject());
+ IType type = JDTTools.findType(name[0], name[1], getJpaProject().javaProject());
if (type != null)
return type;
}
@@ -766,17 +767,7 @@ public class XmlPersistentType extends XmlEObject implements IPersistentType
}
public JavaPersistentType findJavaPersistentType() {
- IType iType = findJdtType();
- if (iType != null) {
- for (IJpaFile jpaFile : getJpaProject().jpaFiles(JptCorePlugin.JAVA_CONTENT_TYPE)) {
- for (JavaPersistentType javaPersistentType : ((JpaCompilationUnit) jpaFile.getContent()).getTypes()) {
- if (javaPersistentType.jdtType().equals(iType)) {
- return javaPersistentType;
- }
- }
- }
- }
- return null;
+ return this.getJpaProject().javaPersistentType(this.findJdtType());
}
public Type findType() {
@@ -901,8 +892,6 @@ public class XmlPersistentType extends XmlEObject implements IPersistentType
public ITextRange attributesTextRange() {
return getMapping().attributesTextRange();
}
-
-
private abstract class AttributeMappingsList<E>
extends EObjectContainmentEList<XmlAttributeMapping>
{
@@ -946,8 +935,6 @@ public class XmlPersistentType extends XmlEObject implements IPersistentType
persistentAttributes().set(index, newObject.getPersistentAttribute());
}
}
-
-
private class SpecifiedAttributeMappingsList<E>
extends AttributeMappingsList<XmlAttributeMapping>
{
@@ -960,8 +947,6 @@ public class XmlPersistentType extends XmlEObject implements IPersistentType
return getSpecifiedPersistentAttributes();
}
}
-
-
private class VirtualAttributeMappingsList<E>
extends AttributeMappingsList<XmlAttributeMapping>
{
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRootContentNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRootContentNode.java
index 3edd7d6e2d..2220ba662b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRootContentNode.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlRootContentNode.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 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
+ * Copyright (c) 2006, 2007 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
- *******************************************************************************/
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal.content.orm;
import org.eclipse.core.resources.IResource;
@@ -100,6 +101,7 @@ public class XmlRootContentNode extends XmlEObject
return (IJpaFile) eContainer();
}
+ @Override
public IResource getResource() {
return getJpaFile().getResource();
}
@@ -347,16 +349,12 @@ public class XmlRootContentNode extends XmlEObject
return getEntityMappings().getContentNode(offset);
}
- /* (non-Javadoc)
- *
- * @see IJpaRootContentNode#handleJavaElementChangedEvent(ElementChangedEvent)
- */
- public void handleJavaElementChangedEvent(ElementChangedEvent event) {
- if (getEntityMappings() != null) {
- getEntityMappings().handleJavaElementChangedEvent(event);
+ public void javaElementChanged(ElementChangedEvent event) {
+ if (this.entityMappings != null) {
+ this.entityMappings.javaElementChanged(event);
}
}
-
+
public void setResource(OrmResource ormResource) {
resource = ormResource;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmAdapterFactory.java
index 2e42c3c2dd..02ee466642 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmAdapterFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmAdapterFactory.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -24,6 +24,7 @@ import org.eclipse.jpt.core.internal.ITypeMapping;
import org.eclipse.jpt.core.internal.IXmlEObject;
import org.eclipse.jpt.core.internal.JpaEObject;
import org.eclipse.jpt.core.internal.XmlEObject;
+import org.eclipse.jpt.core.internal.content.orm.*;
import org.eclipse.jpt.core.internal.content.orm.AbstractXmlColumn;
import org.eclipse.jpt.core.internal.content.orm.AbstractXmlNamedColumn;
import org.eclipse.jpt.core.internal.content.orm.AbstractXmlQuery;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmSwitch.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmSwitch.java
index 1a24e6d3ba..dfc56fe446 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmSwitch.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/util/OrmSwitch.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -23,6 +23,7 @@ import org.eclipse.jpt.core.internal.ITypeMapping;
import org.eclipse.jpt.core.internal.IXmlEObject;
import org.eclipse.jpt.core.internal.JpaEObject;
import org.eclipse.jpt.core.internal.XmlEObject;
+import org.eclipse.jpt.core.internal.content.orm.*;
import org.eclipse.jpt.core.internal.content.orm.AbstractXmlColumn;
import org.eclipse.jpt.core.internal.content.orm.AbstractXmlNamedColumn;
import org.eclipse.jpt.core.internal.content.orm.AbstractXmlQuery;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java
index c99506262d..834c62bbe9 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/JavaClassRef.java
@@ -118,7 +118,7 @@ public class JavaClassRef extends XmlEObject
int dotIndex = fqClassName.lastIndexOf('.');
String packageName = (dotIndex >= 0) ? fqClassName.substring(0, dotIndex) : "";
String className = (dotIndex >= 0) ? fqClassName.substring(dotIndex + 1, fqClassName.length()) : fqClassName;
- return JDTTools.findType(packageName, className, getJpaProject().getJavaProject());
+ return JDTTools.findType(packageName, className, getJpaProject().javaProject());
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java
index e6260ae408..890bd48c7a 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/MappingFileRef.java
@@ -198,13 +198,13 @@ public class MappingFileRef extends XmlEObject
public IJpaFile getMappingFile() {
// check flexible project structure
- IVirtualComponent component = ComponentCore.createComponent(getJpaProject().getProject());
+ IVirtualComponent component = ComponentCore.createComponent(getJpaProject().project());
IVirtualFolder virtualRootFolder = component.getRootFolder();
IVirtualFile virtualMappingFile = virtualRootFolder.getFile(new Path(getJpaProject().rootDeployLocation() + '/' + fileName));
// keep track of whether one has been found so that we may know if multiple exist
IJpaFile mappingFile = null;
for (IFile underlyingFile : virtualMappingFile.getUnderlyingFiles()) {
- IJpaFile jpaFile = JptCorePlugin.getJpaFile(underlyingFile);
+ IJpaFile jpaFile = JptCorePlugin.jpaFile(underlyingFile);
if (jpaFile != null) {
if (mappingFile != null) {
return null; // multiple do exist
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/PersistenceXmlRootContentNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/PersistenceXmlRootContentNode.java
index a8ea6c36d2..ef6717fa62 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/PersistenceXmlRootContentNode.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/PersistenceXmlRootContentNode.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -364,7 +364,7 @@ public class PersistenceXmlRootContentNode extends XmlEObject
return IPersistenceXmlContentNodes.PERSISTENCEXML_ROOT_ID;
}
- public void handleJavaElementChangedEvent(ElementChangedEvent event) {
+ public void javaElementChanged(ElementChangedEvent event) {
// TODO Auto-generated method stub
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceAdapterFactory.java
index 3c41f5b943..f6d8aa2642 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceAdapterFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceAdapterFactory.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -20,6 +20,7 @@ import org.eclipse.jpt.core.internal.IJpaSourceObject;
import org.eclipse.jpt.core.internal.IXmlEObject;
import org.eclipse.jpt.core.internal.JpaEObject;
import org.eclipse.jpt.core.internal.XmlEObject;
+import org.eclipse.jpt.core.internal.content.persistence.*;
import org.eclipse.jpt.core.internal.content.persistence.JavaClassRef;
import org.eclipse.jpt.core.internal.content.persistence.MappingFileRef;
import org.eclipse.jpt.core.internal.content.persistence.Persistence;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceSwitch.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceSwitch.java
index d115ee55dd..767bce195c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceSwitch.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/persistence/util/PersistenceSwitch.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -19,6 +19,7 @@ import org.eclipse.jpt.core.internal.IJpaSourceObject;
import org.eclipse.jpt.core.internal.IXmlEObject;
import org.eclipse.jpt.core.internal.JpaEObject;
import org.eclipse.jpt.core.internal.XmlEObject;
+import org.eclipse.jpt.core.internal.content.persistence.*;
import org.eclipse.jpt.core.internal.content.persistence.JavaClassRef;
import org.eclipse.jpt.core.internal.content.persistence.MappingFileRef;
import org.eclipse.jpt.core.internal.content.persistence.Persistence;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/IJpaFacetDataModelProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/IJpaFacetDataModelProperties.java
index b9d61dabb1..64f3fb8255 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/IJpaFacetDataModelProperties.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/IJpaFacetDataModelProperties.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
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 4180fb0c51..fb6be34ed8 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
@@ -1,15 +1,14 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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.facet;
-import java.util.Arrays;
import java.util.Set;
import org.eclipse.core.runtime.IStatus;
@@ -20,13 +19,11 @@ import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.core.internal.platform.generic.GenericPlatform;
import org.eclipse.jpt.core.internal.prefs.JpaPreferenceConstants;
import org.eclipse.jpt.db.internal.ConnectionProfileRepository;
+import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider;
-import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonMessages;
-import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
@@ -35,14 +32,30 @@ public class JpaFacetDataModelProvider
extends FacetInstallDataModelProvider
implements IJpaFacetDataModelProperties
{
+ @SuppressWarnings("restriction")
+ private static final String EJB_FACET_ID = org.eclipse.wst.common.componentcore.internal.util.IModuleConstants.JST_EJB_MODULE;
+
+ @SuppressWarnings("restriction")
+ private static final String RUNTIME_NONE = org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin.getResourceString(org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonMessages.RUNTIME_NONE, null);
+
+ private static final IStatus PLATFORM_NOT_SPECIFIED_STATUS = buildErrorStatus(JptCoreMessages.VALIDATE_PLATFORM_NOT_SPECIFIED);
+ private static final IStatus CONNECTION_NOT_CONNECTED_STATUS = buildInfoStatus(JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED);
+ private static final IStatus RUNTIME_NOT_SPECIFIED_STATUS = buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_NOT_SPECIFIED);
+ private static final IStatus RUNTIME_DOES_NOT_SUPPORT_EJB_30_STATUS = buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30);
+ private static final IStatus LIBRARY_NOT_SPECIFIED_STATUS = buildWarningStatus(JptCoreMessages.VALIDATE_LIBRARY_NOT_SPECIFIED);
+
+ /**
+ * required default constructor
+ */
public JpaFacetDataModelProvider() {
super();
}
@Override
- public Set getPropertyNames() {
- Set propertyNames = super.getPropertyNames();
+ public Set<String> getPropertyNames() {
+ @SuppressWarnings("unchecked")
+ Set<String> propertyNames = super.getPropertyNames();
propertyNames.add(PLATFORM_ID);
propertyNames.add(CONNECTION);
propertyNames.add(RUNTIME);
@@ -55,54 +68,49 @@ public class JpaFacetDataModelProvider
@Override
public Object getDefaultProperty(String propertyName) {
- if (FACET_ID.equals(propertyName)) {
+ if (propertyName.equals(FACET_ID)) {
return JptCorePlugin.FACET_ID;
}
- else if (PLATFORM_ID.equals(propertyName)) {
+ if (propertyName.equals(PLATFORM_ID)) {
return GenericPlatform.ID;
}
- else if (CONNECTION.equals(propertyName)) {
+ if (propertyName.equals(CONNECTION)) {
return "";
}
- else if (RUNTIME.equals(propertyName)) {
+ if (propertyName.equals(RUNTIME)) {
return null;
}
- else if (USE_SERVER_JPA_IMPLEMENTATION.equals(propertyName)) {
- return runtimeSupportsEjb30(getRuntime());
+ if (propertyName.equals(USE_SERVER_JPA_IMPLEMENTATION)) {
+ return this.runtimeSupportsEjb30(this.runtime());
}
- else if (JPA_LIBRARY.equals(propertyName)) {
- return JptCorePlugin.getPlugin().getPluginPreferences()
- .getString(JpaPreferenceConstants.PREF_DEFAULT_JPA_LIB);
+ if (propertyName.equals(JPA_LIBRARY)) {
+ return JptCorePlugin.instance().getPluginPreferences().getString(JpaPreferenceConstants.PREF_DEFAULT_JPA_LIB);
}
- else if (DISCOVER_ANNOTATED_CLASSES.equals(propertyName)) {
- return runtimeSupportsEjb30(getRuntime());
+ if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) {
+ return runtimeSupportsEjb30(this.runtime());
}
- else if (CREATE_ORM_XML.equals(propertyName)) {
- return true;
- }
- else {
- return super.getDefaultProperty(propertyName);
+ if (propertyName.equals(CREATE_ORM_XML)) {
+ return Boolean.TRUE;
}
+ return super.getDefaultProperty(propertyName);
}
-
+
@Override
public boolean propertySet(String propertyName, Object propertyValue) {
boolean ok = super.propertySet(propertyName, propertyValue);
- if (RUNTIME.equals(propertyName)) {
- model.notifyPropertyChange(USE_SERVER_JPA_IMPLEMENTATION, IDataModel.DEFAULT_CHG);
- model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG);
+ if (propertyName.equals(RUNTIME)) {
+ this.model.notifyPropertyChange(USE_SERVER_JPA_IMPLEMENTATION, IDataModel.DEFAULT_CHG);
+ this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG);
}
return ok;
}
-
+
@Override
public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) {
- if (JPA_LIBRARY.equals(propertyName)) {
- String[] libraries = JavaCore.getUserLibraryNames();
- Arrays.sort(libraries);
+ if (propertyName.equals(JPA_LIBRARY)) {
+ String[] libraries = CollectionTools.sort(JavaCore.getUserLibraryNames());
DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[libraries.length + 1];
-
- descriptors[0] = new DataModelPropertyDescriptor("", WTPCommonPlugin.getResourceString(WTPCommonMessages.RUNTIME_NONE, null));
+ descriptors[0] = new DataModelPropertyDescriptor("", RUNTIME_NONE);
int i = 1;
for (String library : libraries) {
@@ -113,73 +121,89 @@ public class JpaFacetDataModelProvider
return super.getValidPropertyDescriptors(propertyName);
}
-
+
@Override
public IStatus validate(String name) {
- if (PLATFORM_ID.equals(name)) {
- return validatePlatform(getStringProperty(name));
+ if (name.equals(PLATFORM_ID)) {
+ return this.validatePlatformId(this.getStringProperty(name));
}
- else if (CONNECTION.equals(name)) {
- return validateConnection(getStringProperty(name));
+ if (name.equals(CONNECTION)) {
+ return this.validateConnectionName(this.getStringProperty(name));
}
- else if (USE_SERVER_JPA_IMPLEMENTATION.equals(name) || JPA_LIBRARY.equals(name)) {
- return validateJpaLibrary();
+ if (name.equals(USE_SERVER_JPA_IMPLEMENTATION)) {
+ return this.validateJpaLibrary(this.getBooleanProperty(name));
}
- else if (DISCOVER_ANNOTATED_CLASSES.equals(name)) {
- return validatePersistentClassManagement();
- }
- else {
- return super.validate(name);
+ if (name.equals(DISCOVER_ANNOTATED_CLASSES)) {
+ return this.validatePersistentClassManagement(this.getBooleanProperty(name));
}
+ return super.validate(name);
}
-
- private IRuntime getRuntime() {
- return (IRuntime) getProperty(RUNTIME);
+
+ private IRuntime runtime() {
+ return (IRuntime) this.getProperty(RUNTIME);
}
-
+
private boolean runtimeSupportsEjb30(IRuntime runtime) {
- IProjectFacetVersion ejb30 = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_EJB_MODULE).getVersion("3.0");
+ IProjectFacetVersion ejb30 = ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0");
return (runtime == null) ? false : runtime.supports(ejb30);
}
-
- private IStatus validatePlatform(String platformId) {
- if (platformId == null || platformId.equals("")) {
- return new Status(IStatus.ERROR, JptCorePlugin.PLUGIN_ID, JptCoreMessages.VALIDATE_PLATFORM_NOT_SPECIFIED);
- }
- else {
- return OK_STATUS;
- }
+
+
+ // ********** validation **********
+
+ private IStatus validatePlatformId(String platformId) {
+ return StringTools.stringIsEmpty(platformId) ?
+ PLATFORM_NOT_SPECIFIED_STATUS
+ :
+ OK_STATUS;
}
-
- private IStatus validateConnection(String connectionName) {
- if (connectionName == null || connectionName.equals("") || ! ConnectionProfileRepository.instance().profileNamed(connectionName).isConnected()) {
- return new Status(IStatus.INFO, JptCorePlugin.PLUGIN_ID, JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED);
- }
- else {
- return OK_STATUS;
- }
+
+ private IStatus validateConnectionName(String connectionName) {
+ return ConnectionProfileRepository.instance().profileNamed(connectionName).isConnected() ?
+ OK_STATUS
+ :
+ CONNECTION_NOT_CONNECTED_STATUS;
}
-
- private IStatus validateJpaLibrary() {
- if (getBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION)) {
- IRuntime runtime = getRuntime();
+
+ private IStatus validateJpaLibrary(boolean useServerJpaImplementation) {
+ if (useServerJpaImplementation) {
+ IRuntime runtime = this.runtime();
if (runtime == null) {
- return new Status(IStatus.WARNING, JptCorePlugin.PLUGIN_ID, JptCoreMessages.VALIDATE_RUNTIME_NOT_SPECIFIED);
+ return RUNTIME_NOT_SPECIFIED_STATUS;
}
- if (! runtimeSupportsEjb30(runtime)) {
- return new Status(IStatus.WARNING, JptCorePlugin.PLUGIN_ID, JptCoreMessages.VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30);
+ if ( ! this.runtimeSupportsEjb30(runtime)) {
+ return RUNTIME_DOES_NOT_SUPPORT_EJB_30_STATUS;
}
- }
- else {
- if (StringTools.stringIsEmpty(getStringProperty(JPA_LIBRARY))) {
- return new Status(IStatus.WARNING, JptCorePlugin.PLUGIN_ID, JptCoreMessages.VALIDATE_LIBRARY_NOT_SPECIFIED);
+ } else {
+ if (StringTools.stringIsEmpty(this.getStringProperty(JPA_LIBRARY))) {
+ return LIBRARY_NOT_SPECIFIED_STATUS;
}
}
return OK_STATUS;
}
-
- private IStatus validatePersistentClassManagement() {
- // warning if "discovery" is used, but no runtime specified ??
+
+ private IStatus validatePersistentClassManagement(boolean discoverAnnotatedClasses) {
+ // TODO warning if "discovery" is used, but no runtime specified ??
return OK_STATUS;
}
+
+
+ // ********** static methods **********
+
+ private static IStatus buildInfoStatus(String message) {
+ return buildStatus(IStatus.INFO, message);
+ }
+
+ private static IStatus buildWarningStatus(String message) {
+ return buildStatus(IStatus.WARNING, message);
+ }
+
+ private static IStatus buildErrorStatus(String message) {
+ return buildStatus(IStatus.ERROR, message);
+ }
+
+ private static IStatus buildStatus(int severity, String message) {
+ return new Status(severity, JptCorePlugin.PLUGIN_ID, message);
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java
index 791160aff7..a02f763a0e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -12,71 +12,115 @@ package org.eclipse.jpt.core.internal.facet;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil;
import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants;
-import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
-import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+/**
+ * We don't really "install" the JPA facet here. We simply store all the various
+ * data model properties in the appropriate preferences. These settings will
+ * used in the POST_INSTALL event listener to build the JPA project.
+ */
public class JpaFacetInstallDelegate
implements IDelegate, IJpaFacetDataModelProperties
{
+
public void execute(IProject project, IProjectFacetVersion fv,
Object config, IProgressMonitor monitor) throws CoreException {
-
- if (monitor != null) {
- monitor.beginTask("", 1); //$NON-NLS-1$
+ monitor = this.nonNullMonitor(monitor);
+ try {
+ this.execute_(project, fv, config, monitor);
+ } finally {
+ monitor.done();
}
+ }
- // NB: WTP Natures (including the JavaEMFNature)
- // should already be added as this facet should
- // always coexist with a module facet.
+ private void execute_(IProject project, IProjectFacetVersion fv,
+ Object config, IProgressMonitor monitor) throws CoreException {
+ monitor.beginTask("", 1); //$NON-NLS-1$
+
+ // NB: WTP Natures (including the JavaEMFNature)
+ // should already be added, as this facet should
+ // always coexist with a module facet.
+
IJavaProject javaProject = JavaCore.create(project);
-
- boolean usesServerLibrary = ((IDataModel) config).getBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION);
- String jpaLibrary = ((IDataModel) config).getStringProperty(JPA_LIBRARY);
- if (! usesServerLibrary && ! StringTools.stringIsEmpty(jpaLibrary)) {
- IClasspathEntry[] classpath = javaProject.getRawClasspath();
- int newLength = classpath.length + 1;
- boolean isWebApp = FacetedProjectFramework.hasProjectFacet(project, IModuleConstants.JST_WEB_MODULE);
- IClasspathAttribute[] attributes;
- if (! isWebApp && J2EEProjectUtilities.isStandaloneProject(project)) {
- attributes = new IClasspathAttribute[0];
- }
- else {
- attributes = new IClasspathAttribute[] {
- JavaCore.newClasspathAttribute(
- IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY,
- ClasspathDependencyUtil.getDefaultRuntimePath(isWebApp).toString()
- )
- };
- }
-
- IClasspathEntry jpaLibraryEntry =
- JavaCore.newContainerEntry(
- new Path(JavaCore.USER_LIBRARY_CONTAINER_ID + "/" + jpaLibrary),
- null, attributes, true);
- if (! CollectionTools.contains(classpath, jpaLibraryEntry)) {
- IClasspathEntry[] newClasspath = new IClasspathEntry[newLength];
- System.arraycopy(classpath, 0, newClasspath, 0, newLength - 1);
- newClasspath[newLength - 1] = jpaLibraryEntry;
- javaProject.setRawClasspath(newClasspath, monitor);
- }
+ IDataModel dataModel = (IDataModel) config;
+ this.configureClasspath(javaProject, dataModel, monitor);
+
+ JptCorePlugin.setJpaPlatformId(project, dataModel.getStringProperty(PLATFORM_ID));
+ JptCorePlugin.setConnectionProfileName(project, dataModel.getStringProperty(CONNECTION));
+ JptCorePlugin.setDiscoverAnnotatedClasses(project, dataModel.getBooleanProperty(DISCOVER_ANNOTATED_CLASSES));
+
+ monitor.worked(1);
+ }
+
+ private void configureClasspath(IJavaProject javaProject, IDataModel dataModel, IProgressMonitor monitor) throws CoreException {
+ boolean useServerLibrary = dataModel.getBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION);
+ if (useServerLibrary) {
+ return;
}
-
- if (monitor != null) {
- monitor.worked(1);
+
+ String jpaLibrary = dataModel.getStringProperty(JPA_LIBRARY);
+ if (StringTools.stringIsEmpty(jpaLibrary)) {
+ return;
}
+
+ // build the JPA library to be added to the classpath
+ IClasspathAttribute[] attributes = this.buildClasspathAttributes(javaProject.getProject());
+ IClasspathEntry jpaLibraryEntry =
+ JavaCore.newContainerEntry(
+ new Path(JavaCore.USER_LIBRARY_CONTAINER_ID + "/" + jpaLibrary),
+ null, attributes, true
+ );
+
+ // if the JPA library is already there, do nothing
+ IClasspathEntry[] classpath = javaProject.getRawClasspath();
+ if (CollectionTools.contains(classpath, jpaLibraryEntry)) {
+ return;
+ }
+
+ // add the JPA library to the classpath
+ int len = classpath.length;
+ IClasspathEntry[] newClasspath = new IClasspathEntry[len + 1];
+ System.arraycopy(classpath, 0, newClasspath, 0, len);
+ newClasspath[len] = jpaLibraryEntry;
+ javaProject.setRawClasspath(newClasspath, monitor);
+ }
+
+ private static final IClasspathAttribute[] EMPTY_CLASSPATH_ATTRIBUTES = new IClasspathAttribute[0];
+
+ private IClasspathAttribute[] buildClasspathAttributes(IProject project) {
+ boolean webApp = JptCorePlugin.projectHasWebFacet(project);
+ if ( ! webApp && this.projectIsStandalone(project)) {
+ return EMPTY_CLASSPATH_ATTRIBUTES;
+ }
+ return new IClasspathAttribute[] {
+ JavaCore.newClasspathAttribute(
+ IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY,
+ ClasspathDependencyUtil.getDefaultRuntimePath(webApp).toString()
+ )
+ };
+ }
+
+ @SuppressWarnings("restriction")
+ private boolean projectIsStandalone(IProject project) {
+ return org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities.isStandaloneProject(project);
}
+
+ private IProgressMonitor nonNullMonitor(IProgressMonitor monitor) {
+ return (monitor != null) ? monitor : new NullProgressMonitor();
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetPostInstallDelegate.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetPostInstallDelegate.java
deleted file mode 100644
index 9c54db2511..0000000000
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetPostInstallDelegate.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2007 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.facet;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jpt.core.internal.JpaModelManager;
-import org.eclipse.jpt.core.internal.JptCorePlugin;
-import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal;
-import org.eclipse.jpt.core.internal.content.orm.OrmFactory;
-import org.eclipse.jpt.core.internal.content.orm.OrmResource;
-import org.eclipse.jpt.core.internal.content.orm.resource.OrmArtifactEdit;
-import org.eclipse.jpt.core.internal.content.persistence.Persistence;
-import org.eclipse.jpt.core.internal.content.persistence.PersistenceFactory;
-import org.eclipse.jpt.core.internal.content.persistence.PersistenceUnit;
-import org.eclipse.jpt.core.internal.content.persistence.resource.PersistenceArtifactEdit;
-import org.eclipse.jpt.core.internal.content.persistence.resource.PersistenceResource;
-import org.eclipse.jst.j2ee.internal.J2EEConstants;
-import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
-import org.eclipse.wst.common.project.facet.core.IDelegate;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-
-public class JpaFacetPostInstallDelegate
- implements IDelegate, IJpaFacetDataModelProperties
-{
- private final static String WEB_PROJECT_DEPLOY_PREFIX = J2EEConstants.WEB_INF_CLASSES;
-
- private final static String PERSISTENCE_XML_FILE_PATH = "META-INF/persistence.xml";
-
- private final static String ORM_XML_FILE_PATH = "META-INF/orm.xml";
-
-
- public void execute(IProject project, IProjectFacetVersion fv,
- Object config, IProgressMonitor monitor) throws CoreException {
-
- if (monitor != null) {
- monitor.beginTask("", 2); //$NON-NLS-1$
- }
-
- JpaModelManager.instance().createJpaProject(project);
- IDataModel dataModel = (IDataModel) config;
- JpaFacetUtils.setPlatform(project, dataModel.getStringProperty(PLATFORM_ID));
- JpaFacetUtils.setConnectionName(project, dataModel.getStringProperty(CONNECTION));
- JpaFacetUtils.setDiscoverAnnotatedClasses(project, dataModel.getBooleanProperty(DISCOVER_ANNOTATED_CLASSES));
-
- createPersistenceXml(project, dataModel);
-
- if (dataModel.getBooleanProperty(CREATE_ORM_XML)) {
- createOrmXml(project, dataModel);
- }
-
- if (monitor != null) {
- monitor.worked(1);
- }
-
- JpaModelManager.instance().fillJpaProject(project);
-
- if (monitor != null) {
- monitor.worked(2);
- }
- }
-
- private void createPersistenceXml(IProject project, IDataModel dataModel) {
- String deployPath = PERSISTENCE_XML_FILE_PATH;
- try {
- if (FacetedProjectFramework.hasProjectFacet(project, IModuleConstants.JST_WEB_MODULE)) {
- deployPath = WEB_PROJECT_DEPLOY_PREFIX + "/" + deployPath;
- }
- }
- catch (CoreException ce) {
- // could not determine project facets. assume it doesn't have the facet.
- JptCorePlugin.log(ce);
- }
-
- PersistenceArtifactEdit pae =
- PersistenceArtifactEdit.getArtifactEditForWrite(project, deployPath);
- PersistenceResource resource = pae.getPersistenceResource();
-
- // fix for bug 202811 - only add content if it does not already have content
- if (resource.getPersistence() == null) {
- Persistence persistence = PersistenceFactory.eINSTANCE.createPersistence();
- persistence.setVersion("1.0");
- PersistenceUnit pUnit = PersistenceFactory.eINSTANCE.createPersistenceUnit();
- pUnit.setName(project.getName());
- persistence.getPersistenceUnits().add(pUnit);
- resource.getContents().add(persistence);
- pae.save(null);
- }
-
- pae.dispose();
- }
-
- private void createOrmXml(IProject project, IDataModel dataModel) {
- String deployPath = ORM_XML_FILE_PATH;
- try {
- if (FacetedProjectFramework.hasProjectFacet(project, IModuleConstants.JST_WEB_MODULE)) {
- deployPath = WEB_PROJECT_DEPLOY_PREFIX + "/" + deployPath;
- }
- }
- catch (CoreException ce) {
- // could not determine project facets. assume it doesn't have the facet.
- JptCorePlugin.log(ce);
- }
-
- OrmArtifactEdit oae =
- OrmArtifactEdit.getArtifactEditForWrite(project, deployPath);
- OrmResource resource = oae.getOrmResource();
-
- // fix for bug 202811 - only add content if it does not already have content
- if (resource.getEntityMappings() == null) {
- EntityMappingsInternal entityMappings = OrmFactory.eINSTANCE.createEntityMappingsInternal();
- entityMappings.setVersion("1.0");
- resource.getContents().add(entityMappings);
- oae.save(null);
- }
-
- oae.dispose();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUninstallDelegate.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUninstallDelegate.java
deleted file mode 100644
index f887b17b26..0000000000
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUninstallDelegate.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2007 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.facet;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jpt.core.internal.IJpaProject;
-import org.eclipse.jpt.core.internal.JpaModelManager;
-import org.eclipse.jpt.core.internal.JptCorePlugin;
-import org.eclipse.wst.common.project.facet.core.IDelegate;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-
-public class JpaFacetUninstallDelegate
- implements IDelegate
-{
- public void execute(IProject project, IProjectFacetVersion fv,
- Object config, IProgressMonitor monitor) throws CoreException {
-
- if (monitor != null) {
- monitor.beginTask("", 2); //$NON-NLS-1$
- }
-
- // TODO
- // - remove classpath items?
- // - remove persistence.xml
-
- IJpaProject jpaProject = JpaModelManager.instance().getJpaModel().getJpaProject(project);
- if (jpaProject != null) {
- JpaModelManager.instance().disposeJpaProject(jpaProject);
- }
-
- if (monitor != null) {
- monitor.worked(1);
- }
-
- ResourcesPlugin.getWorkspace().deleteMarkers(project.findMarkers(JptCorePlugin.VALIDATION_MARKER_ID, true, IResource.DEPTH_INFINITE));
-
- if (monitor != null) {
- monitor.worked(1);
- }
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUtils.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUtils.java
deleted file mode 100644
index c48c2b5db6..0000000000
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUtils.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2007 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.facet;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ProjectScope;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.IScopeContext;
-import org.eclipse.jpt.core.internal.IJpaCoreConstants;
-import org.eclipse.jpt.core.internal.JpaPlatformRegistry;
-import org.eclipse.jpt.core.internal.JpaProject;
-import org.eclipse.jpt.core.internal.JptCorePlugin;
-import org.eclipse.jpt.core.internal.platform.generic.GenericPlatform;
-import org.osgi.service.prefs.BackingStoreException;
-
-public class JpaFacetUtils
-{
- private static QualifiedName CONNECTION_KEY =
- new QualifiedName(JptCorePlugin.PLUGIN_ID, IJpaCoreConstants.DATA_SOURCE_CONNECTION_NAME);
-
-
- /**
- * Private constructor - static class only
- */
- private JpaFacetUtils() {}
-
-
- public static String getPlatform(final IProject project) {
- final IScopeContext context = new ProjectScope(project);
- final IEclipsePreferences prefs = context.getNode(JptCorePlugin.PLUGIN_ID);
-
- String platformId = prefs.get(IJpaCoreConstants.JPA_PLATFORM, null);
-
- if (platformId == null) {
- try {
- setPlatform(project, GenericPlatform.ID);
- }
- catch (CoreException ce) {
- // do nothing. not sure what can be done here.
- }
- return GenericPlatform.ID;
- }
-
- return platformId;
- }
-
- public static void setPlatform(final IProject project, String jpaPlatformId)
- throws CoreException
- {
- final IScopeContext context = new ProjectScope(project);
- final IEclipsePreferences prefs = context.getNode(JptCorePlugin.PLUGIN_ID);
-
- JpaProject jpaProject = (JpaProject) JptCorePlugin.getJpaProject(project);
-
- if (jpaProject == null) {
- throw new IllegalArgumentException(project.getName());
- }
-
- if (JpaPlatformRegistry.instance().jpaPlatform(jpaPlatformId) == null) {
- throw new IllegalArgumentException(jpaPlatformId);
- }
-
- jpaProject.setPlatform(jpaPlatformId);
- prefs.put(IJpaCoreConstants.JPA_PLATFORM, jpaPlatformId);
-
- try {
- prefs.flush();
- }
- catch( BackingStoreException e ) {
- JptCorePlugin.log(e);
- }
- }
-
- public static String getConnectionName(final IProject project) {
- try {
- return project.getPersistentProperty(CONNECTION_KEY);
- }
- catch (CoreException ce) {
- return null;
- }
- }
-
- public static void setConnectionName(final IProject project, String connectionName)
- throws CoreException
- {
- JpaProject jpaProject = (JpaProject) JptCorePlugin.getJpaProject(project);
-
- if (jpaProject == null) {
- throw new IllegalArgumentException(project.getName());
- }
-
- jpaProject.setDataSource(connectionName);
- project.setPersistentProperty(CONNECTION_KEY, connectionName);
- }
-
- public static boolean getDiscoverAnnotatedClasses(final IProject project) {
- final IScopeContext context = new ProjectScope(project);
- final IEclipsePreferences prefs = context.getNode(JptCorePlugin.PLUGIN_ID);
-
- return prefs.getBoolean(IJpaCoreConstants.DISCOVER_ANNOTATED_CLASSES, false);
- }
-
- public static void setDiscoverAnnotatedClasses(final IProject project, boolean discoverAnnotatedClasses)
- throws CoreException
- {
- final IScopeContext context = new ProjectScope(project);
- final IEclipsePreferences prefs = context.getNode(JptCorePlugin.PLUGIN_ID);
-
- JpaProject jpaProject = (JpaProject) JptCorePlugin.getJpaProject(project);
-
- if (jpaProject == null) {
- throw new IllegalArgumentException(project.getName());
- }
-
- jpaProject.setDiscoverAnnotatedClasses(discoverAnnotatedClasses);
- prefs.putBoolean(IJpaCoreConstants.DISCOVER_ANNOTATED_CLASSES, discoverAnnotatedClasses);
-
- try {
- prefs.flush();
- }
- catch(BackingStoreException e) {
- JptCorePlugin.log(e);
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsAdapterFactory.java
index 5a79a56363..80e7361e47 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsAdapterFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsAdapterFactory.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -17,6 +17,7 @@ import org.eclipse.jpt.core.internal.IAttributeMapping;
import org.eclipse.jpt.core.internal.IJpaEObject;
import org.eclipse.jpt.core.internal.IJpaSourceObject;
import org.eclipse.jpt.core.internal.ITypeMapping;
+import org.eclipse.jpt.core.internal.mappings.*;
import org.eclipse.jpt.core.internal.mappings.IAbstractColumn;
import org.eclipse.jpt.core.internal.mappings.IAbstractJoinColumn;
import org.eclipse.jpt.core.internal.mappings.IAssociationOverride;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsSwitch.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsSwitch.java
index 9467464962..f65bbad6d6 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsSwitch.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/util/JpaCoreMappingsSwitch.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -16,6 +16,7 @@ import org.eclipse.jpt.core.internal.IAttributeMapping;
import org.eclipse.jpt.core.internal.IJpaEObject;
import org.eclipse.jpt.core.internal.IJpaSourceObject;
import org.eclipse.jpt.core.internal.ITypeMapping;
+import org.eclipse.jpt.core.internal.mappings.*;
import org.eclipse.jpt.core.internal.mappings.IAbstractColumn;
import org.eclipse.jpt.core.internal.mappings.IAbstractJoinColumn;
import org.eclipse.jpt.core.internal.mappings.IAssociationOverride;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaFactory.java
index 447456b294..d9a10711bc 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaFactory.java
@@ -1,15 +1,23 @@
/*******************************************************************************
* Copyright (c) 2007 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.
+ * 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.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jpt.core.internal.IJpaDataSource;
import org.eclipse.jpt.core.internal.IJpaFactory;
+import org.eclipse.jpt.core.internal.IJpaFile;
+import org.eclipse.jpt.core.internal.IJpaFileContentProvider;
+import org.eclipse.jpt.core.internal.IJpaProject;
+import org.eclipse.jpt.core.internal.JpaCoreFactory;
+import org.eclipse.jpt.core.internal.JpaProject;
import org.eclipse.jpt.core.internal.content.java.mappings.IJavaBasic;
import org.eclipse.jpt.core.internal.content.java.mappings.IJavaEmbeddable;
import org.eclipse.jpt.core.internal.content.java.mappings.IJavaEmbedded;
@@ -29,6 +37,18 @@ import org.eclipse.jpt.core.internal.jdtutility.Type;
public abstract class BaseJpaFactory implements IJpaFactory
{
+ public IJpaProject createJpaProject(IJpaProject.Config config) throws CoreException {
+ return new JpaProject(config);
+ }
+
+ public IJpaDataSource createDataSource(IJpaProject jpaProject, String connectionProfileName) {
+ return JpaCoreFactory.eINSTANCE.createJpaDataSource(jpaProject, connectionProfileName);
+ }
+
+ public IJpaFile createJpaFile(IJpaProject jpaProject, IFile file, IJpaFileContentProvider provider) {
+ return JpaCoreFactory.eINSTANCE.createJpaFile(jpaProject, file, provider);
+ }
+
public IJavaEntity createJavaEntity(Type type) {
return JpaJavaMappingsFactory.eINSTANCE.createJavaEntity(type);
}
@@ -80,4 +100,5 @@ public abstract class BaseJpaFactory implements IJpaFactory
public IJavaVersion createJavaVersion(Attribute attribute) {
return JpaJavaMappingsFactory.eINSTANCE.createJavaVersion(attribute);
}
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaPlatform.java
index 3db50fb003..624f409735 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaPlatform.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaPlatform.java
@@ -1,21 +1,27 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jpt.core.internal.IJpaFactory;
import org.eclipse.jpt.core.internal.IJpaFile;
import org.eclipse.jpt.core.internal.IJpaFileContentProvider;
@@ -23,6 +29,7 @@ import org.eclipse.jpt.core.internal.IJpaPlatform;
import org.eclipse.jpt.core.internal.IJpaProject;
import org.eclipse.jpt.core.internal.IMappingKeys;
import org.eclipse.jpt.core.internal.IPersistentType;
+import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.core.internal.content.java.IDefaultJavaAttributeMappingProvider;
import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMapping;
import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMappingProvider;
@@ -63,7 +70,6 @@ import org.eclipse.jpt.core.internal.content.persistence.PersistenceXmlJpaFileCo
import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
public abstract class BaseJpaPlatform implements IJpaPlatform
{
@@ -83,7 +89,7 @@ public abstract class BaseJpaPlatform implements IJpaPlatform
private String id;
- protected IJpaProject project;
+ protected IJpaProject project; // TODO this must go ~bjv
private Collection<IJpaFileContentProvider> contentProviders;
@@ -95,14 +101,14 @@ public abstract class BaseJpaPlatform implements IJpaPlatform
private IJpaFactory jpaFactory;
- private IContext context;
+ private IContext context; // TODO this must go ~bjv
protected BaseJpaPlatform() {
super();
- this.jpaFactory = createJpaFactory();
+ this.jpaFactory = buildJpaFactory();
}
- protected abstract IJpaFactory createJpaFactory();
+ protected abstract IJpaFactory buildJpaFactory();
public String getId() {
return this.id;
@@ -130,7 +136,41 @@ public abstract class BaseJpaPlatform implements IJpaPlatform
public IJpaFactory getJpaFactory() {
return this.jpaFactory;
}
-
+
+ public IJpaFile createJpaFile(IJpaProject jpaProject, IFile file) {
+ if ( ! jpaProject.javaProject().isOnClasspath(file)) {
+ return null; // skip the file if it is not on the Java project's classpath
+ }
+
+ IContentType contentType = this.contentType(file);
+ if (contentType == null) {
+ return null; // skip the file if its content type is unknown
+ }
+
+ IJpaFileContentProvider provider = this.fileContentProvider(contentType.getId());
+ if (provider == null) {
+ return null; // no JPA file if we don't have a JPA file content provider for its content
+ }
+ return this.jpaFactory.createJpaFile(jpaProject, file, provider);
+ }
+
+ /**
+ * Return the content type of the specified file.
+ * This cannot be based solely on the file's name (i.e. the file's extension)
+ * because in the case of XML the content type is based on the root
+ * element name (which is inside the file).
+ */
+ protected IContentType contentType(IFile file) {
+ try {
+ return Platform.getContentTypeManager().findContentTypeFor(file.getContents(), file.getName());
+ } catch (IOException ex) {
+ JptCorePlugin.log(ex);
+ } catch (CoreException ex) {
+ JptCorePlugin.log(ex);
+ }
+ return null; // return null if any exceptions occur
+ }
+
// ********** Persistence Unit ********************************************
public boolean containsPersistenceUnitNamed(String name) {
@@ -155,12 +195,7 @@ public abstract class BaseJpaPlatform implements IJpaPlatform
public Iterator<IPersistentType> persistentTypes(String persistenceUnitName) {
PersistenceUnitContext puContext =
((BaseJpaProjectContext) this.context).persistenceUnitContext(persistenceUnitName);
- if (puContext == null) {
- return EmptyIterator.instance();
- }
- return puContext.persistentTypes();
- //hmm, compiler error with ternary operator
-// return (puContext == null) ? EmptyIterator.instance() : puContext.persistentTypes();
+ return (puContext == null) ? EmptyIterator.<IPersistentType>instance() : puContext.persistentTypes();
}
@@ -353,14 +388,15 @@ public abstract class BaseJpaPlatform implements IJpaPlatform
((BaseJpaProjectContext) contextHierarchy).refreshDefaults(monitor);
}
- public void addToMessages(List<IMessage> messages) {
- //I believe we need to be calling JpaProject.resynch() here.
+ @SuppressWarnings("restriction")
+ public void addToMessages(List<org.eclipse.wst.validation.internal.provisional.core.IMessage> messages) {
+ //I believe we need to be calling JpaProject.update() here.
//How can we handle this, we need to resynch and then wait until it is done
//resynching before calling this. what happens if something changes out from
//under us while we are resynching??
- BaseJpaProjectContext context = (BaseJpaProjectContext) buildProjectContext();
- context.refreshDefaults(new NullProgressMonitor());
- context.addToMessages(messages);
+ BaseJpaProjectContext ctx = (BaseJpaProjectContext) buildProjectContext();
+ ctx.refreshDefaults(new NullProgressMonitor());
+ ctx.addToMessages(messages);
}
// public IGeneratorRepository generatorRepository(IPersistentType persistentType) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaProjectContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaProjectContext.java
index b959219eef..1a0c3af2be 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaProjectContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/BaseJpaProjectContext.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 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
+ * Copyright (c) 2007 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
- *******************************************************************************/
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal.platform;
import java.util.ArrayList;
@@ -78,7 +79,8 @@ public class BaseJpaProjectContext extends BaseContext
}
private void sortPersistenceXmlFiles() {
- for (IJpaFile jpaFile : persistenceXmlFiles()) {
+ for (Iterator<IJpaFile> stream = this.persistenceXmlFiles(); stream.hasNext(); ) {
+ IJpaFile jpaFile = stream.next();
if (isValidPersistenceXmlLocation(jpaFile)) {
validPersistenceXmlFiles.add(jpaFile);
}
@@ -88,13 +90,13 @@ public class BaseJpaProjectContext extends BaseContext
}
}
- private Collection<IJpaFile> persistenceXmlFiles() {
+ private Iterator<IJpaFile> persistenceXmlFiles() {
return this.jpaProject.jpaFiles(JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE);
}
private boolean isValidPersistenceXmlLocation(IJpaFile jpaFile) {
IFile file = jpaFile.getFile();
- IProject project = jpaProject.getProject();
+ IProject project = jpaProject.project();
// check flexible jpaProject structure
IVirtualComponent component = ComponentCore.createComponent(project);
@@ -133,7 +135,7 @@ public class BaseJpaProjectContext extends BaseContext
@Override
public IJpaPlatform getPlatform() {
- return this.jpaProject.getPlatform();
+ return this.jpaProject.jpaPlatform();
}
protected Iterator<IJpaFile> validPersistenceXmlFiles(){
@@ -288,7 +290,7 @@ public class BaseJpaProjectContext extends BaseContext
protected boolean okToProceedForConnectionValidation = true;
protected void addNoConnectionMessage(List<IMessage> messages) {
- if (! jpaProject.getDataSource().hasAConnection()) {
+ if (! jpaProject.dataSource().hasAConnection()) {
messages.add(
JpaValidationMessages.buildMessage(
IMessage.NORMAL_SEVERITY,
@@ -300,12 +302,12 @@ public class BaseJpaProjectContext extends BaseContext
}
protected void addInactiveConnectionMessage(List<IMessage> messages) {
- if (okToProceedForConnectionValidation && ! jpaProject.getDataSource().isConnected()) {
+ if (okToProceedForConnectionValidation && ! jpaProject.dataSource().isConnected()) {
messages.add(
JpaValidationMessages.buildMessage(
IMessage.NORMAL_SEVERITY,
IJpaValidationMessages.PROJECT_INACTIVE_CONNECTION,
- new String[] {jpaProject.getDataSource().getConnectionProfileName()},
+ new String[] {jpaProject.dataSource().getConnectionProfileName()},
jpaProject)
);
}
@@ -382,21 +384,20 @@ public class BaseJpaProjectContext extends BaseContext
}
protected void addOrphanedJavaClassMessages(List<IMessage> messages) {
- for (IJpaFile jpaFile : jpaProject.jpaFiles(JptCorePlugin.JAVA_CONTENT_TYPE)) {
- for (JavaPersistentType jpType : ((JpaCompilationUnit) jpaFile.getContent()).getTypes()) {
- if (jpType.getMappingKey() != IMappingKeys.NULL_TYPE_MAPPING_KEY && ! contains(jpType)) {
- messages.add(
- JpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- IJpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CONTEXT,
- jpType.getMapping(), jpType.getMapping().validationTextRange())
- );
- }
+ for (Iterator<JavaPersistentType> stream = jpaProject.javaPersistentTypes(); stream.hasNext(); ) {
+ JavaPersistentType jpType = stream.next();
+ if (jpType.getMappingKey() != IMappingKeys.NULL_TYPE_MAPPING_KEY && ! contains(jpType)) {
+ messages.add(
+ JpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ IJpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CONTEXT,
+ jpType.getMapping(), jpType.getMapping().validationTextRange())
+ );
}
}
}
public String toString() {
- return StringTools.buildToStringFor( this, this.jpaProject.getJavaProject().getProject().getName());
+ return StringTools.buildToStringFor( this, this.jpaProject.javaProject().getProject().getName());
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java
index d2f38cdc05..99d8b2e08f 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 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
+ * Copyright (c) 2006, 2007 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
- *******************************************************************************/
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.core.internal.platform;
import java.util.ArrayList;
@@ -135,13 +136,13 @@ public class PersistenceUnitContext extends BaseContext
protected XmlRootContentNode impliedMappingFileContent() {
// check flexible project structure
- IVirtualComponent component = ComponentCore.createComponent(persistenceUnit.getJpaProject().getProject());
+ IVirtualComponent component = ComponentCore.createComponent(persistenceUnit.getJpaProject().project());
IVirtualFolder virtualRootFolder = component.getRootFolder();
IVirtualFile virtualMappingFile = virtualRootFolder.getFile(new Path(IMPLIED_MAPPING_FILE_LOCATION));
// keep track of whether one has been found so that we may know if multiple exist
IJpaFile mappingFile = null;
for (IFile underlyingFile : virtualMappingFile.getUnderlyingFiles()) {
- IJpaFile jpaFile = JptCorePlugin.getJpaFile(underlyingFile);
+ IJpaFile jpaFile = JptCorePlugin.jpaFile(underlyingFile);
if (jpaFile != null) {
if (mappingFile != null) {
return null; // multiple do exist
@@ -201,19 +202,10 @@ public class PersistenceUnitContext extends BaseContext
}
protected Iterator<JavaPersistentType> discoveredJavaPersistentTypes() {
- if (! persistenceUnit.getJpaProject().isDiscoverAnnotatedClasses()) {
+ if (! persistenceUnit.getJpaProject().discoversAnnotatedClasses()) {
return EmptyIterator.instance();
}
- Collection<IJpaFile> javaJpaFiles = persistenceUnit.getJpaProject().jpaFiles(JptCorePlugin.JAVA_CONTENT_TYPE);
- return new CompositeIterator<JavaPersistentType>(
- new TransformationIterator<IJpaFile, Iterator<JavaPersistentType>>(javaJpaFiles.iterator()) {
- @Override
- protected Iterator<JavaPersistentType> transform(IJpaFile next) {
- JpaCompilationUnit jcu = (JpaCompilationUnit) next.getContent();
- return jcu.getTypes().iterator();
- }
- }
- );
+ return persistenceUnit.getJpaProject().javaPersistentTypes();
}
/**
@@ -237,7 +229,7 @@ public class PersistenceUnitContext extends BaseContext
private JavaPersistentType javaPersistentTypeFor(JavaClassRef javaClassRef) {
IType type = javaClassRef.findJdtType();
- return jpaProject().findJavaPersistentType(type);
+ return jpaProject().javaPersistentType(type);
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericJpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericJpaFactory.java
index 31a259440f..8d5fa90ffe 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericJpaFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericJpaFactory.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2007 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.
+ * 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
@@ -11,5 +11,6 @@ package org.eclipse.jpt.core.internal.platform.generic;
import org.eclipse.jpt.core.internal.platform.BaseJpaFactory;
-public class GenericJpaFactory extends BaseJpaFactory
-{}
+public class GenericJpaFactory extends BaseJpaFactory {
+ // nothing for now... just take everything from the abstract superclass
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericPlatform.java
index e9343fe191..001f795e79 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericPlatform.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/generic/GenericPlatform.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -17,7 +17,8 @@ public class GenericPlatform
{
public final static String ID = "generic";
- protected IJpaFactory createJpaFactory() {
+ @Override
+ protected IJpaFactory buildJpaFactory() {
return new GenericJpaFactory();
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceConstants.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceConstants.java
index fdd98cd73c..c601f4be5c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceConstants.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceConstants.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 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
- *******************************************************************************/
+ * Copyright (c) 2006, 2007 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.prefs;
/**
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceInitializer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceInitializer.java
index 7573522266..9826e6ecfe 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceInitializer.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceInitializer.java
@@ -1,11 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 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
- *******************************************************************************/
+ * Copyright (c) 2006, 2007 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.prefs;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
@@ -24,7 +25,7 @@ public class JpaPreferenceInitializer extends AbstractPreferenceInitializer
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
*/
public void initializeDefaultPreferences() {
- IEclipsePreferences node = new DefaultScope().getNode(JptCorePlugin.getPlugin().getBundle().getSymbolicName());
+ IEclipsePreferences node = new DefaultScope().getNode(JptCorePlugin.instance().getBundle().getSymbolicName());
// default JPA library
node.put(JpaPreferenceConstants.PREF_DEFAULT_JPA_LIB, "");
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/synch/SynchronizeClassesJob.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/synch/SynchronizeClassesJob.java
index a9892d556e..0c943f2d93 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/synch/SynchronizeClassesJob.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/synch/SynchronizeClassesJob.java
@@ -60,7 +60,7 @@ public class SynchronizeClassesJob extends Job
return Status.CANCEL_STATUS;
}
- IJpaFile jpaFile = JptCorePlugin.getJpaFile(this.persistenceXmlFile);
+ IJpaFile jpaFile = JptCorePlugin.jpaFile(this.persistenceXmlFile);
PersistenceXmlRootContentNode root;
try {
root = (PersistenceXmlRootContentNode) jpaFile.getContent();
@@ -122,17 +122,7 @@ public class SynchronizeClassesJob extends Job
}
private Iterator<IPersistentType> mappedTypes(PersistenceUnit persistenceUnit) {
- return new FilteringIterator<IPersistentType>(allJavaTypes(persistenceUnit.getJpaProject()), filter(persistenceUnit));
- }
-
- private Iterator<IPersistentType> allJavaTypes(IJpaProject jpaProject) {
- return new TransformationIterator<IJpaFile, IPersistentType>(jpaProject.jpaFiles(JptCorePlugin.JAVA_CONTENT_TYPE).iterator()) {
- @Override
- protected IPersistentType transform(IJpaFile next) {
- JpaCompilationUnit jcu = (JpaCompilationUnit) next.getContent();
- return (jcu.getTypes().isEmpty()) ? null : jcu.getTypes().get(0);
- }
- };
+ return new FilteringIterator<IPersistentType>(persistenceUnit.getJpaProject().javaPersistentTypes(), filter(persistenceUnit));
}
private Filter<IPersistentType> filter(final PersistenceUnit persistenceUnit) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreAdapterFactory.java
index 781a1fc4c2..eabeccda8e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreAdapterFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreAdapterFactory.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -13,6 +13,7 @@ import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jpt.core.internal.*;
import org.eclipse.jpt.core.internal.IAttributeMapping;
import org.eclipse.jpt.core.internal.IJpaContentNode;
import org.eclipse.jpt.core.internal.IJpaDataSource;
@@ -93,16 +94,6 @@ public class JpaCoreAdapterFactory extends AdapterFactoryImpl
*/
protected JpaCoreSwitch<Adapter> modelSwitch = new JpaCoreSwitch<Adapter>() {
@Override
- public Adapter caseIJpaModel(IJpaModel object) {
- return createIJpaModelAdapter();
- }
-
- @Override
- public Adapter caseJpaModel(JpaModel object) {
- return createJpaModelAdapter();
- }
-
- @Override
public Adapter caseIJpaEObject(IJpaEObject object) {
return createIJpaEObjectAdapter();
}
@@ -113,21 +104,6 @@ public class JpaCoreAdapterFactory extends AdapterFactoryImpl
}
@Override
- public Adapter caseIJpaProject(IJpaProject object) {
- return createIJpaProjectAdapter();
- }
-
- @Override
- public Adapter caseJpaProject(JpaProject object) {
- return createJpaProjectAdapter();
- }
-
- @Override
- public Adapter caseIJpaPlatform(IJpaPlatform object) {
- return createIJpaPlatformAdapter();
- }
-
- @Override
public Adapter caseIJpaDataSource(IJpaDataSource object) {
return createIJpaDataSourceAdapter();
}
@@ -217,34 +193,6 @@ public class JpaCoreAdapterFactory extends AdapterFactoryImpl
}
/**
- * Creates a new adapter for an object of class '{@link org.eclipse.jpt.core.internal.IJpaModel <em>IJpa Model</em>}'.
- * <!-- begin-user-doc -->
- * This default implementation returns null so that we can easily ignore cases;
- * it's useful to ignore a case when inheritance will catch all the cases anyway.
- * <!-- end-user-doc -->
- * @return the new adapter.
- * @see org.eclipse.jpt.core.internal.IJpaModel
- * @generated
- */
- public Adapter createIJpaModelAdapter() {
- return null;
- }
-
- /**
- * Creates a new adapter for an object of class '{@link org.eclipse.jpt.core.internal.JpaModel <em>Jpa Model</em>}'.
- * <!-- begin-user-doc -->
- * This default implementation returns null so that we can easily ignore cases;
- * it's useful to ignore a case when inheritance will catch all the cases anyway.
- * <!-- end-user-doc -->
- * @return the new adapter.
- * @see org.eclipse.jpt.core.internal.JpaModel
- * @generated
- */
- public Adapter createJpaModelAdapter() {
- return null;
- }
-
- /**
* Creates a new adapter for an object of class '{@link org.eclipse.jpt.core.internal.IJpaEObject <em>IJpa EObject</em>}'.
* <!-- begin-user-doc -->
* This default implementation returns null so that we can easily ignore cases;
@@ -273,34 +221,6 @@ public class JpaCoreAdapterFactory extends AdapterFactoryImpl
}
/**
- * Creates a new adapter for an object of class '{@link org.eclipse.jpt.core.internal.IJpaProject <em>IJpa Project</em>}'.
- * <!-- begin-user-doc -->
- * This default implementation returns null so that we can easily ignore cases;
- * it's useful to ignore a case when inheritance will catch all the cases anyway.
- * <!-- end-user-doc -->
- * @return the new adapter.
- * @see org.eclipse.jpt.core.internal.IJpaProject
- * @generated
- */
- public Adapter createIJpaProjectAdapter() {
- return null;
- }
-
- /**
- * Creates a new adapter for an object of class '{@link org.eclipse.jpt.core.internal.JpaProject <em>Jpa Project</em>}'.
- * <!-- begin-user-doc -->
- * This default implementation returns null so that we can easily ignore cases;
- * it's useful to ignore a case when inheritance will catch all the cases anyway.
- * <!-- end-user-doc -->
- * @return the new adapter.
- * @see org.eclipse.jpt.core.internal.JpaProject
- * @generated
- */
- public Adapter createJpaProjectAdapter() {
- return null;
- }
-
- /**
* Creates a new adapter for an object of class '{@link org.eclipse.jpt.core.internal.IJpaFile <em>IJpa File</em>}'.
* <!-- begin-user-doc -->
* This default implementation returns null so that we can easily ignore cases;
@@ -497,20 +417,6 @@ public class JpaCoreAdapterFactory extends AdapterFactoryImpl
}
/**
- * Creates a new adapter for an object of class '{@link org.eclipse.jpt.core.internal.IJpaPlatform <em>IJpa Platform</em>}'.
- * <!-- begin-user-doc -->
- * This default implementation returns null so that we can easily ignore cases;
- * it's useful to ignore a case when inheritance will catch all the cases anyway.
- * <!-- end-user-doc -->
- * @return the new adapter.
- * @see org.eclipse.jpt.core.internal.IJpaPlatform
- * @generated
- */
- public Adapter createIJpaPlatformAdapter() {
- return null;
- }
-
- /**
* Creates a new adapter for the default case.
* <!-- begin-user-doc -->
* This default implementation returns null.
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreSwitch.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreSwitch.java
index 02b0d9f529..3df8e776ed 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreSwitch.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/util/JpaCoreSwitch.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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.
+ * 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
@@ -12,6 +12,7 @@ package org.eclipse.jpt.core.internal.util;
import java.util.List;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jpt.core.internal.*;
import org.eclipse.jpt.core.internal.IAttributeMapping;
import org.eclipse.jpt.core.internal.IJpaContentNode;
import org.eclipse.jpt.core.internal.IJpaDataSource;
@@ -107,26 +108,6 @@ public class JpaCoreSwitch<T>
*/
protected T doSwitch(int classifierID, EObject theEObject) {
switch (classifierID) {
- case JpaCorePackage.IJPA_MODEL : {
- IJpaModel iJpaModel = (IJpaModel) theEObject;
- T result = caseIJpaModel(iJpaModel);
- if (result == null)
- result = defaultCase(theEObject);
- return result;
- }
- case JpaCorePackage.JPA_MODEL : {
- JpaModel jpaModel = (JpaModel) theEObject;
- T result = caseJpaModel(jpaModel);
- if (result == null)
- result = caseJpaEObject(jpaModel);
- if (result == null)
- result = caseIJpaModel(jpaModel);
- if (result == null)
- result = caseIJpaEObject(jpaModel);
- if (result == null)
- result = defaultCase(theEObject);
- return result;
- }
case JpaCorePackage.IJPA_EOBJECT : {
IJpaEObject iJpaEObject = (IJpaEObject) theEObject;
T result = caseIJpaEObject(iJpaEObject);
@@ -143,35 +124,6 @@ public class JpaCoreSwitch<T>
result = defaultCase(theEObject);
return result;
}
- case JpaCorePackage.IJPA_PROJECT : {
- IJpaProject iJpaProject = (IJpaProject) theEObject;
- T result = caseIJpaProject(iJpaProject);
- if (result == null)
- result = caseIJpaEObject(iJpaProject);
- if (result == null)
- result = defaultCase(theEObject);
- return result;
- }
- case JpaCorePackage.JPA_PROJECT : {
- JpaProject jpaProject = (JpaProject) theEObject;
- T result = caseJpaProject(jpaProject);
- if (result == null)
- result = caseJpaEObject(jpaProject);
- if (result == null)
- result = caseIJpaProject(jpaProject);
- if (result == null)
- result = caseIJpaEObject(jpaProject);
- if (result == null)
- result = defaultCase(theEObject);
- return result;
- }
- case JpaCorePackage.IJPA_PLATFORM : {
- IJpaPlatform iJpaPlatform = (IJpaPlatform) theEObject;
- T result = caseIJpaPlatform(iJpaPlatform);
- if (result == null)
- result = defaultCase(theEObject);
- return result;
- }
case JpaCorePackage.IJPA_DATA_SOURCE : {
IJpaDataSource iJpaDataSource = (IJpaDataSource) theEObject;
T result = caseIJpaDataSource(iJpaDataSource);
@@ -344,36 +296,6 @@ public class JpaCoreSwitch<T>
}
/**
- * Returns the result of interpreting the object as an instance of '<em>IJpa Model</em>'.
- * <!-- begin-user-doc -->
- * This implementation returns null;
- * returning a non-null result will terminate the switch.
- * <!-- end-user-doc -->
- * @param object the target of the switch.
- * @return the result of interpreting the object as an instance of '<em>IJpa Model</em>'.
- * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
- * @generated
- */
- public T caseIJpaModel(IJpaModel object) {
- return null;
- }
-
- /**
- * Returns the result of interpreting the object as an instance of '<em>Jpa Model</em>'.
- * <!-- begin-user-doc -->
- * This implementation returns null;
- * returning a non-null result will terminate the switch.
- * <!-- end-user-doc -->
- * @param object the target of the switch.
- * @return the result of interpreting the object as an instance of '<em>Jpa Model</em>'.
- * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
- * @generated
- */
- public T caseJpaModel(JpaModel object) {
- return null;
- }
-
- /**
* Returns the result of interpreting the object as an instance of '<em>IJpa EObject</em>'.
* <!-- begin-user-doc -->
* This implementation returns null;
@@ -404,36 +326,6 @@ public class JpaCoreSwitch<T>
}
/**
- * Returns the result of interpreting the object as an instance of '<em>IJpa Project</em>'.
- * <!-- begin-user-doc -->
- * This implementation returns null;
- * returning a non-null result will terminate the switch.
- * <!-- end-user-doc -->
- * @param object the target of the switch.
- * @return the result of interpreting the object as an instance of '<em>IJpa Project</em>'.
- * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
- * @generated
- */
- public T caseIJpaProject(IJpaProject object) {
- return null;
- }
-
- /**
- * Returns the result of interpreting the object as an instance of '<em>Jpa Project</em>'.
- * <!-- begin-user-doc -->
- * This implementation returns null;
- * returning a non-null result will terminate the switch.
- * <!-- end-user-doc -->
- * @param object the target of the switch.
- * @return the result of interpreting the object as an instance of '<em>Jpa Project</em>'.
- * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
- * @generated
- */
- public T caseJpaProject(JpaProject object) {
- return null;
- }
-
- /**
* Returns the result of interpreting the object as an instance of '<em>IJpa File</em>'.
* <!-- begin-user-doc -->
* This implementation returns null;
@@ -644,21 +536,6 @@ public class JpaCoreSwitch<T>
}
/**
- * Returns the result of interpreting the object as an instance of '<em>IJpa Platform</em>'.
- * <!-- begin-user-doc -->
- * This implementation returns null;
- * returning a non-null result will terminate the switch.
- * <!-- end-user-doc -->
- * @param object the target of the switch.
- * @return the result of interpreting the object as an instance of '<em>IJpa Platform</em>'.
- * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
- * @generated
- */
- public T caseIJpaPlatform(IJpaPlatform object) {
- return null;
- }
-
- /**
* Returns the result of interpreting the object as an instance of '<em>EObject</em>'.
* <!-- begin-user-doc -->
* This implementation returns null;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaHelper.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaHelper.java
index 2b74ce7bac..9b9c2ed667 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaHelper.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaHelper.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2007 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.
+ * 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
@@ -12,18 +12,22 @@ package org.eclipse.jpt.core.internal.validation;
import org.eclipse.core.resources.IResource;
import org.eclipse.jpt.core.internal.IJpaEObject;
import org.eclipse.jpt.core.internal.IJpaProject;
+import org.eclipse.jpt.core.internal.JpaNodeModel;
import org.eclipse.jpt.core.internal.JptCorePlugin;
-import org.eclipse.wst.validation.internal.operations.WorkbenchContext;
-public class JpaHelper extends WorkbenchContext
+public class JpaHelper extends org.eclipse.wst.validation.internal.operations.WorkbenchContext
{
IJpaProject getJpaProject() {
- return JptCorePlugin.getJpaProject(getProject());
+ return JptCorePlugin.jpaProject(getProject());
}
@Override
public IResource getResource(Object obj) {
- return ((IJpaEObject) obj).getResource();
+ // TODO temporary hack until we get rid of EMF
+ return (obj instanceof IJpaEObject) ?
+ ((IJpaEObject) obj).getResource()
+ :
+ ((JpaNodeModel) obj).resource();
}
/*
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidator.java
index df1d64bee4..7b68c2eb09 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidator.java
@@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright (c) 2007 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.
+ * 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
@@ -10,19 +10,11 @@
package org.eclipse.jpt.core.internal.validation;
import java.util.Iterator;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
-import org.eclipse.jpt.core.internal.IJpaProject;
-import org.eclipse.jpt.core.internal.JpaModelManager;
-import org.eclipse.jpt.core.internal.JpaProject;
-import org.eclipse.jpt.core.internal.JptCoreMessages;
-import org.eclipse.jpt.core.internal.JptCorePlugin;
-import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.core.ValidationException;
-import org.eclipse.wst.validation.internal.core.ValidatorLauncher;
import org.eclipse.wst.validation.internal.operations.IWorkbenchContext;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
@@ -39,28 +31,11 @@ public class JpaValidator implements IValidatorJob
public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws ValidationException {
JpaHelper jpaHelper = (JpaHelper) helper;
- IJpaProject jpaProject = jpaHelper.getJpaProject();
-
- if (! ((JpaProject) jpaProject).isFilled()) {
- try {
- JpaModelManager.instance().fillJpaProject(jpaProject.getProject());
- }
- catch (CoreException ce) {
- return new Status(IStatus.ERROR, JptCorePlugin.PLUGIN_ID, JptCoreMessages.ERROR_SYNCHRONIZING_CLASSES_COULD_NOT_VALIDATE, ce);
- }
-
- JpaHelper newJpaHelper = new JpaHelper();
- newJpaHelper.setProject(jpaHelper.getProject());
- newJpaHelper.setValidationFileURIs(jpaHelper.getValidationFileURIs());
- ValidatorLauncher.getLauncher().start(newJpaHelper, this, reporter);
-
- return OK_STATUS;
- }
reporter.removeAllMessages(this);
- for (Iterator stream = jpaProject.validationMessages(); stream.hasNext(); ) {
- reporter.addMessage(this, (Message) stream.next());
+ for (Iterator<IMessage> stream = jpaHelper.getJpaProject().validationMessages(); stream.hasNext(); ) {
+ reporter.addMessage(this, stream.next());
}
return OK_STATUS;

Back to the top