Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » missing MARTE stereotypes with deserialized UML2 models
missing MARTE stereotypes with deserialized UML2 models [message #628448] Fri, 14 May 2010 14:05
Andrew Miga is currently offline Andrew Miga
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 definitely has stereotypes.

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.

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>


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);
}
Previous Topic:[newbie] Basic Types in UML
Next Topic:problems with undo on setting default value for a paremeter
Goto Forum:
  


Current Time: Tue Jul 29 04:59:41 EDT 2014

Powered by FUDForum. Page generated in 0.03508 seconds