Create include relationship between two use cases

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Create include relationship between two use cases

Postby Raul Lorenzo » Tue Feb 28, 2006 8:02 pm

Hi,

I am creating a plugin for create use cases from an requirement
management external application. So I create the use cases elements, but
now I need to make the relations between them.
I am this method to search use cases in a package and then I use
ModelHelper like OpenApi documentation comments to make the relation. I
can´t get make this work.

Is there any other way to do that?

private UseCase Obtener_Caso_Uso(String usecase_name,Namespace parent)
{
Iterator caso_uso=parent.getOwnedElement().iterator();
UseCase caso_encontrado=null;
boolean done=caso_uso.hasNext();
while (done)
{
if (caso_uso.getClass().getName().equals(usecase_name))
{
ERROR-> caso_encontrado=(Element)caso_uso.getClass();
done=true;
}
else
{
caso_uso.next();
done=caso_uso.hasNext();
}
}
return caso_encontrado;
}

Thanks in advance
Raul Lorenzo
 
Posts Rating:

Re: Create include relationship between two use cases (createIncludeInstance)

Postby Raul Lorenzo » Wed Mar 01, 2006 5:09 pm

Hi,

I tried to do it some different. The problem is that
createIncludeInstance returns me null. why?


private Include Crear_Include_Caso_Uso(String name_caso_origen,String
name_caso_destino,Namespace parent)
{
Include include_relation=null;
UseCase caso_origen=null;
UseCase caso_destino=null;
String include_name=name_caso_origen+"_"+name_caso_destino;
SessionManager.getInstance().createSession("Add include into model");
try
{
ElementsFactory f=MD_project.getElementsFactory();
include_relation=f.createIncludeInstance();
caso_origen=(UseCase)ElementFinder.find(parent,UseCase.class.getClass(),name_caso_origen);
caso_destino=(UseCase)ElementFinder.find(parent,UseCase.class.getClass(),name_caso_destino);
include_relation.setName(include_name);
include_relation.setIncludingCase(caso_origen);
include_relation.setAddition(caso_destino);

}
catch (Exception e)
{
e.printStackTrace();
}
SessionManager.getInstance().closeSession();
return include_relation;
}


Raul Lorenzo escribió:
> Hi,
>
> I am creating a plugin for create use cases from an requirement
> management external application. So I create the use cases elements, but
> now I need to make the relations between them.
> I am this method to search use cases in a package and then I use
> ModelHelper like OpenApi documentation comments to make the relation. I
> can´t get make this work.
>
> Is there any other way to do that?
>
> private UseCase Obtener_Caso_Uso(String usecase_name,Namespace parent)
> {
> Iterator caso_uso=parent.getOwnedElement().iterator();
> UseCase caso_encontrado=null;
> boolean done=caso_uso.hasNext();
> while (done)
> {
> if (caso_uso.getClass().getName().equals(usecase_name))
> {
> ERROR-> caso_encontrado=(Element)caso_uso.getClass();
> done=true;
> }
> else
> {
> caso_uso.next();
> done=caso_uso.hasNext();
> }
> }
> return caso_encontrado;
> }
>
> Thanks in advance
Raul Lorenzo
 
Posts Rating:

Re: Create include relationship between two use cases (createIncludeInstance)

Postby Raul Lorenzo » Thu Mar 02, 2006 3:35 am

I forgot this, the message exception I got when crashes

(com.nomagic.uml2.impl.magicdraw.mdusecases.IncludeImpl@115ff74)
null
java.lang.NullPointerException
Raul Lorenzo
 
Posts Rating:

Re: Create include relationship between two use cases (createIncludeInstance)

Postby Raul Lorenzo » Fri Mar 03, 2006 3:34 am

The problem was that I was using ElementFinder which is not static so I
need to create it. But always returns me null, and what I search exists.

what should I consider to use ElementFinder?

Raul Lorenzo escribió:
> Hi,
>
> I tried to do it some different. The problem is that
> createIncludeInstance returns me null. why?
>
>
> private Include Crear_Include_Caso_Uso(String name_caso_origen,String
> name_caso_destino,Namespace parent)
> {
> Include include_relation=null;
> UseCase caso_origen=null;
> UseCase caso_destino=null;
> String include_name=name_caso_origen+"_"+name_caso_destino;
> SessionManager.getInstance().createSession("Add include into model");
> try
> {
> ElementsFactory f=MD_project.getElementsFactory();
> include_relation=f.createIncludeInstance();
> caso_origen=(UseCase)ElementFinder.find(parent,UseCase.class.getClass(),name_caso_origen);
> caso_destino=(UseCase)ElementFinder.find(parent,UseCase.class.getClass(),name_caso_destino);
> include_relation.setName(include_name);
> include_relation.setIncludingCase(caso_origen);
> include_relation.setAddition(caso_destino);
>
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> SessionManager.getInstance().closeSession();
> return include_relation;
> }
>
>
Raul Lorenzo
 
Posts Rating:

Re: SOLVED

Postby Raul Lorenzo » Fri Mar 03, 2006 4:19 am

Now works, I had to remove .getClass() from parameter in
ElementFinder.find, like this

caso_origen=(UseCase)ElementFinder.find(parent,UseCase.class,name_caso_origen);
caso_destino=(UseCase)ElementFinder.find(parent,UseCase.class,name_caso_destino);
Raul Lorenzo
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 2 guests