Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Programmatically serialize with Dynamic instance Xmi format
Programmatically serialize with Dynamic instance Xmi format [message #414598] Wed, 14 November 2007 12:50 Go to next message
Eclipse UserFriend
Originally posted by: yann.davin.gmail.com

Hi all,

I have created a xmi instance of my ecore model with the 'dynamic
instance' menu. Programmatically I read the instance created and copy it
propertly but when I try to serialize it in a new xmi file, the xmi
created file doesn't contain the
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and the
xsi:schemaLocation=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
fractaladl.ecore"
present in the instance created with the 'dynamic instance'.

How can I do to add these informations during the serialization ?

Thanks,


Xmi file created by the dynamic instance :
<?xml version="1.0" encoding="ASCII"?>
<fractaladl:System xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:fractaladl=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0"
xsi:schemaLocation=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
fractaladl.ecore">
<definitions>
<attributes/>
<interfaces/>
<components/>
<components/>
</definitions>
</fractaladl:System>

xmi file serialized programmatically without all needed informations...
<?xml version="1.0" encoding="ASCII"?>
<fractaladl:System xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:fractaladl=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0">
<definitions>
<attributes/>
<interfaces/>
<components/>
<components/>
</definitions>
</fractaladl:System>

--code which loads the xmi file created by the dynamic instance, copy it
and try to serialize it again--
EcoreUtil.Copier copier = new EcoreUtil.Copier();
Collection<EObject> results = copier.copyAll(resource.getContents());
copier.copyReferences();
modifiedResource.getContents().addAll(results);

// Save the contents of the resource to the file system.
try
{
Map options = new HashMap();
//options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
//options.put(XMIResource.OPTION_DECLARE_XML,
Boolean.TRUE);
//options.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
modifiedResource.save(options);
}catch(IOException e){
System.err.println(e.getMessage());
}

Yann
Re: Programmatically serialize with Dynamic instance Xmi format [message #414600 is a reply to message #414598] Wed, 14 November 2007 13:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070107060602060906000103
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Yann,

I added this to the FAQ:

2.21 How can I ensure that an xsi:schemaLocation is serialized for
my packages?
< http://wiki.eclipse.org/EMF/FAQ#How_can_I_ensure_that_an_xsi :schemaLocation_is_serialized_for_my_packages.3F>


yann davin wrote:
> Hi all,
>
> I have created a xmi instance of my ecore model with the 'dynamic
> instance' menu. Programmatically I read the instance created and copy
> it propertly but when I try to serialize it in a new xmi file, the xmi
> created file doesn't contain the
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and the
> xsi:schemaLocation=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
> fractaladl.ecore"
> present in the instance created with the 'dynamic instance'.
>
> How can I do to add these informations during the serialization ?
>
> Thanks,
>
>
> Xmi file created by the dynamic instance :
> <?xml version="1.0" encoding="ASCII"?>
> <fractaladl:System xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:fractaladl=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0"
> xsi:schemaLocation=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
> fractaladl.ecore">
> <definitions>
> <attributes/>
> <interfaces/>
> <components/>
> <components/>
> </definitions>
> </fractaladl:System>
>
> xmi file serialized programmatically without all needed informations...
> <?xml version="1.0" encoding="ASCII"?>
> <fractaladl:System xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:fractaladl=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0">
>
> <definitions>
> <attributes/>
> <interfaces/>
> <components/>
> <components/>
> </definitions>
> </fractaladl:System>
>
> --code which loads the xmi file created by the dynamic instance, copy
> it and try to serialize it again--
> EcoreUtil.Copier copier = new EcoreUtil.Copier();
> Collection<EObject> results =
> copier.copyAll(resource.getContents());
> copier.copyReferences();
> modifiedResource.getContents().addAll(results);
>
> // Save the contents of the resource to the file system.
> try
> {
> Map options = new HashMap();
> //options.put(XMIResource.OPTION_SCHEMA_LOCATION,
> Boolean.TRUE);
> //options.put(XMIResource.OPTION_DECLARE_XML,
> Boolean.TRUE);
> //options.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
> modifiedResource.save(options);
> }catch(IOException e){
> System.err.println(e.getMessage());
> }
>
> Yann


--------------070107060602060906000103
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Yann,<br>
<br>
I added this to the FAQ:<br>
<blockquote><a
href=" http://wiki.eclipse.org/EMF/FAQ#How_can_I_ensure_that_an_xsi :schemaLocation_is_serialized_for_my_packages.3F"><span
class="tocnumber">2.21</span> <span class="toctext">How can I ensure
that an xsi:schemaLocation is serialized for my packages?</span></a><br>
</blockquote>
<br>
yann davin wrote:
<blockquote cite="mid:fhequr$79v$1@build.eclipse.org" type="cite">Hi
all,
<br>
<br>
I have created a xmi instance of my ecore model with the 'dynamic
instance' menu. Programmatically I read the instance created and copy
it propertly but when I try to serialize it in a new xmi file, the xmi
created file doesn't contain the
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>&nbsp; and the
<br>
xsi:schemaLocation=<a class="moz-txt-link-rfc2396E" href=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0fractaladl.ecore">" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
fractaladl.ecore"</a>
<br>
present in the instance created with the 'dynamic instance'.
<br>
<br>
How can I do to add these informations during the serialization ?
<br>
<br>
Thanks,
<br>
<br>
<br>
Xmi file created by the dynamic instance :
<br>
&lt;?xml version="1.0" encoding="ASCII"?&gt;
<br>
&lt;fractaladl:System xmi:version="2.0"
xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns:fractaladl=<a class="moz-txt-link-rfc2396E" href=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0">" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0"</a>
xsi:schemaLocation=<a class="moz-txt-link-rfc2396E" href=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0fractaladl.ecore">" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
fractaladl.ecore"</a>&gt;
<br>
&nbsp; &lt;definitions&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;attributes/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;interfaces/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;components/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;components/&gt;
<br>
&nbsp; &lt;/definitions&gt;
<br>
&lt;/fractaladl:System&gt;
<br>
<br>
xmi file serialized programmatically without all needed informations...
<br>
&lt;?xml version="1.0" encoding="ASCII"?&gt;
<br>
&lt;fractaladl:System xmi:version="2.0"
xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:fractaladl=<a class="moz-txt-link-rfc2396E" href=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0">" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0"</a>&gt;
<br>
&nbsp; &lt;definitions&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;attributes/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;interfaces/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;components/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;components/&gt;
<br>
&nbsp; &lt;/definitions&gt;
<br>
&lt;/fractaladl:System&gt;
<br>
<br>
--code which loads the xmi file created by the dynamic instance, copy
it and try to serialize it again--
<br>
EcoreUtil.Copier copier = new EcoreUtil.Copier();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Collection&lt;EObject&gt; results =
copier.copyAll(resource.getContents());
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; copier.copyReferences();
<br>
modifiedResource.getContents().addAll(results);
<br>
<br>
&nbsp;// Save the contents of the resource to the file system.
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Map options = new HashMap();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; //options.put(XMIResource.OPTION_SCHEMA_LOCATION,
Boolean.TRUE);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; //options.put(XMIResource.OPTION_DECLARE_XML,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Boolean.TRUE);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; //options.put(XMIResource.OPTION_USE_XMI_TYPE,&nbsp;
Boolean.TRUE);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; modifiedResource.save(options);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }catch(IOException e){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; System.err.println(e.getMessage());
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
<br>
Yann
<br>
</blockquote>
<br>
</body>
</html>

--------------070107060602060906000103--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:about JavaSpider
Next Topic:[Announce] The EclipseCon 2008 Submission Deadline is Rapidly Approaching.
Goto Forum:
  


Current Time: Fri Apr 26 06:11:51 GMT 2024

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

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

Back to the top