How to deal with imported packages [message #722253] |
Mon, 05 September 2011 07:19 |
Carlos Hernandez Messages: 3 Registered: September 2011 |
Junior Member |
|
|
Hi,
I'm completely new to uml2 and I'm trying to code a standalone app for reading and writing a model. I have developed the model in IBM RSA and then have the .emx file exported as .uml, but since my model has a package import relationship to another, I got 2 .uml files.
How should I load them? I have been able to load one, but then I cannot read the elements that are imported from the other model/package.
Thank you in advance for any help
Here is the relevant code I use:
// main function I use for loading a model/package
public static Package load(URI uri) {
org.eclipse.uml2.uml.Package package_ = null;
registerPathmaps();
registerPackages();
registerResourceFactories();
try {
RESOURCE_SET.getResource(uri, true);
} catch (WrappedException we) {
System.err.println(we.getMessage());
System.exit(1);
}
EList<Resource> resources = RESOURCE_SET.getResources();
EcoreUtil.resolveAll(resources.get(0));
package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
.getObjectByType(resources.get(0).getContents(),
UMLPackage.Literals.PACKAGE);
return package_;
}
protected static void registerPathmaps() {
String umlResourcePath = "/home/chcorbato/IBM/SDPShared/plugins/org.eclipse.uml2.uml.resources_3.1.0.v201005031530.jar";
URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
+ "!/");
URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
umlResourcePluginURI.appendSegment("libraries").appendSegment(""));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
umlResourcePluginURI.appendSegment("metamodels").appendSegment(""));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
umlResourcePluginURI.appendSegment("profiles").appendSegment(""));
}
protected static void registerPackages() {
Registry packageRegistry = RESOURCE_SET.getPackageRegistry();
packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
}
protected static void registerResourceFactories() {
Map<String, Object> extensionFactoryMap = Resource.Factory.Registry.INSTANCE
.getExtensionToFactoryMap();
extensionFactoryMap.put( UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
}
|
|
|
|
|
|
Re: How to deal with imported packages [message #722753 is a reply to message #722253] |
Tue, 06 September 2011 15:24 |
Ed Merks Messages: 33133 Registered: July 2009 |
Senior Member |
|
|
Carlos,
What are you passing in for the uri value of your load method? The most
common reason for cross resource references to fail to resolve is not
using an absolute URI, e.g., file:/<absolute-path>.
On 05/09/2011 12:19 AM, Carlos Hernandez wrote:
> Hi,
>
> I'm completely new to uml2 and I'm trying to code a standalone app for
> reading and writing a model. I have developed the model in IBM RSA and
> then have the .emx file exported as .uml, but since my model has a
> package import relationship to another, I got 2 .uml files.
>
> How should I load them? I have been able to load one, but then I
> cannot read the elements that are imported from the other model/package.
>
> Thank you in advance for any help
>
>
> Here is the relevant code I use:
>
>
> // main function I use for loading a model/package
> public static Package load(URI uri) {
> org.eclipse.uml2.uml.Package package_ = null;
>
> registerPathmaps();
> registerPackages();
> registerResourceFactories();
>
> try {
> RESOURCE_SET.getResource(uri, true);
> } catch (WrappedException we) {
> System.err.println(we.getMessage());
> System.exit(1);
> }
>
> EList<Resource> resources = RESOURCE_SET.getResources();
> EcoreUtil.resolveAll(resources.get(0));
>
> package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
> .getObjectByType(resources.get(0).getContents(),
> UMLPackage.Literals.PACKAGE);
>
> return package_;
> }
>
> protected static void registerPathmaps() {
>
> String umlResourcePath =
> "/home/chcorbato/IBM/SDPShared/plugins/org.eclipse.uml2.uml.resources_3.1.0.v201005031530.jar";
> URI umlResourcePluginURI = URI.createURI("jar:file:/" +
> umlResourcePath
> + "!/");
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>
> umlResourcePluginURI.appendSegment("libraries").appendSegment(""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>
> umlResourcePluginURI.appendSegment("metamodels").appendSegment(""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>
> umlResourcePluginURI.appendSegment("profiles").appendSegment(""));
>
> }
>
> protected static void registerPackages() {
> Registry packageRegistry = RESOURCE_SET.getPackageRegistry();
> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
> }
>
> protected static void registerResourceFactories() {
> Map<String, Object> extensionFactoryMap =
> Resource.Factory.Registry.INSTANCE
> .getExtensionToFactoryMap();
>
> extensionFactoryMap.put( UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> }
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to deal with imported packages [message #722842 is a reply to message #722747] |
Tue, 06 September 2011 22:17 |
Carlos Hernandez Messages: 3 Registered: September 2011 |
Junior Member |
|
|
Thank you very much Ed, I wasn't building the URI properly and the references didn't got resolved for that cause as you guessed.
I used
load(URI.createURI(modelpath ))
where modelpath is a string with the absolute path of the file in my machine
I changed to
load(URI.createURI("file:/" + modelpath ))
and now references are resolved
Thanks to you too, Vlad, were the case that references weren't resolved this way I could have used your idea to load both models and then substitute the object ill formed as the imported package by the actual model that is imported, and hopefully the IDs will have maintained the consistency.
[Updated on: Tue, 06 September 2011 22:19] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02551 seconds