Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java')
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java84
1 files changed, 25 insertions, 59 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
index 33c7fb9e9d..b27bb6f4ba 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
@@ -16,7 +16,6 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
-import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
@@ -24,7 +23,6 @@ import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.Generator;
import org.eclipse.jpt.jpa.core.context.MappingFile;
import org.eclipse.jpt.jpa.core.context.MappingFilePersistenceUnitMetadata;
-import org.eclipse.jpt.jpa.core.context.MappingFileRoot;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.Query;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
@@ -32,7 +30,6 @@ import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
-import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
import org.eclipse.text.edits.DeleteEdit;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -43,7 +40,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter;
* <br>
* <code>mapping-file</code> element
*/
-public abstract class AbstractMappingFileRef
+public abstract class AbstractMappingFileRef<MF extends MappingFile>
extends AbstractPersistenceXmlContextNode
implements MappingFileRef
{
@@ -53,7 +50,7 @@ public abstract class AbstractMappingFileRef
* The mapping file corresponding to the ref's file name.
* This can be <code>null</code> if the name is invalid.
*/
- protected MappingFile mappingFile;
+ protected MF mappingFile;
// ********** construction/initialization **********
@@ -86,10 +83,6 @@ public abstract class AbstractMappingFileRef
return this.fileName;
}
- public boolean isFor(IFile file) {
- return (this.mappingFile != null) && file.equals(this.mappingFile.getXmlResource().getFile());
- }
-
protected boolean isIn(IFolder folder) {
return (this.mappingFile != null) && this.mappingFile.isIn(folder);
}
@@ -101,16 +94,13 @@ public abstract class AbstractMappingFileRef
return this.mappingFile;
}
- protected void setMappingFile(MappingFile mappingFile) {
+ protected void setMappingFile(MF mappingFile) {
MappingFile old = this.mappingFile;
this.mappingFile = mappingFile;
this.firePropertyChanged(MAPPING_FILE_PROPERTY, old, mappingFile);
}
- protected MappingFile buildMappingFile() {
- JpaXmlResource xmlResource = this.resolveMappingFileXmlResource();
- return (xmlResource == null) ? null : this.buildMappingFile(xmlResource);
- }
+ protected abstract MF buildMappingFile();
protected void syncMappingFile() {
this.syncMappingFile(true);
@@ -122,23 +112,23 @@ public abstract class AbstractMappingFileRef
* <li>a <em>sync</em> will occur when the file is edited directly;
* and the user could modify something (e.g. the version number) that
* triggers the file being "resolved" or not;
- * see {@link #resolveMappingFileXmlResource()}
+ * see {@link #resolveResourceMappingFile()}
* <li>an <em>update</em> will occur whenever the entire file is added or
* removed
* </ul>
*/
protected void syncMappingFile(boolean sync) {
- JpaXmlResource newXmlResource = this.resolveMappingFileXmlResource();
- if (newXmlResource == null) {
+ Object newResourceMappingFile = this.resolveResourceMappingFile();
+ if (newResourceMappingFile == null) {
if (this.mappingFile != null) {
this.mappingFile.dispose();
this.setMappingFile(null);
}
} else {
if (this.mappingFile == null) {
- this.setMappingFile(this.buildMappingFile(newXmlResource));
+ this.setMappingFile(this.buildMappingFile(newResourceMappingFile));
} else {
- if (this.mappingFile.getXmlResource() == newXmlResource) {
+ if (this.mappingFile.getResourceMappingFile() == newResourceMappingFile) {
if (sync) {
this.mappingFile.synchronizeWithResourceModel();
} else {
@@ -150,49 +140,24 @@ public abstract class AbstractMappingFileRef
// [I have hit this before (had this println uncommmented),
// but I am not sure how... ~kfb]
// [I hit this by deleting the implied orm.xml file and then adding it back, I think
- // it will not be possible to hit it now that I null out the mappingFile is dispose() ~kfb]
+ // it will not be possible to hit it now that I null out the mappingFile in dispose() ~kfb]
// System.out.println("AbstractMappingFileRef.syncMappingFile");
// if the resource's content type has changed, we completely rebuild the mapping file
this.mappingFile.dispose();
- this.setMappingFile(this.buildMappingFile(newXmlResource));
+ this.setMappingFile(this.buildMappingFile(newResourceMappingFile));
}
}
}
}
- /**
- * The mapping file ref resource is in the persistence xml resource
- * (<code>persistence.xml</code>). This returns the resource of
- * the mapping file itself (<code>orm.xml</code>).
- */
- protected JpaXmlResource resolveMappingFileXmlResource() {
- if (this.fileName == null) {
- return null;
- }
- JpaXmlResource xmlResource = this.getJpaProject().getMappingFileXmlResource(new Path(this.fileName));
- if (xmlResource == null) {
- return null;
- }
- if (xmlResource.isReverting()) {
- // 308254 - this can happen when orm.xml is closed without saving;
- // the model is completely whacked in another thread - so wipe our model(?)
- return null;
- }
- JptResourceType resourceType = xmlResource.getResourceType();
- if (resourceType == null) {
- return null;
- }
- if ( ! this.getJpaPlatform().supportsResourceType(resourceType)) {
- return null;
- }
- return xmlResource;
- }
+ protected abstract Object resolveResourceMappingFile();
/**
- * pre-condition: 'xmlResource' is not <code>null</code>
+ * pre-condition: 'resourceMappingFile' is not <code>null</code>
*/
- protected MappingFile buildMappingFile(JpaXmlResource xmlResource) {
- return this.getJpaFactory().buildMappingFile(this, xmlResource);
+ @SuppressWarnings("unchecked")
+ protected MF buildMappingFile(Object resourceMappingFile) {
+ return (MF) this.getJpaFactory().buildMappingFile(this, resourceMappingFile);
}
protected void updateMappingFile() {
@@ -242,7 +207,7 @@ public abstract class AbstractMappingFileRef
}
public MappingFilePersistenceUnitMetadata getPersistenceUnitMetadata() {
- MappingFileRoot root = this.getChildMappingFileRoot();
+ MappingFile.Root root = this.getChildMappingFileRoot();
return (root == null) ? null : root.getPersistenceUnitMetadata();
}
@@ -254,7 +219,7 @@ public abstract class AbstractMappingFileRef
* "mapping file root" contained by the mapping file ref (since, actually,
* the mapping file ref is not even contained by a "mapping file root").
*/
- protected MappingFileRoot getChildMappingFileRoot() {
+ protected MappingFile.Root getChildMappingFileRoot() {
return (this.mappingFile == null) ? null : this.mappingFile.getRoot();
}
@@ -297,14 +262,14 @@ public abstract class AbstractMappingFileRef
}
if (this.mappingFile == null) {
- messages.add(this.buildMappingFileValidationMessage());
+ messages.add(this.buildMissingMappingFileValidationMessage());
return;
}
this.mappingFile.validate(messages, reporter);
}
- protected IMessage buildMappingFileValidationMessage() {
+ protected IMessage buildMissingMappingFileValidationMessage() {
int severity = IMessage.HIGH_SEVERITY;
IFile file = this.getPlatformFile();
if ( ! file.exists()) {
@@ -334,10 +299,7 @@ public abstract class AbstractMappingFileRef
/**
* pre-condition: {@link #getPlatformFile()} exists
*/
- protected boolean mappingFileContentIsUnsupported() {
- JpaXmlResource xmlResource = this.getJpaProject().getMappingFileXmlResource(new Path(this.fileName));
- return (xmlResource != null) && ! this.getJpaPlatform().supportsResourceType(xmlResource.getResourceType());
- }
+ protected abstract boolean mappingFileContentIsUnsupported();
// ********** refactoring **********
@@ -381,4 +343,8 @@ public abstract class AbstractMappingFileRef
}
protected abstract ReplaceEdit createMoveEdit(IFile originalFile, IPath runtineDestination);
+
+ protected boolean isFor(IFile file) {
+ return (this.mappingFile != null) && file.equals(this.mappingFile.getResource());
+ }
}

Back to the top