Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2013-01-03 19:45:58 +0000
committerChristian W. Damus2013-01-07 13:56:48 +0000
commitdd07f4c6e437c657336df6f76eadea0beab5ff57 (patch)
tree8cf77bf39c28e8b7c353835d2496a4a997297da5
parentf81041496d650d8dfb3410890fcdface9f3d07fb (diff)
downloadcdo-dd07f4c6e437c657336df6f76eadea0beab5ff57.tar.gz
cdo-dd07f4c6e437c657336df6f76eadea0beab5ff57.tar.xz
cdo-dd07f4c6e437c657336df6f76eadea0beab5ff57.zip
[397405] Don't check EAnnotations for resolvable proxies
https://bugs.eclipse.org/bugs/show_bug.cgi?id=397405
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java106
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java22
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/AllUMLTests.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/DynamicProfileTest.java173
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/RegisteredDynamicProfileTest.java198
5 files changed, 252 insertions, 253 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java
index f9da7208b4..b51bc3332d 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2013 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* Eike Stepper - initial API and implementation
* Stefan Winkler - Bug 332912 - Caching subtype-relationships in the CDOPackageRegistry
* Erdal Karaca - added support for HASHMAP CDO Type
+ * Christian W. Damus (CEA) - don't validate cross-references in EAnnotations
*/
package org.eclipse.emf.cdo.common.model;
@@ -28,6 +29,7 @@ import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
@@ -572,63 +574,73 @@ public final class CDOModelUtil implements CDOModelConstants
while (it.hasNext())
{
EObject e = it.next();
- for (EObject r : e.eCrossReferences())
- {
- EObject refTarget = null;
- if (r.eIsProxy())
+ if (e instanceof EAnnotation)
+ {
+ // we don't need to validate the structure of annotations. The applications that
+ // define annotations will have to take what they can get
+ it.prune();
+ }
+ else
+ {
+ for (EObject r : e.eCrossReferences())
{
- String msg = "Package '%s' contains unresolved proxy '%s'";
- msg = String.format(msg, ePackage.getNsURI(), ((InternalEObject)r).eProxyURI());
- throw new IllegalStateException(msg);
- }
+ EObject refTarget = null;
- if (r.eResource() != null && r.eResource() != e.eResource())
- {
- // It's a ref into another resource
- EPackage pkg = null;
- if (r instanceof EClassifier)
- {
- refTarget = r;
- pkg = ((EClassifier)r).getEPackage();
- }
- else if (r instanceof EStructuralFeature)
+ if (r.eIsProxy())
{
- refTarget = r;
- EStructuralFeature feature = (EStructuralFeature)r;
- EClass ownerClass = (EClass)feature.eContainer();
- pkg = ownerClass.getEPackage();
+ String msg = "Package '%s' contains unresolved proxy '%s'";
+ msg = String.format(msg, ePackage.getNsURI(), ((InternalEObject)r).eProxyURI());
+ throw new IllegalStateException(msg);
}
- else if (r instanceof EGenericType)
+
+ if (r.eResource() != null && r.eResource() != e.eResource())
{
- EGenericType genType = (EGenericType)r;
- EClassifier c = genType.getEClassifier();
- if (c != null)
+ // It's a ref into another resource
+ EPackage pkg = null;
+ if (r instanceof EClassifier)
{
- refTarget = c;
- pkg = c.getEPackage();
+ refTarget = r;
+ pkg = ((EClassifier)r).getEPackage();
+ }
+ else if (r instanceof EStructuralFeature)
+ {
+ refTarget = r;
+ EStructuralFeature feature = (EStructuralFeature)r;
+ EClass ownerClass = (EClass)feature.eContainer();
+ pkg = ownerClass.getEPackage();
+ }
+ else if (r instanceof EGenericType)
+ {
+ EGenericType genType = (EGenericType)r;
+ EClassifier c = genType.getEClassifier();
+ if (c != null)
+ {
+ refTarget = c;
+ pkg = c.getEPackage();
+ }
}
- }
- if (pkg == null)
- {
- continue;
- }
+ if (pkg == null)
+ {
+ continue;
+ }
- while (pkg.getESuperPackage() != null)
- {
- pkg = pkg.getESuperPackage();
- }
+ while (pkg.getESuperPackage() != null)
+ {
+ pkg = pkg.getESuperPackage();
+ }
- String resourceURI = refTarget.eResource().getURI().toString();
- if (!resourceURI.toString().equals(pkg.getNsURI()))
- {
- String msg = "URI of the resource (%s) does not match the nsURI (%s) of the top-level package;\n"
- + "this can be fixed by calling Resource.setURI(URI) after loading the packages,\n"
- + "or by configuring a URI mapping from nsURI's to location URI's before loading the packages,\n"
- + "and then loading them with their nsURI's";
- msg = String.format(msg, resourceURI, pkg.getNsURI());
- throw new IllegalStateException(msg);
+ String resourceURI = refTarget.eResource().getURI().toString();
+ if (!resourceURI.toString().equals(pkg.getNsURI()))
+ {
+ String msg = "URI of the resource (%s) does not match the nsURI (%s) of the top-level package;\n"
+ + "this can be fixed by calling Resource.setURI(URI) after loading the packages,\n"
+ + "or by configuring a URI mapping from nsURI's to location URI's before loading the packages,\n"
+ + "and then loading them with their nsURI's";
+ msg = String.format(msg, resourceURI, pkg.getNsURI());
+ throw new IllegalStateException(msg);
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
index b6b3558498..3c0aaf1132 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2013 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,7 +9,8 @@
* Eike Stepper - initial API and implementation
* Victor Roldan Betancort - maintenance
* Simon McDuff - maintenance
- * Christian W. Damus - support registered dynamic UML profiles
+ * Christian W. Damus (CEA) - support registered dynamic UML profiles
+ * Christian W. Damus (CEA) - don't process EAnnotations for proxy resolution
*/
package org.eclipse.emf.cdo.common.model;
@@ -22,6 +23,7 @@ import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
@@ -571,10 +573,20 @@ public final class EMFUtil
if (notifier instanceof EObject)
{
safeResolve((EObject)notifier, resourceSet);
- Iterator<EObject> it2 = ((EObject)notifier).eCrossReferences().iterator();
- while (it2.hasNext())
+
+ if (notifier instanceof EAnnotation)
+ {
+ // we don't need to validate the structure of annotations. The applications that
+ // define annotations will have to take what they can get
+ it.prune();
+ }
+ else
{
- safeResolve(it2.next(), resourceSet);
+ Iterator<EObject> it2 = ((EObject)notifier).eCrossReferences().iterator();
+ while (it2.hasNext())
+ {
+ safeResolve(it2.next(), resourceSet);
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/AllUMLTests.java b/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/AllUMLTests.java
index 7ce028d60a..a34497c006 100644
--- a/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/AllUMLTests.java
+++ b/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/AllUMLTests.java
@@ -1,12 +1,12 @@
/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * Copyright (c) 2004 - 2013 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Christian W. Damus - initial API and implementation
+ * Christian W. Damus (CEA) - initial API and implementation
*/
package org.eclipse.emf.cdo.tests.uml;
@@ -41,6 +41,6 @@ public class AllUMLTests extends ConfigTestSuite
protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario)
{
testClasses.add(LegacyDynamicPackageTest.class);
- testClasses.add(RegisteredDynamicProfileTest.class);
+ testClasses.add(DynamicProfileTest.class);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/DynamicProfileTest.java b/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/DynamicProfileTest.java
new file mode 100644
index 0000000000..05ba4a4cb4
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/DynamicProfileTest.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2004 - 2013 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus (CEA) - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.uml;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
+import org.eclipse.emf.cdo.tests.config.impl.ModelConfig;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+import org.eclipse.uml2.common.util.UML2Util;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.resource.UMLResource;
+
+/**
+ * Tests legacy-mode support for dynamic UML Profiles.
+ */
+@Requires(ModelConfig.CAPABILITY_LEGACY)
+public class DynamicProfileTest extends AbstractCDOTest
+{
+ private final EPackage stuffPackage = EPackage.Registry.INSTANCE
+ .getEPackage("http://www.eclipse.org/cdo/tests/schema/stuff/1.0");
+
+ private final EFactory originalStuffFactory = stuffPackage.getEFactoryInstance();
+
+ private static final String MY_PROFILE_URI = "http://www.eclipse.org/cdo/tests/schema/myprofile";
+
+ private static final String S_CONCEPT = "Concept";
+
+ //
+ // Test cases
+ //
+
+ public void testInstancesOfRegisteredDynamicUMLProfile() throws Exception
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(UMLPackage.eINSTANCE);
+
+ ResourceSet rset = new ResourceSetImpl();
+ CDOTransaction transaction = session.openTransaction(rset);
+ CDOResource res = transaction.createResource(getResourcePath("/model1.uml"));
+
+ Model umlModel = UMLFactory.eINSTANCE.createModel();
+ res.getContents().add(umlModel);
+
+ umlModel.setName("model");
+ org.eclipse.uml2.uml.Class aClass = umlModel.createOwnedClass("Fruit", true);
+
+ Profile profile = UML2Util.load(rset, URI.createURI(MY_PROFILE_URI), UMLPackage.Literals.PROFILE);
+ assertNotNull(profile);
+
+ umlModel.applyProfile(profile);
+
+ Stereotype conceptStereotype = profile.getOwnedStereotype(S_CONCEPT);
+ aClass.applyStereotype(conceptStereotype);
+
+ transaction.commit();
+
+ // load the model again in a new session (hence new package registry)
+ session.close();
+ session = openSession();
+
+ transaction = session.openTransaction();
+ res = transaction.getResource(getResourcePath("/model1.uml"), true);
+
+ assertEquals(true, res.isLoaded());
+ assertEquals(2, res.getContents().size()); // the model and the stereotype instance
+
+ umlModel = (Model)res.getContents().get(0);
+ aClass = (org.eclipse.uml2.uml.Class)EcoreUtil.getObjectByType(umlModel.getOwnedTypes(), UMLPackage.Literals.CLASS);
+ assertNotNull(aClass);
+
+ // verify that using the UML API to access the applied stereotype works as usual
+ assertEquals("Stereotype doesn't appear to be applied.", true, aClass.isStereotypeApplied(conceptStereotype));
+ assertEquals("Wrong stereotype EClass.",
+ transaction.getResourceSet().getPackageRegistry().getEPackage(MY_PROFILE_URI).getEClassifier(S_CONCEPT), aClass
+ .getStereotypeApplication(conceptStereotype).eClass());
+ }
+
+ public void testInstancesOfLocalDynamicUMLProfile() throws Exception
+ {
+ CDOSession session = openSession();
+ session.getPackageRegistry().putEPackage(UMLPackage.eINSTANCE);
+
+ ResourceSet rset = new ResourceSetImpl();
+ CDOTransaction transaction = session.openTransaction(rset);
+ CDOResource res = transaction.createResource(getResourcePath("/model1.uml"));
+
+ Model umlModel = UMLFactory.eINSTANCE.createModel();
+ res.getContents().add(umlModel);
+
+ umlModel.setName("model");
+ org.eclipse.uml2.uml.Class aClass = umlModel.createOwnedClass("Fruit", true);
+
+ CDOResource profileRes = transaction.createResource(getResourcePath("/profile1.profile.uml"));
+
+ // create a local profile resource in the repository
+ Profile profile = UMLFactory.eINSTANCE.createProfile();
+ profileRes.getContents().add(profile);
+ profile.setName("MyProfile");
+ Stereotype conceptStereotype = profile.createOwnedStereotype(S_CONCEPT, false);
+ Model uml = UML2Util.load(rset, URI.createURI(UMLResource.UML_METAMODEL_URI), UMLPackage.Literals.MODEL);
+ profile.createMetamodelReference(uml);
+ conceptStereotype.createExtension((org.eclipse.uml2.uml.Class)uml.getOwnedType("Classifier"), false);
+ EPackage definition = profile.define();
+
+ // condition the Ecore definition for CDO
+ CDOUtil.prepareDynamicEPackage(definition);
+
+ // apply the profile and stereotype to the model
+ umlModel.applyProfile(profile);
+ aClass.applyStereotype(conceptStereotype);
+ assertEquals("Stereotype not applied.", true, aClass.isStereotypeApplied(conceptStereotype));
+
+ transaction.commit();
+
+ // load the model again in a new session (hence new package registry)
+ session.close();
+ session = openSession();
+
+ transaction = session.openTransaction();
+ res = transaction.getResource(getResourcePath("/model1.uml"), true);
+
+ assertEquals(true, res.isLoaded());
+ assertEquals(2, res.getContents().size()); // the model and the stereotype instance
+
+ umlModel = (Model)res.getContents().get(0);
+ aClass = (org.eclipse.uml2.uml.Class)EcoreUtil.getObjectByType(umlModel.getOwnedTypes(), UMLPackage.Literals.CLASS);
+ assertNotNull(aClass);
+
+ EObject stereotypeApplication = res.getContents().get(1);
+
+ // don't have the version of UML2 API that fixes problems in name-based look-up of stereotypes.
+ // The main point is that commit didn't fail on unresolved proxies in the Ecore definition
+ assertSame("Wrong base element reference.", aClass,
+ stereotypeApplication.eGet(stereotypeApplication.eClass().getEStructuralFeature("base_Classifier")));
+ }
+
+ //
+ // Test framework
+ //
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ // restore the factory replaced by CDO
+ stuffPackage.setEFactoryInstance(originalStuffFactory);
+
+ super.doTearDown();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/RegisteredDynamicProfileTest.java b/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/RegisteredDynamicProfileTest.java
deleted file mode 100644
index 62e24727d4..0000000000
--- a/plugins/org.eclipse.emf.cdo.tests.uml/src/org/eclipse/emf/cdo/tests/uml/RegisteredDynamicProfileTest.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Christian W. Damus - initial API and implementation
- */
-package org.eclipse.emf.cdo.tests.uml;
-
-import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.tests.AbstractCDOTest;
-import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
-import org.eclipse.emf.cdo.tests.config.impl.ModelConfig;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EFactory;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-
-import org.eclipse.uml2.common.util.UML2Util;
-import org.eclipse.uml2.uml.Model;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.UMLFactory;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * Tests legacy-mode support for registered dynamic UML Profiles.
- */
-@Requires(ModelConfig.CAPABILITY_LEGACY)
-public class RegisteredDynamicProfileTest extends AbstractCDOTest
-{
- private final EPackage stuffPackage = EPackage.Registry.INSTANCE
- .getEPackage("http://www.eclipse.org/cdo/tests/schema/stuff/1.0");
-
- private final EFactory originalStuffFactory = stuffPackage.getEFactoryInstance();
-
- private static final String MY_PROFILE_URI = "http://www.eclipse.org/cdo/tests/schema/myprofile";
-
- private static final String S_CONCEPT = "Concept";
-
- //
- // Test cases
- //
-
- public void testInstancesOfRegisteredDynamicUMLProfile() throws Exception
- {
- CDOSession session = openSession();
- session.getPackageRegistry().putEPackage(UMLPackage.eINSTANCE);
-
- ResourceSet rset = new ResourceSetImpl();
- CDOTransaction transaction = session.openTransaction(rset);
- CDOResource res = transaction.createResource(getResourcePath("/model1.uml"));
-
- Model umlModel = UMLFactory.eINSTANCE.createModel();
- res.getContents().add(umlModel);
-
- umlModel.setName("model");
- org.eclipse.uml2.uml.Class aClass = umlModel.createOwnedClass("Fruit", true);
-
- Profile profile = UML2Util.load(rset, URI.createURI(MY_PROFILE_URI), UMLPackage.Literals.PROFILE);
- assertNotNull(profile);
-
- umlModel.applyProfile(profile);
-
- Stereotype conceptStereotype = profile.getOwnedStereotype(S_CONCEPT);
- aClass.applyStereotype(conceptStereotype);
-
- // condition the profile for CDO compatibility, so that we don't try to reference the UML content
- // from the EPackage in the registry. This will be implemented in the UML2 API for Kepler release
- convertDefinitionsToWeakReferences(profile);
- convertDefinitionsToWeakReferences(EPackage.Registry.INSTANCE.getEPackage(MY_PROFILE_URI));
-
- transaction.commit();
-
- // load the model again in a new session (hence new package registry)
- session.close();
- session = openSession();
-
- transaction = session.openTransaction();
- res = transaction.getResource(getResourcePath("/model1.uml"), true);
-
- assertEquals(true, res.isLoaded());
- assertEquals(2, res.getContents().size()); // the model and the stereotype instance
-
- umlModel = (Model)res.getContents().get(0);
- aClass = (org.eclipse.uml2.uml.Class)EcoreUtil.getObjectByType(umlModel.getOwnedTypes(), UMLPackage.Literals.CLASS);
- assertNotNull(aClass);
-
- // changes in UML2 API are needed to recognize the EClass<-->Stereotype relationship using
- // "weak references" (the conditioning step for CDO), so this tests the low-level structure
- EObject conceptInstance = res.getContents().get(1);
- EClass conceptClass = conceptInstance.eClass();
- assertEquals("Concept", conceptClass.getName());
- assertEquals(MY_PROFILE_URI, conceptClass.getEPackage().getNsURI());
-
- assertEquals(aClass, conceptInstance.eGet(conceptClass.getEStructuralFeature("base_Classifier")));
- }
-
- //
- // Test framework
- //
-
- @Override
- protected void doTearDown() throws Exception
- {
- // restore the factory replaced by CDO
- stuffPackage.setEFactoryInstance(originalStuffFactory);
-
- super.doTearDown();
- }
-
- /**
- * <p>
- * Converts all of the Ecore-to-UML traceability references in a dynamic
- * profile from hard references to weak references. This is not yet
- * implemented in Eclipse UML2, but will be for Kepler release.
- * </p>
- * <p>
- * TODO: Remove this when the UML2 implementation is available
- * </p>
- *
- * @param profile
- * a dynamic profile
- *
- * @return the same {@code profile}, for convenience of call chaining
- */
- public static Profile convertDefinitionsToWeakReferences(Profile profile)
- {
- EAnnotation annotation = profile.getEAnnotation("http://www.eclipse.org/uml2/2.0.0/UML");
-
- if (annotation != null)
- {
- for (EObject next : annotation.getContents())
- {
- if (next instanceof EPackage)
- {
- convertDefinitionsToWeakReferences((EPackage)next);
- }
- }
- }
-
- return profile;
- }
-
- /**
- * <p>
- * Converts all of the Ecore-to-UML traceability references in a dynamic
- * profile's Ecore definition from hard references to weak references.
- * This is not yet implemented in Eclipse UML2, but will be for Kepler release.
- * </p>
- * <p>
- * TODO: Remove this when the UML2 implementation is available
- * </p>
- *
- * @param ePackage
- * a dynamic profile's Ecore definition
- *
- * @return the same {@code ePackage}, for convenience of call chaining
- */
- public static EPackage convertDefinitionsToWeakReferences(EPackage ePackage)
- {
- for (EClassifier next : ePackage.getEClassifiers())
- {
- EAnnotation annotation = next.getEAnnotation("http://www.eclipse.org/uml2/2.0.0/UML");
- if (annotation != null && !annotation.getReferences().isEmpty())
- {
- EObject referenced = annotation.getReferences().get(0);
- if (referenced instanceof NamedElement)
- {
- Resource res = referenced.eResource();
- if (res != null)
- {
- StringBuilder buf = new StringBuilder();
- buf.append(res.getURI()).append('#').append(((NamedElement)referenced).getQualifiedName());
- annotation.getDetails().put("href", buf.toString());
- annotation.getReferences().clear();
- }
- }
- }
- }
-
- return ePackage;
- }
-}

Back to the top