Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrschnekenbu2013-08-05 15:24:14 +0000
committerrschnekenbu2013-08-05 15:24:14 +0000
commita8c7e08886617513e552f0ae28aa0bd577d74cc2 (patch)
treedd2fba79050856187a5d162459174d250d2314dc /sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource
parent7930eeaf5707a5083f209d1fa0ce9c83dbad12c6 (diff)
downloadorg.eclipse.papyrus-a8c7e08886617513e552f0ae28aa0bd577d74cc2.tar.gz
org.eclipse.papyrus-a8c7e08886617513e552f0ae28aa0bd577d74cc2.tar.xz
org.eclipse.papyrus-a8c7e08886617513e552f0ae28aa0bd577d74cc2.zip
First version of the module to manage profile application in different
resources
Diffstat (limited to 'sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource')
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.classpath7
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.project28
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/META-INF/MANIFEST.MF19
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/about.html28
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/build.properties7
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/conception.textile27
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/documentation.pdoc4
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/plugin.xml16
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/Activator.java55
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/AbstractStereotypeApplicationLocationStrategy.java35
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExtendedProfileApplicationHelper.java34
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/IStereotypeApplicationLocationStrategy.java44
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/OneResourceOnlyStrategy.java104
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java93
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ResourcePerProfileStrategy.java253
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StandardApplicationLocationStrategy.java64
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StrategyRegistry.java62
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/model/StereotypeApplicationExternalResourceModel.java238
19 files changed, 1125 insertions, 0 deletions
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.classpath b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.project b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.project
new file mode 100644
index 00000000000..ac80b81cd93
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.uml.profile.externalresource</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.settings/org.eclipse.jdt.core.prefs b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..c537b63063c
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/META-INF/MANIFEST.MF b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..bda54b83e1d
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: UML2 Profile Management in External Resources (Incubation)
+Bundle-SymbolicName: org.eclipse.papyrus.uml.profile.externalresource;singleton:=true
+Bundle-Version: 0.10.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.uml.profile.externalresource.Activator
+Bundle-Vendor: Eclipse Modeling Project
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.10.0",
+ org.eclipse.uml2.uml;bundle-version="4.1.0",
+ org.eclipse.papyrus.infra.core;bundle-version="0.10.0",
+ org.eclipse.papyrus.uml.tools.utils;bundle-version="0.10.1",
+ org.eclipse.papyrus.uml.tools;bundle-version="0.10.1",
+ org.eclipse.emf.transaction;bundle-version="1.4.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.papyrus.uml.profile.externalresource,
+ org.eclipse.papyrus.uml.profile.externalresource.helper
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/about.html b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/about.html
new file mode 100644
index 00000000000..d35d5aed64c
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/build.properties b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/build.properties
new file mode 100644
index 00000000000..4b957fe857b
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/build.properties
@@ -0,0 +1,7 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ documentation.pdoc,\
+ plugin.xml
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/conception.textile b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/conception.textile
new file mode 100644
index 00000000000..eb6708f2bab
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/conception.textile
@@ -0,0 +1,27 @@
+
+h1. Conception of the external profile application management module
+
+
+h2. Context
+
+Currently, profile applications are serialized within the same file as the model itself. This feature will enable to serialize profile applications within a dedicated file. This feature will be an option that the user may configure within the Papyrus preferences. If one applies several profiles on a model, each profile application is serialized within its own resource. It has to be possible to switch from one configuration to the other, i.e. either to externalize profile applications or to internalize them.
+Control mode shall be taken into consideration here and should continue to work correctly.
+
+Enable external profile application
+The purpose of this task will consist in patching the UML2 component in order this latter can fully support the possibility to apply profiles on UML models by serializing this profile application in a separate file and vice-versa. Papyrus UI has also to be enriched in order to enable the user to configure Papyrus in order to enable or disable this option. The process will be reversible, i.e. profiles would be serializable individually in or out the model resources. In addition, the tool will also support the ability to apply several times the same profile. In case of a profile has been applied several time (values of the stereotype properties would be possibly different in that case), only one profile application is defined as part of the current configuration.
+Control mode extension
+This task will consist in analyzing the impact of the externalization of profile serialization and update its design in order the control mode can still run correctly in that case. The test set of the control mode will also be extended to cover this new use case.
+
+h2. Thoughts
+
+# currently, the profile application themselves are part of the model (this is a real element in the UML metamodel). the stereotype applications are located in the same resource as the model, at the same level as the model itself. The goal of this module is to separate the stereotype applications from the model resource and to put them in one or several external resources.
+# Several strategies are possible to manage profile applications in external resources. Each profile application can be saved in a separated resource, or all profile applications can have their own resource. This would ease the management of view points on the model (loading or not a given profile would be easy, and so specific domain concepts would be present or not. The sub profiles should also be taken into account: do each sub-profile need its own resource, or the resource is managed by the main profile (example of SysML)
+# The naming of the resource: name of the profile should be present. the name of the UML element on which the profile is applied should be used, in order to be able to have several external resources for the same profile in case of control mode. Should the version of the profile be present also ?
+# integration with the control mode: should one/several new resource be created when splitting the model?
+# integration with rename/copy files
+# integration with copy paste: does the current extension of the copy/paste work with this module?
+
+h2. Current external mechanism limitations
+
+UML2 module provides a framework for externalization of the stereotype applications, but this mechanism is rather basic. It relies with a singleton helper, referenced in the java system properties. If the externalization is done, it will be done for all components in the installation relying on UML2 metamodel, not only Papyrus models. Moreover, only one Eclipse component can provide a customization. If another component that Papyrus relies on that extension mechanism, only one will work at the same time.
+
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/documentation.pdoc b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/documentation.pdoc
new file mode 100644
index 00000000000..a971d3ea382
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/documentation.pdoc
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<doc:Documentation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:doc="http://www.eclipse.org/papyrus/documentation/plugin/documentation" description="Plugin to manage profile and stereotype application in external resources">
+ <referent firstName="Remi" lastName="Schnekenburger" eMail="remi.schnekenburger@cea.fr" currentCompany="CEA LIST"/>
+</doc:Documentation>
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/plugin.xml b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/plugin.xml
new file mode 100644
index 00000000000..59f092516b4
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/plugin.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.papyrus.infra.core.model">
+ <model
+ classname="org.eclipse.papyrus.uml.profile.externalresource.model.StereotypeApplicationExternalResourceModel">
+ <dependency>
+ <loadAfter
+ identifier="org.eclipse.papyrus.infra.core.resource.uml.UmlModel">
+ </loadAfter>
+ </dependency>
+ </model>
+ </extension>
+
+</plugin>
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/Activator.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/Activator.java
new file mode 100644
index 00000000000..5875dc1d46a
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/Activator.java
@@ -0,0 +1,55 @@
+package org.eclipse.papyrus.uml.profile.externalresource;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.profile.externalresource"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /** logger helper */
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ log = null;
+ super.stop(context);
+ }
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/AbstractStereotypeApplicationLocationStrategy.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/AbstractStereotypeApplicationLocationStrategy.java
new file mode 100644
index 00000000000..f6521a180a6
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/AbstractStereotypeApplicationLocationStrategy.java
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.helper;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Element;
+
+
+/**
+ * Abstract strategy class for stereotype application location
+ */
+public abstract class AbstractStereotypeApplicationLocationStrategy implements IStereotypeApplicationLocationStrategy {
+
+ /**
+ * @param element
+ * @param definition
+ * @return
+ */
+ protected EList<EObject> getDefaultContainmentList(Element element, EClass definition) {
+ return element.eResource().getContents();
+ }
+
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExtendedProfileApplicationHelper.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExtendedProfileApplicationHelper.java
new file mode 100644
index 00000000000..d95aab82d65
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExtendedProfileApplicationHelper.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.helper;
+
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.util.UMLUtil.ProfileApplicationHelper;
+
+
+/**
+ * Extended profile application helper for Papyrus tool.
+ * <P>
+ * When this helper is activated, profiles are located in external resources
+ * </P>
+ */
+public class ExtendedProfileApplicationHelper extends ProfileApplicationHelper {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Iterable<Package> getOtherApplyingPackages(Package package_) {
+ return super.getOtherApplyingPackages(package_);
+ }
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/IStereotypeApplicationLocationStrategy.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/IStereotypeApplicationLocationStrategy.java
new file mode 100644
index 00000000000..2f880b9db54
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/IStereotypeApplicationLocationStrategy.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.helper;
+
+import java.util.Set;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Element;
+
+
+/**
+ * Interface implemented by all strategies in charge of the management of resources for stereotype applications
+ */
+public interface IStereotypeApplicationLocationStrategy {
+
+ /**
+ * Returns the containment list in which stereotype applications should be read/added.
+ * @param element the stereotyped element
+ * @param definition the definition of the stereotype to apply
+ * @return the containment list for the new stereotype application. if any problem, this will be the default location (direct content of the resource containing the element)
+ */
+ public EList<EObject> getContainmentList(Element element, EClass definition);
+
+ /**
+ * Returns the list of URIs of the resources in which stereotype applications are placed.
+ * @param root element of the model from which all profile applications are found
+ * @return the list of URIS, an empty collection if not URIs are found.
+ */
+ public Set<URI> getProfileApplicationResourceURIs(EObject root);
+
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/OneResourceOnlyStrategy.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/OneResourceOnlyStrategy.java
new file mode 100644
index 00000000000..1ea97abe14a
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/OneResourceOnlyStrategy.java
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.helper;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ModelUtils;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.resource.UMLResource;
+
+/**
+ * Strategy for only one resource for all profile applications
+ */
+public class OneResourceOnlyStrategy extends AbstractStereotypeApplicationLocationStrategy {
+
+ /** identifier of this strategy */
+ public static final String ID = "OneResourceOnlyStrategy"; //$NON-NLS-1$
+
+ /** default extension for the profile URI */
+ public static final String PROFILE_DEFAULT_EXTENSION = "profiles";
+
+ /** singleton instance */
+ private static OneResourceOnlyStrategy instance;
+
+ /**
+ * Returns the singleton instance for this strategy
+ *
+ * @return the singleton instance for this strategy
+ */
+ public static OneResourceOnlyStrategy getInstance() {
+ if(instance == null) {
+ instance = new OneResourceOnlyStrategy();
+ }
+ return instance;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EList<EObject> getContainmentList(Element element, EClass definition) {
+ // 1. only one resource => look if there is a custom name. Otherwise, use a standard name for the resource
+ // compute the URI of the resource
+ Resource baseResource = element.eResource();
+ if(baseResource == null) {
+ return null;
+ }
+ URI newURI = getProfileResourceURI(element, definition);
+ ResourceSet resourceSet = baseResource.getResourceSet();
+ if(resourceSet instanceof ModelSet && newURI != null) {
+ ModelSet modelSet = (ModelSet)resourceSet;
+ Resource resource = ModelUtils.getOrCreateResource(modelSet, true, newURI, UMLResource.UML_CONTENT_TYPE_IDENTIFIER);
+ return resource.getContents();
+ }
+ // by default, return the resource containing the element
+ return getDefaultContainmentList(element, definition);
+ }
+
+ /**
+ * @param element
+ * @param definition
+ * @return
+ */
+ protected URI getProfileResourceURI(Element element, EClass definition) {
+ if(element.eResource() !=null) {
+ URI uri = element.eResource().getURI();
+ if(uri !=null) {
+ return uri.trimFileExtension().appendFileExtension(PROFILE_DEFAULT_EXTENSION);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<URI> getProfileApplicationResourceURIs(EObject root) {
+ URI uri = root.eResource().getURI();
+ if(uri !=null) {
+ return Collections.singleton(uri.trimFileExtension().appendFileExtension(PROFILE_DEFAULT_EXTENSION));
+ }
+ return Collections.emptySet();
+ }
+
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java
new file mode 100644
index 00000000000..f1398a885fe
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.helper;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper;
+
+
+/**
+ * Specific Stereotype Application Helper for Papyrus tool. If it detects the model is not a model handled by Papyrus, it will delegate to the standard Stereotype application helper.
+ */
+public class PapyrusStereotypeApplicationHelper extends StereotypeApplicationHelper {
+
+ /** Key for the location strategy value */
+ public static final String LOCATION_STRATEGY_KEY = "locationStrategy";
+
+ /** source for the eannotation that is used to store specific URI for stereotype application resource */
+ public static final String PAPYRUS_EXTERNAL_RESOURCE_EANNOTATION_SOURCE = "http://www.eclipse.org/papyrus/uml/profile/externalresource"; //$NON-NLS-1$
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EObject applyStereotype(Element element, EClass definition) {
+ return super.applyStereotype(element, definition);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean addToContainmentList(Element element, EObject stereotypeApplication) {
+ return super.addToContainmentList(element, stereotypeApplication);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected EList<EObject> getContainmentList(Element element, EClass definition) {
+ // 1. find the current strategy used for the model element
+ // 2. use the strategy to find the resource and the containment list
+ // 3. if no strategy found, return usual strategy ==> stereotype application are directly contained by the resource containing the stereotyped element.
+ IStereotypeApplicationLocationStrategy locationStrategy = getCurrentLocationStrategy(element);
+ if(locationStrategy ==null) {
+ return StandardApplicationLocationStrategy.getInstance().getContainmentList(element, definition);
+ }
+ return locationStrategy.getContainmentList(element, definition);
+ }
+
+ /**
+ * Returns the location strategy to use for the given couple element/definition
+ * @param element the stereotyped element
+ * @param definition the definition of the stereotype to be applied
+ * @return the location strategy or <code>null</code> if none was found
+ */
+ public static IStereotypeApplicationLocationStrategy getCurrentLocationStrategy(EObject element) {
+ EObject container = EcoreUtil.getRootContainer(element, true);
+ if(container instanceof Element) {
+ EAnnotation annotation = ((Element)container).getEAnnotation(PAPYRUS_EXTERNAL_RESOURCE_EANNOTATION_SOURCE);
+ if(annotation == null) {
+ return null;
+ }
+
+ String location = annotation.getDetails().get(LOCATION_STRATEGY_KEY);
+ if(location == null) {
+ return null;
+ }
+
+ IStereotypeApplicationLocationStrategy strategy = StrategyRegistry.getInstance().getStrategy(location);
+ if(strategy != null) {
+ return strategy;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ResourcePerProfileStrategy.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ResourcePerProfileStrategy.java
new file mode 100644
index 00000000000..6fb861b60f7
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ResourcePerProfileStrategy.java
@@ -0,0 +1,253 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.helper;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ModelUtils;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+import org.eclipse.uml2.uml.resource.UMLResource;
+
+/**
+ * Strategy that uses one resource per profile application
+ */
+public class ResourcePerProfileStrategy implements IStereotypeApplicationLocationStrategy {
+
+ /** default resource name */
+ protected static final String DEFAULT_RESOURCE_NAME = "default"; //$NON-NLS-1$
+
+ /** default resource extension */
+ protected static final String DEFAULT_RESOURCE_EXTENSION = "profile"; //$NON-NLS-1$
+
+ /** key for the value of the eannotation that is used to store specific URI for stereotype application resource */
+ public static final String SPECIFIC_URI_EANNOTATION_KEY = "specificURI"; //$NON-NLS-1$
+
+ /** identifier of this strategy */
+ public static final String ID = "ResourcePerProfileStrategy"; //$NON-NLS-1$
+
+ /** singleton instance */
+ private static ResourcePerProfileStrategy instance;
+
+ /**
+ * Returns the singleton instance for this strategy
+ *
+ * @return the singleton instance for this strategy
+ */
+ public static ResourcePerProfileStrategy getInstance() {
+ if(instance == null) {
+ instance = new ResourcePerProfileStrategy();
+ }
+ return instance;
+ }
+
+ /**
+ * Returns the resource where the stereotype application should be added for the given couple element/stereotype
+ *
+ * @param element
+ * the stereotyped element
+ * @param definition
+ * the definition of the stereotype to apply
+ * @return the resource where the stereotype application should be added
+ */
+ public Resource getStereotypeApplicationResource(Element element, EClass definition) {
+ // in this case, the resource is specific to the profile application.
+ // the profile application should give the right path.
+ // 1. retrieve profile application
+ // 2. ask it for the resource name (by default, it should give the name of the profile)
+ // 3. compute the resource name
+ // 4. ask to create on demand ?
+ // 5. return the content of this resource
+ ProfileApplication profileApplication = getProfileApplication(element, definition);
+ Resource baseResource = element.eResource();
+ if(baseResource==null) {
+ return null;
+ }
+ ResourceSet resourceSet = baseResource.getResourceSet();
+ if(resourceSet instanceof ModelSet) {
+ ModelSet modelSet = (ModelSet)resourceSet;
+ URI newURI = getProfileApplicationResourceURI(profileApplication, baseResource);
+ Resource resource = ModelUtils.getOrCreateResource(modelSet, true, newURI, UMLResource.UML_CONTENT_TYPE_IDENTIFIER);
+ return resource;
+ }
+ // by default, return the resource containing the element
+ return element.eResource();
+ }
+
+ /**
+ * Returns the specific URI indicated on the profile application
+ *
+ * @param profileApplication
+ * the profile application that should have stereotype applications in resource with specific URI
+ * @return the specific URI or <code>null</code>
+ */
+ protected URI getSpecificURI(ProfileApplication profileApplication, Resource baseResource) {
+ EAnnotation annotation = profileApplication.getEAnnotation(PapyrusStereotypeApplicationHelper.PAPYRUS_EXTERNAL_RESOURCE_EANNOTATION_SOURCE);
+ if(annotation != null) {
+ String value = annotation.getDetails().get(SPECIFIC_URI_EANNOTATION_KEY);
+ URI newURI = baseResource.getURI();
+ newURI = newURI.trimSegments(1);
+ newURI = newURI.appendSegment(value);
+ return newURI;
+ }
+ return null;
+ }
+
+ /**
+ * Checks if the profile application should use a specific URI for the steroetype application resources
+ *
+ * @param profileApplication
+ * profile application that should have stereotype applications in resource with specific URI
+ * @return <code>true</code> if a specific URI is specified for the profile application
+ */
+ protected boolean hasSpecificURI(ProfileApplication profileApplication) {
+ EAnnotation annotation = profileApplication.getEAnnotation(PapyrusStereotypeApplicationHelper.PAPYRUS_EXTERNAL_RESOURCE_EANNOTATION_SOURCE);
+ return annotation != null;
+ }
+
+ protected String getStereotypeApplicationResourceExtension(ProfileApplication profileApplication, boolean basedOnMainProfile) {
+ // 1. check if nested profiles have the same resource or if each nested profile has its own resource
+ // 2. deduce the name from the profile application
+ // 3. return the string. This will be the extension of the file
+ String resourceExtension = null;
+ if(profileApplication != null) {
+ Profile profile = profileApplication.getAppliedProfile();
+ if(profile != null) {
+ // if based on main profile => retrieve the main profile name.
+ // otherwise, returns the name of the profile
+ if(basedOnMainProfile) {
+ Profile parentProfile = profile;
+ while(parentProfile.getNestingPackage() instanceof Profile) {
+ parentProfile = (Profile)parentProfile.getNestingPackage();
+ }
+ resourceExtension = parentProfile.getName() + "Profile"; // warning, can not return an extension which is linked to another factory than a UML Factory
+ } else {
+ resourceExtension = profile.getName() + "Profile";
+ }
+ }
+ }
+ if(resourceExtension == null) {
+ resourceExtension = DEFAULT_RESOURCE_EXTENSION;
+ }
+ return resourceExtension;
+ }
+
+ protected String getStereotypeApplicationResourceName(ProfileApplication profileApplication, boolean basedOnMainProfile) {
+ // 1. check if nested profiles have the same resource or if each nested profile has its own resource
+ // 2. deduce the name from the profile application.
+ // 3. return the string. This will be the extension of the file
+ String resourceName = null;
+ if(profileApplication != null) {
+ Package applyingPackage = profileApplication.getApplyingPackage();
+ if(applyingPackage != null) {
+ resourceName = applyingPackage.eResource().getURI().trimFileExtension().lastSegment();
+ }
+ }
+ if(resourceName == null) {
+ resourceName = DEFAULT_RESOURCE_NAME;
+ }
+ return resourceName;
+ }
+
+ /**
+ * Returns the profile application for the given element on which the stereotype with specified definition is or will be applied
+ *
+ * @param element
+ * the UML element on which stereotype is applied
+ * @return the profile application or <code>null</code> if none was found.
+ */
+ protected ProfileApplication getProfileApplication(Element element, EClass definition) {
+ Package nearestPackage = element.getNearestPackage();
+ if(nearestPackage == null) {
+ return null;
+ }
+ List<ProfileApplication> profileApplications = nearestPackage.getAllProfileApplications();
+ for(ProfileApplication profileApplication : profileApplications) {
+ EPackage appliedDefinition = profileApplication.getAppliedDefinition();
+ List<EClassifier> classifiers = appliedDefinition.getEClassifiers();
+ if(classifiers != null && !classifiers.isEmpty() && classifiers.contains(definition)) {
+ return profileApplication;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EList<EObject> getContainmentList(Element element, EClass definition) {
+ Resource stereotypeApplicationResource = getStereotypeApplicationResource(element, definition);
+ if(stereotypeApplicationResource != null) {
+ return stereotypeApplicationResource.getContents();
+ }
+ // fallback: adds stereotype at the root of the UML resource.
+ Resource elementResource = element.eResource();
+ if(elementResource != null) {
+ return elementResource.getContents();
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<URI> getProfileApplicationResourceURIs(EObject root) {
+ Set<URI> uris = new HashSet<URI>();
+ // 1. retrieve all profile applications
+ // 2. retrieve all URI from all this profile applications
+ if(root instanceof Element && root.eResource()!=null) {
+ Package nearestPackage = ((Element)root).getNearestPackage();
+ if(nearestPackage != null) {
+ List<ProfileApplication> profileApplications = nearestPackage.getAllProfileApplications();
+ for(ProfileApplication profileApplication : profileApplications) {
+ URI newURI = getProfileApplicationResourceURI(profileApplication, root.eResource());
+ uris.add(newURI);
+ }
+ }
+ }
+ return uris;
+ }
+
+ protected URI getProfileApplicationResourceURI(ProfileApplication profileApplication, Resource baseResource) {
+ // test if it needs a specific name. Otherwise, it will use a default name
+ URI newURI = null;
+ if(hasSpecificURI(profileApplication)) {
+ newURI = getSpecificURI(profileApplication, baseResource);
+ }
+ if(newURI == null) {
+ URI baseURI = baseResource.getURI();
+ newURI = baseURI.trimSegments(1);
+ String resourceName = getStereotypeApplicationResourceName(profileApplication, true);
+ newURI = newURI.appendSegment(resourceName);
+ String extension = getStereotypeApplicationResourceExtension(profileApplication, true);
+ newURI = newURI.appendFileExtension(extension);
+ }
+ return newURI;
+ }
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StandardApplicationLocationStrategy.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StandardApplicationLocationStrategy.java
new file mode 100644
index 00000000000..1d75eaba828
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StandardApplicationLocationStrategy.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.helper;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Element;
+
+
+/**
+ * Usual stereotype application strategy
+ */
+public class StandardApplicationLocationStrategy implements IStereotypeApplicationLocationStrategy {
+
+ /** identifier of this strategy */
+ public static final String ID = "standardStrategy"; //$NON-NLS-1$
+
+ /** singleton instance */
+ protected static StandardApplicationLocationStrategy instance;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EList<EObject> getContainmentList(Element element, EClass definition) {
+ if(element.eResource() !=null) {
+ return element.eResource().getContents();
+ }
+ return null;
+ }
+
+ /**
+ * @return
+ */
+ public static StandardApplicationLocationStrategy getInstance() {
+ if(instance ==null) {
+ instance = new StandardApplicationLocationStrategy();
+ }
+ return instance;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<URI> getProfileApplicationResourceURIs(EObject root) {
+ return Collections.emptySet();
+ }
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StrategyRegistry.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StrategyRegistry.java
new file mode 100644
index 00000000000..07af6bfd0b7
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StrategyRegistry.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.helper;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Registry for all {@link IStereotypeApplicationLocationStrategy}.
+ */
+public class StrategyRegistry {
+
+ /** singleton instance */
+ private static StrategyRegistry instance;
+
+ /** map identifier - strategies */
+ private Map<String, IStereotypeApplicationLocationStrategy> registry;
+
+ /**
+ * Returns the singleton instance for this strategy
+ *
+ * @return the singleton instance for this strategy
+ */
+ public static StrategyRegistry getInstance() {
+ if(instance == null) {
+ instance = new StrategyRegistry();
+ instance.init();
+ }
+ return instance;
+ }
+
+ /**
+ * Initialize the strategy registry, reading extension points.
+ */
+ protected void init() {
+ // TODO: read extension points.
+ registry = new HashMap<String, IStereotypeApplicationLocationStrategy>();
+ registry.put(StandardApplicationLocationStrategy.ID, StandardApplicationLocationStrategy.getInstance());
+ registry.put(OneResourceOnlyStrategy.ID, OneResourceOnlyStrategy.getInstance());
+ registry.put(ResourcePerProfileStrategy.ID, ResourcePerProfileStrategy.getInstance());
+ }
+
+ /**
+ * Returns the strategy for the given identifier
+ * @param identifier identifier of the strategy
+ * @return the strategy found or <code>null</code> if none was found
+ */
+ public IStereotypeApplicationLocationStrategy getStrategy(String identifier) {
+ return registry.get(identifier);
+ }
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/model/StereotypeApplicationExternalResourceModel.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/model/StereotypeApplicationExternalResourceModel.java
new file mode 100644
index 00000000000..60a2f0b5ecb
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/model/StereotypeApplicationExternalResourceModel.java
@@ -0,0 +1,238 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.model;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.XMIResource;
+import org.eclipse.papyrus.infra.core.resource.AbstractBaseModel;
+import org.eclipse.papyrus.infra.core.resource.AbstractModel;
+import org.eclipse.papyrus.infra.core.resource.IModel;
+import org.eclipse.papyrus.infra.core.resource.IModelSnippet;
+import org.eclipse.papyrus.infra.core.resource.ModelUtils;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.uml.profile.externalresource.Activator;
+import org.eclipse.papyrus.uml.profile.externalresource.helper.IStereotypeApplicationLocationStrategy;
+import org.eclipse.papyrus.uml.profile.externalresource.helper.PapyrusStereotypeApplicationHelper;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.uml2.uml.resource.UMLResource;
+
+/**
+ * Model to manage stereotype applications in external resources.
+ */
+public class StereotypeApplicationExternalResourceModel extends AbstractModel implements IModel {
+
+ /** identifier of this IModel */
+ public static final String ID = "ExternalStereotypeApplicationModel";
+
+ /** list of resources for stereotype applications */
+ List<Resource> profileApplicationResources = new ArrayList<Resource>();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getIdentifier() {
+ return ID;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void createModel(IPath fullPath) {
+ throw new UnsupportedOperationException("CreateModel_IPath is not supported for " + getClass().getCanonicalName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void createModel(URI uri) {
+ throw new UnsupportedOperationException("CreateModel_URI is not supported for " + getClass().getCanonicalName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void loadModel(IPath path) {
+ loadModel(getPlatformURI(path));
+ }
+
+ /**
+ * Returns a platform resource URI of the given path
+ *
+ * @param path
+ * the path
+ * @return the uri
+ */
+ protected URI getPlatformURI(IPath path) {
+ return URI.createPlatformResourceURI(path.toString(), true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void loadModel(URI uri) {
+ List<Resource> resources = getResources(true);
+ for(Resource resource : resources) {
+ try {
+ if(!resource.isLoaded()) {
+ resource.load(null);
+ }
+ configureResource(resource);
+ profileApplicationResources.add(resource);
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ }
+ // call registered snippets
+ snippets.performStart(this);
+ }
+
+ /**
+ * Returns the dynamically computed list of resources in which stereotype applications should be located
+ *
+ * @return the list of resources in which stereotype applications should be located
+ */
+ protected List<Resource> getResources(boolean loadOnDemand) {
+ List<Resource> resources = new ArrayList<Resource>();
+ // get all profile applications resource to load from the strategy. do not care of the URI ?
+ UmlModel umlModel = (UmlModel)modelSet.getModel(UmlModel.MODEL_ID);
+ try {
+ if(umlModel != null && umlModel.lookupRoot() != null) {
+ EObject root = umlModel.lookupRoot();
+ IStereotypeApplicationLocationStrategy strategy = PapyrusStereotypeApplicationHelper.getCurrentLocationStrategy(root);
+ if(strategy != null) {
+ Set<URI> profileApplicationResourceURIs = strategy.getProfileApplicationResourceURIs(root);
+ for(URI resourceURI : profileApplicationResourceURIs) {
+ Resource resource = ModelUtils.getOrCreateResource(modelSet, loadOnDemand, resourceURI, UMLResource.UML_CONTENT_TYPE_IDENTIFIER);
+ resources.add(resource);
+ }
+ }
+ }
+ } catch (NotFoundException e) {
+ Activator.log.debug(e.getMessage());
+ return Collections.emptyList();
+ }
+ return resources;
+ }
+
+ protected void configureResource(Resource resource) {
+ if(resource instanceof XMIResource) {
+ ((XMIResource)resource).getDefaultSaveOptions().putAll(getSaveOptions());
+ ((XMIResource)resource).setEncoding(AbstractBaseModel.ENCODING);
+ }
+ }
+
+ protected Map<Object, Object> getSaveOptions() {
+ Map<Object, Object> saveOptions = new HashMap<Object, Object>();
+ // default save options.
+ saveOptions.put(XMIResource.OPTION_DECLARE_XML, Boolean.TRUE);
+ saveOptions.put(XMIResource.OPTION_PROCESS_DANGLING_HREF, XMIResource.OPTION_PROCESS_DANGLING_HREF_DISCARD);
+ saveOptions.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
+ saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
+ saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE);
+ saveOptions.put(XMIResource.OPTION_SKIP_ESCAPE_URI, Boolean.FALSE);
+ saveOptions.put(XMIResource.OPTION_ENCODING, "UTF-8");
+ //see bug 397987: [Core][Save] The referenced plugin models are saved using relative path
+ saveOptions.put(XMIResource.OPTION_URI_HANDLER, new org.eclipse.emf.ecore.xmi.impl.URIHandlerImpl.PlatformSchemeAware());
+ return saveOptions;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void importModel(IPath path) {
+ throw new UnsupportedOperationException("ImportModel_IPath is not supported for " + getClass().getCanonicalName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void importModel(URI uri) {
+ throw new UnsupportedOperationException("ImportModel_URI is not supported for " + getClass().getCanonicalName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void saveModel() throws IOException {
+ List<Resource> resources = getResources(true);
+ for(Resource resource : resources) {
+ if(!getModelManager().getTransactionalEditingDomain().isReadOnly(resource) && !ModelUtils.resourceFailedOnLoad(resource)) {
+ resource.save(getSaveOptions());
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void changeModelPath(IPath fullPath) {
+ throw new UnsupportedOperationException("changeModelPath is not supported for " + getClass().getCanonicalName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setModelURI(URI uri) {
+ throw new UnsupportedOperationException("setModelURI is not supported for " + getClass().getCanonicalName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void unload() {
+ // call registered snippets
+ snippets.performDispose(this);
+ List<Resource> resources = getResources(false);
+ for(Resource resource : resources) {
+ resource.unload();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addModelSnippet(IModelSnippet snippet) {
+ snippets.add(snippet);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<URI> getModifiedURIs() {
+ return Collections.emptySet();
+ }
+}

Back to the top