Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Retrieving applied stereotypes
Retrieving applied stereotypes [message #628598] Wed, 18 August 2010 11:03 Go to previous message
Thomas is currently offline Thomas
Messages: 4
Registered: August 2010
Location: Austria
Junior Member
Hi there!

I'm currently facing problems when trying to read applied stereotypes from a UML model. The model itself is created and exported from 16.5 MagicDraw with the "EMF UML 2.x" export option.

When opening the model back in the UML editor the stereotyped elements are perfectly shown like "<<myStereotype>> <Class> myClass". Therefore I guess the model itself is valid (in the context of applied stereotypes).

I found a bunch of hints and guides on how to do stand alone applications (package registrations, pathmaps, ...) and tried "everything" without success. That's why I'm now here hoping to get some enlightenment. :)

Below you find the major code lines I'm using. Any comments and the slightest hints why any call to ...#getAppliedStereotypes leads to an empty list are very much appreciated!


import ...

public class SimpleTest {
public static void main(String[] args) {
String filename = "models/myModel.uml";

ResourceSet resourceSet = new ResourceSetImpl();

resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
resourceSet.getPackageRegistry().put(Ecore2XMLPackage.eNS_UR I, Ecore2XMLPackage.eINSTANCE);

resourceSet.getPackageRegistry().put("http://www.eclipse.org/uml2/2.0.0/UML", UMLPackage.eINSTANCE);
resourceSet.getPackageRegistry().put("http://schema.omg.org/spec/UML/2.0", UMLPackage.eINSTANCE);
resourceSet.getPackageRegistry().put("http://schema.omg.org/spec/UML/2.1", UMLPackage.eINSTANCE);

Map<String, Object> extensionToFactoryMap = resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap();
extensionToFactoryMap.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

extensionToFactoryMap.put("ecore", new EcoreResourceFactoryImpl());
extensionToFactoryMap.put("ecore2xml", new Ecore2XMLFactoryImpl());

extensionToFactoryMap.put(UMLResource.FILE_EXTENSION, XMI2UMLResource.Factory.INSTANCE);
extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_ EXTENSION, new XMIResourceFactoryImpl());

Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();

URI uri = URI.createURI(" jar:file:/ABS_PATH_TO_JAR/org.eclipse.uml2.uml.resources_3.1 .0.v201005031530.jar!/ ");
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));

URI uriPath = URI.createFileURI(filename);
Resource resource = resourceSet.getResource(uriPath, true);
Model myModel = (Model) EcoreUtil.getObjectByType(
resource.getContents(), UMLPackage.eINSTANCE.getModel());

// load the profile (test purpose)
URI profilePath = URI.createFileURI("models/myProfile.profile.uml");
Resource profileResource = resourceSet.getResource(profilePath, true);
Profile umlProfile = (Profile) EcoreUtil.getObjectByType(
profileResource.getContents(), UMLPackage.eINSTANCE.getProfile());
// end loading the profile

System.out.println("Model " + myModel.getName());

Iterator<Element> it = myModel.getOwnedElements().iterator();
while (it.hasNext()) {
Element e = it.next();
if(e instanceof org.eclipse.uml2.uml.Class) {
org.eclipse.uml2.uml.Class umlClass = (org.eclipse.uml2.uml.Class)e;

System.out.print("Class " + umlClass.getName());

// THIS LEADS TO EMPTY LIST
EList stereotypes = umlClass.getAppliedStereotypes();
System.out.println(" (" + stereotypes.size() + " stereotypes)");
for(Object stereotype : stereotypes) {
System.out.println("\tStereotype " + stereotype.toString());
}
} else if (e instanceof NamedElement)
System.out.println("Other " + e);
}
}
}
 
Read Message
Read Message
Read Message
Previous Topic:Retrieving applied stereotypes
Next Topic:UML 2.x - Raising Events on Transition (State Machine / Effect)
Goto Forum:
  


Current Time: Thu May 23 15:06:13 EDT 2013

Powered by FUDForum. Page generated in 0.01654 seconds