Optimization for slow UML element creation

This optimization avoids cross referencing when new elements are
initially attached to a model. This optimization really belongs into the
standard UML code and I'm going to submit a respective review in a few
minutes. This patch is here mostly so that you can continue to test
big models with CDO. Beware that you should not remigrate the UML2
model to CDO before the UML2 project has accepted and merged the change.

Change-Id: I87deddccc0db1730e93185495b38bcfa235bb403
Signed-off-by: Eike Stepper <stepper@esc-net.de>
diff --git a/cdo/bundles/uml/org.eclipse.uml2.uml.cdo/src/org/eclipse/uml2/uml/cdo/internal/impl/ElementImpl.java b/cdo/bundles/uml/org.eclipse.uml2.uml.cdo/src/org/eclipse/uml2/uml/cdo/internal/impl/ElementImpl.java
index 01c273e..6c780a2 100644
--- a/cdo/bundles/uml/org.eclipse.uml2.uml.cdo/src/org/eclipse/uml2/uml/cdo/internal/impl/ElementImpl.java
+++ b/cdo/bundles/uml/org.eclipse.uml2.uml.cdo/src/org/eclipse/uml2/uml/cdo/internal/impl/ElementImpl.java
@@ -900,11 +900,12 @@
 	public NotificationChain eBasicSetContainer(InternalEObject newContainer,
 			int newContainerFeatureID, NotificationChain msgs) {
 
+		InternalEObject oldContainer = eInternalContainer();
+		
 		if (eDirectResource() != null && newContainer != null
 			&& eContainmentFeature(this, newContainer,
 				newContainerFeatureID) == null) {
 
-			InternalEObject oldContainer = eInternalContainer();
 			int oldContainerFeatureID = eContainerFeatureID();
 
 			eBasicSetContainer(newContainer, newContainerFeatureID);
@@ -944,15 +945,19 @@
 				msgs);
 		}
 
-		if (newContainer != null && (CHANGE_DESCRIPTION_CLASS == null
-			|| !(CHANGE_DESCRIPTION_CLASS.isInstance(newContainer)))) {
+		if (CHANGE_DESCRIPTION_CLASS == null
+			|| !(CHANGE_DESCRIPTION_CLASS.isInstance(newContainer))) {
 
 			Resource.Internal eInternalResource = eInternalResource();
-
 			if (eInternalResource == null || !eInternalResource.isLoading()) {
-				ElementOperations.unapplyAllNonApplicableStereotypes(this,
-					false);
-				ElementOperations.applyAllRequiredStereotypes(this, false);
+
+				if (oldContainer != null) {
+					ElementOperations.unapplyAllNonApplicableStereotypes(this, false);
+				}
+				
+				if (newContainer != null) {
+					ElementOperations.applyAllRequiredStereotypes(this, false);
+				}
 			}
 		}