[237467] Edit Model throws exception when closing unsaved file
[238160] Not finding adapter after target object removed
diff --git a/bundles/org.eclipse.wst.xml.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.xml.core/META-INF/MANIFEST.MF
index 452fd52..af632b8 100644
--- a/bundles/org.eclipse.wst.xml.core/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.xml.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.wst.xml.core; singleton:=true
-Bundle-Version: 1.1.300.qualifier
+Bundle-Version: 1.1.301.qualifier
Bundle-Activator: org.eclipse.wst.xml.core.internal.XMLCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSEAdapter.java b/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSEAdapter.java
index 83d6f5e..95e4f3c 100644
--- a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSEAdapter.java
+++ b/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSEAdapter.java
@@ -11,10 +11,8 @@
package org.eclipse.wst.xml.core.internal.emf2xml;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.ecore.EObject;
@@ -277,7 +275,7 @@
//Assert.isNotNull(childMap.getChildAdapterClass());
Assert.isNotNull(node);
- EMF2DOMAdapter adapter = primGetExistingAdapterForCreate(node);
+ EMF2DOMAdapter adapter = primGetExistingAdapter(node);
if (adapter != null) {
if (adapter.isMOFProxy() || adapter.getTarget() == null) {
@@ -298,7 +296,7 @@
// adapted. For instance a subtree that maps to a MOF attribute
// setting.
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
- EMF2DOMAdapter attrAdapter = primGetExistingAdapterForCreate(childNode);
+ EMF2DOMAdapter attrAdapter = primGetExistingAdapter(childNode);
if (attrAdapter == null || attrAdapter.getNode() != getNode()) {
// If the node is adapted, but not by this adapter then remove
@@ -314,62 +312,19 @@
}
}
}
-
+
protected EMF2DOMAdapter primGetExistingAdapter(Node aNode) {
INodeNotifier sseNode = (INodeNotifier) aNode;
Collection adapters = sseNode.getAdapters();
- List sse2domAdapters = new ArrayList();
for (Iterator iterator = adapters.iterator(); iterator.hasNext();) {
INodeAdapter adapter = (INodeAdapter) iterator.next();
// First Check if it's an EMF2DOMAdapter
if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
// Cast to EMF2DOMAdapter
EMF2DOMAdapter e2DAdapter = (EMF2DOMAdapter) adapter;
- // Check if targets are the resources
- if (getTarget() instanceof Resource) {
- /*
- * Now check if it's the right one (Multiple resources
- * could be attached)
- */
- if (e2DAdapter.getTarget() == getTarget()) {
- return e2DAdapter;
- }
- else {
- sse2domAdapters.add(e2DAdapter);
- continue;
- }
- } else {
- // Check if targets are EObjects with the same resources
- EObject myTarget = (EObject) getTarget();
- EObject adapterTarget = (EObject) e2DAdapter.getTarget();
- /*
- * Now check if it's the right one (Multiple resources could
- * be attached)
- */
- if (adapterTarget != null && myTarget != null && adapterTarget.eResource() == myTarget.eResource()) {
- return e2DAdapter;
- }
- sse2domAdapters.add(e2DAdapter);
- }
- }
- }
- if (sse2domAdapters.size() == 1) {
- return (EMF2DOMAdapter) sse2domAdapters.get(0);
- }
-
- //return (EMF2DOMAdapter) ((IDOMNode) aNode).getExistingAdapter(EMF2DOMAdapter.ADAPTER_CLASS);
- return null;
- }
-
- protected EMF2DOMAdapter primGetExistingAdapterForCreate(Node aNode) {
- INodeNotifier sseNode = (INodeNotifier) aNode;
- Collection adapters = sseNode.getAdapters();
- for (Iterator iterator = adapters.iterator(); iterator.hasNext();) {
- INodeAdapter adapter = (INodeAdapter) iterator.next();
- // First Check if it's an EMF2DOMAdapter
- if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
- // Cast to EMF2DOMAdapter
- EMF2DOMAdapter e2DAdapter = (EMF2DOMAdapter) adapter;
+ if (getTarget() == null || e2DAdapter.getTarget() == null)
+ return e2DAdapter;
+
// Check if target is an EMF resource
if (getTarget() instanceof Resource) {
/*
@@ -379,18 +334,24 @@
if (e2DAdapter.getTarget() == getTarget()) {
return e2DAdapter;
}
- else
- continue;
}
- // Check if targets are EObjects with the same resources
- EObject myTarget = (EObject) getTarget();
- EObject adapterTarget = (EObject) e2DAdapter.getTarget();
- /*
- * Now check if it's the right one (Multiple resources could
- * be attached)
- */
- if (adapterTarget != null && myTarget != null && adapterTarget.eResource() == myTarget.eResource()) {
- return e2DAdapter;
+ else {
+ // Check if targets are EObjects with the same resources
+ EObject myTarget = (EObject) getTarget();
+ EObject adapterTarget = (EObject) e2DAdapter.getTarget();
+ /*
+ * Now check if it's the right one (Multiple resources could
+ * be attached)
+ */
+ if (adapterTarget.eResource() == myTarget.eResource()) {
+ return e2DAdapter;
+ }
+ }
+
+ if (e2DAdapter.getTarget() instanceof EObject) {
+ if (((EObject) e2DAdapter.getTarget()).eResource() == null) {
+ return e2DAdapter;
+ }
}
}
}
diff --git a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERenderer.java b/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERenderer.java
index ccf8de7..18ef17b 100644
--- a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERenderer.java
+++ b/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERenderer.java
@@ -267,7 +267,6 @@
//return (EMF2DOMSSEAdapter) xNode.getAdapterFor(EMF2DOMAdapter.ADAPTER_CLASS);
INodeNotifier sseNode = (INodeNotifier) node;
- List sse2domAdapters = new ArrayList();
Collection adapters = sseNode.getAdapters();
for (Iterator iterator = adapters.iterator(); iterator.hasNext();) {
INodeAdapter adapter = (INodeAdapter) iterator.next();
@@ -275,8 +274,11 @@
if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
// Cast to EMF2DOMAdapter
EMF2DOMAdapter e2DAdapter = (EMF2DOMAdapter) adapter;
+ if (getResource() == null || e2DAdapter.getTarget() == null)
+ return e2DAdapter;
+
// First check if targets are resources
- if (e2DAdapter.getTarget() != null && e2DAdapter.getTarget() instanceof Resource) {
+ if (e2DAdapter.getTarget() instanceof Resource) {
/*
* Now check if it's the right one (Multiple resources
* could be attached)
@@ -284,10 +286,6 @@
if (e2DAdapter.getTarget() == getResource()) {
return e2DAdapter;
}
- else {
- sse2domAdapters.add(e2DAdapter);
- continue;
- }
} else {
// Check if targets are EObjects with the same resources
TranslatorResource myTarget = getResource();
@@ -296,16 +294,12 @@
* Now check if it's the right one (Multiple resources could
* be attached)
*/
- if (adapterTarget != null && myTarget != null && adapterTarget.eResource() == myTarget) {
+ if (adapterTarget.eResource() == myTarget || adapterTarget.eResource() == null) {
return e2DAdapter;
}
- sse2domAdapters.add(e2DAdapter);
}
}
}
- if (sse2domAdapters.size() == 1) {
- return (EMF2DOMAdapter) sse2domAdapters.get(0);
- }
return null;
}
@@ -434,26 +428,24 @@
if (isBatchChanges)
return;
try {
- if (aboutToChangeNode != null && model.getStructuredDocument() != null && model.getStructuredDocument().getFirstStructuredDocumentRegion() != aboutToChangeNode) {
- String id = getModelManagerId();
- IStructuredModel tempModel = null;
+ if (aboutToChangeNode != null
+ && model.getStructuredDocument() != null
+ && model.getStructuredDocument()
+ .getFirstStructuredDocumentRegion() != aboutToChangeNode) {
+ modelAccessForWrite();
try {
- tempModel = getModelManager().getExistingModelForEdit(id);
xmlModelReverted = true;
resource.unload();
- }
- finally {
- if (tempModel != null) {
- tempModel.releaseFromEdit();
- }
+ } finally {
+ if (getXMLModel() != null)
+ getXMLModel().releaseFromEdit();
}
}
- }
- finally {
+ } finally {
aboutToChangeNode = null;
}
- }
-
+ }
+
public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty) {
if (!isDirty && resource.isModified()) { // The XMLModel was saved
resource.setModified(false);