Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to deal with imported packages(reading the elements in a package that has an imported package)
How to deal with imported packages [message #722253] Mon, 05 September 2011 07:19 Go to next message
Carlos Hernandez is currently offline 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 #722606 is a reply to message #722253] Tue, 06 September 2011 10:21 Go to previous messageGo to next message
Vlad Varnica is currently offline Vlad Varnica
Messages: 546
Registered: July 2009
Location: Milton Keynes - UK
Senior Member
You have two kind of models in UML.
RSA and Omondo has one single model for the entire application.
The structure is:
Model name :
- Package 1
- Package 2
etc....
Open source tools are using multiple models for the entire project. As soon as you have more than one package or diagrams then you usually have more than one model.

What is possible is to merge all these open source tools models inside a larger RSA or Omondo model but not you can not merge a large model from RSA or Omondo and split them into multiple models

I think that a large model and creating views from this model is a better approach but there is no OMG rule on this model subject therefore each approach is accepted.
Re: How to deal with imported packages [message #722617 is a reply to message #722606] Tue, 06 September 2011 10:46 Go to previous messageGo to next message
Carlos Hernandez is currently offline Carlos Hernandez
Messages: 3
Registered: September 2011
Junior Member
Thank you Vlad, but I think I didn't explain my problem properly:
I have a RSA model (.emx file) that contains that model my application. It has an import relationship to another RSA model package that contains domain elements. Typically my application elements have generalization relationships to the domain elements.

Given this context, I'm building an application that reads my application model using the UML2 java API. I was able to do that properly loading the application model (.emx file) with the RSA plug-in libraries, and from them accessing also the domain elements. However I need my program to be a stand alone app, so now I'm using just the UML2 java api, so I exported my application model to an .uml file. That resulted into two uml. files, the second one accounting for the import of the domain model.

Now I can access programmatically the application elements, but following the generalization relationships from them I cannot access the properties of the domain elements.

I suppose I have to do something when I load the application model so that the relationships to the domain model are resolved and thus can be later accessed. Something similar to the instructions when a uml model has a profile applied, but so far I have not achieved any results when trying. Any help or insight on how to solve this issue is really welcomed.
Re: How to deal with imported packages [message #722747 is a reply to message #722617] Tue, 06 September 2011 15:46 Go to previous messageGo to next message
Vlad Varnica is currently offline Vlad Varnica
Messages: 546
Registered: July 2009
Location: Milton Keynes - UK
Senior Member
You can create a model and two sub RSA models at the root of the model.
At the model creation each UML element get a number called ID therefore if relation between two models it was automatically detected.

It would do the job because I had the same problem and I was able to merge two RSA EMX model with other Papyrus and Topcased models into a single model/
I mean that in my test I add a single model and at the root of it the other models.
I don't know which method to call because I am an end user modeler and not a developer.
Sorry if I can not help you but be sure that what you are looking for is possible using the model IDs.
Re: How to deal with imported packages [message #722753 is a reply to message #722253] Tue, 06 September 2011 15:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26152
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);
> }
>
>
Re: How to deal with imported packages [message #722842 is a reply to message #722747] Tue, 06 September 2011 22:17 Go to previous message
Carlos Hernandez is currently offline 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

Previous Topic:How to apply stereotypes to programmatically generated elements
Next Topic:Class attribute multiplicity property in class diagram designer
Goto Forum:
  


Current Time: Fri Oct 31 20:53:19 GMT 2014

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

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