Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » new Problem on applieng a StereoType
new Problem on applieng a StereoType [message #474274] Wed, 18 July 2007 11:56 Go to next message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Hello NG, hello James ;)
at first I want to congratulate James for his "upgrade" ;)
Well, here is my problem. I have two methods. One is creating a Package
with some classes and the other creates a Package with some stereotypes.
Now I want to apply a StereoType to a Class after creating both
Packages. I tried it as follows:


Package classes = createClassDiagramPackage();
Class classA = getElementByName(Class.class, classes, CLASS_A_NAME);
Package stereoTypes = createStereoTypePackage();
Stereotype st = getElementByName(Stereotype.class, stereoTypes,
STEREOTYPE_TEST);
classA.applyStereotype(st);



But all I get is IllegalArgumentException when applieng the StereoType.
My method getElementByName looks like this:


public static <T extends NamedElement> T getElementByName(
java.lang.Class<T> klasse, Package owningPackage, String name) {
EList<Element> elements = owningPackage.allOwnedElements();
for (Element element : elements) {
if (klasse.isInstance(element)) {
String tempName = ((NamedElement)element).getName();
if (tempName.equals(name)) {
return klasse.cast(element);
}
}
}
return null;
}


This method works fine - that means I don't get null as result. So why
can't I apply the StereoType?


greets
J.R.
Re: new Problem on applieng a StereoType [message #474275 is a reply to message #474274] Wed, 18 July 2007 11:59 Go to previous messageGo to next message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
sorry for the mis-spellt topic ;)
Re: new Problem on applieng a StereoType [message #474276 is a reply to message #474274] Wed, 18 July 2007 11:58 Go to previous messageGo to next message
Philippe is currently offline PhilippeFriend
Messages: 100
Registered: July 2009
Senior Member
Hello Jan,

AFAIK stereotypes needs to be defined within a profile, and you have to
apply this profile to your package "classes" before you can apply
stereotypes to its classes.

You can still have a look at
http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Intro duction_to_UML2_Profiles/article.html

There might have some changes since this article but the learning about
profile and stereotypes is still good

Regards,
Philippe

Jan Reimann wrote:
> Hello NG, hello James ;)
> at first I want to congratulate James for his "upgrade" ;)
> Well, here is my problem. I have two methods. One is creating a Package
> with some classes and the other creates a Package with some stereotypes.
> Now I want to apply a StereoType to a Class after creating both
> Packages. I tried it as follows:
>
>
> Package classes = createClassDiagramPackage();
> Class classA = getElementByName(Class.class, classes, CLASS_A_NAME);
> Package stereoTypes = createStereoTypePackage();
> Stereotype st = getElementByName(Stereotype.class, stereoTypes,
> STEREOTYPE_TEST);
> classA.applyStereotype(st);
>
>
>
> But all I get is IllegalArgumentException when applieng the StereoType.
> My method getElementByName looks like this:
>
>
> public static <T extends NamedElement> T getElementByName(
> java.lang.Class<T> klasse, Package owningPackage, String name) {
> EList<Element> elements = owningPackage.allOwnedElements();
> for (Element element : elements) {
> if (klasse.isInstance(element)) {
> String tempName = ((NamedElement)element).getName();
> if (tempName.equals(name)) {
> return klasse.cast(element);
> }
> }
> }
> return null;
> }
>
>
> This method works fine - that means I don't get null as result. So why
> can't I apply the StereoType?
>
>
> greets
> J.R.
Re: new Problem on applieng a StereoType [message #474277 is a reply to message #474276] Wed, 18 July 2007 12:44 Go to previous messageGo to next message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Philippe schrieb:
> AFAIK stereotypes needs to be defined within a profile, and you have to
> apply this profile to your package "classes" before you can apply
> stereotypes to its classes.

Hmm...If I construct a model with the UML Model Editor you can just
apply a StereoType to a Class without having any Profile. Then you can
right-click the root and Validate the Model without problems. So can
anybody approve that a Profile is needed?

greets
J.R.
Re: new Problem on applieng a StereoType [message #474381 is a reply to message #474277] Wed, 18 July 2007 17:53 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jan,

Thanks for the congrats on the "upgrade" :)

In general, you would need to "define" your profile before actually using it
( unless you are using static profile definition but that's another story ).
Profiles are a way of extending an existing metamodel. Some ecore
representation (dynamic or static) would be needed before they can be used.
Profiles are generally created in a separate resource since they could be
reused.

In terms of creating a stereotype in a package without "define" and without
a "profile" ...it doesn't seem like that should work. I gave it a quick
try in the UML editor and was unable to correctly reference a metaclass or
apply the sterotype to some other element. Could you provide step by step
instructions and I will give it a try.

The getting started article would be the best starting point and indicates
the "traditional" way of working with profiles ( as Philippe pointed out ).

Cheers,

- James.


"Jan Reimann" <eclipse@janreimone.de> wrote in message
news:f7l1vp$927$1@build.eclipse.org...
> Philippe schrieb:
> > AFAIK stereotypes needs to be defined within a profile, and you have to
> > apply this profile to your package "classes" before you can apply
> > stereotypes to its classes.
>
> Hmm...If I construct a model with the UML Model Editor you can just
> apply a StereoType to a Class without having any Profile. Then you can
> right-click the root and Validate the Model without problems. So can
> anybody approve that a Profile is needed?
>
> greets
> J.R.
Re: new Problem on applieng a StereoType [message #623752 is a reply to message #474274] Wed, 18 July 2007 11:59 Go to previous message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
sorry for the mis-spellt topic ;)
Re: new Problem on applieng a StereoType [message #623753 is a reply to message #474274] Wed, 18 July 2007 11:58 Go to previous message
Philippe is currently offline PhilippeFriend
Messages: 100
Registered: July 2009
Senior Member
Hello Jan,

AFAIK stereotypes needs to be defined within a profile, and you have to
apply this profile to your package "classes" before you can apply
stereotypes to its classes.

You can still have a look at
http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Intro duction_to_UML2_Profiles/article.html

There might have some changes since this article but the learning about
profile and stereotypes is still good

Regards,
Philippe

Jan Reimann wrote:
> Hello NG, hello James ;)
> at first I want to congratulate James for his "upgrade" ;)
> Well, here is my problem. I have two methods. One is creating a Package
> with some classes and the other creates a Package with some stereotypes.
> Now I want to apply a StereoType to a Class after creating both
> Packages. I tried it as follows:
>
>
> Package classes = createClassDiagramPackage();
> Class classA = getElementByName(Class.class, classes, CLASS_A_NAME);
> Package stereoTypes = createStereoTypePackage();
> Stereotype st = getElementByName(Stereotype.class, stereoTypes,
> STEREOTYPE_TEST);
> classA.applyStereotype(st);
>
>
>
> But all I get is IllegalArgumentException when applieng the StereoType.
> My method getElementByName looks like this:
>
>
> public static <T extends NamedElement> T getElementByName(
> java.lang.Class<T> klasse, Package owningPackage, String name) {
> EList<Element> elements = owningPackage.allOwnedElements();
> for (Element element : elements) {
> if (klasse.isInstance(element)) {
> String tempName = ((NamedElement)element).getName();
> if (tempName.equals(name)) {
> return klasse.cast(element);
> }
> }
> }
> return null;
> }
>
>
> This method works fine - that means I don't get null as result. So why
> can't I apply the StereoType?
>
>
> greets
> J.R.
Re: new Problem on applieng a StereoType [message #623754 is a reply to message #474276] Wed, 18 July 2007 12:44 Go to previous message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Philippe schrieb:
> AFAIK stereotypes needs to be defined within a profile, and you have to
> apply this profile to your package "classes" before you can apply
> stereotypes to its classes.

Hmm...If I construct a model with the UML Model Editor you can just
apply a StereoType to a Class without having any Profile. Then you can
right-click the root and Validate the Model without problems. So can
anybody approve that a Profile is needed?

greets
J.R.
Re: new Problem on applieng a StereoType [message #623758 is a reply to message #474277] Wed, 18 July 2007 17:53 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jan,

Thanks for the congrats on the "upgrade" :)

In general, you would need to "define" your profile before actually using it
( unless you are using static profile definition but that's another story ).
Profiles are a way of extending an existing metamodel. Some ecore
representation (dynamic or static) would be needed before they can be used.
Profiles are generally created in a separate resource since they could be
reused.

In terms of creating a stereotype in a package without "define" and without
a "profile" ...it doesn't seem like that should work. I gave it a quick
try in the UML editor and was unable to correctly reference a metaclass or
apply the sterotype to some other element. Could you provide step by step
instructions and I will give it a try.

The getting started article would be the best starting point and indicates
the "traditional" way of working with profiles ( as Philippe pointed out ).

Cheers,

- James.


"Jan Reimann" <eclipse@janreimone.de> wrote in message
news:f7l1vp$927$1@build.eclipse.org...
> Philippe schrieb:
> > AFAIK stereotypes needs to be defined within a profile, and you have to
> > apply this profile to your package "classes" before you can apply
> > stereotypes to its classes.
>
> Hmm...If I construct a model with the UML Model Editor you can just
> apply a StereoType to a Class without having any Profile. Then you can
> right-click the root and Validate the Model without problems. So can
> anybody approve that a Profile is needed?
>
> greets
> J.R.
Previous Topic:undo notification
Next Topic:How to check two models against each other
Goto Forum:
  


Current Time: Wed Apr 08 07:55:27 GMT 2020

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

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

Back to the top