|
Re: Evaluate Ecore Instances programatically [message #663335 is a reply to message #663326] |
Mon, 04 April 2011 16:32 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi Khurram
Your example looks very like what the OCLinEcore editor will give you so
I'm presuming that is what you are using.
If you genmodel your model, the OCL text is persisted in the
EAnnotations, so that the OCL can be interpreted appropriately.
(Make sure you set the Operation Reflection parameter to true.)
Then if you're using plugins you need to do no more, the plugin
registrations will happen automatically.
If you are running Standalone you need to 'manually' register the OCL
delegate registrations:
The following is cut and paste from
org.eclipse.ocl.ecore.tests.DelegatesTest.java
String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI;
if (!eclipseIsRunning) { // Install the 'plugin'
registrations
EOperation.Internal.InvocationDelegate.Factory.Registry.INST ANCE.put(oclDelegateURI,
new OCLInvocationDelegateFactory.Global());
EStructuralFeature.Internal.SettingDelegate.Factory.Registry .INSTANCE.put(oclDelegateURI,
new OCLSettingDelegateFactory.Global());
EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDeleg ateURI,
new OCLValidationDelegateFactory.Global());
HTH
Regards
Ed Willink
On 04/04/2011 16:43, khurram wrote:
> Hi,
>
> I am creating ECore model with OCL embedded in it programatically
> using JAVA. I am also creating instances of Ecore model but i want
> instances with evaluated values with respect to OCL derivations
> defined inside Ecore. As there are some attribute having derivation
> statement. I want to access those attributes and want to get the
> derived values from them.
>
> class Library
> {
> property totalBooks : ecore_0::EDouble[1] { derived,volatile }
> {
> derivation: self.books.copies->sum() + testFunction1();
> }
> property books : Book[*] { composes };
> property members : Member[*] { composes };
> property loans : Loan[*] { composes };
> operation testFunction1() : ecore_0::EInt[?]
> {
> body: 2;
> }
> }
> class Book
> {
> attribute name : String[?];
> attribute copies : ecore_0::EIntegerObject[?];
> }
> class Loan
> {
> property member : Member[1];
> property book : Book[1];
> }
>
> This is structure of my generated Ecore. I am taking the instance of
> library and added few books into it and wants that Library.totalBooks
> should have calculated values.
>
> Please guide me!
>
> Warmest Regards,
> Khurram
|
|
|
Powered by
FUDForum. Page generated in 0.02620 seconds