Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Retrieving a stereotype'S property with a static profile
Retrieving a stereotype'S property with a static profile [message #478482] Wed, 03 June 2009 11:36 Go to next message
Timothy Marc is currently offline Timothy MarcFriend
Messages: 547
Registered: July 2009
Senior Member
Hey all,

what is the common way to retrieve a property value of a stereotype from
a staric profile?

I assumed, because of the additional code generation step, it had to be
something like this:

Weight w = (Weight)element.getAppliedStereotype(Misc::Weight);
w.getWeight();

But that causes a ClassCastException. I searched in the newsgroup, but i
didn't found the solution yet.

Regards Timothy
Re: Retrieving a stereotype'S property with a static profile [message #478489 is a reply to message #478482] Thu, 04 June 2009 07:29 Go to previous message
Volker Stolz is currently offline Volker StolzFriend
Messages: 63
Registered: July 2009
Member
In article <h05mvv$fht$1@build.eclipse.org>,
Timothy Marc <timothymarc@freenet.de> wrote:

> Hey all,
>
> what is the common way to retrieve a property value of a stereotype from
> a staric profile?
>
> I assumed, because of the additional code generation step, it had to be
> something like this:
>
> Weight w = (Weight)element.getAppliedStereotype(Misc::Weight);
> w.getWeight();

I'm using the following construct (since I use a lot of stereotypes):

public static ExecutionList isExecutionList(Class e) {
return isRCOSSt(ExecutionList.class,e); }

@SuppressWarnings("unchecked")
private static <M> M isRCOSSt(java.lang.Class<M> stClass, Element e) {
assert(e != null);
Stereotype st =
e.getAppliedStereotype("rCOS::"+stClass.getSimpleName());
if (st == null) return null;
else return (M)e.getStereotypeApplication(st); }

(sorry for the formatting).

ExecutionList is a stereotype I defined for Class. Jumping through the
hoop with the Class<M> ensures that any disappearing classes in the
generated code for the static profile lead to an immediate compilation
error.

If you introduce a common (abstract) superclass for your stereotypes,
you can get even more type safety by stating M extends Super.

Hope this helps,
Volker

--
United Nations University -
Re: Retrieving a stereotype'S property with a static profile [message #627667 is a reply to message #478482] Thu, 04 June 2009 07:29 Go to previous message
Volker Stolz is currently offline Volker StolzFriend
Messages: 63
Registered: July 2009
Member
In article <h05mvv$fht$1@build.eclipse.org>,
Timothy Marc <timothymarc@freenet.de> wrote:

> Hey all,
>
> what is the common way to retrieve a property value of a stereotype from
> a staric profile?
>
> I assumed, because of the additional code generation step, it had to be
> something like this:
>
> Weight w = (Weight)element.getAppliedStereotype(Misc::Weight);
> w.getWeight();

I'm using the following construct (since I use a lot of stereotypes):

public static ExecutionList isExecutionList(Class e) {
return isRCOSSt(ExecutionList.class,e); }

@SuppressWarnings("unchecked")
private static <M> M isRCOSSt(java.lang.Class<M> stClass, Element e) {
assert(e != null);
Stereotype st =
e.getAppliedStereotype("rCOS::"+stClass.getSimpleName());
if (st == null) return null;
else return (M)e.getStereotypeApplication(st); }

(sorry for the formatting).

ExecutionList is a stereotype I defined for Class. Jumping through the
hoop with the Class<M> ensures that any disappearing classes in the
generated code for the static profile lead to an immediate compilation
error.

If you introduce a common (abstract) superclass for your stereotypes,
you can get even more type safety by stating M extends Super.

Hope this helps,
Volker

--
United Nations University -
Previous Topic:Retrieving a stereotype'S property with a static profile
Next Topic:Duplicate XMI id
Goto Forum:
  


Current Time: Fri Apr 26 06:37:23 GMT 2024

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

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

Back to the top