1 | public static Object getTagDefinition(String tdName) { | | 1 | /** |
2 | // look for it in all the models | | 2 | * Helper method that gets a stereotype for the given model |
3 | Collection models = getModels(); | | 3 | * element with the given name. |
4 | for (Object model : models) { | | 4 | * |
5 | Collection tagDefinitions = getModelManagementHelper(). | | 5 | * TODO: this might be a performance bottleneck. If so, caching of |
6 | getAllModelElementsOfKindWithModel(model, | | 6 | * stereotypes for model elements by their stereotypes names could fix it. |
7 | Model.getMetaTypes().getTagDefinition()); | | 7 | * |
8 | for (Object td : tagDefinitions) { | | 8 | * @param modelElement The model element for which to look for the |
9 | if (tdName.equals(getFacade().getName(td))) { | | 9 | * stereotype with the given name |
10 | return td; | | 10 | * @param stereotypeName The name of the stereotype. |
11 | } | | 11 | * @return the stereotype model element or null if not found. |
12 | } | | 12 | */ |
13 | } | | 13 | private Object getStereotype(Object modelElement, String stereotypeName) { |
14 | // create it in an editable model if one is found | | 14 | Object stereotype = null; |
15 | Collection editableModels = getEditableModels(); | | 15 | Collection stereotypes = StereotypeUtility.getAvailableStereotypes( |
16 | Iterator it = editableModels.iterator(); | | 16 | modelElement); |
17 | if (it.hasNext()) { | | 17 | for (Iterator it = stereotypes.iterator(); it.hasNext();) { |
18 | return getExtensionMechanismsFactory().buildTagDefinition(tdName, | | 18 | Object candidateStereotype = it.next(); |
19 | null, it.next()); | | 19 | if (getFacade().getName(candidateStereotype).equals( |
20 | } | | 20 | stereotypeName)) { |
21 | throw new IllegalStateException("Unable to find an editable model."); | | 21 | stereotype = candidateStereotype; |
22 | } | | 22 | break; |
| | | 23 | } |
| | | 24 | } |
| | | 25 | return stereotype; |
| | | 26 | } |