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 |
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 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 |
Kenn Hussey 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 #628466 is a reply to message #533616] |
Tue, 25 May 2010 20:15 |
Kenn Hussey 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);
> }
>
>
|
|
| | |
Goto Forum:
Current Time: Sat May 04 12:26:27 GMT 2024
Powered by FUDForum. Page generated in 0.03309 seconds
|