[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.mdt.uml2tools] Re: get stereotypes applied to an element

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().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));
                    }
                }
            }
        }