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 05: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 07: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 08: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 #36012 is a reply to message #35944] |
Wed, 22 August 2007 08: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
|
|
| | | | | |
Goto Forum:
Current Time: Sat Jul 05 03:24:29 EDT 2025
Powered by FUDForum. Page generated in 0.62006 seconds
|