Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » actor, usecase relationship query
actor, usecase relationship query [message #520911] Mon, 15 March 2010 17:41 Go to next message
arise76  is currently offline arise76 Friend
Messages: 15
Registered: March 2010
Junior Member
Hi,

I am new to UML and OCL. I am reading superstructure document, where actor and usecase relationship is defined in OCL like this:

self.ownedAttribute->forAll ( a |
(a.association->notEmpty()) implies 
((a.association.memberEnd.size() = 2) and
 (a.opposite.class.oclIsKindOf(UseCase) or
  (a.opposite.class.oclIsKindOf(Class) and not a.opposite.class.oclIsKindOf(Behavior))))


I want to count how many usecases are associated with one actor.
from above OCL definition it should be like this (I am using OCL Interpreter console to run this query)

Actor.allInstances().attribute.opposite.class->select(oclIsTypeOf(UseCase))->size()


but it does not work. can any one guide me to resolve this query.


regards,
arise
Re: actor, usecase relationship query [message #520925 is a reply to message #520911] Mon, 15 March 2010 19:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi arise

> but it does not work. can any one guide me to resolve this query.

'does not work' is never a good way to report a problem.

What happened?

Did it return 0.

Did it crash ?

Did it give a syntax error ?

Regards

Ed Willink
Re: actor, usecase relationship query [message #520956 is a reply to message #520925] Mon, 15 March 2010 22:55 Go to previous messageGo to next message
arise76  is currently offline arise76 Friend
Messages: 15
Registered: March 2010
Junior Member
Hi Edward

It returns zero.

does not work --> may be considered as does not provide correct result and I am sorry for misleading words.

regards,
arise






Re: actor, usecase relationship query [message #521008 is a reply to message #520956] Tue, 16 March 2010 03:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
> It returns zero.

Well now you need to bug the problem.

Why is it zero?

Is the expression wrong (with seven terms quite probably)?

Is the source data as expected (quite possibly not, wrong file/didn't
load/...)

Try a simpler expression such as

Actor.allInstances()

then

Actor.allInstances().attribute

and at some point you should encounter a more obvious discrepancy with
your expectation.

Regards

Ed Willink
Re: actor, usecase relationship query [message #521058 is a reply to message #521008] Tue, 16 March 2010 11:12 Go to previous messageGo to next message
arise76  is currently offline arise76 Friend
Messages: 15
Registered: March 2010
Junior Member
Hi Ed,

I follow your steps:

> Actor.allInstances()

successfully parsed with the correct results

> Actor.allInstances().attribute

successfully parsed with out any error but with empty result. I mean there is no output.

I have tried and check with some simple queries on this file and they executed with correct result that means I have loaded the correct UML file.

I do not know whats wrong with the query as I am new to OCL. I may be going in wrong direction to count actor use case relationship.

Do you think any other way to count how many usecases are associated to one actor.

Thanks for help,
arise
Re: actor, usecase relationship query [message #521228 is a reply to message #521058] Tue, 16 March 2010 19:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi arise

You haven't provided any executable evidence, so I'm left to guess at
your meta-models.

If there is no output then I suspect that you have no Actors with
attributes.

NB Actor.allInstances().attribute is shorthand for

Actor.allInstances()->collect(attribute)

Regards

Ed Willink




On 16/03/2010 11:12, arise76 wrote:
> Hi Ed,
>
> I follow your steps:
>
>> Actor.allInstances()
>
> successfully parsed with the correct results
>> Actor.allInstances().attribute
>
> successfully parsed with out any error but with empty result. I mean
> there is no output.
>
> I have tried and check with some simple queries on this file and they
> executed with correct result that means I have loaded the correct UML file.
>
> I do not know whats wrong with the query as I am new to OCL. I may be
> going in wrong direction to count actor use case relationship.
>
> Do you think any other way to count how many usecases are associated to
> one actor.
>
> Thanks for help,
> arise
Re: actor, usecase relationship query [message #521434 is a reply to message #521228] Wed, 17 March 2010 15:26 Go to previous messageGo to next message
arise76  is currently offline arise76 Friend
Messages: 15
Registered: March 2010
Junior Member
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 #521454 is a reply to message #521434] Wed, 17 March 2010 11:12 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

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 #521470 is a reply to message #521454] Wed, 17 March 2010 17:06 Go to previous messageGo to next message
arise76  is currently offline arise76 Friend
Messages: 15
Registered: March 2010
Junior Member
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


Re: actor, usecase relationship query [message #522414 is a reply to message #521470] Mon, 22 March 2010 15:06 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

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
>
>
>
Previous Topic:EMF validation: provide clientData for validationListeners from inside a constraint
Next Topic:OCL related query
Goto Forum:
  


Current Time: Tue Apr 23 12:44:11 GMT 2024

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

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

Back to the top