Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authornhauge2010-05-20 04:45:30 +0000
committernhauge2010-05-20 04:45:30 +0000
commit35beb8e3585d5ee20770c400178c47da6f9e64aa (patch)
treeb74204969109fd92cbeddd04d58ea308c6288650 /jpa
parente4d29d109a117d347ae9a07af9d8de1e486e20fb (diff)
downloadwebtools.dali-35beb8e3585d5ee20770c400178c47da6f9e64aa.tar.gz
webtools.dali-35beb8e3585d5ee20770c400178c47da6f9e64aa.tar.xz
webtools.dali-35beb8e3585d5ee20770c400178c47da6f9e64aa.zip
313405 - better validation for persistence and orm xml when content is not valid. Checking in patch for Paul.
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties9
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java66
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericRootContextNode.java33
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java1
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java2
5 files changed, 62 insertions, 49 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 9e4e16b54b..7ef934e0dc 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
@@ -14,13 +14,14 @@ PROJECT_INACTIVE_CONNECTION=Connection \"{0}\" is not active. No validation wil
PROJECT_NO_PERSISTENCE_XML=No persistence.xml file found in project
PROJECT_MULTIPLE_PERSISTENCE_XML=Multiple persistence.xml files in project
XML_VERSION_NOT_LATEST=A more recent version of this document is supported by this JPA platform
-PERSISTENCE_XML_INVALID_CONTENT=Invalid content (no root node)
+PERSISTENCE_XML_INVALID_CONTENT=The persistence.xml file does not have recognized content.
+PERSISTENCE_XML_UNSUPPORTED_CONTENT=The persistence.xml file does not have supported content for this JPA platform.
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_UNSUPPORTED_MAPPING_FILE_CONTENT=Mapping file {0} does not have supported content for this JPA platform.
+PERSISTENCE_UNIT_INVALID_MAPPING_FILE=Mapping file {0} does not have recognized content.
+PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE=Mapping file \"{0}\" cannot be resolved.
PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE=Duplicate mapping file \"{0}\"
PERSISTENCE_UNIT_UNSPECIFIED_CLASS=Unspecified class
PERSISTENCE_UNIT_NONEXISTENT_CLASS=Class \"{0}\" cannot be resolved
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java
index 9594048ed7..c38e23e3b4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java
@@ -225,55 +225,53 @@ public abstract class AbstractMappingFileRef
@Override
public void validate(List<IMessage> messages, IReporter reporter) {
super.validate(messages, reporter);
-
+
if (StringTools.stringIsEmpty(this.fileName)) {
messages.add(
DefaultJpaValidationMessages.buildMessage(
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,
- this.buildMissingMappingFileMessageID(),
- new String[] {this.fileName},
- this,
- this.getValidationTextRange()
- )
- );
+ messages.add(buildMappingFileValidationMessage());
return;
}
-
- if (this.mappingFile.getRoot() == null) {
- messages.add(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JpaValidationMessages.PERSISTENCE_UNIT_INVALID_MAPPING_FILE,
- new String[] {this.fileName},
- this,
- this.getValidationTextRange()
- )
- );
- }
-
+
this.mappingFile.validate(messages, reporter);
}
-
- protected String buildMissingMappingFileMessageID() {
- return this.getPlatformFile().exists() ?
- JpaValidationMessages.PERSISTENCE_UNIT_UNSUPPORTED_MAPPING_FILE_CONTENT :
- JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE;
+
+ protected IMessage buildMappingFileValidationMessage() {
+ int severity = IMessage.HIGH_SEVERITY;
+ IFile file = getPlatformFile();
+ if (file.exists()) {
+ JpaXmlResource xmlResource = getJpaProject().getMappingFileXmlResource(this.fileName);
+ if (xmlResource != null
+ && ! getJpaPlatform().supportsResourceType(xmlResource.getResourceType())) {
+ return DefaultJpaValidationMessages.buildMessage(
+ severity,
+ JpaValidationMessages.PERSISTENCE_UNIT_UNSUPPORTED_MAPPING_FILE_CONTENT,
+ new String[] {file.getName()},
+ file);
+ }
+ return DefaultJpaValidationMessages.buildMessage(
+ severity,
+ JpaValidationMessages.PERSISTENCE_UNIT_INVALID_MAPPING_FILE,
+ new String[] {file.getName()},
+ file);
+ }
+ return DefaultJpaValidationMessages.buildMessage(
+ severity,
+ JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE,
+ new String[] {this.fileName},
+ this,
+ getValidationTextRange());
}
-
+
protected IFile getPlatformFile() {
return this.getJpaProject().convertToPlatformFile(this.fileName);
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericRootContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericRootContextNode.java
index 2c9fa061eb..1625ac7ff4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericRootContextNode.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericRootContextNode.java
@@ -192,13 +192,7 @@ public class GenericRootContextNode
}
if (this.persistenceXml == null) {
- messages.add(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- this.buildMissingFileMessageID(),
- this
- )
- );
+ messages.add(buildPersistenceXmlValidationMessage());
return;
}
if ( ! this.jpaProject.discoversAnnotatedClasses()) {
@@ -207,10 +201,27 @@ public class GenericRootContextNode
this.persistenceXml.validate(messages, reporter);
}
- protected String buildMissingFileMessageID() {
- return this.getPlatformFile().exists() ?
- JpaValidationMessages.PERSISTENCE_XML_INVALID_CONTENT :
- JpaValidationMessages.PROJECT_NO_PERSISTENCE_XML;
+ protected IMessage buildPersistenceXmlValidationMessage() {
+ int severity = IMessage.HIGH_SEVERITY;
+ IFile file = getPlatformFile();
+ if (file.exists()) {
+ JpaXmlResource xmlResource = this.jpaProject.getPersistenceXmlResource();
+ if (xmlResource != null
+ && ! getJpaPlatform().supportsResourceType(xmlResource.getResourceType())) {
+ return DefaultJpaValidationMessages.buildMessage(
+ severity,
+ JpaValidationMessages.PERSISTENCE_XML_UNSUPPORTED_CONTENT,
+ file);
+ }
+ return DefaultJpaValidationMessages.buildMessage(
+ severity,
+ JpaValidationMessages.PERSISTENCE_XML_INVALID_CONTENT,
+ file);
+ }
+ return DefaultJpaValidationMessages.buildMessage(
+ severity,
+ JpaValidationMessages.PROJECT_NO_PERSISTENCE_XML,
+ this);
}
protected IFile getPlatformFile() {
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 f99cf1d708..d559a919de 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
@@ -21,6 +21,7 @@ public interface JpaValidationMessages {
public static final String PROJECT_MULTIPLE_PERSISTENCE_XML = "PROJECT_MULTIPLE_PERSISTENCE_XML";
public static final String XML_VERSION_NOT_LATEST = "XML_VERSION_NOT_LATEST";
public static final String PERSISTENCE_XML_INVALID_CONTENT = "PERSISTENCE_XML_INVALID_CONTENT";
+ public static final String PERSISTENCE_XML_UNSUPPORTED_CONTENT = "PERSISTENCE_XML_UNSUPPORTED_CONTENT";
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";
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java
index 04e3c1058a..d08d7af1c7 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java
@@ -160,6 +160,7 @@ public abstract class BaseJpaPlatformUi
return definition;
}
}
+ // TODO (bug 313632) - return a null resource ui definition?
throw new IllegalArgumentException("No resource UI definition for the resource type: " + resourceType); //$NON-NLS-1$
}
@@ -168,6 +169,7 @@ public abstract class BaseJpaPlatformUi
return (MappingResourceUiDefinition) getResourceUiDefinition(resourceType);
}
catch (ClassCastException cce) {
+ // TODO (bug 313632) - return a null resource ui definition?
throw new IllegalArgumentException("No mapping resource UI definition for the resource type: " + resourceType, cce); //$NON-NLS-1$
}
}

Back to the top