Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 Tools » get stereotypes applied to an element
get stereotypes applied to an element [message #476586] Fri, 10 July 2009 12:21 Go to next message
Eclipse UserFriend
Hi,
I want to get the stereotypes applied to the elements of my model but when
I use the function “getAppliedStereotypes” in the API uml2 I always obtain
an empty list. I succeed in loading the model and having all the members
of the model. Is there something to do before using the function
“getAppliedStereotypes”?

If someone can help me
Thanks
My code is hereunder:

//get the mmodel :
public ModelPapyrus(org.eclipse.emf.common.util.URI uri) {
try {
ResourceSetImpl resourceSet = new ResourceSetImpl();
// Plug in UML model loader (package and file extension recognition)
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap()
.put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
resource = (UMLResource) resourceSet.getResource(uri, true);
model=(Model)EcoreUtil.getObjectByType(resource.getContents( ),
UMLPackage.eINSTANCE.getModel());
model.getOwnedElements();
} catch (WrappedException we) {
we.printStackTrace();
System.exit(1);
}
}

//search of the stereotypes with a given name
public List<Element> getEltsStereotypes(String name) {
List<Element> liste = new ArrayList<Element>();
List<Element> elements =model.getOwnedElements() ;
for(int i=0;i<elements.size();i++){
System.out.println(elements.get(i)
.getApplicableStereotypes());
EList<Stereotype> stereotypes = elements.get(i)
.getAppliedStereotypes();//here I have always an empty list
if (stereotypes.size() > 0) {
for (int j = 0; j <= stereotypes.size(); j++) {
System.out.println(stereotypes.get(j).getName());
if (stereotypes.get(j).getName().equals("name")) {
liste.add(elements.get(i));
}
}
}
}
Re: get stereotypes applied to an element [message #476588 is a reply to message #476586] Mon, 13 July 2009 13:19 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Guenin,

Does the query for applicable stereotypes return anything? It sounds
like maybe the resource containing the profile (and Ecore definition)
isn't being loaded properly. Depending on the way the profile and model
were created and saved, this could happen if the profile resource is not
in the same location relative to the model. Try inspecting the resource
set to see whether the resource containing the profile is successfully
loaded...

Kenn

guenin wrote:
> Hi, I want to get the stereotypes applied to the elements of my model
> but when I use the function �getAppliedStereotypes� in the API uml2 I
> always obtain an empty list. I succeed in loading the model and having
> all the members of the model. Is there something to do before using the
> function �getAppliedStereotypes�?
>
> If someone can help me
> Thanks
> My code is hereunder:
>
> //get the mmodel :
> public ModelPapyrus(org.eclipse.emf.common.util.URI uri) {
> try {
> ResourceSetImpl resourceSet = new ResourceSetImpl();
> // Plug in UML model loader (package and file extension
> recognition)
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap()
> .put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> resource = (UMLResource) resourceSet.getResource(uri, true);
>
> model=(Model)EcoreUtil.getObjectByType(resource.getContents( ),
> UMLPackage.eINSTANCE.getModel());
> model.getOwnedElements();
> } catch (WrappedException we) {
> we.printStackTrace();
> System.exit(1);
> }
> }
>
> //search of the stereotypes with a given name
> public List<Element> getEltsStereotypes(String name) {
> List<Element> liste = new ArrayList<Element>();
> List<Element> elements =model.getOwnedElements() ;
> for(int i=0;i<elements.size();i++){
> System.out.println(elements.get(i)
> .getApplicableStereotypes());
> EList<Stereotype> stereotypes = elements.get(i)
> .getAppliedStereotypes();//here I have always an empty list
> if (stereotypes.size() > 0) {
> for (int j = 0; j <= stereotypes.size(); j++) {
> System.out.println(stereotypes.get(j).getName());
> if (stereotypes.get(j).getName().equals("name")) {
> liste.add(elements.get(i));
> }
> }
> }
> }
>
>
Re: get stereotypes applied to an element [message #476595 is a reply to message #476588] Wed, 15 July 2009 09:23 Go to previous message
Eclipse UserFriend
Hi Kenn,

Indeed, the query for applicable stereotypes returns nothing and there is
only one resource (my model) in the resourceSet. I tried to put my model
and my profile in the same file but I have always only my model in the
resource set. I also tried to add my profile in the resourceSet but how
specifie it is the profile applied?

Hereunder my uml file : the applied profiles are specified, there is only
one class with the stereotype "SwMutualExclusionResource"

<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SW_Interaction=" http://MARTE.MARTE_DesignModel.SRM/schemas/SW_Interaction/_w jMt8EOMEd6caK5ICj_pSQ/12"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML"
xsi:schemaLocation=" http://MARTE.MARTE_DesignModel.SRM/schemas/SW_Interaction/_w jMt8EOMEd6caK5ICj_pSQ/12
resources/MARTE.profile.uml#_wjeawEOMEd6caK5ICj_pSQ">
<uml:Model xmi:id="_SQGZYHEfEd6HEvR-xSS_ng" name="essai2">
<packageImport xmi:id="_SQGZYXEfEd6HEvR-xSS_ng">
<importedPackage xmi:type="uml:Model"
href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
</packageImport>
<packagedElement xmi:type="uml:Class" xmi:id="_dNWxIHEfEd6HEvR-xSS_ng"
name="Class_0"/>
<profileApplication xmi:id="_SQGZYnEfEd6HEvR-xSS_ng">
<eAnnotations xmi:id="_SQGZY3EfEd6HEvR-xSS_ng"
source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage"
href="http://www.eclipse.org/uml2/schemas/Standard/1#/"/>
</eAnnotations>
<appliedProfile
href="pathmap://UML_PROFILES/Standard.profile.uml#_0"/>
</profileApplication>
<profileApplication xmi:id="_YjBwAXEfEd6HEvR-xSS_ng">
<eAnnotations xmi:id="_YjLhAHEfEd6HEvR-xSS_ng"
source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage"
href="resources/MARTE.profile.uml#_wjeawEOMEd6caK5ICj_pSQ"/ >
</eAnnotations>
<appliedProfile
href="resources/MARTE.profile.uml#_EIfnABJeEdy3Td9UhuLFPg"/ >
</profileApplication>
</uml:Model>
<SW_Interaction:SwMutualExclusionResource
xmi:id="_1XpK4HEfEd6HEvR-xSS_ng"
base_Classifier="_dNWxIHEfEd6HEvR-xSS_ng"/>
</xmi:XMI>

Thank you for your help

Aurelie
Re: get stereotypes applied to an element [message #624574 is a reply to message #476586] Mon, 13 July 2009 13:19 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Guenin,

Does the query for applicable stereotypes return anything? It sounds
like maybe the resource containing the profile (and Ecore definition)
isn't being loaded properly. Depending on the way the profile and model
were created and saved, this could happen if the profile resource is not
in the same location relative to the model. Try inspecting the resource
set to see whether the resource containing the profile is successfully
loaded...

Kenn

guenin wrote:
> Hi, I want to get the stereotypes applied to the elements of my model
> but when I use the function �getAppliedStereotypes� in the API uml2 I
> always obtain an empty list. I succeed in loading the model and having
> all the members of the model. Is there something to do before using the
> function �getAppliedStereotypes�?
>
> If someone can help me
> Thanks
> My code is hereunder:
>
> //get the mmodel :
> public ModelPapyrus(org.eclipse.emf.common.util.URI uri) {
> try {
> ResourceSetImpl resourceSet = new ResourceSetImpl();
> // Plug in UML model loader (package and file extension
> recognition)
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap()
> .put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> resource = (UMLResource) resourceSet.getResource(uri, true);
>
> model=(Model)EcoreUtil.getObjectByType(resource.getContents( ),
> UMLPackage.eINSTANCE.getModel());
> model.getOwnedElements();
> } catch (WrappedException we) {
> we.printStackTrace();
> System.exit(1);
> }
> }
>
> //search of the stereotypes with a given name
> public List<Element> getEltsStereotypes(String name) {
> List<Element> liste = new ArrayList<Element>();
> List<Element> elements =model.getOwnedElements() ;
> for(int i=0;i<elements.size();i++){
> System.out.println(elements.get(i)
> .getApplicableStereotypes());
> EList<Stereotype> stereotypes = elements.get(i)
> .getAppliedStereotypes();//here I have always an empty list
> if (stereotypes.size() > 0) {
> for (int j = 0; j <= stereotypes.size(); j++) {
> System.out.println(stereotypes.get(j).getName());
> if (stereotypes.get(j).getName().equals("name")) {
> liste.add(elements.get(i));
> }
> }
> }
> }
>
>
Re: get stereotypes applied to an element [message #624587 is a reply to message #476588] Wed, 15 July 2009 09:23 Go to previous message
Eclipse UserFriend
Hi Kenn,

Indeed, the query for applicable stereotypes returns nothing and there is
only one resource (my model) in the resourceSet. I tried to put my model
and my profile in the same file but I have always only my model in the
resource set. I also tried to add my profile in the resourceSet but how
specifie it is the profile applied?

Hereunder my uml file : the applied profiles are specified, there is only
one class with the stereotype "SwMutualExclusionResource"

<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SW_Interaction=" http://MARTE.MARTE_DesignModel.SRM/schemas/SW_Interaction/_w jMt8EOMEd6caK5ICj_pSQ/12"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML"
xsi:schemaLocation=" http://MARTE.MARTE_DesignModel.SRM/schemas/SW_Interaction/_w jMt8EOMEd6caK5ICj_pSQ/12
resources/MARTE.profile.uml#_wjeawEOMEd6caK5ICj_pSQ">
<uml:Model xmi:id="_SQGZYHEfEd6HEvR-xSS_ng" name="essai2">
<packageImport xmi:id="_SQGZYXEfEd6HEvR-xSS_ng">
<importedPackage xmi:type="uml:Model"
href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
</packageImport>
<packagedElement xmi:type="uml:Class" xmi:id="_dNWxIHEfEd6HEvR-xSS_ng"
name="Class_0"/>
<profileApplication xmi:id="_SQGZYnEfEd6HEvR-xSS_ng">
<eAnnotations xmi:id="_SQGZY3EfEd6HEvR-xSS_ng"
source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage"
href="http://www.eclipse.org/uml2/schemas/Standard/1#/"/>
</eAnnotations>
<appliedProfile
href="pathmap://UML_PROFILES/Standard.profile.uml#_0"/>
</profileApplication>
<profileApplication xmi:id="_YjBwAXEfEd6HEvR-xSS_ng">
<eAnnotations xmi:id="_YjLhAHEfEd6HEvR-xSS_ng"
source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage"
href="resources/MARTE.profile.uml#_wjeawEOMEd6caK5ICj_pSQ"/ >
</eAnnotations>
<appliedProfile
href="resources/MARTE.profile.uml#_EIfnABJeEdy3Td9UhuLFPg"/ >
</profileApplication>
</uml:Model>
<SW_Interaction:SwMutualExclusionResource
xmi:id="_1XpK4HEfEd6HEvR-xSS_ng"
base_Classifier="_dNWxIHEfEd6HEvR-xSS_ng"/>
</xmi:XMI>

Thank you for your help

Aurelie
Previous Topic:Re: Parameterized classes / Template Signature
Next Topic:Newbie Question about Use Cases and Description
Goto Forum:
  


Current Time: Tue Apr 16 11:53:06 GMT 2024

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

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

Back to the top