Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Load xmi file of UML2 Model
Load xmi file of UML2 Model [message #471809] Mon, 26 March 2007 15:57 Go to next message
Eclipse UserFriend
Originally posted by: sliles.gmu.edu

Hello,
I cannot find any example code that explains how to load an existing
..xmi. If you have a link that can explain this read not further and send me
the link. If not read on and look at the code a cobbled together by looking
at the javadoc for UML2 and EMF. Thanks in advance!!
I have worked through the getting started with UML2 article. I
understand what is covered there. I am interested in reading an existing
model using the API then using the API to access the various parts of the
model. Specifically I will be looking through the activity diagram for
specific information and translating to another form. I think once I get it
loaded the examples for the "Getting Started with UML2" article will be much
more applicable to my application.

Here is my code for reading an xmi file that came from rational system
developer. The header is reproduced below.
<uml:Model xmi:version="2.1"
xsi:schemaLocation="http://schema.omg.org/spec/UML/2.1.1
http://www.eclipse.org/uml2/2.0.0/UML" xmi:id="_YjKpJNiXEduqsZWui7bccg"
name="SmallPrototype">

CODE for loadModel.

public Model loadModel() {
String file = "Simple.xmi";
ResourceSet resourceSet = new ResourceSetImpl();
Resource.Factory.Registry rfr = new ResourceFactoryRegistryImpl();
resourceSet.setResourceFactoryRegistry(rfr);
URI uri = URI.createFileURI(file);

rfr.getFactory(uri);
resourceSet.setResourceFactoryRegistry(rfr);
Resource resource = resourceSet.getResource(uri, true);
model = (Model)
org.eclipse.emf.ecore.util.EcoreUtil.getObjectByType(resourc e.getContents(),
org.eclipse.uml2.uml.UMLPackage.Literals.MODEL);

return model;
}//end loadModel

Thanks,
Stewart Liles
Re: Load xmi file of UML2 Model [message #471810 is a reply to message #471809] Mon, 26 March 2007 21:24 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Stewart,

I'm not sure if you downloaded the source for the getting started articles.
There are example load() functions that will do what you want.
It doesn't really matter what extension your model has as long as the UML
resource factory is registered against that extension but typically .uml
would be the extension.

You might also want to have a look at :
http://www.eclipse.org/modeling/mdt/uml2/docs/guides/UML2_2. 0_Migration_Guide/guide.html
( scroll toward the bottom ) for examples of loading models in a stand
alone application.

You shouldn't have to create a new resource factory as you have done below.

Regards,

- James



"Stewart Liles" <sliles@gmu.edu> wrote in message
news:eu8qeo$m3u$1@utils.eclipse.org...
> Hello,
> I cannot find any example code that explains how to load an existing
> .xmi. If you have a link that can explain this read not further and send
me
> the link. If not read on and look at the code a cobbled together by
looking
> at the javadoc for UML2 and EMF. Thanks in advance!!
> I have worked through the getting started with UML2 article. I
> understand what is covered there. I am interested in reading an existing
> model using the API then using the API to access the various parts of the
> model. Specifically I will be looking through the activity diagram for
> specific information and translating to another form. I think once I get
it
> loaded the examples for the "Getting Started with UML2" article will be
much
> more applicable to my application.
>
> Here is my code for reading an xmi file that came from rational system
> developer. The header is reproduced below.
> <uml:Model xmi:version="2.1"
> xsi:schemaLocation="http://schema.omg.org/spec/UML/2.1.1
> http://www.eclipse.org/uml2/2.0.0/UML" xmi:id="_YjKpJNiXEduqsZWui7bccg"
> name="SmallPrototype">
>
> CODE for loadModel.
>
> public Model loadModel() {
> String file = "Simple.xmi";
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource.Factory.Registry rfr = new ResourceFactoryRegistryImpl();
> resourceSet.setResourceFactoryRegistry(rfr);
> URI uri = URI.createFileURI(file);
>
> rfr.getFactory(uri);
> resourceSet.setResourceFactoryRegistry(rfr);
> Resource resource = resourceSet.getResource(uri, true);
> model = (Model)
>
org.eclipse.emf.ecore.util.EcoreUtil.getObjectByType(resourc e.getContents(),
> org.eclipse.uml2.uml.UMLPackage.Literals.MODEL);
>
> return model;
> }//end loadModel
>
> Thanks,
> Stewart Liles
>
>
Re: Load xmi file of UML2 Model [message #603180 is a reply to message #471809] Mon, 26 March 2007 21:24 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Stewart,

I'm not sure if you downloaded the source for the getting started articles.
There are example load() functions that will do what you want.
It doesn't really matter what extension your model has as long as the UML
resource factory is registered against that extension but typically .uml
would be the extension.

You might also want to have a look at :
http://www.eclipse.org/modeling/mdt/uml2/docs/guides/UML2_2. 0_Migration_Guide/guide.html
( scroll toward the bottom ) for examples of loading models in a stand
alone application.

You shouldn't have to create a new resource factory as you have done below.

Regards,

- James



"Stewart Liles" <sliles@gmu.edu> wrote in message
news:eu8qeo$m3u$1@utils.eclipse.org...
> Hello,
> I cannot find any example code that explains how to load an existing
> .xmi. If you have a link that can explain this read not further and send
me
> the link. If not read on and look at the code a cobbled together by
looking
> at the javadoc for UML2 and EMF. Thanks in advance!!
> I have worked through the getting started with UML2 article. I
> understand what is covered there. I am interested in reading an existing
> model using the API then using the API to access the various parts of the
> model. Specifically I will be looking through the activity diagram for
> specific information and translating to another form. I think once I get
it
> loaded the examples for the "Getting Started with UML2" article will be
much
> more applicable to my application.
>
> Here is my code for reading an xmi file that came from rational system
> developer. The header is reproduced below.
> <uml:Model xmi:version="2.1"
> xsi:schemaLocation="http://schema.omg.org/spec/UML/2.1.1
> http://www.eclipse.org/uml2/2.0.0/UML" xmi:id="_YjKpJNiXEduqsZWui7bccg"
> name="SmallPrototype">
>
> CODE for loadModel.
>
> public Model loadModel() {
> String file = "Simple.xmi";
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource.Factory.Registry rfr = new ResourceFactoryRegistryImpl();
> resourceSet.setResourceFactoryRegistry(rfr);
> URI uri = URI.createFileURI(file);
>
> rfr.getFactory(uri);
> resourceSet.setResourceFactoryRegistry(rfr);
> Resource resource = resourceSet.getResource(uri, true);
> model = (Model)
>
org.eclipse.emf.ecore.util.EcoreUtil.getObjectByType(resourc e.getContents(),
> org.eclipse.uml2.uml.UMLPackage.Literals.MODEL);
>
> return model;
> }//end loadModel
>
> Thanks,
> Stewart Liles
>
>
Previous Topic:Load xmi file of UML2 Model
Next Topic:declaring and using a template class
Goto Forum:
  


Current Time: Sun Apr 05 04:42:55 GMT 2020

Powered by FUDForum. Page generated in 0.01963 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top