Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Register a Profile programmatically
Register a Profile programmatically [message #1168745] Sun, 03 November 2013 14:36 Go to next message
Alan DW is currently offline Alan DW
Messages: 105
Registered: March 2012
Senior Member
Hello everyone,

I have two XMI files: one contains a profile, the other contains a model which uses the profile. What I would like to do is to *register* the profile at the global registry such that the model in the other file can be loaded properly.

The problem is that I'm not running my code in an Eclipse-based environment, so I cannot resort to extension points or plugin.xml files. Also, the profile XMI and the model XMI are produced dynamically at runtime, so I cannot register the profile at build time.

Any hints on how to do this? I think it should be something similar to the first answer in this thread (which registers an EPackage dynamically), but I could not figure out how to do it for profiles. But it must have something to do with EPackages, because the error I get when I load the model is that the "package with uri ... not found", where "..." is the namespace URI of the profile.

I'd be grateful for any help.

Thanks,


Alan

[Updated on: Sun, 03 November 2013 14:41]

Report message to a moderator

Re: Register a Profile programmatically [message #1170164 is a reply to message #1168745] Mon, 04 November 2013 12:50 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 801
Registered: July 2009
Senior Member
Hi, Alan,

There is a profile registry (of a sort) populated by an extension point
in the org.eclipse.uml2.uml namespace that is similar to the EPackage
registry extension point in EMF. It can likewise be manipulated in
code for deployment in "stand-alone" (Eclipse-free) applications.

Have a look at what the UMLResourceUtil API does in the
org.eclipse.uml2.uml.resources plug-in does for registration of the UML
standard profiles. You can do the same for your profiles.

http://git.eclipse.org/c/uml2/org.eclipse.uml2.git/tree/plugins/org.eclipse.uml2.uml.resources/src/org/eclipse/uml2/uml/resources/util/UMLResourcesUtil.java


HTH,

Christian


On 2013-11-03 14:36:44 +0000, Alan DW said:

> Hello everyone,
>
> I have two XMI files: one contains a profile, the other contains a
> model which uses the profile. What I would like to do is to *register*
> the profile at the global registry such that the model in the other
> file can be loaded properly.
>
> The problem is that I'm not running my code in an Eclipse-based
> environment, so I cannot resort to extension points or plugin.xml
> files. Also, the profile XMI and the model XMI are produced dynamically
> at runtime, so I cannot register the profile at build time.
>
> Any hints on how to do this? I think it should be something similar to
> the first answer in
> http://stackoverflow.com/questions/9386348/emf-register-ecore-meta-model-programmatically
> (which registers an EPackage dynamically), but I could not figure out
> how to do it for profiles. But it must have something to do with
> EPackages, because the error I get when I load the model is that the
> "epackage with uri ... not found", where "..." is the namespace URI of
> the profile.
>
> I'd be grateful for any help.
>
> Thanks,
>
>
> Alan
Re: Register a Profile programmatically [message #1173388 is a reply to message #1170164] Wed, 06 November 2013 13:39 Go to previous messageGo to next message
Alan DW is currently offline Alan DW
Messages: 105
Registered: March 2012
Senior Member
Hi Christian,

thank you for your response. Sorry that it took me so long to get back to this thread, I've lots of simultaneous projects going on right now.

I've had a look at the UMLResourcesUtil. However, I'm afraid that I can't see how this relates to registering an org.eclipse.uml2.uml.Profile to a resource set. All of the classes involved in the UMLResourcesUtil come from different branches on the inheritance tree - most of them inherit directly or indirectly from EPackage, but the profile instance does not do that.

I've got the feeling that I'm missing something important detail, but I can't tell what it is. Could you give me a hint?


Thanks,


Alan
Re: Register a Profile programmatically [message #1173495 is a reply to message #1173388] Wed, 06 November 2013 15:09 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 801
Registered: July 2009
Senior Member
Hi, Alan,

Have a look in the initEPackageNsURIToProfileLocationMap(...) method,
for example:

ePackageNsURIToProfileLocationMap.put(L2Package.eNS_URI,

URI.createURI("pathmap://UML_PROFILES/StandardL2.profile.uml#_0"));
//$NON-NLS-1$

(and look at callers of this method to see which map to pass in)

This ensures that the UML2 run-time can correlate the EPackage
representation of the profile (identified by URI, which in this case
appears to belong to a generated profile/EPackage) with the Profile in
the source UML. This particular example uses a (URI-mapped)
pathmap-scheme URI to locate the UML profile resource; you may need
something different.

The other registration is needed by EMF and is done in the
initPackageRegistry(...) method. Looking at the example of the same
profile:

packageRegistry.put(L2Package.eNS_URI, L2Package.eINSTANCE);

Again, this profile is generated statically. If your profile is
dynamic, you'll need to load it and get its active definition via the
Profile::getDefinition() API.

HTH,

Christian


On 2013-11-06 13:39:37 +0000, Alan DW said:

> Hi Christian,
>
> thank you for your response. Sorry that it took me so long to get back
> to this thread, I've lots of simultaneous projects going on right now.
>
> I've had a look at the UMLResourcesUtil. However, I'm afraid that I
> can't see how this relates to registering an
> org.eclipse.uml2.uml.Profile to a resource set. All of the classes
> involved in the UMLResourcesUtil come from different branches on the
> inheritance tree - most of them inherit directly or indirectly from
> EPackage, but the profile instance does not do that.
>
> I've got the feeling that I'm missing something important detail, but I
> can't tell what it is. Could you give me a hint?
>
>
> Thanks,
>
>
> Alan
Re: Register a Profile programmatically [message #1176474 is a reply to message #1173495] Fri, 08 November 2013 10:57 Go to previous message
Alan DW is currently offline Alan DW
Messages: 105
Registered: March 2012
Senior Member
Hello Christian,

thank you for your support. Profile::getDefinition did the trick. Just registered the resulting EPackage at the epackage registry of my resource set and it worked nicely Smile

I wasn't aware of the "getDefinition" method, but I'll make sure to remember it for the future.

Thank you!


Alan
Previous Topic:Class and Package diagrams for eclipse api
Next Topic:inheritance of stereotypes in subclasses
Goto Forum:
  


Current Time: Mon Oct 20 09:52:39 GMT 2014

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

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