[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.modeling.mdt.uml2.uml] Re: Problem saving model with stereotypes

Richard,

The article needs to be updated. Try modifying the save method so that it 
looks like this:

 protected static void save(org.eclipse.uml2.uml.Package package_, URI uri) 
{
  Resource resource = RESOURCE_SET.createResource(uri);
  EList contents = resource.getContents();

  contents.add(package_);

  for (Iterator allContents = UMLUtil.getAllContents(package_, true,
   false); allContents.hasNext();) {

   EObject eObject = (EObject) allContents.next();

   if (eObject instanceof Element) {
    contents
     .addAll(((Element) eObject).getStereotypeApplications());
   }
  }

  try {
   resource.save(null);

   out("Done.");
  } catch (IOException ioe) {
   err(ioe.getMessage());
  }
 }

Kenn

"Richard Craddock" <richard.craddock@xxxxxxxxxxxxxxxxxxxxxxx> wrote in 
message news:e7b05bb7c27813167585b51d892c8dd2$1@xxxxxxxxxxxxxxxxxx
> Hi there,
>
> I'm creating a UML2 model, in which I'm applying some stereotypes to a 
> Class. On the surface this appears to work fine, by which I mean that as I 
> iterate over the model, I can see that my Class has the stereotype, *BUT* 
> when I save the model, the stereotypes do not appear in my .uml file.
>
> Here's what I'm doing..
>
> clazz.applyStereotype(meS);
> as = clazz.getAppliedStereotypes();
> for (int i=0;i<as.size();i++){
>    Stereotype appliedStereo = (Stereotype)as.get(i);
>    out.println("Applied stereotypes : " 
> +appliedStereo.getQualifiedName());
>    for (int s=0;s<appliedStereo.getOwnedAttributes().size();s++){
>        Property p = (Property) appliedStereo.getOwnedAttributes().get(s);
>        if (p.getName().equals("value")){
>            clazz.setValue((Stereotype)as.get(i), p.getName(), "hello" );
>            out.println("Attr Val " +clazz.getValue((Stereotype)as.get(i), 
> p.getName()));
>        }
>    }
> }
>
> In my log, I get :
>
> Applied stereotypes : withArray.Profile::managedEntity
> Attr Val hello
>
> Which seems to say that the Class has the sterotypes applied OK, but 
> there's no sterotypes in the output when I save the model. The file 
> contains the classes and attributes on it.. (My "save" method is taken 
> direct from the "Getting started" tutorial.)
>
> Any help greatly appreciated.
>
> Richard
>
>
>
>
>