Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » stereotypes not found on model reload(UML MARTE stereotypes not found when the same model is deserialized a second time )
stereotypes not found on model reload [message #1272946] Wed, 19 March 2014 06:19 Go to next message
Andrew Miga is currently offline Andrew MigaFriend
Messages: 10
Registered: August 2009
Junior Member
We are working on an application which transforms UML behavior diagrams annotated with MARTE stereotypes into another EMF model. The application deserializes a .uml file (located in a directory with many supporting *.profile.uml files) into UML objects and then converts the MARTE annotated diagrams into another model. At many points MARTE stereotype tags and values which are attached to various diagram elements are successfully read.

Everything works fine the first time a specific .uml model is transformed. The file is deserialized into a UML object model and the attached stereotypes are successfully read. However the second time the same .uml model file is transformed no stereotypes of any kind are found. The UML objects themselves are created but attached stereotypes can't be found. If the application is restarted the everything works fine again.

Is there something that needs to be cleared or reset before the same .uml model is deserialized for a second time ?
Re: stereotypes not found on model reload [message #1273086 is a reply to message #1272946] Wed, 19 March 2014 13:22 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi,

When the same model is loaded again, is it loaded in a different
ResourceSet than the first time? If so, was it unloaded in the first
resource set? And were the profiles also unloaded in that first
resource set?

Because the CacheAdapter is a static singleton and maintains references
(for indexing of non-navigable inverse references, such as the
stereotypes' metaclass extensions) to every UML model element that is
loaded, is it important always to unload every resource in the
ResourceSet when you have finished with that ResourceSet. Otherwise,
it and all of its contents will leak.

I suspect that something cached in the CacheAdapter from the first copy
of the model is interfering with the inverse-reference searches in the
second copy when looking for applied stereotypes. Or else the dynamic
EPackage definitions of the profiles are not being resolved properly
the second time.

This is all guesswork, as you haven't provided many clues as to what
may be going wrong. You can step through the
getAppliedStereotypes(Element) or getStereotypeApplications(Element)
method of the ElementOperations class (depending on which your
application uses) in the debugger to see whether the problem is that

(a) inverse references from stereotype applications are not being found, or
(b) stereotype applications are not traceable to stereotypes

and why (step through the getStereotype(EObject) method and its call
tree to diagnose the latter case).

In any case, the only thing connected with the first time loading your
model that can reasonably be expected to interfere with the second time
is the CacheAdapter, because it is shared globally. So, I expect that
careful unloading should fix your problem.

HTH,

Christian


On 2014-03-19 06:19:30 +0000, Andrew Miga said:

> We are working on an application which transforms UML behavior diagrams
> annotated with MARTE stereotypes into another EMF model. The
> application deserializes a .uml file (located in a directory with many
> supporting *.profile.uml files) into UML objects and then converts the
> MARTE annotated diagrams into another model. At many points MARTE
> stereotype tags and values which are attached to various diagram
> elements are successfully read.
>
> Everything works fine the first time a specific .uml model is
> transformed. The file is deserialized into a UML object model and the
> attached stereotypes are successfully read. However the second time the
> same .uml model file is transformed no stereotypes of any kind are
> found. The UML objects themselves are created but attached stereotypes
> can't be found. If the application is restarted the everything works
> fine again.
>
> Is there something that needs to be cleared or reset before the same
> .uml model is deserialized for a second time ?
>
Re: stereotypes not found on model reload [message #1273832 is a reply to message #1273086] Thu, 20 March 2014 15:57 Go to previous messageGo to next message
Andrew Miga is currently offline Andrew MigaFriend
Messages: 10
Registered: August 2009
Junior Member
This was the problem and it has been fixed. I was actually using the same ResourceSet each time but wasn't unloading the UML model resource from it as I didn't know it was necessary, and didn't know how.

I now initialize the resource pointer to null and if it is non-null when the user attempts to transform the next model I explicitly unload the existing resource and remove it from the ResourceSet.

static UMLResource modelResource = null;

if( modelResource != null ) { // unload previous resource if existing
modelResource.unload();
resourceSet.getResources().remove( modelResource );
}

try {
modelResource = (UMLResource) resourceSet.createResource( fileURI );
modelResource.load( Collections.EMPTY_MAP );
EcoreUtil.resolveAll( modelResource );

} catch (IOException ioe) {

This has solved the problem. There are no more stereotype reading errors the second time with the same model. I can now transform the same model numerous times sequentially and get the exact same output as expected. Thank you very much for your help.

Re: stereotypes not found on model reload [message #1276754 is a reply to message #1272946] Tue, 25 March 2014 01:28 Go to previous messageGo to next message
Andrew Miga is currently offline Andrew MigaFriend
Messages: 10
Registered: August 2009
Junior Member
In an update to my previous reply I have found it necessary to unload all resources from the resource set with the following loop. The code for the loop was from a forum email.


if( modelResource != null ) { // unload previous resources if existing
// unload every resource in the resourceSet including profiles
for (Iterator<Resource> i = resourceSet.getResources().iterator(); i.hasNext()Wink {
Resource current = (Resource) i.next();
current.unload();
i.remove();
}
}
Re: stereotypes not found on model reload [message #1277041 is a reply to message #1276754] Tue, 25 March 2014 11:55 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Yep, you'll find that in every UML-based application. :-) It's
essential to preventing memory leaks.

Cheers,

Christian


On 2014-03-25 01:28:04 +0000, Andrew Miga said:

> In an update to my previous reply I have found it necessary to unload
> all resources from the resource set with the following loop. The code
> for the loop was from a forum email.
>
>
> if( modelResource != null ) { // unload previous resources if existing
> // unload every resource in the resourceSet including profiles
> for (Iterator<Resource> i = resourceSet.getResources().iterator();
> i.hasNext();) {
> Resource current = (Resource) i.next();
> current.unload();
> i.remove();
> }
> }
Previous Topic:How to get diagram information from XMI2.1 file exported by Enterprise Architect
Next Topic:Retrieving applied stereotypes
Goto Forum:
  


Current Time: Thu Apr 18 08:48:36 GMT 2024

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

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

Back to the top