How to create reference to a Usecase using Ireference?


#1

Hi every body
i have a use-case and i want to create a reference to it and add this reference to a task in a business process diagram.
for example i have a Task in a business process diagram with name task1
and also have a use-case with name usecase1 in a use-case diagram (i retrieve this use-case before and have access to that.also i retrieve Task1 from a bp diagram and have access to that too).
i know that i should create an Ireference variable but dont know how connect it to that use case.
some code like bellow don’t work for me :

IReference reference1=null;
reference1.setUrlAsModel(usecase1); // usecase1 is a IModelElement variable that actually is a usease (i retrieve it using toAllLevelModelElementArray() method)

thanks in advance


#2

Please try:

IBPTask task = ...;
IUseCase usecase = ...;

IReference reference = IModelElementFactory.instance().createReference();
task.addReference(reference);
reference.setType(IReference.TYPE_TYPE_MODEL_ELEMENT);
reference.setUrlAsModel(usecase);

#3

Tnx it works !:blush::ok_hand: