Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Registering and loading a profile programatically (standalone)
Registering and loading a profile programatically (standalone) [message #1573733] Mon, 19 January 2015 22:47
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 412
Registered: March 2011
Senior Member
Hi. I'm trying to load a model with a profile in a standalone application.

I've followed the tutorial at

but that still doesn't clarify how to register a third-party profile.

Some related threads suggest looking at UMLResourcesUtil to see how standard profiles are registered. Following the pattern there, I manage to register the profile (see attached file), and at first it seems to work, but as soon as I try to apply it, I get the following exception:

applying profile: org.eclipse.uml2.uml.internal.impl.ProfileImpl@3e5c7b6b (name: UMLRealTime, visibility: <unset>) (URI:
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(
	at org.eclipse.uml2.uml.util.UMLUtil.getProfile(
	at org.eclipse.uml2.uml.util.UMLUtil.getNamedElement(
	at org.eclipse.uml2.uml.util.UMLUtil.getNamedElement(
	at org.eclipse.uml2.uml.util.UMLUtil.getStereotype(
	at org.eclipse.uml2.uml.util.UMLUtil.getStereotype(
	at org.eclipse.uml2.uml.internal.operations.ElementOperations.getStereotypeApplications(
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.getStereotypeApplications(
	at org.eclipse.uml2.uml.internal.operations.PackageOperations.applyProfile(
	at org.eclipse.uml2.uml.internal.impl.PackageImpl.applyProfile(
	at eposse.experiments.profiletest.ProfileTest.applyProfiles(
	at eposse.experiments.profiletest.ProfileTest.main(

If I comment out the line applying the profiles, I still get the same exception when invoking "getAppliedStereotypes".

What's the problem what am I doing wrong?


public class ProfileTest {

    static String UMLRT_PROFILE_ID = "org.eclipse.papyrus.umlrt";
    static String UMLRT_NS_URI = UMLRealTimePackage.eNS_URI; //""
    static UMLRealTimePackage UMLRT_PKG = UMLRealTimePackage.eINSTANCE;
    static String UMLRT_PATHMAP = "pathmap://UML_RT_PROFILE/uml-rt.profile.uml";
    static ResourceSet resourceSet;
    public static void main(String[] args) throws IOException {
        String modelName = "EmptyCapsule";
        String modelProjectName = "EmptyCapsule";
        String projectContainer = "../../../git4/umlrt.general";
        Model model = loadModel(projectContainer, modelProjectName, modelName);
        for (Element element: model.allOwnedElements()) {
            System.out.println("element = " + element);
            System.out.println("  applicable stereotypes = " + element.getApplicableStereotypes());
            System.out.println("  applied stereotypes = " + element.getAppliedStereotypes());
    static void init() {
        // Create the resource set
        resourceSet = new ResourceSetImpl();
        // Initialize global registry
        // Register profile package in the resourceSet package registry
        resourceSet.getPackageRegistry().put(UMLRT_NS_URI, UMLRT_PKG);
        // Register the profile's NS_URI to its pathmap location
        UMLPlugin.getEPackageNsURIToProfileLocationMap().put(UMLRT_NS_URI, URI.createURI(UMLRT_PATHMAP));
        // Find the plugin that contains the profile
        PluginFinder pluginFinder = new PluginFinder(UMLRT_PROFILE_ID);
        String umlrtProfileLocation = pluginFinder.get(UMLRT_PROFILE_ID) + "umlProfile/uml-rt.profile.uml";
        // Register the actual profile location with the URIConverter
        resourceSet.getURIConverter().getURIMap().put(URI.createURI(UMLRT_PATHMAP), URI.createURI(umlrtProfileLocation));

    static Model loadModel(String projectContainer, String projectName, String modelName) throws IOException {
        File projectContainerPath = new File(projectContainer);
        String basePath = projectContainerPath.getCanonicalPath();
        URI baseURI = URI.createURI(basePath);
        URI fullURI = baseURI
        Resource resource = resourceSet.getResource(fullURI, true);
        return (Model) EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE);

    static void applyProfiles(Model model) {
        for (ProfileApplication profileApplication : model.getProfileApplications()) {
            Profile profile = profileApplication.getAppliedProfile();
            System.out.println("applying profile: " + profile);

[Updated on: Mon, 19 January 2015 22:48]

Report message to a moderator

Previous Topic:Stereotype owning two specialization
Next Topic:Registering and loading a profile programatically (standalone)
Goto Forum:

Current Time: Sun Jun 26 04:18:27 GMT 2022

Powered by FUDForum. Page generated in 0.01544 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top