70
 What do YOU want UML to be?  |  Long Talk  |  © Copyright 2007 by IBM Corp.; made available under the EPL v1.0
Lightweight Extensions – Example
org.eclipse.uml2.uml.Package testSuite = UMLFactory.eINSTANCE.createPackage();
resource.getContents().add(testSuite);
Profile lightweightProfile = (Profile) UMLUtil.load(resourceSet, URI.createURI(args[1]), UMLPackage.Literals.PROFILE);
testSuite.applyProfile(lightweightProfile);
Stereotype testSuiteStereotype = lightweightProfile.getOwnedStereotype("TestSuite");
testSuite.applyStereotype(testSuiteStereotype);
testSuite.setName("LightweightTests");
org.eclipse.uml2.uml.Class testContext = testSuite.createOwnedClass("LightweightExample", false);
Stereotype testContextStereotype = lightweightProfile.getOwnedStereotype("TestContext");
EObject testContextStereotypeApplication = testContext.applyStereotype(testContextStereotype);
@SuppressWarnings("unchecked")
EList<EObject> tests = (EList<EObject>) testSuite.getValue(testSuiteStereotype, "tests");
tests.add(testContextStereotypeApplication);
Operation testCase = testContext.createOwnedOperation("testExtension", null, null);
Stereotype testCaseStereotype = lightweightProfile.getOwnedStereotype("TestCase");
testCase.applyStereotype(testCaseStereotype);
testCase.setValue(testCaseStereotype, "context", testContextStereotypeApplication);
testCase.setValue(testCaseStereotype, "objective", "Test lightweight extension of UML2.");