Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Persisting _all_ values?
Persisting _all_ values? [message #422728] Mon, 15 September 2008 13:36 Go to next message
Morten MacFly is currently offline Morten MacFlyFriend
Messages: 69
Registered: July 2009
Member
Dear NG,

I have another question:
I am working with a generated editor out of an ECore model. When I save
the work (in the runtime of the editor) it creates a XML file (just as
setup in the genmodel) which is fine.
Unfortunately the editor's "save routine" does not persist values which
are set to it's default value.
Can I (somehow) tell the persistence layer to save all values to the XML
file, including those which are set to it's default values?

In addition: How would I override the save routine if I wanted to do it
all by myself?

With regards, Morten.
Re: Persisting _all_ values? [message #422732 is a reply to message #422728] Mon, 15 September 2008 14:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30813
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070100030609030208080809
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Morten,

Comments below.

Morten MacFly wrote:
> Dear NG,
>
> I have another question:
> I am working with a generated editor out of an ECore model. When I save
> the work (in the runtime of the editor) it creates a XML file (just as
> setup in the genmodel) which is fine.
> Unfortunately the editor's "save routine" does not persist values which
> are set to it's default value.
> Can I (somehow) tell the persistence layer to save all values to the XML
> file, including those which are set to it's default values?
>
This will serialize the explicit default of the attributes (but not the
implicit default, i.e., the 0 for an int):

/**
* Keep default content ( e.g. default attributes). This applies
to saving and converting contents to DOM.
* By default the default content is discarded.
* To save the default content, set this option to
<code>Boolean.TRUE</code>.
*/
String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";


> In addition: How would I override the save routine if I wanted to do it
> all by myself?
>
> With regards, Morten.
>

--------------070100030609030208080809
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">
Morten,<br>
<br>
Comments below.<br>
<br>
Morten MacFly wrote:
<blockquote cite="mid:galod6$8ce$1@build.eclipse.org" type="cite">
<pre wrap="">Dear NG,

I have another question:
I am working with a generated editor out of an ECore model. When I save
the work (in the runtime of the editor) it creates a XML file (just as
setup in the genmodel) which is fine.
Unfortunately the editor's "save routine" does not persist values which
are set to it's default value.
Can I (somehow) tell the persistence layer to save all values to the XML
file, including those which are set to it's default values?
</pre>
</blockquote>
This will serialize the explicit default of the attributes (but not the
implicit default, i.e., the 0 for an int):<br>
<blockquote>&nbsp; /**<br>
&nbsp;&nbsp; * Keep default content ( e.g. default attributes). This applies to
saving and converting contents to DOM.<br>
&nbsp;&nbsp; * By default the default content is discarded.<br>
&nbsp;&nbsp; * To save the default content, set this option to
&lt;code&gt;Boolean.TRUE&lt;/code&gt;.<br>
&nbsp;&nbsp; */<br>
&nbsp; String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";<br>
</blockquote>
<br>
<blockquote cite="mid:galod6$8ce$1@build.eclipse.org" type="cite">
<pre wrap="">
In addition: How would I override the save routine if I wanted to do it
all by myself?

With regards, Morten.
</pre>
</blockquote>
</body>
</html>

--------------070100030609030208080809--
Re: Persisting _all_ values? [message #422734 is a reply to message #422732] Mon, 15 September 2008 15:57 Go to previous messageGo to next message
Morten MacFly is currently offline Morten MacFlyFriend
Messages: 69
Registered: July 2009
Member
Ed Merks wrote:
> String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";
Sorry Ed,
I understand what you are telling me but I don't get it to work. I
searched the forum / internet for help but no success.

I did the following: In the I did two overrides in the specialisation of
the XMLResourceImpl implementation of the editor this way:

@Override
public void doSave(OutputStream outputStream, Map<?, ?> options) throws
IOException {
this.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEF AULT_CONTENT,
Boolean.TRUE);
super.doSave(outputStream, options);
}

@Override
public void doSave(Writer writer, Map<?, ?> options) throws IOException {
this.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEF AULT_CONTENT,
Boolean.TRUE);
super.doSave(writer, options);
}

Notice I first tried tried directly:
options.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);

....but this gave me the following error:
The method put(capture#3-of ?, capture#4-of ?) in the type
Map<capture#3-of ?,capture#4-of ?> is not applicable for the arguments
(String, Boolean)

Either way the XML serialisation does not change at all.

This might sound stupid, but what am I missing?

With regards, Morten.
Re: Persisting _all_ values? [message #422741 is a reply to message #422734] Mon, 15 September 2008 17:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30813
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090701080900010208020501
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Morten,

Comments below.

Morten MacFly wrote:
> Ed Merks wrote:
>
>> String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";
>>
> Sorry Ed,
> I understand what you are telling me but I don't get it to work. I
> searched the forum / internet for help but no success.
>
> I did the following: In the I did two overrides in the specialisation of
> the XMLResourceImpl implementation of the editor this way:
>
> @Override
> public void doSave(OutputStream outputStream, Map<?, ?> options) throws
> IOException {
> this.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEF AULT_CONTENT,
> Boolean.TRUE);
> super.doSave(outputStream, options);
> }
>
It's expect you to modify the factory. Did you check to notice that
adding it to the default options at this point is already too late?
> @Override
> public void doSave(Writer writer, Map<?, ?> options) throws IOException {
> this.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEF AULT_CONTENT,
> Boolean.TRUE);
> super.doSave(writer, options);
> }
>
> Notice I first tried tried directly:
> options.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
>
> ...but this gave me the following error:
> The method put(capture#3-of ?, capture#4-of ?) in the type
> Map<capture#3-of ?,capture#4-of ?> is not applicable for the arguments
> (String, Boolean)
>
Yes, you shouldn't modify the map the client passed in.
> Either way the XML serialisation does not change at all.
>
> This might sound stupid, but what am I missing?
>
You should do this in your resource factory.
> With regards, Morten.
>

--------------090701080900010208020501
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">
Morten,<br>
<br>
Comments below.<br>
<br>
Morten MacFly wrote:
<blockquote cite="mid:gam0l0$enm$1@build.eclipse.org" type="cite">
<pre wrap="">Ed Merks wrote:
</pre>
<blockquote type="cite">
<pre wrap=""> String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";
</pre>
</blockquote>
<pre wrap=""><!---->Sorry Ed,
I understand what you are telling me but I don't get it to work. I
searched the forum / internet for help but no success.

I did the following: In the I did two overrides in the specialisation of
the XMLResourceImpl implementation of the editor this way:

@Override
public void doSave(OutputStream outputStream, Map&lt;?, ?&gt; options) throws
IOException {
this.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEF AULT_CONTENT,
Boolean.TRUE);
super.doSave(outputStream, options);
}
</pre>
</blockquote>
It's expect you to modify the factory.&nbsp; Did you check to notice that
adding it to the default options at this point is already too late?<br>
<blockquote cite="mid:gam0l0$enm$1@build.eclipse.org" type="cite">
<pre wrap="">
@Override
public void doSave(Writer writer, Map&lt;?, ?&gt; options) throws IOException {
this.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEF AULT_CONTENT,
Boolean.TRUE);
super.doSave(writer, options);
}

Notice I first tried tried directly:
options.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);

....but this gave me the following error:
The method put(capture#3-of ?, capture#4-of ?) in the type
Map&lt;capture#3-of ?,capture#4-of ?&gt; is not applicable for the arguments
(String, Boolean)
</pre>
</blockquote>
Yes, you shouldn't modify the map the client passed in.<br>
<blockquote cite="mid:gam0l0$enm$1@build.eclipse.org" type="cite">
<pre wrap="">
Either way the XML serialisation does not change at all.

This might sound stupid, but what am I missing?
</pre>
</blockquote>
You should do this in your resource factory.<br>
<blockquote cite="mid:gam0l0$enm$1@build.eclipse.org" type="cite">
<pre wrap="">
With regards, Morten.
</pre>
</blockquote>
</body>
</html>

--------------090701080900010208020501--
Re: Persisting _all_ values? [message #422937 is a reply to message #422741] Fri, 19 September 2008 11:28 Go to previous message
Morten MacFly is currently offline Morten MacFlyFriend
Messages: 69
Registered: July 2009
Member
Ed Merks wrote:
[...]
> It's expect you to modify the factory. Did you check to notice that
> adding it to the default options at this point is already too late?
[...]
> Yes, you shouldn't modify the map the client passed in.
[...]
> You should do this in your resource factory.

Darn... obiously. Thanks Ed, it works now. Seems not to have been one of
my smartest days. :-(
Previous Topic:[CDO] Objectivity as CDO database
Next Topic:Strange-looking code in EMF
Goto Forum:
  


Current Time: Sat Jan 25 08:15:24 GMT 2020

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

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

Back to the top