1 | /** | | 1 | /** |
2 | * Find a class in a package. If it does not exist, a new class is | | 2 | * Helper method that gets a stereotype for the given model |
3 | * created. | | 3 | * element with the given name. |
4 | * | | 4 | * |
5 | * @param mPackage Look in this package. | | 5 | * TODO: this might be a performance bottleneck. If so, caching of |
6 | * @param name The name of the class. | | 6 | * stereotypes for model elements by their stereotypes names could fix it. |
7 | * @return The class found or created. | | 7 | * |
8 | */ | | 8 | * @param modelElement The model element for which to look for the |
9 | private Object getClass(Object mPackage, String name) { | | 9 | * stereotype with the given name |
10 | Object mClass = null; | | 10 | * @param stereotypeName The name of the stereotype. |
11 | for (Object c : Model.getCoreHelper().getAllClasses(mPackage)) { | | 11 | * @return the stereotype model element or null if not found. |
12 | if (name.equals(Model.getFacade().getName(c))) { | | 12 | */ |
13 | mClass = c; | | 13 | private Object getStereotype(Object modelElement, String stereotypeName) { |
14 | break; | | 14 | Object stereotype = null; |
15 | } | | 15 | Collection stereotypes = StereotypeUtility.getAvailableStereotypes( |
16 | } | | 16 | modelElement); |
17 | if (mClass == null) { | | 17 | for (Iterator it = stereotypes.iterator(); it.hasNext();) { |
18 | mClass = Model.getCoreFactory().buildClass(name, mPackage); | | 18 | Object candidateStereotype = it.next(); |
19 | newElements.add(mClass); | | 19 | if (getFacade().getName(candidateStereotype).equals( |
20 | } | | 20 | stereotypeName)) { |
21 | return mClass; | | 21 | stereotype = candidateStereotype; |
22 | } | | 22 | break; |
| | | 23 | } |
| | | 24 | } |
| | | 25 | return stereotype; |
| | | 26 | } |