Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » EMF & OCL beginner question
EMF & OCL beginner question [message #523147] Thu, 25 March 2010 10:33 Go to next message
Thomas is currently offline ThomasFriend
Messages: 11
Registered: March 2010
Junior Member
Hello,
i'm new to OCL. I have an simple question
for example: I have an EMF Model with
Shop
Owner

1. A shop has an owner.
so how can i select the owner via OCL?

2. Shop has an attribute numberOfWorkers
how can i asking how many workers there are?

Or is OCL to wrong method

Thanks for your help
Re: EMF & OCL beginner question [message #523191 is a reply to message #523147] Thu, 25 March 2010 13:19 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 846
Registered: July 2009
Senior Member
Hi,

1. If the Shop class has a reference to the Owner named "owner" you
could do:

aShop.owner

where "aShop" is some variable of type Shop.

2. In this case, you already provided the answer:

aShop.numberOfWorkers

I'd suggest reading some introductory material to familiarize yourself
with the language. The Warmer & Kleppe book is excellent (I think it's
"The Object Constraint Language") and there is courseware available in
the Eclipse GMT project's Open Model Courseware sub-project:

http://www.eclipse.org/gmt/omcw/

HTH,

Christian


On 25/03/10 06:33 AM, undeath@gmx.de wrote:
> Hello,
> i'm new to OCL. I have an simple question
> for example: I have an EMF Model with
> Shop
> Owner
>
> 1. A shop has an owner.
> so how can i select the owner via OCL?
>
> 2. Shop has an attribute numberOfWorkers
> how can i asking how many workers there are?
>
> Or is OCL to wrong method
>
> Thanks for your help
Re: EMF & OCL beginner question [message #523408 is a reply to message #523147] Fri, 26 March 2010 10:48 Go to previous messageGo to next message
Thomas is currently offline ThomasFriend
Messages: 11
Registered: March 2010
Junior Member
Hi,
thanks for ur answer, ur suggestions are kinda like mine but i dont get it, it doesn't work.
I expected that OCl is kinda like SQL.
Why should I need a "where" clause if I only want a select an object.
I googled about OCl and EMF but I didn't see any simple tutorial how to get such simple thinks.
Anyways i tried ur suggestions and the owner, but there were no results
My ocl expression strings are:
for the numberOfWorkers: self.numberOfWorkers
for the owner: self.owner

code snippet for self.owner

EObject shop = getShop();
final OCL ocl = org.eclipse.ocl.ecore.OCL.newInstance();
BooleanOCLCondition<EClassifier, EClass, EObject> condition = null;
try {
     condition = new BooleanOCLCondition<EClassifier, EClass, EObject>(ocl.getEnvironment(), "self.owner", null );
} catch( final ParserException ex ) {
     log.error( "UNEXPECTED", ex );
}
final SELECT statement = new SELECT( SELECT.UNBOUNDED, false,  new FROM( shop), new WHERE( condition ),  new NullProgressMonitor() );

final IQueryResult results = statement.execute();
for( final EObject o : results.getEObjects() ) {
 log.debug( o.getClass().getName() );                            
}

Why i dont get the reference (owner)?


Or should I ask in the EMF forum

[Updated on: Fri, 26 March 2010 12:20]

Report message to a moderator

Re: EMF & OCL beginner question [message #523669 is a reply to message #523408] Sun, 28 March 2010 13:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4185
Registered: July 2009
Senior Member
Hi Thomas

The facilities you use are provided by the EMFT/Query framework which
adds value to the MDT/OCL project. You may get a better response from
the emft newsgroup. I have only used EMFq to check for compilation
dependencies.

I Googled too and found
http://help.eclipse.org/help32/topic/org.eclipse.emf.query.d oc/tutorials/oclQueryTutorial.html

Regards

Ed Willink

On 26/03/2010 10:48, Thomas wrote:
> Hi,
> thanks for ur answer, ur suggestions are kinda like mine but i dont get
> it, it doesn't work.
> I expected that OCl is kinda like SQL.
> Why should I need a "where" clause if I only want a select an object. I
> googled about OCl and EMF but I didn't see any simple tutorial how to
> get such simple thinks.
> Anyways i tried ur suggestions and the owner, but there were no results
> My ocl expression strings are:
> for the numberOfWorkers: self.numberOfWorkers
> for the owner: self.owner
>
> code snippet for numberOfWorkers
>
>
> EObject shop = getShop();
> final OCL ocl = org.eclipse.ocl.ecore.OCL.newInstance();
> BooleanOCLCondition<EClassifier, EClass, EObject> condition = null;
> try {
> condition = new BooleanOCLCondition<EClassifier, EClass,
> EObject>(ocl.getEnvironment(), "self.numberOfWorkers", null );
> } catch( final ParserException ex ) {
> log.error( "UNEXPECTED", ex );
> }
> final SELECT statement = new SELECT( SELECT.UNBOUNDED, false, new FROM(
> shop), new WHERE( condition ), new NullProgressMonitor() );
>
> final IQueryResult results = statement.execute();
> for( final EObject o : results.getEObjects() ) {
> log.debug( o.getClass().getName() ); }
>
>
>
Re: EMF & OCL beginner question [message #523754 is a reply to message #523147] Mon, 29 March 2010 08:04 Go to previous message
Thomas is currently offline ThomasFriend
Messages: 11
Registered: March 2010
Junior Member
Hi Ed,
thanks for your response. I'm going to ask the emft newsgroup.

Regards
Previous Topic:OCL related query
Next Topic:[Announce] MoDELS 2010 Call for Papers
Goto Forum:
  


Current Time: Thu Dec 18 19:43:06 GMT 2014

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

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