Attribute constraints on a dynamic model [message #1389251] |
Fri, 27 June 2014 10:43  |
Eclipse User |
|
|
|
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 03:53  |
Eclipse User |
|
|
|
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
>
|
|
|
Powered by
FUDForum. Page generated in 0.07115 seconds