UML Profiles

From PATSWiki

Plug-ins can define their own profiles.

Table of contents

Create a Profile with EMF and UML2

An Introduction to UML Profiles (http://dev.eclipse.org/viewcvs/indextools.cgi/%7Echeckout%7E/uml2-home/docs/articles/Introduction_to_UML2_Profiles/article.html)

Note:

  • If the "define" operation does not work, check if the profile has a name!
  • If the menu looks different than in the tutorial, check that yu installed the complete UML2 distribution
  • Ramses supports only Boolean (uml::Boolean) and String (uml::String) values for the stereotype properties. They are mapped to their counterparts in Java, java.lang.boolean and java.lang.String, resp.

Build an Extension for the Profile

  • Register an entry in the path map.

This is necessary that the UML2 resources do not point to any physical location when referring to the profile, but to the path map. To do so, include the following in plugin.xml, with the source and target attributes adjusted to your profile.

  <extension id="ramse-profiles" point="org.eclipse.emf.ecore.uri_mapping">
     <mapping source="pathmap://RAMSES_PROFILES/"
         target="platform:/plugin/no.ntnu.item.ramses.core/profiles/">
     </mapping>
  </extension>


  • Instead of RAMSES_PROFILES use your own path map. Make sure that you never change this path map after a profile is published and that it does not conflict with any other path maps of existing profiles.
  • Instead of no.ntnu.item.ramses.core use the name of your plug-in that contains the profile.
  • Instead of /profiles/ use the path that leads to the folder in your plug-in that contains your profiles, but /profiles is a good place to put them.

Which EMF plugins must be imported to do this?

  • Register the profile in the Ramses Core.
  <extension point="no.ntnu.item.ramses.core.profile" id="profiles" >
     <profile uri="pathmap://RAMSES_PROFILES/ramses.profile.uml2"/>
  </extension>
  • Instead of RAMSES_PROFILES use your own path map (see above).
  • Instead of ramses.profile.uml2 use the name of the file containing the profile.

Get Values of the Stereotype

The tutorial (http://dev.eclipse.org/viewcvs/indextools.cgi/%7Echeckout%7E/uml2-home/docs/articles/Introduction_to_UML2_Profiles/article.html) mentioned above also explains how to get the values of the stereotype properties. Ramses offers two helper methods for String and Boolean properties, where you just have to give the element, the name of the profile, the name of the stereotype and the name of the property.

  • Note that the tutorial refers to full qualified names, but to our knowledge it works with simple names (we have to check that...)
  • no.ntnu.item.ramses.core.helper.UMLProfileHelper:
public static String getStereotypeStringValue(
    Element element, 
    String profileName, 
    String stereotypeName, 
    String propertyName); 
public static Boolean getStereotypeBooleanValue(
    Element element, 
    String profileName, 
    String stereotypeName, 
    String propertyName);

Both methods return null, if:

  • the profile could not be found
  • the profile is applied in a wrong version
  • the stereotype is not applied

In these cases, warn the user and/or use default values.

Set Values of the Stereotypes

In the Stereotype View users can set the value of the stereotype properties (if they are either Boolean or Strings). You can also set them in some of your operations:

public static void setStereotypeValue(
    Element element, 
    String profileName, 
    String stereotypeName, 
    String propertyName, 
    String value);
public static void setStereotypeValue(
    Element element, 
    String profileName, 
    String stereotypeName, 
    String propertyName, 
    boolean value);

Things to remember when working with Profiles

  • Always Define your profile again whenever you have made changes to it. ("UML Editor"->"Profile"->"Define").