* @roseuid 3F26F54001BF
*/
protected RefObject lookupStereotypeDeclaration(Object object, String stereotypeName)
throws ModelException
{
RefObject modelElement = (RefObject)object;
// Get factory
RefClass stereotypeFactory = modelElement.refOutermostPackage().refPackage("Core").
refClass("Stereotype");
// Get all Core.Stereotype
Collection registeredStereotypes = stereotypeFactory.refAllOfClass();
// Get the baseClass
String baseClass = (String)modelElement.refClass().refMetaObject().refGetValue("name");
// Lookup for a matching concept
Iterator iter = registeredStereotypes.iterator();
while(iter.hasNext())
{
RefObject stereotypeElement = (RefObject)iter.next();
//System.out.println( " stereotype check '" + stereotypeElement.refGetValue("baseClass") + "'" );
if(stereotypeName.equals(stereotypeElement.refGetValue("name")))
{
Collection baseClasses = (Collection)stereotypeElement.refGetValue("baseClass");
// Also check the baseClass
if(baseClasses.contains(baseClass))
{
return stereotypeElement;
}
}
} // end loop
// Not found, create it and populate it.
RefObject stereotype = null;
try
{
stereotype = (RefObject)createInstance("Core.Stereotype");
}
catch(InstantiationException ex)
{
throw new ModelException(ex);
}
stereotype.refSetValue("name", stereotypeName);
Collection baseClasses = (Collection)stereotype.refGetValue("baseClass");
baseClasses.add(baseClass);
// Attach stereotype to first model, if any
Collection models = getAllOfClass("Model_Management.Model");
if(models.size()>0)
{
stereotype.refSetValue("namespace", models.iterator().next());
}
return stereotype;
}