Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsXMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878067/#msg_878067
How to create java objects from an XMI file(target.xmi)?
option 1: I know, it must be possible reading through an XML parser. // I do not like this approach, it is a lot of coding.
option 2: I know, eclipse EMF provides EMF generator model. I could manage to take Generate Model Code from the .ecore model related to this XMI file (target.ecore). The generated code consist of model, model.impl and model.util. Now, Is it possible to use these coding to read XMI file to generate java objects? How to do that?
I am trying to create java objects from the following XMI file(target.xmi).
<HeadModule xsi:type="target:Module"
name="PSSu E F PS (PROFIsafe)"
deviceID="0x00000801"
s7ModuleReference="{9A856DAC-1D0A-46F7-B69F-40E2DC6511DD}{001417C5-0000002F-001417C3-0000002A-00112001-00000107}{SD_example1}"
isSelectedWithinStep7="false"/>
</target:Device>
Thanks in advance.
Kosala]]>Kosala Yapa2012-05-28T13:00:15-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878080/#msg_878080
Trying invoking Generate Test Code and look at the generated XyzExample
in the *.tests project.
On 28/05/2012 3:00 PM, Kosala Yapa wrote:
> Hi there,
>
> How to create java objects from an XMI file(target.xmi)?
> option 1: I know, it must be possible reading through an XML parser.
> // I do not like this approach, it is a lot of coding.
>
> option 2: I know, eclipse EMF provides EMF generator model. I could
> manage to take Generate Model Code from the .ecore model related to
> this XMI file (target.ecore). The generated code consist of model,
> model.impl and model.util. Now, Is it possible to use these coding to
> read XMI file to generate java objects? How to do that?
>
>
> I am trying to create java objects from the following XMI
> file(target.xmi).
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> <target:Device xmi:version="2.0" xmlns:xmi="...//www.omg.org/XMI"
> xmlns:xsi="...//www.w3.org/2001/XMLSchema-instance"
> xmlns:target="target" name="PSSuniversal22222"
> s7DeviceReference="{7F6AC5F1-E8E0-49E5-ABA1-26E4A6A74175}{001417C3-00000003-001417B3-00000002-00112001-00000107}{SD_example1}">
>
> <Module name="PSSuES4DO0.5_1" deviceID="0x00000C00"
>
> s7ModuleReference="CFAF3ED5-37E4-476B-AE64-94FDD6429D1E}{001417C5-00000009-001417C3-00000003-00112001-00000107"
> isSelectedWithinStep7="false"/>
>
> <Module name="PSSuniversal33333" deviceID="0x00000229"
>
> s7ModuleReference="CFAF3ED5-37E4-476B-AE64-94FDD6429D1E}{001417C5-00000009-001417C3-00000003-00112001-00000108"
> isSelectedWithinStep7="false"/>
>
> <HeadModule xsi:type="target:Module" name="PSSu E F PS
> (PROFIsafe)" deviceID="0x00000801"
> s7ModuleReference="{9A856DAC-1D0A-46F7-B69F-40E2DC6511DD}{001417C5-0000002F-001417C3-0000002A-00112001-00000107}{SD_example1}"
> isSelectedWithinStep7="false"/>
>
> </target:Device>
>
>
> Thanks in advance.
> Kosala]]>Ed Merks2012-05-28T13:35:07-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878086/#msg_878086
I right clicked on the package Target and run Generate Test Code, but I cannot find where this XyZExample is created. It looks like something is hapenning without errors. I cannot find any *.tests project. Do you have any clue, where this project is created?
Thanks
Kosala]]>Kosala Yapa2012-05-28T13:49:51-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878092/#msg_878092
Click on the root, i.e., GenModel. Of course the Xyz in XyzExample
depends on the name of your model as does the * in the *.tests project.
On 28/05/2012 3:49 PM, Kosala Yapa wrote:
> Hi Merks,
>
> I right clicked on the package Target and run Generate Test Code, but
> I cannot find where this XyZExample is created. It looks like
> something is hapenning without errors. I cannot find any *.tests
> project. Do you have any clue, where this project is created?
>
> Thanks
> Kosala]]>Ed Merks2012-05-28T14:12:57-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878103/#msg_878103
Thanks. Do you think, should I use Generate Edit and Generate Editor before Generate Test Code? They looks necessary for Generate Test Code. ]]>Kosala Yapa2012-05-28T14:53:14-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878177/#msg_878177
dependencies in the MANIFEST.MF).
On 28/05/2012 4:53 PM, Kosala Yapa wrote:
> Merks,
> Thanks. Do you think, should I use Generate Edit and Generate Editor
> before Generate Test Code? They looks necessary for Generate Test Code.]]>Ed Merks2012-05-28T18:47:32-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878390/#msg_878390
I could manage to get the tests from Generate Test Code.
My xyz.xmi file is located in C:\...\abc.model
How can i read it from XYZExample.java?
I just tried the following, but does not work yet.
Thanks.
Kosala]]>Kosala Yapa2012-05-29T08:03:33-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878424/#msg_878424
Please look closely at how the generated example handles the args from main.
On 29/05/2012 10:03 AM, Kosala Yapa wrote:
> Hi Merks,
>
> I could manage to get the tests from Generate Test Code.
>
> My xyz.xmi file is located in C:\...\abc.model
>
> How can i read it from XYZExample.java?
>
> I just tried the following, but does not work yet.
>
> Resource resource =
> resourceSet.createResource(URI.createURI("C:/.../abc.model/xyz.xmi"));
>
> Any help is appriciated.
>
> Thanks.
> Kosala]]>Ed Merks2012-05-29T09:25:05-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878562/#msg_878562
I am not passing any parameter to main().
that is
----
if (args.length == 0) {
System.out.println("Enter a list of file paths or URIs that have content like this:");
try {
Resource resource = resourceSet.createResource(URI.createURI("C:/.../abc.model/xyz.xmi"));
Device root = TargetFactory.eINSTANCE.createDevice();
resource.getContents().add(root);
resource.save(System.out, null);
}
catch (IOException exception) {
exception.printStackTrace();
}
}
------
but it does not read the xmi file.
]]>Kosala Yapa2012-05-29T14:25:44-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878582/#msg_878582
there actually are arguments?
On 29/05/2012 4:25 PM, Kosala Yapa wrote:
> Hi there,
>
> I am not passing any parameter to main().
>
> that is ----
> if (args.length == 0) {
> System.out.println("Enter a list of file paths or URIs
> that have content like this:");
> try {
> Resource resource =
> resourceSet.createResource(URI.createURI("C:/.../abc.model/xyz.xmi"));
> Device root = TargetFactory.eINSTANCE.createDevice();
> resource.getContents().add(root);
> resource.save(System.out, null);
> }
> catch (IOException exception) {
> exception.printStackTrace();
> }
> }
>
> ------
>
> but it does not read the xmi file.
>
>
>]]>Ed Merks2012-05-29T15:01:16-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878928/#msg_878928
Thanks. You are right.
my xmi file is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Device xmi:version="2.0" xmlns:xmi=".../XMI" xmlns:xsi=".../2001/XMLSchema-instance" xmlns="" name="PSSuniversal22222" s7DeviceReference="{7F6AC5F1-E8E0-49E5-ABA1-26E4A6A74175}{001417C3-00000003-001417B3-00000002-00112001-00000107}{SD_example1}">
<Module name="PSSuES4DO0.5_1" deviceID="0x00000C00" s7ModuleReference="CFAF3ED5-37E4-476B-AE64-94FDD6429D1E}{001417C5-00000009-001417C3-00000003-00112001-00000107" isSelectedWithinStep7="false"/>
<Module name="PSSuniversal33333" deviceID="0x00000229" s7ModuleReference="CFAF3ED5-37E4-476B-AE64-94FDD6429D1E}{001417C5-00000009-001417C3-00000003-00112001-00000108" isSelectedWithinStep7="false"/>
<HeadModule xsi:type="Module" name="PSSu E F PS (PROFIsafe)" deviceID="0x00000801" s7ModuleReference="{9A856DAC-1D0A-46F7-B69F-40E2DC6511DD}{001417C5-0000002F-001417C3-0000002A-00112001-00000107}{SD_example1}" isSelectedWithinStep7="false"/>
</Device>
Thanks
K
]]>Kosala Yapa2012-05-30T08:17:55-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878937/#msg_878937
Your XMI looks quite odd. Doesn't your EPackage have a proper nsURI?
I'd expect the root element of your XMI to be qualified...
if (args.length == 0) {
System.out.println("Enter a list of file paths or URIs that have content like this:");
try {
Resource resource = resourceSet.createResource(URI.createURI("C:/.../tpfOut.xmi"));
Device root = TargetFactory.eINSTANCE.createDevice();
resource.getContents().add(root);
resource.save(System.out, null);
System.out.println(root);
}
output is:
Enter a list of file paths or URIs that have content like this:
<?xml version="1.0" encoding="ASCII"?>
<Device xmi:version="2.0" xmlns:xmi=".../XMI" xmlns="target"/> target.impl.DeviceImpl@aaa392 (name: null, s7DeviceReference: null)
still null data.
]]>Kosala Yapa2012-05-30T09:06:12-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/878988/#msg_878988
Kosala Yapa2012-05-30T10:10:17-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/879028/#msg_879028
Comments below.
On 30/05/2012 11:06 AM, Kosala Yapa wrote:
> EPackage:
>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi=".../XMI" xmlns:xsi=".../2001/XMLSchema-instance"
> xmlns:ecore=".../emf/2002/Ecore" name="source"
> nsURI="source" nsPrefix="">
> ..
>
> now I get xmi as:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Device xmi:version="2.0" xmlns:xmi=".../XMI"
> xmlns:xsi=".../2001/XMLSchema-instance" xmlns="target"
I'd expect this to be "source".
> name="PSSuniversal22222"
> s7DeviceReference="{7F6AC5F1-E8E0-49E5-ABA1-26E4A6A74175}{001417C3-00000003-001417B3-00000002-00112001-00000107}{SD_example1}">
> ..
> </Device>
>
>
>
> java code is:
>
> if (args.length == 0) {
> System.out.println("Enter a list of file paths or URIs
> that have content like this:");
> try {
> Resource resource =
> resourceSet.createResource(URI.createURI("C:/.../tpfOut.xmi"));
> Device root = TargetFactory.eINSTANCE.createDevice();
> resource.getContents().add(root);
> resource.save(System.out, null);
> System.out.println(root);
> }
>
>
>
>
> output is:
>
> Enter a list of file paths or URIs that have content like this:
> <?xml version="1.0" encoding="ASCII"?>
> <Device xmi:version="2.0" xmlns:xmi=".../XMI" xmlns="target"/>
> mailto:target.impl.DeviceImpl@aaa392 (name: null, s7DeviceReference:
> null)
You've created resource with an empty new object where you haven't
populated any data.
>
>
> still null data.
>
>]]>Ed Merks2012-05-30T11:37:20-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/879029/#msg_879029
So you can edit (read/write/modify) instances of your model.
On 30/05/2012 12:10 PM, Kosala Yapa wrote:
> what is the use of edit and editor created from genmodel?]]>Ed Merks2012-05-30T11:37:58-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/879625/#msg_879625
This is done now. Thanks a million Merks.
Presently, I am running this ATL program using eclipse Run Configuration. I am exploring, how to run this transformation using a java program.
org.eclipse.m2m.atl.engine.AtlLauncher looks like a possible approach.
Do you have any clue, any easy way to do this?
Thanks
Kosala]]>Kosala Yapa2012-05-31T14:35:38-00:00Re: XMI to java objects
https://www.eclipse.org/forums/index.php/mv/msg/356288/879637/#msg_879637
On 31/05/2012 4:35 PM, Kosala Yapa wrote:
> Hi,
>
> This is done now. Thanks a million Merks.
> Presently, I am running this ATL program using eclipse Run
> Configuration. I am exploring, how to run this transformation using a
> java program.
> org.eclipse.m2m.atl.engine.AtlLauncher looks like a possible approach.
>
> Do you have any clue, any easy way to do this?
>
> Thanks
> Kosala]]>Ed Merks2012-05-31T14:59:00-00:00