Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » URI.createURI
URI.createURI [message #809015] Tue, 28 February 2012 06:41 Go to next message
Eclipse User
Hello,

here is very newbie question, why we need uri in the following example?

> Map uriMap = resourceSet.getURIConverter().getURIMap();
> URI uri = URI.createURI("jar:file:<path_to_resource_jar_file>/org.eclipse.uml2.uml.resources_<version>.jar!/");
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));

Seems, that <version> here determines which xmi documents i can parse,
for example, if i specify 3.0.0.v200906011111 (and i have
org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar file) i can later
read xmi files which contain

> <xmi:XMI xmi:version="2.1" ... xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">

and not files with xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"

is it possible to "configure" resourceSet, so that it can handle both
xmi files?

honestly, i'm not quite comfortable with all stuff around eclipse uml2,
emf, xmi and maybe also xml

for example i understand, that xmlns:uml defines a namespace, but the
following snipped of code which i have confuses me and i don't
understand it fully:

> private void initializeEditingDomain() {
>
> String path = "lib/xmihandlerjars/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar";
>
> BasicCommandStack commandStack = new BasicCommandStack() {
>
> @Override
> protected void handleError(Exception exception) {
> super.handleError(exception);
> throw new RuntimeException(exception);
> }
>
> };
>
> List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
> factories.add(new UMLResourceItemProviderAdapterFactory());
> factories.add(new UMLItemProviderAdapterFactory());
> factories.add(new EcoreItemProviderAdapterFactory());
> factories.add(new UMLReflectiveItemProviderAdapterFactory());
> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
> factories);
>
> editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
> commandStack);
>
> ResourceSet resourceSet = editingDomain.getResourceSet();
> Map<String, Object> extensionToFactoryMap = resourceSet
> .getResourceFactoryRegistry().getExtensionToFactoryMap();
> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>
> try {
> FileInputStream in = new FileInputStream(path);
> in.close();
> } catch (IOException e) {
> throw (new RuntimeException(e));
> }
>
> path = path.replace('\\', '/');
> URI uri = URI.createURI("jar:file:" + path + "!/");
> Log.debug("eUML.resource URI --> " + uri);
>
> Registry packageRegistry = resourceSet.getPackageRegistry();
> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
> // for other xmi files with further namespaces:
> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_NS_URI,
> UMLPackage.eINSTANCE);
> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_URI,
> UMLPackage.eINSTANCE);
> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_NS_URI,
> UMLPackage.eINSTANCE);
> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_URI,
> UMLPackage.eINSTANCE);
> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_2_NS_URI,
> UMLPackage.eINSTANCE);
> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_NS_URI,
> UMLPackage.eINSTANCE);
> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_URI,
> UMLPackage.eINSTANCE);
> // eclipse namespaces:
> packageRegistry.put(UML212UMLResource.UML_METAMODEL_NS_URI,
> UMLPackage.eINSTANCE);
> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
> UMLPackage.eINSTANCE);
>
> // For the .uml files in the eclipse jar files, we need this:
> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment(
> "libraries").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
> .appendSegment("metamodels").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment(
> "profiles").appendSegment(""));
>
> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
> UML22UMLResource.Factory.INSTANCE);
> extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
> XMI2UMLResource.Factory.INSTANCE);
>
> uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
> uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
> }


in the code above, why we need

> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
> UMLPackage.eINSTANCE);

if namespace http://www.eclipse.org/uml2/3.0.0/UML is already defined
via uri and uriMap?

what is the role of editing domain? Do i need it to just simply parse
xmi files?

i know, questions above are all spontaneous and most likely wrong
formulated, but i'll be very glad if someone help to clarify all that stuff.

thanks in advance!
Re: URI.createURI [message #809042 is a reply to message #809015] Tue, 28 February 2012 07:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4008
Registered: July 2009
Senior Member
Hi Emil

My sympathies; I find it hard too and the support routines are not as
helpful as they might be.

The basic problem is that there are many dramatically different contents
for a *.xmi file, and subtly different contents for a *.uml file.
Whereas for a *.ecore file there is only ever Ecore content, unless you
want to have a really hard time. So for UML, extensions do not define
file content. It is therefore necessary to use content type, so on
encountering an *.xmi file or *.uml file the XML namespace is used to
select the appropriate EMF model handling.

You appear to be using Indigo for which the UML versions have been stuck
at 2.2 for some years. The good/bad news is that in Juno there is
support for UML 2.4 and 2.4.1 so there are now about nine different UML
dialects. Yes, you can (and should) register all at once.

/org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/uml/UMLUtils.java
in the OCL GIT is my attempt to do so.

UML has profiles that allow you to tailor your models, These are
generally shared so it cannot be assumed that they are in a similar
location to the model, so where are they? pathmap:'s give a
reconfigurable indirection which is flexible but also inconvenient
because until they are correctly configured not much works.

A Resource supports usage of one model. A ResourceSet set supports usage
of many models. An EditingDomain supports many models in the context of
an editor and on a good day may be shared across editors and tools so
that when a model is edited in one place everything else updates
accordingly.

UriMap redirects the pathmaps to somewhere useful. Resource registration
facilitates the location of a Resource for loading. Extension and
content registration facilitates the use of appropriate
ResourceFactories to create Resources.

Regards

Ed Willink

On 28/02/2012 11:41, Emil Huseynli wrote:
> Hello,
>
> here is very newbie question, why we need uri in the following example?
>
>> Map uriMap = resourceSet.getURIConverter().getURIMap();
>> URI uri =
>> URI.createURI("jar:file:<path_to_resource_jar_file>/org.eclipse.uml2.uml.resources_<version>.jar!/");
>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>> uri.appendSegment("libraries").appendSegment(""));
>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>> uri.appendSegment("metamodels").appendSegment(""));
>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>> uri.appendSegment("profiles").appendSegment(""));
>
> Seems, that <version> here determines which xmi documents i can parse,
> for example, if i specify 3.0.0.v200906011111 (and i have
> org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar file) i can
> later read xmi files which contain
>
>> <xmi:XMI xmi:version="2.1" ...
>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">
>
> and not files with xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
>
> is it possible to "configure" resourceSet, so that it can handle both
> xmi files?
>
> honestly, i'm not quite comfortable with all stuff around eclipse
> uml2, emf, xmi and maybe also xml
>
> for example i understand, that xmlns:uml defines a namespace, but the
> following snipped of code which i have confuses me and i don't
> understand it fully:
>
>> private void initializeEditingDomain() {
>>
>> String path =
>> "lib/xmihandlerjars/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar";
>>
>> BasicCommandStack commandStack = new BasicCommandStack() {
>>
>> @Override
>> protected void handleError(Exception exception) {
>> super.handleError(exception);
>> throw new RuntimeException(exception);
>> }
>>
>> };
>>
>> List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
>> factories.add(new UMLResourceItemProviderAdapterFactory());
>> factories.add(new UMLItemProviderAdapterFactory());
>> factories.add(new EcoreItemProviderAdapterFactory());
>> factories.add(new UMLReflectiveItemProviderAdapterFactory());
>> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
>> factories);
>>
>> editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
>> commandStack);
>>
>> ResourceSet resourceSet = editingDomain.getResourceSet();
>> Map<String, Object> extensionToFactoryMap = resourceSet
>> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>>
>> try {
>> FileInputStream in = new FileInputStream(path);
>> in.close();
>> } catch (IOException e) {
>> throw (new RuntimeException(e));
>> }
>>
>> path = path.replace('\\', '/');
>> URI uri = URI.createURI("jar:file:" + path + "!/");
>> Log.debug("eUML.resource URI --> " + uri);
>>
>> Registry packageRegistry = resourceSet.getPackageRegistry();
>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>> // for other xmi files with further namespaces:
>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_NS_URI,
>> UMLPackage.eINSTANCE);
>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_URI,
>> UMLPackage.eINSTANCE);
>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_NS_URI,
>> UMLPackage.eINSTANCE);
>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_URI,
>> UMLPackage.eINSTANCE);
>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_2_NS_URI,
>> UMLPackage.eINSTANCE);
>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_NS_URI,
>> UMLPackage.eINSTANCE);
>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_URI,
>> UMLPackage.eINSTANCE);
>> // eclipse namespaces:
>> packageRegistry.put(UML212UMLResource.UML_METAMODEL_NS_URI,
>> UMLPackage.eINSTANCE);
>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>> UMLPackage.eINSTANCE);
>>
>> // For the .uml files in the eclipse jar files, we need this:
>> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
>> UMLResource.Factory.INSTANCE);
>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>> uri.appendSegment(
>> "libraries").appendSegment(""));
>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
>> .appendSegment("metamodels").appendSegment(""));
>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>> uri.appendSegment(
>> "profiles").appendSegment(""));
>>
>> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>> UML22UMLResource.Factory.INSTANCE);
>> extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
>> XMI2UMLResource.Factory.INSTANCE);
>>
>> uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
>> uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
>> }
>
>
> in the code above, why we need
>
>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>> UMLPackage.eINSTANCE);
>
> if namespace http://www.eclipse.org/uml2/3.0.0/UML is already defined
> via uri and uriMap?
>
> what is the role of editing domain? Do i need it to just simply parse
> xmi files?
>
> i know, questions above are all spontaneous and most likely wrong
> formulated, but i'll be very glad if someone help to clarify all that
> stuff.
>
> thanks in advance!
Re: URI.createURI [message #809056 is a reply to message #809042] Tue, 28 February 2012 07:44 Go to previous messageGo to next message
Eclipse User
thanks a lot! i'll take a look at your code

On 28.02.2012 13:26, Ed Willink wrote:
> Hi Emil
>
> My sympathies; I find it hard too and the support routines are not as
> helpful as they might be.
>
> The basic problem is that there are many dramatically different contents
> for a *.xmi file, and subtly different contents for a *.uml file.
> Whereas for a *.ecore file there is only ever Ecore content, unless you
> want to have a really hard time. So for UML, extensions do not define
> file content. It is therefore necessary to use content type, so on
> encountering an *.xmi file or *.uml file the XML namespace is used to
> select the appropriate EMF model handling.
>
> You appear to be using Indigo for which the UML versions have been stuck
> at 2.2 for some years. The good/bad news is that in Juno there is
> support for UML 2.4 and 2.4.1 so there are now about nine different UML
> dialects. Yes, you can (and should) register all at once.
>
> /org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/uml/UMLUtils.java
> in the OCL GIT is my attempt to do so.
>
> UML has profiles that allow you to tailor your models, These are
> generally shared so it cannot be assumed that they are in a similar
> location to the model, so where are they? pathmap:'s give a
> reconfigurable indirection which is flexible but also inconvenient
> because until they are correctly configured not much works.
>
> A Resource supports usage of one model. A ResourceSet set supports usage
> of many models. An EditingDomain supports many models in the context of
> an editor and on a good day may be shared across editors and tools so
> that when a model is edited in one place everything else updates
> accordingly.
>
> UriMap redirects the pathmaps to somewhere useful. Resource registration
> facilitates the location of a Resource for loading. Extension and
> content registration facilitates the use of appropriate
> ResourceFactories to create Resources.
>
> Regards
>
> Ed Willink
>
> On 28/02/2012 11:41, Emil Huseynli wrote:
>> Hello,
>>
>> here is very newbie question, why we need uri in the following example?
>>
>>> Map uriMap = resourceSet.getURIConverter().getURIMap();
>>> URI uri =
>>> URI.createURI("jar:file:<path_to_resource_jar_file>/org.eclipse.uml2.uml.resources_<version>.jar!/");
>>>
>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>> uri.appendSegment("libraries").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>>> uri.appendSegment("metamodels").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>> uri.appendSegment("profiles").appendSegment(""));
>>
>> Seems, that <version> here determines which xmi documents i can parse,
>> for example, if i specify 3.0.0.v200906011111 (and i have
>> org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar file) i can
>> later read xmi files which contain
>>
>>> <xmi:XMI xmi:version="2.1" ...
>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">
>>
>> and not files with xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
>>
>> is it possible to "configure" resourceSet, so that it can handle both
>> xmi files?
>>
>> honestly, i'm not quite comfortable with all stuff around eclipse
>> uml2, emf, xmi and maybe also xml
>>
>> for example i understand, that xmlns:uml defines a namespace, but the
>> following snipped of code which i have confuses me and i don't
>> understand it fully:
>>
>>> private void initializeEditingDomain() {
>>>
>>> String path =
>>> "lib/xmihandlerjars/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar";
>>>
>>>
>>> BasicCommandStack commandStack = new BasicCommandStack() {
>>>
>>> @Override
>>> protected void handleError(Exception exception) {
>>> super.handleError(exception);
>>> throw new RuntimeException(exception);
>>> }
>>>
>>> };
>>>
>>> List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
>>> factories.add(new UMLResourceItemProviderAdapterFactory());
>>> factories.add(new UMLItemProviderAdapterFactory());
>>> factories.add(new EcoreItemProviderAdapterFactory());
>>> factories.add(new UMLReflectiveItemProviderAdapterFactory());
>>> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
>>> factories);
>>>
>>> editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
>>> commandStack);
>>>
>>> ResourceSet resourceSet = editingDomain.getResourceSet();
>>> Map<String, Object> extensionToFactoryMap = resourceSet
>>> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>>> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>>>
>>> try {
>>> FileInputStream in = new FileInputStream(path);
>>> in.close();
>>> } catch (IOException e) {
>>> throw (new RuntimeException(e));
>>> }
>>>
>>> path = path.replace('\\', '/');
>>> URI uri = URI.createURI("jar:file:" + path + "!/");
>>> Log.debug("eUML.resource URI --> " + uri);
>>>
>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>> // for other xmi files with further namespaces:
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_2_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_URI,
>>> UMLPackage.eINSTANCE);
>>> // eclipse namespaces:
>>> packageRegistry.put(UML212UMLResource.UML_METAMODEL_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>> UMLPackage.eINSTANCE);
>>>
>>> // For the .uml files in the eclipse jar files, we need this:
>>> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
>>> UMLResource.Factory.INSTANCE);
>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>> uri.appendSegment(
>>> "libraries").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
>>> .appendSegment("metamodels").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>> uri.appendSegment(
>>> "profiles").appendSegment(""));
>>>
>>> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>> UML22UMLResource.Factory.INSTANCE);
>>> extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
>>> XMI2UMLResource.Factory.INSTANCE);
>>>
>>> uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
>>> uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
>>> }
>>
>>
>> in the code above, why we need
>>
>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>> UMLPackage.eINSTANCE);
>>
>> if namespace http://www.eclipse.org/uml2/3.0.0/UML is already defined
>> via uri and uriMap?
>>
>> what is the role of editing domain? Do i need it to just simply parse
>> xmi files?
>>
>> i know, questions above are all spontaneous and most likely wrong
>> formulated, but i'll be very glad if someone help to clarify all that
>> stuff.
>>
>> thanks in advance!
>
Re: URI.createURI [message #809087 is a reply to message #809042] Tue, 28 February 2012 08:13 Go to previous messageGo to next message
Eclipse User
in UMLUtils.java you use URI.createPlatformPluginURI, does it load all
available jar files with resources? i.e.

org.eclipse.uml2.uml.resources_<version>.jar

where <version> are 3.0.0.v200906011111 or 2.0.0v20080702111 or whatever
else

should i do URI.createURI multiple times for different jar files in
order to support xmi files with different namespaces?

or are the instructions like

packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
UMLPackage.eINSTANCE);

which determine how many different xmi-types will be available?


On 28.02.2012 13:26, Ed Willink wrote:
> Hi Emil
>
> My sympathies; I find it hard too and the support routines are not as
> helpful as they might be.
>
> The basic problem is that there are many dramatically different contents
> for a *.xmi file, and subtly different contents for a *.uml file.
> Whereas for a *.ecore file there is only ever Ecore content, unless you
> want to have a really hard time. So for UML, extensions do not define
> file content. It is therefore necessary to use content type, so on
> encountering an *.xmi file or *.uml file the XML namespace is used to
> select the appropriate EMF model handling.
>
> You appear to be using Indigo for which the UML versions have been stuck
> at 2.2 for some years. The good/bad news is that in Juno there is
> support for UML 2.4 and 2.4.1 so there are now about nine different UML
> dialects. Yes, you can (and should) register all at once.
>
> /org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/uml/UMLUtils.java
> in the OCL GIT is my attempt to do so.
>
> UML has profiles that allow you to tailor your models, These are
> generally shared so it cannot be assumed that they are in a similar
> location to the model, so where are they? pathmap:'s give a
> reconfigurable indirection which is flexible but also inconvenient
> because until they are correctly configured not much works.
>
> A Resource supports usage of one model. A ResourceSet set supports usage
> of many models. An EditingDomain supports many models in the context of
> an editor and on a good day may be shared across editors and tools so
> that when a model is edited in one place everything else updates
> accordingly.
>
> UriMap redirects the pathmaps to somewhere useful. Resource registration
> facilitates the location of a Resource for loading. Extension and
> content registration facilitates the use of appropriate
> ResourceFactories to create Resources.
>
> Regards
>
> Ed Willink
>
> On 28/02/2012 11:41, Emil Huseynli wrote:
>> Hello,
>>
>> here is very newbie question, why we need uri in the following example?
>>
>>> Map uriMap = resourceSet.getURIConverter().getURIMap();
>>> URI uri =
>>> URI.createURI("jar:file:<path_to_resource_jar_file>/org.eclipse.uml2.uml.resources_<version>.jar!/");
>>>
>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>> uri.appendSegment("libraries").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>>> uri.appendSegment("metamodels").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>> uri.appendSegment("profiles").appendSegment(""));
>>
>> Seems, that <version> here determines which xmi documents i can parse,
>> for example, if i specify 3.0.0.v200906011111 (and i have
>> org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar file) i can
>> later read xmi files which contain
>>
>>> <xmi:XMI xmi:version="2.1" ...
>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">
>>
>> and not files with xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
>>
>> is it possible to "configure" resourceSet, so that it can handle both
>> xmi files?
>>
>> honestly, i'm not quite comfortable with all stuff around eclipse
>> uml2, emf, xmi and maybe also xml
>>
>> for example i understand, that xmlns:uml defines a namespace, but the
>> following snipped of code which i have confuses me and i don't
>> understand it fully:
>>
>>> private void initializeEditingDomain() {
>>>
>>> String path =
>>> "lib/xmihandlerjars/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar";
>>>
>>>
>>> BasicCommandStack commandStack = new BasicCommandStack() {
>>>
>>> @Override
>>> protected void handleError(Exception exception) {
>>> super.handleError(exception);
>>> throw new RuntimeException(exception);
>>> }
>>>
>>> };
>>>
>>> List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
>>> factories.add(new UMLResourceItemProviderAdapterFactory());
>>> factories.add(new UMLItemProviderAdapterFactory());
>>> factories.add(new EcoreItemProviderAdapterFactory());
>>> factories.add(new UMLReflectiveItemProviderAdapterFactory());
>>> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
>>> factories);
>>>
>>> editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
>>> commandStack);
>>>
>>> ResourceSet resourceSet = editingDomain.getResourceSet();
>>> Map<String, Object> extensionToFactoryMap = resourceSet
>>> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>>> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>>>
>>> try {
>>> FileInputStream in = new FileInputStream(path);
>>> in.close();
>>> } catch (IOException e) {
>>> throw (new RuntimeException(e));
>>> }
>>>
>>> path = path.replace('\\', '/');
>>> URI uri = URI.createURI("jar:file:" + path + "!/");
>>> Log.debug("eUML.resource URI --> " + uri);
>>>
>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>> // for other xmi files with further namespaces:
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_2_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_URI,
>>> UMLPackage.eINSTANCE);
>>> // eclipse namespaces:
>>> packageRegistry.put(UML212UMLResource.UML_METAMODEL_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>> UMLPackage.eINSTANCE);
>>>
>>> // For the .uml files in the eclipse jar files, we need this:
>>> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
>>> UMLResource.Factory.INSTANCE);
>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>> uri.appendSegment(
>>> "libraries").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
>>> .appendSegment("metamodels").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>> uri.appendSegment(
>>> "profiles").appendSegment(""));
>>>
>>> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>> UML22UMLResource.Factory.INSTANCE);
>>> extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
>>> XMI2UMLResource.Factory.INSTANCE);
>>>
>>> uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
>>> uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
>>> }
>>
>>
>> in the code above, why we need
>>
>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>> UMLPackage.eINSTANCE);
>>
>> if namespace http://www.eclipse.org/uml2/3.0.0/UML is already defined
>> via uri and uriMap?
>>
>> what is the role of editing domain? Do i need it to just simply parse
>> xmi files?
>>
>> i know, questions above are all spontaneous and most likely wrong
>> formulated, but i'll be very glad if someone help to clarify all that
>> stuff.
>>
>> thanks in advance!
>
Re: URI.createURI [message #809099 is a reply to message #809087] Tue, 28 February 2012 08:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4008
Registered: July 2009
Senior Member
Hi

You may need
/org.eclipse.ocl.examples.domain/src/org/eclipse/ocl/examples/domain/utilities/ProjectMap.java
to scan the classpath for all possible JARs.

Regards

Ed Willink


On 28/02/2012 13:13, Emil Huseynli wrote:
> in UMLUtils.java you use URI.createPlatformPluginURI, does it load all
> available jar files with resources? i.e.
>
> org.eclipse.uml2.uml.resources_<version>.jar
>
> where <version> are 3.0.0.v200906011111 or 2.0.0v20080702111 or
> whatever else
>
> should i do URI.createURI multiple times for different jar files in
> order to support xmi files with different namespaces?
>
> or are the instructions like
>
> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
> UMLPackage.eINSTANCE);
>
> which determine how many different xmi-types will be available?
>
>
> On 28.02.2012 13:26, Ed Willink wrote:
>> Hi Emil
>>
>> My sympathies; I find it hard too and the support routines are not as
>> helpful as they might be.
>>
>> The basic problem is that there are many dramatically different contents
>> for a *.xmi file, and subtly different contents for a *.uml file.
>> Whereas for a *.ecore file there is only ever Ecore content, unless you
>> want to have a really hard time. So for UML, extensions do not define
>> file content. It is therefore necessary to use content type, so on
>> encountering an *.xmi file or *.uml file the XML namespace is used to
>> select the appropriate EMF model handling.
>>
>> You appear to be using Indigo for which the UML versions have been stuck
>> at 2.2 for some years. The good/bad news is that in Juno there is
>> support for UML 2.4 and 2.4.1 so there are now about nine different UML
>> dialects. Yes, you can (and should) register all at once.
>>
>> /org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/uml/UMLUtils.java
>>
>> in the OCL GIT is my attempt to do so.
>>
>> UML has profiles that allow you to tailor your models, These are
>> generally shared so it cannot be assumed that they are in a similar
>> location to the model, so where are they? pathmap:'s give a
>> reconfigurable indirection which is flexible but also inconvenient
>> because until they are correctly configured not much works.
>>
>> A Resource supports usage of one model. A ResourceSet set supports usage
>> of many models. An EditingDomain supports many models in the context of
>> an editor and on a good day may be shared across editors and tools so
>> that when a model is edited in one place everything else updates
>> accordingly.
>>
>> UriMap redirects the pathmaps to somewhere useful. Resource registration
>> facilitates the location of a Resource for loading. Extension and
>> content registration facilitates the use of appropriate
>> ResourceFactories to create Resources.
>>
>> Regards
>>
>> Ed Willink
>>
>> On 28/02/2012 11:41, Emil Huseynli wrote:
>>> Hello,
>>>
>>> here is very newbie question, why we need uri in the following example?
>>>
>>>> Map uriMap = resourceSet.getURIConverter().getURIMap();
>>>> URI uri =
>>>> URI.createURI("jar:file:<path_to_resource_jar_file>/org.eclipse.uml2.uml.resources_<version>.jar!/");
>>>>
>>>>
>>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>>> uri.appendSegment("libraries").appendSegment(""));
>>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>>>> uri.appendSegment("metamodels").appendSegment(""));
>>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>>> uri.appendSegment("profiles").appendSegment(""));
>>>
>>> Seems, that <version> here determines which xmi documents i can parse,
>>> for example, if i specify 3.0.0.v200906011111 (and i have
>>> org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar file) i can
>>> later read xmi files which contain
>>>
>>>> <xmi:XMI xmi:version="2.1" ...
>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">
>>>
>>> and not files with xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
>>>
>>> is it possible to "configure" resourceSet, so that it can handle both
>>> xmi files?
>>>
>>> honestly, i'm not quite comfortable with all stuff around eclipse
>>> uml2, emf, xmi and maybe also xml
>>>
>>> for example i understand, that xmlns:uml defines a namespace, but the
>>> following snipped of code which i have confuses me and i don't
>>> understand it fully:
>>>
>>>> private void initializeEditingDomain() {
>>>>
>>>> String path =
>>>> "lib/xmihandlerjars/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar";
>>>>
>>>>
>>>>
>>>> BasicCommandStack commandStack = new BasicCommandStack() {
>>>>
>>>> @Override
>>>> protected void handleError(Exception exception) {
>>>> super.handleError(exception);
>>>> throw new RuntimeException(exception);
>>>> }
>>>>
>>>> };
>>>>
>>>> List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
>>>> factories.add(new UMLResourceItemProviderAdapterFactory());
>>>> factories.add(new UMLItemProviderAdapterFactory());
>>>> factories.add(new EcoreItemProviderAdapterFactory());
>>>> factories.add(new UMLReflectiveItemProviderAdapterFactory());
>>>> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
>>>> factories);
>>>>
>>>> editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
>>>> commandStack);
>>>>
>>>> ResourceSet resourceSet = editingDomain.getResourceSet();
>>>> Map<String, Object> extensionToFactoryMap = resourceSet
>>>> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>>>> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>>>>
>>>> try {
>>>> FileInputStream in = new FileInputStream(path);
>>>> in.close();
>>>> } catch (IOException e) {
>>>> throw (new RuntimeException(e));
>>>> }
>>>>
>>>> path = path.replace('\\', '/');
>>>> URI uri = URI.createURI("jar:file:" + path + "!/");
>>>> Log.debug("eUML.resource URI --> " + uri);
>>>>
>>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>> // for other xmi files with further namespaces:
>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_NS_URI,
>>>> UMLPackage.eINSTANCE);
>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_URI,
>>>> UMLPackage.eINSTANCE);
>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_NS_URI,
>>>> UMLPackage.eINSTANCE);
>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_URI,
>>>> UMLPackage.eINSTANCE);
>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_2_NS_URI,
>>>> UMLPackage.eINSTANCE);
>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_NS_URI,
>>>> UMLPackage.eINSTANCE);
>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_URI,
>>>> UMLPackage.eINSTANCE);
>>>> // eclipse namespaces:
>>>> packageRegistry.put(UML212UMLResource.UML_METAMODEL_NS_URI,
>>>> UMLPackage.eINSTANCE);
>>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>>> UMLPackage.eINSTANCE);
>>>>
>>>> // For the .uml files in the eclipse jar files, we need this:
>>>> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>> UMLResource.Factory.INSTANCE);
>>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>>> uri.appendSegment(
>>>> "libraries").appendSegment(""));
>>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
>>>> .appendSegment("metamodels").appendSegment(""));
>>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>>> uri.appendSegment(
>>>> "profiles").appendSegment(""));
>>>>
>>>> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>> UML22UMLResource.Factory.INSTANCE);
>>>> extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
>>>> XMI2UMLResource.Factory.INSTANCE);
>>>>
>>>> uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
>>>> uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
>>>> }
>>>
>>>
>>> in the code above, why we need
>>>
>>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>>> UMLPackage.eINSTANCE);
>>>
>>> if namespace http://www.eclipse.org/uml2/3.0.0/UML is already defined
>>> via uri and uriMap?
>>>
>>> what is the role of editing domain? Do i need it to just simply parse
>>> xmi files?
>>>
>>> i know, questions above are all spontaneous and most likely wrong
>>> formulated, but i'll be very glad if someone help to clarify all that
>>> stuff.
>>>
>>> thanks in advance!
>>
>
Re: URI.createURI [message #809131 is a reply to message #809099] Tue, 28 February 2012 09:09 Go to previous messageGo to next message
Eclipse User
I'm trying to load resource from standalone application, and one
important thing is not clear:

in order to support different xmi versions, do i need also different
versions of org.eclipse.uml2.uml.resources_<version>.jar ? Or only
latest version and support for different xmi is achieved with following?

> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
> UMLPackage.eINSTANCE);
> packageRegistry.put("http://www.eclipse.org/uml2/2.0.0/UML",
> UMLPackage.eINSTANCE);



On 28.02.2012 14:27, Ed Willink wrote:
> Hi
>
> You may need
> /org.eclipse.ocl.examples.domain/src/org/eclipse/ocl/examples/domain/utilities/ProjectMap.java
> to scan the classpath for all possible JARs.
>
> Regards
>
> Ed Willink
>
>
> On 28/02/2012 13:13, Emil Huseynli wrote:
>> in UMLUtils.java you use URI.createPlatformPluginURI, does it load all
>> available jar files with resources? i.e.
>>
>> org.eclipse.uml2.uml.resources_<version>.jar
>>
>> where <version> are 3.0.0.v200906011111 or 2.0.0v20080702111 or
>> whatever else
>>
>> should i do URI.createURI multiple times for different jar files in
>> order to support xmi files with different namespaces?
>>
>> or are the instructions like
>>
>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>> UMLPackage.eINSTANCE);
>>
>> which determine how many different xmi-types will be available?
>>
>>
>> On 28.02.2012 13:26, Ed Willink wrote:
>>> Hi Emil
>>>
>>> My sympathies; I find it hard too and the support routines are not as
>>> helpful as they might be.
>>>
>>> The basic problem is that there are many dramatically different contents
>>> for a *.xmi file, and subtly different contents for a *.uml file.
>>> Whereas for a *.ecore file there is only ever Ecore content, unless you
>>> want to have a really hard time. So for UML, extensions do not define
>>> file content. It is therefore necessary to use content type, so on
>>> encountering an *.xmi file or *.uml file the XML namespace is used to
>>> select the appropriate EMF model handling.
>>>
>>> You appear to be using Indigo for which the UML versions have been stuck
>>> at 2.2 for some years. The good/bad news is that in Juno there is
>>> support for UML 2.4 and 2.4.1 so there are now about nine different UML
>>> dialects. Yes, you can (and should) register all at once.
>>>
>>> /org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/uml/UMLUtils.java
>>>
>>> in the OCL GIT is my attempt to do so.
>>>
>>> UML has profiles that allow you to tailor your models, These are
>>> generally shared so it cannot be assumed that they are in a similar
>>> location to the model, so where are they? pathmap:'s give a
>>> reconfigurable indirection which is flexible but also inconvenient
>>> because until they are correctly configured not much works.
>>>
>>> A Resource supports usage of one model. A ResourceSet set supports usage
>>> of many models. An EditingDomain supports many models in the context of
>>> an editor and on a good day may be shared across editors and tools so
>>> that when a model is edited in one place everything else updates
>>> accordingly.
>>>
>>> UriMap redirects the pathmaps to somewhere useful. Resource registration
>>> facilitates the location of a Resource for loading. Extension and
>>> content registration facilitates the use of appropriate
>>> ResourceFactories to create Resources.
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>> On 28/02/2012 11:41, Emil Huseynli wrote:
>>>> Hello,
>>>>
>>>> here is very newbie question, why we need uri in the following example?
>>>>
>>>>> Map uriMap = resourceSet.getURIConverter().getURIMap();
>>>>> URI uri =
>>>>> URI.createURI("jar:file:<path_to_resource_jar_file>/org.eclipse.uml2.uml.resources_<version>.jar!/");
>>>>>
>>>>>
>>>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>>>> uri.appendSegment("libraries").appendSegment(""));
>>>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>>>>> uri.appendSegment("metamodels").appendSegment(""));
>>>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>>>> uri.appendSegment("profiles").appendSegment(""));
>>>>
>>>> Seems, that <version> here determines which xmi documents i can parse,
>>>> for example, if i specify 3.0.0.v200906011111 (and i have
>>>> org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar file) i can
>>>> later read xmi files which contain
>>>>
>>>>> <xmi:XMI xmi:version="2.1" ...
>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">
>>>>
>>>> and not files with xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
>>>>
>>>> is it possible to "configure" resourceSet, so that it can handle both
>>>> xmi files?
>>>>
>>>> honestly, i'm not quite comfortable with all stuff around eclipse
>>>> uml2, emf, xmi and maybe also xml
>>>>
>>>> for example i understand, that xmlns:uml defines a namespace, but the
>>>> following snipped of code which i have confuses me and i don't
>>>> understand it fully:
>>>>
>>>>> private void initializeEditingDomain() {
>>>>>
>>>>> String path =
>>>>> "lib/xmihandlerjars/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar";
>>>>>
>>>>>
>>>>>
>>>>> BasicCommandStack commandStack = new BasicCommandStack() {
>>>>>
>>>>> @Override
>>>>> protected void handleError(Exception exception) {
>>>>> super.handleError(exception);
>>>>> throw new RuntimeException(exception);
>>>>> }
>>>>>
>>>>> };
>>>>>
>>>>> List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
>>>>> factories.add(new UMLResourceItemProviderAdapterFactory());
>>>>> factories.add(new UMLItemProviderAdapterFactory());
>>>>> factories.add(new EcoreItemProviderAdapterFactory());
>>>>> factories.add(new UMLReflectiveItemProviderAdapterFactory());
>>>>> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
>>>>> factories);
>>>>>
>>>>> editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
>>>>> commandStack);
>>>>>
>>>>> ResourceSet resourceSet = editingDomain.getResourceSet();
>>>>> Map<String, Object> extensionToFactoryMap = resourceSet
>>>>> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>>>>> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>>>>>
>>>>> try {
>>>>> FileInputStream in = new FileInputStream(path);
>>>>> in.close();
>>>>> } catch (IOException e) {
>>>>> throw (new RuntimeException(e));
>>>>> }
>>>>>
>>>>> path = path.replace('\\', '/');
>>>>> URI uri = URI.createURI("jar:file:" + path + "!/");
>>>>> Log.debug("eUML.resource URI --> " + uri);
>>>>>
>>>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>>> // for other xmi files with further namespaces:
>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_NS_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_NS_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_2_NS_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_NS_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>> // eclipse namespaces:
>>>>> packageRegistry.put(UML212UMLResource.UML_METAMODEL_NS_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>>>> UMLPackage.eINSTANCE);
>>>>>
>>>>> // For the .uml files in the eclipse jar files, we need this:
>>>>> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>>> UMLResource.Factory.INSTANCE);
>>>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>>>> uri.appendSegment(
>>>>> "libraries").appendSegment(""));
>>>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
>>>>> .appendSegment("metamodels").appendSegment(""));
>>>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>>>> uri.appendSegment(
>>>>> "profiles").appendSegment(""));
>>>>>
>>>>> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>>> UML22UMLResource.Factory.INSTANCE);
>>>>> extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
>>>>> XMI2UMLResource.Factory.INSTANCE);
>>>>>
>>>>> uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
>>>>> uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
>>>>> }
>>>>
>>>>
>>>> in the code above, why we need
>>>>
>>>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>>>> UMLPackage.eINSTANCE);
>>>>
>>>> if namespace http://www.eclipse.org/uml2/3.0.0/UML is already defined
>>>> via uri and uriMap?
>>>>
>>>> what is the role of editing domain? Do i need it to just simply parse
>>>> xmi files?
>>>>
>>>> i know, questions above are all spontaneous and most likely wrong
>>>> formulated, but i'll be very glad if someone help to clarify all that
>>>> stuff.
>>>>
>>>> thanks in advance!
>>>
>>
>
Re: URI.createURI [message #809157 is a reply to message #809131] Tue, 28 February 2012 09:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4008
Registered: July 2009
Senior Member
Hi

The latest version should support all UML versions. There is subtle code
in the meta-model loading that enables the one meta-model to support all
dialects.

If you use plugins you should never need to worry about _<version>.

Regards

Ed Willink

On 28/02/2012 14:09, Emil Huseynli wrote:
> I'm trying to load resource from standalone application, and one
> important thing is not clear:
>
> in order to support different xmi versions, do i need also different
> versions of org.eclipse.uml2.uml.resources_<version>.jar ? Or only
> latest version and support for different xmi is achieved with following?
>
>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>> UMLPackage.eINSTANCE);
>> packageRegistry.put("http://www.eclipse.org/uml2/2.0.0/UML",
>> UMLPackage.eINSTANCE);
>
>
>
> On 28.02.2012 14:27, Ed Willink wrote:
>> Hi
>>
>> You may need
>> /org.eclipse.ocl.examples.domain/src/org/eclipse/ocl/examples/domain/utilities/ProjectMap.java
>>
>> to scan the classpath for all possible JARs.
>>
>> Regards
>>
>> Ed Willink
>>
>>
>> On 28/02/2012 13:13, Emil Huseynli wrote:
>>> in UMLUtils.java you use URI.createPlatformPluginURI, does it load all
>>> available jar files with resources? i.e.
>>>
>>> org.eclipse.uml2.uml.resources_<version>.jar
>>>
>>> where <version> are 3.0.0.v200906011111 or 2.0.0v20080702111 or
>>> whatever else
>>>
>>> should i do URI.createURI multiple times for different jar files in
>>> order to support xmi files with different namespaces?
>>>
>>> or are the instructions like
>>>
>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>> UMLPackage.eINSTANCE);
>>>
>>> which determine how many different xmi-types will be available?
>>>
>>>
>>> On 28.02.2012 13:26, Ed Willink wrote:
>>>> Hi Emil
>>>>
>>>> My sympathies; I find it hard too and the support routines are not as
>>>> helpful as they might be.
>>>>
>>>> The basic problem is that there are many dramatically different
>>>> contents
>>>> for a *.xmi file, and subtly different contents for a *.uml file.
>>>> Whereas for a *.ecore file there is only ever Ecore content, unless
>>>> you
>>>> want to have a really hard time. So for UML, extensions do not define
>>>> file content. It is therefore necessary to use content type, so on
>>>> encountering an *.xmi file or *.uml file the XML namespace is used to
>>>> select the appropriate EMF model handling.
>>>>
>>>> You appear to be using Indigo for which the UML versions have been
>>>> stuck
>>>> at 2.2 for some years. The good/bad news is that in Juno there is
>>>> support for UML 2.4 and 2.4.1 so there are now about nine different
>>>> UML
>>>> dialects. Yes, you can (and should) register all at once.
>>>>
>>>> /org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/uml/UMLUtils.java
>>>>
>>>>
>>>> in the OCL GIT is my attempt to do so.
>>>>
>>>> UML has profiles that allow you to tailor your models, These are
>>>> generally shared so it cannot be assumed that they are in a similar
>>>> location to the model, so where are they? pathmap:'s give a
>>>> reconfigurable indirection which is flexible but also inconvenient
>>>> because until they are correctly configured not much works.
>>>>
>>>> A Resource supports usage of one model. A ResourceSet set supports
>>>> usage
>>>> of many models. An EditingDomain supports many models in the
>>>> context of
>>>> an editor and on a good day may be shared across editors and tools so
>>>> that when a model is edited in one place everything else updates
>>>> accordingly.
>>>>
>>>> UriMap redirects the pathmaps to somewhere useful. Resource
>>>> registration
>>>> facilitates the location of a Resource for loading. Extension and
>>>> content registration facilitates the use of appropriate
>>>> ResourceFactories to create Resources.
>>>>
>>>> Regards
>>>>
>>>> Ed Willink
>>>>
>>>> On 28/02/2012 11:41, Emil Huseynli wrote:
>>>>> Hello,
>>>>>
>>>>> here is very newbie question, why we need uri in the following
>>>>> example?
>>>>>
>>>>>> Map uriMap = resourceSet.getURIConverter().getURIMap();
>>>>>> URI uri =
>>>>>> URI.createURI("jar:file:<path_to_resource_jar_file>/org.eclipse.uml2.uml.resources_<version>.jar!/");
>>>>>>
>>>>>>
>>>>>>
>>>>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>>>>> uri.appendSegment("libraries").appendSegment(""));
>>>>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>>>>>> uri.appendSegment("metamodels").appendSegment(""));
>>>>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>>>>> uri.appendSegment("profiles").appendSegment(""));
>>>>>
>>>>> Seems, that <version> here determines which xmi documents i can
>>>>> parse,
>>>>> for example, if i specify 3.0.0.v200906011111 (and i have
>>>>> org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar file) i can
>>>>> later read xmi files which contain
>>>>>
>>>>>> <xmi:XMI xmi:version="2.1" ...
>>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">
>>>>>
>>>>> and not files with xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
>>>>>
>>>>> is it possible to "configure" resourceSet, so that it can handle both
>>>>> xmi files?
>>>>>
>>>>> honestly, i'm not quite comfortable with all stuff around eclipse
>>>>> uml2, emf, xmi and maybe also xml
>>>>>
>>>>> for example i understand, that xmlns:uml defines a namespace, but the
>>>>> following snipped of code which i have confuses me and i don't
>>>>> understand it fully:
>>>>>
>>>>>> private void initializeEditingDomain() {
>>>>>>
>>>>>> String path =
>>>>>> "lib/xmihandlerjars/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar";
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> BasicCommandStack commandStack = new BasicCommandStack() {
>>>>>>
>>>>>> @Override
>>>>>> protected void handleError(Exception exception) {
>>>>>> super.handleError(exception);
>>>>>> throw new RuntimeException(exception);
>>>>>> }
>>>>>>
>>>>>> };
>>>>>>
>>>>>> List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
>>>>>> factories.add(new UMLResourceItemProviderAdapterFactory());
>>>>>> factories.add(new UMLItemProviderAdapterFactory());
>>>>>> factories.add(new EcoreItemProviderAdapterFactory());
>>>>>> factories.add(new UMLReflectiveItemProviderAdapterFactory());
>>>>>> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
>>>>>> factories);
>>>>>>
>>>>>> editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
>>>>>> commandStack);
>>>>>>
>>>>>> ResourceSet resourceSet = editingDomain.getResourceSet();
>>>>>> Map<String, Object> extensionToFactoryMap = resourceSet
>>>>>> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>>>>>> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>>>>>>
>>>>>> try {
>>>>>> FileInputStream in = new FileInputStream(path);
>>>>>> in.close();
>>>>>> } catch (IOException e) {
>>>>>> throw (new RuntimeException(e));
>>>>>> }
>>>>>>
>>>>>> path = path.replace('\\', '/');
>>>>>> URI uri = URI.createURI("jar:file:" + path + "!/");
>>>>>> Log.debug("eUML.resource URI --> " + uri);
>>>>>>
>>>>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>>>> // for other xmi files with further namespaces:
>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_NS_URI,
>>>>>> UMLPackage.eINSTANCE);
>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_URI,
>>>>>> UMLPackage.eINSTANCE);
>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_NS_URI,
>>>>>> UMLPackage.eINSTANCE);
>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_URI,
>>>>>> UMLPackage.eINSTANCE);
>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_2_NS_URI,
>>>>>> UMLPackage.eINSTANCE);
>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_NS_URI,
>>>>>> UMLPackage.eINSTANCE);
>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_URI,
>>>>>> UMLPackage.eINSTANCE);
>>>>>> // eclipse namespaces:
>>>>>> packageRegistry.put(UML212UMLResource.UML_METAMODEL_NS_URI,
>>>>>> UMLPackage.eINSTANCE);
>>>>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>>>>> UMLPackage.eINSTANCE);
>>>>>>
>>>>>> // For the .uml files in the eclipse jar files, we need this:
>>>>>> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>>>> UMLResource.Factory.INSTANCE);
>>>>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>>>>> uri.appendSegment(
>>>>>> "libraries").appendSegment(""));
>>>>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
>>>>>> .appendSegment("metamodels").appendSegment(""));
>>>>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>>>>> uri.appendSegment(
>>>>>> "profiles").appendSegment(""));
>>>>>>
>>>>>> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>>>> UML22UMLResource.Factory.INSTANCE);
>>>>>> extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
>>>>>> XMI2UMLResource.Factory.INSTANCE);
>>>>>>
>>>>>> uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
>>>>>> uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
>>>>>> }
>>>>>
>>>>>
>>>>> in the code above, why we need
>>>>>
>>>>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>>>>> UMLPackage.eINSTANCE);
>>>>>
>>>>> if namespace http://www.eclipse.org/uml2/3.0.0/UML is already defined
>>>>> via uri and uriMap?
>>>>>
>>>>> what is the role of editing domain? Do i need it to just simply parse
>>>>> xmi files?
>>>>>
>>>>> i know, questions above are all spontaneous and most likely wrong
>>>>> formulated, but i'll be very glad if someone help to clarify all that
>>>>> stuff.
>>>>>
>>>>> thanks in advance!
>>>>
>>>
>>
>
Re: URI.createURI [message #809206 is a reply to message #809042] Tue, 28 February 2012 10:42 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn Hussey
Messages: 1618
Registered: July 2009
Senior Member
FYI, there is a related enhancement request open (364419) which I hope
to have addressed in time for Juno...

Kenn

On 12-02-28 7:26 AM, Ed Willink wrote:
> Hi Emil
>
> My sympathies; I find it hard too and the support routines are not as
> helpful as they might be.
>
> The basic problem is that there are many dramatically different contents
> for a *.xmi file, and subtly different contents for a *.uml file.
> Whereas for a *.ecore file there is only ever Ecore content, unless you
> want to have a really hard time. So for UML, extensions do not define
> file content. It is therefore necessary to use content type, so on
> encountering an *.xmi file or *.uml file the XML namespace is used to
> select the appropriate EMF model handling.
>
> You appear to be using Indigo for which the UML versions have been stuck
> at 2.2 for some years. The good/bad news is that in Juno there is
> support for UML 2.4 and 2.4.1 so there are now about nine different UML
> dialects. Yes, you can (and should) register all at once.
>
> /org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/uml/UMLUtils.java
> in the OCL GIT is my attempt to do so.
>
> UML has profiles that allow you to tailor your models, These are
> generally shared so it cannot be assumed that they are in a similar
> location to the model, so where are they? pathmap:'s give a
> reconfigurable indirection which is flexible but also inconvenient
> because until they are correctly configured not much works.
>
> A Resource supports usage of one model. A ResourceSet set supports usage
> of many models. An EditingDomain supports many models in the context of
> an editor and on a good day may be shared across editors and tools so
> that when a model is edited in one place everything else updates
> accordingly.
>
> UriMap redirects the pathmaps to somewhere useful. Resource registration
> facilitates the location of a Resource for loading. Extension and
> content registration facilitates the use of appropriate
> ResourceFactories to create Resources.
>
> Regards
>
> Ed Willink
>
> On 28/02/2012 11:41, Emil Huseynli wrote:
>> Hello,
>>
>> here is very newbie question, why we need uri in the following example?
>>
>>> Map uriMap = resourceSet.getURIConverter().getURIMap();
>>> URI uri =
>>> URI.createURI("jar:file:<path_to_resource_jar_file>/org.eclipse.uml2.uml.resources_<version>.jar!/");
>>>
>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>> uri.appendSegment("libraries").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>>> uri.appendSegment("metamodels").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>> uri.appendSegment("profiles").appendSegment(""));
>>
>> Seems, that <version> here determines which xmi documents i can parse,
>> for example, if i specify 3.0.0.v200906011111 (and i have
>> org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar file) i can
>> later read xmi files which contain
>>
>>> <xmi:XMI xmi:version="2.1" ...
>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">
>>
>> and not files with xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
>>
>> is it possible to "configure" resourceSet, so that it can handle both
>> xmi files?
>>
>> honestly, i'm not quite comfortable with all stuff around eclipse
>> uml2, emf, xmi and maybe also xml
>>
>> for example i understand, that xmlns:uml defines a namespace, but the
>> following snipped of code which i have confuses me and i don't
>> understand it fully:
>>
>>> private void initializeEditingDomain() {
>>>
>>> String path =
>>> "lib/xmihandlerjars/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar";
>>>
>>>
>>> BasicCommandStack commandStack = new BasicCommandStack() {
>>>
>>> @Override
>>> protected void handleError(Exception exception) {
>>> super.handleError(exception);
>>> throw new RuntimeException(exception);
>>> }
>>>
>>> };
>>>
>>> List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
>>> factories.add(new UMLResourceItemProviderAdapterFactory());
>>> factories.add(new UMLItemProviderAdapterFactory());
>>> factories.add(new EcoreItemProviderAdapterFactory());
>>> factories.add(new UMLReflectiveItemProviderAdapterFactory());
>>> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
>>> factories);
>>>
>>> editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
>>> commandStack);
>>>
>>> ResourceSet resourceSet = editingDomain.getResourceSet();
>>> Map<String, Object> extensionToFactoryMap = resourceSet
>>> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>>> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>>>
>>> try {
>>> FileInputStream in = new FileInputStream(path);
>>> in.close();
>>> } catch (IOException e) {
>>> throw (new RuntimeException(e));
>>> }
>>>
>>> path = path.replace('\\', '/');
>>> URI uri = URI.createURI("jar:file:" + path + "!/");
>>> Log.debug("eUML.resource URI --> " + uri);
>>>
>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>> // for other xmi files with further namespaces:
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_2_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_URI,
>>> UMLPackage.eINSTANCE);
>>> // eclipse namespaces:
>>> packageRegistry.put(UML212UMLResource.UML_METAMODEL_NS_URI,
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>> UMLPackage.eINSTANCE);
>>>
>>> // For the .uml files in the eclipse jar files, we need this:
>>> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
>>> UMLResource.Factory.INSTANCE);
>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>> uri.appendSegment(
>>> "libraries").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
>>> .appendSegment("metamodels").appendSegment(""));
>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>> uri.appendSegment(
>>> "profiles").appendSegment(""));
>>>
>>> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>> UML22UMLResource.Factory.INSTANCE);
>>> extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
>>> XMI2UMLResource.Factory.INSTANCE);
>>>
>>> uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
>>> uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
>>> }
>>
>>
>> in the code above, why we need
>>
>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>> UMLPackage.eINSTANCE);
>>
>> if namespace http://www.eclipse.org/uml2/3.0.0/UML is already defined
>> via uri and uriMap?
>>
>> what is the role of editing domain? Do i need it to just simply parse
>> xmi files?
>>
>> i know, questions above are all spontaneous and most likely wrong
>> formulated, but i'll be very glad if someone help to clarify all that
>> stuff.
>>
>> thanks in advance!
>
Re: URI.createURI [message #809207 is a reply to message #809157] Tue, 28 February 2012 10:47 Go to previous messageGo to next message
Eclipse User
if i use plugins? which plugins do you mean?

On 28.02.2012 15:38, Ed Willink wrote:
> Hi
>
> The latest version should support all UML versions. There is subtle code
> in the meta-model loading that enables the one meta-model to support all
> dialects.
>
> If you use plugins you should never need to worry about _<version>.
>
> Regards
>
> Ed Willink
>
> On 28/02/2012 14:09, Emil Huseynli wrote:
>> I'm trying to load resource from standalone application, and one
>> important thing is not clear:
>>
>> in order to support different xmi versions, do i need also different
>> versions of org.eclipse.uml2.uml.resources_<version>.jar ? Or only
>> latest version and support for different xmi is achieved with following?
>>
>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>> UMLPackage.eINSTANCE);
>>> packageRegistry.put("http://www.eclipse.org/uml2/2.0.0/UML",
>>> UMLPackage.eINSTANCE);
>>
>>
>>
>> On 28.02.2012 14:27, Ed Willink wrote:
>>> Hi
>>>
>>> You may need
>>> /org.eclipse.ocl.examples.domain/src/org/eclipse/ocl/examples/domain/utilities/ProjectMap.java
>>>
>>> to scan the classpath for all possible JARs.
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>>
>>> On 28/02/2012 13:13, Emil Huseynli wrote:
>>>> in UMLUtils.java you use URI.createPlatformPluginURI, does it load all
>>>> available jar files with resources? i.e.
>>>>
>>>> org.eclipse.uml2.uml.resources_<version>.jar
>>>>
>>>> where <version> are 3.0.0.v200906011111 or 2.0.0v20080702111 or
>>>> whatever else
>>>>
>>>> should i do URI.createURI multiple times for different jar files in
>>>> order to support xmi files with different namespaces?
>>>>
>>>> or are the instructions like
>>>>
>>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>>> UMLPackage.eINSTANCE);
>>>>
>>>> which determine how many different xmi-types will be available?
>>>>
>>>>
>>>> On 28.02.2012 13:26, Ed Willink wrote:
>>>>> Hi Emil
>>>>>
>>>>> My sympathies; I find it hard too and the support routines are not as
>>>>> helpful as they might be.
>>>>>
>>>>> The basic problem is that there are many dramatically different
>>>>> contents
>>>>> for a *.xmi file, and subtly different contents for a *.uml file.
>>>>> Whereas for a *.ecore file there is only ever Ecore content, unless
>>>>> you
>>>>> want to have a really hard time. So for UML, extensions do not define
>>>>> file content. It is therefore necessary to use content type, so on
>>>>> encountering an *.xmi file or *.uml file the XML namespace is used to
>>>>> select the appropriate EMF model handling.
>>>>>
>>>>> You appear to be using Indigo for which the UML versions have been
>>>>> stuck
>>>>> at 2.2 for some years. The good/bad news is that in Juno there is
>>>>> support for UML 2.4 and 2.4.1 so there are now about nine different
>>>>> UML
>>>>> dialects. Yes, you can (and should) register all at once.
>>>>>
>>>>> /org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/uml/UMLUtils.java
>>>>>
>>>>>
>>>>> in the OCL GIT is my attempt to do so.
>>>>>
>>>>> UML has profiles that allow you to tailor your models, These are
>>>>> generally shared so it cannot be assumed that they are in a similar
>>>>> location to the model, so where are they? pathmap:'s give a
>>>>> reconfigurable indirection which is flexible but also inconvenient
>>>>> because until they are correctly configured not much works.
>>>>>
>>>>> A Resource supports usage of one model. A ResourceSet set supports
>>>>> usage
>>>>> of many models. An EditingDomain supports many models in the
>>>>> context of
>>>>> an editor and on a good day may be shared across editors and tools so
>>>>> that when a model is edited in one place everything else updates
>>>>> accordingly.
>>>>>
>>>>> UriMap redirects the pathmaps to somewhere useful. Resource
>>>>> registration
>>>>> facilitates the location of a Resource for loading. Extension and
>>>>> content registration facilitates the use of appropriate
>>>>> ResourceFactories to create Resources.
>>>>>
>>>>> Regards
>>>>>
>>>>> Ed Willink
>>>>>
>>>>> On 28/02/2012 11:41, Emil Huseynli wrote:
>>>>>> Hello,
>>>>>>
>>>>>> here is very newbie question, why we need uri in the following
>>>>>> example?
>>>>>>
>>>>>>> Map uriMap = resourceSet.getURIConverter().getURIMap();
>>>>>>> URI uri =
>>>>>>> URI.createURI("jar:file:<path_to_resource_jar_file>/org.eclipse.uml2.uml.resources_<version>.jar!/");
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>>>>>> uri.appendSegment("libraries").appendSegment(""));
>>>>>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>>>>>>> uri.appendSegment("metamodels").appendSegment(""));
>>>>>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>>>>>> uri.appendSegment("profiles").appendSegment(""));
>>>>>>
>>>>>> Seems, that <version> here determines which xmi documents i can
>>>>>> parse,
>>>>>> for example, if i specify 3.0.0.v200906011111 (and i have
>>>>>> org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar file) i can
>>>>>> later read xmi files which contain
>>>>>>
>>>>>>> <xmi:XMI xmi:version="2.1" ...
>>>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">
>>>>>>
>>>>>> and not files with xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
>>>>>>
>>>>>> is it possible to "configure" resourceSet, so that it can handle both
>>>>>> xmi files?
>>>>>>
>>>>>> honestly, i'm not quite comfortable with all stuff around eclipse
>>>>>> uml2, emf, xmi and maybe also xml
>>>>>>
>>>>>> for example i understand, that xmlns:uml defines a namespace, but the
>>>>>> following snipped of code which i have confuses me and i don't
>>>>>> understand it fully:
>>>>>>
>>>>>>> private void initializeEditingDomain() {
>>>>>>>
>>>>>>> String path =
>>>>>>> "lib/xmihandlerjars/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar";
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> BasicCommandStack commandStack = new BasicCommandStack() {
>>>>>>>
>>>>>>> @Override
>>>>>>> protected void handleError(Exception exception) {
>>>>>>> super.handleError(exception);
>>>>>>> throw new RuntimeException(exception);
>>>>>>> }
>>>>>>>
>>>>>>> };
>>>>>>>
>>>>>>> List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
>>>>>>> factories.add(new UMLResourceItemProviderAdapterFactory());
>>>>>>> factories.add(new UMLItemProviderAdapterFactory());
>>>>>>> factories.add(new EcoreItemProviderAdapterFactory());
>>>>>>> factories.add(new UMLReflectiveItemProviderAdapterFactory());
>>>>>>> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
>>>>>>> factories);
>>>>>>>
>>>>>>> editingDomain = new UML2AdapterFactoryEditingDomain(adapterFactory,
>>>>>>> commandStack);
>>>>>>>
>>>>>>> ResourceSet resourceSet = editingDomain.getResourceSet();
>>>>>>> Map<String, Object> extensionToFactoryMap = resourceSet
>>>>>>> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>>>>>>> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>>>>>>>
>>>>>>> try {
>>>>>>> FileInputStream in = new FileInputStream(path);
>>>>>>> in.close();
>>>>>>> } catch (IOException e) {
>>>>>>> throw (new RuntimeException(e));
>>>>>>> }
>>>>>>>
>>>>>>> path = path.replace('\\', '/');
>>>>>>> URI uri = URI.createURI("jar:file:" + path + "!/");
>>>>>>> Log.debug("eUML.resource URI --> " + uri);
>>>>>>>
>>>>>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>>>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>>>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>>>>> // for other xmi files with further namespaces:
>>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_NS_URI,
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_1_URI,
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_NS_URI,
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_1_URI,
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_2_2_NS_URI,
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_NS_URI,
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>> packageRegistry.put(XMI212UMLResource.UML_METAMODEL_URI,
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>> // eclipse namespaces:
>>>>>>> packageRegistry.put(UML212UMLResource.UML_METAMODEL_NS_URI,
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>>
>>>>>>> // For the .uml files in the eclipse jar files, we need this:
>>>>>>> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>>>>> UMLResource.Factory.INSTANCE);
>>>>>>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>>>>>>> uri.appendSegment(
>>>>>>> "libraries").appendSegment(""));
>>>>>>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri
>>>>>>> .appendSegment("metamodels").appendSegment(""));
>>>>>>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>>>>>>> uri.appendSegment(
>>>>>>> "profiles").appendSegment(""));
>>>>>>>
>>>>>>> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>>>>> UML22UMLResource.Factory.INSTANCE);
>>>>>>> extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION,
>>>>>>> XMI2UMLResource.Factory.INSTANCE);
>>>>>>>
>>>>>>> uriMap.putAll(UML22UMLExtendedMetaData.getURIMap());
>>>>>>> uriMap.putAll(XMI2UMLExtendedMetaData.getURIMap());
>>>>>>> }
>>>>>>
>>>>>>
>>>>>> in the code above, why we need
>>>>>>
>>>>>>> packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML",
>>>>>>> UMLPackage.eINSTANCE);
>>>>>>
>>>>>> if namespace http://www.eclipse.org/uml2/3.0.0/UML is already defined
>>>>>> via uri and uriMap?
>>>>>>
>>>>>> what is the role of editing domain? Do i need it to just simply parse
>>>>>> xmi files?
>>>>>>
>>>>>> i know, questions above are all spontaneous and most likely wrong
>>>>>> formulated, but i'll be very glad if someone help to clarify all that
>>>>>> stuff.
>>>>>>
>>>>>> thanks in advance!
>>>>>
>>>>
>>>
>>
>
Re: URI.createURI [message #809240 is a reply to message #809207] Tue, 28 February 2012 11:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4008
Registered: July 2009
Senior Member
Hi

I mean place your code in a Plugin (Java) project rather than a Java
Project so that MANIFEST.MF sorts out the classpath.

Regards

Ed Willink

On 28/02/2012 15:47, Emil Huseynli wrote:
> if i use plugins? which plugins do you mean?
Re: URI.createURI [message #809277 is a reply to message #809240] Tue, 28 February 2012 12:15 Go to previous message
Eclipse User
understood :)

thanks a lot!

On 28.02.2012 17:25, Ed Willink wrote:
> Hi
>
> I mean place your code in a Plugin (Java) project rather than a Java
> Project so that MANIFEST.MF sorts out the classpath.
>
> Regards
>
> Ed Willink
>
> On 28/02/2012 15:47, Emil Huseynli wrote:
>> if i use plugins? which plugins do you mean?
>
Previous Topic:Get all elements with stereotype X applied
Next Topic:Model or package as root element
Goto Forum:
  


Current Time: Mon Jul 28 08:29:40 EDT 2014

Powered by FUDForum. Page generated in 0.03083 seconds