package hl7template.api.generator; import java.util.Iterator; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Stereotype; /** * * @author Abderrazek Boufahja * */ public class UmlServices { /** * Return the stereotype if is applied to element. * * @param elt * Element used. * @param stereotype * Stereotype to return. * * @return the stereotype. * * @throws ENodeCastException * the e node cast exception */ public Stereotype getStereotype(Element elt, String stereotype) { Stereotype result = null; // search with real stereotype for (Iterator iter = elt.getAppliedStereotypes().iterator(); iter .hasNext();) { Stereotype element = iter.next(); if (element.getName().equals(stereotype)) { result = element; } } return result; } /** * Return the stereotype value if is applied to element. * * @param elt * Element used. * @param stereotype * Stereotype to return. * @param propertyName * the property name * * @return Object contain the value. * * @throws ENodeCastException * the e node cast exception */ public Object getStereotypeValue(Element elt, String stereotype, String propertyName) { // search with real stereotype Stereotype stereotypeFound = getStereotype(elt, stereotype); if (stereotypeFound == null) { return null; } else { return elt.getValue(stereotypeFound, propertyName); } } /** * Verify if an Element have a stereotype. Use keyword and profile to find * stereotype. Multiple stereotype are allow. * * @param elt * Element used. * @param stereotype * Stereotype to search. * * @return true if found. false else. * * @throws ENodeCastException * the e node cast exception */ public boolean hasStereotype(Element elt, String stereotype) { return (getStereotype(elt, stereotype) != null); } }