Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » How do I override doSave and doLoad?(It is already overridden by XMLResourceImpl)
| | |
Re: How do I override doSave and doLoad? [message #521206 is a reply to message #521198] |
Tue, 16 March 2010 17:53 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------070004040702040401010907
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Herb,
Comments below.
Herb Miller wrote:
> Just remember this is not my idea, but here goes.
A disclaimer. Whose idea might it be?
>
> Included is a short sample file and under that is the same file with
> changes. The changes are to remove the "kms_ns:"
Given it's an XMI serialization, I'm not sure the sense in removing the
namespace qualification for the root element. Who could possibly stand
to benefit by making the corresponding package/schema unknowable? You
could look at the extended meta data annotations and generated resource
factory impl for a no target namespace schema for how to achieve this.
> and the "xsi:" when saving the files, and to replace them when loading
> the files.
And what would you do in place of xsi? The deserializer will need to
know what type of object to create. I.e., an Observation verses a
Decision? You could use substitution groups:
<http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html>
http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html
>
> Thanks.
>
> === Existing===========================
> <?xml version="1.0" encoding="UTF-8"?>
>
> <kms_ns:Item
> xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:kms_ns="com.cohesionforce.kms"
> URI="URI-000001"
> Description="Placeholder for head of list. See:
> http://www.eclipse.org/articles/Article-EMF-goes-RCP/rcp.htm l"
> Title="Root"
> DesignatedAuthority="" ResponsibleParty="">
>
> <Type>ITEM_ITEM_LITERAL</Type>
> <Category>BLANK_CATEGORY_LITERAL</Category>
> <itemList
> xsi:type="kms_ns:Observation"
> URI="URI-000002"
> Description="Could not add a sibling to root - duh!"
> Title="1st child"
> Originator="Herb"
> OccurrenceDate="0007-12-31T00:00:00.000-0600">
> <Type>OBSERVATION_ITEM_LITERAL</Type>
> <Category>BLANK_CATEGORY_LITERAL</Category>
> <itemList
> xsi:type="kms_ns:Observation"
> URI="URI-000003"
> Description="Able to add child here"
> Title="Child for 2"
> DesignatedAuthority="anyone"
> ResponsibleParty=""
> Originator="Herb"
> OccurrenceDate="0007-10-01T00:00:00.000-0600">
> <Type>OBSERVATION_ITEM_LITERAL</Type>
> <Category>BLANK_CATEGORY_LITERAL</Category>
> </itemList>
> </itemList>
>
> <itemList
> xsi:type="kms_ns:Observation"
> URI="URI-000004"
> Description="Able to add sibling"
> Title="Sibling for 2"
> Originator="Herb"
> OccurrenceDate="0007-08-31T00:00:00.000-0600">
> <Type>OBSERVATION_ITEM_LITERAL</Type>
> <Category>BLANK_CATEGORY_LITERAL</Category>
> </itemList>
>
> <itemList
> xsi:type="kms_ns:Decision"
> URI=""
> />
>
> </kms_ns:Item>
>
>
> === Proposed New=======================
> <?xml version="1.0" encoding="UTF-8"?>
>
> <Item
> xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="com.cohesionforce.kms"
> URI="URI-000001"
> Description="Placeholder for head of list. See:
> http://www.eclipse.org/articles/Article-EMF-goes-RCP/rcp.htm l"
> Title="Root"
> DesignatedAuthority="" ResponsibleParty="">
>
> <Type>ITEM_ITEM_LITERAL</Type>
> <Category>BLANK_CATEGORY_LITERAL</Category>
> <itemList
> type="Observation"
> URI="URI-000002"
> Description="Could not add a sibling to root - duh!"
> Title="1st child"
> Originator="Herb"
> OccurrenceDate="0007-12-31T00:00:00.000-0600">
> <Type>OBSERVATION_ITEM_LITERAL</Type>
> <Category>BLANK_CATEGORY_LITERAL</Category>
> <itemList
> type="Observation"
> URI="URI-000003"
> Description="Able to add child here"
> Title="Child for 2"
> DesignatedAuthority="anyone"
> ResponsibleParty=""
> Originator="Herb"
> OccurrenceDate="0007-10-01T00:00:00.000-0600">
> <Type>OBSERVATION_ITEM_LITERAL</Type>
> <Category>BLANK_CATEGORY_LITERAL</Category>
> </itemList>
> </itemList>
>
> <itemList
> type="Observation"
> URI="URI-000004"
> Description="Able to add sibling"
> Title="Sibling for 2"
> Originator="Herb"
> OccurrenceDate="0007-08-31T00:00:00.000-0600">
> <Type>OBSERVATION_ITEM_LITERAL</Type>
> <Category>BLANK_CATEGORY_LITERAL</Category>
> </itemList>
>
> <itemList
> type="Decision"
> URI=""
> />
>
> </Item>
>
>
>
--------------070004040702040401010907
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Herb,<br>
<br>
Comments below.<br>
<br>
Herb Miller wrote:
<blockquote cite="mid:hnofeg$nqr$1@build.eclipse.org" type="cite">Just
remember this is not my idea, but here goes.
<br>
</blockquote>
A disclaimer. Whose idea might it be?<br>
<blockquote cite="mid:hnofeg$nqr$1@build.eclipse.org" type="cite"><br>
Included is a short sample file and under that is the same file with
changes. The changes are to remove the "kms_ns:" </blockquote>
Given it's an XMI serialization, I'm not sure the sense in removing the
namespace qualification for the root element. Who could possibly stand
to benefit by making the corresponding package/schema unknowable? You
could look at the extended meta data annotations and generated resource
factory impl for a no target namespace schema for how to achieve this.<br>
<blockquote cite="mid:hnofeg$nqr$1@build.eclipse.org" type="cite">and
the "xsi:" when saving the files, and to replace them when loading the
files.
<br>
</blockquote>
And what would you do in place of xsi? The deserializer will need to
know what type of object to create. I.e., an Observation verses a
Decision? You could use substitution groups:<a
href="http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html"><br>
</a>
<blockquote><a
href="http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html">http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html</a><br>
</blockquote>
<blockquote cite="mid:hnofeg$nqr$1@build.eclipse.org" type="cite"><br>
Thanks.
<br>
<br>
=== Existing===========================
<br>
<?xml version="1.0" encoding="UTF-8"?>
<br>
<br>
<kms_ns:Item
<br>
xmi:version="2.0"
<br>
xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
<br>
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
<br>
xmlns:kms_ns="com.cohesionforce.kms"
<br>
URI="URI-000001"
<br>
Description="Placeholder for head of list. See:
<a class="moz-txt-link-freetext" href=" http://www.eclipse.org/articles/Article-EMF-goes-RCP/rcp.htm l"> http://www.eclipse.org/articles/Article-EMF-goes-RCP/rcp.htm l</a>"
<br>
Title="Root"
<br>
DesignatedAuthority="" ResponsibleParty="">
<br>
<br>
<Type>ITEM_ITEM_LITERAL</Type>
<br>
<Category>BLANK_CATEGORY_LITERAL</Cat egory>
<br>
<itemList
<br>
xsi:type="kms_ns:Observation"
<br>
URI="URI-000002"
<br>
Description="Could not add a sibling to root - duh!"
<br>
Title="1st child"
<br>
Originator="Herb"
<br>
OccurrenceDate="0007-12-31T00:00:00.000-0600">
<br>
<Type>OBSERVATION_ITEM_LITERAL</Type&am p;gt;
<br>
<Category>BLANK_CATEGORY_LITERAL</Categ ory>
<br>
<itemList
<br>
xsi:type="kms_ns:Observation"
<br>
URI="URI-000003"
<br>
Description="Able to add child here"
<br>
Title="Child for 2"
<br>
DesignatedAuthority="anyone"
<br>
ResponsibleParty=""
<br>
Originator="Herb"
<br>
OccurrenceDate="0007-10-01T00:00:00.000-0600">
<br>
<Type>OBSERVATION_ITEM_LITERAL</Type&am p;gt;
<br>
<Category>BLANK_CATEGORY_LITERAL</Categ ory>
<br>
</itemList>
<br>
</itemList>
<br>
<br>
<itemList
<br>
xsi:type="kms_ns:Observation"
<br>
URI="URI-000004"
<br>
Description="Able to add sibling"
<br>
Title="Sibling for 2"
<br>
Originator="Herb"
<br>
OccurrenceDate="0007-08-31T00:00:00.000-0600">
<br>
<Type>OBSERVATION_ITEM_LITERAL</Type&am p;gt;
<br>
<Category>BLANK_CATEGORY_LITERAL</Categ ory>
<br>
</itemList>
<br>
<br>
<itemList
<br>
xsi:type="kms_ns:Decision"
<br>
URI=""
<br>
/>
<br>
<br>
</kms_ns:Item>
<br>
<br>
<br>
=== Proposed New=======================
<br>
<?xml version="1.0" encoding="UTF-8"?>
<br>
<br>
<Item
<br>
xmi:version="2.0"
<br>
xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
<br>
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
<br>
xmlns="com.cohesionforce.kms"
<br>
URI="URI-000001"
<br>
Description="Placeholder for head of list. See:
<a class="moz-txt-link-freetext" href=" http://www.eclipse.org/articles/Article-EMF-goes-RCP/rcp.htm l"> http://www.eclipse.org/articles/Article-EMF-goes-RCP/rcp.htm l</a>"
<br>
Title="Root"
<br>
DesignatedAuthority="" ResponsibleParty="">
<br>
<br>
<Type>ITEM_ITEM_LITERAL</Type>
<br>
<Category>BLANK_CATEGORY_LITERAL</Cat egory>
<br>
<itemList
<br>
type="Observation"
<br>
URI="URI-000002"
<br>
Description="Could not add a sibling to root - duh!"
<br>
Title="1st child"
<br>
Originator="Herb"
<br>
OccurrenceDate="0007-12-31T00:00:00.000-0600">
<br>
<Type>OBSERVATION_ITEM_LITERAL</Type&am p;gt;
<br>
<Category>BLANK_CATEGORY_LITERAL</Categ ory>
<br>
<itemList
<br>
type="Observation"
<br>
URI="URI-000003"
<br>
Description="Able to add child here"
<br>
Title="Child for 2"
<br>
DesignatedAuthority="anyone"
<br>
ResponsibleParty=""
<br>
Originator="Herb"
<br>
OccurrenceDate="0007-10-01T00:00:00.000-0600">
<br>
<Type>OBSERVATION_ITEM_LITERAL</Type&am p;gt;
<br>
<Category>BLANK_CATEGORY_LITERAL</Categ ory>
<br>
</itemList>
<br>
</itemList>
<br>
<br>
<itemList
<br>
type="Observation"
<br>
URI="URI-000004"
<br>
Description="Able to add sibling"
<br>
Title="Sibling for 2"
<br>
Originator="Herb"
<br>
OccurrenceDate="0007-08-31T00:00:00.000-0600">
<br>
<Type>OBSERVATION_ITEM_LITERAL</Type&am p;gt;
<br>
<Category>BLANK_CATEGORY_LITERAL</Categ ory>
<br>
</itemList>
<br>
<br>
<itemList
<br>
type="Decision"
<br>
URI=""
<br>
/>
<br>
<br>
</Item>
<br>
<br>
<br>
<br>
</blockquote>
</body>
</html>
--------------070004040702040401010907--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | |
Re: How do I override doSave and doLoad? [message #521528 is a reply to message #521518] |
Wed, 17 March 2010 17:38 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Herb,
Comments below.
Herb Miller wrote:
> I have a couple of questions. The 1st refers to this paragraph you
> wrote:
>
>> I see the same element referring to two different types so the element
>> name does not fully determine the type. EMF wouldn't serialize an
>> xsi:type if it were redundant.
>
> Question 1:
> I am thinking there are 2 possibilities here, and I was wondering
> which one you meant.
> 1) Is this a problem with the model we have now even before I try to
> modify the "look" of the data in the files.
Yes. Right now the xsi:type is absolute necessary.
> 2) Is this a problem we will have with the files if I make the changes
> mentioned in "Merk's Meanderings".
That's the only way to avoid xsi:type. Something needs to be done.
>
> One of the reasons I wanted to override doSave and doLoad was so the
> program would see and deal with the data in the appropriate format,
> but the data in the stored files would look "prettier" (like lipstick
> on a pig). I was going to translate the data on the way into and out
> of the program.
Yes, but surely something finer grained is needed. There is no magic.
>
> Question 2:
> I am terrible at XSD.
But it's so wonderful! :-P
> I am studying up on it right now, so I will catch up pretty soon.
> That is why we use UML drawings (picture worth 1,000 words). I am
> having a problem understanding the schema at the "Merk's Meanderings"
> article you pointed me to.
Oh dear....
>
> In this little snippet of the schema from the article (I think there
> are no typographical errors), does the complex type named "FileSystem"
> define the type in the element named "fileSystem"? What is confusing
> is the element's type is "resource:FileSystem", but the complex type's
> name is just "FileSystem".
Oh dear, even element qualification is throwing you for a loop. What can
I do? I can't teach all the basic XML and XML Schema concepts in the
newsgroup...
>
> <xsd:element
> name="fileSystem"
> type="resource:FileSystem"/>
>
> <xsd:complexType
> name="FileSystem">
> <xsd:sequence>
> <xsd:element
> name="folder"
> ecore:name="folders"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> Thanks.
>
>
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | | | | | | |
Re: How do I override doSave and doLoad? [message #622336 is a reply to message #622335] |
Wed, 17 March 2010 21:52 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Herb,
Comments below.
Herb Miller wrote:
> I have a couple of questions. The 1st refers to this paragraph you
> wrote:
>
>> I see the same element referring to two different types so the element
>> name does not fully determine the type. EMF wouldn't serialize an
>> xsi:type if it were redundant.
>
> Question 1:
> I am thinking there are 2 possibilities here, and I was wondering
> which one you meant.
> 1) Is this a problem with the model we have now even before I try to
> modify the "look" of the data in the files.
Yes. Right now the xsi:type is absolute necessary.
> 2) Is this a problem we will have with the files if I make the changes
> mentioned in "Merk's Meanderings".
That's the only way to avoid xsi:type. Something needs to be done.
>
> One of the reasons I wanted to override doSave and doLoad was so the
> program would see and deal with the data in the appropriate format,
> but the data in the stored files would look "prettier" (like lipstick
> on a pig). I was going to translate the data on the way into and out
> of the program.
Yes, but surely something finer grained is needed. There is no magic.
>
> Question 2:
> I am terrible at XSD.
But it's so wonderful! :-P
> I am studying up on it right now, so I will catch up pretty soon.
> That is why we use UML drawings (picture worth 1,000 words). I am
> having a problem understanding the schema at the "Merk's Meanderings"
> article you pointed me to.
Oh dear....
>
> In this little snippet of the schema from the article (I think there
> are no typographical errors), does the complex type named "FileSystem"
> define the type in the element named "fileSystem"? What is confusing
> is the element's type is "resource:FileSystem", but the complex type's
> name is just "FileSystem".
Oh dear, even element qualification is throwing you for a loop. What can
I do? I can't teach all the basic XML and XML Schema concepts in the
newsgroup...
>
> <xsd:element
> name="fileSystem"
> type="resource:FileSystem"/>
>
> <xsd:complexType
> name="FileSystem">
> <xsd:sequence>
> <xsd:element
> name="folder"
> ecore:name="folders"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> Thanks.
>
>
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | | | | |
Re: How do I override doSave and doLoad? [message #622358 is a reply to message #622357] |
Fri, 19 March 2010 21:54 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Herg,
Comments below.
Herb Miller wrote:
> Ok, I found an article here:
> http://wiki.eclipse.org/EMF/Recipes#Recipe:_Exploiting_Subst itution_Groups_Without_Polluting_Your_Generated_API
>
>
> which sounds a lot like what you are talking about. This article
> gives an example of the problem I am having in many instances. It
> seems like everything I want to override is being used inside of a
> delivered plug-in that is necessary for my project.
>
> For instance, there is a line in the article that says:
> Generate as normal and modify the generated resource factory to use
> the XMLResource.OPTION_ELEMENT_HANDLER option:
> Followed by:
> /**
> * Creates an instance of the resource.
> * * * @generated NOT
> */
> @Override
> public Resource createResource(URI uri)
> {
> //...
> result.getDefaultSaveOptions().put(XMLResource.OPTION_ELEMEN
> T_HANDLER, new ElementHandlerImpl(false));
> result.getDefaultLoadOptions().put(XMLResource.OPTION_SUPPRE
> SS_DOCUMENT_ROOT, Boolean.TRUE);
>
> return result;
> }
> ================================
>
> The only problem is that I have no generated code that looks like this.
The GenPackage has a Resource Type property that you could set that to
XMI. This should cause a plugin.xml registration for that generated
resource factory to be registered, but the plugin.xml will not be
updated once it exists, so you'll need to delete it so it will be
regenerated.
> The only use of createResource in the generated code is a call to
> createResource. But the actual createResource code is in
> EPAckageImpl.class in one of the plug-ins. So how do I add that line
> to a delivered plug-in?
Once you do the above, you'll see an XyzResourceFactoryImpl in which you
can apply your local changes. Be sure to use the debugger to verify
that this code path is being taken.
>
> Thanks.
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Wed Apr 24 20:12:10 GMT 2024
Powered by FUDForum. Page generated in 0.05074 seconds
|