Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Applying stereotype to a model which is not contained in a resource yet?
Applying stereotype to a model which is not contained in a resource yet? [message #627953] Tue, 22 September 2009 22:58 Go to next message
No real name is currently offline No real nameFriend
Messages: 61
Registered: July 2009
Member
Hi,

if I want to apply a stereotype to a model programmaticly I do this:
element.applyStereotype(this.arrayStereotype);
Unfortunatly, that does not work, if the model is not yet contained in a resource (because I am just constructing it).

That is because of these methods in org.eclipse.uml2.uml.util.UMLUtil:

protected EList<EObject> getContainmentList(Element element,
EClass definition) {

if (element.eResource() != null) {
return element.eResource().getContents();
}
return null;
}

public EObject applyStereotype(Element element, EClass definition) {
EObject stereotypeApplication = EcoreUtil.create(definition);

CacheAdapter.INSTANCE.adapt(stereotypeApplication);

EList<EObject> containmentList = getContainmentList(element,
definition);
if (containmentList != null) {
containmentList.add(stereotypeApplication);
}
setBaseElement(stereotypeApplication, element);

return stereotypeApplication;
}

So my code for applying a stereotype does not do anything and no exception is thrown (which is bad in my oppinnion: If something does not do what it is supposed to do there should be an exception).

Why is it compulsory for the model to be in a resource just for applying a stereotype? And is there a way to get around this?

Thank you
Re: Applying stereotype to a model which is not contained in a resource yet? [message #627954 is a reply to message #627953] Wed, 23 September 2009 14:59 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi,

The result of applyStereotype() is the stereotype application so you can do
what you like with it at that point.

In addition, you can simply override the getContainmentList() method and
return what you like by specializing the stereotype application helper.
You can have the UML2 infrastructure load your special helper by using the
org.eclipse.uml2.uml.util$SterotypeApplicationHelper.INSTANC E system
property.

The method is trying to locate a place to put the stereotype applications.
Typically they are placed in the same resource as the element to which the
stereotype is applied, however you can put them anywhere you like.

The result of calling applyStereotype() (with no resource being set) is the
application of the stereotype. The stereotype application is cached and the
base element is set. The in-memory representation of the application
should be fine. I don't see why an exception should be thrown.

- James.

<skobilke@gmx.de> wrote in message news:h9bkqc$8mu$1@build.eclipse.org...
> Hi,
>
> if I want to apply a stereotype to a model programmaticly I do this:
> element.applyStereotype(this.arrayStereotype);
> Unfortunatly, that does not work, if the model is not yet contained in a
> resource (because I am just constructing it).
>
> That is because of these methods in org.eclipse.uml2.uml.util.UMLUtil:
>
> protected EList<EObject> getContainmentList(Element element,
> EClass definition) {
>
> if (element.eResource() != null) {
> return element.eResource().getContents();
> }
> return null;
> }
>
> public EObject applyStereotype(Element element, EClass definition) {
> EObject stereotypeApplication = EcoreUtil.create(definition);
>
> CacheAdapter.INSTANCE.adapt(stereotypeApplication);
>
> EList<EObject> containmentList = getContainmentList(element,
> definition);
> if (containmentList != null) {
> containmentList.add(stereotypeApplication);
> }
> setBaseElement(stereotypeApplication, element);
>
> return stereotypeApplication;
> }
>
> So my code for applying a stereotype does not do anything and no exception
> is thrown (which is bad in my oppinnion: If something does not do what it
> is supposed to do there should be an exception).
>
> Why is it compulsory for the model to be in a resource just for applying a
> stereotype? And is there a way to get around this?
>
> Thank you
Previous Topic:[Announce] MDT UML2 3.1.0M2 is available
Next Topic:Importing Eclipse UML2 Class diagrams from Visio, ArgoUML, Poseidon,...
Goto Forum:
  


Current Time: Wed Apr 24 15:05:11 GMT 2024

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

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

Back to the top