Handling stereotypes

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Handling stereotypes

Postby Thierry Beigbeder » Mon May 21, 2007 2:31 am

Hi
it does not seem obvious to handle stereotypes.

In particular, how to create a new stereotype in a model.
ElementsFactory.createStereotypeInstance
creates a stereotype but without any metaclass,
while
StereotypesHelper.createStereotype(Element owner, String name,
Collection metaClasses)
requires metaClasses, but how to specify them?

Also what API is recommended for retrieving a given stereotype from a model?

The class StereotypesHelper seems rich but yet not easy to use. A lot of
operations have only little javadoc documentation. Is there other source
of information about this subject?

kind regards,

--
Thierry Beigbeder
Thierry Beigbeder
 
Posts Rating:

Re: Handling stereotypes

Postby Martynas Lelevicius » Mon May 21, 2007 6:23 am

Hi,

There are several ways to create stereotype. E.g:

// get metaclass "Class"
com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class metaClass =
StereotypesHelper.getMetaClassByName(project, "Class");
List metaClasses = Arrays.asList(new Object[]{metaClass});

// create stereotype instance
Stereotype stereotype =
project.getElementsFactory().createStereotypeInstance();
stereotype.setName("ST1");
stereotype.setOwner(project.getModel());
// set metaclasses
StereotypesHelper.deriveStereotypeFromMetaClasses(stereotype,
metaClasses);

// create stereotype with metaclasses
StereotypesHelper.createStereotype(project.getModel(), "ST2",
metaClasses);


To find a stereotype you can use:

StereotypesHelper.getStereotype(project, "ST2");


Unfortunately javadoc is the only info source for working with stereotypes.

Regards,
--
Martynas Lelevicius
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
E-mail : marte
WWW: http://www.magicdraw.com

----- Original Message -----
From: "nntp://news.nomagic.com/nomagic.products.magicdrawuml.openapi"
<nobody-to-reply>
To: "Martynas Lelevicius" <marlel>
Sent: Monday, May 21, 2007 2:44 PM
Subject: Handling stereotypes


> Hi
> it does not seem obvious to handle stereotypes.
>
> In particular, how to create a new stereotype in a model.
> ElementsFactory.createStereotypeInstance
> creates a stereotype but without any metaclass,
> while
> StereotypesHelper.createStereotype(Element owner, String name, Collection
> metaClasses)
> requires metaClasses, but how to specify them?
>
> Also what API is recommended for retrieving a given stereotype from a
> model?
>
> The class StereotypesHelper seems rich but yet not easy to use. A lot of
> operations have only little javadoc documentation. Is there other source
> of information about this subject?
>
> kind regards,
>
> --
> Thierry Beigbeder
>

Martynas Lelevicius
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 1 guest