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 #624571] Fri, 10 July 2009 08:21
guenin is currently offline guenin
Messages: 42
Registered: July 2009
Member
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));
}
}
}
}
Previous Topic:New to UML2tools & existing Java project
Next Topic:[TOPCASED] Galileo compatible?
Goto Forum:
  


Current Time: Wed Aug 27 09:17:25 EDT 2014

Powered by FUDForum. Page generated in 0.01673 seconds