Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Attribute constraints on a dynamic model
Attribute constraints on a dynamic model [message #1389251] Fri, 27 June 2014 14:43 Go to next message
Michal Sudra is currently offline Michal SudraFriend
Messages: 5
Registered: March 2014
Junior Member
Hi,

I'm building a dynamic ecore model and creating instances of that model. And my question is how can I add constraints to my dynamic model attributes that can be checked by the validation framework.

Let say I have a following code example:

EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
EClass productClass = ecoreFactory.createEClass();
productClass.setName( "Product" );
        
EAttribute name = ecoreFactory.createEAttribute();
productClass.getEStructuralFeatures().add( name );
name.setName( "name" );
name.setEType( EcorePackage.eINSTANCE.getEString() );
        
EAttribute price = ecoreFactory.createEAttribute();
productClass.getEStructuralFeatures().add( price );
price.setName( "price" );
price.setEType( EcorePackage.eINSTANCE.getEDouble() );

And my goal is to add a min and max values constraints to the 'price' attribute.
Any working example will be appreciated.

Thanks,
Michal
Re: Attribute constraints on a dynamic model [message #1389280 is a reply to message #1389251] Fri, 27 June 2014 15:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30372
Registered: July 2009
Senior Member
Michal,

If you add extended metadata annotations just like the ones produce when
creating a model from XML Schema, those constraints will be check even
for dynamic models. It's possible with OCL as well...


On 27/06/2014 4:43 PM, Michal Sudra wrote:
> Hi,
>
> I'm building a dynamic ecore model and creating instances of that
> model. And my question is how can I add constraints to my dynamic
> model attributes that can be checked by the validation framework.
>
> Let say I have a following code example:
>
>
> EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
> EClass productClass = ecoreFactory.createEClass();
> productClass.setName( "Product" );
> EAttribute name = ecoreFactory.createEAttribute();
> productClass.getEStructuralFeatures().add( name );
> name.setName( "name" );
> name.setEType( EcorePackage.eINSTANCE.getEString() );
> EAttribute price = ecoreFactory.createEAttribute();
> productClass.getEStructuralFeatures().add( price );
> price.setName( "price" );
> price.setEType( EcorePackage.eINSTANCE.getEDouble() );
>
> And my goal is to add a min and max values constraints to the 'price'
> attribute.
> Any working example will be appreciated.
>
> Thanks,
> Michal
Re: Attribute constraints on a dynamic model [message #1389725 is a reply to message #1389280] Sat, 28 June 2014 07:53 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
Hi

The OCLinEcore tutorial is a working example in Help->Help Contents->OCL
Documentation.

Regards

Ed Willink

On 27/06/2014 16:23, Ed Merks wrote:
> Michal,
>
> If you add extended metadata annotations just like the ones produce
> when creating a model from XML Schema, those constraints will be check
> even for dynamic models. It's possible with OCL as well...
>
>
> On 27/06/2014 4:43 PM, Michal Sudra wrote:
>> Hi,
>>
>> I'm building a dynamic ecore model and creating instances of that
>> model. And my question is how can I add constraints to my dynamic
>> model attributes that can be checked by the validation framework.
>>
>> Let say I have a following code example:
>>
>>
>> EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
>> EClass productClass = ecoreFactory.createEClass();
>> productClass.setName( "Product" );
>> EAttribute name = ecoreFactory.createEAttribute();
>> productClass.getEStructuralFeatures().add( name );
>> name.setName( "name" );
>> name.setEType( EcorePackage.eINSTANCE.getEString() );
>> EAttribute price = ecoreFactory.createEAttribute();
>> productClass.getEStructuralFeatures().add( price );
>> price.setName( "price" );
>> price.setEType( EcorePackage.eINSTANCE.getEDouble() );
>>
>> And my goal is to add a min and max values constraints to the 'price'
>> attribute.
>> Any working example will be appreciated.
>>
>> Thanks,
>> Michal
>
Previous Topic:[XCore] org.eclipse.emf.ecore.xcore.lib cannot be resolved
Next Topic:[CDO] CDOServerExporter Out of memory exception
Goto Forum:
  


Current Time: Sun Aug 25 06:51:59 GMT 2019

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

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

Back to the top