Home » Modeling » OCL » ocl query
ocl query [message #36871] |
Wed, 12 September 2007 12:15 |
Eclipse User |
|
|
|
Originally posted by: nickkirtley.gmail.com
hi,
I have a problem with an OCL query:
I have:
Component c1, with stereotyped port e, port has two interfaces, one
provided one required, provided is stereotyped and called ObserveEvent ,
required is stereotyped and called update.
Component c2, with stereotyped port c, port has two interfaces, one
provided one required, provided is stereotyped and called update ,
required is stereotyped and called ObserveEvent.
c2 has two properties, foo and bar, these two are connected with a
connector. Within the context of c2. The connector is stereotyped.
problem 1:
if self is c2: self.ownedPort.getRequireds does not work. Provided does
work. Is there a reason for this?
problem 2:
if self is c2: I want to traverse along the connector to c1 and check if
the interfaces of c1 have been stereotyped:
self.ownedConnector.end.role.type->select(name='c1').ownedElement
this returns port of c1. Problem is that I know I have a port, but OCL
doesn't know it's a port and thus does not give me the option of doing
port specific things. Infact the element above it, which is c1, also
doesn't know that it's a component and I can't just use .OwnedPort.
What I need is some sort of cast or that OCL would know directly what kind
of element it is dealing with.
So really with :
self.ownedConnector.end.role.type->select(name='c1') I would like to be able
to a component specific command - .ownedPort. Unfortunately I can't.
I suspect the problem is that I selected it with select, and thus OCL
doens't know what kind of element it is.
thx in advance,
Nick
|
|
|
Re: ocl query [message #36905 is a reply to message #36871] |
Wed, 12 September 2007 14:01 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Nick,
See some replies in-line, below.
HTH,
Christian
nick kirtley wrote:
> hi,
>
> I have a problem with an OCL query:
>
> I have:
>
> Component c1, with stereotyped port e, port has two interfaces, one
> provided one required, provided is stereotyped and called ObserveEvent ,
> required is stereotyped and called update.
>
> Component c2, with stereotyped port c, port has two interfaces, one
> provided one required, provided is stereotyped and called update ,
> required is stereotyped and called ObserveEvent.
>
> c2 has two properties, foo and bar, these two are connected with a
> connector. Within the context of c2. The connector is stereotyped.
>
> problem 1:
> if self is c2: self.ownedPort.getRequireds does not work. Provided does
> work. Is there a reason for this?
What do you mean by "does not work?" Do you mean that it doesn't parse, or
that evaluating it doesn't give you the expected result?
If getRequireds() and getProvideds() are both Operations specified in the
UML metamodel, then OCL will be able to invoke them and any deviation from
expected results would be caused by their implementation in the UML2 API.
Are the requireds a property or an operation? i.e., should your expression
look like
self.ownedPort.required
or like
self.ownedPort.getRequireds()
? You didn't use either of these forms in your problem statement.
> problem 2:
> if self is c2: I want to traverse along the connector to c1 and check if
> the interfaces of c1 have been stereotyped:
>
> self.ownedConnector.end.role.type->select(name='c1').ownedElement
> this returns port of c1. Problem is that I know I have a port, but OCL
> doesn't know it's a port and thus does not give me the option of doing
> port specific things. Infact the element above it, which is c1, also
> doesn't know that it's a component and I can't just use .OwnedPort.
> What I need is some sort of cast or that OCL would know directly what kind
> of element it is dealing with.
You can use the oclAsType(Port) operation on the element to cast it as a
Port. However, the owned elements of the c1 component will, in general, be
many more than just the ports that it owns.
> So really with :
> self.ownedConnector.end.role.type->select(name='c1') I would like to be
> able to a component specific command - .ownedPort. Unfortunately I can't.
> I suspect the problem is that I selected it with select, and thus OCL
> doens't know what kind of element it is.
Try this:
self.ownedConnector.end.role.type->any(name='c1').oclAsType(Component).ownedPort
Note the use of the "any" iterator to get the first available match instead
of a collection of matches, and the cast to work with it as a Component.
> thx in advance,
>
>
> Nick
|
|
|
Re: ocl query [message #36973 is a reply to message #36871] |
Wed, 12 September 2007 15:29 |
Eclipse User |
|
|
|
Originally posted by: nickkirtley.gmail.com
hi,
I've found what i'm looking for:
I use the oclAsType command, then I can tell it that it's dealing with
port or component.
The getRequierds is still not working though. help on that would be
appreciated.
cheers,
Nick
|
|
|
Re: ocl query [message #37005 is a reply to message #36973] |
Wed, 12 September 2007 17:13 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Nick,
Did you read my reply to your post? That it "is not working" is not a
sufficient statement of the problem. Please describe the symptoms so that
we may help:
- does the expression not parse? (what is the exact form,
including any parentheses for operation calls)
- if it does not parse, what is the error message?
- if it just doesn't evaluate as expected, what are the expected
and actual results?
- what does debugging the execution show?
Without diagnostic information, I doubt that anyone will be able to help.
Cheers,
Christian
nick kirtley wrote:
> hi,
>
> I've found what i'm looking for:
>
> I use the oclAsType command, then I can tell it that it's dealing with
> port or component.
>
> The getRequierds is still not working though. help on that would be
> appreciated.
>
>
> cheers,
>
> Nick
|
|
|
Re: ocl query [message #37072 is a reply to message #37005] |
Thu, 13 September 2007 11:54 |
Eclipse User |
|
|
|
Originally posted by: nickkirtley.gmail.com
Hi Christian,
I hadn't read your reply in my second post.
Sorry about not being very clear regarding problem1.
Query1:
Evaluating:
self.ownedPort.getProvideds()
Results:
Interface update
Query2:
Evaluating:
self.ownedPort.getRequireds()
Results:
I should get an Interface just as I did in query1.
One other thing I noticed was that in the component diagram, when you
create a provided interface from a port, that it has a line between the
two.
When I do the same for required there's no line.
Could this have something to do with uml2 rather than ocl?
Are you able to retrieve a required interface?
thx again,
nick
|
|
|
Re: ocl query [message #37107 is a reply to message #37072] |
Thu, 13 September 2007 14:51 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Nick,
Thanks for the additional diagnostic information. I'm including the UML2
newsgroup in my reply because it looks like a problem either in the
structure of your model or in the computation of required interfaces.
Your OCL expression evidently is successfully invoking getRequireds() on
each owned port of your component, then aggregating the results into some
collection that depends on the combination of the collection kinds of
ownedPort and getRequireds() (which are both multi-valued features).
So, you can expect the same result from computing the requireds in Java
code.
Your original post indicates that each of your components' ports has a
required interface. How did you express that in your model? AFAIK, this
requires that the port's type have some kind of usage or like dependency on
the interface. But I only know as recently as UML 2.0; it's possible that
this is refined/changed in UML 2.1 (the newsgroup can help, there, I'm
sure). Possibly the diagramming tool that you are using isn't configuring
your model correctly?
I think the UML2 API is OK because, when I use Rational Software Modeler to
create a component with a port having a required interface, executing
self.ownedPort.getRequireds()
in the OCL Console example gives me the expected required interface.
Cheers,
Christian
Nick Kirtley wrote:
> Hi Christian,
>
> I hadn't read your reply in my second post.
> Sorry about not being very clear regarding problem1.
>
> Query1:
> Evaluating:
> self.ownedPort.getProvideds()
>
> Results:
> Interface update
>
> Query2:
> Evaluating:
> self.ownedPort.getRequireds()
>
> Results:
>
> I should get an Interface just as I did in query1.
> One other thing I noticed was that in the component diagram, when you
> create a provided interface from a port, that it has a line between the
> two.
> When I do the same for required there's no line.
>
> Could this have something to do with uml2 rather than ocl?
>
> Are you able to retrieve a required interface?
>
> thx again,
> nick
|
|
|
Goto Forum:
Current Time: Sun Sep 08 14:12:25 GMT 2024
Powered by FUDForum. Page generated in 0.04347 seconds
|