Skip to main content



      Home
Home » Modeling » OCL » OCL to validate XML models?
OCL to validate XML models? [message #1057832] Thu, 09 May 2013 03:31 Go to next message
Eclipse UserFriend
Hi there,

I have model.ecore and model.xml and its codebase generated from model.genmodel. Now I need to find a way to write OCL rules and validate model.xml.

I like to keep OCL constraints separated from model.ecore.

Can someone propose me a good approach or tutorial?

Many thanks.
Yapa

[Updated on: Thu, 09 May 2013 04:38] by Moderator

Re: OCL to validate XML models? [message #1057840 is a reply to message #1057832] Thu, 09 May 2013 04:55 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Have you looked at the Eclipse OCL documentation where you will find two
tutorials?

Regards

Ed Willink

On 09/05/2013 08:31, Kosala Yapa wrote:
> Hi there,
>
> I have model.ecore and model.xml and its codebase generated from
> model.genmodel. Now I need to find a way to write OCL rules and
> validate model.xml.
>
> Can someone propose me a good approach or tutorial?
>
> Many thanks.
> Yapa
>
>
Re: OCL to validate XML models? [message #1057847 is a reply to message #1057840] Thu, 09 May 2013 05:57 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,

I did but could not find it is useful in my case.

I need to keep OCL constraints separated from ecore model, read them and validate against xml model.

Kosala

Re: OCL to validate XML models? [message #1057857 is a reply to message #1057847] Thu, 09 May 2013 07:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi

So read the Complete OCL tutorial

Regards

Ed Willink

On 09/05/2013 10:57, Kosala Yapa wrote:
> Hi Ed,
>
> I did but could not find it is useful in my case.
>
> I need to keep OCL constraints separated from ecore model, read them
> and validate against xml model.
> Kosala
>
>
Re: OCL to validate XML models? [message #1058258 is a reply to message #1057857] Mon, 13 May 2013 07:51 Go to previous messageGo to next message
Eclipse UserFriend
Thanks.

Now I have


// create OCL instance for ecore
OCL ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);

// create OCL helper
OCLHelper<EClassifier, EOperation, EStructuralFeature, Constraint> helper = ocl
.createOCLHelper();

// set OCL context classifier
helper.setContext(ModelPackage.Literals.DEVICE);

//set device EObject
helper.setInstanceContext(device);

//create query expression
OCLExpression<EClassifier> query = helper
.createQuery("self.Modules->forAll(m|m.number<>null)->asSet()->size()");


Now the issue is, How to execute this query?

Any help is appreciated.

Thanks
Yapa

Re: OCL to validate XML models? [message #1058267 is a reply to message #1058258] Mon, 13 May 2013 08:21 Go to previous message
Eclipse UserFriend
Thanks. I could get that working. Complete code is:


// create OCL instance for Ecore
OCL ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);

// create OCL helper
OCLHelper<EClassifier, EOperation, EStructuralFeature, Constraint> helper = ocl
.createOCLHelper();

// set OCL context classifier
helper.setContext(ModelPackage.Literals.DEVICE);
// helper.setInstanceContext(ModelPackage.Literals.DEVICE__MODULES);
helper.setInstanceContext(device);

// create query
OCLExpression<EClassifier> query = helper
.createQuery("self.Modules->select(m|m.number<>null)->size()");

// use the query expression parsed before to create a Query
Query eval = ocl.createQuery(query);
int result = (Integer) eval.evaluate(device);

System.out.println(result);


However this has a small problem, which is creating query takes a considerable time.

Any fix for that?


Any help is appreciated.

Thanks
Kosala
Previous Topic:Problems with nested exists
Next Topic:createQuery() takes a considerable time?
Goto Forum:
  


Current Time: Wed Jul 23 19:44:03 EDT 2025

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

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

Back to the top