Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Re: XMI Parser
Re: XMI Parser [message #477309] Thu, 01 May 2008 11:58 Go to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030100080004050309000608
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Naeem,

Comments below.


Khan wrote:
> hallo every one,
>
> I am intermediate level Java programmer. I have to parse the XMI 2.0
> to check the classes, its attributes, data types and relations among
> classes (Class diagram converted from UML2 into XMI). I am trying
> since 2 months. First I followed a book called Mastering XMI with
> Netbeans. It was not good enough. Then I came to EMF and Ecore. I like
> to have clear example where I can access my XMI and grab every object
> in it. Could any one help me out to make my concept clear with some
> examples.
> I am also trying to get any tutorial about this. But didnt find any.
There is a common misconception that you can just throw an XMI
serialization at a system and out will pop well formed model. Of course
this misconception is aided by the fact that this is generally how it's
supposed to work. The misconception part is that you can throw any old
XMI serialized instance at the system with the expectation that nice a
model will pop out. In reality the system must effectively know the
model that corresponds to each namespace mentioned in the XMI
serialization and if it doesn't know that model in intimate detail, the
XMI is just so much meaningless syntax.

Given you have a UML2 serialization, it's best to ask on the UML2
newsgroup how to read it; I've added that group to the "to" list of the
reply. Of course starting with the documentation at their website would
be best:
<http://www.eclipse.org/modeling/mdt/?project=uml2>

http://www.eclipse.org/modeling/mdt/?project=uml2
http://wiki.eclipse.org/index.php/MDT-UML2

>
> Your help definitely will bring me out from this problem.
>
> Best Regards,
> Naeem Khan
>
>


--------------030100080004050309000608
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Naeem,<br>
<br>
Comments below.<br>
<br>
<br>
Khan wrote:
<blockquote
cite="mid:06d44eb0c2099cb2bffcd74b6636103f$1@www.eclipse.org"
type="cite">hallo every one,
<br>
<br>
I am intermediate level Java programmer. I have to parse the XMI 2.0 to
check the classes, its attributes, data types and relations among
classes (Class diagram converted from UML2 into XMI). I am trying since
2 months. First I followed a book called Mastering XMI with Netbeans.
It was not good enough. Then I came to EMF and Ecore. I like to have
clear example where I can access my XMI and grab every object in it.
Could any one help me out to make my concept clear with some examples. <br>
I am also trying to get any tutorial about this. But didnt find any.
<br>
</blockquote>
There is a common misconception that you can just throw an XMI
serialization at a system and out will pop well formed model.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #477310 is a reply to message #477309] Thu, 01 May 2008 14:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

Thank you for your answer. But I might have wrong conception about reading
XMI files. I have already asked help in UML2 Newsgroup, as you recommend
me. Could you please give me any idea how would you do this task.

Further more, I dont have to generate any UML model. I have already
exported XMI file which I have to parse. How can I do this??

regards,
Khan
Re: XMI Parser [message #477311 is a reply to message #477310] Thu, 01 May 2008 14:35 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Khan,

Do you know which tool produced the XMI file and which version of UML it is
based on?

Kenn

"Khan" <naeemkhans79@hotmail.com> wrote in message
news:8a50003e4eeed184153af7f59fb8d569$1@www.eclipse.org...
> Thank you for your answer. But I might have wrong conception about reading
> XMI files. I have already asked help in UML2 Newsgroup, as you recommend
> me. Could you please give me any idea how would you do this task.
> Further more, I dont have to generate any UML model. I have already
> exported XMI file which I have to parse. How can I do this??
>
> regards,
> Khan
>
>
Re: XMI Parser [message #477315 is a reply to message #477311] Thu, 01 May 2008 20:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

thanks for giving time. Basically, I am Using EclipseUML 3.3.2 and it is
based on UML 2.0 which is completable with XMI 2.0. If you have any Idea
what should better to use then please let me know. What I did is, I just
made Ecore Model and then opened it with Text Editor, copy the XMI Code
and saved with notepad with XMI Extension. I guess It is damn what I
did??? :-) But your recommendation are really welcome.

Regards,
Khan
Re: XMI Parser [message #477316 is a reply to message #477315] Thu, 01 May 2008 21:13 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Khan,

Have you tried saving the file with a .uml2 extension and opening it with
the sample UML editor? If you could attach the file (or a representative
sample) we could better advise you...

Kenn

"Khan" <naeemkhans79@hotmail.com> wrote in message
news:496858f813f8a9ff91780ecf4d3b918b$1@www.eclipse.org...
> thanks for giving time. Basically, I am Using EclipseUML 3.3.2 and it is
> based on UML 2.0 which is completable with XMI 2.0. If you have any Idea
> what should better to use then please let me know. What I did is, I just
> made Ecore Model and then opened it with Text Editor, copy the XMI Code
> and saved with notepad with XMI Extension. I guess It is damn what I
> did??? :-) But your recommendation are really welcome.
>
> Regards,
> Khan
>
>
Re: XMI Parser [message #477319 is a reply to message #477316] Fri, 02 May 2008 09:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

ja sure, below you can see the code of copied file as XMI from Ecore Model.

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="myFactory">
<eClassifiers xsi:type="ecore:EClass" name="Customer">
<eOperations name="getCstID" eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EBigInteger"/>
<eOperations name="getCustomerStatus" eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="CstID"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EBigInteger"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="CustomerStatus"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
</ecore:EPackage>


I like to parse this file and grab the object like Class Customer, Its
Properties and data types, and relations. What I have written the code in
java is you see here.

package src;

import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;

public class parser {

public static void main(String[] args){

// create resource set and resource
try{

ResourceSet resourceSet = new ResourceSetImpl();
// Register XML resource factory

resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xmi",
new XMIResourceFactoryImpl());

URI uri =
org.eclipse.emf.common.util.URI.createURI("C:/EcoreCustomer.XMI ");
Resource resource = resourceSet.createResource(uri);
TreeIterator ti = resource.getAllContents();
while (ti.hasNext()){
System.out.println(ti.getClass().getSimpleName());
}
}// end of try
catch (NullPointerException e){
e.getStackTrace();
}
}
}


Am I doing in the right thing to grab the XMI file saved on C: drive???
please help me out.

Khan
Re: XMI Parser [message #477321 is a reply to message #477319] Fri, 02 May 2008 11:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Khan,

Now the example seems completely unrelated to a serialized UML
instance. You're also using an upper case fix suffix, although you
registered a lower case one. And you're using a OS-dependent file
system path as if it were a URI. If you're just working with a simple
EMF model, I'd suggest you follow one of our tutorials, and invoke
"Generate Test Code" in the generator. That will produce a *.tests
project with an XyzExample.java that illustrates what you need to do to
read and write instances of that model in a stand-alone program.


Khan wrote:
> ja sure, below you can see the code of copied file as XMI from Ecore
> Model.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="myFactory">
> <eClassifiers xsi:type="ecore:EClass" name="Customer">
> <eOperations name="getCstID" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EBigInteger"/>
> <eOperations name="getCustomerStatus" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="CstID"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EBigInteger"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="CustomerStatus" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> I like to parse this file and grab the object like Class Customer, Its
> Properties and data types, and relations. What I have written the
> code in java is you see here.
>
> package src;
>
> import org.eclipse.emf.common.util.TreeIterator;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
>
> public class parser {
>
> public static void main(String[] args){
>
> // create resource set and resource try{
> ResourceSet resourceSet = new ResourceSetImpl();
> // Register XML resource factory
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xmi",
> new XMIResourceFactoryImpl());
>
> URI uri =
> org.eclipse.emf.common.util.URI.createURI("C:/EcoreCustomer.XMI ");
> Resource resource = resourceSet.createResource(uri);
> TreeIterator ti = resource.getAllContents();
> while (ti.hasNext()){
> System.out.println(ti.getClass().getSimpleName());
> }
> }// end of try
> catch (NullPointerException e){
> e.getStackTrace();
> } } }
>
>
> Am I doing in the right thing to grab the XMI file saved on C:
> drive??? please help me out.
>
> Khan
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #477328 is a reply to message #477321] Fri, 02 May 2008 15:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

Ed Merks,

If I change the suffix in lower case would it work, will I be able to read
XMI??? As you said, it is totally unrelated for UML instance. Well Merks,
I only have to write a java class where I can read stored Xmi file,
supposedly I have already converted XMI file saved some where on my
computer. In this case, am I going right???
Re: XMI Parser [message #477333 is a reply to message #477328] Fri, 02 May 2008 16:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Khan,

If you follow the EMF tutorial using your Ecore model and do what I
suggested to generate the example, that will provide you a working
example of what you need specific to your model. That's the best I can
offer.


Khan wrote:
> Ed Merks,
>
> If I change the suffix in lower case would it work, will I be able to
> read XMI??? As you said, it is totally unrelated for UML instance.
> Well Merks, I only have to write a java class where I can read stored
> Xmi file, supposedly I have already converted XMI file saved some
> where on my computer. In this case, am I going right???
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #477335 is a reply to message #477333] Fri, 02 May 2008 16:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

where can i find EMF tutorials and how can I generate Test Code?? can you
send me a link of that tutorial???
Re: XMI Parser [message #477336 is a reply to message #477335] Fri, 02 May 2008 16:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010907050800000600000201
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Khan,

Have a look at the tutorials on this page

http://www.eclipse.org/modeling/emf/docs/

These tutorials describe how to use the Generator to "Generate Model
Code". You'll see "Generate Test Code" on the same popup menu.


Khan wrote:
> where can i find EMF tutorials and how can I generate Test Code?? can
> you send me a link of that tutorial???
>


--------------010907050800000600000201
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Khan,<br>
<br>
Have a look at the tutorials on this page<br>
<blockquote><a href="http://www.eclipse.org/modeling/emf/docs/">http://www.eclipse.org/modeling/emf/docs/</a><br>
</blockquote>
These tutorials describe how to use the Generator to "Generate Model
Code".


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #477338 is a reply to message #477336] Sun, 04 May 2008 16:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

hi Ed Merks,

I am back to you after having detail EMF tutorial and your fantastic
online demostration of EMF round trip. Ecore to Java and back to it.

Well, EMF it very cool thing to facilitate modeling and programing world.
I can now create Ecore model based on any UML class diagram. and then What
I understood is to generate EMF Model which is called *.genmodel to
generate java codes.

I saw in your presentation project architecture which you created as Empty
EMF Project. It provides you Model folder and META-INF folder and other
two things I have seen (Plug-in Dependencies, and JRE System Library) that
I dont get any, when I create any Empty EMF Project.

But code generator I have seen. I will also generate code in my case
depending upon what I have made UML Class diagram. SO far it is fine, and
I uderstood. But later I need to parse the generated classes. Could you
please guide me how can i do this???


Regards,
Khan
Re: XMI Parser [message #477339 is a reply to message #477338] Sun, 04 May 2008 17:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Khan,

So you've invoked Generate Test Code and you have a *.tests project with
an XyzExample? This wasn't shown in the tutorials...

An empty project is useful for if you want to build your modeling from
annotated Javadoc or want to create an Ecore model directly. Once you
generate code into that project, the plugin.xml should be generated and
the MANFIEST.MF will be updated.


Khan wrote:
> hi Ed Merks,
>
> I am back to you after having detail EMF tutorial and your fantastic
> online demostration of EMF round trip. Ecore to Java and back to it.
>
> Well, EMF it very cool thing to facilitate modeling and programing
> world. I can now create Ecore model based on any UML class diagram.
> and then What I understood is to generate EMF Model which is called
> *.genmodel to generate java codes.
>
> I saw in your presentation project architecture which you created as
> Empty EMF Project. It provides you Model folder and META-INF folder
> and other two things I have seen (Plug-in Dependencies, and JRE System
> Library) that I dont get any, when I create any Empty EMF Project.
>
> But code generator I have seen. I will also generate code in my case
> depending upon what I have made UML Class diagram. SO far it is fine,
> and I uderstood. But later I need to parse the generated classes.
> Could you please guide me how can i do this???
>
>
> Regards,
> Khan
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #477340 is a reply to message #477339] Sun, 04 May 2008 17:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

of course, that was not in tutorial but I have seen similar example in
your live demonstration (uploaded at eclipse.org) that generates *.tests
folders. But please recommend me how can I parse UML model which is
generated as classes by *.genmodel (generate options).
Re: XMI Parser [message #477341 is a reply to message #477340] Sun, 04 May 2008 20:45 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Khan,

I'm not sure if you mean instances of UML itself or just a model for
which you happened to use UML as the way to define it. If the former,
the using the generated example is good, if the latter, then using the
documentation from the UML website is good.


Khan wrote:
> of course, that was not in tutorial but I have seen similar example in
> your live demonstration (uploaded at eclipse.org) that generates
> *.tests folders. But please recommend me how can I parse UML model
> which is generated as classes by *.genmodel (generate options).
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #626470 is a reply to message #477309] Thu, 01 May 2008 14:21 Go to previous message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

Thank you for your answer. But I might have wrong conception about reading
XMI files. I have already asked help in UML2 Newsgroup, as you recommend
me. Could you please give me any idea how would you do this task.

Further more, I dont have to generate any UML model. I have already
exported XMI file which I have to parse. How can I do this??

regards,
Khan
Re: XMI Parser [message #626471 is a reply to message #477310] Thu, 01 May 2008 14:35 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Khan,

Do you know which tool produced the XMI file and which version of UML it is
based on?

Kenn

"Khan" <naeemkhans79@hotmail.com> wrote in message
news:8a50003e4eeed184153af7f59fb8d569$1@www.eclipse.org...
> Thank you for your answer. But I might have wrong conception about reading
> XMI files. I have already asked help in UML2 Newsgroup, as you recommend
> me. Could you please give me any idea how would you do this task.
> Further more, I dont have to generate any UML model. I have already
> exported XMI file which I have to parse. How can I do this??
>
> regards,
> Khan
>
>
Re: XMI Parser [message #626476 is a reply to message #477311] Thu, 01 May 2008 20:45 Go to previous message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

thanks for giving time. Basically, I am Using EclipseUML 3.3.2 and it is
based on UML 2.0 which is completable with XMI 2.0. If you have any Idea
what should better to use then please let me know. What I did is, I just
made Ecore Model and then opened it with Text Editor, copy the XMI Code
and saved with notepad with XMI Extension. I guess It is damn what I
did??? :-) But your recommendation are really welcome.

Regards,
Khan
Re: XMI Parser [message #626477 is a reply to message #477315] Thu, 01 May 2008 21:13 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Khan,

Have you tried saving the file with a .uml2 extension and opening it with
the sample UML editor? If you could attach the file (or a representative
sample) we could better advise you...

Kenn

"Khan" <naeemkhans79@hotmail.com> wrote in message
news:496858f813f8a9ff91780ecf4d3b918b$1@www.eclipse.org...
> thanks for giving time. Basically, I am Using EclipseUML 3.3.2 and it is
> based on UML 2.0 which is completable with XMI 2.0. If you have any Idea
> what should better to use then please let me know. What I did is, I just
> made Ecore Model and then opened it with Text Editor, copy the XMI Code
> and saved with notepad with XMI Extension. I guess It is damn what I
> did??? :-) But your recommendation are really welcome.
>
> Regards,
> Khan
>
>
Re: XMI Parser [message #626480 is a reply to message #477316] Fri, 02 May 2008 09:28 Go to previous message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

ja sure, below you can see the code of copied file as XMI from Ecore Model.

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="myFactory">
<eClassifiers xsi:type="ecore:EClass" name="Customer">
<eOperations name="getCstID" eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EBigInteger"/>
<eOperations name="getCustomerStatus" eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="CstID"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EBigInteger"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="CustomerStatus"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
</ecore:EPackage>


I like to parse this file and grab the object like Class Customer, Its
Properties and data types, and relations. What I have written the code in
java is you see here.

package src;

import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;

public class parser {

public static void main(String[] args){

// create resource set and resource
try{

ResourceSet resourceSet = new ResourceSetImpl();
// Register XML resource factory

resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xmi",
new XMIResourceFactoryImpl());

URI uri =
org.eclipse.emf.common.util.URI.createURI("C:/EcoreCustomer.XMI ");
Resource resource = resourceSet.createResource(uri);
TreeIterator ti = resource.getAllContents();
while (ti.hasNext()){
System.out.println(ti.getClass().getSimpleName());
}
}// end of try
catch (NullPointerException e){
e.getStackTrace();
}
}
}


Am I doing in the right thing to grab the XMI file saved on C: drive???
please help me out.

Khan
Re: XMI Parser [message #626482 is a reply to message #477319] Fri, 02 May 2008 11:00 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Khan,

Now the example seems completely unrelated to a serialized UML
instance. You're also using an upper case fix suffix, although you
registered a lower case one. And you're using a OS-dependent file
system path as if it were a URI. If you're just working with a simple
EMF model, I'd suggest you follow one of our tutorials, and invoke
"Generate Test Code" in the generator. That will produce a *.tests
project with an XyzExample.java that illustrates what you need to do to
read and write instances of that model in a stand-alone program.


Khan wrote:
> ja sure, below you can see the code of copied file as XMI from Ecore
> Model.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="myFactory">
> <eClassifiers xsi:type="ecore:EClass" name="Customer">
> <eOperations name="getCstID" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EBigInteger"/>
> <eOperations name="getCustomerStatus" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="CstID"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EBigInteger"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="CustomerStatus" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> I like to parse this file and grab the object like Class Customer, Its
> Properties and data types, and relations. What I have written the
> code in java is you see here.
>
> package src;
>
> import org.eclipse.emf.common.util.TreeIterator;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
>
> public class parser {
>
> public static void main(String[] args){
>
> // create resource set and resource try{
> ResourceSet resourceSet = new ResourceSetImpl();
> // Register XML resource factory
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xmi",
> new XMIResourceFactoryImpl());
>
> URI uri =
> org.eclipse.emf.common.util.URI.createURI("C:/EcoreCustomer.XMI ");
> Resource resource = resourceSet.createResource(uri);
> TreeIterator ti = resource.getAllContents();
> while (ti.hasNext()){
> System.out.println(ti.getClass().getSimpleName());
> }
> }// end of try
> catch (NullPointerException e){
> e.getStackTrace();
> } } }
>
>
> Am I doing in the right thing to grab the XMI file saved on C:
> drive??? please help me out.
>
> Khan
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #626489 is a reply to message #477321] Fri, 02 May 2008 15:17 Go to previous message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

Ed Merks,

If I change the suffix in lower case would it work, will I be able to read
XMI??? As you said, it is totally unrelated for UML instance. Well Merks,
I only have to write a java class where I can read stored Xmi file,
supposedly I have already converted XMI file saved some where on my
computer. In this case, am I going right???
Re: XMI Parser [message #626510 is a reply to message #477328] Fri, 02 May 2008 16:03 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Khan,

If you follow the EMF tutorial using your Ecore model and do what I
suggested to generate the example, that will provide you a working
example of what you need specific to your model. That's the best I can
offer.


Khan wrote:
> Ed Merks,
>
> If I change the suffix in lower case would it work, will I be able to
> read XMI??? As you said, it is totally unrelated for UML instance.
> Well Merks, I only have to write a java class where I can read stored
> Xmi file, supposedly I have already converted XMI file saved some
> where on my computer. In this case, am I going right???
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #626513 is a reply to message #477333] Fri, 02 May 2008 16:22 Go to previous message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

where can i find EMF tutorials and how can I generate Test Code?? can you
send me a link of that tutorial???
Re: XMI Parser [message #626514 is a reply to message #477335] Fri, 02 May 2008 16:30 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010907050800000600000201
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Khan,

Have a look at the tutorials on this page

http://www.eclipse.org/modeling/emf/docs/

These tutorials describe how to use the Generator to "Generate Model
Code". You'll see "Generate Test Code" on the same popup menu.


Khan wrote:
> where can i find EMF tutorials and how can I generate Test Code?? can
> you send me a link of that tutorial???
>


--------------010907050800000600000201
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Khan,<br>
<br>
Have a look at the tutorials on this page<br>
<blockquote><a href="http://www.eclipse.org/modeling/emf/docs/">http://www.eclipse.org/modeling/emf/docs/</a><br>
</blockquote>
These tutorials describe how to use the Generator to "Generate Model
Code".


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #626516 is a reply to message #477336] Sun, 04 May 2008 16:38 Go to previous message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

hi Ed Merks,

I am back to you after having detail EMF tutorial and your fantastic
online demostration of EMF round trip. Ecore to Java and back to it.

Well, EMF it very cool thing to facilitate modeling and programing world.
I can now create Ecore model based on any UML class diagram. and then What
I understood is to generate EMF Model which is called *.genmodel to
generate java codes.

I saw in your presentation project architecture which you created as Empty
EMF Project. It provides you Model folder and META-INF folder and other
two things I have seen (Plug-in Dependencies, and JRE System Library) that
I dont get any, when I create any Empty EMF Project.

But code generator I have seen. I will also generate code in my case
depending upon what I have made UML Class diagram. SO far it is fine, and
I uderstood. But later I need to parse the generated classes. Could you
please guide me how can i do this???


Regards,
Khan
Re: XMI Parser [message #626517 is a reply to message #477338] Sun, 04 May 2008 17:06 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Khan,

So you've invoked Generate Test Code and you have a *.tests project with
an XyzExample? This wasn't shown in the tutorials...

An empty project is useful for if you want to build your modeling from
annotated Javadoc or want to create an Ecore model directly. Once you
generate code into that project, the plugin.xml should be generated and
the MANFIEST.MF will be updated.


Khan wrote:
> hi Ed Merks,
>
> I am back to you after having detail EMF tutorial and your fantastic
> online demostration of EMF round trip. Ecore to Java and back to it.
>
> Well, EMF it very cool thing to facilitate modeling and programing
> world. I can now create Ecore model based on any UML class diagram.
> and then What I understood is to generate EMF Model which is called
> *.genmodel to generate java codes.
>
> I saw in your presentation project architecture which you created as
> Empty EMF Project. It provides you Model folder and META-INF folder
> and other two things I have seen (Plug-in Dependencies, and JRE System
> Library) that I dont get any, when I create any Empty EMF Project.
>
> But code generator I have seen. I will also generate code in my case
> depending upon what I have made UML Class diagram. SO far it is fine,
> and I uderstood. But later I need to parse the generated classes.
> Could you please guide me how can i do this???
>
>
> Regards,
> Khan
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMI Parser [message #626518 is a reply to message #477339] Sun, 04 May 2008 17:45 Go to previous message
Eclipse UserFriend
Originally posted by: naeemkhans79.hotmail.com

of course, that was not in tutorial but I have seen similar example in
your live demonstration (uploaded at eclipse.org) that generates *.tests
folders. But please recommend me how can I parse UML model which is
generated as classes by *.genmodel (generate options).
Re: XMI Parser [message #626519 is a reply to message #477340] Sun, 04 May 2008 20:45 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Khan,

I'm not sure if you mean instances of UML itself or just a model for
which you happened to use UML as the way to define it. If the former,
the using the generated example is good, if the latter, then using the
documentation from the UML website is good.


Khan wrote:
> of course, that was not in tutorial but I have seen similar example in
> your live demonstration (uploaded at eclipse.org) that generates
> *.tests folders. But please recommend me how can I parse UML model
> which is generated as classes by *.genmodel (generate options).
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Template Parameter upper/lower bound spec
Next Topic:Wich UML2 metamodel implemetation MagicDraw uses?
Goto Forum:
  


Current Time: Thu Mar 28 10:01:58 GMT 2024

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

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

Back to the top