Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » restriction of child elements
restriction of child elements [message #1067743] Wed, 10 July 2013 12:08 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi,

I'm not sure what's the best way to solve this, so I ask here. Think of this metamodel:

abstract class Hw{
	attr Type type;
}

class ConcreteHw extends Hw{
	attr EString identifier = "";

	val ConcreteHw[*] concreteHws;
}

enum Type{
	Core;
	Memory;
	Quartz;
	Bridge;
	Bus;
}


Starting from this metamodel, it's possible to define constructs like this:

Core
- Quartz
- Bridge
- Bus
- Bridge

Since this can lead to wrong models, I would like to restrict the model so that e.g. a Bridge can't be the child of a Bus. Is there any smooth way in EMF to handle this restrictions?

Cheers,
Phil
Re: restriction of child elements [message #1067747 is a reply to message #1067743] Wed, 10 July 2013 12:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Phil,

You'd could do that by defining a constraint on ConcreteHw
http://help.eclipse.org/juno/index.jsp?topic=/org.eclipse.emf.doc/references/overview/EMF.Validation.html
and writing logic that checks that the members of concreteHws conform to
that constraint.

On 10/07/2013 2:08 PM, Phil H wrote:
> Hi,
>
> I'm not sure what's the best way to solve this, so I ask here. Think
> of this metamodel:
>
> abstract class Hw{
> attr Type type;
> }
>
> class ConcreteHw extends Hw{
> attr EString identifier = "";
>
> val ConcreteHw[*] concreteHws;
> }
>
> enum Type{
> Core;
> Memory;
> Quartz;
> Bridge;
> Bus;
> }
>
> Starting from this metamodel, it's possible to define constructs like
> this:
>
> Core
> - Quartz
> - Bridge
> - Bus
> - Bridge
>
> Since this can lead to wrong models, I would like to restrict the
> model so that e.g. a Bridge can't be the child of a Bus. Is there any
> smooth way in EMF to handle this restrictions?
>
> Cheers,
> Phil


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: restriction of child elements [message #1068044 is a reply to message #1067747] Thu, 11 July 2013 19:21 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Thx Ed,

this seems to be a possible solution for my usecase.

But I would prefer a solution where the user has no chance to model something wrong.

For example when adding a child to Core, only Memory and Quartz will be offered. Is it possible to modify the generated emf code in order to reach this?

Cheers,
Phil
Re: restriction of child elements [message #1068087 is a reply to message #1068044] Fri, 12 July 2013 04:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Phil,

Given that you made such things modeled via a type attribute on Hw,
you've not modeled it a way where you have Core, Memory, and Quartz
classes so just changing that attribute value can lead to an invalid
model. If you modeled actual classes for these things, you'd have the
support of the type system to enforce validity.


On 11/07/2013 9:21 PM, Phil H wrote:
> Thx Ed,
>
> this seems to be a possible solution for my usecase.
>
> But I would prefer a solution where the user has no chance to model
> something wrong.
>
> For example when adding a child to Core, only Memory and Quartz will
> be offered. Is it possible to modify the generated emf code in order
> to reach this?
>
> Cheers,
> Phil


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Notifying of changes to attributes of child objects in a list.
Next Topic:References in EMF
Goto Forum:
  


Current Time: Thu Apr 25 22:25:26 GMT 2024

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

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

Back to the top