Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Containment problem.
Containment problem. [message #511651] Tue, 02 February 2010 12:08 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
I am trying to get one single instance of a class to be contained into
another, but I must be doing something wrong because I get an exception
when saving the model.

I am building from annotated java.

/**
* @model
*/
public interface TimeEvent extends EObject {
/**
* @model
*/
public String getCaption();
/**
* @model
*/
public Date getDate();
/**
* @model
*/
public Date getEndDate();
}

/**
* @model
*/
public interface IBase extends EObject {
....
/**
* @model contained="true"
*/
public TimeEvent getTime();
....
}

/**
* @model
*/
public interface Scene extends IBase {
....
}

I am using the following code to create and set TimeEvent into Scene:

Scene _s = WorldFactory.eINSTANCE.createScene();
TimeEvent _t = WorldFactory.eINSTANCE.createTimeEvent();
_t.setDate(startDate);
_t.setEndDate(endDate);
_s.setTime(_t);

When I save the model I get the error:
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: The object
'it.condarelli.rcp.writer.model.world.impl.TimeEventImpl@1b88122
(caption: null, date: Sat May 03 11:42:00 CEST 2730, endDate: Sat May 03
11:47:00 CEST 2730)' is not contained in a resource.
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.endSave(XMLSaveIm pl.java:306)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:270)
at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:206)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
at it.condarelli.rcp.writer.Transfer.main(Transfer.java:273)
Caused by: org.eclipse.emf.ecore.xmi.DanglingHREFException: The object
'it.condarelli.rcp.writer.model.world.impl.TimeEventImpl@1b88122
(caption: null, date: Sat May 03 11:42:00 CEST 2730, endDate: Sat May 03
11:47:00 CEST 2730)' is not contained in a resource.
at
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.handleDanglingH REF(XMLHelperImpl.java:760)
at
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getURIFragment( XMLHelperImpl.java:731)

The 'contained="true"' clause was a (misguided) attempt to cure the error.

What am I doing wrong? How do I tell EMF I just want a single instance
of TimeEvent there? (in other places I have TimeEvent List and it seems
to work fine).

TiA
Mauro
Re: Containment problem. [message #511663 is a reply to message #511651] Tue, 02 February 2010 13:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> I am trying to get one single instance of a class to be contained into
> another, but I must be doing something wrong because I get an
> exception when saving the model.
>
> I am building from annotated java.
>
> /**
> * @model
> */
> public interface TimeEvent extends EObject {
> /**
> * @model
> */
> public String getCaption();
> /**
> * @model
> */
> public Date getDate();
> /**
> * @model
> */
> public Date getEndDate();
> }
>
> /**
> * @model
> */
> public interface IBase extends EObject {
> ...
> /**
> * @model contained="true"
You mean containment="true" right? Unfortunately the @model process
does almost no validation checking so if you feed it garbage, it quietly
ignores that.
> */
> public TimeEvent getTime();
> ...
> }
>
> /**
> * @model
> */
> public interface Scene extends IBase {
> ...
> }
>
> I am using the following code to create and set TimeEvent into Scene:
>
> Scene _s = WorldFactory.eINSTANCE.createScene();
> TimeEvent _t = WorldFactory.eINSTANCE.createTimeEvent();
> _t.setDate(startDate);
> _t.setEndDate(endDate);
> _s.setTime(_t);
>
> When I save the model I get the error:
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: The object
> 'it.condarelli.rcp.writer.model.world.impl.TimeEventImpl@1b88122
> (caption: null, date: Sat May 03 11:42:00 CEST 2730, endDate: Sat May
> 03 11:47:00 CEST 2730)' is not contained in a resource.
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.endSave(XMLSaveIm pl.java:306)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:270)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:206)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
>
> at it.condarelli.rcp.writer.Transfer.main(Transfer.java:273)
> Caused by: org.eclipse.emf.ecore.xmi.DanglingHREFException: The object
> 'it.condarelli.rcp.writer.model.world.impl.TimeEventImpl@1b88122
> (caption: null, date: Sat May 03 11:42:00 CEST 2730, endDate: Sat May
> 03 11:47:00 CEST 2730)' is not contained in a resource.
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.handleDanglingH REF(XMLHelperImpl.java:760)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getURIFragment( XMLHelperImpl.java:731)
>
>
> The 'contained="true"' clause was a (misguided) attempt to cure the
> error.
The EMF Refcard is a good quick reference for the right annontations to use.
>
> What am I doing wrong? How do I tell EMF I just want a single instance
> of TimeEvent there? (in other places I have TimeEvent List and it
> seems to work fine).
>
> TiA
> Mauro


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Containment problem. [message #511781 is a reply to message #511663] Tue, 02 February 2010 19:26 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Ed Merks wrote:
> Mauro,
>
> Comments below.
ditto.

> Mauro Condarelli wrote:
>> I am trying to get one single instance of a class to be contained into
....
>> /**
>> * @model contained="true"
> You mean containment="true" right? Unfortunately the @model process
> does almost no validation checking so if you feed it garbage, it quietly
> ignores that.

AAAARGHHHH!!
I feel *SO* idiot :(

Thanks.

Now it works.
Two small quirks:

1) I had to clean the project before it actually decided to acknowledge
the changes in the generated files.

2) My app requires another project in the same workspace. Each time I
"Generate Model code" the Build Path (Properties->Java Build
Path->Projects) is reset to null and I have to add it again. Is this a
bug or (another) misunderstanding from my side?

Thanks a LOT!
Mauro
Re: Containment problem. [message #511937 is a reply to message #511781] Wed, 03 February 2010 13:24 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Ed Merks wrote:
>> Mauro,
>>
>> Comments below.
> ditto.
>
>> Mauro Condarelli wrote:
>>> I am trying to get one single instance of a class to be contained into
> ...
>>> /**
>>> * @model contained="true"
>> You mean containment="true" right? Unfortunately the @model process
>> does almost no validation checking so if you feed it garbage, it
>> quietly ignores that.
>
> AAAARGHHHH!!
> I feel *SO* idiot :(
Not really. It would be awfully nice if the converter complained about
bogus annotations but given how the logic is implemented (by pattern
matching each supported case against the full string), it's a fair bit
of work to add the extra checking (how to know which parts never matched
any pattern).
>
> Thanks.
>
> Now it works.
> Two small quirks:
>
> 1) I had to clean the project before it actually decided to
> acknowledge the changes in the generated files.
I've not seen that before. Perhaps the workspace was out of sync with
the actual file system?
>
> 2) My app requires another project in the same workspace. Each time I
> "Generate Model code" the Build Path (Properties->Java Build
> Path->Projects) is reset to null and I have to add it again. Is this a
> bug or (another) misunderstanding from my side?
Generally you should be modifying the classpath for plugin projects
(which is what EMF always generates) only by modifying the dependencies
in the MANIFEST.MF.
>
> Thanks a LOT!
> Mauro


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Databiding] need basic tutorial with running example
Next Topic:IRC for EMF
Goto Forum:
  


Current Time: Tue Apr 23 17:26:05 GMT 2024

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

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

Back to the top