Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL with UML
OCL with UML [message #547976] Tue, 20 July 2010 10:12 Go to next message
Eclipse UserFriend
Originally posted by: mugbi83.googlemail.com

Hi

I am trying to write a standalone application using EMF UML and OCL. At
the moment it's just a test to see how things work.
I am using the latest OCL and UML libraries downloaded on the
corresponding websites.

The core of my problem is that I want to read an XMI file (that contains
a UML model) and query one of its InstanceSpezifications for a certain
attribute.

//1.load model... and look for the instance, store the instancespec in spec

EClassifier classifier =
UMLPackage.eINSTANCE.getEClassifier("InstanceSpecification") ;

Classifier cla = OCLUMLUtil.getClassifier(classifier,
model.eResource().getResourceSet());
oclHelper.setContext(cla) ;
OCLExpression<Classifier> query = null;
try {
query = oclHelper.createQuery("let result:Classifier = self.for_subject
in result");
result = ocl.evaluate(spec, query);
}catch(Exception e)
{


This is an abbreviated version of my first test. for_subject is the name
of the attribute I want to query. This version did not work since it
can not find the variable for_subject. My first question therefore is:
how can I load the model in a way that OCL has no problems? Maybe the
metamodel is not loaded properly...

I altered my query (just to test)

let result:Set(Element) = self.allOwnedElements()-> select(r
|r.oclIsKindOf(Element)) in result");

The strange thing is that it resulted in an empty set (but should result
in the same set as allOwnedElements returns). It looks like it has
problems with the types of these elements.

Of course

let result:Set(Element) = self.allOwnedElements()-> select(r
|r.oclIsKindOf(Slot)) in result");

did not work too..

Can you give me a hint why it does not work? Do I have to use a
different setup or load the model in a special way?

Sorry for the long mail, thanks for help
best regards
Philipp
Re: OCL with UML [message #548065 is a reply to message #547976] Tue, 20 July 2010 14:45 Go to previous message
Eclipse UserFriend
Originally posted by: mugbi83.googlemail.com

Hi

I solved the problem (with a lot of luck).
The context was wrong :/

best regards
Philipp

Am 20.07.2010 12:12, schrieb Philipp Kalb:
> Hi
>
> I am trying to write a standalone application using EMF UML and OCL. At
> the moment it's just a test to see how things work.
> I am using the latest OCL and UML libraries downloaded on the
> corresponding websites.
>
> The core of my problem is that I want to read an XMI file (that contains
> a UML model) and query one of its InstanceSpezifications for a certain
> attribute.
>
> //1.load model... and look for the instance, store the instancespec in spec
>
> EClassifier classifier =
> UMLPackage.eINSTANCE.getEClassifier("InstanceSpecification") ;
>
> Classifier cla = OCLUMLUtil.getClassifier(classifier,
> model.eResource().getResourceSet());
> oclHelper.setContext(cla) ;
> OCLExpression<Classifier> query = null;
> try {
> query = oclHelper.createQuery("let result:Classifier = self.for_subject
> in result");
> result = ocl.evaluate(spec, query);
> }catch(Exception e)
> {
> …
>
> This is an abbreviated version of my first test. for_subject is the name
> of the attribute I want to query. This version did not work since it can
> not find the variable for_subject. My first question therefore is: how
> can I load the model in a way that OCL has no problems? Maybe the
> metamodel is not loaded properly...
>
> I altered my query (just to test)
>
> let result:Set(Element) = self.allOwnedElements()-> select(r
> |r.oclIsKindOf(Element)) in result");
>
> The strange thing is that it resulted in an empty set (but should result
> in the same set as allOwnedElements returns). It looks like it has
> problems with the types of these elements.
>
> Of course
>
> let result:Set(Element) = self.allOwnedElements()-> select(r
> |r.oclIsKindOf(Slot)) in result");
>
> did not work too..
>
> Can you give me a hint why it does not work? Do I have to use a
> different setup or load the model in a special way?
>
> Sorry for the long mail, thanks for help
> best regards
> Philipp
Previous Topic:Problems with helper...
Next Topic:Helper Problem _ I don't know how to solve?
Goto Forum:
  


Current Time: Mon Nov 24 22:59:43 GMT 2014

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

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