Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties1
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java101
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java1
4 files changed, 59 insertions, 48 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties
index 7f0d00b530..598a375830 100644
--- a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties
+++ b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties
@@ -17,6 +17,7 @@ PERSISTENCE_XML_INVALID_CONTENT=Invalid content (no root node)
PERSISTENCE_NO_PERSISTENCE_UNIT=No persistence unit defined
PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS=Multiple persistence units defined - only the first persistence unit will be recognized
PERSISTENCE_UNIT_UNSPECIFIED_MAPPING_FILE=Unspecified mapping file
+PERSISTENCE_UNIT_UNSUPPORTED_MAPPING_FILE_CONTENT=Mapping file \"{0}\" does not have supported content for this JPA platform
PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE=Mapping file \"{0}\" cannot be resolved
PERSISTENCE_UNIT_INVALID_MAPPING_FILE=Mapping file \"{0}\" does not have ORM content
PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE=Duplicate mapping file \"{0}\"
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java
index 8649fb0819..ada461049c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java
@@ -25,12 +25,10 @@ import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode;
import org.eclipse.jpt.core.internal.resource.JpaResourceModelProviderManager;
-import org.eclipse.jpt.core.internal.resource.orm.OrmResourceModelProvider;
import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
import org.eclipse.jpt.core.resource.JpaResourceModelProvider;
import org.eclipse.jpt.core.resource.common.JpaXmlResource;
-import org.eclipse.jpt.core.resource.orm.OrmResource;
import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.utility.internal.StringTools;
@@ -96,7 +94,7 @@ public class GenericMappingFileRef extends AbstractXmlContextNode
protected void initialize(XmlMappingFileRef mappingFileRef) {
this.xmlMappingFileRef = mappingFileRef;
initializeFileName();
- initializeOrmXml();
+ initializeMappingFile();
}
protected void initializeFileName() {
@@ -108,14 +106,13 @@ public class GenericMappingFileRef extends AbstractXmlContextNode
}
}
- protected void initializeOrmXml() {
- if (fileName != null) {
- OrmResourceModelProvider modelProvider =
- OrmResourceModelProvider.getModelProvider(getJpaProject().getProject(), fileName);
- OrmResource ormResource = modelProvider.getResource();
-
- if (ormResource != null && ormResource.exists()) {
- mappingFile = buildMappingFile(ormResource);
+ protected void initializeMappingFile() {
+ IFile platformFile = getPlatformFile();
+ if ((platformFile != null) && platformFile.exists()) {
+ JpaResourceModelProvider modelProvider = JpaResourceModelProviderManager.instance().getModelProvider(platformFile);
+ JpaXmlResource resource = (modelProvider == null) ? null : modelProvider.getResource();
+ if (resource != null && resource.exists()) {
+ this.mappingFile = buildMappingFile(resource);
}
}
}
@@ -136,26 +133,23 @@ public class GenericMappingFileRef extends AbstractXmlContextNode
}
protected void updateMappingFile() {
- if (fileName != null) {
- IProject project = getJpaProject().getProject();
- IVirtualFile vFile = ComponentCore.createFile(project, new Path(fileName));
- IFile realFile = vFile.getUnderlyingFile();
-
- if ((realFile != null) && realFile.exists()) {
- JpaResourceModelProvider modelProvider = JpaResourceModelProviderManager.instance().getModelProvider(realFile);
- JpaXmlResource resource = (modelProvider == null) ? null : modelProvider.getResource();
- if (resource != null) {
- if (this.mappingFile != null && ! resource.equals(this.mappingFile.getXmlResource())) {
- this.mappingFile.dispose();
- }
- if (this.mappingFile == null) {
- setMappingFile(buildMappingFile(resource));
- }
- else {
- this.mappingFile.update(resource);
- }
- return;
+ IFile platformFile = getPlatformFile();
+ if ((platformFile != null) && platformFile.exists()) {
+ JpaResourceModelProvider modelProvider = JpaResourceModelProviderManager.instance().getModelProvider(platformFile);
+ JpaXmlResource resource = (modelProvider == null) ? null : modelProvider.getResource();
+ if (resource != null && resource.exists()) {
+ // this check is done to determine whether the resource type has
+ // changed. if so, the mapping file must be rebuilt.
+ if (this.mappingFile != null && ! resource.equals(this.mappingFile.getXmlResource())) {
+ this.mappingFile.dispose();
}
+ if (this.mappingFile == null) {
+ setMappingFile(buildMappingFile(resource));
+ }
+ else {
+ this.mappingFile.update(resource);
+ }
+ return;
}
}
@@ -165,6 +159,15 @@ public class GenericMappingFileRef extends AbstractXmlContextNode
}
}
+ protected IFile getPlatformFile() {
+ if (fileName == null) {
+ return null;
+ }
+ IProject project = getJpaProject().getProject();
+ IVirtualFile vFile = ComponentCore.createFile(project, new Path(fileName));
+ return vFile.getUnderlyingFile();
+ }
+
protected MappingFile buildMappingFile(JpaXmlResource resource) {
XmlContextNode context = this.getJpaFactory().buildContextNode(this, resource);
try {
@@ -242,22 +245,30 @@ public class GenericMappingFileRef extends AbstractXmlContextNode
IMessage.HIGH_SEVERITY,
JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_MAPPING_FILE,
this,
- this.getValidationTextRange()
- )
- );
+ this.getValidationTextRange()));
return;
}
-
+
if (this.mappingFile == null) {
- messages.add(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE,
- new String[] {this.fileName},
- this,
- this.getValidationTextRange()
- )
- );
+ IFile platformFile = getPlatformFile();
+ if (platformFile != null && platformFile.exists()) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.PERSISTENCE_UNIT_UNSUPPORTED_MAPPING_FILE_CONTENT,
+ new String[] {this.fileName},
+ this,
+ this.getValidationTextRange()));
+ }
+ else {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE,
+ new String[] {this.fileName},
+ this,
+ this.getValidationTextRange()));
+ }
return;
}
@@ -268,9 +279,7 @@ public class GenericMappingFileRef extends AbstractXmlContextNode
JpaValidationMessages.PERSISTENCE_UNIT_INVALID_MAPPING_FILE,
new String[] {this.fileName},
this,
- this.getValidationTextRange()
- )
- );
+ this.getValidationTextRange()));
}
this.mappingFile.validate(messages);
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java
index cb578a1a1c..79cf8c74c9 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java
@@ -283,10 +283,10 @@ public class GenericJpaFactory
}
public XmlContextNode buildContextNode(JpaContextNode parent, JpaXmlResource resource) {
- if (resource instanceof PersistenceResource) {
+ if (resource.getType() == JpaFile.PERSISTENCE_RESOURCE_TYPE) {
return this.buildPersistenceXml((JpaRootContextNode) parent, (PersistenceResource) resource);
}
- if (resource instanceof OrmResource) {
+ if (resource.getType() == JpaFile.ORM_RESOURCE_TYPE) {
return this.buildOrmXml((MappingFileRef) parent, (OrmResource) resource);
}
return null;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java
index b2faee9eeb..28586e9b36 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java
@@ -23,6 +23,7 @@ public interface JpaValidationMessages {
public static final String PERSISTENCE_NO_PERSISTENCE_UNIT = "PERSISTENCE_NO_PERSISTENCE_UNIT";
public static final String PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS = "PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS";
public static final String PERSISTENCE_UNIT_UNSPECIFIED_MAPPING_FILE = "PERSISTENCE_UNIT_UNSPECIFIED_MAPPING_FILE";
+ public static final String PERSISTENCE_UNIT_UNSUPPORTED_MAPPING_FILE_CONTENT = "PERSISTENCE_UNIT_UNSUPPORTED_MAPPING_FILE_CONTENT";
public static final String PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE = "PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE";
public static final String PERSISTENCE_UNIT_INVALID_MAPPING_FILE = "PERSISTENCE_UNIT_INVALID_MAPPING_FILE";
public static final String PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE = "PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE";

Back to the top