Home » Modeling » OCL » new to ocl - how to check ocl on uml model
new to ocl - how to check ocl on uml model [message #35707] |
Tue, 21 August 2007 09:54 |
Eclipse User |
|
|
|
Originally posted by: nickkirtley.gmail.com
hi,
I have a uml model (from the component diagram/uml2tools) and I want to
check ocl constraints. So all I want is to check whether conditions have
been met or not.
Could someone tell me how to get started. Like initialization of things
and how I execute the ocl commands.
What I was thinking was start with a selected element (which I have). This
element could be a component for example. And that I then check whether it
has a port and an interface(s) - this is what I'd like to do to get
started.
I also read something about needing an external parser from sourceforge?
is this corrent and what do I need to do to get that working?
OCL is new to me so please keep it simple and step by step.
thanks in advance, appreciate any replies,
nick
|
|
|
Re: new to ocl - how to check ocl on uml model [message #35742 is a reply to message #35707] |
Tue, 21 August 2007 11:59 |
Eclipse User |
|
|
|
Originally posted by: nickkirtley.gmail.com
hi,
I tried the following:
// create an OCL instance for Ecore
OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject>
ocl;
ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
// create an OCL helper object
OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl.createOCLHelper();
// set the OCL context classifier
helper.setContext(EXTLibraryPackage.Literals.LIBRARY);
Constraint invariant = helper.createInvariant(
"books->forAll(b1, b2 | b1 <> b2 implies b1.title <> b2.title)");
OCLExpression<EClassifier> query = helper.createQuery(
"books->collect(b : Book | b.category)->asSet()");
As I can tell this initializes ocl so that I can use it and defines some
constraints. Are these constraints checked or are these only the
definitions? Also this is for the ecore model whereas would like it to be
used for uml.
Another thing is when I put this in my action it does not work because
Eclassifier and EClass(first line of code) cannot be resolved to a type.
I think I have imported the right packages.
am i on the right track?
thx,nick
|
|
|
Re: new to ocl - how to check ocl on uml model [message #35876 is a reply to message #35742] |
Wed, 22 August 2007 12:26 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Nick,
The Ecore environment is good for parsing and evaluating constraints on
Ecore models. For UML models, the UML environment (created by the
org.eclipse.ocl.uml.UMLEnvironmentFactory) is most appropriate.
In any case, the OCL parser/interpreter is based on EMF, so you will have to
have the core EMF plug-ins in your classpath: start with
org.eclipse.emf.ecore.
It looks like you have already found the tutorial and/or example in the OCL
SDK. The org.eclipse.emf.ocl.examples.interpreter example plug-in is an
interactive OCL console, which in the 1.1 release has a UML mode for
working in UML models. This is a good scratchpad for testing your OCL
constraint expressions as well as an example of how to use the OCL API with
UML. Install it in your workspace using the "File -> New -> Example..."
menu and explore the code from there.
HTH,
Christian
Nick Kirtley wrote:
> hi,
>
> I tried the following:
>
>
> // create an OCL instance for Ecore
> OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject>
> ocl;
> ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
>
> // create an OCL helper object
> OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl.createOCLHelper();
>
> // set the OCL context classifier
> helper.setContext(EXTLibraryPackage.Literals.LIBRARY);
>
> Constraint invariant = helper.createInvariant(
> "books->forAll(b1, b2 | b1 <> b2 implies b1.title <> b2.title)");
>
> OCLExpression<EClassifier> query = helper.createQuery(
> "books->collect(b : Book | b.category)->asSet()");
>
>
> As I can tell this initializes ocl so that I can use it and defines some
> constraints. Are these constraints checked or are these only the
> definitions? Also this is for the ecore model whereas would like it to be
> used for uml.
> Another thing is when I put this in my action it does not work because
> Eclassifier and EClass(first line of code) cannot be resolved to a type.
> I think I have imported the right packages.
>
> am i on the right track?
>
> thx,nick
|
|
|
Re: new to ocl - how to check ocl on uml model [message #35944 is a reply to message #35876] |
Wed, 22 August 2007 12:41 |
Eclipse User |
|
|
|
Originally posted by: nickkirtley.gmail.com
hi,
another update:
i tried the following, which I got from an earlier post.
OCL myOcl = org.eclipse.ocl.uml.OCL.newInstance();
myOcl.setEvaluationTracingEnabled(true);
myOcl.setParseTracingEnabled(true);
OCLHelper oclHelper = myOcl.createOCLHelper();
oclHelper.setInstanceContext(element);
OCLExpression oclInv=null;
String myQuery = "self.required->size()=1";
try {
oclInv = (OCLExpression) oclHelper.createQuery(myQuery);
System.out.println("still in try");
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("in catch now");
e.printStackTrace();
}
myOcl.check(element, oclInv)
In the first line i deleted resourceSet as a variable.
I get to the try and that fails and then goes to the catch. What is going
wrong here. Is it that I didn't initialize properly because I got rid of
resourceSet or is it that the query is no good?
regards,
nick
|
|
|
Re: new to ocl - how to check ocl on uml model [message #36012 is a reply to message #35944] |
Wed, 22 August 2007 12:49 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Nick,
The exception probably has a message that provides a hint. Otherwise, the
stack trace may indicate where, for example, a null pointer was accessed.
I can't just guess; there are too many possibilities.
I am assuming that your UML element is in a resource that is in a resource
set, and that resource is in a resource set, because this is in a
UML2Tools-based diagram editor, right? In that case, using the
OCL::newInstance(ResourceSet) factory method is a good idea because
otherwise you will be creating a new resource set and loading the (rather
large) UML.metamodel.uml resource in it every time that you parse and OCL
expression.
Cheers,
Christian
Nick Kirtley wrote:
> hi,
>
> another update:
>
> i tried the following, which I got from an earlier post.
>
>
>
> OCL myOcl = org.eclipse.ocl.uml.OCL.newInstance();
>
> myOcl.setEvaluationTracingEnabled(true);
> myOcl.setParseTracingEnabled(true);
>
> OCLHelper oclHelper = myOcl.createOCLHelper();
>
> oclHelper.setInstanceContext(element);
>
> OCLExpression oclInv=null;
> String myQuery = "self.required->size()=1";
> try {
> oclInv = (OCLExpression) oclHelper.createQuery(myQuery);
> System.out.println("still in try");
> } catch (Exception e) {
> // TODO Auto-generated catch block
> System.out.println("in catch now");
> e.printStackTrace();
> }
> myOcl.check(element, oclInv)
>
> In the first line i deleted resourceSet as a variable.
> I get to the try and that fails and then goes to the catch. What is going
> wrong here. Is it that I didn't initialize properly because I got rid of
> resourceSet or is it that the query is no good?
>
> regards,
> nick
|
|
|
Re: new to ocl - how to check ocl on uml model [message #36182 is a reply to message #36012] |
Mon, 27 August 2007 13:35 |
Eclipse User |
|
|
|
Originally posted by: nickkirtley.gmail.com
Hi Christian,
I got an ocl query working. I have the following query:
self.name='nick';
when i name the component (self) nick then the query is true if i name it
something else then false. Hooray!
What I'm having trouble with now is the following:
1)I have a component, a port and two interfaces.
what I want to do is check whether component exists, (which obviously it
does since self=component)if component has a port and if port has two
interfaces.
2) After that I want to check whether port and interface(s) have been
stereotyped with a certain stereotype name.
Could you give me the query code for something like this? (1 & 2)
I've tried this:
self.port. etc but it says that it doesn't know the variable port.
I thought that in ocl if port is connected to component then self.port
should go to port from self.
thx for your replies, it is helping.
regards,
Nick
|
|
|
Re: new to ocl - how to check ocl on uml model [message #36250 is a reply to message #36182] |
Wed, 29 August 2007 15:18 |
Eclipse User |
|
|
|
Originally posted by: nickkirtley.gmail.com
hi,
i got it working so no problem.
except for getRequireds() for the required interface. for some reason it
will not return the required interface that is associated with port.
Provided will though.
You know why this could be the case?
thx, nick
|
|
|
Re: new to ocl - how to check ocl on uml model [message #36405 is a reply to message #36250] |
Thu, 06 September 2007 14:46 |
Eclipse User |
|
|
|
Originally posted by: nickkirtley.gmail.com
so can anyone tell me why this is possible:
self.name = 'port' - returns a boolean, true if self is called port
self.ownedPort.name = returns name of ownedPort if self is a component
the two statements work
now this one doesn't:
self.ownedPort.name = 'port'
Error: (operationCallExpCS): (cannot find operation (=(String)) for the
type (Bag(String)).
why doesn't the third query work when the first two work without any
problems?
regards,nick
|
|
| | |
Goto Forum:
Current Time: Mon Sep 23 09:52:21 GMT 2024
Powered by FUDForum. Page generated in 0.04684 seconds
|