Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Getting applied profile names programmatically?
Getting applied profile names programmatically? [message #476813] Mon, 31 December 2007 15:45 Go to next message
Eclipse UserFriend
Originally posted by: matt.mcgill.gmail.com

Hello all,

I've looked through many profile-related posts on the newsgroup here,
and haven't been able to put my finger on the source of my troubles.
I'm loading a UML2 model programmatically with the following code:

public static Model loadFromFile(String path) {
ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
"uml", new XMIResourceFactoryImpl());
URI uri = URI.createFileURI(path);
EClass eClass = UMLPackage.eINSTANCE.getModel();
Model m = (Model) EcoreUtil.getObjectByType(
rs.getResource(uri, true).getContents(), eClass);
return m;
}

I'm writing a UML simulator that will rely on information supplied in a profile,
and as a first step, I want to check that the profile is applied. I wrote the
following code to do so:

boolean foundProfile = false;
for (Profile p : m.getAllAppliedProfiles()) {
if ("hydra-uml".equals(p.getName())) {
foundProfile = true;
break;
}
}
if (!foundProfile)
throw new HydraException(...);

Running this code on a simple test model with some applied profiles fails, however.
getAppliedProfiles() returns Profile instances representing the applied profiles,
but getName() returns null, and using the debugger I can see that only the eProxyURI
attribute on the ProfileImpl instances is initialized.

What do I need to do to get access to the names of these profiles? This code is all
stand-alone, not running within an Eclipse workbench.

Thanks,
-Matt
Re: Getting applied profile names programmatically? [message #476814 is a reply to message #476813] Mon, 31 December 2007 16:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: matt.mcgill.gmail.com

I've continued reading profile-related posts here on the newsgroup, and think perhaps
I'm zeroing in on my problem. I'm using the Papyrus plugin to edit my profile and model.
Here's a snippet from the UML model file:

<profileApplication xmi:id="_frAlQLe8Edy1zMLaMA2OeQ">
<eAnnotations xmi:id="_frJvMLe8Edy1zMLaMA2OeQ" source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage" href=" ../resources/edu/msu/cse/sens/hydra/semantics/hydra-uml.prof ile.uml#_79Ygobe6Edy1zMLaMA2OeQ "/>
</eAnnotations>
<appliedProfile href=" ../resources/edu/msu/cse/sens/hydra/semantics/hydra-uml.prof ile.uml#_pi624Lb-Edy1zMLaMA2OeQ "/>
</profileApplication>

The URI is relative to the location of the model itself. How does EMF resolve such URIs?
Would EMF be able to find the profile using this URI when loading the model
programmatically in a stand-alone environment?

If this is in fact my problem, what are my options?

Thanks,
-Matt


Matt McGill wrote:
> Hello all,
>
> I've looked through many profile-related posts on the newsgroup here,
> and haven't been able to put my finger on the source of my troubles.
> I'm loading a UML2 model programmatically with the following code:
>
> public static Model loadFromFile(String path) {
> ResourceSet rs = new ResourceSetImpl();
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
> "uml", new XMIResourceFactoryImpl());
> URI uri = URI.createFileURI(path);
> EClass eClass = UMLPackage.eINSTANCE.getModel();
> Model m = (Model) EcoreUtil.getObjectByType(
> rs.getResource(uri, true).getContents(), eClass);
> return m;
> }
>
> I'm writing a UML simulator that will rely on information supplied in a
> profile,
> and as a first step, I want to check that the profile is applied. I
> wrote the
> following code to do so:
>
> boolean foundProfile = false;
> for (Profile p : m.getAllAppliedProfiles()) {
> if ("hydra-uml".equals(p.getName())) {
> foundProfile = true;
> break;
> }
> }
> if (!foundProfile)
> throw new HydraException(...);
>
> Running this code on a simple test model with some applied profiles
> fails, however.
> getAppliedProfiles() returns Profile instances representing the applied
> profiles,
> but getName() returns null, and using the debugger I can see that only
> the eProxyURI
> attribute on the ProfileImpl instances is initialized.
>
> What do I need to do to get access to the names of these profiles? This
> code is all
> stand-alone, not running within an Eclipse workbench.
>
> Thanks,
> -Matt
Re: Getting applied profile names programmatically? [message #476816 is a reply to message #476814] Wed, 02 January 2008 16:57 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Matt,

These URIs are resolved like any other cross document reference in EMF...
the proxies should be resolved succesfully, assuming the referenced resource
is located in the expected relative location. Note that when loading
models/profiles programatically, there are a few preparatory steps that must
be taken - see the articles on the documentation page and the FAQ for
details.

Kenn

"Matt McGill" <matt.mcgill@gmail.com> wrote in message
news:flb6fu$k6l$1@build.eclipse.org...
> I've continued reading profile-related posts here on the newsgroup, and
> think perhaps
> I'm zeroing in on my problem. I'm using the Papyrus plugin to edit my
> profile and model.
> Here's a snippet from the UML model file:
>
> <profileApplication xmi:id="_frAlQLe8Edy1zMLaMA2OeQ">
> <eAnnotations xmi:id="_frJvMLe8Edy1zMLaMA2OeQ"
> source="http://www.eclipse.org/uml2/2.0.0/UML">
> <references xmi:type="ecore:EPackage"
> href=" ../resources/edu/msu/cse/sens/hydra/semantics/hydra-uml.prof ile.uml#_79Ygobe6Edy1zMLaMA2OeQ "/>
> </eAnnotations>
> <appliedProfile
> href=" ../resources/edu/msu/cse/sens/hydra/semantics/hydra-uml.prof ile.uml#_pi624Lb-Edy1zMLaMA2OeQ "/>
> </profileApplication>
>
> The URI is relative to the location of the model itself. How does EMF
> resolve such URIs?
> Would EMF be able to find the profile using this URI when loading the
> model
> programmatically in a stand-alone environment?
>
> If this is in fact my problem, what are my options?
>
> Thanks,
> -Matt
>
>
> Matt McGill wrote:
>> Hello all,
>>
>> I've looked through many profile-related posts on the newsgroup here,
>> and haven't been able to put my finger on the source of my troubles.
>> I'm loading a UML2 model programmatically with the following code:
>>
>> public static Model loadFromFile(String path) {
>> ResourceSet rs = new ResourceSetImpl();
>> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
>> "uml", new XMIResourceFactoryImpl());
>> URI uri = URI.createFileURI(path);
>> EClass eClass = UMLPackage.eINSTANCE.getModel();
>> Model m = (Model) EcoreUtil.getObjectByType(
>> rs.getResource(uri, true).getContents(), eClass);
>> return m;
>> }
>>
>> I'm writing a UML simulator that will rely on information supplied in a
>> profile,
>> and as a first step, I want to check that the profile is applied. I wrote
>> the
>> following code to do so:
>>
>> boolean foundProfile = false;
>> for (Profile p : m.getAllAppliedProfiles()) {
>> if ("hydra-uml".equals(p.getName())) {
>> foundProfile = true;
>> break;
>> }
>> }
>> if (!foundProfile)
>> throw new HydraException(...);
>>
>> Running this code on a simple test model with some applied profiles
>> fails, however.
>> getAppliedProfiles() returns Profile instances representing the applied
>> profiles,
>> but getName() returns null, and using the debugger I can see that only
>> the eProxyURI
>> attribute on the ProfileImpl instances is initialized.
>>
>> What do I need to do to get access to the names of these profiles? This
>> code is all
>> stand-alone, not running within an Eclipse workbench.
>>
>> Thanks,
>> -Matt
Re: Getting applied profile names programmatically? [message #625790 is a reply to message #476813] Mon, 31 December 2007 16:52 Go to previous message
Eclipse UserFriend
Originally posted by: matt.mcgill.gmail.com

I've continued reading profile-related posts here on the newsgroup, and think perhaps
I'm zeroing in on my problem. I'm using the Papyrus plugin to edit my profile and model.
Here's a snippet from the UML model file:

<profileApplication xmi:id="_frAlQLe8Edy1zMLaMA2OeQ">
<eAnnotations xmi:id="_frJvMLe8Edy1zMLaMA2OeQ" source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage" href=" ../resources/edu/msu/cse/sens/hydra/semantics/hydra-uml.prof ile.uml#_79Ygobe6Edy1zMLaMA2OeQ "/>
</eAnnotations>
<appliedProfile href=" ../resources/edu/msu/cse/sens/hydra/semantics/hydra-uml.prof ile.uml#_pi624Lb-Edy1zMLaMA2OeQ "/>
</profileApplication>

The URI is relative to the location of the model itself. How does EMF resolve such URIs?
Would EMF be able to find the profile using this URI when loading the model
programmatically in a stand-alone environment?

If this is in fact my problem, what are my options?

Thanks,
-Matt


Matt McGill wrote:
> Hello all,
>
> I've looked through many profile-related posts on the newsgroup here,
> and haven't been able to put my finger on the source of my troubles.
> I'm loading a UML2 model programmatically with the following code:
>
> public static Model loadFromFile(String path) {
> ResourceSet rs = new ResourceSetImpl();
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
> "uml", new XMIResourceFactoryImpl());
> URI uri = URI.createFileURI(path);
> EClass eClass = UMLPackage.eINSTANCE.getModel();
> Model m = (Model) EcoreUtil.getObjectByType(
> rs.getResource(uri, true).getContents(), eClass);
> return m;
> }
>
> I'm writing a UML simulator that will rely on information supplied in a
> profile,
> and as a first step, I want to check that the profile is applied. I
> wrote the
> following code to do so:
>
> boolean foundProfile = false;
> for (Profile p : m.getAllAppliedProfiles()) {
> if ("hydra-uml".equals(p.getName())) {
> foundProfile = true;
> break;
> }
> }
> if (!foundProfile)
> throw new HydraException(...);
>
> Running this code on a simple test model with some applied profiles
> fails, however.
> getAppliedProfiles() returns Profile instances representing the applied
> profiles,
> but getName() returns null, and using the debugger I can see that only
> the eProxyURI
> attribute on the ProfileImpl instances is initialized.
>
> What do I need to do to get access to the names of these profiles? This
> code is all
> stand-alone, not running within an Eclipse workbench.
>
> Thanks,
> -Matt
Re: Getting applied profile names programmatically? [message #625792 is a reply to message #476814] Wed, 02 January 2008 16:57 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Matt,

These URIs are resolved like any other cross document reference in EMF...
the proxies should be resolved succesfully, assuming the referenced resource
is located in the expected relative location. Note that when loading
models/profiles programatically, there are a few preparatory steps that must
be taken - see the articles on the documentation page and the FAQ for
details.

Kenn

"Matt McGill" <matt.mcgill@gmail.com> wrote in message
news:flb6fu$k6l$1@build.eclipse.org...
> I've continued reading profile-related posts here on the newsgroup, and
> think perhaps
> I'm zeroing in on my problem. I'm using the Papyrus plugin to edit my
> profile and model.
> Here's a snippet from the UML model file:
>
> <profileApplication xmi:id="_frAlQLe8Edy1zMLaMA2OeQ">
> <eAnnotations xmi:id="_frJvMLe8Edy1zMLaMA2OeQ"
> source="http://www.eclipse.org/uml2/2.0.0/UML">
> <references xmi:type="ecore:EPackage"
> href=" ../resources/edu/msu/cse/sens/hydra/semantics/hydra-uml.prof ile.uml#_79Ygobe6Edy1zMLaMA2OeQ "/>
> </eAnnotations>
> <appliedProfile
> href=" ../resources/edu/msu/cse/sens/hydra/semantics/hydra-uml.prof ile.uml#_pi624Lb-Edy1zMLaMA2OeQ "/>
> </profileApplication>
>
> The URI is relative to the location of the model itself. How does EMF
> resolve such URIs?
> Would EMF be able to find the profile using this URI when loading the
> model
> programmatically in a stand-alone environment?
>
> If this is in fact my problem, what are my options?
>
> Thanks,
> -Matt
>
>
> Matt McGill wrote:
>> Hello all,
>>
>> I've looked through many profile-related posts on the newsgroup here,
>> and haven't been able to put my finger on the source of my troubles.
>> I'm loading a UML2 model programmatically with the following code:
>>
>> public static Model loadFromFile(String path) {
>> ResourceSet rs = new ResourceSetImpl();
>> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
>> "uml", new XMIResourceFactoryImpl());
>> URI uri = URI.createFileURI(path);
>> EClass eClass = UMLPackage.eINSTANCE.getModel();
>> Model m = (Model) EcoreUtil.getObjectByType(
>> rs.getResource(uri, true).getContents(), eClass);
>> return m;
>> }
>>
>> I'm writing a UML simulator that will rely on information supplied in a
>> profile,
>> and as a first step, I want to check that the profile is applied. I wrote
>> the
>> following code to do so:
>>
>> boolean foundProfile = false;
>> for (Profile p : m.getAllAppliedProfiles()) {
>> if ("hydra-uml".equals(p.getName())) {
>> foundProfile = true;
>> break;
>> }
>> }
>> if (!foundProfile)
>> throw new HydraException(...);
>>
>> Running this code on a simple test model with some applied profiles
>> fails, however.
>> getAppliedProfiles() returns Profile instances representing the applied
>> profiles,
>> but getName() returns null, and using the debugger I can see that only
>> the eProxyURI
>> attribute on the ProfileImpl instances is initialized.
>>
>> What do I need to do to get access to the names of these profiles? This
>> code is all
>> stand-alone, not running within an Eclipse workbench.
>>
>> Thanks,
>> -Matt
Previous Topic:Getting applied profile names programmatically?
Next Topic:Generate UML - class diagram
Goto Forum:
  


Current Time: Fri Apr 19 09:39:01 GMT 2024

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

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

Back to the top