|
Re: EMF & OCL beginner question [message #523191 is a reply to message #523147] |
Thu, 25 March 2010 13:19 |
|
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 |
Thomas 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 |
Ed Willink Messages: 7655 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() ); }
>
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03754 seconds