Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to Load a Model that is invalid?(Loading an invalid model so that it can be migrated )
How to Load a Model that is invalid? [message #546713] Tue, 13 July 2010 22:03 Go to next message
prestate  is currently offline prestate Friend
Messages: 1
Registered: July 2010
Junior Member
Hi all, first post !
I have an emf ecore that, every week or so, grows a bit, whether it be that some new features are added, or old ones are removed or renamed.
My whole team is constantly writing models based on this ecore, and everytime I make a modification to the ecore I have to "upgrade" all their existing models so that they are valid.
I have used xslt, find/replace, and in some special ocassions I have created an interim ecore that has enough of the old and all of the new so that i can make the changes using the emf api.
I know there have to be better solutions out there. My favorite approach so far has been to use the emf api to get'r done. Unfortunately creating an ecore that can handle both the new and old models is a bit tricky. I was really hoping that there would be a way to load the model and avoid the "featurenotfoundexception" so that i can walk it with emf the hard way. I see that the generated editor can do this, even for busted models you can still view some of the pieces, I just havent figured out the correct incantation for the resourceSet.getResource(...) to not blow up. any ideas?
Re: How to Load a Model that is invalid? [message #546717 is a reply to message #546713] Tue, 13 July 2010 22:19 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.
--------------080807080907050805040904
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Comments below.

prestate wrote:
> Hi all, first post !
May you always figure it out by yourself. :-P
> I have an emf ecore that, every week or so, grows a bit, whether it be
> that some new features are added, or old ones are removed or renamed.
> My whole team is constantly writing models based on this ecore, and
> everytime I make a modification to the ecore I have to "upgrade" all
> their existing models so that they are valid. I have used xslt,
> find/replace, and in some special ocassions I have created an interim
> ecore that has enough of the old and all of the new so that i can make
> the changes using the emf api.
> I know there have to be better solutions out there. My favorite
> approach so far has been to use the emf api to get'r done.
> Unfortunately creating an ecore that can handle both the new and old
> models is a bit tricky. I was really hoping that there would be a way
> to load the model and avoid the "featurenotfoundexception" so that i
> can walk it with emf the hard way. I see that the generated editor can
> do this, even for busted models you can still view some of the pieces,
> I just havent figured out the correct incantation for the
> resourceSet.getResource(...) to not blow up. any ideas?
Note that even when resourceSet.getResource throws an exception, there
will still be a resource in the resource set containing as much of the
content as the parser was able to deduce. That's why you see code like
this in the generated editor:

Resource resource = null;
try
{
// Load the resource through the editing domain.
//
resource = editingDomain.getResourceSet().getResource(resourceURI,
true);
}
catch (Exception e)
{
exception = e;
resource = editingDomain.getResourceSet().getResource(resourceURI,
false);
}

I.e., we try to get it a second time if the first time fails with an
exception. The resource.getErrors will contain all the
problems/exceptions, including stack traces. You're likely to find
this option very helpful:

/**
* This options allows you to record unknown features during
deserialization/loading.
* The default is <code>Boolean.FALSE</code> unless set to
<code>Boolean.TRUE</code> explicitly.
* The unknown features and their values can be accessed via
getEObjectToExtensionMap().
* @see #getEObjectToExtensionMap()
*/
String OPTION_RECORD_UNKNOWN_FEATURE = "RECORD_UNKNOWN_FEATURE";

This option

/**
* This option allows you to tailor the XML serialization of objects.
* You should provide an ExtendedMetaData as the value of this option.
* @see org.eclipse.emf.ecore.util.BasicExtendedMetaData
*/
String OPTION_EXTENDED_META_DATA = "EXTENDED_META_DATA";

with a specialized implementation of BasicExtendedMetaData can help with
renaming, i.e., making getType/getElement/getAttribute find the feature
with the new name.

--------------080807080907050805040904
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">
Comments below.<br>
<br>
prestate wrote:
<blockquote cite="mid:i1ins1$8uc$1@build.eclipse.org" type="cite">Hi
all, first post !</blockquote>
May you always figure it out by yourself. :-P<br>
<blockquote cite="mid:i1ins1$8uc$1@build.eclipse.org" type="cite"> I
have an emf ecore that, every week or so, grows a bit, whether it be
that some new features are added, or old ones are removed or renamed.
My whole team is constantly writing models based on this ecore, and
everytime I make a modification to the ecore I have to "upgrade" all
their existing models so that they are valid. I have used xslt,
find/replace, and in some special ocassions I have created an interim
ecore that has enough of the old and all of the new so that i can make
the changes using the emf api.
<br>
I know there have to be better solutions out there. My favorite
approach so far has been to use the emf api to get'r done.
Unfortunately creating an ecore that can handle both the new and old
models is a bit tricky. I was really hoping that there would be a way
to load the model and avoid the "featurenotfoundexception" so that i
can walk it with emf the hard way. I see that the generated editor can
do this, even for busted models you can still view some of the pieces,
I just havent figured out the correct incantation for the
resourceSet.getResource(...) to not blow up. any ideas?
<br>
</blockquote>
Note that even when resourceSet.getResource throws an exception, there
will still be a resource in the resource set containing as much of the
content as the parser was able to deduce.   That's why you see code
like this in the generated editor:<br>
<br>
    Resource resource = null;<br>
    try<br>
    {<br>
      // Load the resource through the editing domain.<br>
      //<br>
      resource =
editingDomain.getResourceSet().getResource(resourceURI, true);<br>
    }<br>
    catch (Exception e)<br>
    {<br>
      exception = e;<br>
      resource =
editingDomain.getResourceSet().getResource(resourceURI, false);<br>
    }<br>
<br>
I.e., we try to get it a second time if the first time fails with an
exception. The resource.getErrors will contain all the
problems/exceptions, including stack traces.   You're likely to find
this option very helpful:<br>
<blockquote>  /**<br>
   * This options allows you to record unknown features during
deserialization/loading.<br>
   * The default is &lt;code&gt;Boolean.FALSE&lt;/code&gt; unless set
to &lt;code&gt;Boolean.TRUE&lt;/code&gt; explicitly. <br>
   * The unknown features and their values can be accessed via
getEObjectToExtensionMap().<br>
   * @see #getEObjectToExtensionMap()  <br>
   */<br>
  String OPTION_RECORD_UNKNOWN_FEATURE = "RECORD_UNKNOWN_FEATURE";<br>
</blockquote>
This option<br>
<blockquote><small>  /**</small><br>
<small>   * This option allows you to tailor the XML serialization of
objects. </small><br>
<small>   * You should provide an ExtendedMetaData as the value of
this option.</small><br>
<small>   * @see org.eclipse.emf.ecore.util.BasicExtendedMetaData</small><br >
<small>   */</small><br>
<small>  String OPTION_EXTENDED_META_DATA = "EXTENDED_META_DATA";</small><br>
</blockquote>
with a specialized implementation of BasicExtendedMetaData can help
with renaming, i.e., making getType/getElement/getAttribute find the
feature with the new name.<br>
</body>
</html>

--------------080807080907050805040904--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Multiple implementations for a single meta-model/interface
Next Topic:ecore plugins missing
Goto Forum:
  


Current Time: Thu Apr 25 21:45:04 GMT 2024

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

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

Back to the top