[321794] ClassCast exception can occur while updating XML model adapted to two EMF models
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 2ebce04..7c13264 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
@@ -104,6 +104,60 @@
 			Logger.log(Logger.INFO_DEBUG, "\tnewValue      : " + newValue); //$NON-NLS-1$
 		}
 	}
+	
+	protected EMF2DOMAdapter primGetExistingAdapter(Node aNode, Translator childMap) {
+		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
+				EMF2DOMSSEAdapter e2DAdapter = (EMF2DOMSSEAdapter) adapter;
+				Object adapterTarget = e2DAdapter.getTarget();
+				//Translator adapterTranslator = e2DAdapter.fTranslator;
+				
+				//Handle the cases where either adapter's target is null 
+				if ((getTarget() == null) || (adapterTarget == null))
+					if (resourceClass != null && resourceClass.equals(e2DAdapter.getResourceClass()))
+						return e2DAdapter;
+					else
+						continue;
+				
+				
+				// Check if target is an EMF resource
+				if (getTarget() instanceof Resource) {
+					/*
+					 * Now check if it's the right one (Multiple resources
+					 * could be attached)
+					 */
+					if (adapterTarget != null && adapterTarget == getTarget()) {
+						return e2DAdapter;
+					}
+				}
+				else {
+					// Check if targets are EObjects with the same resources
+					EObject myTarget = (EObject) getTarget();
+					/*
+					 * Now check if it's the right one (Multiple resources could
+					 * be attached)
+					 */
+					if (adapterTarget != null && ((EObject)adapterTarget).eResource() == myTarget.eResource()) {
+						return e2DAdapter;
+					}
+				}
+				
+				if (adapterTarget instanceof EObject) {
+					if (((EObject) e2DAdapter.getTarget()).eResource() == null && e2DAdapter.fTranslator == childMap) {
+						return e2DAdapter;
+					}
+				}
+			}
+		}
+		return null;
+	}
+	
+
 
 	protected void disableUndoManagementIfNecessary() {
 		IDOMModel model = getXMLModel();
@@ -276,7 +330,7 @@
 		//Assert.isNotNull(childMap.getChildAdapterClass());
 		Assert.isNotNull(node);
 
-		EMF2DOMAdapter adapter = primGetExistingAdapter(node);
+		EMF2DOMAdapter adapter = primGetExistingAdapter(node,childMap);
 
 		if (adapter != null) {
 			if (adapter.isMOFProxy() || adapter.getTarget() == null) {
diff --git a/features/org.eclipse.wst.xml_core.feature.patch/buildnotes_org.eclipse.wst.xml_core.feature.patch.html b/features/org.eclipse.wst.xml_core.feature.patch/buildnotes_org.eclipse.wst.xml_core.feature.patch.html
index 0c94a81..cef4229 100644
--- a/features/org.eclipse.wst.xml_core.feature.patch/buildnotes_org.eclipse.wst.xml_core.feature.patch.html
+++ b/features/org.eclipse.wst.xml_core.feature.patch/buildnotes_org.eclipse.wst.xml_core.feature.patch.html
@@ -30,5 +30,6 @@
 <p>Bug <a href='https://bugs.eclipse.org/308548'>308548</a>. XSD to XML generator can cause an out of memory error on certain types of documents</p>
 <p>Bug <a href='https://bugs.eclipse.org/316222'>316222</a>. [parser] < or > in attribute values are not supported</p>
 <p>Bug <a href='https://bugs.eclipse.org/316551'>316551</a>. [parser] Is HTML DOM correctly treating implicitly-closed tags?</p>
+<p>Bug <a href='https://bugs.eclipse.org/321794'>321794</a>. ClassCast exception can occur while updating XML model adapted to two EMF models</p>
 </body>
 </head>
\ No newline at end of file
diff --git a/features/org.eclipse.wst.xml_core.feature.patch/feature.properties b/features/org.eclipse.wst.xml_core.feature.patch/feature.properties
index 3e94307..618e6d9 100644
--- a/features/org.eclipse.wst.xml_core.feature.patch/feature.properties
+++ b/features/org.eclipse.wst.xml_core.feature.patch/feature.properties
@@ -48,6 +48,7 @@
 Bug https://bugs.eclipse.org/308548 XSD to XML generator can cause an out of memory error on certain types of documents\n\
 Bug https://bugs.eclipse.org/316222 [parser] < or > in attribute values are not supported\n\
 Bug https://bugs.eclipse.org/316551 [parser] Is HTML DOM correctly treating implicitly-closed tags?\n\
+Bug https://bugs.eclipse.org/321794 ClassCast exception can occur while updating XML model adapted to two EMF models\n\
 \n\
 
 # "copyright" property - text of the "Feature Update Copyright"