get stereotypes applied to an element [message #476586] |
Fri, 10 July 2009 08:21  |
Eclipse User |
|
|
|
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 #624574 is a reply to message #476586] |
Mon, 13 July 2009 09:19  |
Eclipse User |
|
|
|
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));
> }
> }
> }
> }
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.45535 seconds