Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL to validate XML models?
OCL to validate XML models? [message #1057832] Thu, 09 May 2013 07:31 Go to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
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 08:38]

Report message to a moderator

Re: OCL to validate XML models? [message #1057840 is a reply to message #1057832] Thu, 09 May 2013 08:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
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 09:57 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
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 11:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
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 11:51 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
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 12:21 Go to previous message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
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: Fri Dec 19 09:30:15 GMT 2014

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

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