Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » DanglingHREFException when saving Ecore model
DanglingHREFException when saving Ecore model [message #424888] Sun, 09 November 2008 03:42 Go to next message
Derek Palma is currently offline Derek PalmaFriend
Messages: 141
Registered: July 2009
Senior Member
Hi,

I have written code to load an .xsd via XSDResourceFactoryImpl and then
convert it to an Ecore model with XSDEcoreBuilder. My last step is to save
the Ecore model so I don't have to rebuild it each time I want to use it. I
receive a DanglingHREFException with the code below. I can imagine what this
exception means, however, I am not sure how to proceed since I really can't
edit the original .xsd if that is actually required in some cases. I hope
that I am just using the APIs incorrectly.

EcoreResourceFactoryImpl ecoreResourceFactory = new
EcoreResourceFactoryImpl();

Resource ecoreResource = ecoreResourceFactory.createResource(modelUri);

ecoreResource.getContents().add(ePackage);

ecoreResource.save(null);
Re: DanglingHREFException when saving Ecore model [message #424889 is a reply to message #424888] Sun, 09 November 2008 04:28 Go to previous messageGo to next message
Derek Palma is currently offline Derek PalmaFriend
Messages: 141
Registered: July 2009
Senior Member
I noticed that this XSD references another, so actually two EPackages are
created. When I added the second EPackage to the ecoreResource, the
exception no longer occurs, which makes complete sense.

However, now I noticed an interesting thing. When I display the model in the
model viewer I get two copies of the second namespace (EPackage). This is
the one referenced from the out XSD. I must not be serializing the Ecore
model correctly. (???)


"Derek Palma" <derek.palma@gmail.com> wrote in message
news:gf5maq$1dp$1@build.eclipse.org...
> Hi,
>
> I have written code to load an .xsd via XSDResourceFactoryImpl and then
> convert it to an Ecore model with XSDEcoreBuilder. My last step is to save
> the Ecore model so I don't have to rebuild it each time I want to use it.
> I receive a DanglingHREFException with the code below. I can imagine what
> this exception means, however, I am not sure how to proceed since I really
> can't edit the original .xsd if that is actually required in some cases. I
> hope that I am just using the APIs incorrectly.
>
> EcoreResourceFactoryImpl ecoreResourceFactory = new
> EcoreResourceFactoryImpl();
>
> Resource ecoreResource = ecoreResourceFactory.createResource(modelUri);
>
> ecoreResource.getContents().add(ePackage);
>
> ecoreResource.save(null);
>
Re: DanglingHREFException when saving Ecore model [message #424892 is a reply to message #424889] Sun, 09 November 2008 13:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Derik,

Comments below.

Derek Palma wrote:
> I noticed that this XSD references another, so actually two EPackages
> are created.
One per namespace, yes.
> When I added the second EPackage to the ecoreResource, the exception
> no longer occurs, which makes complete sense.
Typically you'd put each in a separate resource.
>
> However, now I noticed an interesting thing. When I display the model
> in the model viewer I get two copies of the second namespace
> (EPackage). This is the one referenced from the out XSD. I must not be
> serializing the Ecore model correctly. (???)
It's hard to say without more details. Where are they appearing twice?
>
>
> "Derek Palma" <derek.palma@gmail.com> wrote in message
> news:gf5maq$1dp$1@build.eclipse.org...
>> Hi,
>>
>> I have written code to load an .xsd via XSDResourceFactoryImpl and
>> then convert it to an Ecore model with XSDEcoreBuilder. My last step
>> is to save the Ecore model so I don't have to rebuild it each time I
>> want to use it. I receive a DanglingHREFException with the code
>> below. I can imagine what this exception means, however, I am not
>> sure how to proceed since I really can't edit the original .xsd if
>> that is actually required in some cases. I hope that I am just using
>> the APIs incorrectly.
>>
>> EcoreResourceFactoryImpl ecoreResourceFactory = new
>> EcoreResourceFactoryImpl();
>>
>> Resource ecoreResource = ecoreResourceFactory.createResource(modelUri);
>>
>> ecoreResource.getContents().add(ePackage);
>>
>> ecoreResource.save(null);
Note that it's important you put all the packages in a resource before
you serialize any of them...
>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DanglingHREFException when saving Ecore model [message #424893 is a reply to message #424892] Sun, 09 November 2008 14:56 Go to previous message
Derek Palma is currently offline Derek PalmaFriend
Messages: 141
Registered: July 2009
Senior Member
I think I committed a newbie mistake by not putting all ecore models into
the same ResourceSet before persisting any of them. Everything seems fine
now. Thanks for your help Ed!

Derek

"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:gf6o6e$egu$1@build.eclipse.org...
> Derik,
>
> Comments below.
>
> Derek Palma wrote:
>> I noticed that this XSD references another, so actually two EPackages are
>> created.
> One per namespace, yes.
>> When I added the second EPackage to the ecoreResource, the exception no
>> longer occurs, which makes complete sense.
> Typically you'd put each in a separate resource.
>>
>> However, now I noticed an interesting thing. When I display the model in
>> the model viewer I get two copies of the second namespace (EPackage).
>> This is the one referenced from the out XSD. I must not be serializing
>> the Ecore model correctly. (???)
> It's hard to say without more details. Where are they appearing twice?
>>
>>
>> "Derek Palma" <derek.palma@gmail.com> wrote in message
>> news:gf5maq$1dp$1@build.eclipse.org...
>>> Hi,
>>>
>>> I have written code to load an .xsd via XSDResourceFactoryImpl and then
>>> convert it to an Ecore model with XSDEcoreBuilder. My last step is to
>>> save the Ecore model so I don't have to rebuild it each time I want to
>>> use it. I receive a DanglingHREFException with the code below. I can
>>> imagine what this exception means, however, I am not sure how to proceed
>>> since I really can't edit the original .xsd if that is actually required
>>> in some cases. I hope that I am just using the APIs incorrectly.
>>>
>>> EcoreResourceFactoryImpl ecoreResourceFactory = new
>>> EcoreResourceFactoryImpl();
>>>
>>> Resource ecoreResource = ecoreResourceFactory.createResource(modelUri);
>>>
>>> ecoreResource.getContents().add(ePackage);
>>>
>>> ecoreResource.save(null);
> Note that it's important you put all the packages in a resource before you
> serialize any of them...
>>>
>>
Previous Topic:Open an EMF Generator Editor through double-click on custom marker
Next Topic:[CDO] Editor
Goto Forum:
  


Current Time: Fri Apr 26 04:40:51 GMT 2024

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

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

Back to the top