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 next 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);
}
}
}
Re: Retrieving applied stereotypes [message #628599 is a reply to message #628598] Wed, 18 August 2010 12:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25749
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 "&lt;&lt;myStereotype&gt;&gt; &lt;Class&gt;
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&lt;String, Object&gt; 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&lt;URI, URI&gt; 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&lt;Element&gt; 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--
Re: Retrieving applied stereotypes [message #628606 is a reply to message #628598] Thu, 19 August 2010 04:40 Go to previous messageGo to next message
Thomas is currently offline Thomas
Messages: 4
Registered: August 2010
Location: Austria
Junior Member
Many thanks, that did the trick for me!
Re: Retrieving applied stereotypes [message #1278387 is a reply to message #628598] Thu, 27 March 2014 05:01 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
Hi

I have a same problem. Here is a test project:
https://github.com/AresEkb/XMILoadTest
with a two model variants: Test.uml and Test.xmi

If you'll use the first one as an input, everithing works as expected and the output is
Loading file:/C:/Work/workspace/XMILoadTest/model/Test.uml
Loading file:/C:/Work/workspace/XMILoadTest/model/TestProfile.profile.uml
Root: class org.eclipse.uml2.uml.internal.impl.ModelImpl
Count: 3
Loading pathmap://UML_PROFILES/Standard.profile.uml
Loading file:/C:/Work/workspace/XMILoadTest/model/Default.profile.uml
Loading file:/C:/Work/workspace/XMILoadTest/model/Deployment.profile.uml
Loading file:/C:/Work/workspace/XMILoadTest/model/ProfileBase.profile.uml
org.eclipse.uml2.uml.internal.impl.ProfileImpl@d3f2d04 (eProxyURI: pathmap://UML_PROFILES/Standard.profile.uml#_0)
org.eclipse.uml2.uml.internal.impl.ProfileImpl@5fc81d2c (name: Default, visibility: <unset>) (URI: null)
org.eclipse.uml2.uml.internal.impl.ProfileImpl@1c7769f7 (name: Deployment, visibility: <unset>) (URI: null)
org.eclipse.uml2.uml.internal.impl.ProfileImpl@3d2cd949 (name: TestProfile, visibility: <unset>) (URI: null)
org.eclipse.uml2.uml.internal.impl.StereotypeImpl@5324c30d (name: ModelStereotype, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)


But If you'll try to load and XMI-version of the model, stereotypes will not be loaded:
Loading file:/C:/Work/workspace/XMILoadTest/model/Test.xmi
Loading file:/C:/Work/workspace/XMILoadTest/model/TestProfile.profile.xmi
Loading file:/C:/Work/workspace/XMILoadTest/model/ProfileBase.profile.xmi
Loading http://schema.omg.org/spec/UML/2.1.1/StandardProfileL2.xmi
Loading file:/C:/Work/workspace/XMILoadTest/model/Default.profile.xmi
Loading file:/C:/Work/workspace/XMILoadTest/model/Deployment.profile.xmi
Root: class org.eclipse.uml2.uml.internal.impl.ModelImpl
Count: 3
org.eclipse.uml2.uml.internal.impl.ProfileImpl@64a21666 (eProxyURI: http://schema.omg.org/spec/UML/2.1.1/StandardProfileL2.xmi#_0)
org.eclipse.uml2.uml.internal.impl.ProfileImpl@38d1099c (name: Default, visibility: <unset>) (URI: null)
org.eclipse.uml2.uml.internal.impl.ProfileImpl@67dbb4ce (name: Deployment, visibility: <unset>) (URI: null)
org.eclipse.uml2.uml.internal.impl.ProfileImpl@6e81f88f (name: TestProfile, visibility: <unset>) (URI: null)


What's wrong with my code?
Re: Retrieving applied stereotypes [message #1278522 is a reply to message #1278387] Thu, 27 March 2014 08:55 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 701
Registered: July 2009
Senior Member
Hi, Denis,

I think there are a good many more registrations needed to make XMI
loading work.

Try inserting the following between lines 22 and 23 in your sample code
(after creating the resource set):

UMLResourcesUtil.init(rs);

You can then also remove the resource factory registrations at lines 26 and 28.

HTH,

Christian

On 2014-03-27 09:01:41 +0000, Denis Nikiforov said:

> Hi
>
> I have a same problem. Here is a test project:
> https://github.com/AresEkb/XMILoadTest
> with a two model variants: Test.uml and Test.xmi
>
> If you'll use the first one as an input, everithing works as expected
> and the output is
> Loading file:/C:/Work/workspace/XMILoadTest/model/Test.uml
> Loading file:/C:/Work/workspace/XMILoadTest/model/TestProfile.profile.uml
> Root: class org.eclipse.uml2.uml.internal.impl.ModelImpl
> Count: 3
> Loading pathmap://UML_PROFILES/Standard.profile.uml
> Loading file:/C:/Work/workspace/XMILoadTest/model/Default.profile.uml
> Loading file:/C:/Work/workspace/XMILoadTest/model/Deployment.profile.uml
> Loading file:/C:/Work/workspace/XMILoadTest/model/ProfileBase.profile.uml
> org.eclipse.uml2.uml.internal.impl.ProfileImpl@d3f2d04 (eProxyURI:
> pathmap://UML_PROFILES/Standard.profile.uml#_0)
> org.eclipse.uml2.uml.internal.impl.ProfileImpl@5fc81d2c (name: Default,
> visibility: <unset>) (URI: null)
> org.eclipse.uml2.uml.internal.impl.ProfileImpl@1c7769f7 (name:
> Deployment, visibility: <unset>) (URI: null)
> org.eclipse.uml2.uml.internal.impl.ProfileImpl@3d2cd949 (name:
> TestProfile, visibility: <unset>) (URI: null)
> org.eclipse.uml2.uml.internal.impl.StereotypeImpl@5324c30d (name:
> ModelStereotype, visibility: <unset>) (isLeaf: false, isAbstract:
> false, isFinalSpecialization: false) (isActive: false)
>
> But If you'll try to load and XMI-version of the model, stereotypes
> will not be loaded:
> Loading file:/C:/Work/workspace/XMILoadTest/model/Test.xmi
> Loading file:/C:/Work/workspace/XMILoadTest/model/TestProfile.profile.xmi
> Loading file:/C:/Work/workspace/XMILoadTest/model/ProfileBase.profile.xmi
> Loading http://schema.omg.org/spec/UML/2.1.1/StandardProfileL2.xmi
> Loading file:/C:/Work/workspace/XMILoadTest/model/Default.profile.xmi
> Loading file:/C:/Work/workspace/XMILoadTest/model/Deployment.profile.xmi
> Root: class org.eclipse.uml2.uml.internal.impl.ModelImpl
> Count: 3
> org.eclipse.uml2.uml.internal.impl.ProfileImpl@64a21666 (eProxyURI:
> http://schema.omg.org/spec/UML/2.1.1/StandardProfileL2.xmi#_0)
> org.eclipse.uml2.uml.internal.impl.ProfileImpl@38d1099c (name: Default,
> visibility: <unset>) (URI: null)
> org.eclipse.uml2.uml.internal.impl.ProfileImpl@67dbb4ce (name:
> Deployment, visibility: <unset>) (URI: null)
> org.eclipse.uml2.uml.internal.impl.ProfileImpl@6e81f88f (name:
> TestProfile, visibility: <unset>) (URI: null)
>
> What's wrong with my code?
Re: Retrieving applied stereotypes [message #1279143 is a reply to message #1278522] Fri, 28 March 2014 05:42 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
Hi!

It doesn't help Sad And also after removing the lines
        rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
                UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
        rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
                XMI2UMLResource.FILE_EXTENSION, XMI2UMLResource.Factory.INSTANCE);

the program throws an exception:
Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: java.net.MalformedURLException: unknown protocol: platform
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at org.eclipse.uml2.uml.internal.resource.XMI212UMLResourceFactoryImpl.createResource(XMI212UMLResourceFactoryImpl.java:110)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:434)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandCreateResource(ResourceSetImpl.java:243)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:400)
	at xmiLoadTest.Main.main(Main.java:33)
Caused by: java.net.MalformedURLException: unknown protocol: platform
	at java.net.URL.<init>(Unknown Source)
	at java.net.URL.<init>(Unknown Source)
	at java.net.URL.<init>(Unknown Source)
	at org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.createInputStream(URIHandlerImpl.java:199)
	at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:360)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1269)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	... 6 more
Re: Retrieving applied stereotypes [message #1279246 is a reply to message #1279143] Fri, 28 March 2014 08:59 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 701
Registered: July 2009
Senior Member
Hi, Denis,

See some replies in-line, below.

Cheers,

Christian

On 2014-03-28 09:42:58 +0000, Denis Nikiforov said:

> Hi!
>
> It doesn't help :( And also after removing the lines
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
> UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
> XMI2UMLResource.FILE_EXTENSION,
> XMI2UMLResource.Factory.INSTANCE);

Well, these could only be removed when setting up the resource set with
the UMLResourcesUtil.init(...) API, because they are redundant with the
registrations that the latter does.


> the program throws an exception:
> Exception in thread "main"
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
> java.net.MalformedURLException: unknown protocol: platform
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
>
> at
> org.eclipse.uml2.uml.internal.resource.XMI212UMLResourceFactoryImpl.createResource(XMI212UMLResourceFactoryImpl.java:110)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:434)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandCreateResource(ResourceSetImpl.java:243)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:400)
>
> at xmiLoadTest.Main.main(Main.java:33)
> Caused by: java.net.MalformedURLException: unknown protocol: platform
> at java.net.URL.<init>(Unknown Source)
> at java.net.URL.<init>(Unknown Source)
> at java.net.URL.<init>(Unknown Source)
> at
> org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.createInputStream(URIHandlerImpl.java:199)
>
> at
> org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:360)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1269)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
>
> ... 6 more


This should only happen if you didn't do UMLResourcesUtil.init(...), I think.

Sorry, but I don't know enough about the UML2 project's support for
OMG-standard XMI to help any further. Hopefully somebody who does will
chime in.
Re: Retrieving applied stereotypes [message #1281063 is a reply to message #1279246] Mon, 31 March 2014 05:57 Go to previous message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
Hi Christian

I've added UMLResourcesUtil.init(...) into my code. But the exception is caused by UML212UMLResourceFactoryImpl.createResource(URI uri). It tries to load "platform:/plugin/..." URI:
		ecore2xmlRegistry
			.put(
				UML212UMLResource.UML_METAMODEL_NS_URI,
				EcoreUtil
					.getObjectByType(
						resourceSet
							.getResource(
								URI
									.createURI("platform:/plugin/org.eclipse.uml2.uml/model/UML21_2_UML.ecore2xml"), //$NON-NLS-1$
								true).getContents(),
						Ecore2XMLPackage.Literals.XML_MAP));


The following lines forces EMF to use a different Factory. And the exceptions disappears:
        rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
                UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
        rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
                XMI2UMLResource.FILE_EXTENSION, XMI2UMLResource.Factory.INSTANCE);


Why EMF couldn't load platform:/plugin/org.eclipse.uml2.uml/model/UML21_2_UML.ecore2xml?

I added a following line to initialize a EcorePlugin.getPlatformResourceMap():
org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.getAdapter(rs);


The map contains the following entries. But the exception still exists.
org.eclipse.xtext : archive:file:/C:/Work/eclipse/plugins/org.eclipse.xtext_2.6.0.v201403111428.jar!/
org.eclipse.ocl.examples.pivot : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.examples.pivot_3.4.0.v20140310-1427.jar!/
org.apache.log4j : archive:file:/C:/Work/eclipse/plugins/org.apache.log4j_1.2.15.v201012070815.jar!/
org.eclipse.emf.ecore.xmi : archive:file:/C:/Work/eclipse/plugins/org.eclipse.emf.ecore.xmi_2.10.0.v20140303-1023.jar!/
org.eclipse.uml2.types : archive:file:/C:/Work/eclipse/plugins/org.eclipse.uml2.types_2.0.0.v20140310-0733.jar!/
org.eclipse.ocl.examples.xtext.essentialocl : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.examples.xtext.essentialocl_3.4.0.v20140208-1141.jar!/
org.apache.commons.cli : archive:file:/C:/Work/eclipse/plugins/org.apache.commons.cli_1.2.0.v201105210650.jar!/
org.eclipse.ocl.examples.xtext.oclinecore : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.examples.xtext.oclinecore_3.4.0.v20140208-1154.jar!/
org.eclipse.ocl.examples.xtext.base : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.examples.xtext.base_3.4.0.v20140303-1414.jar!/
org.eclipse.uml2.common : archive:file:/C:/Work/eclipse/plugins/org.eclipse.uml2.common_2.0.0.v20140310-0733.jar!/
org.eclipse.emf.mapping.ecore2xml : archive:file:/C:/Work/eclipse/plugins/org.eclipse.emf.mapping.ecore2xml_2.7.0.v20140310-0546.jar!/
org.eclipse.ocl : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl_3.4.0.v20130903-1625.jar!/
org.eclipse.emf.mwe.utils : archive:file:/C:/Work/eclipse/plugins/org.eclipse.emf.mwe.utils_1.3.2.v201403111231.jar!/
org.eclipse.emf.ecore : archive:file:/C:/Work/eclipse/plugins/org.eclipse.emf.ecore_2.10.0.v20140303-1023.jar!/
org.eclipse.jdt.annotation : archive:file:/C:/Work/eclipse/plugins/org.eclipse.jdt.annotation_1.1.0.v20130513-1648.jar!/
org.eclipse.xtext.util : archive:file:/C:/Work/eclipse/plugins/org.eclipse.xtext.util_2.6.0.v201403111428.jar!/
XMILoadTest : file:/C:/Work/workspace/XMILoadTest/
org.eclipse.emf.edit : archive:file:/C:/Work/eclipse/plugins/org.eclipse.emf.edit_2.10.0.v20140310-0546.jar!/
com.google.guava : archive:file:/C:/Work/eclipse/plugins/com.google.guava_15.0.0.v201402241730.jar!/
org.antlr.runtime : archive:file:/C:/Work/eclipse/plugins/org.antlr.runtime_3.2.0.v201101311130.jar!/
org.eclipse.ocl.examples.xtext.completeocl : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.examples.xtext.completeocl_3.4.0.v20140208-1141.jar!/
org.eclipse.xtext.common.types : archive:file:/C:/Work/eclipse/plugins/org.eclipse.xtext.common.types_2.6.0.v201403111428.jar!/
org.eclipse.emf.ecore.change : archive:file:/C:/Work/eclipse/plugins/org.eclipse.emf.ecore.change_2.9.0.v20140303-1023.jar!/
org.eclipse.ocl.common : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.common_1.1.100.v20140121-1437.jar!/
org.eclipse.emf.mwe2.runtime : archive:file:/C:/Work/eclipse/plugins/org.eclipse.emf.mwe2.runtime_2.6.0.v201403111231.jar!/
org.eclipse.ocl.examples.domain : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.examples.domain_3.4.0.v20140310-1503.jar!/
org.eclipse.emf.mwe.core : archive:file:/C:/Work/eclipse/plugins/org.eclipse.emf.mwe.core_1.3.1.v201403111231.jar!/
org.eclipse.ocl.examples.xtext.oclstdlib : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.examples.xtext.oclstdlib_3.4.0.v20140208-1141.jar!/
org.eclipse.ocl.examples.common : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.examples.common_3.3.0.v20140310-1047.jar!/
org.eclipse.ocl.examples.library : archive:file:/C:/Work/eclipse/plugins/org.eclipse.ocl.examples.library_3.4.0.v20140308-1252.jar!/
org.eclipse.uml2.uml.profile.standard : archive:file:/C:/Work/eclipse/plugins/org.eclipse.uml2.uml.profile.standard_1.0.0.v20140310-0733.jar!/
lpg.runtime.java : archive:file:/C:/Work/eclipse/plugins/lpg.runtime.java_2.0.17.v201004271640.jar!/
org.eclipse.emf.common : archive:file:/C:/Work/eclipse/plugins/org.eclipse.emf.common_2.10.0.v20140303-1023.jar!/
org.eclipse.uml2.uml.resources : archive:file:/C:/Work/eclipse/plugins/org.eclipse.uml2.uml.resources_5.0.0.v20140310-0733.jar!/
org.eclipse.uml2.uml : archive:file:/C:/Work/eclipse/plugins/org.eclipse.uml2.uml_5.0.0.v20140310-0733.jar!/
javax.inject : archive:file:/C:/Work/eclipse/plugins/javax.inject_1.0.0.v20091030.jar!/
com.google.inject : archive:file:/C:/Work/eclipse/plugins/com.google.inject_3.0.0.v201312141243.jar!/


Why EMF couldn't load platform:/plugin/org.eclipse.uml2.uml/model/UML21_2_UML.ecore2xml in standalone application?

An updated test project is here: https://github.com/AresEkb/XMILoadTest
Previous Topic:stereotypes not found on model reload
Next Topic:how to make instance model from ecore file
Goto Forum:
  


Current Time: Wed Apr 23 17:46:37 EDT 2014

Powered by FUDForum. Page generated in 0.08381 seconds