[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.mdt.uml2tools] get stereotypes applied to an element
|
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().getExtensionToFactoryMap()
.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));
}
}
}
}