Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » loading serialized UML2 models standalone(unable to recognize stereotypes contained in model)
loading serialized UML2 models standalone [message #533616] Fri, 14 May 2010 18:05 Go to next message
Andrew Miga is currently offline Andrew MigaFriend
Messages: 10
Registered: August 2009
Junior Member
I am trying to load serialized xmi UML2 models with numerous MARTE profile files. I am able to deserialize the files and create org.eclipse.uml2.uml Model and Profile objects. However when I apply the profiles to the model there are no stereotypes found. The example I am using has stereotypes which are visible when I open the model file in Eclipse tree view. The model .uml file and .profile.uml files were all exported from Rational RSA.

I am trying to do it programmatically standalone as I need handles to org.eclipse.uml2.uml.Model objects ( with stereotypes applied ) in memory for further processing.

Alternatively could someone please tell me how to use the UML2 plugin to load model files with profiles programmatically and obtain handles to model objects in memory.

I have removed most of the debugging code from the code which follows to make it more compact. The following debug output shows that no stereotypes were found with the loading process.

modelProfiles: [null, Default, Deployment, GQAM, RUPAnalysis, PAM, GRM, VSL, SRM, RSM, NFPs, HRM]

The stereotypes aren't being recognized when loading standalone. I am new to UML2 and fairly new to Eclipse and don't know how to properly apply UML profiles to UML Model objects. Any help would be appreciated.


simplified code:

static ResourceSet resourceSet = new ResourceSetImpl();
static Vector<String> modelProfiles = new Vector<String>();
static Vector<Profile> modelProfileObjects = new Vector<Profile>();
static Map<String, Profile> profileList = new HashMap<String, Profile>();
static UMLResource modelResource;

public static void main(String[] args) {

Model umlModel = null;
Profile umlProfile = null;

String filePath = "/home/CSM/models/example1.uml";

File inputFile = new File( filePath );
File inputDirectory = new File( inputFile.getParent() );

FilenameFilter filter = new FilenameFilter() {
public boolean accept( File dir, String name ) {
if( name.endsWith( ".profile.xmi" ) )
return true;
else if( name.endsWith( ".profile.uml" ) )
return true;
else
return false;
}
};

File [] profileFiles = inputDirectory.listFiles( filter );

try{
umlModel = loadModel( inputFile );
}
catch(Exception e){
System.err.println( "umlModel load failed. Error:" + e.getLocalizedMessage() + " Exiting." );
e.printStackTrace();
System.exit(1);
}

if( umlModel == null ){
System.err.println( "\numlModel is null. Exiting.\n" );
System.exit(1);
} else {
System.out.println( "\nFile \"" + filePath + "\" has been succesfully loaded.\n" );
System.out.println( "model.getAppliedProfiles() = " + umlModel.getAppliedProfiles());

}

// load profile files

for( File profileFile : profileFiles ) {
try {
umlProfile = loadProfile( profileFile );
} catch (IOException e) {
System.err.println( "umlProfile load failed. Error:" + e.getLocalizedMessage() );
System.err.println( "\nProfile file \"" + profileFile + "\" could not be loaded.\n" );
e.printStackTrace();
}

if( umlProfile == null ){
System.err.println( "\nProfile file \"" + profileFile + "\" could not be loaded.\n" );
} else {
System.out.println( "\nProfile file \"" + profileFile + "\" has been succesfully loaded." );
System.out.println( "Profile name: " + umlProfile.getQualifiedName() );

if( modelProfiles.contains( umlProfile.getQualifiedName())) {
if( !umlModel.isProfileApplied( umlProfile ) ) {
modelProfileObjects.add( umlProfile );

}
}
}

EcoreUtil.resolveAll( resourceSet );
EcoreUtil.resolveAll( umlModel );

for( Profile cp : modelProfileObjects ) {
EcoreUtil.resolveAll( cp );
}

for( Profile cp : modelProfileObjects ) {
umlModel.applyProfile( cp );
}

private static Model loadModel( File modelFile ) throws IOException
{
Model umlModel = null;
URI fileURI = URI.createFileURI( modelFile.getAbsolutePath() );


String umlResourcePath = " /usr/local/eclipse/plugins/org.eclipse.uml2.uml.resources_3. 0.0.v200906011111.jar ";
URI umlResourcePluginURI = URI.createURI( "jar:file:/" + umlResourcePath + "!/" );

registerPathmaps( resourceSet, umlResourcePluginURI );
registerPackages( resourceSet );
registerExtensions( resourceSet );

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

} catch (IOException ioe) {
System.err.println( ioe.toString() );
throw ioe;
}

EList<EObject> content = modelResource.getContents();


if ( content.get(0) instanceof Model ) {
umlModel = (Model) content.get(0);
EcoreUtil.resolveAll( umlModel );
for( Profile p : umlModel.getAppliedProfiles() )
modelProfiles.add( p.getQualifiedName() );
}

System.out.println( "\nmodelProfiles: " + modelProfiles.toString() );
return umlModel;
}

private static Profile loadProfile( File profileFile ) throws IOException
{
UMLResource resource;
Profile umlProfile = null;
org.eclipse.uml2.uml.Package umlPackage = null;
URI profileURI = URI.createFileURI( profileFile.getAbsolutePath() );

try {
resource = (UMLResource) resourceSet.createResource( profileURI );
resource.load( Collections.EMPTY_MAP );
EcoreUtil.resolveAll( resource );

} catch (IOException ioe) {
System.err.println( ioe.toString() );
throw ioe;
}

EList<EObject> content = resource.getContents();

if( content.get(0) instanceof Profile ) {
umlProfile = (Profile) content.get(0);
if( !umlProfile.isDefined() )
umlProfile.define();
profileList.put( umlProfile.getQualifiedName(), umlProfile );
}

return umlProfile;
}

private static void registerPathmaps( ResourceSet resourceSet, URI umlResourcePluginURI )
{
Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
uriMap.put(URI.createURI( UMLResource.LIBRARIES_PATHMAP), umlResourcePluginURI.appendSegment("libraries").appendSegment( "") );
uriMap.put(URI.createURI( UMLResource.METAMODELS_PATHMAP), umlResourcePluginURI.appendSegment("metamodels").appendSegment( "") );
uriMap.put(URI.createURI( UMLResource.PROFILES_PATHMAP), umlResourcePluginURI.appendSegment("profiles").appendSegment( "") );
}

private static void registerExtensions( ResourceSet resourceSet )
{
Map<String, Object> extensionFactoryMap = resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap();
extensionFactoryMap.put( UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE );
extensionFactoryMap.put( UMLResource.PROFILE_FILE_EXTENSION, UMLResource.Factory.INSTANCE );
extensionFactoryMap.put( "xmi", XMI2UMLResource.Factory.INSTANCE );
extensionFactoryMap.put( "profile.xmi", XMI2UMLResource.Factory.INSTANCE );
}

private static void registerPackages( ResourceSet resourceSet )
{
resourceSet.getPackageRegistry().put( UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
resourceSet.getPackageRegistry().put( "http://www.eclipse.org/uml2/2.0.0/UML", UMLPackage.eINSTANCE);
}

Thank you for your help.

[Updated on: Wed, 26 May 2010 03:25]

Report message to a moderator

Re: missing MARTE stereotypes with deserialized UML2 models [message #535827 is a reply to message #533616] Tue, 25 May 2010 20:15 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Andrew,

Is it possible that the profiles you are trying to load are based on an
older version of the UML2 API? If so, you'll need to make a few more
resource factory registrations so that the proper migration is done
during load. I would suggest trying to get the files to load properly
using the sample editor and then, if/when that works, try to get it
working programmatically.

More comments, in-line, below.

Kenn

Andrew Miga wrote:
> I am trying to load serialized xmi UML2 models with numerous MARTE
> profile files. I am able to deserialize the files and create
> org.eclipse.uml2.uml Model and Profile objects. However when I apply the
> profiles to the model there are no stereotypes found. The example I am
> using definitely has stereotypes.

Note that one would only expect to see stereotypes automatically applied
to a model upon applying a profile iff the profile contains required
stereotypes... is this the case?

>
> I have removed most of the debugging code from the code which follows to
> make it more compact. The following debug output shows that no
> stereotypes were found although the loaded profiles have many other
> owned elements.

The stereotypes may well be found, but it's possible that their Ecore
metadata (the Ecore representation of them that's needed in order to
apply them) could not be found/resolved...

>
> modelProfiles: [null, Default, Deployment, GQAM, RUPAnalysis, PAM, GRM,
> VSL, SRM, RSM, NFPs, HRM]
>
> Applying profile "GRM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 51
> Applying profile "PAM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 19
> Applying profile "NFPs" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 18
> Applying profile "Deployment" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 40
> Applying profile "GQAM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 54
> Applying profile "VSL" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 26
> Applying profile "SRM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 104
> Applying profile "Default" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 15
> Applying profile "RSM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 17
> Applying profile "HRM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 72
> Applying profile "RUPAnalysis" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 8
> model.getApplicableStereotypes() = []
>
> The example model I am using is from the MARTE package and has
> stereotypes such as the following. My loading process just does not find
> them.
>
> <GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q"
> base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">
> <blockT xmi:id="_eAhvll8IEd-UUY3lkMJH9Q" value="(10,ms)"/>
> </GQAM:GaCommHost>
> <GQAM:GaExecHost xmi:id="_eAhvl18IEd-UUY3lkMJH9Q"
> base_Classifier="_eAhvSF8IEd-UUY3lkMJH9Q">
> <resMult xmi:id="_eAhvmF8IEd-UUY3lkMJH9Q" value="5"/>
> <commTxOvh xmi:id="_eAhvmV8IEd-UUY3lkMJH9Q" value="(0.1,ms/KB)"/>
> <commRcvOvh xmi:id="_eAhvml8IEd-UUY3lkMJH9Q" value="(0.15,ms/KB)"/>
> </GQAM:GaExecHost>
>

Can you trace the XMI types of these elements back to their (Ecore)
definitions in the profiles?

>
> simplified code:
>
> static ResourceSet resourceSet = new ResourceSetImpl();
> static Vector<String> modelProfiles = new Vector<String>();
> static Vector<Profile> modelProfileObjects = new Vector<Profile>();
> static Map<String, Profile> profileList = new HashMap<String,
> Profile>();
> static UMLResource modelResource;
>
> public static void main(String[] args) {
>
> Model umlModel = null;
> Profile umlProfile = null;
>
> String filePath = "/home/CSM/models/example1.uml";
>
> File inputFile = new File( filePath );
> File inputDirectory = new File( inputFile.getParent() );
>
> FilenameFilter filter = new FilenameFilter() {
> public boolean accept( File dir, String name ) {
> if( name.endsWith( ".profile.xmi" ) )
> return true;
> else if( name.endsWith( ".profile.uml" ) )
> return true;
> else if( name.endsWith( ".profile.uml2" ) )
> return true;
> else
> return false; }
> };
> File [] profileFiles = inputDirectory.listFiles( filter );
>
> try{
> umlModel = loadModel( inputFile );
> }
> catch(Exception e){
> System.err.println( "umlModel load failed. Error:" +
> e.getLocalizedMessage() + " Exiting." );
> e.printStackTrace();
> System.exit(1);
> }
>
> if( umlModel == null ){
> System.err.println( "\numlModel is null. Exiting.\n" );
> System.exit(1);
> } else {
> System.out.println( "\nFile \"" + filePath + "\" has been
> succesfully loaded.\n" );
> System.out.println( "model.getAppliedProfiles() = " +
> umlModel.getAppliedProfiles());
>
> }
>
> // load profile files
>
> for( File profileFile : profileFiles ) {
> try {
> umlProfile = loadProfile( profileFile );
> } catch (IOException e) {
> System.err.println( "umlProfile load failed. Error:" +
> e.getLocalizedMessage() );
> System.err.println( "\nProfile file \"" + profileFile +
> "\" could not be loaded.\n" );
> e.printStackTrace();
> }
>
> if( umlProfile == null ){
> System.err.println( "\nProfile file \"" + profileFile +
> "\" could not be loaded.\n" );
> } else {
> System.out.println( "\nProfile file \"" + profileFile +
> "\" has been succesfully loaded." );
> System.out.println( "Profile name: " +
> umlProfile.getQualifiedName() );
>
> if( modelProfiles.contains(
> umlProfile.getQualifiedName())) {
> if( !umlModel.isProfileApplied( umlProfile ) ) {
> modelProfileObjects.add( umlProfile );
>
> } }
> }
>
> EcoreUtil.resolveAll( resourceSet );
> EcoreUtil.resolveAll( umlModel );
>
> for( Profile cp : modelProfileObjects ) {
> EcoreUtil.resolveAll( cp );
> }
>
> for( Profile cp : modelProfileObjects ) {
> umlModel.applyProfile( cp );
> }
>
> private static Model loadModel( File modelFile ) throws IOException
> {
> Model umlModel = null;
> URI fileURI = URI.createFileURI( modelFile.getAbsolutePath() );
>
>
> String umlResourcePath = "
> /usr/local/eclipse/plugins/org.eclipse.uml2.uml.resources_3.
> 0.0.v200906011111.jar ";
> URI umlResourcePluginURI = URI.createURI( "jar:file:/" +
> umlResourcePath + "!/" );
>
> registerPathmaps( resourceSet, umlResourcePluginURI );
> registerPackages( resourceSet );
> registerExtensions( resourceSet );
>
> try {
> modelResource = (UMLResource) resourceSet.createResource(
> fileURI );
> modelResource.load( Collections.EMPTY_MAP );
> EcoreUtil.resolveAll( modelResource );
>
> } catch (IOException ioe) {
> System.err.println( ioe.toString() );
> throw ioe;
> }
>
> EList<EObject> content = modelResource.getContents();
>
>
> if ( content.get(0) instanceof Model ) {
> umlModel = (Model) content.get(0);
> EcoreUtil.resolveAll( umlModel );
> for( Profile p : umlModel.getAppliedProfiles() )
> modelProfiles.add( p.getQualifiedName() );
> }
>
> System.out.println( "\nmodelProfiles: " +
> modelProfiles.toString() );
> return umlModel;
> }
>
> private static Profile loadProfile( File profileFile ) throws
> IOException
> {
> UMLResource resource;
> Profile umlProfile = null;
> org.eclipse.uml2.uml.Package umlPackage = null;
> URI profileURI = URI.createFileURI(
> profileFile.getAbsolutePath() );
>
> try {
> resource = (UMLResource) resourceSet.createResource(
> profileURI );
> resource.load( Collections.EMPTY_MAP );
> EcoreUtil.resolveAll( resource );
>
> } catch (IOException ioe) {
> System.err.println( ioe.toString() );
> throw ioe;
> }
>
> EList<EObject> content = resource.getContents();
>
> if( content.get(0) instanceof Profile ) {
> umlProfile = (Profile) content.get(0);
> if( !umlProfile.isDefined() )
> umlProfile.define();
> profileList.put( umlProfile.getQualifiedName(), umlProfile );
> }
>
> return umlProfile;
> }
>
> private static void registerPathmaps( ResourceSet resourceSet, URI
> umlResourcePluginURI )
> {
> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
> uriMap.put(URI.createURI( UMLResource.LIBRARIES_PATHMAP),
> umlResourcePluginURI.appendSegment("libraries").appendSegment( "") );
> uriMap.put(URI.createURI( UMLResource.METAMODELS_PATHMAP),
> umlResourcePluginURI.appendSegment("metamodels").appendSegment( "") );
> uriMap.put(URI.createURI( UMLResource.PROFILES_PATHMAP),
> umlResourcePluginURI.appendSegment("profiles").appendSegment( "") );
> }
>
> private static void registerExtensions( ResourceSet resourceSet )
> {
> Map<String, Object> extensionFactoryMap =
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap();
> extensionFactoryMap.put( UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE );
> extensionFactoryMap.put( "uml2", UMLResource.Factory.INSTANCE );
> extensionFactoryMap.put( "uml", UMLResource.Factory.INSTANCE );
> extensionFactoryMap.put( "xmi", UMLResource.Factory.INSTANCE );
> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
> XMI2UMLResource.Factory.INSTANCE);
> }
>
> private static void registerPackages( ResourceSet resourceSet )
> {
> resourceSet.getPackageRegistry().put( EcorePackage.eNS_URI,
> EcorePackage.eINSTANCE);
> resourceSet.getPackageRegistry().put( UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
> resourceSet.getPackageRegistry().put( Ecore2XMLPackage.eNS_URI,
> Ecore2XMLPackage.eINSTANCE );
> resourceSet.getPackageRegistry().put(
> "http://www.eclipse.org/uml2/2.0.0/UML", UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http://schema.omg.org/spec/UML/2.1",
> UMLPackage.eINSTANCE);
> }
>
>
Re: missing MARTE stereotypes with deserialized UML2 models [message #535849 is a reply to message #535827] Wed, 26 May 2010 01:31 Go to previous messageGo to next message
Andrew Miga is currently offline Andrew MigaFriend
Messages: 10
Registered: August 2009
Junior Member
Hello Kenn,

I have managed to get this working in the last day or so before I read your reply. Explaining what was wrong is complex. It was several small errors and incorrect assumptions that confused me.

First of all I didn't mention it in my original message but I was using two models, one with a .xmi extension. I realized i need to use

extensionFactoryMap.put( "xmi", XMI2UMLResource.Factory.INSTANCE );

for UML2 files in xmi format. If you use the UMLResource factory it loads but incorrectly with stereotypes not found.

The second error was that I didn't realize how stereotypes were stored. The debugging code I was using was something I got from another forum post. It was looking in all the wrong places for stereotypes. For the .uml model I was using the stereotypes were actually being loaded but as they were attached to elements inside the model they did not output. I have changed the debug code and am now looking deep inside the model for all stereotypes and have found them all.

>Note that one would only expect to see stereotypes automatically applied to a model upon applying a profile iff the profile contains required stereotypes... is this the case?

This is not the case for MARTE profiles and since I am new to UML2 this was a source of confusion. The MARTE models I am using have stereotypes attached to model elements as is expected. I didn't understand how they were stored.

The third confusion resulted from unresolved xmi_ids that pointed to nothing. The load procedure is now working but I still have one unresolved question. I have noticed that the first xmi_id of every stereotype does not point to anything either in its own .uml file or any of the .profile.uml files.

<GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q" base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">
<blockT xmi:id="_eAhvll8IEd-UUY3lkMJH9Q" value="(10,ms)"/>
</GQAM:GaCommHost>

For example:

[andrew@localhost models]$ grep -n _eAhvlV8IEd-UUY3lkMJH9Q *.uml
example1.uml:150: <GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q" base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">

The model file and all of the profiles are in the same directory.

[andrew@localhost models]$ ls *.uml
Default.profile.uml MARTE_Alloc.profile.uml MARTE_HRM.profile.uml MARTE_PAM.profile.uml MARTE_Time.profile.uml RUPAnalysis.profile.uml
Deployment.profile.uml MARTE_GQAM.profile.uml MARTE_InternalMarteLibrary.profile.uml MARTE_RSM.profile.uml MARTE_VSL.profile.uml
example1.uml MARTE_GRM.profile.uml MARTE_NFPs.profile.uml MARTE_SRM.profile.uml ProfileBase.profile.uml

The xmi_id of the stereotype and all stereotypes does not point to anything else. This was leading me to believe that I was missing some files. Is this situation normal ?

Thank you for your help.

Andrew
Re: missing MARTE stereotypes with deserialized UML2 models [message #535858 is a reply to message #535849] Wed, 26 May 2010 04:00 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Andrew,

The "first xmi_id" that you're referring to is actually the identifier
of the XMI element representing the stereotype application itself; in
general, each element in the resource should have its own value for the
xmi:id attribute, so this is expected.

Kenn

Andrew Miga wrote:
> Hello Kenn,
>
> I have managed to get this working in the last day or so before I read
> your reply. Explaining what was wrong is complex. It was several small
> errors and incorrect assumptions that confused me.
> First of all I didn't mention it in my original message but I was using
> two models, one with a .xmi extension. I realized i need to use
>
> extensionFactoryMap.put( "xmi", XMI2UMLResource.Factory.INSTANCE );
>
> for UML2 files in xmi format. If you use the UMLResource factory it
> loads but incorrectly with stereotypes not found.
>
> The second error was that I didn't realize how stereotypes were stored.
> The debugging code I was using was something I got from another forum
> post. It was looking in all the wrong places for stereotypes. For the
> .uml model I was using the stereotypes were actually being loaded but as
> they were attached to elements inside the model they did not output. I
> have changed the debug code and am now looking deep inside the model for
> all stereotypes and have found them all.
>
>> Note that one would only expect to see stereotypes automatically
>> applied to a model upon applying a profile iff the profile contains
>> required stereotypes... is this the case?
>
> This is not the case for MARTE profiles and since I am new to UML2 this
> was a source of confusion. The MARTE models I am using have stereotypes
> attached to model elements as is expected. I didn't understand how they
> were stored.
>
> The third confusion resulted from unresolved xmi_ids that pointed to
> nothing. The load procedure is now working but I still have one
> unresolved question. I have noticed that the first xmi_id of every
> stereotype does not point to anything either in its own .uml file or any
> of the .profile.uml files.
>
> <GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q"
> base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">
> <blockT xmi:id="_eAhvll8IEd-UUY3lkMJH9Q" value="(10,ms)"/>
> </GQAM:GaCommHost>
>
> For example:
>
> [mailto:andrew@localhost models]$ grep -n _eAhvlV8IEd-UUY3lkMJH9Q *.uml
> example1.uml:150: <GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q"
> base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">
>
> The model file and all of the profiles are in the same directory.
>
> [mailto:andrew@localhost models]$ ls *.uml
> Default.profile.uml MARTE_Alloc.profile.uml
> MARTE_HRM.profile.uml MARTE_PAM.profile.uml
> MARTE_Time.profile.uml RUPAnalysis.profile.uml
> Deployment.profile.uml MARTE_GQAM.profile.uml
> MARTE_InternalMarteLibrary.profile.uml MARTE_RSM.profile.uml
> MARTE_VSL.profile.uml
> example1.uml MARTE_GRM.profile.uml
> MARTE_NFPs.profile.uml MARTE_SRM.profile.uml
> ProfileBase.profile.uml
>
> The xmi_id of the stereotype and all stereotypes does not point to
> anything else. This was leading me to believe that I was missing some
> files. Is this situation normal ?
>
> Thank you for your help.
>
> Andrew
Re: missing MARTE stereotypes with deserialized UML2 models [message #628466 is a reply to message #533616] Tue, 25 May 2010 20:15 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Andrew,

Is it possible that the profiles you are trying to load are based on an
older version of the UML2 API? If so, you'll need to make a few more
resource factory registrations so that the proper migration is done
during load. I would suggest trying to get the files to load properly
using the sample editor and then, if/when that works, try to get it
working programmatically.

More comments, in-line, below.

Kenn

Andrew Miga wrote:
> I am trying to load serialized xmi UML2 models with numerous MARTE
> profile files. I am able to deserialize the files and create
> org.eclipse.uml2.uml Model and Profile objects. However when I apply the
> profiles to the model there are no stereotypes found. The example I am
> using definitely has stereotypes.

Note that one would only expect to see stereotypes automatically applied
to a model upon applying a profile iff the profile contains required
stereotypes... is this the case?

>
> I have removed most of the debugging code from the code which follows to
> make it more compact. The following debug output shows that no
> stereotypes were found although the loaded profiles have many other
> owned elements.

The stereotypes may well be found, but it's possible that their Ecore
metadata (the Ecore representation of them that's needed in order to
apply them) could not be found/resolved...

>
> modelProfiles: [null, Default, Deployment, GQAM, RUPAnalysis, PAM, GRM,
> VSL, SRM, RSM, NFPs, HRM]
>
> Applying profile "GRM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 51
> Applying profile "PAM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 19
> Applying profile "NFPs" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 18
> Applying profile "Deployment" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 40
> Applying profile "GQAM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 54
> Applying profile "VSL" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 26
> Applying profile "SRM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 104
> Applying profile "Default" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 15
> Applying profile "RSM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 17
> Applying profile "HRM" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 72
> Applying profile "RUPAnalysis" to loaded Model.
> Stereotype count: 0 cp.getOwnedElements().size(): 8
> model.getApplicableStereotypes() = []
>
> The example model I am using is from the MARTE package and has
> stereotypes such as the following. My loading process just does not find
> them.
>
> <GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q"
> base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">
> <blockT xmi:id="_eAhvll8IEd-UUY3lkMJH9Q" value="(10,ms)"/>
> </GQAM:GaCommHost>
> <GQAM:GaExecHost xmi:id="_eAhvl18IEd-UUY3lkMJH9Q"
> base_Classifier="_eAhvSF8IEd-UUY3lkMJH9Q">
> <resMult xmi:id="_eAhvmF8IEd-UUY3lkMJH9Q" value="5"/>
> <commTxOvh xmi:id="_eAhvmV8IEd-UUY3lkMJH9Q" value="(0.1,ms/KB)"/>
> <commRcvOvh xmi:id="_eAhvml8IEd-UUY3lkMJH9Q" value="(0.15,ms/KB)"/>
> </GQAM:GaExecHost>
>

Can you trace the XMI types of these elements back to their (Ecore)
definitions in the profiles?

>
> simplified code:
>
> static ResourceSet resourceSet = new ResourceSetImpl();
> static Vector<String> modelProfiles = new Vector<String>();
> static Vector<Profile> modelProfileObjects = new Vector<Profile>();
> static Map<String, Profile> profileList = new HashMap<String,
> Profile>();
> static UMLResource modelResource;
>
> public static void main(String[] args) {
>
> Model umlModel = null;
> Profile umlProfile = null;
>
> String filePath = "/home/CSM/models/example1.uml";
>
> File inputFile = new File( filePath );
> File inputDirectory = new File( inputFile.getParent() );
>
> FilenameFilter filter = new FilenameFilter() {
> public boolean accept( File dir, String name ) {
> if( name.endsWith( ".profile.xmi" ) )
> return true;
> else if( name.endsWith( ".profile.uml" ) )
> return true;
> else if( name.endsWith( ".profile.uml2" ) )
> return true;
> else
> return false; }
> };
> File [] profileFiles = inputDirectory.listFiles( filter );
>
> try{
> umlModel = loadModel( inputFile );
> }
> catch(Exception e){
> System.err.println( "umlModel load failed. Error:" +
> e.getLocalizedMessage() + " Exiting." );
> e.printStackTrace();
> System.exit(1);
> }
>
> if( umlModel == null ){
> System.err.println( "\numlModel is null. Exiting.\n" );
> System.exit(1);
> } else {
> System.out.println( "\nFile \"" + filePath + "\" has been
> succesfully loaded.\n" );
> System.out.println( "model.getAppliedProfiles() = " +
> umlModel.getAppliedProfiles());
>
> }
>
> // load profile files
>
> for( File profileFile : profileFiles ) {
> try {
> umlProfile = loadProfile( profileFile );
> } catch (IOException e) {
> System.err.println( "umlProfile load failed. Error:" +
> e.getLocalizedMessage() );
> System.err.println( "\nProfile file \"" + profileFile +
> "\" could not be loaded.\n" );
> e.printStackTrace();
> }
>
> if( umlProfile == null ){
> System.err.println( "\nProfile file \"" + profileFile +
> "\" could not be loaded.\n" );
> } else {
> System.out.println( "\nProfile file \"" + profileFile +
> "\" has been succesfully loaded." );
> System.out.println( "Profile name: " +
> umlProfile.getQualifiedName() );
>
> if( modelProfiles.contains(
> umlProfile.getQualifiedName())) {
> if( !umlModel.isProfileApplied( umlProfile ) ) {
> modelProfileObjects.add( umlProfile );
>
> } }
> }
>
> EcoreUtil.resolveAll( resourceSet );
> EcoreUtil.resolveAll( umlModel );
>
> for( Profile cp : modelProfileObjects ) {
> EcoreUtil.resolveAll( cp );
> }
>
> for( Profile cp : modelProfileObjects ) {
> umlModel.applyProfile( cp );
> }
>
> private static Model loadModel( File modelFile ) throws IOException
> {
> Model umlModel = null;
> URI fileURI = URI.createFileURI( modelFile.getAbsolutePath() );
>
>
> String umlResourcePath = "
> /usr/local/eclipse/plugins/org.eclipse.uml2.uml.resources_3.
> 0.0.v200906011111.jar ";
> URI umlResourcePluginURI = URI.createURI( "jar:file:/" +
> umlResourcePath + "!/" );
>
> registerPathmaps( resourceSet, umlResourcePluginURI );
> registerPackages( resourceSet );
> registerExtensions( resourceSet );
>
> try {
> modelResource = (UMLResource) resourceSet.createResource(
> fileURI );
> modelResource.load( Collections.EMPTY_MAP );
> EcoreUtil.resolveAll( modelResource );
>
> } catch (IOException ioe) {
> System.err.println( ioe.toString() );
> throw ioe;
> }
>
> EList<EObject> content = modelResource.getContents();
>
>
> if ( content.get(0) instanceof Model ) {
> umlModel = (Model) content.get(0);
> EcoreUtil.resolveAll( umlModel );
> for( Profile p : umlModel.getAppliedProfiles() )
> modelProfiles.add( p.getQualifiedName() );
> }
>
> System.out.println( "\nmodelProfiles: " +
> modelProfiles.toString() );
> return umlModel;
> }
>
> private static Profile loadProfile( File profileFile ) throws
> IOException
> {
> UMLResource resource;
> Profile umlProfile = null;
> org.eclipse.uml2.uml.Package umlPackage = null;
> URI profileURI = URI.createFileURI(
> profileFile.getAbsolutePath() );
>
> try {
> resource = (UMLResource) resourceSet.createResource(
> profileURI );
> resource.load( Collections.EMPTY_MAP );
> EcoreUtil.resolveAll( resource );
>
> } catch (IOException ioe) {
> System.err.println( ioe.toString() );
> throw ioe;
> }
>
> EList<EObject> content = resource.getContents();
>
> if( content.get(0) instanceof Profile ) {
> umlProfile = (Profile) content.get(0);
> if( !umlProfile.isDefined() )
> umlProfile.define();
> profileList.put( umlProfile.getQualifiedName(), umlProfile );
> }
>
> return umlProfile;
> }
>
> private static void registerPathmaps( ResourceSet resourceSet, URI
> umlResourcePluginURI )
> {
> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
> uriMap.put(URI.createURI( UMLResource.LIBRARIES_PATHMAP),
> umlResourcePluginURI.appendSegment("libraries").appendSegment( "") );
> uriMap.put(URI.createURI( UMLResource.METAMODELS_PATHMAP),
> umlResourcePluginURI.appendSegment("metamodels").appendSegment( "") );
> uriMap.put(URI.createURI( UMLResource.PROFILES_PATHMAP),
> umlResourcePluginURI.appendSegment("profiles").appendSegment( "") );
> }
>
> private static void registerExtensions( ResourceSet resourceSet )
> {
> Map<String, Object> extensionFactoryMap =
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap();
> extensionFactoryMap.put( UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE );
> extensionFactoryMap.put( "uml2", UMLResource.Factory.INSTANCE );
> extensionFactoryMap.put( "uml", UMLResource.Factory.INSTANCE );
> extensionFactoryMap.put( "xmi", UMLResource.Factory.INSTANCE );
> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
> XMI2UMLResource.Factory.INSTANCE);
> }
>
> private static void registerPackages( ResourceSet resourceSet )
> {
> resourceSet.getPackageRegistry().put( EcorePackage.eNS_URI,
> EcorePackage.eINSTANCE);
> resourceSet.getPackageRegistry().put( UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
> resourceSet.getPackageRegistry().put( Ecore2XMLPackage.eNS_URI,
> Ecore2XMLPackage.eINSTANCE );
> resourceSet.getPackageRegistry().put(
> "http://www.eclipse.org/uml2/2.0.0/UML", UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http://schema.omg.org/spec/UML/2.1",
> UMLPackage.eINSTANCE);
> }
>
>
Re: missing MARTE stereotypes with deserialized UML2 models [message #628467 is a reply to message #535827] Wed, 26 May 2010 01:31 Go to previous message
Andrew Miga is currently offline Andrew MigaFriend
Messages: 10
Registered: August 2009
Junior Member
Hello Kenn,

I have managed to get this working in the last day or so before I read your reply. Explaining what was wrong is complex. It was several small errors and incorrect assumptions that confused me.

First of all I didn't mention it in my original message but I was using two models, one with a .xmi extension. I realized i need to use

extensionFactoryMap.put( "xmi", XMI2UMLResource.Factory.INSTANCE );

for UML2 files in xmi format. If you use the UMLResource factory it loads but incorrectly with stereotypes not found.

The second error was that I didn't realize how stereotypes were stored. The debugging code I was using was something I got from another forum post. It was looking in all the wrong places for stereotypes. For the .uml model I was using the stereotypes were actually being loaded but as they were attached to elements inside the model they did not output. I have changed the debug code and am now looking deep inside the model for all stereotypes and have found them all.

>Note that one would only expect to see stereotypes automatically applied to a model upon applying a profile iff the profile contains required stereotypes... is this the case?

This is not the case for MARTE profiles and since I am new to UML2 this was a source of confusion. The MARTE models I am using have stereotypes attached to model elements as is expected. I didn't understand how they were stored.

The third confusion resulted from unresolved xmi_ids that pointed to nothing. The load procedure is now working but I still have one unresolved question. I have noticed that the first xmi_id of every stereotype does not point to anything either in its own .uml file or any of the .profile.uml files.

<GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q" base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">
<blockT xmi:id="_eAhvll8IEd-UUY3lkMJH9Q" value="(10,ms)"/>
</GQAM:GaCommHost>

For example:

[mailto:andrew@localhost models]$ grep -n _eAhvlV8IEd-UUY3lkMJH9Q *.uml
example1.uml:150: <GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q" base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">

The model file and all of the profiles are in the same directory.

[mailto:andrew@localhost models]$ ls *.uml
Default.profile.uml MARTE_Alloc.profile.uml MARTE_HRM.profile.uml MARTE_PAM.profile.uml MARTE_Time.profile.uml RUPAnalysis.profile.uml
Deployment.profile.uml MARTE_GQAM.profile.uml MARTE_InternalMarteLibrary.profile.uml MARTE_RSM.profile.uml MARTE_VSL.profile.uml
example1.uml MARTE_GRM.profile.uml MARTE_NFPs.profile.uml MARTE_SRM.profile.uml ProfileBase.profile.uml

The xmi_id of the stereotype and all stereotypes does not point to anything else. This was leading me to believe that I was missing some files. Is this situation normal ?

Thank you for your help.

Andrew
Re: missing MARTE stereotypes with deserialized UML2 models [message #628468 is a reply to message #535849] Wed, 26 May 2010 04:00 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Andrew,

The "first xmi_id" that you're referring to is actually the identifier
of the XMI element representing the stereotype application itself; in
general, each element in the resource should have its own value for the
xmi:id attribute, so this is expected.

Kenn

Andrew Miga wrote:
> Hello Kenn,
>
> I have managed to get this working in the last day or so before I read
> your reply. Explaining what was wrong is complex. It was several small
> errors and incorrect assumptions that confused me.
> First of all I didn't mention it in my original message but I was using
> two models, one with a .xmi extension. I realized i need to use
>
> extensionFactoryMap.put( "xmi", XMI2UMLResource.Factory.INSTANCE );
>
> for UML2 files in xmi format. If you use the UMLResource factory it
> loads but incorrectly with stereotypes not found.
>
> The second error was that I didn't realize how stereotypes were stored.
> The debugging code I was using was something I got from another forum
> post. It was looking in all the wrong places for stereotypes. For the
> .uml model I was using the stereotypes were actually being loaded but as
> they were attached to elements inside the model they did not output. I
> have changed the debug code and am now looking deep inside the model for
> all stereotypes and have found them all.
>
>> Note that one would only expect to see stereotypes automatically
>> applied to a model upon applying a profile iff the profile contains
>> required stereotypes... is this the case?
>
> This is not the case for MARTE profiles and since I am new to UML2 this
> was a source of confusion. The MARTE models I am using have stereotypes
> attached to model elements as is expected. I didn't understand how they
> were stored.
>
> The third confusion resulted from unresolved xmi_ids that pointed to
> nothing. The load procedure is now working but I still have one
> unresolved question. I have noticed that the first xmi_id of every
> stereotype does not point to anything either in its own .uml file or any
> of the .profile.uml files.
>
> <GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q"
> base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">
> <blockT xmi:id="_eAhvll8IEd-UUY3lkMJH9Q" value="(10,ms)"/>
> </GQAM:GaCommHost>
>
> For example:
>
> [mailto:andrew@localhost models]$ grep -n _eAhvlV8IEd-UUY3lkMJH9Q *.uml
> example1.uml:150: <GQAM:GaCommHost xmi:id="_eAhvlV8IEd-UUY3lkMJH9Q"
> base_Classifier="_eAhvQl8IEd-UUY3lkMJH9Q">
>
> The model file and all of the profiles are in the same directory.
>
> [mailto:andrew@localhost models]$ ls *.uml
> Default.profile.uml MARTE_Alloc.profile.uml
> MARTE_HRM.profile.uml MARTE_PAM.profile.uml
> MARTE_Time.profile.uml RUPAnalysis.profile.uml
> Deployment.profile.uml MARTE_GQAM.profile.uml
> MARTE_InternalMarteLibrary.profile.uml MARTE_RSM.profile.uml
> MARTE_VSL.profile.uml
> example1.uml MARTE_GRM.profile.uml
> MARTE_NFPs.profile.uml MARTE_SRM.profile.uml
> ProfileBase.profile.uml
>
> The xmi_id of the stereotype and all stereotypes does not point to
> anything else. This was leading me to believe that I was missing some
> files. Is this situation normal ?
>
> Thank you for your help.
>
> Andrew
Previous Topic:Validating an EMF model programatically
Next Topic:Build 3.1 RC2
Goto Forum:
  


Current Time: Thu Apr 25 05:12:36 GMT 2024

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

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

Back to the top