Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Root class for models?
Root class for models? [message #509380] Fri, 22 January 2010 10:06 Go to next message
Dennis Hendriks is currently offline Dennis HendriksFriend
Messages: 66
Registered: January 2010
Location: Eindhoven, The Netherland...
Member
Hello,

in an Ecore I have multiple classes defined. I would like all instances of my ecore (all models) to have one specific class as the root of the model instance (tree). Is there a way to specify which classes may occur as the top level model element?

When creating a new model instance, you get a wizard and you need to "Select a model object to create". However, this is always the same thing for my ecore. There is no choice, only one class is allowed. I would like that question to be omitted.

http://www.eclipse.org/forums/index.php?t=tree&th=132052 has some information on how to set the default. It does not state whether that is just the default selection or that it enforces a single class to be the root. Also, it requires code modification.

Furthermore, when generating an XSD using the genmodel, I get an <xsd:element .../> as well as an <xsd:complexType .../> for each class, meaning they can indeed all occur at the top level. I would like the number of <xsd:element .../>s generated to be limited to the classes that can actually occur as top level elements. Changing code doesn't influence XSD generation, does it? So it needs to be specified in the ecore or genmodel?

Is there a way to specify the top level or root class in the ecore itself (or in the genmodel)?

Dennis
Re: Root class for models? [message #509402 is a reply to message #509380] Fri, 22 January 2010 06:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30653
Registered: July 2009
Senior Member
Dennis,

Comments below.

D. Hendriks (Dennis) wrote:
> Hello,
>
> in an Ecore I have multiple classes defined. I would like all
> instances of my ecore (all models) to have one specific class as the
> root of the model instance (tree). Is there a way to specify which
> classes may occur as the top level model element?

The Root Extends Interface property of the GenModel should do the trick.
>
> When creating a new model instance, you get a wizard and you need to
> "Select a model object to create". However, this is always the same
> thing for my ecore. There is no choice, only one class is allowed. I
> would like that question to be omitted.
You'll need to specialize the generated wizard.
>
> http://www.eclipse.org/forums/index.php?t=tree&th=132052 has some
> information on how to set the default. It does not state whether that
> is just the default selection or that it enforces a single class to be
> the root. Also, it requires code modification.
Yes.
>
> Furthermore, when generating an XSD using the genmodel, I get an
> <xsd:element .../> as well as an <xsd:complexType .../> for each
> class, meaning they can indeed all occur at the top level. I would
> like the number of <xsd:element .../>s generated to be limited to the
> classes that can actually occur as top level elements. Changing code
> doesn't influence XSD generation, does it? So it needs to be specified
> in the ecore or genmodel?
>
> Is there a way to specify the top level or root class in the ecore
> itself (or in the genmodel)?
No.

Your model would need a DocumentRoot with only a single element-based
feature to limit what's allowed at the root. You might achieve this by
modifying the generated schema and then reloading your model from that
schema.
>
> Dennis
Re: Root class for models? [message #509462 is a reply to message #509402] Fri, 22 January 2010 14:16 Go to previous message
Dennis Hendriks is currently offline Dennis HendriksFriend
Messages: 66
Registered: January 2010
Location: Eindhoven, The Netherland...
Member
1)

Ed Merks wrote on Fri, 22 January 2010 07:40
> Is there a way to specify the top level or root class in the ecore
> itself (or in the genmodel)?
No.


Is this something that you would like to have? And if so, are there any plans for this?


2)

Ed Merks wrote on Fri, 22 January 2010 07:40
Your model would need a DocumentRoot with only a single element-based
feature to limit what's allowed at the root. You might achieve this by
modifying the generated schema and then reloading your model from that
schema.
>
> Dennis


I generated XSDs, and all Ecore classes are top level elements. From the XSDs I recreated my ecores. It did not have any effect, related to top-level elements in the ecore/genmodel. I created new XSDs from the new Ecores. Now none of the Ecore classes are top level elements...
Re: Root class for models? [message #509474 is a reply to message #509462] Fri, 22 January 2010 09:42 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30653
Registered: July 2009
Senior Member
Dennis,

Comments below.

D. Hendriks (Dennis) wrote:
> 1)
>
> Ed Merks wrote on Fri, 22 January 2010 07:40
>> > Is there a way to specify the top level or root class in the ecore
>> > itself (or in the genmodel)?
>> No.
>
>
> Is this something that you would like to have? And if so, are there
> any plans for this?
The list of "like to haves" already far exceeds any expectation of ever
addressing them so collecting more of them isn't all that productive.
>
>
> 2)
>
> Ed Merks wrote on Fri, 22 January 2010 07:40
>> Your model would need a DocumentRoot with only a single element-based
>> feature to limit what's allowed at the root. You might achieve this
>> by modifying the generated schema and then reloading your model from
>> that schema.
>> >
>> > Dennis
>
>
> I generated XSDs, and all Ecore classes are top level elements. From
> the XSDs I recreated my ecores. It did not have any effect, related to
> top-level elements in the ecore/genmodel. I created new XSDs from the
> new Ecores. Now none of the Ecore classes are top level elements...
I'm not sure what you're saying. If you write a schema with a single
global element, you'll only be able to create instances of types that
conform to that element's type.
Previous Topic:Re: [Teneo] Generate CDO - Hibernate OR Mapping
Next Topic:emf validation question
Goto Forum:
  


Current Time: Thu Nov 21 03:12:41 GMT 2019

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

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

Back to the top