Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » problems using OPTION_RESOURCE_HANDLER(migration and versionning)
problems using OPTION_RESOURCE_HANDLER [message #505290] Tue, 29 December 2009 10:38 Go to next message
peter  is currently offline peter Friend
Messages: 4
Registered: December 2009
Junior Member
Hi,

Following the cookbook recipe on model migration I have successfully added my own ResourceHandler to help catch and migrate model errors.

http://wiki.eclipse.org/EMF/Recipes#Recipe:_Data_Migration

I had some simple tests that worked on one set of models but more recently I tried on another model and I get the following exception(s) continuously:

org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Unresolved reference '//@someObject/@anotherObject'. (, 15, 121) ...

I get this error when, and only when, the following option is set:

options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);

If its false or not set then there are no issues but there is no correct error reporting in my Handler ie the postLoad isn't correctly called. Note that it fails even if the model is correct; you cannot appear to use the above option AND resolve references it seems.

The only differences between my new test case and the previous is that the model I am working on now is a single entity, the previous one was a multiple top level entity containing cross references.

Finally I don't use the ExtendedMetaData option but I have never used this or appeared to need it.

thanks for any help or advice on this topic.

cheers,

peter
Re: problems using OPTION_RESOURCE_HANDLER [message #505297 is a reply to message #505290] Tue, 29 December 2009 11:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30620
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050608010004070504050008
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Peter,

Comments below.


peter wrote:
> Hi,
>
> Following the cookbook recipe on model migration I have successfully
> added my own ResourceHandler to help catch and migrate model errors.
> http://wiki.eclipse.org/EMF/Recipes#Recipe:_Data_Migration
>
> I had some simple tests that worked on one set of models but more
> recently I tried on another model and I get the following exception(s)
> continuously:
>
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Unresolved
> reference '//@someObject/@anotherObject'. (, 15, 121) ...
This is what happens when an IDREF (intradocument reference) can't be
resolved at the end of loading. Proxies are not created for such
cases. Such a document is internally inconsistent.
>
> I get this error when, and only when, the following option is set:
>
> options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
The above error doesn't have anything to do with unrecognized features
though.
>
> If its false or not set then there are no issues but there is no
> correct error reporting in my Handler ie the postLoad isn't correctly
> called. Note that it fails even if the model is correct; you cannot
> appear to use the above option AND resolve references it seems.
I'm not quite sure what you're saying here. Loading is implemented like
this:

public void doLoad(InputStream inputStream, Map<?, ?> options)
throws IOException
{
XMLLoad xmlLoad = createXMLLoad();

if (options == null)
{
options = Collections.EMPTY_MAP;
}

ResourceHandler handler =
(ResourceHandler)options.get(OPTION_RESOURCE_HANDLER);

if (handler != null)
{
handler.preLoad(this, inputStream, options);
}

xmlLoad.load(this, inputStream, options);
xmlLoad = null;

if (handler != null)
{
handler.postLoad(this, inputStream, options);
}
}

Maybe postLoad should be called even when an exception is thrown using a
finally block, but you seem to be saying the opposite of what I expect.
>
> The only differences between my new test case and the previous is that
> the model I am working on now is a single entity, the previous one was
> a multiple top level entity containing cross references.
You're talking multiple root objects?
> Finally I don't use the ExtendedMetaData option but I have never used
> this or appeared to need it.
>
> thanks for any help or advice on this topic.
Set a breakpoint for the exception being thrown and figure out why the
referenced object isn't being found. It looks like
UnresolvedReferenceException.
>
> cheers,
>
> peter

--------------050608010004070504050008
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">
Peter,<br>
<br>
Comments below.<br>
<br>
<br>
peter wrote:
<blockquote cite="mid:hhcm74$rc1$1@build.eclipse.org" type="cite">Hi,
<br>
<br>
Following the cookbook recipe on model migration I have successfully
added my own ResourceHandler to help catch and migrate model errors. <br>
<a class="moz-txt-link-freetext" href="http://wiki.eclipse.org/EMF/Recipes#Recipe:_Data_Migration">http://wiki.eclipse.org/EMF/Recipes#Recipe:_Data_Migration</a>
<br>
<br>
I had some simple tests that worked on one set of models but more
recently I tried on another model and I get the following exception(s)
continuously:
<br>
<br>
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Unresolved
reference '//@someObject/@anotherObject'. (, 15, 121) ...
<br>
</blockquote>
This is what happens when an IDREF (intradocument reference) can't be
resolved at the end of loading.  Proxies are not created for such
cases.  Such a document is internally inconsistent.<br>
<blockquote cite="mid:hhcm74$rc1$1@build.eclipse.org" type="cite"><br>
I get this error when, and only when, the following option is set:
<br>
<br>
options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE,  Boolean.TRUE);
<br>
</blockquote>
The above error doesn't have anything to do with unrecognized features
though.<br>
<blockquote cite="mid:hhcm74$rc1$1@build.eclipse.org" type="cite"><br>
If its false or not set then there are no issues but there is no
correct error reporting in my Handler ie the postLoad isn't correctly
called. Note that it fails even if the model is correct; you cannot
appear to use the above option AND resolve references it seems.
<br>
</blockquote>
I'm not quite sure what you're saying here.  Loading is implemented
like this:<br>
<blockquote><small>  public void doLoad(InputStream inputStream,
Map&lt;?, ?&gt; options) throws IOException</small><br>
<small>  {</small><br>
<small>    XMLLoad xmlLoad = createXMLLoad();</small><br>
<br>
<small>    if (options == null)</small><br>
<small>    {</small><br>
<small>      options = Collections.EMPTY_MAP;</small><br>
<small>    }</small><br>
<br>
<small>    ResourceHandler handler =
(ResourceHandler)options.get(OPTION_RESOURCE_HANDLER);</small ><br>
<br>
<small>    if (handler != null)</small><br>
<small>    {</small><br>
<small>      handler.preLoad(this, inputStream, options);</small><br>
<small>    }</small><br>
<br>
<small>    xmlLoad.load(this, inputStream, options);</small><br>
<small>    xmlLoad = null;</small><br>
<br>
<small>    if (handler != null)</small><br>
<small>    {</small><br>
<small>      handler.postLoad(this, inputStream, options);</small><br>
<small>    }</small><br>
<small>  }</small><br>
</blockquote>
Maybe postLoad should be called even when an exception is thrown using
a finally block, but you seem to be saying the opposite of what I
expect.<br>
<blockquote cite="mid:hhcm74$rc1$1@build.eclipse.org" type="cite"><br>
The only differences between my new test case and the previous is that
the model I am working on now is a single entity, the previous one was
a multiple top level entity containing cross references. <br>
</blockquote>
You're talking multiple root objects?<br>
<blockquote cite="mid:hhcm74$rc1$1@build.eclipse.org" type="cite">Finally
I don't use the ExtendedMetaData option but I have never used this or
appeared to need it.
<br>
<br>
thanks for any help or advice on this topic.
<br>
</blockquote>
Set a breakpoint for the exception being thrown and figure out why the
referenced object isn't being found.  It looks like
UnresolvedReferenceException.<br>
<blockquote cite="mid:hhcm74$rc1$1@build.eclipse.org" type="cite"><br>
cheers,
<br>
<br>
peter
<br>
</blockquote>
</body>
</html>

--------------050608010004070504050008--
Re: problems using OPTION_RESOURCE_HANDLER [message #505299 is a reply to message #505290] Tue, 29 December 2009 12:24 Go to previous messageGo to next message
peter  is currently offline peter Friend
Messages: 4
Registered: December 2009
Junior Member
thanks, I am trying to debug but not its quite hard to find the exact source of error.

Just a clarification, if I load the model without setting the 'report errors' setting then the model will load and the reference is resolved. I have just checked this part. The reference is roughly

//@item/@child

And this reference is resolved in the final loaded model. And there are no other errors.

Its only when I set the option that the reference cannot be resolved, so you are right the postLoad is called but the error reported is completely wrong as it basically gets a key that is the root element and the rest of the model is an AnyType containing all the model. My previous experience is that errors were correctly reported and model elements that could be loaded were.







Re: problems using OPTION_RESOURCE_HANDLER [message #505302 is a reply to message #505299] Tue, 29 December 2009 12:51 Go to previous messageGo to next message
peter  is currently offline peter Friend
Messages: 4
Registered: December 2009
Junior Member
Having debugged the two variants what I see is that in the code in XMLHandler:

protected void handleForwardReferences(boolean isEndDocument)
{

...

for (Iterator<SingleReference> i = forwardSingleReferences.iterator(); i.hasNext(); )
{
SingleReference ref = i.next();
EObject obj = xmlResource.getEObject((String) ref.getValue());

The obj returned here is always correct when the OPTION_RECORD_UNKNOWN_FEATURE is not set but its always null when it is set.



Re: problems using OPTION_RESOURCE_HANDLER [message #505322 is a reply to message #505299] Tue, 29 December 2009 15:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30620
Registered: July 2009
Senior Member
Peter,

Comments below.

peter wrote:
> thanks, I am trying to debug but not its quite hard to find the exact
> source of error.
So you've found where it's throwing the exception and what ID its
failing to resolve?
>
> Just a clarification, if I load the model without setting the 'report
> errors' setting then the model will load and the reference is
> resolved. I have just checked this part. The reference is roughly
>
> //@item/@child
>
> And this reference is resolved in the final loaded model. And there
> are no other errors.
> Its only when I set the option that the reference cannot be resolved,
> so you are right the postLoad is called but the error reported is
> completely wrong as it basically gets a key that is the root element
> and the rest of the model is an AnyType containing all the model. My
> previous experience is that errors were correctly reported and model
> elements that could be loaded were.
It's very hard to follow all the details you describe. You seem to
suggest you have a model that loads fine but if you add the resource
handling it doesn't work fine or maybe that if you tell it to record
unknown features then it starts failing (which is very odd given there
shouldn't be any unknown features when it's loading fine). It's hard to
give advice in the face things that sound contradictory...
>
>
>
>
>
>
>
>
Re: problems using OPTION_RESOURCE_HANDLER [message #505323 is a reply to message #505302] Tue, 29 December 2009 15:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30620
Registered: July 2009
Senior Member
Peter,

So you might want to monitor what happens in XMLHandler for branches
guarded with recordUnknownFeature. Without a reproducible test case, I
can't offer much help.


peter wrote:
> Having debugged the two variants what I see is that in the code in
> XMLHandler:
>
> protected void handleForwardReferences(boolean isEndDocument)
> {
>
> ..
>
> for (Iterator<SingleReference> i =
> forwardSingleReferences.iterator(); i.hasNext(); )
> {
> SingleReference ref = i.next();
> EObject obj = xmlResource.getEObject((String) ref.getValue());
>
> The obj returned here is always correct when the
> OPTION_RECORD_UNKNOWN_FEATURE is not set but its always null when it
> is set.
>
>
>
Re: problems using OPTION_RESOURCE_HANDLER [message #505325 is a reply to message #505323] Tue, 29 December 2009 15:29 Go to previous message
peter  is currently offline peter Friend
Messages: 4
Registered: December 2009
Junior Member
ok, I need to work an a sample for you as I cannot share the model I am using ... I have tried looking at all references to the record option but it doesn't seem to have an obvious impact.

Very confused.

thanks,

peter
Re: problems using OPTION_RESOURCE_HANDLER [message #505327 is a reply to message #505325] Tue, 29 December 2009 10:40 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30620
Registered: July 2009
Senior Member
Peter,

I'd recommend doing more than looking at it statically. The debugger is
your best friend so best you not ignore him. E.g., set a breakpoint in
the logic after each guard and see why you go in that branch when you
use the option. That's more likely to produce results quickly than
asking me.


peter wrote:
> ok, I need to work an a sample for you as I cannot share the model I
> am using ... I have tried looking at all references to the record
> option but it doesn't seem to have an obvious impact.
>
> Very confused.
>
> thanks,
>
> peter
Previous Topic:[CDO] Hudson Update zips do not contain source
Next Topic:Implementing "Equals" and "HashCode" in an EMF Model
Goto Forum:
  


Current Time: Mon Nov 11 19:40:52 GMT 2019

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

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

Back to the top