Home » Modeling » UML2 » Retrieving applied stereotypes
Retrieving applied stereotypes [message #553715] |
Wed, 18 August 2010 15:03 |
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_URI, 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().getExtensionToFactoryMap();
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);
}
}
}
Many thanks for any efforts,
Thomas
[Updated on: Wed, 18 August 2010 15:06] Report message to a moderator
|
|
|
Re: Retrieving applied stereotypes [message #553737 is a reply to message #553715] |
Wed, 18 August 2010 16:12 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------070907070000030103040600
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
One suggestion is to ensure *all *your paths are absolute. I.e., use
new java.io.File("models/myModel.uml").getAbsolutePath() before creating
a file URI from it.
tomtro13@gmail.com wrote:
> 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);
> }
> }
> }
>
--------------070907070000030103040600
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
One suggestion is to ensure <b>all </b>your paths are absolute.
I.e., use new java.io.File("models/myModel.uml").getAbsolutePath()
before creating a file URI from it.<br>
<br>
<br>
<a class="moz-txt-link-abbreviated" href="mailto:tomtro13@gmail.com">tomtro13@gmail.com</a> wrote:
<blockquote cite="mid:i4gsne$acm$1@build.eclipse.org" type="cite">Hi
there!
<br>
<br>
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.
<br>
<br>
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).
<br>
<br>
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. :) <br>
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!
<br>
<br>
<br>
import ...
<br>
<br>
public class SimpleTest {
<br>
public static void main(String[] args) {
<br>
String filename = "models/myModel.uml";
<br>
<br>
ResourceSet resourceSet = new ResourceSetImpl();
<br>
<br>
resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI,
EcorePackage.eINSTANCE);
<br>
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
<br>
resourceSet.getPackageRegistry().put(Ecore2XMLPackage.eNS_UR I,
Ecore2XMLPackage.eINSTANCE);
<br>
<br>
resourceSet.getPackageRegistry().put(<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/uml2/2.0.0/UML">"http://www.eclipse.org/uml2/2.0.0/UML"</a>,
UMLPackage.eINSTANCE);
<br>
resourceSet.getPackageRegistry().put(<a class="moz-txt-link-rfc2396E" href="http://schema.omg.org/spec/UML/2.0">"http://schema.omg.org/spec/UML/2.0"</a>,
UMLPackage.eINSTANCE);
<br>
resourceSet.getPackageRegistry().put(<a class="moz-txt-link-rfc2396E" href="http://schema.omg.org/spec/UML/2.1">"http://schema.omg.org/spec/UML/2.1"</a>,
UMLPackage.eINSTANCE);
<br>
<br>
Map<String, Object> extensionToFactoryMap =
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap();
<br>
extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
<br>
<br>
extensionToFactoryMap.put("ecore", new
EcoreResourceFactoryImpl());
<br>
extensionToFactoryMap.put("ecore2xml", new
Ecore2XMLFactoryImpl());
<br>
<br>
extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
XMI2UMLResource.Factory.INSTANCE);
<br>
extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_ EXTENSION,
new XMIResourceFactoryImpl());
<br>
<br>
Map<URI, URI> uriMap =
resourceSet.getURIConverter().getURIMap();
<br>
<br>
URI uri =
URI.createURI(<a class="moz-txt-link-rfc2396E" href=" jar:file:/ABS_PATH_TO_JAR/org.eclipse.uml2.uml.resources_3.1 .0.v201005031530.jar!/ ">" jar:file:/ABS_PATH_TO_JAR/org.eclipse.uml2.uml.resources_3.1 .0.v201005031530.jar!/ "</a>);
<br>
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
uri.appendSegment("libraries").appendSegment(""));
<br>
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
uri.appendSegment("metamodels").appendSegment(""));
<br>
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
uri.appendSegment("profiles").appendSegment(""));
<br>
<br>
URI uriPath = URI.createFileURI(filename);
<br>
Resource resource = resourceSet.getResource(uriPath, true);
<br>
Model myModel = (Model) EcoreUtil.getObjectByType(
<br>
resource.getContents(),
UMLPackage.eINSTANCE.getModel());
<br>
<br>
// load the profile (test purpose)
<br>
URI profilePath =
URI.createFileURI("models/myProfile.profile.uml");
<br>
Resource profileResource = resourceSet.getResource(profilePath,
true);
<br>
Profile umlProfile = (Profile) EcoreUtil.getObjectByType(
<br>
profileResource.getContents(),
UMLPackage.eINSTANCE.getProfile());
<br>
// end loading the profile
<br>
<br>
System.out.println("Model " + myModel.getName());
<br>
<br>
Iterator<Element> it =
myModel.getOwnedElements().iterator();
<br>
while (it.hasNext()) {
<br>
Element e = it.next();
<br>
if(e instanceof org.eclipse.uml2.uml.Class) {
<br>
org.eclipse.uml2.uml.Class umlClass =
(org.eclipse.uml2.uml.Class)e;
<br>
<br>
System.out.print("Class " + umlClass.getName());
<br>
<br>
// THIS LEADS TO EMPTY LIST <br>
EList stereotypes = umlClass.getAppliedStereotypes();
<br>
System.out.println(" (" + stereotypes.size() + "
stereotypes)");
<br>
for(Object stereotype : stereotypes) {
<br>
System.out.println("\tStereotype " +
stereotype.toString());
<br>
}
<br>
} else if (e instanceof NamedElement)
<br>
System.out.println("Other " + e);
<br>
}
<br>
}
<br>
}
<br>
<br>
</blockquote>
</body>
</html>
--------------070907070000030103040600--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Goto Forum:
Current Time: Fri Apr 19 21:57:43 GMT 2024
Powered by FUDForum. Page generated in 0.03088 seconds
|