Home » Modeling » OCL » actor, usecase relationship query
| | | | | | |
Re: actor, usecase relationship query [message #521454 is a reply to message #521434] |
Wed, 17 March 2010 11:12 |
|
Hi, arise,
In the UML2 metamodel, Actors and Use Cases cannot own attributes.
Their "attribute" property has no subsets contributing any elements to
it, so it is always empty.
You will have to search by assocation, instead. The "other way" that
you tried is the correct approach. For your original problem of
counting how many uses cases are associated with a given actor, you
might try (I have not tested this):
context Actor
def: associatedUseCases : Set(UseCase) =
Association.allInstances()->select(
isBinary() and endType->contains(self))->iterate(
assoc : Assocation; ucs : Set(UseCase) = Set{} |
let actorEnd : Property = assoc.end->any(type = self).otherEnd,
useCase : UseCase = actorEnd.type.oclAsType(UseCase)
if useCase.oclIsUndefined() then
ucs
else
ucs->including(useCase)
endif
)
def: countUseCases : Integer = associatedUseCases->size()
Basically, the idea is to iterate through the associations involving the
actor and, for each, find the end that is the actor's end. The actor's
end is the opposite of the end typed by the actor, and thus is the one
expected to be typed by the use case. Then, if this end actually is
typed by a use case, the result of oclAsType is defined and we can add
it to the result set.
Cheers,
Christian
On 17/03/10 11:26 AM, arise76 wrote:
> Hi Ed,
>
> I do not understand what do you mean by attribute.
>
> suppose usecase diagram is like this:
> actor A---uc1
> actor A---uc2
> actor A-- uc3
>
> from above scenario actor A is associated to three usecases.
> I want to use OCL query to calculate this:
>
> The follwoing queries I have tested..
> 1. Actor.allInstances()->size()
> Result:
> 3
> 2. Actor.allInstances().attribute
> Result
> no result
> 3. Actor.allInstances().attribute->size()
> Result
> 0
>
> I tried with another way I got the result but I do not know it is
> correct way or not:
>
> Association.allInstances().endType-> select(e|e.oclIsTypeOf(Actor).and(Association.allInstances() .endType- >exists(a|a.oclIsTypeOf(UseCase))))->size()
>
>
>
> regards,
> arise
|
|
| |
Re: actor, usecase relationship query [message #522414 is a reply to message #521470] |
Mon, 22 March 2010 15:06 |
|
Hi, arise,
The OCL Interactive Console does not use the syntax for context
declaration. It parses expressions in the "embedded" style, taking as
the context the element currently selected in the model editor.
So, for example, if you have selected an Actor "arise" in your model,
then the expression that you enter in the console is parsed as
- an invariant constraint (the most appropriate for when the
context is a classifier) in the context of the "arise" actor
if the modeling level control is set to M1 (User Model)
- a query expression in the context of the Actor metaclass if the
modeling level control is set to M2 (Metamodel)
You would get different results if you select, say, operations or
properties in the M1 modeling level.
Concerning usage of OCLEvaluator, there is no tutorial, but the example
itself is, of course, an example of how to use it. Just see how the
console uses it.
HTH,
Christian
On 17/03/10 01:06 PM, arise76 wrote:
> Hi Christian,
>
> Thanks alot, I understand the problem now, but I am new to OCL world. I
> am using eclipse OCL interpreter console to execute OCL queries. It
> always complain about context keyword.
> Another question I have related to OCL, I hope you will guide me:
>
> I want to reuse OCLEvaluator Class (from OCLInterpreter example) to my
> java project to run these queries , is there any tutorial available or
> any simple example to run these queries.
>
> Thanks,
> arise
>
>
>
|
|
|
Goto Forum:
Current Time: Tue Apr 23 12:44:11 GMT 2024
Powered by FUDForum. Page generated in 0.06161 seconds
|