summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-05-06 08:11:40 (EDT)
committerBenoit Maggi2014-05-06 08:11:40 (EDT)
commitc3de50fff9b6b3bb30928f5a76d9dc76933124d8 (patch)
tree592ad4ad213a6c144e9fa9528f3dc1dbf4856e7f
parent5d3aa60ec10de3fc6965e9047310a28a99c1bbb7 (diff)
downloadorg.eclipse.papyrus-c3de50fff9b6b3bb30928f5a76d9dc76933124d8.zip
org.eclipse.papyrus-c3de50fff9b6b3bb30928f5a76d9dc76933124d8.tar.gz
org.eclipse.papyrus-c3de50fff9b6b3bb30928f5a76d9dc76933124d8.tar.bz2
Clean - Add missing LIFL header & add missing //$NON-NLS-1$refs/changes/41/26041/1
Change-Id: Ibf31e2cbfdc5f394163db3245902e530d041fe5a Change-Id: Iaa704d756b1d9762d87bcf0aa252e60add3c8482 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/contentoutline/ContentOutlineRegistry.java526
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelManagerServiceFactory.java224
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelMngrServiceFactory.java202
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/PageMngrServiceFactory.java140
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageIconsRegistry.java230
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java178
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/ExtensionUtils.java182
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorDescriptorExtensionFactory.java162
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/PluggableEditorFactoryReader.java280
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/lifecycleevents/SaveAndDirtyService.java1062
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/listenerservice/ModelListenerManager.java260
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/BadStateException.java84
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedService.java196
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedServicePart.java160
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ExtensionServicesRegistry.java402
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IService.java94
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IServiceFactory.java66
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceDescriptor.java612
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceException.java124
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceMultiException.java288
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceNotFoundException.java115
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceStartKind.java46
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceState.java38
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java1442
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/PapyrusImageUtils.java134
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java324
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForWorkbenchPage.java124
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/BadStateException.java109
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/DescriptorsCache.java716
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServiceDescriptorsWithIdProvider.java1068
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServicesRegistry.java402
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IService.java94
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IServiceFactory.java66
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptor.java612
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorUtils.java290
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorsWithIdProviderCollection.java514
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceException.java124
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceMultiException.java288
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceNotFoundException.java115
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceRegistryFactory.java452
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceStartKind.java46
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceState.java38
-rw-r--r--plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServicesRegistry.java2746
43 files changed, 7811 insertions, 7564 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/contentoutline/ContentOutlineRegistry.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/contentoutline/ContentOutlineRegistry.java
index deabb0c..8a96ab4 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/contentoutline/ContentOutlineRegistry.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/contentoutline/ContentOutlineRegistry.java
@@ -1,263 +1,263 @@
-/*****************************************************************************
- * Copyright (c) 2008 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.core.contentoutline;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.papyrus.infra.core.editor.BackboneException;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.extension.BadClassNameException;
-import org.eclipse.papyrus.infra.core.extension.NotFoundException;
-import org.eclipse.papyrus.infra.core.extension.diagrameditor.EditorDescriptorExtensionFactory;
-import org.osgi.framework.Bundle;
-
-public class ContentOutlineRegistry {
-
- /** ID of the editor extension (schema filename) */
- public static final String EDITOR_EXTENSION_ID = "papyrusContentOutline";
-
- private static String classAttributeName = "class";
-
- private static String actionBarContributorIdPropertyName = "actionBarContributorId";
-
- /** Namespace where to look for the extension points. */
- protected String extensionPointNamespace;
-
- /**
- * The selected content outline.
- */
- protected IPapyrusContentOutlinePage contentOutline;
-
- /**
- * Associated editor.
- */
- private IMultiDiagramEditor multiEditor;
-
- /**
- * Constructor. defaultContext, input and site are explicitly required in
- * order be sure that they are initialized. The multiEditor should be
- * initialized. In particular, getEditorSite(), getEditorInput() and
- * getDefaultContext() should return initialized values.
- *
- * @param multiEditor
- * @param defaultContext
- * @param input
- * @param site
- * @param extensionPointNamespace
- */
- public ContentOutlineRegistry(IMultiDiagramEditor multiEditor, String extensionPointNamespace) {
- this.multiEditor = multiEditor;
- this.extensionPointNamespace = extensionPointNamespace;
- }
-
- /**
- * Returns the single instance of the content outline. Creates one if
- * necessary.
- *
- * @return the contentOutline the single instance of the content outline
- * @throws BackboneException
- * exception thrown when the outline can not be created.
- */
- public IPapyrusContentOutlinePage getContentOutline() throws BackboneException {
- if(contentOutline == null) {
- createContentOutline();
- }
- return contentOutline;
- }
-
- /**
- * Return the {@link ContentOutlineDescriptor} with the highest priority.
- *
- * @return
- * @throws BackboneException
- * @throws NotFoundException
- * If no ContentOutline can be found in extensions
- */
- private ContentOutlineDescriptor getContentOutlineDescriptor() throws BackboneException {
- IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, EDITOR_EXTENSION_ID);
- ContentOutlineDescriptor found = null;
-
- // look for the one with the highest priority
- for(IConfigurationElement ele : configElements) {
- ContentOutlineDescriptor desc = new ContentOutlineDescriptor(ele);
- if(desc.isHigher(found)) {
- found = desc;
- }
- }
-
- // Instanciate the object
- if(found == null) {
- throw new NotFoundException("No ContentOutline registered.");
- }
-
- return found;
-
- }
-
- /**
- * Creates the content outline from the selected extension.
- *
- * @throws BackboneException
- * exception thrown when the outline can not be created.
- */
- private void createContentOutline() throws BackboneException {
-
- ContentOutlineDescriptor found = getContentOutlineDescriptor();
- // Instanciate the object
- if(found != null) {
- contentOutline = found.createContentOutlinePage();
- }
- }
-
- /**
- * Inner Descriptor for content outline. This class load data from Eclipse
- * extension mechanism TODO Change the parent class. It is here just to have
- * quick code.
- */
- protected class ContentOutlineDescriptor extends EditorDescriptorExtensionFactory {
-
- private int priority;
-
- private String className;
-
- private String actionBarContributorID;
-
- private IConfigurationElement element;
-
- /**
- * Instance is created when requested.
- */
- protected IPapyrusContentOutlinePage instance = null;
-
- /**
- * Create a descriptor backuped by the config element.
- */
- protected ContentOutlineDescriptor(IConfigurationElement element) throws BackboneException {
- String tagName = "contentoutline";
- checkTagName(element, tagName);
- this.className = element.getAttribute(classAttributeName);
- this.actionBarContributorID = element.getAttribute(actionBarContributorIdPropertyName);
- try {
- this.priority = Integer.parseInt(element.getAttribute("priority"));
- } catch (NumberFormatException e) {
- this.priority = 0;
- }
-
- this.element = element;
- // check parameters
- if(className == null) {
- throw new BadClassNameException("Class name must be set", "contentoutline", classAttributeName);
- }
-
- }
-
- /**
- * Compare priority. The highest priority win.
- */
- public boolean isHigher(ContentOutlineDescriptor found) {
- if(found == null) {
- return true;
- }
- return this.getPriority() > found.getPriority();
- }
-
- /**
- * Return the higher value of the descriptor. This value is used to
- * order the contentOutline. The highest priority win.
- */
- private int getPriority() {
- return priority;
- }
-
- /**
- * @return the actionBarContributorID
- */
- public String getActionBarContributorID() {
- return actionBarContributorID;
- }
-
- /**
- * Returns the content outline page instance (lazy initialization)
- *
- * @return the context outline page
- * @throws BackboneException
- * exception thrown when a problem occurs.
- */
- protected IPapyrusContentOutlinePage getContentOutline() throws BackboneException {
- if(instance == null) {
- instance = createContentOutlinePage();
- }
- return instance;
- }
-
- /**
- * Create the class corresponding to the class attribute.
- */
- private Class<IPapyrusContentOutlinePage> loadClass() throws BadClassNameException {
- if(className == null || className.length() == 0) {
- throw new BadClassNameException("Classname should be set.", "contentoutline", classAttributeName);
- }
- Class<IPapyrusContentOutlinePage> factoryClass;
- try {
- factoryClass = (Class<IPapyrusContentOutlinePage>)Class.forName(className);
- } catch (ClassNotFoundException e) {
- // try another way
- try {
- String declaringID = element.getContributor().getName();
- Bundle bundle = Platform.getBundle(declaringID);
- factoryClass = (Class<IPapyrusContentOutlinePage>)bundle.loadClass(className);
- } catch (ClassNotFoundException e1) {
- throw new BadClassNameException("", "contentoutline", classAttributeName, e1);
- }
- }
- return factoryClass;
- }
-
- /**
- * create the outlinepage by calling constructor without parameter and
- * then call init method
- *
- * @return the outline.
- * @throws BackboneException
- */
- protected IPapyrusContentOutlinePage createContentOutlinePage() throws BackboneException {
- if(false) {
- System.out.println("Not yet");
- return null;
- }
- try {
- IPapyrusContentOutlinePage outline = loadClass().newInstance();
- outline.init(multiEditor);
- return outline;
-
- } catch (SecurityException e) {
- // Lets propagate. This is an implementation problem that should
- // be solved by programmer.
- throw new RuntimeException(e);
- }
-
- catch (InstantiationException e) {
- // Lets propagate. This is an implementation problem that should
- // be solved by programmer.
- // throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- // Lets propagate. This is an implementation problem that should
- // be solved by programmer.
- throw new RuntimeException(e);
- }
- return null;
- }
-
- } // end class
-}
+/*****************************************************************************
+ * Copyright (c) 2008 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.contentoutline;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.infra.core.editor.BackboneException;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.extension.BadClassNameException;
+import org.eclipse.papyrus.infra.core.extension.NotFoundException;
+import org.eclipse.papyrus.infra.core.extension.diagrameditor.EditorDescriptorExtensionFactory;
+import org.osgi.framework.Bundle;
+
+public class ContentOutlineRegistry {
+
+ /** ID of the editor extension (schema filename) */
+ public static final String EDITOR_EXTENSION_ID = "papyrusContentOutline";
+
+ private static String classAttributeName = "class";
+
+ private static String actionBarContributorIdPropertyName = "actionBarContributorId";
+
+ /** Namespace where to look for the extension points. */
+ protected String extensionPointNamespace;
+
+ /**
+ * The selected content outline.
+ */
+ protected IPapyrusContentOutlinePage contentOutline;
+
+ /**
+ * Associated editor.
+ */
+ private IMultiDiagramEditor multiEditor;
+
+ /**
+ * Constructor. defaultContext, input and site are explicitly required in
+ * order be sure that they are initialized. The multiEditor should be
+ * initialized. In particular, getEditorSite(), getEditorInput() and
+ * getDefaultContext() should return initialized values.
+ *
+ * @param multiEditor
+ * @param defaultContext
+ * @param input
+ * @param site
+ * @param extensionPointNamespace
+ */
+ public ContentOutlineRegistry(IMultiDiagramEditor multiEditor, String extensionPointNamespace) {
+ this.multiEditor = multiEditor;
+ this.extensionPointNamespace = extensionPointNamespace;
+ }
+
+ /**
+ * Returns the single instance of the content outline. Creates one if
+ * necessary.
+ *
+ * @return the contentOutline the single instance of the content outline
+ * @throws BackboneException
+ * exception thrown when the outline can not be created.
+ */
+ public IPapyrusContentOutlinePage getContentOutline() throws BackboneException {
+ if(contentOutline == null) {
+ createContentOutline();
+ }
+ return contentOutline;
+ }
+
+ /**
+ * Return the {@link ContentOutlineDescriptor} with the highest priority.
+ *
+ * @return
+ * @throws BackboneException
+ * @throws NotFoundException
+ * If no ContentOutline can be found in extensions
+ */
+ private ContentOutlineDescriptor getContentOutlineDescriptor() throws BackboneException {
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, EDITOR_EXTENSION_ID);
+ ContentOutlineDescriptor found = null;
+
+ // look for the one with the highest priority
+ for(IConfigurationElement ele : configElements) {
+ ContentOutlineDescriptor desc = new ContentOutlineDescriptor(ele);
+ if(desc.isHigher(found)) {
+ found = desc;
+ }
+ }
+
+ // Instanciate the object
+ if(found == null) {
+ throw new NotFoundException("No ContentOutline registered."); //$NON-NLS-1$
+ }
+
+ return found;
+
+ }
+
+ /**
+ * Creates the content outline from the selected extension.
+ *
+ * @throws BackboneException
+ * exception thrown when the outline can not be created.
+ */
+ private void createContentOutline() throws BackboneException {
+
+ ContentOutlineDescriptor found = getContentOutlineDescriptor();
+ // Instanciate the object
+ if(found != null) {
+ contentOutline = found.createContentOutlinePage();
+ }
+ }
+
+ /**
+ * Inner Descriptor for content outline. This class load data from Eclipse
+ * extension mechanism TODO Change the parent class. It is here just to have
+ * quick code.
+ */
+ protected class ContentOutlineDescriptor extends EditorDescriptorExtensionFactory {
+
+ private int priority;
+
+ private String className;
+
+ private String actionBarContributorID;
+
+ private IConfigurationElement element;
+
+ /**
+ * Instance is created when requested.
+ */
+ protected IPapyrusContentOutlinePage instance = null;
+
+ /**
+ * Create a descriptor backuped by the config element.
+ */
+ protected ContentOutlineDescriptor(IConfigurationElement element) throws BackboneException {
+ String tagName = "contentoutline";
+ checkTagName(element, tagName);
+ this.className = element.getAttribute(classAttributeName);
+ this.actionBarContributorID = element.getAttribute(actionBarContributorIdPropertyName);
+ try {
+ this.priority = Integer.parseInt(element.getAttribute("priority"));
+ } catch (NumberFormatException e) {
+ this.priority = 0;
+ }
+
+ this.element = element;
+ // check parameters
+ if(className == null) {
+ throw new BadClassNameException("Class name must be set", "contentoutline", classAttributeName); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ }
+
+ /**
+ * Compare priority. The highest priority win.
+ */
+ public boolean isHigher(ContentOutlineDescriptor found) {
+ if(found == null) {
+ return true;
+ }
+ return this.getPriority() > found.getPriority();
+ }
+
+ /**
+ * Return the higher value of the descriptor. This value is used to
+ * order the contentOutline. The highest priority win.
+ */
+ private int getPriority() {
+ return priority;
+ }
+
+ /**
+ * @return the actionBarContributorID
+ */
+ public String getActionBarContributorID() {
+ return actionBarContributorID;
+ }
+
+ /**
+ * Returns the content outline page instance (lazy initialization)
+ *
+ * @return the context outline page
+ * @throws BackboneException
+ * exception thrown when a problem occurs.
+ */
+ protected IPapyrusContentOutlinePage getContentOutline() throws BackboneException {
+ if(instance == null) {
+ instance = createContentOutlinePage();
+ }
+ return instance;
+ }
+
+ /**
+ * Create the class corresponding to the class attribute.
+ */
+ private Class<IPapyrusContentOutlinePage> loadClass() throws BadClassNameException {
+ if(className == null || className.length() == 0) {
+ throw new BadClassNameException("Classname should be set.", "contentoutline", classAttributeName); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ Class<IPapyrusContentOutlinePage> factoryClass;
+ try {
+ factoryClass = (Class<IPapyrusContentOutlinePage>)Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ // try another way
+ try {
+ String declaringID = element.getContributor().getName();
+ Bundle bundle = Platform.getBundle(declaringID);
+ factoryClass = (Class<IPapyrusContentOutlinePage>)bundle.loadClass(className);
+ } catch (ClassNotFoundException e1) {
+ throw new BadClassNameException("", "contentoutline", classAttributeName, e1); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ return factoryClass;
+ }
+
+ /**
+ * create the outlinepage by calling constructor without parameter and
+ * then call init method
+ *
+ * @return the outline.
+ * @throws BackboneException
+ */
+ protected IPapyrusContentOutlinePage createContentOutlinePage() throws BackboneException {
+ if(false) {
+ System.out.println("Not yet"); // FIXME : no syso
+ return null;
+ }
+ try {
+ IPapyrusContentOutlinePage outline = loadClass().newInstance();
+ outline.init(multiEditor);
+ return outline;
+
+ } catch (SecurityException e) {
+ // Lets propagate. This is an implementation problem that should
+ // be solved by programmer.
+ throw new RuntimeException(e);
+ }
+
+ catch (InstantiationException e) {
+ // Lets propagate. This is an implementation problem that should
+ // be solved by programmer.
+ // throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ // Lets propagate. This is an implementation problem that should
+ // be solved by programmer.
+ throw new RuntimeException(e);
+ }
+ return null;
+ }
+
+ } // end class
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelManagerServiceFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelManagerServiceFactory.java
index 2137518..8d0b3ca 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelManagerServiceFactory.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelManagerServiceFactory.java
@@ -1,112 +1,112 @@
-/*****************************************************************************
- * Copyright (c) 2013 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.editor;
-
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.core.Activator;
-import org.eclipse.papyrus.infra.core.editorsfactory.PageModelFactoryRegistry;
-import org.eclipse.papyrus.infra.core.extension.diagrameditor.PluggableEditorFactoryReader;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelManager;
-import org.eclipse.papyrus.infra.core.services.IServiceFactory;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-
-/**
- * Service Factory to create the {@link DiSashModelManager} service.
- *
- * @author cedric dumoulin
- *
- */
-public class DiSashModelManagerServiceFactory implements IServiceFactory {
-
- private TransactionalEditingDomain transactionalEditingDomain;
-
- private SashModel sashModel;
-
- private DiSashModelManager sashModelMngr;
-
- private ServicesRegistry servicesRegistry;
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
- *
- * @param servicesRegistry
- * @throws ServiceException
- */
- @Override
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
-
- this.servicesRegistry = servicesRegistry;
- // Get required service
- transactionalEditingDomain = servicesRegistry.getService(TransactionalEditingDomain.class);
-
- // Get the model holding the contentProvider
- sashModel = SashModelUtils.getSashModelChecked(servicesRegistry);
-
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#startService()
- *
- * @throws ServiceException
- */
- @Override
- public void startService() throws ServiceException {
-
- // Read declared editors
- PageModelFactoryRegistry pageModelRegistry = new PageModelFactoryRegistry();
- PluggableEditorFactoryReader editorReader = new PluggableEditorFactoryReader(Activator.PLUGIN_ID);
- editorReader.populate(pageModelRegistry, servicesRegistry);
-
- if(sashModel.getResource() == null) {
- throw new ServiceException("Can't start " + this.getClass().getSimpleName() + "'. Required model (SashModel) should be loaded prior starting the service.");
- }
-
- // create the service
- sashModelMngr = new DiSashModelManager(pageModelRegistry, sashModel.getResource(), transactionalEditingDomain);
-
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
- *
- * @throws ServiceException
- */
- @Override
- public void disposeService() throws ServiceException {
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IServiceFactory#createServiceInstance()
- *
- * @return
- * @throws ServiceException
- */
- @Override
- public Object createServiceInstance() throws ServiceException {
-
- // Start locally the service if needed.
- // Question: Can createServiceInstance() method be called before
- // startService() is called ?
- if(sashModelMngr == null) {
- startService();
- }
-
- return sashModelMngr;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.editor;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.papyrus.infra.core.editorsfactory.PageModelFactoryRegistry;
+import org.eclipse.papyrus.infra.core.extension.diagrameditor.PluggableEditorFactoryReader;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelManager;
+import org.eclipse.papyrus.infra.core.services.IServiceFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+
+/**
+ * Service Factory to create the {@link DiSashModelManager} service.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class DiSashModelManagerServiceFactory implements IServiceFactory {
+
+ private TransactionalEditingDomain transactionalEditingDomain;
+
+ private SashModel sashModel;
+
+ private DiSashModelManager sashModelMngr;
+
+ private ServicesRegistry servicesRegistry;
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ @Override
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+
+ this.servicesRegistry = servicesRegistry;
+ // Get required service
+ transactionalEditingDomain = servicesRegistry.getService(TransactionalEditingDomain.class);
+
+ // Get the model holding the contentProvider
+ sashModel = SashModelUtils.getSashModelChecked(servicesRegistry);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void startService() throws ServiceException {
+
+ // Read declared editors
+ PageModelFactoryRegistry pageModelRegistry = new PageModelFactoryRegistry();
+ PluggableEditorFactoryReader editorReader = new PluggableEditorFactoryReader(Activator.PLUGIN_ID);
+ editorReader.populate(pageModelRegistry, servicesRegistry);
+
+ if(sashModel.getResource() == null) {
+ throw new ServiceException("Can't start " + this.getClass().getSimpleName() + "'. Required model (SashModel) should be loaded prior starting the service."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // create the service
+ sashModelMngr = new DiSashModelManager(pageModelRegistry, sashModel.getResource(), transactionalEditingDomain);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void disposeService() throws ServiceException {
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IServiceFactory#createServiceInstance()
+ *
+ * @return
+ * @throws ServiceException
+ */
+ @Override
+ public Object createServiceInstance() throws ServiceException {
+
+ // Start locally the service if needed.
+ // Question: Can createServiceInstance() method be called before
+ // startService() is called ?
+ if(sashModelMngr == null) {
+ startService();
+ }
+
+ return sashModelMngr;
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelMngrServiceFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelMngrServiceFactory.java
index 4f2e1f4..e905032 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelMngrServiceFactory.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/DiSashModelMngrServiceFactory.java
@@ -1,101 +1,101 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.editor;
-
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.core.Activator;
-import org.eclipse.papyrus.infra.core.editorsfactory.PageModelFactoryRegistry;
-import org.eclipse.papyrus.infra.core.extension.diagrameditor.PluggableEditorFactoryReader;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelMngr;
-import org.eclipse.papyrus.infra.core.services.IServiceFactory;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-
-/**
- * Service Factory to create the {@link DiSashModelMngr} service.
- *
- * @author cedric dumoulin
- *
- */
-public class DiSashModelMngrServiceFactory implements IServiceFactory {
-
- private TransactionalEditingDomain transactionalEditingDomain;
-
- private SashModel sashModel;
-
- private DiSashModelMngr sashModelMngr;
-
- private ServicesRegistry servicesRegistry;
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
- *
- * @param servicesRegistry
- * @throws ServiceException
- */
- @Override
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
-
- this.servicesRegistry = servicesRegistry;
- // Get required service
- transactionalEditingDomain = servicesRegistry.getService(TransactionalEditingDomain.class);
-
- // Get the model holding the contentProvider
- sashModel = SashModelUtils.getSashModelChecked(servicesRegistry);
-
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#startService()
- *
- * @throws ServiceException
- */
- @Override
- public void startService() throws ServiceException {
-
- // Read declared editors
- PageModelFactoryRegistry pageModelRegistry = new PageModelFactoryRegistry();
- PluggableEditorFactoryReader editorReader = new PluggableEditorFactoryReader(Activator.PLUGIN_ID);
- editorReader.populate(pageModelRegistry, servicesRegistry);
-
- if(sashModel.getResource() == null) {
- throw new ServiceException("Can't start " + this.getClass().getSimpleName() + "'. Required model (SashModel) should be loaded prior starting the service.");
- }
-
- // create the service
- sashModelMngr = new DiSashModelMngr(pageModelRegistry, sashModel.getResource());
-
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
- *
- * @throws ServiceException
- */
- @Override
- public void disposeService() throws ServiceException {
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IServiceFactory#createServiceInstance()
- *
- * @return
- * @throws ServiceException
- */
- @Override
- public Object createServiceInstance() throws ServiceException {
-
- // Start locally the service if needed.
- // Question: Can createServiceInstance() method be called before
- // startService() is called ?
- if(sashModelMngr == null) {
- startService();
- }
-
- return sashModelMngr;
- }
-
-}
+/**
+ *
+ */
+package org.eclipse.papyrus.infra.core.editor;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.papyrus.infra.core.editorsfactory.PageModelFactoryRegistry;
+import org.eclipse.papyrus.infra.core.extension.diagrameditor.PluggableEditorFactoryReader;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelMngr;
+import org.eclipse.papyrus.infra.core.services.IServiceFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+
+/**
+ * Service Factory to create the {@link DiSashModelMngr} service.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class DiSashModelMngrServiceFactory implements IServiceFactory {
+
+ private TransactionalEditingDomain transactionalEditingDomain;
+
+ private SashModel sashModel;
+
+ private DiSashModelMngr sashModelMngr;
+
+ private ServicesRegistry servicesRegistry;
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ @Override
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+
+ this.servicesRegistry = servicesRegistry;
+ // Get required service
+ transactionalEditingDomain = servicesRegistry.getService(TransactionalEditingDomain.class);
+
+ // Get the model holding the contentProvider
+ sashModel = SashModelUtils.getSashModelChecked(servicesRegistry);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void startService() throws ServiceException {
+
+ // Read declared editors
+ PageModelFactoryRegistry pageModelRegistry = new PageModelFactoryRegistry();
+ PluggableEditorFactoryReader editorReader = new PluggableEditorFactoryReader(Activator.PLUGIN_ID);
+ editorReader.populate(pageModelRegistry, servicesRegistry);
+
+ if(sashModel.getResource() == null) {
+ throw new ServiceException("Can't start " + this.getClass().getSimpleName() + "'. Required model (SashModel) should be loaded prior starting the service."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // create the service
+ sashModelMngr = new DiSashModelMngr(pageModelRegistry, sashModel.getResource());
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void disposeService() throws ServiceException {
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IServiceFactory#createServiceInstance()
+ *
+ * @return
+ * @throws ServiceException
+ */
+ @Override
+ public Object createServiceInstance() throws ServiceException {
+
+ // Start locally the service if needed.
+ // Question: Can createServiceInstance() method be called before
+ // startService() is called ?
+ if(sashModelMngr == null) {
+ startService();
+ }
+
+ return sashModelMngr;
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/PageMngrServiceFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/PageMngrServiceFactory.java
index 72c9a38..00085dd 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/PageMngrServiceFactory.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/PageMngrServiceFactory.java
@@ -1,65 +1,75 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.editor;
-
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelManager;
-import org.eclipse.papyrus.infra.core.services.IServiceFactory;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-
-/**
- * A service factory to create the {@link IPageMngr} service. This
- * serviceFactory depends on {@link ISashWindowsContentProvider} service.
- *
- * @author cedric dumoulin
- *
- */
-public class PageMngrServiceFactory implements IServiceFactory {
-
- /**
- * The sashModelMangr.
- */
- private DiSashModelManager sashModelMngr;
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
- *
- * @param servicesRegistry
- * @throws ServiceException
- */
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
-
- // Get required services
- sashModelMngr = servicesRegistry.getService(DiSashModelManager.class);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#startService()
- *
- * @throws ServiceException
- */
- public void startService() throws ServiceException {
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
- *
- * @throws ServiceException
- */
- public void disposeService() throws ServiceException {
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IServiceFactory#createServiceInstance()
- *
- * @return
- * @throws ServiceException
- */
- public Object createServiceInstance() throws ServiceException {
- return sashModelMngr.getIPageMngr();
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.editor;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelManager;
+import org.eclipse.papyrus.infra.core.services.IServiceFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+
+/**
+ * A service factory to create the {@link IPageMngr} service. This
+ * serviceFactory depends on {@link ISashWindowsContentProvider} service.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class PageMngrServiceFactory implements IServiceFactory {
+
+ /**
+ * The sashModelMangr.
+ */
+ private DiSashModelManager sashModelMngr;
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+
+ // Get required services
+ sashModelMngr = servicesRegistry.getService(DiSashModelManager.class);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ public void startService() throws ServiceException {
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ public void disposeService() throws ServiceException {
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IServiceFactory#createServiceInstance()
+ *
+ * @return
+ * @throws ServiceException
+ */
+ public Object createServiceInstance() throws ServiceException {
+ return sashModelMngr.getIPageMngr();
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageIconsRegistry.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageIconsRegistry.java
index 16723cf..cdd4b36 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageIconsRegistry.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageIconsRegistry.java
@@ -1,115 +1,115 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.editorsfactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Concrete implementation of the {@link IPageIconsRegistry}. This
- * implementation allows to add and remove {@link IPageIconsRegistry}.
- *
- *
- * @author cedric dumoulin
- */
-public class PageIconsRegistry implements IPageIconsRegistryExtended {
-
- /** list of registered icon factories */
- protected List<IEditorIconFactory> pageIcons = new ArrayList<IEditorIconFactory>();
-
- /**
- * Constructor.
- *
- * @param editorFactoryRegistry
- * @param servicesRegistry
- */
- public PageIconsRegistry() {
-
- }
-
- /**
- * Walk each registered {@link IEditorFactory} to find the one handling the
- * specified pageIdentifier. Call the corresponding method in the found
- * pageIdentifier.
- *
- * TODO Throw an exception to report errors.
- *
- * @see org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IPageModelFactory#createIPageModel(java.lang.Object)
- */
- public Image getEditorIcon(Object pageIdentifier) {
-
- for(IEditorIconFactory factory : getPageIcons()) {
- if(factory.isPageModelFactoryFor(pageIdentifier)) {
- {
- // return factory.getEditorIcon(pageIdentifier);
- return factory.getEditorIcon(pageIdentifier);
- }
- }
- }
- // no editor found !
- // TODO Throw an exception.
- // throw new EditorNotFoundException("No editor registered for '" +
- // pageIdentifier + "'.");
- return null;
- }
-
- /**
- * @return the editorFactories
- */
- protected List<IEditorIconFactory> getPageIcons() {
- return pageIcons;
- }
-
- /**
- * Add the specified {@link IEditorFactory}
- *
- * @param editorIconFactory
- */
- public void add(IEditorIconFactory editorIconFactory) {
- // This should never happen
- if(editorIconFactory == null) {
- throw new RuntimeException("Parameter should not be null.");
- }
-
- pageIcons.add(editorIconFactory);
- }
-
- /**
- * Remove the specified {@link IEditorFactory}
- *
- * @param editorIconFactory
- */
- public void remove(IEditorIconFactory editorIconFactory) {
- pageIcons.remove(editorIconFactory);
- }
-
- /**
- * Return the path to the icon ressource.
- *
- * @see org.eclipse.papyrus.infra.core.editorsfactory.IPageIconsRegistryExtended#getEditorURLIcon(java.lang.Object)
- *
- * @param model
- * @return
- */
- public String getEditorURLIcon(Object model) {
- for(IEditorIconFactory factory : getPageIcons()) {
- if(factory.isPageModelFactoryFor(model)) {
- {
- if(factory instanceof IEditorIconFactoryExtended) {
- return ((IEditorIconFactoryExtended)factory).getURLMainIcon(model);
- }
- }
- }
- }
- return "";
- }
-
- public void dispose() {
- for(IEditorIconFactory factory : pageIcons) {
- factory.dispose();
- }
- }
-}
+/**
+ *
+ */
+package org.eclipse.papyrus.infra.core.editorsfactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Concrete implementation of the {@link IPageIconsRegistry}. This
+ * implementation allows to add and remove {@link IPageIconsRegistry}.
+ *
+ *
+ * @author cedric dumoulin
+ */
+public class PageIconsRegistry implements IPageIconsRegistryExtended {
+
+ /** list of registered icon factories */
+ protected List<IEditorIconFactory> pageIcons = new ArrayList<IEditorIconFactory>();
+
+ /**
+ * Constructor.
+ *
+ * @param editorFactoryRegistry
+ * @param servicesRegistry
+ */
+ public PageIconsRegistry() {
+
+ }
+
+ /**
+ * Walk each registered {@link IEditorFactory} to find the one handling the
+ * specified pageIdentifier. Call the corresponding method in the found
+ * pageIdentifier.
+ *
+ * TODO Throw an exception to report errors.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IPageModelFactory#createIPageModel(java.lang.Object)
+ */
+ public Image getEditorIcon(Object pageIdentifier) {
+
+ for(IEditorIconFactory factory : getPageIcons()) {
+ if(factory.isPageModelFactoryFor(pageIdentifier)) {
+ {
+ // return factory.getEditorIcon(pageIdentifier);
+ return factory.getEditorIcon(pageIdentifier);
+ }
+ }
+ }
+ // no editor found !
+ // TODO Throw an exception.
+ // throw new EditorNotFoundException("No editor registered for '" +
+ // pageIdentifier + "'.");
+ return null;
+ }
+
+ /**
+ * @return the editorFactories
+ */
+ protected List<IEditorIconFactory> getPageIcons() {
+ return pageIcons;
+ }
+
+ /**
+ * Add the specified {@link IEditorFactory}
+ *
+ * @param editorIconFactory
+ */
+ public void add(IEditorIconFactory editorIconFactory) {
+ // This should never happen
+ if(editorIconFactory == null) {
+ throw new RuntimeException("Parameter should not be null."); //$NON-NLS-1$
+ }
+
+ pageIcons.add(editorIconFactory);
+ }
+
+ /**
+ * Remove the specified {@link IEditorFactory}
+ *
+ * @param editorIconFactory
+ */
+ public void remove(IEditorIconFactory editorIconFactory) {
+ pageIcons.remove(editorIconFactory);
+ }
+
+ /**
+ * Return the path to the icon ressource.
+ *
+ * @see org.eclipse.papyrus.infra.core.editorsfactory.IPageIconsRegistryExtended#getEditorURLIcon(java.lang.Object)
+ *
+ * @param model
+ * @return
+ */
+ public String getEditorURLIcon(Object model) {
+ for(IEditorIconFactory factory : getPageIcons()) {
+ if(factory.isPageModelFactoryFor(model)) {
+ {
+ if(factory instanceof IEditorIconFactoryExtended) {
+ return ((IEditorIconFactoryExtended)factory).getURLMainIcon(model);
+ }
+ }
+ }
+ }
+ return "";
+ }
+
+ public void dispose() {
+ for(IEditorIconFactory factory : pageIcons) {
+ factory.dispose();
+ }
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java
index 19b6717..5d4dc03 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java
@@ -1,89 +1,89 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.editorsfactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IPageModelFactory;
-
-/**
- * Concrete implementation of the {@link IPageModelFactory} required by the di
- * implementation of {@link ISashWindowsContentProvider}. This implementation
- * allows to add and remove {@link IEditorFactory}.
- *
- *
- * @author cedric dumoulin
- */
-public class PageModelFactoryRegistry implements IPageModelFactory {
-
- /** list of editor factories */
- protected List<IEditorFactory> editorFactories = new ArrayList<IEditorFactory>();
-
- /**
- * Constructor.
- *
- * @param editorFactoryRegistry
- * @param servicesRegistry
- */
- public PageModelFactoryRegistry() {
-
- }
-
- /**
- * Walk each registered {@link IEditorFactory} to find the one handling the
- * specified pageIdentifier. Call the corresponding method in the found
- * pageIdentifier.
- *
- * TODO Throw an exception to report errors.
- *
- * @see org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IPageModelFactory#createIPageModel(java.lang.Object)
- */
- public IPageModel createIPageModel(Object pageIdentifier) {
-
- for(IEditorFactory factory : getEditorFactories()) {
- if(factory.isPageModelFactoryFor(pageIdentifier)) {
- {
- return factory.createIPageModel(pageIdentifier);
- }
- }
- }
- // no editor found !
- // TODO Throw an exception.
- // throw new EditorNotFoundException("No editor registered for '" +
- // pageIdentifier + "'.");
- return null;
- }
-
- /**
- * @return the editorFactories
- */
- protected List<IEditorFactory> getEditorFactories() {
- return editorFactories;
- }
-
- /**
- * Add the specified {@link IEditorFactory}
- *
- * @param editorFactory
- */
- public void add(IEditorFactory editorFactory) {
- // This should never happen
- if(editorFactory == null) {
- throw new RuntimeException("Parameter should not be null.");
- }
-
- editorFactories.add(editorFactory);
- }
-
- /**
- * Remove the specified {@link IEditorFactory}
- *
- * @param editorFactory
- */
- public void remove(IEditorFactory editorFactory) {
- editorFactories.remove(editorFactory);
- }
-}
+/**
+ *
+ */
+package org.eclipse.papyrus.infra.core.editorsfactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IPageModelFactory;
+
+/**
+ * Concrete implementation of the {@link IPageModelFactory} required by the di
+ * implementation of {@link ISashWindowsContentProvider}. This implementation
+ * allows to add and remove {@link IEditorFactory}.
+ *
+ *
+ * @author cedric dumoulin
+ */
+public class PageModelFactoryRegistry implements IPageModelFactory {
+
+ /** list of editor factories */
+ protected List<IEditorFactory> editorFactories = new ArrayList<IEditorFactory>();
+
+ /**
+ * Constructor.
+ *
+ * @param editorFactoryRegistry
+ * @param servicesRegistry
+ */
+ public PageModelFactoryRegistry() {
+
+ }
+
+ /**
+ * Walk each registered {@link IEditorFactory} to find the one handling the
+ * specified pageIdentifier. Call the corresponding method in the found
+ * pageIdentifier.
+ *
+ * TODO Throw an exception to report errors.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IPageModelFactory#createIPageModel(java.lang.Object)
+ */
+ public IPageModel createIPageModel(Object pageIdentifier) {
+
+ for(IEditorFactory factory : getEditorFactories()) {
+ if(factory.isPageModelFactoryFor(pageIdentifier)) {
+ {
+ return factory.createIPageModel(pageIdentifier);
+ }
+ }
+ }
+ // no editor found !
+ // TODO Throw an exception.
+ // throw new EditorNotFoundException("No editor registered for '" +
+ // pageIdentifier + "'.");
+ return null;
+ }
+
+ /**
+ * @return the editorFactories
+ */
+ protected List<IEditorFactory> getEditorFactories() {
+ return editorFactories;
+ }
+
+ /**
+ * Add the specified {@link IEditorFactory}
+ *
+ * @param editorFactory
+ */
+ public void add(IEditorFactory editorFactory) {
+ // This should never happen
+ if(editorFactory == null) {
+ throw new RuntimeException("Parameter should not be null."); //$NON-NLS-1$
+ }
+
+ editorFactories.add(editorFactory);
+ }
+
+ /**
+ * Remove the specified {@link IEditorFactory}
+ *
+ * @param editorFactory
+ */
+ public void remove(IEditorFactory editorFactory) {
+ editorFactories.remove(editorFactory);
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/ExtensionUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/ExtensionUtils.java
index 211d7b2..5f816d4 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/ExtensionUtils.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/ExtensionUtils.java
@@ -1,91 +1,91 @@
-/*****************************************************************************
- * Copyright (c) 2008 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:
- * Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.core.extension;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.osgi.framework.Bundle;
-
-/**
- * Utility methods for Eclipse extension reading. This class can be extended, or
- * access throw the unique instance.
- *
- * @author cedric dumoulin
- * @author Patrick Tessier
- */
-public abstract class ExtensionUtils {
-
- /**
- * Unique instance that can be used directly.
- */
- static public ExtensionUtils INSTANCE = new ExtensionUtils() {
- };
-
- /**
- * used to verify if the name of the {@link IConfigurationElement} is the
- * same as the given name
- *
- * @param element
- * an {@link IConfigurationElement} see eclipse extension point
- * @param tagName
- * the name of the {@link IConfigurationElement} that has to be
- * verified
- * @throws InvalidRegistryObjectException
- * @throws BadNameExtensionException
- */
- protected void checkTagName(IConfigurationElement element, String tagName) throws BadNameExtensionException {
- String name = element.getName();
- if(!tagName.equals(name))
- throw new BadNameExtensionException("Expected '" + tagName + "', found '" + name + "'.");
- }
-
- /**
- * Retrieves the value of a specific attribute in a configuration element
- *
- * @param element
- * the configuration element to parse
- * @param attributeName
- * the name of the attribute to read
- * @param extensionPointName
- * Name of the extension point. Used in exception msg. TODO:
- * remove ?
- *
- * @return the class, result of the parsing
- * @throws InvalidRegistryObjectException
- * @throws BadClassNameException
- */
- protected Class<?> parseClass(IConfigurationElement element, String attributeName, String extensionPointName) throws BadClassNameException {
- String className = element.getAttribute(attributeName);
-
- element.getContributor().getName();
- if(className == null || className.length() == 0) {
- throw new BadClassNameException(attributeName + "=null ", extensionPointName, attributeName);
- }
- Class<?> factoryClass;
- try {
- factoryClass = Class.forName(className);
- } catch (ClassNotFoundException e) {
- // try another way
- try {
- String declaringID = element.getContributor().getName();
- Bundle bundle = Platform.getBundle(declaringID);
- factoryClass = bundle.loadClass(className);
- } catch (ClassNotFoundException e1) {
- throw new BadClassNameException(className + " can not be loaded ", extensionPointName, attributeName, e1);
- }
- }
- return factoryClass;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2008 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:
+ * Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.extension;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+
+/**
+ * Utility methods for Eclipse extension reading. This class can be extended, or
+ * access throw the unique instance.
+ *
+ * @author cedric dumoulin
+ * @author Patrick Tessier
+ */
+public abstract class ExtensionUtils {
+
+ /**
+ * Unique instance that can be used directly.
+ */
+ static public ExtensionUtils INSTANCE = new ExtensionUtils() {
+ };
+
+ /**
+ * used to verify if the name of the {@link IConfigurationElement} is the
+ * same as the given name
+ *
+ * @param element
+ * an {@link IConfigurationElement} see eclipse extension point
+ * @param tagName
+ * the name of the {@link IConfigurationElement} that has to be
+ * verified
+ * @throws InvalidRegistryObjectException
+ * @throws BadNameExtensionException
+ */
+ protected void checkTagName(IConfigurationElement element, String tagName) throws BadNameExtensionException {
+ String name = element.getName();
+ if(!tagName.equals(name))
+ throw new BadNameExtensionException("Expected '" + tagName + "', found '" + name + "'."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ /**
+ * Retrieves the value of a specific attribute in a configuration element
+ *
+ * @param element
+ * the configuration element to parse
+ * @param attributeName
+ * the name of the attribute to read
+ * @param extensionPointName
+ * Name of the extension point. Used in exception msg. TODO:
+ * remove ?
+ *
+ * @return the class, result of the parsing
+ * @throws InvalidRegistryObjectException
+ * @throws BadClassNameException
+ */
+ protected Class<?> parseClass(IConfigurationElement element, String attributeName, String extensionPointName) throws BadClassNameException {
+ String className = element.getAttribute(attributeName);
+
+ element.getContributor().getName();
+ if(className == null || className.length() == 0) {
+ throw new BadClassNameException(attributeName + "=null ", extensionPointName, attributeName); //$NON-NLS-1$
+ }
+ Class<?> factoryClass;
+ try {
+ factoryClass = Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ // try another way
+ try {
+ String declaringID = element.getContributor().getName();
+ Bundle bundle = Platform.getBundle(declaringID);
+ factoryClass = bundle.loadClass(className);
+ } catch (ClassNotFoundException e1) {
+ throw new BadClassNameException(className + " can not be loaded ", extensionPointName, attributeName, e1); //$NON-NLS-1$
+ }
+ }
+ return factoryClass;
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorDescriptorExtensionFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorDescriptorExtensionFactory.java
index a651d69..caf1225 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorDescriptorExtensionFactory.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorDescriptorExtensionFactory.java
@@ -1,81 +1,81 @@
-/*****************************************************************************
- * Copyright (c) 2008 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.core.extension.diagrameditor;
-
-import static org.eclipse.papyrus.infra.core.Activator.log;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.papyrus.infra.core.extension.ExtensionException;
-import org.eclipse.papyrus.infra.core.extension.ExtensionUtils;
-
-/**
- * A factory used to create editor descriptor object from Eclipse extensions points elements.
- *
- *@author Cedric Dumoulin
- *@author Patrick Tessier
- */
-public class EditorDescriptorExtensionFactory extends ExtensionUtils {
-
- /** singleton eINSTANCE of this class */
- public final static EditorDescriptorExtensionFactory eINSTANCE = new EditorDescriptorExtensionFactory();
-
- /** constant for the editor diagram **/
- public final static String EDITOR_DIAGRAM_EXTENSIONPOINT = "editorDiagram";
-
- /** constant for the attribute factoryClass **/
- public final static String FACTORYCLASS_ATTRIBUTE = "factoryClass";
-
- /** constant for the attribute contextId **/
- public final static String ACTIONBARCONTRIBUTORID_ATTRIBUTE = "actionBarContributorId";
-
- /** constant for the attribute icon **/
- public final static String ICON_ATTRIBUTE = "icon";
-
- /**
- * @return the eINSTANCE
- */
- public static EditorDescriptorExtensionFactory getInstance() {
- return eINSTANCE;
- }
-
- /**
- * Create a descriptor instance corresponding to the ConfigurationElement.
- *
- * @param element
- * an {@link IConfigurationElement} see eclipse extension point
- * @return a nestedEditorDescriptor structure that contains information to create diagrams
- * @throws BadNameExtensionException
- */
- @SuppressWarnings("unchecked")
- public EditorDescriptor createNestedEditorDescriptor(IConfigurationElement element) throws ExtensionException {
- EditorDescriptor res;
-
- checkTagName(element, EDITOR_DIAGRAM_EXTENSIONPOINT);
-
- res = new EditorDescriptor();
- res.setEditorFactoryClass((Class<IPluggableEditorFactory>)parseClass(element, FACTORYCLASS_ATTRIBUTE, EDITOR_DIAGRAM_EXTENSIONPOINT));
- res.setActionBarContributorId(element.getAttribute(ACTIONBARCONTRIBUTORID_ATTRIBUTE));
- String iconPath = element.getAttribute(ICON_ATTRIBUTE);
- if(iconPath != null) {
- /** Implementation which set the icon and register the complete URL of the icon : Bug eclipse 358732*/
- res.setIcon(element, iconPath, org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
-
- }
-
- if(log.isDebugEnabled()) {
- log.debug("Read editor descriptor " + res);
- }
- return res;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.extension.diagrameditor;
+
+import static org.eclipse.papyrus.infra.core.Activator.log;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.papyrus.infra.core.extension.ExtensionException;
+import org.eclipse.papyrus.infra.core.extension.ExtensionUtils;
+
+/**
+ * A factory used to create editor descriptor object from Eclipse extensions points elements.
+ *
+ *@author Cedric Dumoulin
+ *@author Patrick Tessier
+ */
+public class EditorDescriptorExtensionFactory extends ExtensionUtils {
+
+ /** singleton eINSTANCE of this class */
+ public final static EditorDescriptorExtensionFactory eINSTANCE = new EditorDescriptorExtensionFactory();
+
+ /** constant for the editor diagram **/
+ public final static String EDITOR_DIAGRAM_EXTENSIONPOINT = "editorDiagram";
+
+ /** constant for the attribute factoryClass **/
+ public final static String FACTORYCLASS_ATTRIBUTE = "factoryClass";
+
+ /** constant for the attribute contextId **/
+ public final static String ACTIONBARCONTRIBUTORID_ATTRIBUTE = "actionBarContributorId";
+
+ /** constant for the attribute icon **/
+ public final static String ICON_ATTRIBUTE = "icon";
+
+ /**
+ * @return the eINSTANCE
+ */
+ public static EditorDescriptorExtensionFactory getInstance() {
+ return eINSTANCE;
+ }
+
+ /**
+ * Create a descriptor instance corresponding to the ConfigurationElement.
+ *
+ * @param element
+ * an {@link IConfigurationElement} see eclipse extension point
+ * @return a nestedEditorDescriptor structure that contains information to create diagrams
+ * @throws BadNameExtensionException
+ */
+ @SuppressWarnings("unchecked")
+ public EditorDescriptor createNestedEditorDescriptor(IConfigurationElement element) throws ExtensionException {
+ EditorDescriptor res;
+
+ checkTagName(element, EDITOR_DIAGRAM_EXTENSIONPOINT);
+
+ res = new EditorDescriptor();
+ res.setEditorFactoryClass((Class<IPluggableEditorFactory>)parseClass(element, FACTORYCLASS_ATTRIBUTE, EDITOR_DIAGRAM_EXTENSIONPOINT));
+ res.setActionBarContributorId(element.getAttribute(ACTIONBARCONTRIBUTORID_ATTRIBUTE));
+ String iconPath = element.getAttribute(ICON_ATTRIBUTE);
+ if(iconPath != null) {
+ /** Implementation which set the icon and register the complete URL of the icon : Bug eclipse 358732*/
+ res.setIcon(element, iconPath, org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
+
+ }
+
+ if(log.isDebugEnabled()) {
+ log.debug("Read editor descriptor " + res); //$NON-NLS-1$
+ }
+ return res;
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/PluggableEditorFactoryReader.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/PluggableEditorFactoryReader.java
index f92ac07..b054fd6 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/PluggableEditorFactoryReader.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/PluggableEditorFactoryReader.java
@@ -1,140 +1,140 @@
-/*****************************************************************************
- * Copyright (c) 2008 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.core.extension.diagrameditor;
-
-import static org.eclipse.papyrus.infra.core.Activator.log;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.papyrus.infra.core.editorsfactory.PageIconsRegistry;
-import org.eclipse.papyrus.infra.core.editorsfactory.PageModelFactoryRegistry;
-import org.eclipse.papyrus.infra.core.extension.ExtensionException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-
-/**
- * This reader is used to read PluggableEditorFactory from the Eclipse extension
- * declarations. It can be used to populate an {@link PageModelFactoryRegistry}.
- */
-public class PluggableEditorFactoryReader {
-
- /** list of editor descriptors */
- protected List<EditorDescriptor> editorDescriptors;
-
- /** ID of the editor extension (schema filename) */
- public static final String EDITOR_EXTENSION_ID = "papyrusDiagram";
-
- /** Namespace where to look for the extension points. */
- protected String extensionPointNamespace;
-
- /** indicates if extension is loaded or not */
- private boolean isExtensionLoaded = false;
-
- /**
- * Create a new Registry reading extension from the specified namespace. The
- * namespace is usually the name of the plugin owning the registry.
- *
- * @param extensionPointNamespace
- */
- public PluggableEditorFactoryReader(String extensionPointNamespace) {
- super();
- this.extensionPointNamespace = extensionPointNamespace;
- editorDescriptors = new ArrayList<EditorDescriptor>();
- }
-
- /**
- * Populate the provided {@link PageModelFactoryRegistry} with {@link IPluggableEditorFactory} read from Eclipse extension declarations.
- * For each declared editor, create a proxy encapsulating the real
- * EditorFactory. Then the proxy is added to the PageModelFactoryRegistry.
- *
- * @param pageModelFactoryRegistry
- * The object to populate
- * @param serviceRegistry
- * ServiceRegistry provided to newly instantiated {@link IPluggableEditorFactory}.
- */
- public void populate(PageModelFactoryRegistry pageModelFactoryRegistry, ServicesRegistry serviceRegistry) {
-
- for(EditorDescriptor desc : getEditorDescriptors()) {
-
- // Create and add a proxy encapsulating the EditorFactory.
- pageModelFactoryRegistry.add(new EditorFactoryProxy(serviceRegistry, desc));
- }
- }
-
- /**
- * Populate the provided {@link PageIconsRegistry} with icons read from
- * Eclipse extension declarations. For each declared editor, create a {@link EditorIconFactory}.
- *
- * @param pageModelFactoryRegistry
- * The object to populate
- * @param serviceRegistry
- * ServiceRegistry provided to newly instantiated {@link IPluggableEditorFactory}.
- */
- public void populate(PageIconsRegistry registry) {
-
- for(EditorDescriptor desc : getEditorDescriptors()) {
-
- // Create and add a proxy encapsulating the EditorFactory.
- registry.add(new EditorIconFactory(desc));
- }
- }
-
- /**
- * Get the list of editor descriptor.
- *
- * @return the list of editor descriptor.
- */
- public List<EditorDescriptor> getEditorDescriptors() {
- if(!isExtensionLoaded) {
- isExtensionLoaded = true;
- initializeEditorDescriptors();
- }
- return editorDescriptors;
- }
-
- /**
- * Read editor descriptors from extension points.
- */
- private void initializeEditorDescriptors() {
- // Reading data from plugins
- IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, EDITOR_EXTENSION_ID);
-
- for(IConfigurationElement ele : configElements) {
- EditorDescriptor desc;
- try {
- if(EditorDescriptorExtensionFactory.EDITOR_DIAGRAM_EXTENSIONPOINT.equals(ele.getName())) {
- desc = EditorDescriptorExtensionFactory.eINSTANCE.createNestedEditorDescriptor(ele);
- editorDescriptors.add(desc);
- }
- } catch (ExtensionException e) {
- log.error("Initialization editor problem ", e);
- }
- }
-
- if(log.isDebugEnabled()) {
- log.debug("Read " + editorDescriptors.size() + " editor descriptors from Eclipse extensions");
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "EditorFactoryRegistry: " + editorDescriptors.toString();
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2008 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.extension.diagrameditor;
+
+import static org.eclipse.papyrus.infra.core.Activator.log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.infra.core.editorsfactory.PageIconsRegistry;
+import org.eclipse.papyrus.infra.core.editorsfactory.PageModelFactoryRegistry;
+import org.eclipse.papyrus.infra.core.extension.ExtensionException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+
+/**
+ * This reader is used to read PluggableEditorFactory from the Eclipse extension
+ * declarations. It can be used to populate an {@link PageModelFactoryRegistry}.
+ */
+public class PluggableEditorFactoryReader {
+
+ /** list of editor descriptors */
+ protected List<EditorDescriptor> editorDescriptors;
+
+ /** ID of the editor extension (schema filename) */
+ public static final String EDITOR_EXTENSION_ID = "papyrusDiagram";
+
+ /** Namespace where to look for the extension points. */
+ protected String extensionPointNamespace;
+
+ /** indicates if extension is loaded or not */
+ private boolean isExtensionLoaded = false;
+
+ /**
+ * Create a new Registry reading extension from the specified namespace. The
+ * namespace is usually the name of the plugin owning the registry.
+ *
+ * @param extensionPointNamespace
+ */
+ public PluggableEditorFactoryReader(String extensionPointNamespace) {
+ super();
+ this.extensionPointNamespace = extensionPointNamespace;
+ editorDescriptors = new ArrayList<EditorDescriptor>();
+ }
+
+ /**
+ * Populate the provided {@link PageModelFactoryRegistry} with {@link IPluggableEditorFactory} read from Eclipse extension declarations.
+ * For each declared editor, create a proxy encapsulating the real
+ * EditorFactory. Then the proxy is added to the PageModelFactoryRegistry.
+ *
+ * @param pageModelFactoryRegistry
+ * The object to populate
+ * @param serviceRegistry
+ * ServiceRegistry provided to newly instantiated {@link IPluggableEditorFactory}.
+ */
+ public void populate(PageModelFactoryRegistry pageModelFactoryRegistry, ServicesRegistry serviceRegistry) {
+
+ for(EditorDescriptor desc : getEditorDescriptors()) {
+
+ // Create and add a proxy encapsulating the EditorFactory.
+ pageModelFactoryRegistry.add(new EditorFactoryProxy(serviceRegistry, desc));
+ }
+ }
+
+ /**
+ * Populate the provided {@link PageIconsRegistry} with icons read from
+ * Eclipse extension declarations. For each declared editor, create a {@link EditorIconFactory}.
+ *
+ * @param pageModelFactoryRegistry
+ * The object to populate
+ * @param serviceRegistry
+ * ServiceRegistry provided to newly instantiated {@link IPluggableEditorFactory}.
+ */
+ public void populate(PageIconsRegistry registry) {
+
+ for(EditorDescriptor desc : getEditorDescriptors()) {
+
+ // Create and add a proxy encapsulating the EditorFactory.
+ registry.add(new EditorIconFactory(desc));
+ }
+ }
+
+ /**
+ * Get the list of editor descriptor.
+ *
+ * @return the list of editor descriptor.
+ */
+ public List<EditorDescriptor> getEditorDescriptors() {
+ if(!isExtensionLoaded) {
+ isExtensionLoaded = true;
+ initializeEditorDescriptors();
+ }
+ return editorDescriptors;
+ }
+
+ /**
+ * Read editor descriptors from extension points.
+ */
+ private void initializeEditorDescriptors() {
+ // Reading data from plugins
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, EDITOR_EXTENSION_ID);
+
+ for(IConfigurationElement ele : configElements) {
+ EditorDescriptor desc;
+ try {
+ if(EditorDescriptorExtensionFactory.EDITOR_DIAGRAM_EXTENSIONPOINT.equals(ele.getName())) {
+ desc = EditorDescriptorExtensionFactory.eINSTANCE.createNestedEditorDescriptor(ele);
+ editorDescriptors.add(desc);
+ }
+ } catch (ExtensionException e) {
+ log.error("Initialization editor problem ", e); //$NON-NLS-1$
+ }
+ }
+
+ if(log.isDebugEnabled()) {
+ log.debug("Read " + editorDescriptors.size() + " editor descriptors from Eclipse extensions"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "EditorFactoryRegistry: " + editorDescriptors.toString();
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/lifecycleevents/SaveAndDirtyService.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/lifecycleevents/SaveAndDirtyService.java
index fba5f63..ca7da6f 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/lifecycleevents/SaveAndDirtyService.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/lifecycleevents/SaveAndDirtyService.java
@@ -1,531 +1,531 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2013 LIFL & 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:
- * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
- * Christian W. Damus (CEA) - Don't make editor dirty on empty ResourceSetChangeEvent
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.lifecycleevents;
-
-import static org.eclipse.papyrus.infra.core.Activator.log;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.EventObject;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.command.BasicCommandStack;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CommandStack;
-import org.eclipse.emf.common.command.CommandStackListener;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.transaction.NotificationFilter;
-import org.eclipse.emf.transaction.ResourceSetChangeEvent;
-import org.eclipse.emf.transaction.ResourceSetListener;
-import org.eclipse.emf.transaction.RollbackException;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.services.IService;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.ISaveablePart;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
-import org.eclipse.ui.dialogs.SaveAsDialog;
-import org.eclipse.ui.part.FileEditorInput;
-
-/**
- * A Papyrus Service allowing to perform save and saveAs on Papyrus Models. The
- * service also allows to listen on the dirty state of the Models. <br>
- * The service implements the {@link ISaveablePart} interface, and can be used
- * directly in part requiring such interface of adapter.
- *
- * <br>
- * This class allows nested editors to register themselves as nested {@link ISaveablePart}. In this case, the registered part will be notified
- * each time a save or saveAs is performed. Also, the nested part will be asked
- * for its dirtyState.
- *
- * TODO : Improve the implementation by registering the isDirty flag value, and
- * firing events only if the value really change. Actually, the event is fired
- * every time the model is modified, even if the virtual value of the flag
- * hasn't changed.
- *
- * @author cedric dumoulin
- *
- */
-public class SaveAndDirtyService extends LifeCycleEventsProvider implements ISaveablePart, IService, ISaveAndDirtyService {
-
- /**
- * Class used to propagate life cycle events. This class can be retrieved as
- * a service using {@link ILifeCycleEventsProvider}.class. This class
- * extends LifeCycleEventsProvider, so the local variable is set with
- * ourself (historical reasons). TODO : remove this local variable.
- */
- protected LifeCycleEventsProvider lifeCycleEventsProvider = this;
-
- /**
- * Cached event that can be reused.
- */
- protected DoSaveEvent lifeCycleEvent;
-
- /**
- * Model set managing models.
- */
- private ModelSet resourceSet;
-
- /**
- *
- */
- private TransactionalEditingDomain transactionalEditingDomain;
-
- /**
- * The serviceRegistry.
- */
- // private ServicesRegistry servicesRegistry;
-
- /**
- * Associated editor. Needed by saveAs to synchronize editor input.
- */
- private IMultiDiagramEditor multiDiagramEditor;
-
- /**
- * List of registered {@link ISaveablePart}. This are usually nested
- * editors.
- */
- private ISaveablePartList registeredIsaveablePart;
-
- /**
- * List of listeners on input changed event after a call to saveAs.
- */
- private List<IEditorInputChangedListener> inputChangedListeners;
-
- /**
- * Listener on commandStack changes.
- */
- private final CommandStackListener commandStackListener = new CommandStackListener() {
-
- public void commandStackChanged(EventObject event) {
-
- fireIsDirtyChanged();
- };
- };
-
- /*
- * Listener on ResourceSet
- */
- private final ResourceSetListener resourceSetListener = new ResourceSetListener() {
-
- public NotificationFilter getFilter() {
- return null;
- }
-
- public boolean isAggregatePrecommitListener() {
- return false;
- }
-
- public boolean isPostcommitOnly() {
- return true;
- }
-
- public boolean isPrecommitOnly() {
- return false;
- }
-
- public void resourceSetChanged(ResourceSetChangeEvent event) {
- if(event.getTransaction() != null && event.getTransaction().getStatus().isOK() && madePersistableChanges(event)) {
- fireIsDirtyChanged();
- }
- }
-
- private boolean madePersistableChanges(ResourceSetChangeEvent event) {
- return !event.getNotifications().isEmpty() && !isUnprotected(event.getTransaction());
- }
-
- private boolean isUnprotected(Transaction transaction) {
- return !Boolean.TRUE.equals(transaction.getOptions().get(Transaction.OPTION_UNPROTECTED));
- }
-
- public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
- return null;
- }
-
- };
-
- /**
- * Constructor.
- *
- */
- public SaveAndDirtyService() {
- registeredIsaveablePart = new ISaveablePartList();
- inputChangedListeners = new ArrayList<IEditorInputChangedListener>();
- }
-
- /**
- * Initialize the service. Retrieve other required services (ModelSet,
- * CoreEditor).
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
- *
- * @param servicesRegistry
- * @throws ServiceException
- */
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
-
- // this.servicesRegistry = servicesRegistry;
-
- // Retrieve required services.
- resourceSet = servicesRegistry.getService(ModelSet.class);
- multiDiagramEditor = servicesRegistry.getService(IMultiDiagramEditor.class);
- transactionalEditingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(servicesRegistry);
-
- // Initialize and register the ILifeCycleEventsProvider service (which
- // is ourself).
- // This mean that the ILifeCycleEventsProvider is not available until we
- // are started.
- lifeCycleEvent = new DoSaveEvent(servicesRegistry, multiDiagramEditor);
- // servicesRegistry.add(ILifeCycleEventsProvider.class, 1,
- // lifeCycleEventsProvider);
-
- }
-
- /**
- * Do nothing.
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#startService()
- *
- * @throws ServiceException
- */
- public void startService() throws ServiceException {
-
- // Listen to the modifications of the EMF model
- transactionalEditingDomain.getCommandStack().addCommandStackListener(commandStackListener);
-
- // Let's listen to the resource set change
- transactionalEditingDomain.addResourceSetListener(resourceSetListener);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
- *
- * @throws ServiceException
- */
- public void disposeService() throws ServiceException {
- if(transactionalEditingDomain != null) {
- // Check if commandStack is null (meaning that transactionalEditingDomain
- // is disposed
- CommandStack commandStack = transactionalEditingDomain.getCommandStack();
- if(commandStack != null) {
- transactionalEditingDomain.getCommandStack().removeCommandStackListener(commandStackListener);
- }
- transactionalEditingDomain.removeResourceSetListener(resourceSetListener);
- // resourceSetListener = null;
- }
-
- // clean properties in order to help GC
- inputChangedListeners.clear();
- inputChangedListeners = null;
- multiDiagramEditor = null;
- // servicesRegistry = null;
- transactionalEditingDomain = null;
- resourceSet = null;
- lifeCycleEvent = null;
-
- postSaveListeners.clear();
- saveListeners.clear();
- preSaveListeners.clear();
-
-
- }
-
- /**
- * Save the Models
- *
- * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
- *
- * @param monitor
- */
- public void doSave(IProgressMonitor monitor) {
- // Sent pre doSave event
- lifeCycleEventsProvider.fireAboutToDoSaveEvent(lifeCycleEvent);
-
- // sent doSaveEvent
- lifeCycleEventsProvider.fireDoSaveEvent(lifeCycleEvent);
- // Perform local doSave
- // TODO : put it in a listener ?
- try {
- // Save each associated resource
- resourceSet.save(monitor);
- // notify registered IsaveablePart
- registeredIsaveablePart.doSave(monitor);
- markSaveLocation();
- } catch (IOException e) {
- log.error("Error during save", e);
- }
-
- // Sent post Events
- lifeCycleEventsProvider.firePostDoSaveEvent(lifeCycleEvent);
-
- }
-
- /**
- * @see org.eclipse.ui.ISaveablePart#doSaveAs()
- *
- */
- public void doSaveAs() {
- // Sent pre doSave event
- lifeCycleEventsProvider.fireAboutToDoSaveAsEvent(lifeCycleEvent);
-
- // sent doSaveEvent
- lifeCycleEventsProvider.fireDoSaveAsEvent(lifeCycleEvent);
- // Perform local doSaveAs
-
- // Show a SaveAs dialog
- Shell shell = multiDiagramEditor.getEditorSite().getWorkbenchWindow().getShell();
- SaveAsDialog dialog = new SaveAsDialog(shell);
- dialog.setOriginalFile(((IFileEditorInput)multiDiagramEditor.getEditorInput()).getFile());
- dialog.open();
- final IPath path = dialog.getResult();
- if(path != null) {
- // try to save the editor's contents under a different file name
- final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
- try {
- new ProgressMonitorDialog(shell).run(false, // don't fork
- false, // can't cancel
- new WorkspaceModifyOperation() { // run this operation
-
- @Override
- public void execute(final IProgressMonitor monitor) {
- try {
- //to event bad redirection after the saveAs
- //see bug 319023
- EcoreUtil.resolveAll(resourceSet);
- resourceSet.saveAs(path);
- // notify registered IsaveablePart
- registeredIsaveablePart.doSave(monitor);
- } catch (IOException e) {
- log.error("Unable to saveAs the resource set", e);
- }
- }
- });
- // set input to the new file
- fireEditorInputChanged(new FileEditorInput(file));
- markSaveLocation();
- } catch (InterruptedException e) {
- // should not happen, since the monitor dialog is not cancelable
- log.error(e);
- } catch (InvocationTargetException e) {
- log.error(e);
- }
- }
-
- // sent doSaveEvent
- lifeCycleEventsProvider.firePostDoSaveAsEvent(lifeCycleEvent);
- }
-
- /**
- * Change the input of the underlying editor.
- *
- * @param fileEditorInput
- */
- private void fireEditorInputChanged(FileEditorInput fileEditorInput) {
-
- for(IEditorInputChangedListener listener : inputChangedListeners) {
- try {
- listener.editorInputChanged(fileEditorInput);
- } catch (Exception e) {
- log.error("Can't set input for '" + listener + "'", e);
- }
- }
-
- }
-
- /**
- * Fire a PropertyChanged event to registered {@link IEditorInputChangedListener}.
- *
- * @param propertyId
- */
- private void fireIsDirtyChanged() {
-
- for(IEditorInputChangedListener listener : inputChangedListeners) {
- try {
- listener.isDirtyChanged();
- } catch (Exception e) {
- log.error("Can't call listener '" + listener + "'", e);
- }
- }
-
- }
-
- /**
- * Return true if the multiEditor is dirty, false otherwise. The dirty state
- * is compute as follow:
- * <ul>
- * <li>The {@link TransactionalEditingDomain} commandStack is checked</li>
- * <li>and each registered nested Isaveable.isDirty() state is checked</li>
- * <li></li>
- * <li></li>
- * <li></li>
- * <li></li>
- * </ul>
- * If one of these states is false, the returned value is false. <br>
- * If all of these states are true, the returned value is true.
- *
- * @see org.eclipse.ui.ISaveablePart#isDirty()
- *
- * @return
- */
- public boolean isDirty() {
- // First, look if the model part (EMF) is dirty, else look at the
- // Graphical part (GEF/GMF)
- if(transactionalEditingDomain == null) {
- return false;
- }
- return ((BasicCommandStack)transactionalEditingDomain.getCommandStack()).isSaveNeeded() || registeredIsaveablePart.isDirty();
- }
-
- /**
- * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
- *
- * @return
- */
- public boolean isSaveAsAllowed() {
- return true;
- }
-
- /**
- * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
- *
- * @return
- */
- public boolean isSaveOnCloseNeeded() {
- return isDirty();
- }
-
- /**
- * Mark the command stack of all sub-editors. Default implementation do
- * nothing.
- */
- protected void markSaveLocation() {
- ((BasicCommandStack)transactionalEditingDomain.getCommandStack()).saveIsDone();
- fireIsDirtyChanged();
- }
-
- /**
- * Register a nested {@link ISaveablePart} as a listener that will be
- * notified each time a {@link #doSave(IProgressMonitor)} or {@link #doSaveAs()} is performed. Also, it will be asked for the
- * dirtyState.
- *
- * @param saveablePart
- */
- public void registerIsaveablePart(ISaveablePart saveablePart) {
- registeredIsaveablePart.add(saveablePart);
- }
-
- /**
- * Remove the specified {@link ISaveablePart} from the list of listeners.
- *
- * @param saveablePart
- */
- public void removeIsaveablePart(ISaveablePart saveablePart) {
- registeredIsaveablePart.remove(saveablePart);
- }
-
- /**
- * Add a listeners on input changed event.
- *
- * @param inputChangedListener
- */
- public void addInputChangedListener(IEditorInputChangedListener inputChangedListener) {
- inputChangedListeners.add(inputChangedListener);
- }
-
- /**
- * Remove a listeners on input changed event.
- *
- * @param inputChangedListener
- */
- public void removeInputChangedListener(IEditorInputChangedListener inputChangedListener) {
- inputChangedListeners.remove(inputChangedListener);
- }
-
- /**
- * A list of {@link ISaveablePart}.
- *
- * @author dumoulin
- *
- */
- public class ISaveablePartList extends ArrayList<ISaveablePart> {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Return true if one of the part is dirty, false if all part are not
- * dirty.
- *
- * @return
- */
- public boolean isDirty() {
- for(ISaveablePart part : this) {
- if(part.isDirty()) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Call doSave on each registered {@link ISaveablePart}.
- *
- * @param monitor
- */
- public void doSave(IProgressMonitor monitor) {
- for(ISaveablePart part : this) {
-
- try {
- part.doSave(monitor);
- } catch (Exception e) {
- log.error("Can't save ISaveablePart '" + part + "'", e);
- }
- }
-
- }
-
- /**
- * Call doSaveAs on each registered {@link ISaveablePart}.
- *
- * @param monitor
- */
- public void doSaveAs() {
- for(ISaveablePart part : this) {
- try {
- part.doSaveAs();
- } catch (Exception e) {
- log.error("Can't save ISaveablePart '" + part + "'", e);
- }
- }
-
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2013 LIFL & 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - Don't make editor dirty on empty ResourceSetChangeEvent
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.lifecycleevents;
+
+import static org.eclipse.papyrus.infra.core.Activator.log;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.EventObject;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.BasicCommandStack;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.common.command.CommandStackListener;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.NotificationFilter;
+import org.eclipse.emf.transaction.ResourceSetChangeEvent;
+import org.eclipse.emf.transaction.ResourceSetListener;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.emf.transaction.Transaction;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.IService;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.ISaveablePart;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.dialogs.SaveAsDialog;
+import org.eclipse.ui.part.FileEditorInput;
+
+/**
+ * A Papyrus Service allowing to perform save and saveAs on Papyrus Models. The
+ * service also allows to listen on the dirty state of the Models. <br>
+ * The service implements the {@link ISaveablePart} interface, and can be used
+ * directly in part requiring such interface of adapter.
+ *
+ * <br>
+ * This class allows nested editors to register themselves as nested {@link ISaveablePart}. In this case, the registered part will be notified
+ * each time a save or saveAs is performed. Also, the nested part will be asked
+ * for its dirtyState.
+ *
+ * TODO : Improve the implementation by registering the isDirty flag value, and
+ * firing events only if the value really change. Actually, the event is fired
+ * every time the model is modified, even if the virtual value of the flag
+ * hasn't changed.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class SaveAndDirtyService extends LifeCycleEventsProvider implements ISaveablePart, IService, ISaveAndDirtyService {
+
+ /**
+ * Class used to propagate life cycle events. This class can be retrieved as
+ * a service using {@link ILifeCycleEventsProvider}.class. This class
+ * extends LifeCycleEventsProvider, so the local variable is set with
+ * ourself (historical reasons). TODO : remove this local variable.
+ */
+ protected LifeCycleEventsProvider lifeCycleEventsProvider = this;
+
+ /**
+ * Cached event that can be reused.
+ */
+ protected DoSaveEvent lifeCycleEvent;
+
+ /**
+ * Model set managing models.
+ */
+ private ModelSet resourceSet;
+
+ /**
+ *
+ */
+ private TransactionalEditingDomain transactionalEditingDomain;
+
+ /**
+ * The serviceRegistry.
+ */
+ // private ServicesRegistry servicesRegistry;
+
+ /**
+ * Associated editor. Needed by saveAs to synchronize editor input.
+ */
+ private IMultiDiagramEditor multiDiagramEditor;
+
+ /**
+ * List of registered {@link ISaveablePart}. This are usually nested
+ * editors.
+ */
+ private ISaveablePartList registeredIsaveablePart;
+
+ /**
+ * List of listeners on input changed event after a call to saveAs.
+ */
+ private List<IEditorInputChangedListener> inputChangedListeners;
+
+ /**
+ * Listener on commandStack changes.
+ */
+ private final CommandStackListener commandStackListener = new CommandStackListener() {
+
+ public void commandStackChanged(EventObject event) {
+
+ fireIsDirtyChanged();
+ };
+ };
+
+ /*
+ * Listener on ResourceSet
+ */
+ private final ResourceSetListener resourceSetListener = new ResourceSetListener() {
+
+ public NotificationFilter getFilter() {
+ return null;
+ }
+
+ public boolean isAggregatePrecommitListener() {
+ return false;
+ }
+
+ public boolean isPostcommitOnly() {
+ return true;
+ }
+
+ public boolean isPrecommitOnly() {
+ return false;
+ }
+
+ public void resourceSetChanged(ResourceSetChangeEvent event) {
+ if(event.getTransaction() != null && event.getTransaction().getStatus().isOK() && madePersistableChanges(event)) {
+ fireIsDirtyChanged();
+ }
+ }
+
+ private boolean madePersistableChanges(ResourceSetChangeEvent event) {
+ return !event.getNotifications().isEmpty() && !isUnprotected(event.getTransaction());
+ }
+
+ private boolean isUnprotected(Transaction transaction) {
+ return !Boolean.TRUE.equals(transaction.getOptions().get(Transaction.OPTION_UNPROTECTED));
+ }
+
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
+ return null;
+ }
+
+ };
+
+ /**
+ * Constructor.
+ *
+ */
+ public SaveAndDirtyService() {
+ registeredIsaveablePart = new ISaveablePartList();
+ inputChangedListeners = new ArrayList<IEditorInputChangedListener>();
+ }
+
+ /**
+ * Initialize the service. Retrieve other required services (ModelSet,
+ * CoreEditor).
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+
+ // this.servicesRegistry = servicesRegistry;
+
+ // Retrieve required services.
+ resourceSet = servicesRegistry.getService(ModelSet.class);
+ multiDiagramEditor = servicesRegistry.getService(IMultiDiagramEditor.class);
+ transactionalEditingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(servicesRegistry);
+
+ // Initialize and register the ILifeCycleEventsProvider service (which
+ // is ourself).
+ // This mean that the ILifeCycleEventsProvider is not available until we
+ // are started.
+ lifeCycleEvent = new DoSaveEvent(servicesRegistry, multiDiagramEditor);
+ // servicesRegistry.add(ILifeCycleEventsProvider.class, 1,
+ // lifeCycleEventsProvider);
+
+ }
+
+ /**
+ * Do nothing.
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ public void startService() throws ServiceException {
+
+ // Listen to the modifications of the EMF model
+ transactionalEditingDomain.getCommandStack().addCommandStackListener(commandStackListener);
+
+ // Let's listen to the resource set change
+ transactionalEditingDomain.addResourceSetListener(resourceSetListener);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ public void disposeService() throws ServiceException {
+ if(transactionalEditingDomain != null) {
+ // Check if commandStack is null (meaning that transactionalEditingDomain
+ // is disposed
+ CommandStack commandStack = transactionalEditingDomain.getCommandStack();
+ if(commandStack != null) {
+ transactionalEditingDomain.getCommandStack().removeCommandStackListener(commandStackListener);
+ }
+ transactionalEditingDomain.removeResourceSetListener(resourceSetListener);
+ // resourceSetListener = null;
+ }
+
+ // clean properties in order to help GC
+ inputChangedListeners.clear();
+ inputChangedListeners = null;
+ multiDiagramEditor = null;
+ // servicesRegistry = null;
+ transactionalEditingDomain = null;
+ resourceSet = null;
+ lifeCycleEvent = null;
+
+ postSaveListeners.clear();
+ saveListeners.clear();
+ preSaveListeners.clear();
+
+
+ }
+
+ /**
+ * Save the Models
+ *
+ * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+ *
+ * @param monitor
+ */
+ public void doSave(IProgressMonitor monitor) {
+ // Sent pre doSave event
+ lifeCycleEventsProvider.fireAboutToDoSaveEvent(lifeCycleEvent);
+
+ // sent doSaveEvent
+ lifeCycleEventsProvider.fireDoSaveEvent(lifeCycleEvent);
+ // Perform local doSave
+ // TODO : put it in a listener ?
+ try {
+ // Save each associated resource
+ resourceSet.save(monitor);
+ // notify registered IsaveablePart
+ registeredIsaveablePart.doSave(monitor);
+ markSaveLocation();
+ } catch (IOException e) {
+ log.error("Error during save", e); //$NON-NLS-1$
+ }
+
+ // Sent post Events
+ lifeCycleEventsProvider.firePostDoSaveEvent(lifeCycleEvent);
+
+ }
+
+ /**
+ * @see org.eclipse.ui.ISaveablePart#doSaveAs()
+ *
+ */
+ public void doSaveAs() {
+ // Sent pre doSave event
+ lifeCycleEventsProvider.fireAboutToDoSaveAsEvent(lifeCycleEvent);
+
+ // sent doSaveEvent
+ lifeCycleEventsProvider.fireDoSaveAsEvent(lifeCycleEvent);
+ // Perform local doSaveAs
+
+ // Show a SaveAs dialog
+ Shell shell = multiDiagramEditor.getEditorSite().getWorkbenchWindow().getShell();
+ SaveAsDialog dialog = new SaveAsDialog(shell);
+ dialog.setOriginalFile(((IFileEditorInput)multiDiagramEditor.getEditorInput()).getFile());
+ dialog.open();
+ final IPath path = dialog.getResult();
+ if(path != null) {
+ // try to save the editor's contents under a different file name
+ final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ try {
+ new ProgressMonitorDialog(shell).run(false, // don't fork
+ false, // can't cancel
+ new WorkspaceModifyOperation() { // run this operation
+
+ @Override
+ public void execute(final IProgressMonitor monitor) {
+ try {
+ //to event bad redirection after the saveAs
+ //see bug 319023
+ EcoreUtil.resolveAll(resourceSet);
+ resourceSet.saveAs(path);
+ // notify registered IsaveablePart
+ registeredIsaveablePart.doSave(monitor);
+ } catch (IOException e) {
+ log.error("Unable to saveAs the resource set", e); //$NON-NLS-1$
+ }
+ }
+ });
+ // set input to the new file
+ fireEditorInputChanged(new FileEditorInput(file));
+ markSaveLocation();
+ } catch (InterruptedException e) {
+ // should not happen, since the monitor dialog is not cancelable
+ log.error(e);
+ } catch (InvocationTargetException e) {
+ log.error(e);
+ }
+ }
+
+ // sent doSaveEvent
+ lifeCycleEventsProvider.firePostDoSaveAsEvent(lifeCycleEvent);
+ }
+
+ /**
+ * Change the input of the underlying editor.
+ *
+ * @param fileEditorInput
+ */
+ private void fireEditorInputChanged(FileEditorInput fileEditorInput) {
+
+ for(IEditorInputChangedListener listener : inputChangedListeners) {
+ try {
+ listener.editorInputChanged(fileEditorInput);
+ } catch (Exception e) {
+ log.error("Can't set input for '" + listener + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ }
+
+ /**
+ * Fire a PropertyChanged event to registered {@link IEditorInputChangedListener}.
+ *
+ * @param propertyId
+ */
+ private void fireIsDirtyChanged() {
+
+ for(IEditorInputChangedListener listener : inputChangedListeners) {
+ try {
+ listener.isDirtyChanged();
+ } catch (Exception e) {
+ log.error("Can't call listener '" + listener + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ }
+
+ /**
+ * Return true if the multiEditor is dirty, false otherwise. The dirty state
+ * is compute as follow:
+ * <ul>
+ * <li>The {@link TransactionalEditingDomain} commandStack is checked</li>
+ * <li>and each registered nested Isaveable.isDirty() state is checked</li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * <li></li>
+ * </ul>
+ * If one of these states is false, the returned value is false. <br>
+ * If all of these states are true, the returned value is true.
+ *
+ * @see org.eclipse.ui.ISaveablePart#isDirty()
+ *
+ * @return
+ */
+ public boolean isDirty() {
+ // First, look if the model part (EMF) is dirty, else look at the
+ // Graphical part (GEF/GMF)
+ if(transactionalEditingDomain == null) {
+ return false;
+ }
+ return ((BasicCommandStack)transactionalEditingDomain.getCommandStack()).isSaveNeeded() || registeredIsaveablePart.isDirty();
+ }
+
+ /**
+ * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
+ *
+ * @return
+ */
+ public boolean isSaveAsAllowed() {
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
+ *
+ * @return
+ */
+ public boolean isSaveOnCloseNeeded() {
+ return isDirty();
+ }
+
+ /**
+ * Mark the command stack of all sub-editors. Default implementation do
+ * nothing.
+ */
+ protected void markSaveLocation() {
+ ((BasicCommandStack)transactionalEditingDomain.getCommandStack()).saveIsDone();
+ fireIsDirtyChanged();
+ }
+
+ /**
+ * Register a nested {@link ISaveablePart} as a listener that will be
+ * notified each time a {@link #doSave(IProgressMonitor)} or {@link #doSaveAs()} is performed. Also, it will be asked for the
+ * dirtyState.
+ *
+ * @param saveablePart
+ */
+ public void registerIsaveablePart(ISaveablePart saveablePart) {
+ registeredIsaveablePart.add(saveablePart);
+ }
+
+ /**
+ * Remove the specified {@link ISaveablePart} from the list of listeners.
+ *
+ * @param saveablePart
+ */
+ public void removeIsaveablePart(ISaveablePart saveablePart) {
+ registeredIsaveablePart.remove(saveablePart);
+ }
+
+ /**
+ * Add a listeners on input changed event.
+ *
+ * @param inputChangedListener
+ */
+ public void addInputChangedListener(IEditorInputChangedListener inputChangedListener) {
+ inputChangedListeners.add(inputChangedListener);
+ }
+
+ /**
+ * Remove a listeners on input changed event.
+ *
+ * @param inputChangedListener
+ */
+ public void removeInputChangedListener(IEditorInputChangedListener inputChangedListener) {
+ inputChangedListeners.remove(inputChangedListener);
+ }
+
+ /**
+ * A list of {@link ISaveablePart}.
+ *
+ * @author dumoulin
+ *
+ */
+ public class ISaveablePartList extends ArrayList<ISaveablePart> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Return true if one of the part is dirty, false if all part are not
+ * dirty.
+ *
+ * @return
+ */
+ public boolean isDirty() {
+ for(ISaveablePart part : this) {
+ if(part.isDirty()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Call doSave on each registered {@link ISaveablePart}.
+ *
+ * @param monitor
+ */
+ public void doSave(IProgressMonitor monitor) {
+ for(ISaveablePart part : this) {
+
+ try {
+ part.doSave(monitor);
+ } catch (Exception e) {
+ log.error("Can't save ISaveablePart '" + part + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ }
+
+ /**
+ * Call doSaveAs on each registered {@link ISaveablePart}.
+ *
+ * @param monitor
+ */
+ public void doSaveAs() {
+ for(ISaveablePart part : this) {
+ try {
+ part.doSaveAs();
+ } catch (Exception e) {
+ log.error("Can't save ISaveablePart '" + part + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ }
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/listenerservice/ModelListenerManager.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/listenerservice/ModelListenerManager.java
index e39d60f..82e6527 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/listenerservice/ModelListenerManager.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/listenerservice/ModelListenerManager.java
@@ -1,130 +1,130 @@
-/*******************************************************************************
- * Copyright (c) 2008 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.papyrus.infra.core.listenerservice;
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.util.EContentAdapter;
-import org.eclipse.papyrus.infra.core.Activator;
-import org.osgi.framework.Bundle;
-
-/**
- * This class is a manager that loads all listeners of the uml model
- *
- */
-
-public class ModelListenerManager extends EContentAdapter {
-
- // list of of listener
- private Hashtable<String, IPapyrusListener> listenerRegistry;
-
- // extension point ID
- private String MODELLISTENERID_EXTENSION_ID = "org.eclipse.papyrus.infra.core.modelListener";
-
- private String NAME_ID = "name";
-
- private String REALIZATION_ID = "realization";
-
- /**
- * Constructor
- */
- public ModelListenerManager() {
- super();
- // init stack
- listenerRegistry = new Hashtable<String, IPapyrusListener>();
- initializeListenerList();
- }
-
- /**
- * Load all listeners of the model
- */
- private void initializeListenerList() {
- // Reading data from plugins
- IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(MODELLISTENERID_EXTENSION_ID);
- for(int i = 0; i < configElements.length; i++) {
- inializeOneRule(configElements[i]);
- }
-
- }
-
- /**
- * Load one listener
- *
- * @param element
- * the extension point
- */
- private void inializeOneRule(IConfigurationElement element) {
- String listenerName = element.getAttribute(NAME_ID);
- try {
- IPapyrusListener listener = (IPapyrusListener)createExtension(element, element.getAttribute(REALIZATION_ID));
- listenerRegistry.put(listenerName, listener);
- } catch (Exception e) {
- Activator.log.error("- " + listenerName + " can not be loaded: " + e.getLocalizedMessage(), e);
- }
-
- }
-
- /**
- * Load an instance of a class
- *
- * @param element
- * the extension point
- * @param classAttribute
- * the name of the class to load
- * @return the loaded Class
- * @throws Exception
- * if the class is not loaded
- */
- private static Object createExtension(final IConfigurationElement element, final String classAttribute) throws Exception {
- try {
- Bundle extensionBundle = Platform.getBundle(element.getDeclaringExtension().getNamespaceIdentifier());
- Class clazz = extensionBundle.loadClass(classAttribute);
- Object obj = clazz.newInstance();
- return obj;
- // return element.createExecutableExtension(classAttribute);
- } catch (Exception e) {
- throw new Exception("unable to create Extension" + e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public String toString() {
- String out = "ModelListener: \n";
- Enumeration<String> keyenum = listenerRegistry.keys();
- // we will call to string in each class
- while(keyenum.hasMoreElements()) {
- String aKey = keyenum.nextElement();
- out = out + "- " + aKey + " (" + listenerRegistry.get(aKey).toString() + ")\n";
- }
- return out;
- }
-
- /**
- * {@inheritDoc}
- */
- public void notifyChanged(Notification notification) {
- super.notifyChanged(notification);
- Enumeration<IPapyrusListener> papyrusListenersEnum = listenerRegistry.elements();
- while(papyrusListenersEnum.hasMoreElements()) {
- try {
- papyrusListenersEnum.nextElement().notifyChanged(notification);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.core.listenerservice;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.osgi.framework.Bundle;
+
+/**
+ * This class is a manager that loads all listeners of the uml model
+ *
+ */
+
+public class ModelListenerManager extends EContentAdapter {
+
+ // list of of listener
+ private Hashtable<String, IPapyrusListener> listenerRegistry;
+
+ // extension point ID
+ private String MODELLISTENERID_EXTENSION_ID = "org.eclipse.papyrus.infra.core.modelListener";
+
+ private String NAME_ID = "name";
+
+ private String REALIZATION_ID = "realization";
+
+ /**
+ * Constructor
+ */
+ public ModelListenerManager() {
+ super();
+ // init stack
+ listenerRegistry = new Hashtable<String, IPapyrusListener>();
+ initializeListenerList();
+ }
+
+ /**
+ * Load all listeners of the model
+ */
+ private void initializeListenerList() {
+ // Reading data from plugins
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(MODELLISTENERID_EXTENSION_ID);
+ for(int i = 0; i < configElements.length; i++) {
+ inializeOneRule(configElements[i]);
+ }
+
+ }
+
+ /**
+ * Load one listener
+ *
+ * @param element
+ * the extension point
+ */
+ private void inializeOneRule(IConfigurationElement element) {
+ String listenerName = element.getAttribute(NAME_ID);
+ try {
+ IPapyrusListener listener = (IPapyrusListener)createExtension(element, element.getAttribute(REALIZATION_ID));
+ listenerRegistry.put(listenerName, listener);
+ } catch (Exception e) {
+ Activator.log.error("- " + listenerName + " can not be loaded: " + e.getLocalizedMessage(), e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ }
+
+ /**
+ * Load an instance of a class
+ *
+ * @param element
+ * the extension point
+ * @param classAttribute
+ * the name of the class to load
+ * @return the loaded Class
+ * @throws Exception
+ * if the class is not loaded
+ */
+ private static Object createExtension(final IConfigurationElement element, final String classAttribute) throws Exception {
+ try {
+ Bundle extensionBundle = Platform.getBundle(element.getDeclaringExtension().getNamespaceIdentifier());
+ Class clazz = extensionBundle.loadClass(classAttribute);
+ Object obj = clazz.newInstance();
+ return obj;
+ // return element.createExecutableExtension(classAttribute);
+ } catch (Exception e) {
+ throw new Exception("unable to create Extension" + e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ String out = "ModelListener: \n";
+ Enumeration<String> keyenum = listenerRegistry.keys();
+ // we will call to string in each class
+ while(keyenum.hasMoreElements()) {
+ String aKey = keyenum.nextElement();
+ out = out + "- " + aKey + " (" + listenerRegistry.get(aKey).toString() + ")\n";
+ }
+ return out;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void notifyChanged(Notification notification) {
+ super.notifyChanged(notification);
+ Enumeration<IPapyrusListener> papyrusListenersEnum = listenerRegistry.elements();
+ while(papyrusListenersEnum.hasMoreElements()) {
+ try {
+ papyrusListenersEnum.nextElement().notifyChanged(notification);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/BadStateException.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/BadStateException.java
index d3bccad..d9fe533 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/BadStateException.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/BadStateException.java
@@ -1,37 +1,47 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-/**
- * @author cedric dumoulin
- *
- */
-public class BadStateException extends ServiceException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor.
- *
- */
- public BadStateException(ServiceState expectedState, ServiceState state, ServiceDescriptor descriptor) {
- super("Bad state for service '" + descriptor.getKey() + "'. Expected '" + expectedState + "' found '" + state + "'.");
- }
-
- /**
- *
- * Constructor.
- *
- * @param text
- * @param state
- * @param serviceDescriptor
- */
- public BadStateException(String text, ServiceState state, ServiceDescriptor descriptor) {
- super(text + " (Service= '" + descriptor.getKey() + ", state= " + state + ")");
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class BadStateException extends ServiceException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public BadStateException(ServiceState expectedState, ServiceState state, ServiceDescriptor descriptor) {
+ super("Bad state for service '" + descriptor.getKey() + "'. Expected '" + expectedState + "' found '" + state + "'.");
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param text
+ * @param state
+ * @param serviceDescriptor
+ */
+ public BadStateException(String text, ServiceState state, ServiceDescriptor descriptor) {
+ super(text + " (Service= '" + descriptor.getKey() + ", state= " + state + ")");
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedService.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedService.java
index 22198fd..7f7472f 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedService.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedService.java
@@ -1,93 +1,103 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Base class to create a Service composed of other services called Parts.
- * ServiceParts register themselves to the ComposedService. The ComposedService
- * maintain a list of its part.
- *
- * @author cedric dumoulin
- *
- * @param T
- * The type of sub-services that can register to this
- * ComposedService.
- */
-public abstract class ComposedService<T> implements IService {
-
- /**
- * The list of serviceParts composing this Service.
- */
- protected List<T> serviceParts = new ArrayList<T>();
-
- /**
- * Constructor. Constructor.
- *
- */
- public ComposedService() {
-
- }
-
- /**
- * Add the provided servicePart.
- *
- * @param servicePart
- */
- public void addServicePart(T servicePart) {
- serviceParts.add(servicePart);
- }
-
- /**
- * Remove the provided servicePart.
- *
- * @param servicePart
- */
- public void removeServicePart(T servicePart) {
- serviceParts.remove(servicePart);
- }
-
- /**
- * Do nothing here.
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
- *
- * @param servicesRegistry
- * @throws ServiceException
- */
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
- }
-
- /**
- * Do nothing here.
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#startService()
- *
- * @throws ServiceException
- */
- public void startService() throws ServiceException {
- }
-
- /**
- * Do nothing here.
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
- *
- * @throws ServiceException
- */
- public void disposeService() throws ServiceException {
- }
-
- /**
- * Get a list of registered sub service parts.
- *
- * @return List of registered services.
- */
- public List<T> getRegisteredServices() {
- return serviceParts;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Base class to create a Service composed of other services called Parts.
+ * ServiceParts register themselves to the ComposedService. The ComposedService
+ * maintain a list of its part.
+ *
+ * @author cedric dumoulin
+ *
+ * @param T
+ * The type of sub-services that can register to this
+ * ComposedService.
+ */
+public abstract class ComposedService<T> implements IService {
+
+ /**
+ * The list of serviceParts composing this Service.
+ */
+ protected List<T> serviceParts = new ArrayList<T>();
+
+ /**
+ * Constructor. Constructor.
+ *
+ */
+ public ComposedService() {
+
+ }
+
+ /**
+ * Add the provided servicePart.
+ *
+ * @param servicePart
+ */
+ public void addServicePart(T servicePart) {
+ serviceParts.add(servicePart);
+ }
+
+ /**
+ * Remove the provided servicePart.
+ *
+ * @param servicePart
+ */
+ public void removeServicePart(T servicePart) {
+ serviceParts.remove(servicePart);
+ }
+
+ /**
+ * Do nothing here.
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+ }
+
+ /**
+ * Do nothing here.
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ public void startService() throws ServiceException {
+ }
+
+ /**
+ * Do nothing here.
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ public void disposeService() throws ServiceException {
+ }
+
+ /**
+ * Get a list of registered sub service parts.
+ *
+ * @return List of registered services.
+ */
+ public List<T> getRegisteredServices() {
+ return serviceParts;
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedServicePart.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedServicePart.java
index ad10f74..cded164 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedServicePart.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ComposedServicePart.java
@@ -1,75 +1,85 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-/**
- * A service that register itself to its associated {@link ComposedService}.
- *
- * @param T
- * The main ComposedService
- *
- * @author cedric dumoulin
- * @param T
- * The type of the ComposedService to which this part will be
- * registered.
- *
- */
-@SuppressWarnings("rawtypes")
-public abstract class ComposedServicePart<T extends ComposedService> implements IService {
-
- /**
- *
- */
- protected ServicesRegistry servicesRegistry;
-
- /**
- * Class of the parent ComposedService
- */
- private Class<T> composedServiceKey;
-
- /**
- * ComposedService that will own this part.
- */
- T parentService;
-
- public ComposedServicePart(Class<T> composedServiceKey) {
- this.composedServiceKey = composedServiceKey;
- }
-
- /**
- * Initialize the service. Attach itself to the ComposedService
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
- *
- * @param servicesRegistry
- * @throws ServiceException
- */
- @SuppressWarnings("unchecked")
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
- this.servicesRegistry = servicesRegistry;
- parentService = servicesRegistry.getService(composedServiceKey);
- parentService.addServicePart(this);
- }
-
- /**
- * Start the service.
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#startService()
- *
- */
- public void startService() throws ServiceException {
-
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
- *
- */
- @SuppressWarnings("unchecked")
- public void disposeService() {
- parentService.removeServicePart(this);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+/**
+ * A service that register itself to its associated {@link ComposedService}.
+ *
+ * @param T
+ * The main ComposedService
+ *
+ * @author cedric dumoulin
+ * @param T
+ * The type of the ComposedService to which this part will be
+ * registered.
+ *
+ */
+@SuppressWarnings("rawtypes")
+public abstract class ComposedServicePart<T extends ComposedService> implements IService {
+
+ /**
+ *
+ */
+ protected ServicesRegistry servicesRegistry;
+
+ /**
+ * Class of the parent ComposedService
+ */
+ private Class<T> composedServiceKey;
+
+ /**
+ * ComposedService that will own this part.
+ */
+ T parentService;
+
+ public ComposedServicePart(Class<T> composedServiceKey) {
+ this.composedServiceKey = composedServiceKey;
+ }
+
+ /**
+ * Initialize the service. Attach itself to the ComposedService
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ @SuppressWarnings("unchecked")
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+ this.servicesRegistry = servicesRegistry;
+ parentService = servicesRegistry.getService(composedServiceKey);
+ parentService.addServicePart(this);
+ }
+
+ /**
+ * Start the service.
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ */
+ public void startService() throws ServiceException {
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ */
+ @SuppressWarnings("unchecked")
+ public void disposeService() {
+ parentService.removeServicePart(this);
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ExtensionServicesRegistry.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ExtensionServicesRegistry.java
index 28daa5b..246ca8e 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ExtensionServicesRegistry.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ExtensionServicesRegistry.java
@@ -1,196 +1,206 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.papyrus.infra.core.services.ServiceDescriptor.ServiceTypeKind;
-
-/**
- * ServiceRegistry reading and registering services declared in Eclipse
- * Extensions.
- *
- * @author dumoulin
- *
- */
-public class ExtensionServicesRegistry extends ServicesRegistry {
-
- /** ID of the extension (schema filename) */
- public static final String SERVICE_EXTENSION_ID = "service";
-
- /** Namespace where to look for the extension points. */
- protected String extensionPointNamespace;
-
- /** Extension point name inside the extension description **/
- public final static String SERVICE_EXTENSIONPOINT = "service";
-
- /** ServiceFactory Extension point **/
- public final static String SERVICE_FACTORY_ELEMENT_NAME = "serviceFactory";
-
- /** constant for the attribute factoryClass **/
- public final static String CONTEXTCLASS_ATTRIBUTE = "contextClass";
-
- /** extension point propertyname */
- private final static String STARTKIND_PROPERTY = "startKind";
-
- /** name of the dependsOn element */
- private static final String DEPENDSON_ELEMENT_NAME = "dependsOn";
-
- /** name of the key attribute inside the DEPENDSON element */
- private static final String DEPENDSON_KEY_ATTRIBUTE_NAME = "serviceKeyRef";
-
- /**
- * Constructor.
- *
- * @throws Exception
- */
- public ExtensionServicesRegistry(String extensionPointNamespace) throws ServiceException {
- this.extensionPointNamespace = extensionPointNamespace;
- registerDeclaredExtensions();
- }
-
- /**
- * Register the services declared in Eclipse Extension.
- *
- * @throws Exception
- */
- private void registerDeclaredExtensions() throws ServiceException {
-
- List<ServiceDescriptor> descriptors = new ArrayList<ServiceDescriptor>();
- List<ServiceException> exceptions = null;
-
- // Reading data from plugins
- IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
-
- for(IConfigurationElement ele : configElements) {
- ServiceDescriptor desc;
- if(SERVICE_EXTENSIONPOINT.equals(ele.getName())) {
- // Read a Service
- try {
- desc = readServiceDescriptor(ele);
- desc.setServiceTypeKind(ServiceTypeKind.service);
- // Add created desc
- descriptors.add(desc);
- } catch (ServiceException e) {
- // record exceptions
- if(exceptions == null)
- exceptions = new ArrayList<ServiceException>();
- exceptions.add(e);
- }
- } else if(SERVICE_FACTORY_ELEMENT_NAME.equals(ele.getName())) {
- // Read a Service Factory
- try {
- desc = readServiceDescriptor(ele);
- desc.setServiceTypeKind(ServiceTypeKind.serviceFactory);
- // Add created desc
- descriptors.add(desc);
- } catch (ServiceException e) {
- // record exceptions
- if(exceptions == null)
- exceptions = new ArrayList<ServiceException>();
- exceptions.add(e);
- }
- }
- }
-
- // Add found descriptors
- for(ServiceDescriptor desc : descriptors) {
- add(desc);
- }
-
- // Throw exceptions if pb encountered
- if(exceptions != null) {
- if(exceptions.size() == 1)
- throw exceptions.get(0);
- else
- throw new ServiceException("Somme services are not started (first is shown)", exceptions.get(0));
-
- }
-
- }
-
- /**
- * Read descriptor values from provided element.
- *
- * @param ele
- * @return
- * @throws ServiceException
- */
- private ServiceDescriptor readServiceDescriptor(IConfigurationElement ele) throws ServiceException {
-
- // classname
- String serviceClassname = ele.getAttribute("classname");
-
- // key
- String key = ele.getAttribute("id");
- if(key == null || key.length() == 0) {
- key = serviceClassname;
- }
-
- // Service start kind
- ServiceStartKind serviceStartKind = ServiceStartKind.LAZY;
- String serviceStartKindStr = ele.getAttribute(STARTKIND_PROPERTY);
- if(serviceStartKindStr != null && serviceStartKindStr.length() > 0) {
- try {
- serviceStartKind = ServiceStartKind.valueOf(serviceStartKindStr.toUpperCase());
- } catch (IllegalArgumentException e) {
- // Can't convert property
- throw new ServiceException("Can't convert property " + STARTKIND_PROPERTY + "(plugin=" + ele.getContributor() + "declaringExtension=" + ele.getDeclaringExtension() + ")", e);
- }
- }
-
- // priority
- int priority = 1;
- String priorityStr = ele.getAttribute("priority");
- if(priorityStr != null && priorityStr.length() > 0) {
- try {
- priority = Integer.parseInt(priorityStr);
- } catch (NumberFormatException e) {
- }
- }
-
- // Read dependsOn keys
- List<String> keys = getDependsOn(ele);
-
- // Create descriptor
- ServiceDescriptor desc = new ServiceDescriptor(key, serviceClassname, serviceStartKind, priority);
- desc.setClassBundleID(ele.getContributor().getName());
-
- if(keys.size() > 0)
- desc.setRequiredServiceKeys(keys);
-
- return desc;
- }
-
- /**
- * Add dependsOn keys.
- *
- * @param parentElement
- * @param model
- */
- private List<String> getDependsOn(IConfigurationElement parentElement) {
-
- List<String> keys = new ArrayList<String>();
-
- // Get children
- IConfigurationElement[] configElements = parentElement.getChildren(DEPENDSON_ELEMENT_NAME);
-
- for(IConfigurationElement ele : configElements) {
- String key = ele.getAttribute(DEPENDSON_KEY_ATTRIBUTE_NAME);
- if(key != null && key.length() > 0) {
- keys.add(key.trim());
- }
- }
-
- if(keys.size() == 0)
- return Collections.emptyList();
-
- return keys;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.infra.core.services.ServiceDescriptor.ServiceTypeKind;
+
+/**
+ * ServiceRegistry reading and registering services declared in Eclipse
+ * Extensions.
+ *
+ * @author dumoulin
+ *
+ */
+public class ExtensionServicesRegistry extends ServicesRegistry {
+
+ /** ID of the extension (schema filename) */
+ public static final String SERVICE_EXTENSION_ID = "service";
+
+ /** Namespace where to look for the extension points. */
+ protected String extensionPointNamespace;
+
+ /** Extension point name inside the extension description **/
+ public final static String SERVICE_EXTENSIONPOINT = "service";
+
+ /** ServiceFactory Extension point **/
+ public final static String SERVICE_FACTORY_ELEMENT_NAME = "serviceFactory";
+
+ /** constant for the attribute factoryClass **/
+ public final static String CONTEXTCLASS_ATTRIBUTE = "contextClass";
+
+ /** extension point propertyname */
+ private final static String STARTKIND_PROPERTY = "startKind";
+
+ /** name of the dependsOn element */
+ private static final String DEPENDSON_ELEMENT_NAME = "dependsOn";
+
+ /** name of the key attribute inside the DEPENDSON element */
+ private static final String DEPENDSON_KEY_ATTRIBUTE_NAME = "serviceKeyRef";
+
+ /**
+ * Constructor.
+ *
+ * @throws Exception
+ */
+ public ExtensionServicesRegistry(String extensionPointNamespace) throws ServiceException {
+ this.extensionPointNamespace = extensionPointNamespace;
+ registerDeclaredExtensions();
+ }
+
+ /**
+ * Register the services declared in Eclipse Extension.
+ *
+ * @throws Exception
+ */
+ private void registerDeclaredExtensions() throws ServiceException {
+
+ List<ServiceDescriptor> descriptors = new ArrayList<ServiceDescriptor>();
+ List<ServiceException> exceptions = null;
+
+ // Reading data from plugins
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
+
+ for(IConfigurationElement ele : configElements) {
+ ServiceDescriptor desc;
+ if(SERVICE_EXTENSIONPOINT.equals(ele.getName())) {
+ // Read a Service
+ try {
+ desc = readServiceDescriptor(ele);
+ desc.setServiceTypeKind(ServiceTypeKind.service);
+ // Add created desc
+ descriptors.add(desc);
+ } catch (ServiceException e) {
+ // record exceptions
+ if(exceptions == null)
+ exceptions = new ArrayList<ServiceException>();
+ exceptions.add(e);
+ }
+ } else if(SERVICE_FACTORY_ELEMENT_NAME.equals(ele.getName())) {
+ // Read a Service Factory
+ try {
+ desc = readServiceDescriptor(ele);
+ desc.setServiceTypeKind(ServiceTypeKind.serviceFactory);
+ // Add created desc
+ descriptors.add(desc);
+ } catch (ServiceException e) {
+ // record exceptions
+ if(exceptions == null)
+ exceptions = new ArrayList<ServiceException>();
+ exceptions.add(e);
+ }
+ }
+ }
+
+ // Add found descriptors
+ for(ServiceDescriptor desc : descriptors) {
+ add(desc);
+ }
+
+ // Throw exceptions if pb encountered
+ if(exceptions != null) {
+ if(exceptions.size() == 1)
+ throw exceptions.get(0);
+ else
+ throw new ServiceException("Somme services are not started (first is shown)", exceptions.get(0)); //$NON-NLS-1$
+
+ }
+
+ }
+
+ /**
+ * Read descriptor values from provided element.
+ *
+ * @param ele
+ * @return
+ * @throws ServiceException
+ */
+ private ServiceDescriptor readServiceDescriptor(IConfigurationElement ele) throws ServiceException {
+
+ // classname
+ String serviceClassname = ele.getAttribute("classname");
+
+ // key
+ String key = ele.getAttribute("id");
+ if(key == null || key.length() == 0) {
+ key = serviceClassname;
+ }
+
+ // Service start kind
+ ServiceStartKind serviceStartKind = ServiceStartKind.LAZY;
+ String serviceStartKindStr = ele.getAttribute(STARTKIND_PROPERTY);
+ if(serviceStartKindStr != null && serviceStartKindStr.length() > 0) {
+ try {
+ serviceStartKind = ServiceStartKind.valueOf(serviceStartKindStr.toUpperCase());
+ } catch (IllegalArgumentException e) {
+ // Can't convert property
+ throw new ServiceException("Can't convert property " + STARTKIND_PROPERTY + "(plugin=" + ele.getContributor() + "declaringExtension=" + ele.getDeclaringExtension() + ")", e);
+ }
+ }
+
+ // priority
+ int priority = 1;
+ String priorityStr = ele.getAttribute("priority");
+ if(priorityStr != null && priorityStr.length() > 0) {
+ try {
+ priority = Integer.parseInt(priorityStr);
+ } catch (NumberFormatException e) {
+ }
+ }
+
+ // Read dependsOn keys
+ List<String> keys = getDependsOn(ele);
+
+ // Create descriptor
+ ServiceDescriptor desc = new ServiceDescriptor(key, serviceClassname, serviceStartKind, priority);
+ desc.setClassBundleID(ele.getContributor().getName());
+
+ if(keys.size() > 0)
+ desc.setRequiredServiceKeys(keys);
+
+ return desc;
+ }
+
+ /**
+ * Add dependsOn keys.
+ *
+ * @param parentElement
+ * @param model
+ */
+ private List<String> getDependsOn(IConfigurationElement parentElement) {
+
+ List<String> keys = new ArrayList<String>();
+
+ // Get children
+ IConfigurationElement[] configElements = parentElement.getChildren(DEPENDSON_ELEMENT_NAME);
+
+ for(IConfigurationElement ele : configElements) {
+ String key = ele.getAttribute(DEPENDSON_KEY_ATTRIBUTE_NAME);
+ if(key != null && key.length() > 0) {
+ keys.add(key.trim());
+ }
+ }
+
+ if(keys.size() == 0)
+ return Collections.emptyList();
+
+ return keys;
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IService.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IService.java
index 0e89847..88448bb 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IService.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IService.java
@@ -1,42 +1,52 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-/**
- * An Service that can be registered in the {@link ServicesRegistry}. A service
- * is a singleton available throw the registry. A service can be shared across
- * editors. <br>
- * The life cycle is as follow:
- * <ul>
- * <li>service creation</li>
- * <li>{@link #init(ServicesRegistry)} - Other service can be retrieved from the registry, but are not started yet.</li>
- * <li>{@link #startService()} - service is started.</li>
- * <li>Service can be used</li>
- * <li>{@link #disposeService()} - service is disposed and should not be used anymore.</li>
- * </ul>
- *
- * @author cedric dumoulin
- *
- */
-public interface IService {
-
- /**
- * Init the service and set its associated Registry. The registry can be
- * used to retrieve other services.
- *
- * @param servicesRegistry
- */
- public void init(ServicesRegistry servicesRegistry) throws ServiceException;
-
- /**
- * Start the service. This method is called when the service is started.
- */
- public void startService() throws ServiceException;
-
- /**
- * Dispose the service.
- */
- public void disposeService() throws ServiceException;
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+/**
+ * An Service that can be registered in the {@link ServicesRegistry}. A service
+ * is a singleton available throw the registry. A service can be shared across
+ * editors. <br>
+ * The life cycle is as follow:
+ * <ul>
+ * <li>service creation</li>
+ * <li>{@link #init(ServicesRegistry)} - Other service can be retrieved from the registry, but are not started yet.</li>
+ * <li>{@link #startService()} - service is started.</li>
+ * <li>Service can be used</li>
+ * <li>{@link #disposeService()} - service is disposed and should not be used anymore.</li>
+ * </ul>
+ *
+ * @author cedric dumoulin
+ *
+ */
+public interface IService {
+
+ /**
+ * Init the service and set its associated Registry. The registry can be
+ * used to retrieve other services.
+ *
+ * @param servicesRegistry
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException;
+
+ /**
+ * Start the service. This method is called when the service is started.
+ */
+ public void startService() throws ServiceException;
+
+ /**
+ * Dispose the service.
+ */
+ public void disposeService() throws ServiceException;
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IServiceFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IServiceFactory.java
index 5688f92..4f7d682 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IServiceFactory.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/IServiceFactory.java
@@ -1,28 +1,38 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-/**
- * A factory creating a Service that can be registered in the {@link ServicesRegistry}.
- *
- * A service is a singleton available throw the registry. A service can be
- * shared across editors. The service lifecycle events (init, start and dispose)
- * are sent to the factory. The factory is responsible to forward them to the
- * real service.
- *
- * @author dumoulin
- *
- */
-public interface IServiceFactory extends IService {
-
- /**
- * Create the instance of the service that will be returned by {@link ServicesRegistry#getService(Class)}.
- *
- * @return The instance of the service.
- * @throws ServiceException
- * If an error occurs during the operation.
- */
- public Object createServiceInstance() throws ServiceException;
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+/**
+ * A factory creating a Service that can be registered in the {@link ServicesRegistry}.
+ *
+ * A service is a singleton available throw the registry. A service can be
+ * shared across editors. The service lifecycle events (init, start and dispose)
+ * are sent to the factory. The factory is responsible to forward them to the
+ * real service.
+ *
+ * @author dumoulin
+ *
+ */
+public interface IServiceFactory extends IService {
+
+ /**
+ * Create the instance of the service that will be returned by {@link ServicesRegistry#getService(Class)}.
+ *
+ * @return The instance of the service.
+ * @throws ServiceException
+ * If an error occurs during the operation.
+ */
+ public Object createServiceInstance() throws ServiceException;
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceDescriptor.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceDescriptor.java
index 31de15c..b92cb64 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceDescriptor.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceDescriptor.java
@@ -1,301 +1,311 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Descriptor of a service. This descriptor describe a service.
- *
- * @author cedirc dumoulin
- *
- */
-public class ServiceDescriptor {
-
- /**
- * Possible kind for service types.
- *
- */
- public enum ServiceTypeKind {
- service, serviceFactory, pojo
- };
-
- /** Classname of the service. USed to start the service */
- private String serviceClassname;
-
- /** Kind of start for this service */
- private ServiceStartKind serviceStartKind;
-
- /** Kind of service */
- private ServiceTypeKind serviceTypeKind = ServiceTypeKind.service;
-
- /**
- * Service priority. If two service are registered under the same key, only
- * the one with the higher priority is started.
- */
- private int priority;
-
- /**
- * Key used to register the service.
- */
- private String key;
-
- /**
- * Id of the bundle owning the .class that is referenced by
- * serviceClassname. Requested when instanciating the class.
- */
- private String classBundleID;
-
- /**
- * If set to true, the service is anonymous : it is not registered and can't
- * be retrieved with getService().
- */
- private boolean isAnonymous = false;
-
- /**
- * List of keys of Services required by this service.
- */
- private List<String> requiredServices = Collections.emptyList();
-
- /**
- * Empty list.
- */
- private static List<String> EMPTY_LIST_STRING = Collections.emptyList();
-
- /**
- * Constructor.
- *
- * @param key
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param requiredServices
- */
- public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
- this.key = key;
- this.serviceClassname = serviceClassname;
- this.serviceStartKind = serviceStartKind;
- this.priority = priority;
- this.requiredServices = requiredServices;
- }
-
- /**
- * Constructor.
- *
- * @param key
- * A class used as key. The classname is used as key.
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param requiredServices
- */
- public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
- this(key.getName(), serviceClassname, serviceStartKind, priority, requiredServices);
- }
-
- /**
- * Constructor.
- *
- * @param key
- * A class used as key. The classname is used as key.
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param isAnonymous
- * @param requiredServices
- */
- public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous, List<String> requiredServices) {
- this.key = key;
- this.serviceClassname = serviceClassname;
- this.serviceStartKind = serviceStartKind;
- this.priority = priority;
- this.isAnonymous = isAnonymous;
- this.requiredServices = requiredServices;
- }
-
- /**
- * Constructor.
- *
- * @param key
- * A class used as key. The classname is used as key.
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param isAnonymous
- * @param requiredServices
- */
- public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous, List<String> requiredServices) {
- this(key.getName(), serviceClassname, serviceStartKind, priority, isAnonymous, requiredServices);
- }
-
- /**
- * Constructor.
- *
- * @param key
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- */
- public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
- this(key, serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
- }
-
- /**
- * Constructor.
- *
- * @param key
- * A class used as key. The classname is used as key.
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- */
- public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
- this(key.getName(), serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
- }
-
- /**
- * Constructor.
- *
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param requiredServices
- */
- public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
- this(serviceClassname, serviceClassname, serviceStartKind, priority, requiredServices);
- }
-
- /**
- * Constructor.
- *
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- */
- public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous) {
- this(serviceClassname, serviceClassname, serviceStartKind, priority, isAnonymous, EMPTY_LIST_STRING);
- }
-
- /**
- * Constructor.
- *
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- */
- public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
- this(serviceClassname, serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
- }
-
- /**
- * @return the serviceStartKind
- */
- public ServiceStartKind getServiceStartKind() {
- return serviceStartKind;
- }
-
- /**
- * Return true if StartKind is 'always'.
- *
- * @return
- */
- public boolean isStartAtStartup() {
- return serviceStartKind == ServiceStartKind.STARTUP;
- }
-
- /**
- * @return the priority
- */
- public int getPriority() {
- return priority;
- }
-
- /**
- * @return the key
- */
- public String getKey() {
- return key;
- }
-
- /**
- * @return the serviceClassname
- */
- public String getServiceClassname() {
- return serviceClassname;
- }
-
- /**
- * @return the classBundleID
- */
- public String getClassBundleID() {
- return classBundleID;
- }
-
- /**
- * @param classBundleId
- * the classBundleID to set
- */
- public void setClassBundleID(String classBundleId) {
- classBundleID = classBundleId;
- }
-
- /**
- * Get the keys of all the required services
- *
- * @return the requiredServices
- */
- public List<String> getRequiredServiceKeys() {
- return requiredServices;
- }
-
- /**
- * @param requiredServices
- * the requiredServices to set
- */
- public void setRequiredServiceKeys(List<String> requiredServices) {
- this.requiredServices = requiredServices;
- }
-
- /**
- * @see java.lang.Object#toString()
- * @return
- *
- */
- @Override
- public String toString() {
- return "ServiceDescriptor [key=" + key + ", serviceClassname=" + serviceClassname + ", serviceStartKind=" + serviceStartKind + ", priority=" + priority + "]";
- }
-
- /**
- * @return the isAnonymous
- */
- public boolean isAnonymous() {
- return isAnonymous;
- }
-
- /**
- * @param isAnonymous
- * the isAnonymous to set
- */
- public void setAnonymous(boolean isAnonymous) {
- this.isAnonymous = isAnonymous;
- }
-
- /**
- * @return the serviceTypeKind
- */
- public ServiceTypeKind getServiceTypeKind() {
- return serviceTypeKind;
- }
-
- /**
- * @param serviceTypeKind
- * the serviceTypeKind to set
- */
- public void setServiceTypeKind(ServiceTypeKind serviceTypeKind) {
- this.serviceTypeKind = serviceTypeKind;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Descriptor of a service. This descriptor describe a service.
+ *
+ * @author cedirc dumoulin
+ *
+ */
+public class ServiceDescriptor {
+
+ /**
+ * Possible kind for service types.
+ *
+ */
+ public enum ServiceTypeKind {
+ service, serviceFactory, pojo
+ };
+
+ /** Classname of the service. USed to start the service */
+ private String serviceClassname;
+
+ /** Kind of start for this service */
+ private ServiceStartKind serviceStartKind;
+
+ /** Kind of service */
+ private ServiceTypeKind serviceTypeKind = ServiceTypeKind.service;
+
+ /**
+ * Service priority. If two service are registered under the same key, only
+ * the one with the higher priority is started.
+ */
+ private int priority;
+
+ /**
+ * Key used to register the service.
+ */
+ private String key;
+
+ /**
+ * Id of the bundle owning the .class that is referenced by
+ * serviceClassname. Requested when instanciating the class.
+ */
+ private String classBundleID;
+
+ /**
+ * If set to true, the service is anonymous : it is not registered and can't
+ * be retrieved with getService().
+ */
+ private boolean isAnonymous = false;
+
+ /**
+ * List of keys of Services required by this service.
+ */
+ private List<String> requiredServices = Collections.emptyList();
+
+ /**
+ * Empty list.
+ */
+ private static List<String> EMPTY_LIST_STRING = Collections.emptyList();
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param requiredServices
+ */
+ public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
+ this.key = key;
+ this.serviceClassname = serviceClassname;
+ this.serviceStartKind = serviceStartKind;
+ this.priority = priority;
+ this.requiredServices = requiredServices;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * A class used as key. The classname is used as key.
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param requiredServices
+ */
+ public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
+ this(key.getName(), serviceClassname, serviceStartKind, priority, requiredServices);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * A class used as key. The classname is used as key.
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param isAnonymous
+ * @param requiredServices
+ */
+ public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous, List<String> requiredServices) {
+ this.key = key;
+ this.serviceClassname = serviceClassname;
+ this.serviceStartKind = serviceStartKind;
+ this.priority = priority;
+ this.isAnonymous = isAnonymous;
+ this.requiredServices = requiredServices;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * A class used as key. The classname is used as key.
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param isAnonymous
+ * @param requiredServices
+ */
+ public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous, List<String> requiredServices) {
+ this(key.getName(), serviceClassname, serviceStartKind, priority, isAnonymous, requiredServices);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ */
+ public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
+ this(key, serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * A class used as key. The classname is used as key.
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ */
+ public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
+ this(key.getName(), serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param requiredServices
+ */
+ public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
+ this(serviceClassname, serviceClassname, serviceStartKind, priority, requiredServices);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ */
+ public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous) {
+ this(serviceClassname, serviceClassname, serviceStartKind, priority, isAnonymous, EMPTY_LIST_STRING);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ */
+ public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
+ this(serviceClassname, serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
+ }
+
+ /**
+ * @return the serviceStartKind
+ */
+ public ServiceStartKind getServiceStartKind() {
+ return serviceStartKind;
+ }
+
+ /**
+ * Return true if StartKind is 'always'.
+ *
+ * @return
+ */
+ public boolean isStartAtStartup() {
+ return serviceStartKind == ServiceStartKind.STARTUP;
+ }
+
+ /**
+ * @return the priority
+ */
+ public int getPriority() {
+ return priority;
+ }
+
+ /**
+ * @return the key
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * @return the serviceClassname
+ */
+ public String getServiceClassname() {
+ return serviceClassname;
+ }
+
+ /**
+ * @return the classBundleID
+ */
+ public String getClassBundleID() {
+ return classBundleID;
+ }
+
+ /**
+ * @param classBundleId
+ * the classBundleID to set
+ */
+ public void setClassBundleID(String classBundleId) {
+ classBundleID = classBundleId;
+ }
+
+ /**
+ * Get the keys of all the required services
+ *
+ * @return the requiredServices
+ */
+ public List<String> getRequiredServiceKeys() {
+ return requiredServices;
+ }
+
+ /**
+ * @param requiredServices
+ * the requiredServices to set
+ */
+ public void setRequiredServiceKeys(List<String> requiredServices) {
+ this.requiredServices = requiredServices;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ * @return
+ *
+ */
+ @Override
+ public String toString() {
+ return "ServiceDescriptor [key=" + key + ", serviceClassname=" + serviceClassname + ", serviceStartKind=" + serviceStartKind + ", priority=" + priority + "]";
+ }
+
+ /**
+ * @return the isAnonymous
+ */
+ public boolean isAnonymous() {
+ return isAnonymous;
+ }
+
+ /**
+ * @param isAnonymous
+ * the isAnonymous to set
+ */
+ public void setAnonymous(boolean isAnonymous) {
+ this.isAnonymous = isAnonymous;
+ }
+
+ /**
+ * @return the serviceTypeKind
+ */
+ public ServiceTypeKind getServiceTypeKind() {
+ return serviceTypeKind;
+ }
+
+ /**
+ * @param serviceTypeKind
+ * the serviceTypeKind to set
+ */
+ public void setServiceTypeKind(ServiceTypeKind serviceTypeKind) {
+ this.serviceTypeKind = serviceTypeKind;
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceException.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceException.java
index 0724c14..0c494c2 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceException.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceException.java
@@ -1,57 +1,67 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-/**
- * Root Exception of Services Exception.
- *
- * @author dumoulin
- *
- */
-public class ServiceException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor.
- */
- public ServiceException() {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * Constructor.
- *
- * @param message
- */
- public ServiceException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * Constructor.
- *
- * @param cause
- */
- public ServiceException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * Constructor.
- *
- * @param message
- * @param cause
- */
- public ServiceException(String message, Throwable cause) {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+/**
+ * Root Exception of Services Exception.
+ *
+ * @author dumoulin
+ *
+ */
+public class ServiceException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ */
+ public ServiceException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public ServiceException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause
+ */
+ public ServiceException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ */
+ public ServiceException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceMultiException.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceMultiException.java
index e2d9160..a298d95 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceMultiException.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceMultiException.java
@@ -1,139 +1,149 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * An exception encapsulating multiple exceptions. This exception is thrown when
- * an operation performed on several Services fails on one or more of these
- * Service. The exception contains all the exceptions encoutered while
- * opertating on Services.
- *
- * @author cedric dumoulin
- *
- */
-public class ServiceMultiException extends ServiceException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * List of encountered exceptions.
- */
- List<Throwable> encounteredExceptions = new ArrayList<Throwable>();
-
- /**
- * List of identifiers corresponding to exceptions.
- */
- List<Object> serviceIdentifiers = new ArrayList<Object>();
-
- /**
- * @return the encounteredExceptions
- */
- public List<Throwable> getExceptions() {
- return encounteredExceptions;
- }
-
- /**
- * Constructor.
- *
- */
- public ServiceMultiException() {
- super("Multiple exceptions");
- }
-
- /**
- * Constructor.
- *
- * @param message
- */
- public ServiceMultiException(String message) {
- super(message);
- }
-
- /**
- * Return the first exception.
- *
- * @see java.lang.Throwable#getCause()
- *
- * @return
- */
- @Override
- public Throwable getCause() {
- return (encounteredExceptions.size() > 0 ? encounteredExceptions.get(0) : null);
- }
-
- /**
- * Return the message if any, or the message of the first exception.
- *
- * @see java.lang.Throwable#getMessage()
- *
- * @return
- */
- @Override
- public String getMessage() {
-
- StringBuffer buffer = new StringBuffer();
-
- String message = super.getMessage();
- if(message != null)
- buffer.append(message).append('\n');
-
- buffer.append("----- exceptions : ----------\n");
- for(int i = 0; i < encounteredExceptions.size(); i++) {
- Throwable exception = encounteredExceptions.get(i);
- Object identifierMsg = serviceIdentifiers.get(i);
-
- if(identifierMsg != null)
- buffer.append(identifierMsg.toString()).append(" : ");
- String msg = exception.getMessage();
- if(msg != null)
- buffer.append(msg).append('\n');
- }
- buffer.append("----------------------------- \n");
-
- return buffer.toString();
- // // Check for first exception
- // if( encounteredExceptions.size() > 1)
- // return encounteredExceptions.get(0).getMessage();
- //
- // // default
- // return null;
- }
-
- /**
- * Add an exception to the list of exceptions.
- *
- * @param exception
- */
- public void addException(Throwable exception) {
- addException("unknown", exception);
- }
-
- /**
- * Add an exception to the list of exceptions. Also record the corresponding
- * model identifier if any.
- *
- * @param exception
- */
- public void addException(Object identifier, Throwable exception) {
- encounteredExceptions.add(exception);
- serviceIdentifiers.add(identifier);
- }
-
- /**
- * Merge both exceptions
- *
- * @param e
- */
- public void addAll(ServiceMultiException e) {
- encounteredExceptions.addAll(e.encounteredExceptions);
- serviceIdentifiers.addAll(serviceIdentifiers);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An exception encapsulating multiple exceptions. This exception is thrown when
+ * an operation performed on several Services fails on one or more of these
+ * Service. The exception contains all the exceptions encoutered while
+ * opertating on Services.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ServiceMultiException extends ServiceException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * List of encountered exceptions.
+ */
+ List<Throwable> encounteredExceptions = new ArrayList<Throwable>();
+
+ /**
+ * List of identifiers corresponding to exceptions.
+ */
+ List<Object> serviceIdentifiers = new ArrayList<Object>();
+
+ /**
+ * @return the encounteredExceptions
+ */
+ public List<Throwable> getExceptions() {
+ return encounteredExceptions;
+ }
+
+ /**
+ * Constructor.
+ *
+ */
+ public ServiceMultiException() {
+ super("Multiple exceptions"); //$NON-NLS-1$
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public ServiceMultiException(String message) {
+ super(message);
+ }
+
+ /**
+ * Return the first exception.
+ *
+ * @see java.lang.Throwable#getCause()
+ *
+ * @return
+ */
+ @Override
+ public Throwable getCause() {
+ return (encounteredExceptions.size() > 0 ? encounteredExceptions.get(0) : null);
+ }
+
+ /**
+ * Return the message if any, or the message of the first exception.
+ *
+ * @see java.lang.Throwable#getMessage()
+ *
+ * @return
+ */
+ @Override
+ public String getMessage() {
+
+ StringBuffer buffer = new StringBuffer();
+
+ String message = super.getMessage();
+ if(message != null)
+ buffer.append(message).append('\n');
+
+ buffer.append("----- exceptions : ----------\n");
+ for(int i = 0; i < encounteredExceptions.size(); i++) {
+ Throwable exception = encounteredExceptions.get(i);
+ Object identifierMsg = serviceIdentifiers.get(i);
+
+ if(identifierMsg != null)
+ buffer.append(identifierMsg.toString()).append(" : ");
+ String msg = exception.getMessage();
+ if(msg != null)
+ buffer.append(msg).append('\n');
+ }
+ buffer.append("----------------------------- \n");
+
+ return buffer.toString();
+ // // Check for first exception
+ // if( encounteredExceptions.size() > 1)
+ // return encounteredExceptions.get(0).getMessage();
+ //
+ // // default
+ // return null;
+ }
+
+ /**
+ * Add an exception to the list of exceptions.
+ *
+ * @param exception
+ */
+ public void addException(Throwable exception) {
+ addException("unknown", exception);
+ }
+
+ /**
+ * Add an exception to the list of exceptions. Also record the corresponding
+ * model identifier if any.
+ *
+ * @param exception
+ */
+ public void addException(Object identifier, Throwable exception) {
+ encounteredExceptions.add(exception);
+ serviceIdentifiers.add(identifier);
+ }
+
+ /**
+ * Merge both exceptions
+ *
+ * @param e
+ */
+ public void addAll(ServiceMultiException e) {
+ encounteredExceptions.addAll(e.encounteredExceptions);
+ serviceIdentifiers.addAll(serviceIdentifiers);
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceNotFoundException.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceNotFoundException.java
index 5c0c8c7..4859f7b 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceNotFoundException.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceNotFoundException.java
@@ -1,51 +1,64 @@
-package org.eclipse.papyrus.infra.core.services;
-
-/**
- * Service is not found.
- *
- * @author dumoulin
- *
- */
-public class ServiceNotFoundException extends ServiceException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor.
- */
- public ServiceNotFoundException() {
- super();
- }
-
- /**
- * Constructor.
- *
- * @param message
- * @param cause
- */
- public ServiceNotFoundException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Constructor.
- *
- * @param message
- */
- public ServiceNotFoundException(String message) {
- super(message);
- }
-
- /**
- * Constructor.
- *
- * @param cause
- */
- public ServiceNotFoundException(Throwable cause) {
- super(cause);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+/**
+ * Service is not found.
+ *
+ * @author dumoulin
+ *
+ */
+public class ServiceNotFoundException extends ServiceException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ */
+ public ServiceNotFoundException() {
+ super();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ */
+ public ServiceNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public ServiceNotFoundException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause
+ */
+ public ServiceNotFoundException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceStartKind.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceStartKind.java
index daedcf0..bc8f9c6 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceStartKind.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceStartKind.java
@@ -1,18 +1,28 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-/**
- * Kind of possible start method for a service. LAZY - The service start when it
- * is requested for the first time. STARTUP - The service start as soon as the
- * registry is started, or when the service is added is the registry is already
- * started.
- *
- * @author dumoulin
- *
- */
-public enum ServiceStartKind {
-
- LAZY, STARTUP;
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+/**
+ * Kind of possible start method for a service. LAZY - The service start when it
+ * is requested for the first time. STARTUP - The service start as soon as the
+ * registry is started, or when the service is added is the registry is already
+ * started.
+ *
+ * @author dumoulin
+ *
+ */
+public enum ServiceStartKind {
+
+ LAZY, STARTUP;
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceState.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceState.java
index dfe07d1..6496615 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceState.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/ServiceState.java
@@ -1,14 +1,24 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.services;
-
-/**
- * The different states that a service can have.
- *
- * @author dumoulin
- *
- */
-public enum ServiceState {
- registered, created, initialized, starting, started, disposed, error
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services;
+
+/**
+ * The different states that a service can have.
+ *
+ * @author dumoulin
+ *
+ */
+public enum ServiceState {
+ registered, created, initialized, starting, started, disposed, error
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java
index 09aebef..f2b3c72 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorUtils.java
@@ -1,721 +1,721 @@
-/*****************************************************************************
- * Copyright (c) 2008, 2013 CEA LIST and others.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- * <a href="mailto:thomas.szadel@atosorigin.com">Thomas Szadel</a>: Code simplification and NPE
- * management.
- * Christian W. Damus (CEA LIST) - API for determining URI of a resource in an editor
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.core.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.emf.common.ui.URIEditorInput;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.core.Activator;
-import org.eclipse.papyrus.infra.core.editor.BackboneException;
-import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelMngr;
-import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
-import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorReference;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IURIEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * Set of utility methods for the CoreEditor. <br>
- * WARNING : Some of these methods rely on
- * PlatformUI.getWorkbench().getActiveWorkbenchWindow()getActivePage() to lookup
- * for shared objects owned by the main editor. This doesn't work during the
- * initialization of the main editor because the main editor is not yet
- * registered in the Eclipse workbench. This can lead to a null or an exception,
- * and sometime this can lead to getting the shared object of another main
- * editor !
- *
- * @author cedric dumoulin
- * @author <a href="mailto:thomas.szadel@atosorigin.com">Thomas Szadel</a>
- */
-// FIXME throws Exception (eg: NotFoundException) instead of null
-public class EditorUtils {
-
- /**
- * Gets the opened multi-diagram editors.
- *
- * @return The opened {@link IMultiDiagramEditor} or null if an error
- * occured.
- */
- public static IMultiDiagramEditor[] getMultiDiagramEditors() {
- // Lookup ServiceRegistry
- IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if(workbenchWindow == null) {
- return null;
- }
- IWorkbenchPage page = workbenchWindow.getActivePage();
- if(page == null) {
- return null;
- }
- List<IMultiDiagramEditor> list = new ArrayList<IMultiDiagramEditor>();
- for(IEditorReference editorRef : page.getEditorReferences()) {
- IEditorPart editorPart = editorRef.getEditor(false);
- if(editorPart instanceof IMultiDiagramEditor) {
- list.add((IMultiDiagramEditor)editorPart);
- }
- }
- return list.toArray(new IMultiDiagramEditor[list.size()]);
- }
-
- /**
- * Returns the editors that are related to to given file.<BR>
- *
- * @param file
- * The file (model, di or notation).
- * @return The associated editors.
- */
- public static IMultiDiagramEditor[] getRelatedEditors(IFile file) {
- // Get the DI file
- IFile diFile = DiModelUtils.getRelatedDiFile(file);
- if(diFile == null || !diFile.exists()) {
- return new IMultiDiagramEditor[0];
- }
-
- IMultiDiagramEditor[] openedEditors = EditorUtils.getMultiDiagramEditors();
- if(openedEditors == null) {
- return new IMultiDiagramEditor[0];
- }
- List<IMultiDiagramEditor> list = new ArrayList<IMultiDiagramEditor>(openedEditors.length);
-
- for(IMultiDiagramEditor editorPart : openedEditors) {
- if(editorPart.getEditorInput() instanceof IFileEditorInput && diFile.equals(((IFileEditorInput)editorPart.getEditorInput()).getFile())) {
- list.add(editorPart);
- }
- }
- return list.toArray(new IMultiDiagramEditor[list.size()]);
- }
-
- /**
- * Create an instance of IPageMngr acting on the provided resource. This
- * instance is suitable to add, remove, close or open diagrams.
- *
- * @param diResource
- * @return The non transactional implementation of IPageMngr
- */
- public static IPageManager getIPageMngr(Resource diResource) {
- return DiSashModelMngr.createIPageMngr(diResource);
- }
-
-
- ////////////////////////////////////////////
- // The following methods are deprecated. They have been replaced by specific
- // implementations of ServiceUtils (e.g. ServiceUtilsForHandlers, ServiceUtilsForEObject),
- // which depend on a specific context (ExecutionEvent, EObject, ...) instead of
- // the active editor
- ////////////////////////////////////////////
-
- /**
- * Gets the {@link IMultiDiagramEditor} interface of the a Eclipse active
- * editor, if possible, or null if not possible. <br>
- * WARNING - This method doesn't work during the initialization of the main
- * editor. See note in class doc. <br>
- * This method return null if there is no active editor, or if the editor is
- * not instance of IMultiDiagramEditor. <br>
- * This method is designed to be used by ui actions that interact with the
- * active editor. <br>
- * This method should not be used during the editor initialization phase. <br>
- * In any case, a check should be done on the returned value that can be
- * null. Usage of this method is discouraged. Use {@link #getMultiDiagramEditorChecked()} instead.
- *
- *
- * @return Get the current {@link IMultiDiagramEditor} or null if not found.
- */
- public static IMultiDiagramEditor getMultiDiagramEditor() {
- // Lookup ServiceRegistry
- IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if(workbenchWindow == null) {
- return null;
- }
- IWorkbenchPage page = workbenchWindow.getActivePage();
- if(page == null) {
- return null;
- }
- IEditorPart editor = page.getActiveEditor();
- if(editor instanceof IMultiDiagramEditor) {
- return (IMultiDiagramEditor)editor;
- } else {
- return null;
- }
- }
-
- /**
- * Lookup the currently active Diagram from the Papyrus editor. Return the
- * current Diagram or null if none is active. <br>
- * WARNING - This method doesn't work during the initialization of the main
- * editor. See note in class doc. <br>
- * This method return null if the ServicesRegistry can not be found. <br>
- * TODO This method introduce dependency on GMF. It can be moved to a GMF
- * plugin.
- *
- * @return The active diagram or null if not found.
- *
- * @deprecated The core do make suppositions about the type of nested
- * Editors, GMF stuff should be moved in GMF projects. In many
- * case, {@link #lookupActiveNestedIEditor()} can be used.
- */
- // @Deprecated
- // public static Diagram lookupEditorActiveDiagram() {
- // DiagramEditor diagEditor = lookupActiveDiagramEditor();
- // return diagEditor == null ? null : diagEditor.getDiagram();
- // }
-
- /**
- * Lookup the currently active Diagram from the Papyrus editor. Return the
- * current Diagram or null if none is active. <br>
- * WARNING - This method doesn't work during the initialization of the main
- * editor. See note in class doc. <br>
- * This method return null if the ServicesRegistry can not be found. <br>
- * TODO This method introduce dependency on GMF. It can be moved to a GMF
- * plugin.
- *
- * @return the active diagram editor or null if not found.
- *
- * @deprecated The core do make suppositions about the type of nested
- * Editors, GMF stuff should be moved in GMF projects. In many
- * case, {@link #lookupActiveNestedIEditor()} can be used.
- */
- // @Deprecated
- // public static DiagramEditor lookupActiveDiagramEditor() {
- // // Get the active page within the sashcontainer
- // IEditorPart activeEditor = lookupActiveNestedIEditor();
- // // Check if it is a GMF DiagramEditor
- // if(activeEditor instanceof DiagramEditor) {
- // return ((DiagramEditor)activeEditor);
- // } else {
- // // Not found
- // return null;
- // }
- //
- // }
-
- /**
- * Lookup the currently active {@link IEditorPart} from the Papyrus editor.
- * Return the current nested editor part, or null if it can not be found. <br>
- * WARNING - This method doesn't work during the initialization of the main
- * editor. See note in class doc. <br>
- * This method return null if the ServicesRegistry can not be found. <br>
- * This method is designed to be used by ui actions that interact with the
- * active editor. <br>
- * This method should not be used during the editor initialization phase. <br>
- * In any case, a check should be done on the returned value that can be
- * null. An alternative is to use
- * serviceRegistry.getService(ISashWindowsContainer
- * .class).getActiveEditor(); <br>
- * It is preferable to retrieve the ServiceRegistry from elsewhere whenever
- * it is possible. <br>
- *
- *
- * @return
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * <li>
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
- * <li>
- * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
- * </ul>
- */
- @Deprecated
- public static IEditorPart lookupActiveNestedIEditor() {
- // Get the sashwindow container
- ISashWindowsContainer container = getSashWindowContainer();
- // Get the active page within the sashcontainer
- return container == null ? null : container.getActiveEditor();
- }
-
- /**
- * Lookup the currently active IEditor in the SashSystem. If the currently
- * eclipse active editor doesn't contains a {@link ISashWindowsContainer},
- * return null. If the current SashSystem page is not a IEditor, return
- * null. <br>
- * WARNING - This method doesn't work during the initialization of the main
- * editor. See note in class doc. <br>
- * This method return null if the ServicesRegistry can not be found. <br>
- * This method is designed to be used by ui actions that interact with the
- * active editor. <br>
- * This method should not be used during the editor initialization phase. <br>
- * In any case, a check should be done on the returned value that can be
- * null. An alternative is to use
- * serviceRegistry.getService(ISashWindowsContainer
- * .class).getActiveSashWindowsPage(); <br>
- * It is preferable to retrieve the ServiceRegistry from elsewhere whenever
- * it is possible.
- *
- * @return
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * <li>
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
- * <li>
- * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
- * </ul>
- */
- @Deprecated
- public static IPage lookupActiveNestedPage() {
-
- // Get the sashwindow container
- ISashWindowsContainer container = getSashWindowContainer();
- // Get the active page within the sashcontainer
- return container == null ? null : container.getActiveSashWindowsPage();
- }
-
- /**
- *
- * @return
- */
- private static ISashWindowsContainer getSashWindowContainer() {
-
- try {
- return getServiceRegistryChecked().getService(ISashWindowsContainer.class);
- } catch (ServiceException e) {
- // The contract says that we return null if not found
- return null;
- }
- }
-
- /**
- * Gets the di resource set.
- *
- * @return Get the current {@link DiResourceSet} or null if not found.
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * <li>
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
- * <li>
- * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
- * </ul>
- */
- @Deprecated
- public static DiResourceSet getDiResourceSet() {
- try {
- ServicesRegistry registry = getServiceRegistry();
- return registry == null ? null : registry.getService(DiResourceSet.class);
- } catch (ServiceException e) {
- Activator.log.error(e);
- }
- return null;
- }
-
- /**
- * Gets the {@link TransactionalEditingDomain} of the current active Eclipse
- * Editor. This method should be used only when it is sure that the active
- * editor exist, and that you want the EditingDomain of this editor. <br>
- * This method return null if the TransactionalEditingDomain can not be
- * found. <br>
- * This method is designed to be used by ui actions that interact with the
- * active editor. <br>
- * This method should not be used during the editor initialization phase. <br>
- * In any case, a check should be done on the returned value that can be
- * null. An alternative is to use {@link #getTransactionalEditingDomainChecked()} and to catch the
- * exception. <br>
- * It is preferable to use {@link #getTransactionalEditingDomain(ServicesRegistry)} whenever it is
- * possible. <br>
- * In GMF EditParts or EditPolicies, the ServiceRegistry can be retrieved
- * with methods from
- * org.eclipse.papyrus.uml.diagram.common.util.DiagramCoreServiceUtils <br>
- * WARNING: This method can return null if there is no Active Editor. This
- * happen during the editor initialization, especially when there is no
- * other editor opened.
- *
- * @return Get the current {@link TransactionalEditingDomain} or null if not
- * found
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * <li>
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
- * <li>
- * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
- * </ul>
- */
- @Deprecated
- public static TransactionalEditingDomain getTransactionalEditingDomain() {
- try {
- ServicesRegistry registry = getServiceRegistry();
- return registry == null ? null : registry.getService(TransactionalEditingDomain.class);
- } catch (IllegalStateException e) {
- // Registry can't be found, do nothing.
- } catch (ServiceException e) {
- Activator.log.error(e);
- }
- return null;
- }
-
- /**
- * Gets the {@link TransactionalEditingDomain} of the current active Eclipse
- * Editor. This method should be used only when it is sure that the active
- * editor exist, and that you want the EditingDomain of this editor. <br>
- * This method is designed to be used by ui actions that interact with the
- * active editor. <br>
- * This method should not be used during the editor initialization phase. <br>
- * It is preferable to use {@link #getTransactionalEditingDomain(ServicesRegistry)} whenever it is
- * possible. <br>
- * This method throw a {@link ServiceException} if the
- * TransactionalEditingDomain can not be found. <br>
- * In GMF EditParts or EditPolicies, the ServiceRegistry can be retrieved
- * with methods from
- * org.eclipse.papyrus.uml.diagram.common.util.DiagramCoreServiceUtils
- *
- *
- * WARNING: This method throws an exception when no Active Editor is found.
- * This happen during the editor initialization, especially when there is no
- * other editor opened.
- *
- * @return Get the current {@link TransactionalEditingDomain}
- * @throws ServiceException
- * @throws ServiceNotFoundException
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * <li>
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
- * <li>
- * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
- * </ul>
- */
- @Deprecated
- public static TransactionalEditingDomain getTransactionalEditingDomainChecked() throws ServiceException {
- try {
- ServicesRegistry registry = getServiceRegistryChecked();
- return registry.getService(TransactionalEditingDomain.class);
- } catch (IllegalStateException e) {
- throw new ServiceException(e);
- } catch (Exception e) {
- throw new ServiceException(e);
- }
- }
-
- /**
- * Gets the {@link TransactionalEditingDomain} registered in the {@link ServicesRegistry}.
- *
- * @param servicesRegistry
- * @return
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * </ul>
- */
- @Deprecated
- public static TransactionalEditingDomain getTransactionalEditingDomain(ServicesRegistry registry) {
- try {
- return registry.getService(TransactionalEditingDomain.class);
- } catch (IllegalStateException e) {
- // Registry can't be found, do nothing.
- } catch (ServiceException e) {
- Activator.log.error(e);
- }
- return null;
- }
-
- /**
- * Gets the {@link TransactionalEditingDomain} registered in the {@link ServicesRegistry}.
- *
- * @param servicesRegistry
- * @return
- * @throws ServiceException
- * If the TransactionalEditingDomain can not be found.
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * </ul>
- */
- @Deprecated
- public static TransactionalEditingDomain getTransactionalEditingDomainChecked(ServicesRegistry registry) throws ServiceException {
- return registry.getService(TransactionalEditingDomain.class);
- }
-
- /**
- * Get the {@link ServicesRegistry}of the currently active eclipse editor. <br>
- * WARNING - This method doesn't work during the initialization of the main
- * editor. See note in class doc. <br>
- * This method return null if the ServicesRegistry can not be found. <br>
- * This method is designed to be used by ui actions that interact with the
- * active editor. <br>
- * This method should not be used during the editor initialization phase. <br>
- * In any case, a check should be done on the returned value that can be
- * null. An alternative is to use {@link #getServiceRegistryChecked()} and
- * to catch the exception. <br>
- * It is preferable to retrieve the ServiceRegistry from elsewhere whenever
- * it is possible. <br>
- * In GMF EditParts or EditPolicies, the ServiceRegistry can be retrieved
- * with methods from
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF
- *
- * <br>
- * WARNING: This method can return null if there is no Active Editor. This
- * happen during the editor initialization, especially when there is no
- * other editor opened.
- *
- * @return The {@link ServicesRegistry} or null if not found.
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * <li>
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
- * <li>
- * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
- * </ul>
- */
- @Deprecated
- static public ServicesRegistry getServiceRegistry() {
- // Lookup ServiceRegistry
- IMultiDiagramEditor editor = getMultiDiagramEditor();
- return editor == null ? null : (ServicesRegistry)editor.getAdapter(ServicesRegistry.class);
- }
-
- /**
- * Get the service registry of the currently active main editor. <br>
- * WARNING - This method doesn't work during the initialization of the main
- * editor. See note in class doc.
- *
- * @return The {@link ServicesRegistry} or null if not found.
- * @throws ServiceException
- * If an error occurs.
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * <li>
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
- * <li>
- * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
- * </ul>
- */
- @Deprecated
- static public ServicesRegistry getServiceRegistryChecked() throws ServiceException {
- // Lookup ServiceRegistry
- IMultiDiagramEditor editor = getMultiDiagramEditor();
- if(editor == null) {
- throw new ServiceException("Can't get ServiceRegistry");
- }
-
- return (ServicesRegistry)editor.getAdapter(ServicesRegistry.class);
- }
-
- /**
- * Get the ISashWindowsContentProvider of the active Eclipse Editor, if
- * possible. <br>
- * This method return null if the ServiceRegistry can not be found or if an
- * error occur. <br>
- * This method is designed to be used by ui actions that interact with the
- * active editor. <br>
- * This method should not be used during the editor initialization phase. <br>
- * In any case, a check should be done on the returned value that can be
- * null. <br>
- *
- * @return the ISashWindowsContentProvider from the main editor or null if
- * not found.
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * <li>
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
- * <li>
- * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
- * </ul>
- */
- @Deprecated
- static public ISashWindowsContentProvider getISashWindowsContentProvider() {
-
- try {
- return getServiceRegistryChecked().getService(ISashWindowsContentProvider.class);
- } catch (ServiceException e) {
- // The contract says that we return null if not found
- return null;
- }
- }
-
- /**
- * Get the ISashWindowsContentProvider of the active Eclipse Editor, if
- * possible. <br>
- * This method return null if the ServiceRegistry can not be found or if an
- * error occur. <br>
- * This method is designed to be used by ui actions that interact with the
- * active editor. <br>
- * This method should not be used during the editor initialization phase. <br>
- * In any case, a check should be done on the returned value that can be
- * null.
- *
- * @return the ISashWindowsContentProvider from the main editor or null if
- * not found.
- * @deprecated Check
- * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
- * /cookbook/PapyrusCookBook.odt and use one of the replacement:
- * <ul>
- * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
- * <li>
- * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
- * <li>
- * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
- * </ul>
- */
- @Deprecated
- public static IPageMngr getIPageMngr() {
-
- try {
- return getServiceRegistryChecked().getService(IPageMngr.class);
- } catch (ServiceException e) {
- // The contract says that we return null if not found
- return null;
- }
- }
-
- /**
- * Get the Eclipse ActiveEditor.
- *
- * @return The active {@link CoreMultiDiagramEditor} or null if not found.
- * @deprecated Use {@link EditorUtils#getMultiDiagramEditor()}
- */
- @Deprecated
- protected static IEditorPart getWorkbenchActiveEditor() {
- IMultiDiagramEditor editorPart = getMultiDiagramEditor();
- if(editorPart instanceof CoreMultiDiagramEditor) {
- return editorPart;
- } else {
- return null;
- }
- }
-
- /**
- * Gets the {@link IMultiDiagramEditor} interface of the a Eclipse active
- * editor, if possible, or throw an exception if not possible. <br>
- * WARNING - This method throw an exception during the initialization of the
- * main editor. This method throws an exception if there is no active
- * editor, or if the editor is not instance of IMultiDiagramEditor. <br>
- * This method is designed to be used by ui actions that interact with the
- * active editor. <br>
- *
- *
- * @return Get the current {@link IMultiDiagramEditor} or null if not found.
- * @throws BackboneException
- * If it is not possible to get an instanceof {@link IMultiDiagramEditor}
- */
- public static IMultiDiagramEditor getMultiDiagramEditorChecked() throws BackboneException {
- IEditorPart editor;
- try {
- editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- } catch (NullPointerException e) {
- // Can't get the active editor
- throw new BackboneException("Can't get the current Eclipse Active Editor: There is no active editor at this time.");
- }
-
- if(editor instanceof IMultiDiagramEditor) {
- return (IMultiDiagramEditor)editor;
- } else {
- throw new BackboneException("Can't get an Active Editor instance of IMultiDiagramEditor. (actual type:" + editor.getClass().getName() + ")");
- }
- }
-
- /**
- * Obtains the URI of the EMF resource identified by the given editor reference.
- *
- * @param editorRef
- * an editor reference
- *
- * @return the best-effort URI of the resource that it edits, or {@code null} if it could not be determined,
- * including the case when the editor input could not be obtained from the reference
- */
- public static URI getResourceURI(IEditorReference editorRef) {
- try {
- return getResourceURI(editorRef.getEditorInput());
- } catch (PartInitException e) {
- Activator.log.error("Could not obtain editor input from editor reference.", e); //$NON-NLS-1$
- return null;
- }
- }
-
- /**
- * Obtains the URI of the EMF resource edited by the given {@code editor}.
- *
- * @param editor
- * an open editor
- *
- * @return the best-effort URI of the resource that it edits, or {@code null} if it could not be determined,
- * such as if the editor input could not be obtained from the editor
- */
- public static URI getResourceURI(IEditorPart editor) {
- return getResourceURI(editor.getEditorInput());
- }
-
- /**
- * Obtains the URI of the EMF resource identified by the given editor input.
- *
- * @param editorInput
- * an editor input
- *
- * @return the best-effort URI of the resource that it edits, or {@code null} if it could not be determined
- */
- public static URI getResourceURI(IEditorInput editorInput) {
- URI result = null;
-
- if(editorInput instanceof IFileEditorInput) {
- result = URI.createPlatformResourceURI(((IFileEditorInput)editorInput).getFile().getFullPath().toString(), true);
- } else if(editorInput instanceof URIEditorInput) {
- result = ((URIEditorInput)editorInput).getURI();
- } else if(editorInput instanceof IURIEditorInput) {
- result = URI.createURI(((IURIEditorInput)editorInput).getURI().toASCIIString(), true);
- } else if(editorInput != null) {
- // desperation
- Object adapter = editorInput.getAdapter(URI.class);
- if(adapter instanceof URI) {
- result = (URI)adapter;
- }
- }
-
- return result;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008, 2013 CEA LIST and others.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ * <a href="mailto:thomas.szadel@atosorigin.com">Thomas Szadel</a>: Code simplification and NPE
+ * management.
+ * Christian W. Damus (CEA LIST) - API for determining URI of a resource in an editor
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.ui.URIEditorInput;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.papyrus.infra.core.editor.BackboneException;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelMngr;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IURIEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Set of utility methods for the CoreEditor. <br>
+ * WARNING : Some of these methods rely on
+ * PlatformUI.getWorkbench().getActiveWorkbenchWindow()getActivePage() to lookup
+ * for shared objects owned by the main editor. This doesn't work during the
+ * initialization of the main editor because the main editor is not yet
+ * registered in the Eclipse workbench. This can lead to a null or an exception,
+ * and sometime this can lead to getting the shared object of another main
+ * editor !
+ *
+ * @author cedric dumoulin
+ * @author <a href="mailto:thomas.szadel@atosorigin.com">Thomas Szadel</a>
+ */
+// FIXME throws Exception (eg: NotFoundException) instead of null
+public class EditorUtils {
+
+ /**
+ * Gets the opened multi-diagram editors.
+ *
+ * @return The opened {@link IMultiDiagramEditor} or null if an error
+ * occured.
+ */
+ public static IMultiDiagramEditor[] getMultiDiagramEditors() {
+ // Lookup ServiceRegistry
+ IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if(workbenchWindow == null) {
+ return null;
+ }
+ IWorkbenchPage page = workbenchWindow.getActivePage();
+ if(page == null) {
+ return null;
+ }
+ List<IMultiDiagramEditor> list = new ArrayList<IMultiDiagramEditor>();
+ for(IEditorReference editorRef : page.getEditorReferences()) {
+ IEditorPart editorPart = editorRef.getEditor(false);
+ if(editorPart instanceof IMultiDiagramEditor) {
+ list.add((IMultiDiagramEditor)editorPart);
+ }
+ }
+ return list.toArray(new IMultiDiagramEditor[list.size()]);
+ }
+
+ /**
+ * Returns the editors that are related to to given file.<BR>
+ *
+ * @param file
+ * The file (model, di or notation).
+ * @return The associated editors.
+ */
+ public static IMultiDiagramEditor[] getRelatedEditors(IFile file) {
+ // Get the DI file
+ IFile diFile = DiModelUtils.getRelatedDiFile(file);
+ if(diFile == null || !diFile.exists()) {
+ return new IMultiDiagramEditor[0];
+ }
+
+ IMultiDiagramEditor[] openedEditors = EditorUtils.getMultiDiagramEditors();
+ if(openedEditors == null) {
+ return new IMultiDiagramEditor[0];
+ }
+ List<IMultiDiagramEditor> list = new ArrayList<IMultiDiagramEditor>(openedEditors.length);
+
+ for(IMultiDiagramEditor editorPart : openedEditors) {
+ if(editorPart.getEditorInput() instanceof IFileEditorInput && diFile.equals(((IFileEditorInput)editorPart.getEditorInput()).getFile())) {
+ list.add(editorPart);
+ }
+ }
+ return list.toArray(new IMultiDiagramEditor[list.size()]);
+ }
+
+ /**
+ * Create an instance of IPageMngr acting on the provided resource. This
+ * instance is suitable to add, remove, close or open diagrams.
+ *
+ * @param diResource
+ * @return The non transactional implementation of IPageMngr
+ */
+ public static IPageManager getIPageMngr(Resource diResource) {
+ return DiSashModelMngr.createIPageMngr(diResource);
+ }
+
+
+ ////////////////////////////////////////////
+ // The following methods are deprecated. They have been replaced by specific
+ // implementations of ServiceUtils (e.g. ServiceUtilsForHandlers, ServiceUtilsForEObject),
+ // which depend on a specific context (ExecutionEvent, EObject, ...) instead of
+ // the active editor
+ ////////////////////////////////////////////
+
+ /**
+ * Gets the {@link IMultiDiagramEditor} interface of the a Eclipse active
+ * editor, if possible, or null if not possible. <br>
+ * WARNING - This method doesn't work during the initialization of the main
+ * editor. See note in class doc. <br>
+ * This method return null if there is no active editor, or if the editor is
+ * not instance of IMultiDiagramEditor. <br>
+ * This method is designed to be used by ui actions that interact with the
+ * active editor. <br>
+ * This method should not be used during the editor initialization phase. <br>
+ * In any case, a check should be done on the returned value that can be
+ * null. Usage of this method is discouraged. Use {@link #getMultiDiagramEditorChecked()} instead.
+ *
+ *
+ * @return Get the current {@link IMultiDiagramEditor} or null if not found.
+ */
+ public static IMultiDiagramEditor getMultiDiagramEditor() {
+ // Lookup ServiceRegistry
+ IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if(workbenchWindow == null) {
+ return null;
+ }
+ IWorkbenchPage page = workbenchWindow.getActivePage();
+ if(page == null) {
+ return null;
+ }
+ IEditorPart editor = page.getActiveEditor();
+ if(editor instanceof IMultiDiagramEditor) {
+ return (IMultiDiagramEditor)editor;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Lookup the currently active Diagram from the Papyrus editor. Return the
+ * current Diagram or null if none is active. <br>
+ * WARNING - This method doesn't work during the initialization of the main
+ * editor. See note in class doc. <br>
+ * This method return null if the ServicesRegistry can not be found. <br>
+ * TODO This method introduce dependency on GMF. It can be moved to a GMF
+ * plugin.
+ *
+ * @return The active diagram or null if not found.
+ *
+ * @deprecated The core do make suppositions about the type of nested
+ * Editors, GMF stuff should be moved in GMF projects. In many
+ * case, {@link #lookupActiveNestedIEditor()} can be used.
+ */
+ // @Deprecated
+ // public static Diagram lookupEditorActiveDiagram() {
+ // DiagramEditor diagEditor = lookupActiveDiagramEditor();
+ // return diagEditor == null ? null : diagEditor.getDiagram();
+ // }
+
+ /**
+ * Lookup the currently active Diagram from the Papyrus editor. Return the
+ * current Diagram or null if none is active. <br>
+ * WARNING - This method doesn't work during the initialization of the main
+ * editor. See note in class doc. <br>
+ * This method return null if the ServicesRegistry can not be found. <br>
+ * TODO This method introduce dependency on GMF. It can be moved to a GMF
+ * plugin.
+ *
+ * @return the active diagram editor or null if not found.
+ *
+ * @deprecated The core do make suppositions about the type of nested
+ * Editors, GMF stuff should be moved in GMF projects. In many
+ * case, {@link #lookupActiveNestedIEditor()} can be used.
+ */
+ // @Deprecated
+ // public static DiagramEditor lookupActiveDiagramEditor() {
+ // // Get the active page within the sashcontainer
+ // IEditorPart activeEditor = lookupActiveNestedIEditor();
+ // // Check if it is a GMF DiagramEditor
+ // if(activeEditor instanceof DiagramEditor) {
+ // return ((DiagramEditor)activeEditor);
+ // } else {
+ // // Not found
+ // return null;
+ // }
+ //
+ // }
+
+ /**
+ * Lookup the currently active {@link IEditorPart} from the Papyrus editor.
+ * Return the current nested editor part, or null if it can not be found. <br>
+ * WARNING - This method doesn't work during the initialization of the main
+ * editor. See note in class doc. <br>
+ * This method return null if the ServicesRegistry can not be found. <br>
+ * This method is designed to be used by ui actions that interact with the
+ * active editor. <br>
+ * This method should not be used during the editor initialization phase. <br>
+ * In any case, a check should be done on the returned value that can be
+ * null. An alternative is to use
+ * serviceRegistry.getService(ISashWindowsContainer
+ * .class).getActiveEditor(); <br>
+ * It is preferable to retrieve the ServiceRegistry from elsewhere whenever
+ * it is possible. <br>
+ *
+ *
+ * @return
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * <li>
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
+ * <li>
+ * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
+ * </ul>
+ */
+ @Deprecated
+ public static IEditorPart lookupActiveNestedIEditor() {
+ // Get the sashwindow container
+ ISashWindowsContainer container = getSashWindowContainer();
+ // Get the active page within the sashcontainer
+ return container == null ? null : container.getActiveEditor();
+ }
+
+ /**
+ * Lookup the currently active IEditor in the SashSystem. If the currently
+ * eclipse active editor doesn't contains a {@link ISashWindowsContainer},
+ * return null. If the current SashSystem page is not a IEditor, return
+ * null. <br>
+ * WARNING - This method doesn't work during the initialization of the main
+ * editor. See note in class doc. <br>
+ * This method return null if the ServicesRegistry can not be found. <br>
+ * This method is designed to be used by ui actions that interact with the
+ * active editor. <br>
+ * This method should not be used during the editor initialization phase. <br>
+ * In any case, a check should be done on the returned value that can be
+ * null. An alternative is to use
+ * serviceRegistry.getService(ISashWindowsContainer
+ * .class).getActiveSashWindowsPage(); <br>
+ * It is preferable to retrieve the ServiceRegistry from elsewhere whenever
+ * it is possible.
+ *
+ * @return
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * <li>
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
+ * <li>
+ * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
+ * </ul>
+ */
+ @Deprecated
+ public static IPage lookupActiveNestedPage() {
+
+ // Get the sashwindow container
+ ISashWindowsContainer container = getSashWindowContainer();
+ // Get the active page within the sashcontainer
+ return container == null ? null : container.getActiveSashWindowsPage();
+ }
+
+ /**
+ *
+ * @return
+ */
+ private static ISashWindowsContainer getSashWindowContainer() {
+
+ try {
+ return getServiceRegistryChecked().getService(ISashWindowsContainer.class);
+ } catch (ServiceException e) {
+ // The contract says that we return null if not found
+ return null;
+ }
+ }
+
+ /**
+ * Gets the di resource set.
+ *
+ * @return Get the current {@link DiResourceSet} or null if not found.
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * <li>
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
+ * <li>
+ * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
+ * </ul>
+ */
+ @Deprecated
+ public static DiResourceSet getDiResourceSet() {
+ try {
+ ServicesRegistry registry = getServiceRegistry();
+ return registry == null ? null : registry.getService(DiResourceSet.class);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * Gets the {@link TransactionalEditingDomain} of the current active Eclipse
+ * Editor. This method should be used only when it is sure that the active
+ * editor exist, and that you want the EditingDomain of this editor. <br>
+ * This method return null if the TransactionalEditingDomain can not be
+ * found. <br>
+ * This method is designed to be used by ui actions that interact with the
+ * active editor. <br>
+ * This method should not be used during the editor initialization phase. <br>
+ * In any case, a check should be done on the returned value that can be
+ * null. An alternative is to use {@link #getTransactionalEditingDomainChecked()} and to catch the
+ * exception. <br>
+ * It is preferable to use {@link #getTransactionalEditingDomain(ServicesRegistry)} whenever it is
+ * possible. <br>
+ * In GMF EditParts or EditPolicies, the ServiceRegistry can be retrieved
+ * with methods from
+ * org.eclipse.papyrus.uml.diagram.common.util.DiagramCoreServiceUtils <br>
+ * WARNING: This method can return null if there is no Active Editor. This
+ * happen during the editor initialization, especially when there is no
+ * other editor opened.
+ *
+ * @return Get the current {@link TransactionalEditingDomain} or null if not
+ * found
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * <li>
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
+ * <li>
+ * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
+ * </ul>
+ */
+ @Deprecated
+ public static TransactionalEditingDomain getTransactionalEditingDomain() {
+ try {
+ ServicesRegistry registry = getServiceRegistry();
+ return registry == null ? null : registry.getService(TransactionalEditingDomain.class);
+ } catch (IllegalStateException e) {
+ // Registry can't be found, do nothing.
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * Gets the {@link TransactionalEditingDomain} of the current active Eclipse
+ * Editor. This method should be used only when it is sure that the active
+ * editor exist, and that you want the EditingDomain of this editor. <br>
+ * This method is designed to be used by ui actions that interact with the
+ * active editor. <br>
+ * This method should not be used during the editor initialization phase. <br>
+ * It is preferable to use {@link #getTransactionalEditingDomain(ServicesRegistry)} whenever it is
+ * possible. <br>
+ * This method throw a {@link ServiceException} if the
+ * TransactionalEditingDomain can not be found. <br>
+ * In GMF EditParts or EditPolicies, the ServiceRegistry can be retrieved
+ * with methods from
+ * org.eclipse.papyrus.uml.diagram.common.util.DiagramCoreServiceUtils
+ *
+ *
+ * WARNING: This method throws an exception when no Active Editor is found.
+ * This happen during the editor initialization, especially when there is no
+ * other editor opened.
+ *
+ * @return Get the current {@link TransactionalEditingDomain}
+ * @throws ServiceException
+ * @throws ServiceNotFoundException
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * <li>
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
+ * <li>
+ * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
+ * </ul>
+ */
+ @Deprecated
+ public static TransactionalEditingDomain getTransactionalEditingDomainChecked() throws ServiceException {
+ try {
+ ServicesRegistry registry = getServiceRegistryChecked();
+ return registry.getService(TransactionalEditingDomain.class);
+ } catch (IllegalStateException e) {
+ throw new ServiceException(e);
+ } catch (Exception e) {
+ throw new ServiceException(e);
+ }
+ }
+
+ /**
+ * Gets the {@link TransactionalEditingDomain} registered in the {@link ServicesRegistry}.
+ *
+ * @param servicesRegistry
+ * @return
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * </ul>
+ */
+ @Deprecated
+ public static TransactionalEditingDomain getTransactionalEditingDomain(ServicesRegistry registry) {
+ try {
+ return registry.getService(TransactionalEditingDomain.class);
+ } catch (IllegalStateException e) {
+ // Registry can't be found, do nothing.
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * Gets the {@link TransactionalEditingDomain} registered in the {@link ServicesRegistry}.
+ *
+ * @param servicesRegistry
+ * @return
+ * @throws ServiceException
+ * If the TransactionalEditingDomain can not be found.
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * </ul>
+ */
+ @Deprecated
+ public static TransactionalEditingDomain getTransactionalEditingDomainChecked(ServicesRegistry registry) throws ServiceException {
+ return registry.getService(TransactionalEditingDomain.class);
+ }
+
+ /**
+ * Get the {@link ServicesRegistry}of the currently active eclipse editor. <br>
+ * WARNING - This method doesn't work during the initialization of the main
+ * editor. See note in class doc. <br>
+ * This method return null if the ServicesRegistry can not be found. <br>
+ * This method is designed to be used by ui actions that interact with the
+ * active editor. <br>
+ * This method should not be used during the editor initialization phase. <br>
+ * In any case, a check should be done on the returned value that can be
+ * null. An alternative is to use {@link #getServiceRegistryChecked()} and
+ * to catch the exception. <br>
+ * It is preferable to retrieve the ServiceRegistry from elsewhere whenever
+ * it is possible. <br>
+ * In GMF EditParts or EditPolicies, the ServiceRegistry can be retrieved
+ * with methods from
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF
+ *
+ * <br>
+ * WARNING: This method can return null if there is no Active Editor. This
+ * happen during the editor initialization, especially when there is no
+ * other editor opened.
+ *
+ * @return The {@link ServicesRegistry} or null if not found.
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * <li>
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
+ * <li>
+ * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
+ * </ul>
+ */
+ @Deprecated
+ static public ServicesRegistry getServiceRegistry() {
+ // Lookup ServiceRegistry
+ IMultiDiagramEditor editor = getMultiDiagramEditor();
+ return editor == null ? null : (ServicesRegistry)editor.getAdapter(ServicesRegistry.class);
+ }
+
+ /**
+ * Get the service registry of the currently active main editor. <br>
+ * WARNING - This method doesn't work during the initialization of the main
+ * editor. See note in class doc.
+ *
+ * @return The {@link ServicesRegistry} or null if not found.
+ * @throws ServiceException
+ * If an error occurs.
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * <li>
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
+ * <li>
+ * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
+ * </ul>
+ */
+ @Deprecated
+ static public ServicesRegistry getServiceRegistryChecked() throws ServiceException {
+ // Lookup ServiceRegistry
+ IMultiDiagramEditor editor = getMultiDiagramEditor();
+ if(editor == null) {
+ throw new ServiceException("Can't get ServiceRegistry"); //$NON-NLS-1$
+ }
+
+ return (ServicesRegistry)editor.getAdapter(ServicesRegistry.class);
+ }
+
+ /**
+ * Get the ISashWindowsContentProvider of the active Eclipse Editor, if
+ * possible. <br>
+ * This method return null if the ServiceRegistry can not be found or if an
+ * error occur. <br>
+ * This method is designed to be used by ui actions that interact with the
+ * active editor. <br>
+ * This method should not be used during the editor initialization phase. <br>
+ * In any case, a check should be done on the returned value that can be
+ * null. <br>
+ *
+ * @return the ISashWindowsContentProvider from the main editor or null if
+ * not found.
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * <li>
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
+ * <li>
+ * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
+ * </ul>
+ */
+ @Deprecated
+ static public ISashWindowsContentProvider getISashWindowsContentProvider() {
+
+ try {
+ return getServiceRegistryChecked().getService(ISashWindowsContentProvider.class);
+ } catch (ServiceException e) {
+ // The contract says that we return null if not found
+ return null;
+ }
+ }
+
+ /**
+ * Get the ISashWindowsContentProvider of the active Eclipse Editor, if
+ * possible. <br>
+ * This method return null if the ServiceRegistry can not be found or if an
+ * error occur. <br>
+ * This method is designed to be used by ui actions that interact with the
+ * active editor. <br>
+ * This method should not be used during the editor initialization phase. <br>
+ * In any case, a check should be done on the returned value that can be
+ * null.
+ *
+ * @return the ISashWindowsContentProvider from the main editor or null if
+ * not found.
+ * @deprecated Check
+ * modeling/org.eclipse.mdt.papyrus/trunk/doc/DevelopperDocuments
+ * /cookbook/PapyrusCookBook.odt and use one of the replacement:
+ * <ul>
+ * <li>org.eclipse.papyrus.infra.core.utils.ServiceUtils</li>
+ * <li>
+ * org.eclipse.papyrus.uml.diagram.common.util.ServiceUtilsForGMF</li>
+ * <li>
+ * org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers (to be used with care !)</li>
+ * </ul>
+ */
+ @Deprecated
+ public static IPageMngr getIPageMngr() {
+
+ try {
+ return getServiceRegistryChecked().getService(IPageMngr.class);
+ } catch (ServiceException e) {
+ // The contract says that we return null if not found
+ return null;
+ }
+ }
+
+ /**
+ * Get the Eclipse ActiveEditor.
+ *
+ * @return The active {@link CoreMultiDiagramEditor} or null if not found.
+ * @deprecated Use {@link EditorUtils#getMultiDiagramEditor()}
+ */
+ @Deprecated
+ protected static IEditorPart getWorkbenchActiveEditor() {
+ IMultiDiagramEditor editorPart = getMultiDiagramEditor();
+ if(editorPart instanceof CoreMultiDiagramEditor) {
+ return editorPart;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Gets the {@link IMultiDiagramEditor} interface of the a Eclipse active
+ * editor, if possible, or throw an exception if not possible. <br>
+ * WARNING - This method throw an exception during the initialization of the
+ * main editor. This method throws an exception if there is no active
+ * editor, or if the editor is not instance of IMultiDiagramEditor. <br>
+ * This method is designed to be used by ui actions that interact with the
+ * active editor. <br>
+ *
+ *
+ * @return Get the current {@link IMultiDiagramEditor} or null if not found.
+ * @throws BackboneException
+ * If it is not possible to get an instanceof {@link IMultiDiagramEditor}
+ */
+ public static IMultiDiagramEditor getMultiDiagramEditorChecked() throws BackboneException {
+ IEditorPart editor;
+ try {
+ editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ } catch (NullPointerException e) {
+ // Can't get the active editor
+ throw new BackboneException("Can't get the current Eclipse Active Editor: There is no active editor at this time."); //$NON-NLS-1$
+ }
+
+ if(editor instanceof IMultiDiagramEditor) {
+ return (IMultiDiagramEditor)editor;
+ } else {
+ throw new BackboneException("Can't get an Active Editor instance of IMultiDiagramEditor. (actual type:" + editor.getClass().getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ /**
+ * Obtains the URI of the EMF resource identified by the given editor reference.
+ *
+ * @param editorRef
+ * an editor reference
+ *
+ * @return the best-effort URI of the resource that it edits, or {@code null} if it could not be determined,
+ * including the case when the editor input could not be obtained from the reference
+ */
+ public static URI getResourceURI(IEditorReference editorRef) {
+ try {
+ return getResourceURI(editorRef.getEditorInput());
+ } catch (PartInitException e) {
+ Activator.log.error("Could not obtain editor input from editor reference.", e); //$NON-NLS-1$
+ return null;
+ }
+ }
+
+ /**
+ * Obtains the URI of the EMF resource edited by the given {@code editor}.
+ *
+ * @param editor
+ * an open editor
+ *
+ * @return the best-effort URI of the resource that it edits, or {@code null} if it could not be determined,
+ * such as if the editor input could not be obtained from the editor
+ */
+ public static URI getResourceURI(IEditorPart editor) {
+ return getResourceURI(editor.getEditorInput());
+ }
+
+ /**
+ * Obtains the URI of the EMF resource identified by the given editor input.
+ *
+ * @param editorInput
+ * an editor input
+ *
+ * @return the best-effort URI of the resource that it edits, or {@code null} if it could not be determined
+ */
+ public static URI getResourceURI(IEditorInput editorInput) {
+ URI result = null;
+
+ if(editorInput instanceof IFileEditorInput) {
+ result = URI.createPlatformResourceURI(((IFileEditorInput)editorInput).getFile().getFullPath().toString(), true);
+ } else if(editorInput instanceof URIEditorInput) {
+ result = ((URIEditorInput)editorInput).getURI();
+ } else if(editorInput instanceof IURIEditorInput) {
+ result = URI.createURI(((IURIEditorInput)editorInput).getURI().toASCIIString(), true);
+ } else if(editorInput != null) {
+ // desperation
+ Object adapter = editorInput.getAdapter(URI.class);
+ if(adapter instanceof URI) {
+ result = (URI)adapter;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/PapyrusImageUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/PapyrusImageUtils.java
index 1e5b0e6..5670486 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/PapyrusImageUtils.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/PapyrusImageUtils.java
@@ -1,67 +1,67 @@
-/*****************************************************************************
- * Copyright (c) 2010 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:
- * Tristan Faure (ATOS ORIGIN INTEGRATION) tristan.faure@atosorigin.com - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.core.utils;
-
-import java.io.IOException;
-import java.net.URL;
-
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.papyrus.infra.core.Activator;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * Services to access to Papyrus images
- *
- * @author tristan faure
- *
- */
-public class PapyrusImageUtils {
-
- private static final String default_icon_32 = "/icons/papyrus/32x32/Papyrus_32x32_t.gif";
-
- private static final String default_icon = "/icons/papyrus/Papyrus.gif";
-
- /**
- * get the default icon for Papyrus the image does not have to be disposed
- * as it is registered in an ImageRegistry
- *
- * @return the Image
- */
- public static Image getDefaultIcon() {
- return getIcon(default_icon);
- }
-
- /**
- * get the default icon 32x32 for Papyrus the image does not have to be
- * disposed as it is registered in an ImageRegistry
- *
- * @return the Image
- */
- public static Image getDefaultIcon32() {
- return getIcon(default_icon_32);
- }
-
- private static Image getIcon(String path) {
- String key = Activator.PLUGIN_ID + path;
- Image result = JFaceResources.getImageRegistry().get(key);
- if(result == null) {
- URL url = Activator.getDefault().getBundle().getEntry(path);
- try {
- result = new Image(Display.getDefault(), url.openStream());
- JFaceResources.getImageRegistry().put(key, result);
- } catch (IOException e) {
- }
- }
- return result;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Tristan Faure (ATOS ORIGIN INTEGRATION) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.utils;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Services to access to Papyrus images
+ *
+ * @author tristan faure
+ *
+ */
+public class PapyrusImageUtils {
+
+ private static final String default_icon_32 = "/icons/papyrus/32x32/Papyrus_32x32_t.gif"; //$NON-NLS-1$
+
+ private static final String default_icon = "/icons/papyrus/Papyrus.gif"; //$NON-NLS-1$
+
+ /**
+ * get the default icon for Papyrus the image does not have to be disposed
+ * as it is registered in an ImageRegistry
+ *
+ * @return the Image
+ */
+ public static Image getDefaultIcon() {
+ return getIcon(default_icon);
+ }
+
+ /**
+ * get the default icon 32x32 for Papyrus the image does not have to be
+ * disposed as it is registered in an ImageRegistry
+ *
+ * @return the Image
+ */
+ public static Image getDefaultIcon32() {
+ return getIcon(default_icon_32);
+ }
+
+ private static Image getIcon(String path) {
+ String key = Activator.PLUGIN_ID + path;
+ Image result = JFaceResources.getImageRegistry().get(key);
+ if(result == null) {
+ URL url = Activator.getDefault().getBundle().getEntry(path);
+ try {
+ result = new Image(Display.getDefault(), url.openStream());
+ JFaceResources.getImageRegistry().put(key, result);
+ } catch (IOException e) {
+ }
+ }
+ return result;
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java
index 4a83992..023c1f5 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java
@@ -1,162 +1,162 @@
-/*****************************************************************************
- * Copyright (c) 2010 LIFL & 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:
- * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.utils;
-
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.lifecycleevents.ILifeCycleEventsProvider;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
-import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.tools.util.WorkbenchPartHelper;
-import org.eclipse.ui.IEditorPart;
-
-/**
- * Set of utility methods for accessing core Services. This class provide
- * methods to access the Papyrus well known services. This class is designed to
- * be used from ui Action Handlers or from any code relying on the Eclipse
- * Active Editor. <br>
- * All methods from this class rely on the Eclipse Active Editor, which should
- * be an instance of {@link IMultiDiagramEditor}. If this is not the case,
- * methods throw an exception {@link ServiceException}.
- *
- * @author cedric dumoulin
- *
- * @deprecated 0.10: Use org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForHandlers instead
- */
-@Deprecated
-public class ServiceUtilsForActionHandlers {
-
- private ServiceUtilsForActionHandlers() {
- //Singleton
- }
-
- private final static ServiceUtilsForActionHandlers instance = new ServiceUtilsForActionHandlers();
-
- /**
- * Get the singleton instance of the class.
- *
- * @return
- */
- public static final ServiceUtilsForActionHandlers getInstance() {
- return instance;
- }
-
- /**
- * Get the service registry from the specified parameter.
- *
- * @param from
- * @return
- */
- public ServicesRegistry getServiceRegistry() throws ServiceException {
- IEditorPart editor = WorkbenchPartHelper.getCurrentActiveEditorPart();
- if(editor != null) {
- ServicesRegistry serviceRegistry = (ServicesRegistry)editor.getAdapter(ServicesRegistry.class);
- if(serviceRegistry != null) {
- return serviceRegistry;
- }
- }
-
- // Not found
- throw new ServiceNotFoundException("Can't get the ServiceRegistry from current Eclipse Active Editor");
- }
-
- /**
- * Gets the {@link TransactionalEditingDomain} registered in the {@link ServicesRegistry}.
- *
- * @return
- * @throws ServiceException
- * If an error occurs while getting the requested service.
- */
- public TransactionalEditingDomain getTransactionalEditingDomain() throws ServiceException {
- return getServiceRegistry().getService(TransactionalEditingDomain.class);
- }
-
- /**
- * Gets the {@link IPageMngr} registered in the {@link ServicesRegistry}.
- *
- * @return
- * @throws ServiceException
- * If an error occurs while getting the requested service.
- *
- * @deprecated Use {@link #getIPageManager} instead
- */
- @Deprecated
- public IPageMngr getIPageMngr() throws ServiceException {
- return getServiceRegistry().getService(IPageMngr.class);
- }
-
- /**
- * Gets the {@link IPageManager} registered in the {@link ServicesRegistry}.
- *
- * @return
- * @throws ServiceException
- * If an error occurs while getting the requested service.
- */
- public IPageManager getIPageManager() throws ServiceException {
- return getServiceRegistry().getService(IPageManager.class);
- }
-
- /**
- * Gets the {@link IPageMngr} registered in the {@link ServicesRegistry}.
- *
- * @return
- * @throws ServiceException
- * If an error occurs while getting the requested service.
- */
- public ModelSet getModelSet() throws ServiceException {
- return getServiceRegistry().getService(ModelSet.class);
- }
-
- /**
- * Gets the {@link ILifeCycleEventsProvider} registered in the {@link ServicesRegistry}.
- *
- * @param from
- * @return
- * @throws ServiceException
- * If an error occurs while getting the requested service.
- */
- public ILifeCycleEventsProvider getILifeCycleEventsProvider() throws ServiceException {
- return getServiceRegistry().getService(ILifeCycleEventsProvider.class);
- }
-
- /**
- * Gets the {@link ISashWindowsContainer} registered in the {@link ServicesRegistry}.
- *
- * @param from
- * @return
- * @throws ServiceException
- * If an error occurs while getting the requested service.
- */
- public ISashWindowsContainer getISashWindowsContainer() throws ServiceException {
- return getServiceRegistry().getService(ISashWindowsContainer.class);
- }
-
- /**
- * Gets the {@link IEditorPart} of the currently nested active editor.
- *
- * @param from
- * @return
- * @throws ServiceException
- * If an error occurs while getting the requested service.
- */
- public IEditorPart getNestedActiveIEditorPart() throws ServiceException {
- return getISashWindowsContainer().getActiveEditor();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010 LIFL & 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.utils;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.lifecycleevents.ILifeCycleEventsProvider;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.tools.util.WorkbenchPartHelper;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Set of utility methods for accessing core Services. This class provide
+ * methods to access the Papyrus well known services. This class is designed to
+ * be used from ui Action Handlers or from any code relying on the Eclipse
+ * Active Editor. <br>
+ * All methods from this class rely on the Eclipse Active Editor, which should
+ * be an instance of {@link IMultiDiagramEditor}. If this is not the case,
+ * methods throw an exception {@link ServiceException}.
+ *
+ * @author cedric dumoulin
+ *
+ * @deprecated 0.10: Use org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForHandlers instead
+ */
+@Deprecated
+public class ServiceUtilsForActionHandlers {
+
+ private ServiceUtilsForActionHandlers() {
+ //Singleton
+ }
+
+ private final static ServiceUtilsForActionHandlers instance = new ServiceUtilsForActionHandlers();
+
+ /**
+ * Get the singleton instance of the class.
+ *
+ * @return
+ */
+ public static final ServiceUtilsForActionHandlers getInstance() {
+ return instance;
+ }
+
+ /**
+ * Get the service registry from the specified parameter.
+ *
+ * @param from
+ * @return
+ */
+ public ServicesRegistry getServiceRegistry() throws ServiceException {
+ IEditorPart editor = WorkbenchPartHelper.getCurrentActiveEditorPart();
+ if(editor != null) {
+ ServicesRegistry serviceRegistry = (ServicesRegistry)editor.getAdapter(ServicesRegistry.class);
+ if(serviceRegistry != null) {
+ return serviceRegistry;
+ }
+ }
+
+ // Not found
+ throw new ServiceNotFoundException("Can't get the ServiceRegistry from current Eclipse Active Editor"); //$NON-NLS-1$
+ }
+
+ /**
+ * Gets the {@link TransactionalEditingDomain} registered in the {@link ServicesRegistry}.
+ *
+ * @return
+ * @throws ServiceException
+ * If an error occurs while getting the requested service.
+ */
+ public TransactionalEditingDomain getTransactionalEditingDomain() throws ServiceException {
+ return getServiceRegistry().getService(TransactionalEditingDomain.class);
+ }
+
+ /**
+ * Gets the {@link IPageMngr} registered in the {@link ServicesRegistry}.
+ *
+ * @return
+ * @throws ServiceException
+ * If an error occurs while getting the requested service.
+ *
+ * @deprecated Use {@link #getIPageManager} instead
+ */
+ @Deprecated
+ public IPageMngr getIPageMngr() throws ServiceException {
+ return getServiceRegistry().getService(IPageMngr.class);
+ }
+
+ /**
+ * Gets the {@link IPageManager} registered in the {@link ServicesRegistry}.
+ *
+ * @return
+ * @throws ServiceException
+ * If an error occurs while getting the requested service.
+ */
+ public IPageManager getIPageManager() throws ServiceException {
+ return getServiceRegistry().getService(IPageManager.class);
+ }
+
+ /**
+ * Gets the {@link IPageMngr} registered in the {@link ServicesRegistry}.
+ *
+ * @return
+ * @throws ServiceException
+ * If an error occurs while getting the requested service.
+ */
+ public ModelSet getModelSet() throws ServiceException {
+ return getServiceRegistry().getService(ModelSet.class);
+ }
+
+ /**
+ * Gets the {@link ILifeCycleEventsProvider} registered in the {@link ServicesRegistry}.
+ *
+ * @param from
+ * @return
+ * @throws ServiceException
+ * If an error occurs while getting the requested service.
+ */
+ public ILifeCycleEventsProvider getILifeCycleEventsProvider() throws ServiceException {
+ return getServiceRegistry().getService(ILifeCycleEventsProvider.class);
+ }
+
+ /**
+ * Gets the {@link ISashWindowsContainer} registered in the {@link ServicesRegistry}.
+ *
+ * @param from
+ * @return
+ * @throws ServiceException
+ * If an error occurs while getting the requested service.
+ */
+ public ISashWindowsContainer getISashWindowsContainer() throws ServiceException {
+ return getServiceRegistry().getService(ISashWindowsContainer.class);
+ }
+
+ /**
+ * Gets the {@link IEditorPart} of the currently nested active editor.
+ *
+ * @param from
+ * @return
+ * @throws ServiceException
+ * If an error occurs while getting the requested service.
+ */
+ public IEditorPart getNestedActiveIEditorPart() throws ServiceException {
+ return getISashWindowsContainer().getActiveEditor();
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForWorkbenchPage.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForWorkbenchPage.java
index 6343892..da96d4a 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForWorkbenchPage.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForWorkbenchPage.java
@@ -1,62 +1,62 @@
-/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.core.utils;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.ui.IWorkbenchPage;
-
-/**
- * A ServiceUtils implementation for manipulating the Papyrus services from an IWorkbenchPage
- *
- * @author Camille Letavernier
- *
- */
-public class ServiceUtilsForWorkbenchPage extends AbstractServiceUtils<IWorkbenchPage> {
-
- @Override
- public ServicesRegistry getServiceRegistry(IWorkbenchPage from) throws ServiceException {
- IAdaptable adaptable = null;
- if(from instanceof IAdaptable) {
- adaptable = (IAdaptable)from;
- } else if(from != null) {
- //421392: [Model Explorer] Link with Editor does not work properly
- //https://bugs.eclipse.org/bugs/show_bug.cgi?id=421392
-
- //Since Eclipse 4.4, the concrete WorkbenchPage is not IAdaptable anymore.
- //Try the ActivePart
- adaptable = from.getActivePart();
- }
-
- if(adaptable != null) {
- ServicesRegistry registry = (ServicesRegistry)adaptable.getAdapter(ServicesRegistry.class);
- if(registry != null) {
- return registry;
- }
- }
-
-
- throw new ServiceException("Cannot resolve the ServiceRegistry from the IWorkbenchPage. Page: " + from);
- }
-
- public static ServiceUtilsForWorkbenchPage getInstance() {
- return instance;
- }
-
- private static ServiceUtilsForWorkbenchPage instance = new ServiceUtilsForWorkbenchPage();
-
- private ServiceUtilsForWorkbenchPage() {
- //Singleton
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.utils;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.ui.IWorkbenchPage;
+
+/**
+ * A ServiceUtils implementation for manipulating the Papyrus services from an IWorkbenchPage
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class ServiceUtilsForWorkbenchPage extends AbstractServiceUtils<IWorkbenchPage> {
+
+ @Override
+ public ServicesRegistry getServiceRegistry(IWorkbenchPage from) throws ServiceException {
+ IAdaptable adaptable = null;
+ if(from instanceof IAdaptable) {
+ adaptable = (IAdaptable)from;
+ } else if(from != null) {
+ //421392: [Model Explorer] Link with Editor does not work properly
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=421392
+
+ //Since Eclipse 4.4, the concrete WorkbenchPage is not IAdaptable anymore.
+ //Try the ActivePart
+ adaptable = from.getActivePart();
+ }
+
+ if(adaptable != null) {
+ ServicesRegistry registry = (ServicesRegistry)adaptable.getAdapter(ServicesRegistry.class);
+ if(registry != null) {
+ return registry;
+ }
+ }
+
+
+ throw new ServiceException("Cannot resolve the ServiceRegistry from the IWorkbenchPage. Page: " + from); //$NON-NLS-1$
+ }
+
+ public static ServiceUtilsForWorkbenchPage getInstance() {
+ return instance;
+ }
+
+ private static ServiceUtilsForWorkbenchPage instance = new ServiceUtilsForWorkbenchPage();
+
+ private ServiceUtilsForWorkbenchPage() {
+ //Singleton
+ }
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/BadStateException.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/BadStateException.java
index a7651c8..a9885e6 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/BadStateException.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/BadStateException.java
@@ -1,49 +1,60 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-/**
- * @author cedric dumoulin
- *
- */
-public class BadStateException extends ServiceException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor.
- *
- */
- public BadStateException(ServiceState expectedState, ServiceState state, ServiceDescriptor descriptor) {
- super("Bad state for service '" + descriptor.getKey() + "'. Expected '" + expectedState + "' found '" + state + "'.");
- }
-
- /**
- *
- * Constructor.
- *
- * @param text
- * @param state
- * @param serviceDescriptor
- */
- public BadStateException(String text, ServiceState state, ServiceDescriptor descriptor) {
- super(text + " (Service= '" + (descriptor!=null?descriptor.getKey():"unknown") + ", state= " + state + ")");
- }
-
- /**
- *
- * Constructor.
- *
- * @param text
- * @param state
- * @param serviceDescriptor
- */
- public BadStateException(String text, ServiceState state, ServiceDescriptor descriptor, Throwable cause) {
- super(text + " (Service= '" + descriptor.getKey() + ", state= " + state + ")", cause);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class BadStateException extends ServiceException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public BadStateException(ServiceState expectedState, ServiceState state, ServiceDescriptor descriptor) {
+ super("Bad state for service '" + descriptor.getKey() + "'. Expected '" + expectedState + "' found '" + state + "'."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param text
+ * @param state
+ * @param serviceDescriptor
+ */
+ public BadStateException(String text, ServiceState state, ServiceDescriptor descriptor) {
+ super(text + " (Service= '" + (descriptor!=null?descriptor.getKey():"unknown") + ", state= " + state + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param text
+ * @param state
+ * @param serviceDescriptor
+ */
+ public BadStateException(String text, ServiceState state, ServiceDescriptor descriptor, Throwable cause) {
+ super(text + " (Service= '" + descriptor.getKey() + ", state= " + state + ")", cause); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/DescriptorsCache.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/DescriptorsCache.java
index 751010a..c7e897c 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/DescriptorsCache.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/DescriptorsCache.java
@@ -1,358 +1,358 @@
-/*****************************************************************************
- * Copyright (c) 2012 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-import java.util.List;
-
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AbstractServiceDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AliasDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.Descriptors;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.RegistryDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServiceDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServiceFactoryDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServiceSetDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServicedescriptorsFactory;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.StartupKind;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AbstractServiceIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AliasIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.RegistryIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceFactoryIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceSetIdDesc;
-
-
-/**
- * A cache used to query the {@link IServiceDescriptorsWithIdProvider}. The cache return resolved descriptors,
- * in the form of instance of the ServiceDescriptors model.
- *
- * @author cedric dumoulin
- *
- */
-public class DescriptorsCache {
-
- /**
- * The cache of descriptors.
- */
- protected Descriptors descriptorsCache;
-
- /**
- * The provider used to query declarations.
- */
- protected ServiceDescriptorsWithIdProviderCollection declaredDescriptorProvider;
-
-
-
- /**
- *
- * Constructor.
- *
- */
- public DescriptorsCache() {
- declaredDescriptorProvider = new ServiceDescriptorsWithIdProviderCollection();
- descriptorsCache = ServicedescriptorsFactory.eINSTANCE.createDescriptors();
- }
-
- /**
- * Add all the provided {@link IServiceDescriptorsWithIdProvider} to the list of providers to use.
- *
- * @param declaredDescriptorProviders
- */
- public void addAll(IServiceDescriptorsWithIdProvider... declaredDescriptorProviders) {
-
- declaredDescriptorProvider.addAll(declaredDescriptorProviders);
- descriptorsCache = ServicedescriptorsFactory.eINSTANCE.createDescriptors();
-
- }
-
- /**
- * Get the descriptor for the specified registry.
- * The descriptor is built from the declarations found in {@link #declaredDescriptorProvider}.
- * The descriptor is cached. This mean that subsequent calls for the same name will return the same
- * result. <br/>
- * If the registry is not found, throws an exception.
- *
- * @param registryName
- * The name of the registry for which the descriptor is required.
- *
- * @return The registry descriptor
- * @throws DeclarationException
- * If an error occur while reading declarations.
- *
- */
- public RegistryDesc getRegistryDesc(String registryName) throws DeclarationException {
-
- // Try from cache
- RegistryDesc desc = descriptorsCache.getRegistryDesc(registryName);
-
- if(desc != null) {
- return desc;
- }
-
- // Load from providers
- // this can throw exception
- RegistryIdDesc idDesc = declaredDescriptorProvider.getRegistryIdDesc(registryName);
-
- // Create a RegistryDesc from a RegistryIdDesc, and set minimal data
- desc = ServicedescriptorsFactory.eINSTANCE.createRegistryDesc();
- desc.setName(idDesc.getName());
- desc.setIsUnique(idDesc.isUnique());
- desc.setDescription(idDesc.getDescription());
-
- // Add it to the cache, so it can be found by other requests
- descriptorsCache.getRegistries().add(desc);
-
- // Set the references
- // serviceSet
- for(String serviceSetId : idDesc.getSets()) {
- desc.getServiceSets().add(getServiceSetDesc(serviceSetId));
- }
-
- // extends
- for(String extendsId : idDesc.getExtends()) {
- desc.getExtends().add(getRegistryDesc(extendsId));
- }
-
- // parents
- for(String extendsId : idDesc.getParents()) {
- desc.getParents().add(getRegistryDesc(extendsId));
- }
-
-
- // Resolve inheritances
- // need to compute services available for this registry
- // Available services are those from all sets, and from extends.
- computeRegistryServices(desc);
-
-
- return desc;
- }
-
- /**
- * Get the {@link ServiceSetDesc} for the specified name.
- * The descriptor is built from the declarations found in {@link #declaredDescriptorProvider}.
- * The descriptor is cached. This mean that subsequent calls for the same name will return the same
- * result. <br/>
- * If the descriptor is not found, throws an exception.
- *
- * @param serviceSetId
- * @return
- * @throws DeclarationException
- */
- public ServiceSetDesc getServiceSetDesc(String serviceSetId) throws DeclarationException {
- // Try from cache
- ServiceSetDesc desc = descriptorsCache.getServiceSetDesc(serviceSetId);
-
- if(desc != null) {
- return desc;
- }
-
- // Load from providers
- // this can throw exception
- ServiceSetIdDesc idDesc = declaredDescriptorProvider.getServiceSet(serviceSetId);
-
- // Create a RegistryDesc from a RegistryIdDesc, and set minimal data
- desc = ServicedescriptorsFactory.eINSTANCE.createServiceSetDesc();
- desc.setName(idDesc.getName());
- desc.setDescription(idDesc.getDescription());
-
- // Add it to the cache, so it can be found by other requests
- descriptorsCache.getServiceSets().add(desc);
-
- // Set the references
- // serviceSet
- for(AbstractServiceIdDesc serviceIdDesc : idDesc.getServiceDescriptors()) {
- desc.getOwnedServices().add(transformAbstractServiceIdDescToRef(serviceIdDesc));
- }
-
- // extends
- for(String extendsId : idDesc.getExtends()) {
- desc.getExtends().add(getServiceSetDesc(extendsId));
- }
-
- // Resolve inheritances
- // need to compute services available for this set
- // Available services are those from all extends.
- computeServiceSetServices(desc);
-
- return desc;
- }
-
- /**
- * Transform {@link AncestorEvent} {@link AbstractServiceIdDesc} to an {@link AbstractServiceDesc}.
- *
- * @param serviceIdDesc
- * @return
- */
- private AbstractServiceDesc transformAbstractServiceIdDescToRef(AbstractServiceIdDesc serviceIdDesc) {
- if(serviceIdDesc instanceof ServiceFactoryIdDesc) {
- return transformServiceFactoryIdDescToRef((ServiceFactoryIdDesc)serviceIdDesc);
- } else if(serviceIdDesc instanceof ServiceIdDesc) {
- return transformServiceIdDescToRef((ServiceIdDesc)serviceIdDesc);
- } else if(serviceIdDesc instanceof AliasIdDesc) {
- return transformAliasIdDescToRef((AliasIdDesc)serviceIdDesc);
- } else {
- // Should never happen
- throw new UnsupportedOperationException("Don't no how to transform '" + serviceIdDesc + "' to AbstractServiceDesc.");
- }
- }
-
- /**
- *
- * @param serviceIdDesc
- * @return
- */
- private AbstractServiceDesc transformServiceIdDescToRef(ServiceIdDesc serviceIdDesc) {
-
- ServiceDesc desc = ServicedescriptorsFactory.eINSTANCE.createServiceDesc();
- desc.setBundleID(serviceIdDesc.getBundleID());
- desc.setClassname(serviceIdDesc.getClassname());
- desc.setDescription(serviceIdDesc.getDescription());
- desc.setName(serviceIdDesc.getName());
- desc.setPriority(serviceIdDesc.getPriority());
- desc.setStartKind(transformStartKind(serviceIdDesc.getStartKind()));
- // dependsOn
- desc.getDependsOnIds().addAll(serviceIdDesc.getDependsOn());
-
- return desc;
- }
-
- /**
- *
- * @param startKind
- * @return
- */
- private StartupKind transformStartKind(org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.StartupKind startKind) {
-
- switch(startKind) {
- case STARTUP:
- return StartupKind.STARTUP;
- case LAZY:
- return StartupKind.LAZY;
- default:
- return StartupKind.STARTUP;
- }
- }
-
- /**
- *
- * @param serviceIdDesc
- * @return
- */
- private AbstractServiceDesc transformAliasIdDescToRef(AliasIdDesc serviceIdDesc) {
- AliasDesc desc = ServicedescriptorsFactory.eINSTANCE.createAliasDesc();
- desc.setBundleID(serviceIdDesc.getBundleID());
- desc.setDescription(serviceIdDesc.getDescription());
- desc.setName(serviceIdDesc.getName());
- desc.setPriority(serviceIdDesc.getPriority());
- // dependsOn
- desc.getDependsOnIds().addAll(serviceIdDesc.getDependsOn());
-
- return desc;
-
- }
-
- /**
- *
- * @param serviceIdDesc
- * @return
- */
- private AbstractServiceDesc transformServiceFactoryIdDescToRef(ServiceFactoryIdDesc serviceIdDesc) {
- ServiceFactoryDesc desc = ServicedescriptorsFactory.eINSTANCE.createServiceFactoryDesc();
- desc.setBundleID(serviceIdDesc.getBundleID());
- desc.setClassname(serviceIdDesc.getClassname());
- desc.setDescription(serviceIdDesc.getDescription());
- desc.setName(serviceIdDesc.getName());
- desc.setPriority(serviceIdDesc.getPriority());
- desc.setStartKind(transformStartKind(serviceIdDesc.getStartKind()));
- // dependsOn
- desc.getDependsOnIds().addAll(serviceIdDesc.getDependsOn());
-
- return desc;
- }
-
- /**
- * Compute the services available from this registry. This implies
- * resolving inheritances from extends.
- *
- * @param registryDesc
- * The descriptor for which services should be computed.
- *
- *
- */
- private void computeRegistryServices(RegistryDesc registryDesc) {
-
- // Reset the services
- List<AbstractServiceDesc> services = registryDesc.getServices();
- services.clear();
-
- // do the union of all services from sets
- // Do not check for double names (this is done in the Registry).
- for(ServiceSetDesc setDesc : registryDesc.getServiceSets()) {
-
- services.addAll(setDesc.getServices());
- }
-
- // Add services from extends
- // Add a services from a parent only if there is not a service with the same name
- // in the child
- for(RegistryDesc extendsDesc : registryDesc.getExtends()) {
-
- // Walk each service of the parent
- for(AbstractServiceDesc serviceDesc : extendsDesc.getServices()) {
-
- // Check if the service is already in the child
- if(!registryDesc.servicesContains(serviceDesc.getName())) {
- services.add(serviceDesc);
- }
- }
- }
-
- }
-
- /**
- * Compute the services available from the specified {@link ServiceSetDesc}. This reset and compute
- * the {@link ServiceSetDesc#getServices()} property.
- *
- * @param serviceSetDesc
- */
- private void computeServiceSetServices(ServiceSetDesc serviceSetDesc) {
-
- // Reset the services
- List<AbstractServiceDesc> services = serviceSetDesc.getServices();
- services.clear();
-
- // Add its own services
- services.addAll(serviceSetDesc.getOwnedServices());
-
- // Add services from extends
- // Add a services from an extends only if there is not a service with the same name
- // in the child
- for(ServiceSetDesc extendsDesc : serviceSetDesc.getExtends()) {
-
- // Walk each service of the parent
- for(AbstractServiceDesc serviceDesc : extendsDesc.getServices()) {
-
- // Check if the service is already in the child
- if(!serviceSetDesc.servicesContains(serviceDesc.getName())) {
- services.add(serviceDesc);
- }
- }
- }
-
- }
-
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+import java.util.List;
+
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AbstractServiceDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AliasDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.Descriptors;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.RegistryDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServiceDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServiceFactoryDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServiceSetDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServicedescriptorsFactory;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.StartupKind;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AbstractServiceIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AliasIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.RegistryIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceFactoryIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceSetIdDesc;
+
+
+/**
+ * A cache used to query the {@link IServiceDescriptorsWithIdProvider}. The cache return resolved descriptors,
+ * in the form of instance of the ServiceDescriptors model.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class DescriptorsCache {
+
+ /**
+ * The cache of descriptors.
+ */
+ protected Descriptors descriptorsCache;
+
+ /**
+ * The provider used to query declarations.
+ */
+ protected ServiceDescriptorsWithIdProviderCollection declaredDescriptorProvider;
+
+
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public DescriptorsCache() {
+ declaredDescriptorProvider = new ServiceDescriptorsWithIdProviderCollection();
+ descriptorsCache = ServicedescriptorsFactory.eINSTANCE.createDescriptors();
+ }
+
+ /**
+ * Add all the provided {@link IServiceDescriptorsWithIdProvider} to the list of providers to use.
+ *
+ * @param declaredDescriptorProviders
+ */
+ public void addAll(IServiceDescriptorsWithIdProvider... declaredDescriptorProviders) {
+
+ declaredDescriptorProvider.addAll(declaredDescriptorProviders);
+ descriptorsCache = ServicedescriptorsFactory.eINSTANCE.createDescriptors();
+
+ }
+
+ /**
+ * Get the descriptor for the specified registry.
+ * The descriptor is built from the declarations found in {@link #declaredDescriptorProvider}.
+ * The descriptor is cached. This mean that subsequent calls for the same name will return the same
+ * result. <br/>
+ * If the registry is not found, throws an exception.
+ *
+ * @param registryName
+ * The name of the registry for which the descriptor is required.
+ *
+ * @return The registry descriptor
+ * @throws DeclarationException
+ * If an error occur while reading declarations.
+ *
+ */
+ public RegistryDesc getRegistryDesc(String registryName) throws DeclarationException {
+
+ // Try from cache
+ RegistryDesc desc = descriptorsCache.getRegistryDesc(registryName);
+
+ if(desc != null) {
+ return desc;
+ }
+
+ // Load from providers
+ // this can throw exception
+ RegistryIdDesc idDesc = declaredDescriptorProvider.getRegistryIdDesc(registryName);
+
+ // Create a RegistryDesc from a RegistryIdDesc, and set minimal data
+ desc = ServicedescriptorsFactory.eINSTANCE.createRegistryDesc();
+ desc.setName(idDesc.getName());
+ desc.setIsUnique(idDesc.isUnique());
+ desc.setDescription(idDesc.getDescription());
+
+ // Add it to the cache, so it can be found by other requests
+ descriptorsCache.getRegistries().add(desc);
+
+ // Set the references
+ // serviceSet
+ for(String serviceSetId : idDesc.getSets()) {
+ desc.getServiceSets().add(getServiceSetDesc(serviceSetId));
+ }
+
+ // extends
+ for(String extendsId : idDesc.getExtends()) {
+ desc.getExtends().add(getRegistryDesc(extendsId));
+ }
+
+ // parents
+ for(String extendsId : idDesc.getParents()) {
+ desc.getParents().add(getRegistryDesc(extendsId));
+ }
+
+
+ // Resolve inheritances
+ // need to compute services available for this registry
+ // Available services are those from all sets, and from extends.
+ computeRegistryServices(desc);
+
+
+ return desc;
+ }
+
+ /**
+ * Get the {@link ServiceSetDesc} for the specified name.
+ * The descriptor is built from the declarations found in {@link #declaredDescriptorProvider}.
+ * The descriptor is cached. This mean that subsequent calls for the same name will return the same
+ * result. <br/>
+ * If the descriptor is not found, throws an exception.
+ *
+ * @param serviceSetId
+ * @return
+ * @throws DeclarationException
+ */
+ public ServiceSetDesc getServiceSetDesc(String serviceSetId) throws DeclarationException {
+ // Try from cache
+ ServiceSetDesc desc = descriptorsCache.getServiceSetDesc(serviceSetId);
+
+ if(desc != null) {
+ return desc;
+ }
+
+ // Load from providers
+ // this can throw exception
+ ServiceSetIdDesc idDesc = declaredDescriptorProvider.getServiceSet(serviceSetId);
+
+ // Create a RegistryDesc from a RegistryIdDesc, and set minimal data
+ desc = ServicedescriptorsFactory.eINSTANCE.createServiceSetDesc();
+ desc.setName(idDesc.getName());
+ desc.setDescription(idDesc.getDescription());
+
+ // Add it to the cache, so it can be found by other requests
+ descriptorsCache.getServiceSets().add(desc);
+
+ // Set the references
+ // serviceSet
+ for(AbstractServiceIdDesc serviceIdDesc : idDesc.getServiceDescriptors()) {
+ desc.getOwnedServices().add(transformAbstractServiceIdDescToRef(serviceIdDesc));
+ }
+
+ // extends
+ for(String extendsId : idDesc.getExtends()) {
+ desc.getExtends().add(getServiceSetDesc(extendsId));
+ }
+
+ // Resolve inheritances
+ // need to compute services available for this set
+ // Available services are those from all extends.
+ computeServiceSetServices(desc);
+
+ return desc;
+ }
+
+ /**
+ * Transform {@link AncestorEvent} {@link AbstractServiceIdDesc} to an {@link AbstractServiceDesc}.
+ *
+ * @param serviceIdDesc
+ * @return
+ */
+ private AbstractServiceDesc transformAbstractServiceIdDescToRef(AbstractServiceIdDesc serviceIdDesc) {
+ if(serviceIdDesc instanceof ServiceFactoryIdDesc) {
+ return transformServiceFactoryIdDescToRef((ServiceFactoryIdDesc)serviceIdDesc);
+ } else if(serviceIdDesc instanceof ServiceIdDesc) {
+ return transformServiceIdDescToRef((ServiceIdDesc)serviceIdDesc);
+ } else if(serviceIdDesc instanceof AliasIdDesc) {
+ return transformAliasIdDescToRef((AliasIdDesc)serviceIdDesc);
+ } else {
+ // Should never happen
+ throw new UnsupportedOperationException("Don't no how to transform '" + serviceIdDesc + "' to AbstractServiceDesc."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ /**
+ *
+ * @param serviceIdDesc
+ * @return
+ */
+ private AbstractServiceDesc transformServiceIdDescToRef(ServiceIdDesc serviceIdDesc) {
+
+ ServiceDesc desc = ServicedescriptorsFactory.eINSTANCE.createServiceDesc();
+ desc.setBundleID(serviceIdDesc.getBundleID());
+ desc.setClassname(serviceIdDesc.getClassname());
+ desc.setDescription(serviceIdDesc.getDescription());
+ desc.setName(serviceIdDesc.getName());
+ desc.setPriority(serviceIdDesc.getPriority());
+ desc.setStartKind(transformStartKind(serviceIdDesc.getStartKind()));
+ // dependsOn
+ desc.getDependsOnIds().addAll(serviceIdDesc.getDependsOn());
+
+ return desc;
+ }
+
+ /**
+ *
+ * @param startKind
+ * @return
+ */
+ private StartupKind transformStartKind(org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.StartupKind startKind) {
+
+ switch(startKind) {
+ case STARTUP:
+ return StartupKind.STARTUP;
+ case LAZY:
+ return StartupKind.LAZY;
+ default:
+ return StartupKind.STARTUP;
+ }
+ }
+
+ /**
+ *
+ * @param serviceIdDesc
+ * @return
+ */
+ private AbstractServiceDesc transformAliasIdDescToRef(AliasIdDesc serviceIdDesc) {
+ AliasDesc desc = ServicedescriptorsFactory.eINSTANCE.createAliasDesc();
+ desc.setBundleID(serviceIdDesc.getBundleID());
+ desc.setDescription(serviceIdDesc.getDescription());
+ desc.setName(serviceIdDesc.getName());
+ desc.setPriority(serviceIdDesc.getPriority());
+ // dependsOn
+ desc.getDependsOnIds().addAll(serviceIdDesc.getDependsOn());
+
+ return desc;
+
+ }
+
+ /**
+ *
+ * @param serviceIdDesc
+ * @return
+ */
+ private AbstractServiceDesc transformServiceFactoryIdDescToRef(ServiceFactoryIdDesc serviceIdDesc) {
+ ServiceFactoryDesc desc = ServicedescriptorsFactory.eINSTANCE.createServiceFactoryDesc();
+ desc.setBundleID(serviceIdDesc.getBundleID());
+ desc.setClassname(serviceIdDesc.getClassname());
+ desc.setDescription(serviceIdDesc.getDescription());
+ desc.setName(serviceIdDesc.getName());
+ desc.setPriority(serviceIdDesc.getPriority());
+ desc.setStartKind(transformStartKind(serviceIdDesc.getStartKind()));
+ // dependsOn
+ desc.getDependsOnIds().addAll(serviceIdDesc.getDependsOn());
+
+ return desc;
+ }
+
+ /**
+ * Compute the services available from this registry. This implies
+ * resolving inheritances from extends.
+ *
+ * @param registryDesc
+ * The descriptor for which services should be computed.
+ *
+ *
+ */
+ private void computeRegistryServices(RegistryDesc registryDesc) {
+
+ // Reset the services
+ List<AbstractServiceDesc> services = registryDesc.getServices();
+ services.clear();
+
+ // do the union of all services from sets
+ // Do not check for double names (this is done in the Registry).
+ for(ServiceSetDesc setDesc : registryDesc.getServiceSets()) {
+
+ services.addAll(setDesc.getServices());
+ }
+
+ // Add services from extends
+ // Add a services from a parent only if there is not a service with the same name
+ // in the child
+ for(RegistryDesc extendsDesc : registryDesc.getExtends()) {
+
+ // Walk each service of the parent
+ for(AbstractServiceDesc serviceDesc : extendsDesc.getServices()) {
+
+ // Check if the service is already in the child
+ if(!registryDesc.servicesContains(serviceDesc.getName())) {
+ services.add(serviceDesc);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Compute the services available from the specified {@link ServiceSetDesc}. This reset and compute
+ * the {@link ServiceSetDesc#getServices()} property.
+ *
+ * @param serviceSetDesc
+ */
+ private void computeServiceSetServices(ServiceSetDesc serviceSetDesc) {
+
+ // Reset the services
+ List<AbstractServiceDesc> services = serviceSetDesc.getServices();
+ services.clear();
+
+ // Add its own services
+ services.addAll(serviceSetDesc.getOwnedServices());
+
+ // Add services from extends
+ // Add a services from an extends only if there is not a service with the same name
+ // in the child
+ for(ServiceSetDesc extendsDesc : serviceSetDesc.getExtends()) {
+
+ // Walk each service of the parent
+ for(AbstractServiceDesc serviceDesc : extendsDesc.getServices()) {
+
+ // Check if the service is already in the child
+ if(!serviceSetDesc.servicesContains(serviceDesc.getName())) {
+ services.add(serviceDesc);
+ }
+ }
+ }
+
+ }
+
+
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServiceDescriptorsWithIdProvider.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServiceDescriptorsWithIdProvider.java
index f5a3454..d0d424c 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServiceDescriptorsWithIdProvider.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServiceDescriptorsWithIdProvider.java
@@ -1,534 +1,534 @@
-/*****************************************************************************
- * Copyright (c) 2012 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.papyrus.infra.core.serviceregistry.internal.BadDeclarationException;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AbstractServiceIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AliasIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.RegistryIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceSetIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServicedescriptorswithidFactory;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.StartupKind;
-
-
-/**
- * A declared service provider reading declaration from eclipse extensions (plugin.xml).
- *
- * @author cedric dumoulin
- *
- */
-public class ExtensionServiceDescriptorsWithIdProvider implements IServiceDescriptorsWithIdProvider {
-
- /** Namespace where to look for the extension points. */
- public static String extensionPointNamespace = "org.eclipse.papyrus.infra.core.serviceregistry";
-
- /** ID of the extension (schema filename) */
- public static final String SERVICE_EXTENSION_ID = "service";
-
- /** Extension point name inside the extension description **/
- public final static String REGISTRY_ELEMENT_NAME = "registry";
-
- /** Extension point name inside the extension description **/
- public final static String REGISTRY_EXTENDS_ELEMENT = "extendedRegistry";
-
- /** Extension point name inside the extension description **/
- public final static String REGISTRY_PARENT_ELEMENT = "parentRegistry";
-
- /** Extension point name inside the extension description **/
- public final static String REGISTRY_SERVICE_SETS_ELEMENT = "serviceSets";
-
- /** Extension point name inside the extension description **/
- public final static String SERVICE_ELEMENT_NAME = "service";
-
- /** servicesSet name **/
- public final static String SERVICE_SET_ELEMENT_NAME = "servicesSet";
-
- /** ServiceFactory Extension point **/
- public final static String SERVICE_FACTORY_ELEMENT_NAME = "serviceFactory";
-
- /** ServiceFactory Extension point **/
- public final static String ALIAS_ELEMENT_NAME = "alias";
-
- /** ServiceFactory Extension point **/
- public final static String ALIASED_SERVICE_ID_ATTRIBUTE = "aliasedServiceId";
-
- /** id attribute */
- private static final String ID_ATTRIBUTE = "id";
-
- /** constant for the attribute factoryClass **/
- public final static String CONTEXTCLASS_ATTRIBUTE = "contextClass";
-
- /** extension point propertyname */
- private final static String STARTKIND_PROPERTY = "startKind";
-
- /** name of the dependsOn element */
- private static final String DEPENDSON_ELEMENT_NAME = "dependsOn";
-
- /** */
- private static final String SERVICE_ID_ATTRIBUTE_NAME = "serviceId";
-
- /** */
- private static final String SERVICE_SET_EXTENDS_ELEMENT = "extendedServiceSet";
-
- /** */
- private static final String DESCRIPTION_ATTRIBUTE = "description";
-
- /** */
- private static final String IS_UNIQUE_ATTRIBUTE = "isUnique";
-
- /** */
- private static final String REGISTRY_ID_ATTRIBUTE = "registryId";
-
- /** */
- private static final String SERVICE_SET_ID_ATTRIBUTE = "serviceSetId";
-
- /**
- * Get the descriptor for the specified registry.
- * Return null if not found.
- * @see org.eclipse.papyrus.infra.core.serviceregistry.IServiceDescriptorsWithIdProvider#getRegistryDescriptor(java.lang.String)
- *
- * @param registryName
- * @return The specified descriptor, or null if not found
- * @throws DeclarationException If there is more than one registry declared under the name.
- *
- */
- public RegistryIdDesc getRegistryDescriptor(String registryName) throws DeclarationException {
-
- // Reading data from plugins
- IConfigurationElement[] configElements = getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
-
- RegistryIdDesc registryIdDesc = null;
- boolean isRegistryFound = false;
- List<Throwable> warnings = new ArrayList<Throwable>();
-
- for( IConfigurationElement ele : configElements) {
-
- // SEarch for "registry"
- if(REGISTRY_ELEMENT_NAME.equals(ele.getName()) && registryName.equals(ele.getAttribute(ID_ATTRIBUTE))) {
- if(isRegistryFound) {
- // Already found: exception
- throw new DeclarationException("More than one registry declared under name '" + registryName + "'. "
- + " Declaration from '" + ele.getContributor().getName() + "' is disguarded.");
- }
- isRegistryFound = true;
- // read the set
- registryIdDesc = parseRegistryDescriptor( ele, warnings);
- }
-
- }
-
- if( warnings.size()>0) {
- throw new DeclarationMultiException("Problems encountered during extensions processing.", warnings);
- }
- return registryIdDesc;
- }
-
- /**
- * Parse the RegistryDescriptor from the provided {@link IConfigurationElement}.
- *
- * @param ele The {@link IConfigurationElement} representing a RegistryDescriptor.
- * @param warnings A list used to record encountered warnings.
- * @return A registry descriptor.
- */
- private RegistryIdDesc parseRegistryDescriptor(IConfigurationElement ele, List<Throwable> warnings) {
- RegistryIdDesc registryIdDesc = ServicedescriptorswithidFactory.eINSTANCE.createRegistryIdDesc();
-
- registryIdDesc.setName(ele.getAttribute(ID_ATTRIBUTE));
- registryIdDesc.setDescription(ele.getAttribute(DESCRIPTION_ATTRIBUTE));
- registryIdDesc.setIsUnique(Boolean.parseBoolean(ele.getAttribute(IS_UNIQUE_ATTRIBUTE)));
- parseRegistryExtends(ele, registryIdDesc, warnings);
- parseRegistryParent(ele, registryIdDesc, warnings);
- parseRegistryServiceSetId(ele, registryIdDesc, warnings);
-
- return registryIdDesc;
- }
-
- /**
- * Parse the declared sets of a Registry.
- *
- * @param ele
- * @param registryIdDesc
- * @param warnings
- */
- private void parseRegistryServiceSetId(IConfigurationElement parentElement, RegistryIdDesc registryIdDesc, List<Throwable> warnings) {
- // Get all extends declarations
- IConfigurationElement[] extendDeclarations = parentElement.getChildren(REGISTRY_SERVICE_SETS_ELEMENT);
-
- // Process extends
- for(IConfigurationElement ele : extendDeclarations) {
-
- String extendedRegistry = ele.getAttribute(SERVICE_SET_ID_ATTRIBUTE);
- if(extendedRegistry == null || extendedRegistry.length() == 0) {
- warnings.add( new BadDeclarationException( ele.getName() + "/" + SERVICE_SET_ID_ATTRIBUTE + " should be set.") );
- }
- else {
- registryIdDesc.getSets().add(extendedRegistry);
- }
- }
- }
-
- /**
- * Parse the parent declaration of a Registry.
- * @param ele
- * @param registryIdDesc
- * @param warnings
- */
- private void parseRegistryParent(IConfigurationElement parentElement, RegistryIdDesc registryIdDesc, List<Throwable> warnings) {
- // Get all extends declarations
- IConfigurationElement[] extendDeclarations = parentElement.getChildren(REGISTRY_PARENT_ELEMENT);
-
- // Process extends
- for(IConfigurationElement ele : extendDeclarations) {
-
- String extendedRegistry = ele.getAttribute(REGISTRY_ID_ATTRIBUTE);
- if(extendedRegistry == null || extendedRegistry.length() == 0) {
- warnings.add( new BadDeclarationException( ele.getName() + "/" + REGISTRY_ID_ATTRIBUTE + " should be set.") );
- }
- else {
- registryIdDesc.getParents().add(extendedRegistry);
- }
- }
- }
-
- /**
- * Parse the extends declaration of a Registry.
- * @param parentElement The element to parse. This element must represent a Registry.
- * @param registryIdDesc The registry into which the result is stored
- * @param warnings A list used to record encountered warnings.
- */
- private void parseRegistryExtends(IConfigurationElement parentElement, RegistryIdDesc registryIdDesc, List<Throwable> warnings) {
- // Get all extends declarations
- IConfigurationElement[] extendDeclarations = parentElement.getChildren(REGISTRY_EXTENDS_ELEMENT);
-
- // Process extends
- for(IConfigurationElement ele : extendDeclarations) {
-
- String extendedRegistry = ele.getAttribute(REGISTRY_ID_ATTRIBUTE);
- if(extendedRegistry == null || extendedRegistry.length() == 0) {
- warnings.add( new BadDeclarationException( ele.getName() + "/" + REGISTRY_ID_ATTRIBUTE + " should be set.") );
- }
- else {
- registryIdDesc.getExtends().add(extendedRegistry);
- }
- }
- }
-
- /**
- * Get all fragments contributing to the declaration of the specified ServiceSetIdDesc.
- *
- * @see org.eclipse.papyrus.infra.core.serviceregistry.IServiceDescriptorsWithIdProvider#getServiceSetFragments(java.lang.String)
- *
- * @param serviceSetName
- * @return
- * @throws DeclarationMultiException
- */
- public List<ServiceSetIdDesc> getServiceSetFragments(String serviceSetName) throws DeclarationException {
- // Reading data from plugins
- IConfigurationElement[] configElements = getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
-
- List<ServiceSetIdDesc> fragments = new ArrayList<ServiceSetIdDesc>();
- List<Throwable> warnings = new ArrayList<Throwable>();
-
- for( IConfigurationElement ele : configElements) {
-
- // SEarch for "registry"
- if(SERVICE_SET_ELEMENT_NAME.equals(ele.getName()) && serviceSetName.equals(ele.getAttribute(ID_ATTRIBUTE))) {
- ServiceSetIdDesc serviceSet = parseServiceSetDescriptor( ele, warnings);
- fragments.add(serviceSet);
- }
-
- }
-
- if( warnings.size()>0) {
- throw new DeclarationMultiException("Problems encountered during extensions processing.", warnings);
- }
- return fragments;
- }
-
- /**
- * Get the requested ServiceSetIdDesc. If several fragmants are used to declare the ServiceSetIdDesc,
- * this fragments are concatenated in one ServiceSetIdDesc.
- *
- * @see org.eclipse.papyrus.infra.core.serviceregistry.IServiceDescriptorsWithIdProvider#getServiceSetFragments(java.lang.String)
- *
- * @param serviceSetName
- * @return
- * @throws DeclarationMultiException
- */
- public ServiceSetIdDesc getServiceSet(String serviceSetName) throws DeclarationException {
- // Reading data from plugins
- IConfigurationElement[] configElements = getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
-
- ServiceSetIdDesc serviceSet = ServicedescriptorswithidFactory.eINSTANCE.createServiceSetIdDesc();
- List<Throwable> warnings = new ArrayList<Throwable>();
-
- for( IConfigurationElement ele : configElements) {
-
- // SEarch for "registry"
- if(SERVICE_SET_ELEMENT_NAME.equals(ele.getName()) && serviceSetName.equals(ele.getAttribute(ID_ATTRIBUTE))) {
- parseServiceSetDescriptor( ele, serviceSet, warnings);
- }
-
- }
-
- if( warnings.size()>0) {
- throw new DeclarationMultiException("Problems encountered during extensions processing.", warnings);
- }
- return serviceSet;
- }
-
-
- /**
- * Add the ServiceSetIdDesc declarations found in the provided {@link IConfigurationElement}, and add
- * it to the provided {@link ServiceSetIdDesc}.
- * @param ele
- * @param warnings
- */
- private void parseServiceSetDescriptor(IConfigurationElement ele, ServiceSetIdDesc serviceSet, List<Throwable> warnings) {
-
- serviceSet.setName(ele.getAttribute(ID_ATTRIBUTE));
-// serviceSet.setDescription(ele.getAttribute(DESCRIPTION_ATTRIBUTE));
- parseServiceSetExtends(ele, serviceSet, warnings);
- parseServiceSetServices(ele, serviceSet.getServiceDescriptors(), warnings);
- }
-
- /**
- * Parse a {@link ServiceSetIdDesc}
- * @param ele
- * @param warnings
- * @return A newly created ServiceSetIdDesc initialized with the declaration found in ele.
- */
- private ServiceSetIdDesc parseServiceSetDescriptor(IConfigurationElement ele, List<Throwable> warnings) {
-
- ServiceSetIdDesc serviceSet = ServicedescriptorswithidFactory.eINSTANCE.createServiceSetIdDesc();
-
- parseServiceSetDescriptor(ele, serviceSet, warnings);
- return serviceSet;
- }
-
- /**
- * Parse the extended attribute of a ServiceSetIdDesc declaration.
- * @param parentElement
- * @param serviceSet
- * @param warnings
- */
- private void parseServiceSetExtends(IConfigurationElement parentElement, ServiceSetIdDesc serviceSet, List<Throwable> warnings) {
- // Get all extends declarations
- IConfigurationElement[] extendDeclarations = parentElement.getChildren(SERVICE_SET_EXTENDS_ELEMENT);
-
- // Process extends
- for(IConfigurationElement ele : extendDeclarations) {
-
- String extendedServiceSet = ele.getAttribute(SERVICE_SET_ID_ATTRIBUTE);
- if(extendedServiceSet == null || extendedServiceSet.length() == 0) {
- warnings.add( new BadDeclarationException( ele.getName() + "/" + SERVICE_SET_ID_ATTRIBUTE + " should be set.") );
- }
- else {
- serviceSet.getExtends().add(extendedServiceSet);
- }
- }
- }
-
- /**
- * Read services descriptors from the specified element configuration.
- * The element configuration should contains service elements declarations.
- * IdDescriptors are added to the specified list
- *
- * @param descriptors The list into which descriptors are added
- * @param parentElement The configuration element containing some service declarations.
- * @param serviceSet
- * @param exceptions List used to add encountered exceptions.
- */
- private void parseServiceSetServices( IConfigurationElement parentElement, List<AbstractServiceIdDesc> descriptors, List<Throwable> exceptions) {
-
- // Get all children
- IConfigurationElement[] configElements = parentElement.getChildren();
-
- // Process services
- for(IConfigurationElement ele : configElements) {
- AbstractServiceIdDesc desc;
- if(SERVICE_ELEMENT_NAME.equals(ele.getName())) {
- // Read a Service
- try {
- desc = parseServiceDescriptor(ele);
- // Add created desc
- descriptors.add(desc);
- } catch (DeclarationException e) {
- // record exceptions
- exceptions.add(e);
- }
- } else if(SERVICE_FACTORY_ELEMENT_NAME.equals(ele.getName())) {
- // Read a Service Factory
- try {
- desc = parseServiceDescriptor(ele);
- // Add created desc
- descriptors.add(desc);
- } catch (DeclarationException e) {
- // record exceptions
- exceptions.add(e);
- }
- } else if(ALIAS_ELEMENT_NAME.equals(ele.getName())) {
- try {
- desc = parseAliasDescriptor(ele);
- // Add created desc
- descriptors.add(desc);
- } catch (DeclarationException e) {
- // record exceptions
- exceptions.add(e);
- }
-
- }
-
- }
-
- }
-
- /**
- * Read an alias descriptor.
- * @param ele
- * @return
- */
- private AliasIdDesc parseAliasDescriptor(IConfigurationElement ele) throws DeclarationException {
-
- AliasIdDesc aliasIdDesc = ServicedescriptorswithidFactory.eINSTANCE.createAliasIdDesc();
-
- // key
- String key = ele.getAttribute(ID_ATTRIBUTE);
- if(key == null || key.length() == 0) {
- throw new BadDeclarationException( ele.getName() + "/" + ID_ATTRIBUTE + " should be set for an alias.");
- }
- aliasIdDesc.setName(key);
-
- // key
- String aliasedService = ele.getAttribute(ALIASED_SERVICE_ID_ATTRIBUTE);
- if(key == null || key.length() == 0) {
- throw new BadDeclarationException( ele.getName() + "/" + ALIASED_SERVICE_ID_ATTRIBUTE + " should be set for an alias.");
- }
- aliasIdDesc.setAliasedService(aliasedService);
-
- aliasIdDesc.setPriority(parsePriorityAttribute(ele));
-
- aliasIdDesc.setBundleID(ele.getContributor().getName());
- aliasIdDesc.setDescription(ele.getAttribute(DESCRIPTION_ATTRIBUTE));
- parseServiceDependsOn( ele, aliasIdDesc.getDependsOn());
-
-
- return aliasIdDesc;
- }
-
- /**
- * Read descriptor values from provided element.
- *
- * @param ele
- * @return
- * @throws ServiceException
- */
- private ServiceIdDesc parseServiceDescriptor(IConfigurationElement ele) throws DeclarationException {
-
- ServiceIdDesc serviceIdDesc = ServicedescriptorswithidFactory.eINSTANCE.createServiceIdDesc();
-
- // classname
- String serviceClassname = ele.getAttribute("classname");
- serviceIdDesc.setClassname(serviceClassname);
-
- // key
- String key = ele.getAttribute(ID_ATTRIBUTE);
- if(key == null || key.length() == 0) {
- key = serviceClassname;
- }
- serviceIdDesc.setName(key);
-
- serviceIdDesc.setStartKind(parseStartKindAttribute(ele));
- serviceIdDesc.setPriority(parsePriorityAttribute(ele));
- serviceIdDesc.setBundleID(ele.getContributor().getName());
- parseServiceDependsOn( ele, serviceIdDesc.getDependsOn());
-
- return serviceIdDesc;
- }
-
- /**
- * Parse the StartupKind attribute.
- * @param ele
- * @return
- * @throws DeclarationException
- */
- private StartupKind parseStartKindAttribute(IConfigurationElement ele) throws DeclarationException {
- // Service start kind
- StartupKind serviceStartKind = StartupKind.LAZY;
- String serviceStartKindStr = ele.getAttribute(STARTKIND_PROPERTY);
- if(serviceStartKindStr != null && serviceStartKindStr.length() > 0) {
- try {
- serviceStartKind = StartupKind.valueOf(serviceStartKindStr.toUpperCase());
- } catch (IllegalArgumentException e) {
- // Can't convert property
- throw new DeclarationException("Can't convert property " + STARTKIND_PROPERTY + "(plugin=" + ele.getContributor() + "declaringExtension=" + ele.getDeclaringExtension() + ")", e);
- }
- }
- return serviceStartKind;
- }
-
- /**
- * @param ele
- * @return
- */
- private int parsePriorityAttribute(IConfigurationElement ele) {
- // priority
- int priority = 1;
- String priorityStr = ele.getAttribute("priority");
- if(priorityStr != null && priorityStr.length() > 0) {
- try {
- priority = Integer.parseInt(priorityStr);
- } catch (NumberFormatException e) {
- }
- }
- return priority;
- }
-
- /**
- * Parse the dependsOn attribute of a service.
- * @param parentElement The {@link IConfigurationElement} containing a dependsOn attribute.
- * @param dependsOnServices Parsed value are added in this list.
- */
- private void parseServiceDependsOn(IConfigurationElement parentElement, List<String> dependsOnServices) {
- // Get children
- IConfigurationElement[] configElements = parentElement.getChildren(DEPENDSON_ELEMENT_NAME);
-
- for(IConfigurationElement ele : configElements) {
- String key = ele.getAttribute(SERVICE_ID_ATTRIBUTE_NAME);
- if(key != null && key.length() > 0) {
- dependsOnServices.add(key.trim());
- }
- }
- }
-
- /**
- * Get the Eclipse extensionRegistry.
- * This method can be overloaded by subclasses. This is useful for tests.
- *
- * @return
- */
- protected IExtensionRegistry getExtensionRegistry() {
- return Platform.getExtensionRegistry();
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.infra.core.serviceregistry.internal.BadDeclarationException;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AbstractServiceIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AliasIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.RegistryIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceSetIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServicedescriptorswithidFactory;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.StartupKind;
+
+
+/**
+ * A declared service provider reading declaration from eclipse extensions (plugin.xml).
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ExtensionServiceDescriptorsWithIdProvider implements IServiceDescriptorsWithIdProvider {
+
+ /** Namespace where to look for the extension points. */
+ public static String extensionPointNamespace = "org.eclipse.papyrus.infra.core.serviceregistry";
+
+ /** ID of the extension (schema filename) */
+ public static final String SERVICE_EXTENSION_ID = "service";
+
+ /** Extension point name inside the extension description **/
+ public final static String REGISTRY_ELEMENT_NAME = "registry";
+
+ /** Extension point name inside the extension description **/
+ public final static String REGISTRY_EXTENDS_ELEMENT = "extendedRegistry";
+
+ /** Extension point name inside the extension description **/
+ public final static String REGISTRY_PARENT_ELEMENT = "parentRegistry";
+
+ /** Extension point name inside the extension description **/
+ public final static String REGISTRY_SERVICE_SETS_ELEMENT = "serviceSets";
+
+ /** Extension point name inside the extension description **/
+ public final static String SERVICE_ELEMENT_NAME = "service";
+
+ /** servicesSet name **/
+ public final static String SERVICE_SET_ELEMENT_NAME = "servicesSet";
+
+ /** ServiceFactory Extension point **/
+ public final static String SERVICE_FACTORY_ELEMENT_NAME = "serviceFactory";
+
+ /** ServiceFactory Extension point **/
+ public final static String ALIAS_ELEMENT_NAME = "alias";
+
+ /** ServiceFactory Extension point **/
+ public final static String ALIASED_SERVICE_ID_ATTRIBUTE = "aliasedServiceId";
+
+ /** id attribute */
+ private static final String ID_ATTRIBUTE = "id";
+
+ /** constant for the attribute factoryClass **/
+ public final static String CONTEXTCLASS_ATTRIBUTE = "contextClass";
+
+ /** extension point propertyname */
+ private final static String STARTKIND_PROPERTY = "startKind";
+
+ /** name of the dependsOn element */
+ private static final String DEPENDSON_ELEMENT_NAME = "dependsOn";
+
+ /** */
+ private static final String SERVICE_ID_ATTRIBUTE_NAME = "serviceId";
+
+ /** */
+ private static final String SERVICE_SET_EXTENDS_ELEMENT = "extendedServiceSet";
+
+ /** */
+ private static final String DESCRIPTION_ATTRIBUTE = "description";
+
+ /** */
+ private static final String IS_UNIQUE_ATTRIBUTE = "isUnique";
+
+ /** */
+ private static final String REGISTRY_ID_ATTRIBUTE = "registryId";
+
+ /** */
+ private static final String SERVICE_SET_ID_ATTRIBUTE = "serviceSetId";
+
+ /**
+ * Get the descriptor for the specified registry.
+ * Return null if not found.
+ * @see org.eclipse.papyrus.infra.core.serviceregistry.IServiceDescriptorsWithIdProvider#getRegistryDescriptor(java.lang.String)
+ *
+ * @param registryName
+ * @return The specified descriptor, or null if not found
+ * @throws DeclarationException If there is more than one registry declared under the name.
+ *
+ */
+ public RegistryIdDesc getRegistryDescriptor(String registryName) throws DeclarationException {
+
+ // Reading data from plugins
+ IConfigurationElement[] configElements = getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
+
+ RegistryIdDesc registryIdDesc = null;
+ boolean isRegistryFound = false;
+ List<Throwable> warnings = new ArrayList<Throwable>();
+
+ for( IConfigurationElement ele : configElements) {
+
+ // SEarch for "registry"
+ if(REGISTRY_ELEMENT_NAME.equals(ele.getName()) && registryName.equals(ele.getAttribute(ID_ATTRIBUTE))) {
+ if(isRegistryFound) {
+ // Already found: exception
+ throw new DeclarationException("More than one registry declared under name '" + registryName + "'. " //$NON-NLS-1$ //$NON-NLS-2$
+ + " Declaration from '" + ele.getContributor().getName() + "' is disguarded."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ isRegistryFound = true;
+ // read the set
+ registryIdDesc = parseRegistryDescriptor( ele, warnings);
+ }
+
+ }
+
+ if( warnings.size()>0) {
+ throw new DeclarationMultiException("Problems encountered during extensions processing.", warnings); //$NON-NLS-1$
+ }
+ return registryIdDesc;
+ }
+
+ /**
+ * Parse the RegistryDescriptor from the provided {@link IConfigurationElement}.
+ *
+ * @param ele The {@link IConfigurationElement} representing a RegistryDescriptor.
+ * @param warnings A list used to record encountered warnings.
+ * @return A registry descriptor.
+ */
+ private RegistryIdDesc parseRegistryDescriptor(IConfigurationElement ele, List<Throwable> warnings) {
+ RegistryIdDesc registryIdDesc = ServicedescriptorswithidFactory.eINSTANCE.createRegistryIdDesc();
+
+ registryIdDesc.setName(ele.getAttribute(ID_ATTRIBUTE));
+ registryIdDesc.setDescription(ele.getAttribute(DESCRIPTION_ATTRIBUTE));
+ registryIdDesc.setIsUnique(Boolean.parseBoolean(ele.getAttribute(IS_UNIQUE_ATTRIBUTE)));
+ parseRegistryExtends(ele, registryIdDesc, warnings);
+ parseRegistryParent(ele, registryIdDesc, warnings);
+ parseRegistryServiceSetId(ele, registryIdDesc, warnings);
+
+ return registryIdDesc;
+ }
+
+ /**
+ * Parse the declared sets of a Registry.
+ *
+ * @param ele
+ * @param registryIdDesc
+ * @param warnings
+ */
+ private void parseRegistryServiceSetId(IConfigurationElement parentElement, RegistryIdDesc registryIdDesc, List<Throwable> warnings) {
+ // Get all extends declarations
+ IConfigurationElement[] extendDeclarations = parentElement.getChildren(REGISTRY_SERVICE_SETS_ELEMENT);
+
+ // Process extends
+ for(IConfigurationElement ele : extendDeclarations) {
+
+ String extendedRegistry = ele.getAttribute(SERVICE_SET_ID_ATTRIBUTE);
+ if(extendedRegistry == null || extendedRegistry.length() == 0) {
+ warnings.add( new BadDeclarationException( ele.getName() + "/" + SERVICE_SET_ID_ATTRIBUTE + " should be set.") ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else {
+ registryIdDesc.getSets().add(extendedRegistry);
+ }
+ }
+ }
+
+ /**
+ * Parse the parent declaration of a Registry.
+ * @param ele
+ * @param registryIdDesc
+ * @param warnings
+ */
+ private void parseRegistryParent(IConfigurationElement parentElement, RegistryIdDesc registryIdDesc, List<Throwable> warnings) {
+ // Get all extends declarations
+ IConfigurationElement[] extendDeclarations = parentElement.getChildren(REGISTRY_PARENT_ELEMENT);
+
+ // Process extends
+ for(IConfigurationElement ele : extendDeclarations) {
+
+ String extendedRegistry = ele.getAttribute(REGISTRY_ID_ATTRIBUTE);
+ if(extendedRegistry == null || extendedRegistry.length() == 0) {
+ warnings.add( new BadDeclarationException( ele.getName() + "/" + REGISTRY_ID_ATTRIBUTE + " should be set.") ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else {
+ registryIdDesc.getParents().add(extendedRegistry);
+ }
+ }
+ }
+
+ /**
+ * Parse the extends declaration of a Registry.
+ * @param parentElement The element to parse. This element must represent a Registry.
+ * @param registryIdDesc The registry into which the result is stored
+ * @param warnings A list used to record encountered warnings.
+ */
+ private void parseRegistryExtends(IConfigurationElement parentElement, RegistryIdDesc registryIdDesc, List<Throwable> warnings) {
+ // Get all extends declarations
+ IConfigurationElement[] extendDeclarations = parentElement.getChildren(REGISTRY_EXTENDS_ELEMENT);
+
+ // Process extends
+ for(IConfigurationElement ele : extendDeclarations) {
+
+ String extendedRegistry = ele.getAttribute(REGISTRY_ID_ATTRIBUTE);
+ if(extendedRegistry == null || extendedRegistry.length() == 0) {
+ warnings.add( new BadDeclarationException( ele.getName() + "/" + REGISTRY_ID_ATTRIBUTE + " should be set.") ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else {
+ registryIdDesc.getExtends().add(extendedRegistry);
+ }
+ }
+ }
+
+ /**
+ * Get all fragments contributing to the declaration of the specified ServiceSetIdDesc.
+ *
+ * @see org.eclipse.papyrus.infra.core.serviceregistry.IServiceDescriptorsWithIdProvider#getServiceSetFragments(java.lang.String)
+ *
+ * @param serviceSetName
+ * @return
+ * @throws DeclarationMultiException
+ */
+ public List<ServiceSetIdDesc> getServiceSetFragments(String serviceSetName) throws DeclarationException {
+ // Reading data from plugins
+ IConfigurationElement[] configElements = getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
+
+ List<ServiceSetIdDesc> fragments = new ArrayList<ServiceSetIdDesc>();
+ List<Throwable> warnings = new ArrayList<Throwable>();
+
+ for( IConfigurationElement ele : configElements) {
+
+ // SEarch for "registry"
+ if(SERVICE_SET_ELEMENT_NAME.equals(ele.getName()) && serviceSetName.equals(ele.getAttribute(ID_ATTRIBUTE))) {
+ ServiceSetIdDesc serviceSet = parseServiceSetDescriptor( ele, warnings);
+ fragments.add(serviceSet);
+ }
+
+ }
+
+ if( warnings.size()>0) {
+ throw new DeclarationMultiException("Problems encountered during extensions processing.", warnings); //$NON-NLS-1$
+ }
+ return fragments;
+ }
+
+ /**
+ * Get the requested ServiceSetIdDesc. If several fragmants are used to declare the ServiceSetIdDesc,
+ * this fragments are concatenated in one ServiceSetIdDesc.
+ *
+ * @see org.eclipse.papyrus.infra.core.serviceregistry.IServiceDescriptorsWithIdProvider#getServiceSetFragments(java.lang.String)
+ *
+ * @param serviceSetName
+ * @return
+ * @throws DeclarationMultiException
+ */
+ public ServiceSetIdDesc getServiceSet(String serviceSetName) throws DeclarationException {
+ // Reading data from plugins
+ IConfigurationElement[] configElements = getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
+
+ ServiceSetIdDesc serviceSet = ServicedescriptorswithidFactory.eINSTANCE.createServiceSetIdDesc();
+ List<Throwable> warnings = new ArrayList<Throwable>();
+
+ for( IConfigurationElement ele : configElements) {
+
+ // SEarch for "registry"
+ if(SERVICE_SET_ELEMENT_NAME.equals(ele.getName()) && serviceSetName.equals(ele.getAttribute(ID_ATTRIBUTE))) {
+ parseServiceSetDescriptor( ele, serviceSet, warnings);
+ }
+
+ }
+
+ if( warnings.size()>0) {
+ throw new DeclarationMultiException("Problems encountered during extensions processing.", warnings); //$NON-NLS-1$
+ }
+ return serviceSet;
+ }
+
+
+ /**
+ * Add the ServiceSetIdDesc declarations found in the provided {@link IConfigurationElement}, and add
+ * it to the provided {@link ServiceSetIdDesc}.
+ * @param ele
+ * @param warnings
+ */
+ private void parseServiceSetDescriptor(IConfigurationElement ele, ServiceSetIdDesc serviceSet, List<Throwable> warnings) {
+
+ serviceSet.setName(ele.getAttribute(ID_ATTRIBUTE));
+// serviceSet.setDescription(ele.getAttribute(DESCRIPTION_ATTRIBUTE));
+ parseServiceSetExtends(ele, serviceSet, warnings);
+ parseServiceSetServices(ele, serviceSet.getServiceDescriptors(), warnings);
+ }
+
+ /**
+ * Parse a {@link ServiceSetIdDesc}
+ * @param ele
+ * @param warnings
+ * @return A newly created ServiceSetIdDesc initialized with the declaration found in ele.
+ */
+ private ServiceSetIdDesc parseServiceSetDescriptor(IConfigurationElement ele, List<Throwable> warnings) {
+
+ ServiceSetIdDesc serviceSet = ServicedescriptorswithidFactory.eINSTANCE.createServiceSetIdDesc();
+
+ parseServiceSetDescriptor(ele, serviceSet, warnings);
+ return serviceSet;
+ }
+
+ /**
+ * Parse the extended attribute of a ServiceSetIdDesc declaration.
+ * @param parentElement
+ * @param serviceSet
+ * @param warnings
+ */
+ private void parseServiceSetExtends(IConfigurationElement parentElement, ServiceSetIdDesc serviceSet, List<Throwable> warnings) {
+ // Get all extends declarations
+ IConfigurationElement[] extendDeclarations = parentElement.getChildren(SERVICE_SET_EXTENDS_ELEMENT);
+
+ // Process extends
+ for(IConfigurationElement ele : extendDeclarations) {
+
+ String extendedServiceSet = ele.getAttribute(SERVICE_SET_ID_ATTRIBUTE);
+ if(extendedServiceSet == null || extendedServiceSet.length() == 0) {
+ warnings.add( new BadDeclarationException( ele.getName() + "/" + SERVICE_SET_ID_ATTRIBUTE + " should be set.") ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else {
+ serviceSet.getExtends().add(extendedServiceSet);
+ }
+ }
+ }
+
+ /**
+ * Read services descriptors from the specified element configuration.
+ * The element configuration should contains service elements declarations.
+ * IdDescriptors are added to the specified list
+ *
+ * @param descriptors The list into which descriptors are added
+ * @param parentElement The configuration element containing some service declarations.
+ * @param serviceSet
+ * @param exceptions List used to add encountered exceptions.
+ */
+ private void parseServiceSetServices( IConfigurationElement parentElement, List<AbstractServiceIdDesc> descriptors, List<Throwable> exceptions) {
+
+ // Get all children
+ IConfigurationElement[] configElements = parentElement.getChildren();
+
+ // Process services
+ for(IConfigurationElement ele : configElements) {
+ AbstractServiceIdDesc desc;
+ if(SERVICE_ELEMENT_NAME.equals(ele.getName())) {
+ // Read a Service
+ try {
+ desc = parseServiceDescriptor(ele);
+ // Add created desc
+ descriptors.add(desc);
+ } catch (DeclarationException e) {
+ // record exceptions
+ exceptions.add(e);
+ }
+ } else if(SERVICE_FACTORY_ELEMENT_NAME.equals(ele.getName())) {
+ // Read a Service Factory
+ try {
+ desc = parseServiceDescriptor(ele);
+ // Add created desc
+ descriptors.add(desc);
+ } catch (DeclarationException e) {
+ // record exceptions
+ exceptions.add(e);
+ }
+ } else if(ALIAS_ELEMENT_NAME.equals(ele.getName())) {
+ try {
+ desc = parseAliasDescriptor(ele);
+ // Add created desc
+ descriptors.add(desc);
+ } catch (DeclarationException e) {
+ // record exceptions
+ exceptions.add(e);
+ }
+
+ }
+
+ }
+
+ }
+
+ /**
+ * Read an alias descriptor.
+ * @param ele
+ * @return
+ */
+ private AliasIdDesc parseAliasDescriptor(IConfigurationElement ele) throws DeclarationException {
+
+ AliasIdDesc aliasIdDesc = ServicedescriptorswithidFactory.eINSTANCE.createAliasIdDesc();
+
+ // key
+ String key = ele.getAttribute(ID_ATTRIBUTE);
+ if(key == null || key.length() == 0) {
+ throw new BadDeclarationException( ele.getName() + "/" + ID_ATTRIBUTE + " should be set for an alias."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ aliasIdDesc.setName(key);
+
+ // key
+ String aliasedService = ele.getAttribute(ALIASED_SERVICE_ID_ATTRIBUTE);
+ if(key == null || key.length() == 0) {
+ throw new BadDeclarationException( ele.getName() + "/" + ALIASED_SERVICE_ID_ATTRIBUTE + " should be set for an alias."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ aliasIdDesc.setAliasedService(aliasedService);
+
+ aliasIdDesc.setPriority(parsePriorityAttribute(ele));
+
+ aliasIdDesc.setBundleID(ele.getContributor().getName());
+ aliasIdDesc.setDescription(ele.getAttribute(DESCRIPTION_ATTRIBUTE));
+ parseServiceDependsOn( ele, aliasIdDesc.getDependsOn());
+
+
+ return aliasIdDesc;
+ }
+
+ /**
+ * Read descriptor values from provided element.
+ *
+ * @param ele
+ * @return
+ * @throws ServiceException
+ */
+ private ServiceIdDesc parseServiceDescriptor(IConfigurationElement ele) throws DeclarationException {
+
+ ServiceIdDesc serviceIdDesc = ServicedescriptorswithidFactory.eINSTANCE.createServiceIdDesc();
+
+ // classname
+ String serviceClassname = ele.getAttribute("classname");
+ serviceIdDesc.setClassname(serviceClassname);
+
+ // key
+ String key = ele.getAttribute(ID_ATTRIBUTE);
+ if(key == null || key.length() == 0) {
+ key = serviceClassname;
+ }
+ serviceIdDesc.setName(key);
+
+ serviceIdDesc.setStartKind(parseStartKindAttribute(ele));
+ serviceIdDesc.setPriority(parsePriorityAttribute(ele));
+ serviceIdDesc.setBundleID(ele.getContributor().getName());
+ parseServiceDependsOn( ele, serviceIdDesc.getDependsOn());
+
+ return serviceIdDesc;
+ }
+
+ /**
+ * Parse the StartupKind attribute.
+ * @param ele
+ * @return
+ * @throws DeclarationException
+ */
+ private StartupKind parseStartKindAttribute(IConfigurationElement ele) throws DeclarationException {
+ // Service start kind
+ StartupKind serviceStartKind = StartupKind.LAZY;
+ String serviceStartKindStr = ele.getAttribute(STARTKIND_PROPERTY);
+ if(serviceStartKindStr != null && serviceStartKindStr.length() > 0) {
+ try {
+ serviceStartKind = StartupKind.valueOf(serviceStartKindStr.toUpperCase());
+ } catch (IllegalArgumentException e) {
+ // Can't convert property
+ throw new DeclarationException("Can't convert property " + STARTKIND_PROPERTY + "(plugin=" + ele.getContributor() + "declaringExtension=" + ele.getDeclaringExtension() + ")", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+ }
+ return serviceStartKind;
+ }
+
+ /**
+ * @param ele
+ * @return
+ */
+ private int parsePriorityAttribute(IConfigurationElement ele) {
+ // priority
+ int priority = 1;
+ String priorityStr = ele.getAttribute("priority");
+ if(priorityStr != null && priorityStr.length() > 0) {
+ try {
+ priority = Integer.parseInt(priorityStr);
+ } catch (NumberFormatException e) {
+ }
+ }
+ return priority;
+ }
+
+ /**
+ * Parse the dependsOn attribute of a service.
+ * @param parentElement The {@link IConfigurationElement} containing a dependsOn attribute.
+ * @param dependsOnServices Parsed value are added in this list.
+ */
+ private void parseServiceDependsOn(IConfigurationElement parentElement, List<String> dependsOnServices) {
+ // Get children
+ IConfigurationElement[] configElements = parentElement.getChildren(DEPENDSON_ELEMENT_NAME);
+
+ for(IConfigurationElement ele : configElements) {
+ String key = ele.getAttribute(SERVICE_ID_ATTRIBUTE_NAME);
+ if(key != null && key.length() > 0) {
+ dependsOnServices.add(key.trim());
+ }
+ }
+ }
+
+ /**
+ * Get the Eclipse extensionRegistry.
+ * This method can be overloaded by subclasses. This is useful for tests.
+ *
+ * @return
+ */
+ protected IExtensionRegistry getExtensionRegistry() {
+ return Platform.getExtensionRegistry();
+ }
+
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServicesRegistry.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServicesRegistry.java
index 791b2f1..905ca5e 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServicesRegistry.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ExtensionServicesRegistry.java
@@ -1,196 +1,206 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.papyrus.infra.core.serviceregistry.ServiceDescriptor.ServiceTypeKind;
-
-/**
- * ServiceRegistry reading and registering services declared in Eclipse
- * Extensions.
- *
- * @author dumoulin
- *
- */
-public class ExtensionServicesRegistry extends ServicesRegistry {
-
- /** ID of the extension (schema filename) */
- public static final String SERVICE_EXTENSION_ID = "service";
-
- /** Namespace where to look for the extension points. */
- protected String extensionPointNamespace;
-
- /** Extension point name inside the extension description **/
- public final static String SERVICE_EXTENSIONPOINT = "service";
-
- /** ServiceFactory Extension point **/
- public final static String SERVICE_FACTORY_ELEMENT_NAME = "serviceFactory";
-
- /** constant for the attribute factoryClass **/
- public final static String CONTEXTCLASS_ATTRIBUTE = "contextClass";
-
- /** extension point propertyname */
- private final static String STARTKIND_PROPERTY = "startKind";
-
- /** name of the dependsOn element */
- private static final String DEPENDSON_ELEMENT_NAME = "dependsOn";
-
- /** name of the key attribute inside the DEPENDSON element */
- private static final String DEPENDSON_KEY_ATTRIBUTE_NAME = "serviceKeyRef";
-
- /**
- * Constructor.
- *
- * @throws Exception
- */
- public ExtensionServicesRegistry(String extensionPointNamespace) throws ServiceException {
- this.extensionPointNamespace = extensionPointNamespace;
- registerDeclaredExtensions();
- }
-
- /**
- * Register the services declared in Eclipse Extension.
- *
- * @throws Exception
- */
- private void registerDeclaredExtensions() throws ServiceException {
-
- List<ServiceDescriptor> descriptors = new ArrayList<ServiceDescriptor>();
- List<ServiceException> exceptions = null;
-
- // Reading data from plugins
- IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
-
- for(IConfigurationElement ele : configElements) {
- ServiceDescriptor desc;
- if(SERVICE_EXTENSIONPOINT.equals(ele.getName())) {
- // Read a Service
- try {
- desc = readServiceDescriptor(ele);
- desc.setServiceTypeKind(ServiceTypeKind.service);
- // Add created desc
- descriptors.add(desc);
- } catch (ServiceException e) {
- // record exceptions
- if(exceptions == null)
- exceptions = new ArrayList<ServiceException>();
- exceptions.add(e);
- }
- } else if(SERVICE_FACTORY_ELEMENT_NAME.equals(ele.getName())) {
- // Read a Service Factory
- try {
- desc = readServiceDescriptor(ele);
- desc.setServiceTypeKind(ServiceTypeKind.serviceFactory);
- // Add created desc
- descriptors.add(desc);
- } catch (ServiceException e) {
- // record exceptions
- if(exceptions == null)
- exceptions = new ArrayList<ServiceException>();
- exceptions.add(e);
- }
- }
- }
-
- // Add found descriptors
- for(ServiceDescriptor desc : descriptors) {
- add(desc);
- }
-
- // Throw exceptions if pb encountered
- if(exceptions != null) {
- if(exceptions.size() == 1)
- throw exceptions.get(0);
- else
- throw new ServiceException("Somme services are not started (first is shown)", exceptions.get(0));
-
- }
-
- }
-
- /**
- * Read descriptor values from provided element.
- *
- * @param ele
- * @return
- * @throws ServiceException
- */
- private ServiceDescriptor readServiceDescriptor(IConfigurationElement ele) throws ServiceException {
-
- // classname
- String serviceClassname = ele.getAttribute("classname");
-
- // key
- String key = ele.getAttribute("id");
- if(key == null || key.length() == 0) {
- key = serviceClassname;
- }
-
- // Service start kind
- ServiceStartKind serviceStartKind = ServiceStartKind.LAZY;
- String serviceStartKindStr = ele.getAttribute(STARTKIND_PROPERTY);
- if(serviceStartKindStr != null && serviceStartKindStr.length() > 0) {
- try {
- serviceStartKind = ServiceStartKind.valueOf(serviceStartKindStr.toUpperCase());
- } catch (IllegalArgumentException e) {
- // Can't convert property
- throw new ServiceException("Can't convert property " + STARTKIND_PROPERTY + "(plugin=" + ele.getContributor() + "declaringExtension=" + ele.getDeclaringExtension() + ")", e);
- }
- }
-
- // priority
- int priority = 1;
- String priorityStr = ele.getAttribute("priority");
- if(priorityStr != null && priorityStr.length() > 0) {
- try {
- priority = Integer.parseInt(priorityStr);
- } catch (NumberFormatException e) {
- }
- }
-
- // Read dependsOn keys
- List<String> keys = getDependsOn(ele);
-
- // Create descriptor
- ServiceDescriptor desc = new ServiceDescriptor(key, serviceClassname, serviceStartKind, priority);
- desc.setClassBundleID(ele.getContributor().getName());
-
- if(keys.size() > 0)
- desc.setRequiredServiceKeys(keys);
-
- return desc;
- }
-
- /**
- * Add dependsOn keys.
- *
- * @param parentElement
- * @param model
- */
- private List<String> getDependsOn(IConfigurationElement parentElement) {
-
- List<String> keys = new ArrayList<String>();
-
- // Get children
- IConfigurationElement[] configElements = parentElement.getChildren(DEPENDSON_ELEMENT_NAME);
-
- for(IConfigurationElement ele : configElements) {
- String key = ele.getAttribute(DEPENDSON_KEY_ATTRIBUTE_NAME);
- if(key != null && key.length() > 0) {
- keys.add(key.trim());
- }
- }
-
- if(keys.size() == 0)
- return Collections.emptyList();
-
- return keys;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.infra.core.serviceregistry.ServiceDescriptor.ServiceTypeKind;
+
+/**
+ * ServiceRegistry reading and registering services declared in Eclipse
+ * Extensions.
+ *
+ * @author dumoulin
+ *
+ */
+public class ExtensionServicesRegistry extends ServicesRegistry {
+
+ /** ID of the extension (schema filename) */
+ public static final String SERVICE_EXTENSION_ID = "service";
+
+ /** Namespace where to look for the extension points. */
+ protected String extensionPointNamespace;
+
+ /** Extension point name inside the extension description **/
+ public final static String SERVICE_EXTENSIONPOINT = "service";
+
+ /** ServiceFactory Extension point **/
+ public final static String SERVICE_FACTORY_ELEMENT_NAME = "serviceFactory";
+
+ /** constant for the attribute factoryClass **/
+ public final static String CONTEXTCLASS_ATTRIBUTE = "contextClass";
+
+ /** extension point propertyname */
+ private final static String STARTKIND_PROPERTY = "startKind";
+
+ /** name of the dependsOn element */
+ private static final String DEPENDSON_ELEMENT_NAME = "dependsOn";
+
+ /** name of the key attribute inside the DEPENDSON element */
+ private static final String DEPENDSON_KEY_ATTRIBUTE_NAME = "serviceKeyRef";
+
+ /**
+ * Constructor.
+ *
+ * @throws Exception
+ */
+ public ExtensionServicesRegistry(String extensionPointNamespace) throws ServiceException {
+ this.extensionPointNamespace = extensionPointNamespace;
+ registerDeclaredExtensions();
+ }
+
+ /**
+ * Register the services declared in Eclipse Extension.
+ *
+ * @throws Exception
+ */
+ private void registerDeclaredExtensions() throws ServiceException {
+
+ List<ServiceDescriptor> descriptors = new ArrayList<ServiceDescriptor>();
+ List<ServiceException> exceptions = null;
+
+ // Reading data from plugins
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointNamespace, SERVICE_EXTENSION_ID);
+
+ for(IConfigurationElement ele : configElements) {
+ ServiceDescriptor desc;
+ if(SERVICE_EXTENSIONPOINT.equals(ele.getName())) {
+ // Read a Service
+ try {
+ desc = readServiceDescriptor(ele);
+ desc.setServiceTypeKind(ServiceTypeKind.service);
+ // Add created desc
+ descriptors.add(desc);
+ } catch (ServiceException e) {
+ // record exceptions
+ if(exceptions == null)
+ exceptions = new ArrayList<ServiceException>();
+ exceptions.add(e);
+ }
+ } else if(SERVICE_FACTORY_ELEMENT_NAME.equals(ele.getName())) {
+ // Read a Service Factory
+ try {
+ desc = readServiceDescriptor(ele);
+ desc.setServiceTypeKind(ServiceTypeKind.serviceFactory);
+ // Add created desc
+ descriptors.add(desc);
+ } catch (ServiceException e) {
+ // record exceptions
+ if(exceptions == null)
+ exceptions = new ArrayList<ServiceException>();
+ exceptions.add(e);
+ }
+ }
+ }
+
+ // Add found descriptors
+ for(ServiceDescriptor desc : descriptors) {
+ add(desc);
+ }
+
+ // Throw exceptions if pb encountered
+ if(exceptions != null) {
+ if(exceptions.size() == 1)
+ throw exceptions.get(0);
+ else
+ throw new ServiceException("Somme services are not started (first is shown)", exceptions.get(0)); //$NON-NLS-1$
+
+ }
+
+ }
+
+ /**
+ * Read descriptor values from provided element.
+ *
+ * @param ele
+ * @return
+ * @throws ServiceException
+ */
+ private ServiceDescriptor readServiceDescriptor(IConfigurationElement ele) throws ServiceException {
+
+ // classname
+ String serviceClassname = ele.getAttribute("classname");
+
+ // key
+ String key = ele.getAttribute("id");
+ if(key == null || key.length() == 0) {
+ key = serviceClassname;
+ }
+
+ // Service start kind
+ ServiceStartKind serviceStartKind = ServiceStartKind.LAZY;
+ String serviceStartKindStr = ele.getAttribute(STARTKIND_PROPERTY);
+ if(serviceStartKindStr != null && serviceStartKindStr.length() > 0) {
+ try {
+ serviceStartKind = ServiceStartKind.valueOf(serviceStartKindStr.toUpperCase());
+ } catch (IllegalArgumentException e) {
+ // Can't convert property
+ throw new ServiceException("Can't convert property " + STARTKIND_PROPERTY + "(plugin=" + ele.getContributor() + "declaringExtension=" + ele.getDeclaringExtension() + ")", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+
+ // priority
+ int priority = 1;
+ String priorityStr = ele.getAttribute("priority");
+ if(priorityStr != null && priorityStr.length() > 0) {
+ try {
+ priority = Integer.parseInt(priorityStr);
+ } catch (NumberFormatException e) {
+ }
+ }
+
+ // Read dependsOn keys
+ List<String> keys = getDependsOn(ele);
+
+ // Create descriptor
+ ServiceDescriptor desc = new ServiceDescriptor(key, serviceClassname, serviceStartKind, priority);
+ desc.setClassBundleID(ele.getContributor().getName());
+
+ if(keys.size() > 0)
+ desc.setRequiredServiceKeys(keys);
+
+ return desc;
+ }
+
+ /**
+ * Add dependsOn keys.
+ *
+ * @param parentElement
+ * @param model
+ */
+ private List<String> getDependsOn(IConfigurationElement parentElement) {
+
+ List<String> keys = new ArrayList<String>();
+
+ // Get children
+ IConfigurationElement[] configElements = parentElement.getChildren(DEPENDSON_ELEMENT_NAME);
+
+ for(IConfigurationElement ele : configElements) {
+ String key = ele.getAttribute(DEPENDSON_KEY_ATTRIBUTE_NAME);
+ if(key != null && key.length() > 0) {
+ keys.add(key.trim());
+ }
+ }
+
+ if(keys.size() == 0)
+ return Collections.emptyList();
+
+ return keys;
+ }
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IService.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IService.java
index b9a3735..ac10425 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IService.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IService.java
@@ -1,42 +1,52 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-/**
- * An Service that can be registered in the {@link ServicesRegistry}. A service
- * is a singleton available throw the registry. A service can be shared across
- * editors. <br>
- * The life cycle is as follow:
- * <ul>
- * <li>service creation</li>
- * <li>{@link #init(ServicesRegistry)} - Other service can be retrieved from the registry, but are not started yet.</li>
- * <li>{@link #startService()} - service is started.</li>
- * <li>Service can be used</li>
- * <li>{@link #disposeService()} - service is disposed and should not be used anymore.</li>
- * </ul>
- *
- * @author cedric dumoulin
- *
- */
-public interface IService {
-
- /**
- * Init the service and set its associated Registry. The registry can be
- * used to retrieve other services.
- *
- * @param servicesRegistry
- */
- public void init(ServicesRegistry servicesRegistry) throws ServiceException;
-
- /**
- * Start the service. This method is called when the service is started.
- */
- public void startService() throws ServiceException;
-
- /**
- * Dispose the service.
- */
- public void disposeService() throws ServiceException;
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+/**
+ * An Service that can be registered in the {@link ServicesRegistry}. A service
+ * is a singleton available throw the registry. A service can be shared across
+ * editors. <br>
+ * The life cycle is as follow:
+ * <ul>
+ * <li>service creation</li>
+ * <li>{@link #init(ServicesRegistry)} - Other service can be retrieved from the registry, but are not started yet.</li>
+ * <li>{@link #startService()} - service is started.</li>
+ * <li>Service can be used</li>
+ * <li>{@link #disposeService()} - service is disposed and should not be used anymore.</li>
+ * </ul>
+ *
+ * @author cedric dumoulin
+ *
+ */
+public interface IService {
+
+ /**
+ * Init the service and set its associated Registry. The registry can be
+ * used to retrieve other services.
+ *
+ * @param servicesRegistry
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException;
+
+ /**
+ * Start the service. This method is called when the service is started.
+ */
+ public void startService() throws ServiceException;
+
+ /**
+ * Dispose the service.
+ */
+ public void disposeService() throws ServiceException;
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IServiceFactory.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IServiceFactory.java
index 37e5289..a666b85 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IServiceFactory.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/IServiceFactory.java
@@ -1,28 +1,38 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-/**
- * A factory creating a Service that can be registered in the {@link ServicesRegistry}.
- *
- * A service is a singleton available throw the registry. A service can be
- * shared across editors. The service lifecycle events (init, start and dispose)
- * are sent to the factory. The factory is responsible to forward them to the
- * real service.
- *
- * @author dumoulin
- *
- */
-public interface IServiceFactory extends IService {
-
- /**
- * Create the instance of the service that will be returned by {@link ServicesRegistry#getService(Class)}.
- *
- * @return The instance of the service.
- * @throws ServiceException
- * If an error occurs during the operation.
- */
- public Object createServiceInstance() throws ServiceException;
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+/**
+ * A factory creating a Service that can be registered in the {@link ServicesRegistry}.
+ *
+ * A service is a singleton available throw the registry. A service can be
+ * shared across editors. The service lifecycle events (init, start and dispose)
+ * are sent to the factory. The factory is responsible to forward them to the
+ * real service.
+ *
+ * @author dumoulin
+ *
+ */
+public interface IServiceFactory extends IService {
+
+ /**
+ * Create the instance of the service that will be returned by {@link ServicesRegistry#getService(Class)}.
+ *
+ * @return The instance of the service.
+ * @throws ServiceException
+ * If an error occurs during the operation.
+ */
+ public Object createServiceInstance() throws ServiceException;
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptor.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptor.java
index e2b0162..0d5f980 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptor.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptor.java
@@ -1,301 +1,311 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Descriptor of a service. This descriptor describe a service.
- *
- * @author cedirc dumoulin
- *
- */
-public class ServiceDescriptor {
-
- /**
- * Possible kind for service types.
- *
- */
- public enum ServiceTypeKind {
- service, serviceFactory, pojo, alias
- }
-
- /** Classname of the service. USed to start the service */
- private String serviceClassname;
-
- /** Kind of start for this service */
- private ServiceStartKind serviceStartKind;
-
- /** Kind of service */
- private ServiceTypeKind serviceTypeKind = ServiceTypeKind.service;
-
- /**
- * Service priority. If two service are registered under the same key, only
- * the one with the higher priority is started.
- */
- private int priority;
-
- /**
- * Key used to register the service.
- */
- private String key;
-
- /**
- * Id of the bundle owning the .class that is referenced by
- * serviceClassname. Requested when instanciating the class.
- */
- private String classBundleID;
-
- /**
- * If set to true, the service is anonymous : it is not registered and can't
- * be retrieved with getService().
- */
- private boolean isAnonymous = false;
-
- /**
- * List of keys of Services required by this service.
- */
- private List<String> requiredServices = Collections.emptyList();
-
- /**
- * Empty list.
- */
- private static List<String> EMPTY_LIST_STRING = Collections.emptyList();
-
- /**
- * Constructor.
- *
- * @param key
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param requiredServices
- */
- public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
- this.key = key;
- this.serviceClassname = serviceClassname;
- this.serviceStartKind = serviceStartKind;
- this.priority = priority;
- this.requiredServices = requiredServices;
- }
-
- /**
- * Constructor.
- *
- * @param key
- * A class used as key. The classname is used as key.
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param requiredServices
- */
- public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
- this(key.getName(), serviceClassname, serviceStartKind, priority, requiredServices);
- }
-
- /**
- * Constructor.
- *
- * @param key
- * A class used as key. The classname is used as key.
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param isAnonymous
- * @param requiredServices
- */
- public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous, List<String> requiredServices) {
- this.key = key;
- this.serviceClassname = serviceClassname;
- this.serviceStartKind = serviceStartKind;
- this.priority = priority;
- this.isAnonymous = isAnonymous;
- this.requiredServices = requiredServices;
- }
-
- /**
- * Constructor.
- *
- * @param key
- * A class used as key. The classname is used as key.
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param isAnonymous
- * @param requiredServices
- */
- public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous, List<String> requiredServices) {
- this(key.getName(), serviceClassname, serviceStartKind, priority, isAnonymous, requiredServices);
- }
-
- /**
- * Constructor.
- *
- * @param key
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- */
- public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
- this(key, serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
- }
-
- /**
- * Constructor.
- *
- * @param key
- * A class used as key. The classname is used as key.
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- */
- public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
- this(key.getName(), serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
- }
-
- /**
- * Constructor.
- *
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- * @param requiredServices
- */
- public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
- this(serviceClassname, serviceClassname, serviceStartKind, priority, requiredServices);
- }
-
- /**
- * Constructor.
- *
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- */
- public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous) {
- this(serviceClassname, serviceClassname, serviceStartKind, priority, isAnonymous, EMPTY_LIST_STRING);
- }
-
- /**
- * Constructor.
- *
- * @param serviceClassname
- * @param serviceStartKind
- * @param priority
- */
- public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
- this(serviceClassname, serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
- }
-
- /**
- * @return the serviceStartKind
- */
- public ServiceStartKind getServiceStartKind() {
- return serviceStartKind;
- }
-
- /**
- * Return true if StartKind is 'always'.
- *
- * @return
- */
- public boolean isStartAtStartup() {
- return serviceStartKind == ServiceStartKind.STARTUP;
- }
-
- /**
- * @return the priority
- */
- public int getPriority() {
- return priority;
- }
-
- /**
- * @return the key
- */
- public String getKey() {
- return key;
- }
-
- /**
- * @return the serviceClassname
- */
- public String getServiceClassname() {
- return serviceClassname;
- }
-
- /**
- * @return the classBundleID
- */
- public String getClassBundleID() {
- return classBundleID;
- }
-
- /**
- * @param classBundleId
- * the classBundleID to set
- */
- public void setClassBundleID(String classBundleId) {
- classBundleID = classBundleId;
- }
-
- /**
- * Get the keys of all the required services
- *
- * @return the requiredServices
- */
- public List<String> getRequiredServiceKeys() {
- return requiredServices;
- }
-
- /**
- * @param requiredServices
- * the requiredServices to set
- */
- public void setRequiredServiceKeys(List<String> requiredServices) {
- this.requiredServices = requiredServices;
- }
-
- /**
- * @see java.lang.Object#toString()
- * @return
- *
- */
- @Override
- public String toString() {
- return "ServiceDescriptor [key=" + key + ", serviceClassname=" + serviceClassname + ", serviceStartKind=" + serviceStartKind + ", priority=" + priority + "]";
- }
-
- /**
- * @return the isAnonymous
- */
- public boolean isAnonymous() {
- return isAnonymous;
- }
-
- /**
- * @param isAnonymous
- * the isAnonymous to set
- */
- public void setAnonymous(boolean isAnonymous) {
- this.isAnonymous = isAnonymous;
- }
-
- /**
- * @return the serviceTypeKind
- */
- public ServiceTypeKind getServiceTypeKind() {
- return serviceTypeKind;
- }
-
- /**
- * @param serviceTypeKind
- * the serviceTypeKind to set
- */
- public void setServiceTypeKind(ServiceTypeKind serviceTypeKind) {
- this.serviceTypeKind = serviceTypeKind;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Descriptor of a service. This descriptor describe a service.
+ *
+ * @author cedirc dumoulin
+ *
+ */
+public class ServiceDescriptor {
+
+ /**
+ * Possible kind for service types.
+ *
+ */
+ public enum ServiceTypeKind {
+ service, serviceFactory, pojo, alias
+ }
+
+ /** Classname of the service. USed to start the service */
+ private String serviceClassname;
+
+ /** Kind of start for this service */
+ private ServiceStartKind serviceStartKind;
+
+ /** Kind of service */
+ private ServiceTypeKind serviceTypeKind = ServiceTypeKind.service;
+
+ /**
+ * Service priority. If two service are registered under the same key, only
+ * the one with the higher priority is started.
+ */
+ private int priority;
+
+ /**
+ * Key used to register the service.
+ */
+ private String key;
+
+ /**
+ * Id of the bundle owning the .class that is referenced by
+ * serviceClassname. Requested when instanciating the class.
+ */
+ private String classBundleID;
+
+ /**
+ * If set to true, the service is anonymous : it is not registered and can't
+ * be retrieved with getService().
+ */
+ private boolean isAnonymous = false;
+
+ /**
+ * List of keys of Services required by this service.
+ */
+ private List<String> requiredServices = Collections.emptyList();
+
+ /**
+ * Empty list.
+ */
+ private static List<String> EMPTY_LIST_STRING = Collections.emptyList();
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param requiredServices
+ */
+ public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
+ this.key = key;
+ this.serviceClassname = serviceClassname;
+ this.serviceStartKind = serviceStartKind;
+ this.priority = priority;
+ this.requiredServices = requiredServices;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * A class used as key. The classname is used as key.
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param requiredServices
+ */
+ public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
+ this(key.getName(), serviceClassname, serviceStartKind, priority, requiredServices);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * A class used as key. The classname is used as key.
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param isAnonymous
+ * @param requiredServices
+ */
+ public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous, List<String> requiredServices) {
+ this.key = key;
+ this.serviceClassname = serviceClassname;
+ this.serviceStartKind = serviceStartKind;
+ this.priority = priority;
+ this.isAnonymous = isAnonymous;
+ this.requiredServices = requiredServices;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * A class used as key. The classname is used as key.
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param isAnonymous
+ * @param requiredServices
+ */
+ public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous, List<String> requiredServices) {
+ this(key.getName(), serviceClassname, serviceStartKind, priority, isAnonymous, requiredServices);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ */
+ public ServiceDescriptor(String key, String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
+ this(key, serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key
+ * A class used as key. The classname is used as key.
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ */
+ public ServiceDescriptor(Class<?> key, String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
+ this(key.getName(), serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ * @param requiredServices
+ */
+ public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority, List<String> requiredServices) {
+ this(serviceClassname, serviceClassname, serviceStartKind, priority, requiredServices);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ */
+ public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority, boolean isAnonymous) {
+ this(serviceClassname, serviceClassname, serviceStartKind, priority, isAnonymous, EMPTY_LIST_STRING);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param serviceClassname
+ * @param serviceStartKind
+ * @param priority
+ */
+ public ServiceDescriptor(String serviceClassname, ServiceStartKind serviceStartKind, int priority) {
+ this(serviceClassname, serviceClassname, serviceStartKind, priority, EMPTY_LIST_STRING);
+ }
+
+ /**
+ * @return the serviceStartKind
+ */
+ public ServiceStartKind getServiceStartKind() {
+ return serviceStartKind;
+ }
+
+ /**
+ * Return true if StartKind is 'always'.
+ *
+ * @return
+ */
+ public boolean isStartAtStartup() {
+ return serviceStartKind == ServiceStartKind.STARTUP;
+ }
+
+ /**
+ * @return the priority
+ */
+ public int getPriority() {
+ return priority;
+ }
+
+ /**
+ * @return the key
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * @return the serviceClassname
+ */
+ public String getServiceClassname() {
+ return serviceClassname;
+ }
+
+ /**
+ * @return the classBundleID
+ */
+ public String getClassBundleID() {
+ return classBundleID;
+ }
+
+ /**
+ * @param classBundleId
+ * the classBundleID to set
+ */
+ public void setClassBundleID(String classBundleId) {
+ classBundleID = classBundleId;
+ }
+
+ /**
+ * Get the keys of all the required services
+ *
+ * @return the requiredServices
+ */
+ public List<String> getRequiredServiceKeys() {
+ return requiredServices;
+ }
+
+ /**
+ * @param requiredServices
+ * the requiredServices to set
+ */
+ public void setRequiredServiceKeys(List<String> requiredServices) {
+ this.requiredServices = requiredServices;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ * @return
+ *
+ */
+ @Override
+ public String toString() {
+ return "ServiceDescriptor [key=" + key + ", serviceClassname=" + serviceClassname + ", serviceStartKind=" + serviceStartKind + ", priority=" + priority + "]";
+ }
+
+ /**
+ * @return the isAnonymous
+ */
+ public boolean isAnonymous() {
+ return isAnonymous;
+ }
+
+ /**
+ * @param isAnonymous
+ * the isAnonymous to set
+ */
+ public void setAnonymous(boolean isAnonymous) {
+ this.isAnonymous = isAnonymous;
+ }
+
+ /**
+ * @return the serviceTypeKind
+ */
+ public ServiceTypeKind getServiceTypeKind() {
+ return serviceTypeKind;
+ }
+
+ /**
+ * @param serviceTypeKind
+ * the serviceTypeKind to set
+ */
+ public void setServiceTypeKind(ServiceTypeKind serviceTypeKind) {
+ this.serviceTypeKind = serviceTypeKind;
+ }
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorUtils.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorUtils.java
index 6985e06..a5b51e3 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorUtils.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorUtils.java
@@ -1,145 +1,145 @@
-/*****************************************************************************
- * Copyright (c) 2012 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AbstractServiceDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AliasDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServiceDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AbstractServiceIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AliasIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.StartupKind;
-
-
-/**
- * Utilities used as bridge between {@link ServiceDescriptor} and {@link AbstractServiceIdDesc}.
- *
- * @author cedric dumoulin
- *
- */
-public class ServiceDescriptorUtils {
-
- /**
- * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
- * @param idDesc
- * @return
- */
- public static ServiceDescriptor toServiceDescriptor(AbstractServiceIdDesc idDesc) {
-
-
- if( idDesc instanceof ServiceIdDesc ) {
- return toServiceDescriptor((ServiceIdDesc)idDesc);
- }
- else if(idDesc instanceof AliasIdDesc ) {
- return toServiceDescriptor((AliasIdDesc)idDesc);
- }
-
- // Should not happen
- throw new UnsupportedOperationException("Don't know how to transform '" + idDesc.getClass().getName() + "'.");
- }
-
- /**
- * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
- * @param serviceDesc
- * @return
- */
- public static ServiceDescriptor toServiceDescriptor(AbstractServiceDesc serviceDesc) {
- if( serviceDesc instanceof ServiceDesc ) {
- return toServiceDescriptor((ServiceDesc)serviceDesc);
- }
- else if(serviceDesc instanceof AliasDesc ) {
- return toServiceDescriptor((AliasDesc)serviceDesc);
- }
-
- // Should not happen
- throw new UnsupportedOperationException("Don't know how to transform '" + serviceDesc.getClass().getName() + "'.");
- }
-
- /**
- * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
- * @param serviceIdDesc
- * @return
- */
- public static ServiceDescriptor toServiceDescriptor(ServiceIdDesc serviceIdDesc) {
-
- ServiceStartKind serviceStartKind = transformToServiceStartKind(serviceIdDesc.getStartKind());
- return new ServiceDescriptor(serviceIdDesc.getName(), serviceIdDesc.getClassname(), serviceStartKind, serviceIdDesc.getPriority(), serviceIdDesc.getDependsOn());
- }
-
- /**
- *
- * @param startKind
- * @return
- */
- private static ServiceStartKind transformToServiceStartKind(StartupKind startKind) {
- switch( startKind) {
- case STARTUP:
- return ServiceStartKind.STARTUP;
- case LAZY:
- return ServiceStartKind.LAZY;
- default:
- return ServiceStartKind.STARTUP;
- }
- }
-
- /**
- * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
- * @param serviceDesc
- * @return
- */
- public static ServiceDescriptor toServiceDescriptor(AliasIdDesc serviceDesc) {
-
- return new AliasDescriptor(serviceDesc.getName(), serviceDesc.getAliasedService(), serviceDesc.getPriority());
- }
-
- /**
- * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
- * @param serviceIdDesc
- * @return
- */
- public static ServiceDescriptor toServiceDescriptor(ServiceDesc serviceIdDesc) {
-
- ServiceStartKind serviceStartKind = transformToServiceStartKind(serviceIdDesc.getStartKind());
- return new ServiceDescriptor(serviceIdDesc.getName(), serviceIdDesc.getClassname(), serviceStartKind, serviceIdDesc.getPriority(), serviceIdDesc.getDependsOnIds());
- }
-
- /**
- *
- * @param startKind
- * @return
- */
- private static ServiceStartKind transformToServiceStartKind(org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.StartupKind startKind) {
- switch( startKind) {
- case STARTUP:
- return ServiceStartKind.STARTUP;
- case LAZY:
- return ServiceStartKind.LAZY;
- default:
- return ServiceStartKind.STARTUP;
- }
- }
-
- /**
- * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
- * @param serviceDesc
- * @return
- */
- public static ServiceDescriptor toServiceDescriptor(AliasDesc serviceDesc) {
-
- return new AliasDescriptor(serviceDesc.getName(), serviceDesc.getAliasedServiceId(), serviceDesc.getPriority());
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AbstractServiceDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AliasDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.ServiceDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AbstractServiceIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AliasIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.StartupKind;
+
+
+/**
+ * Utilities used as bridge between {@link ServiceDescriptor} and {@link AbstractServiceIdDesc}.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ServiceDescriptorUtils {
+
+ /**
+ * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
+ * @param idDesc
+ * @return
+ */
+ public static ServiceDescriptor toServiceDescriptor(AbstractServiceIdDesc idDesc) {
+
+
+ if( idDesc instanceof ServiceIdDesc ) {
+ return toServiceDescriptor((ServiceIdDesc)idDesc);
+ }
+ else if(idDesc instanceof AliasIdDesc ) {
+ return toServiceDescriptor((AliasIdDesc)idDesc);
+ }
+
+ // Should not happen
+ throw new UnsupportedOperationException("Don't know how to transform '" + idDesc.getClass().getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
+ * @param serviceDesc
+ * @return
+ */
+ public static ServiceDescriptor toServiceDescriptor(AbstractServiceDesc serviceDesc) {
+ if( serviceDesc instanceof ServiceDesc ) {
+ return toServiceDescriptor((ServiceDesc)serviceDesc);
+ }
+ else if(serviceDesc instanceof AliasDesc ) {
+ return toServiceDescriptor((AliasDesc)serviceDesc);
+ }
+
+ // Should not happen
+ throw new UnsupportedOperationException("Don't know how to transform '" + serviceDesc.getClass().getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
+ * @param serviceIdDesc
+ * @return
+ */
+ public static ServiceDescriptor toServiceDescriptor(ServiceIdDesc serviceIdDesc) {
+
+ ServiceStartKind serviceStartKind = transformToServiceStartKind(serviceIdDesc.getStartKind());
+ return new ServiceDescriptor(serviceIdDesc.getName(), serviceIdDesc.getClassname(), serviceStartKind, serviceIdDesc.getPriority(), serviceIdDesc.getDependsOn());
+ }
+
+ /**
+ *
+ * @param startKind
+ * @return
+ */
+ private static ServiceStartKind transformToServiceStartKind(StartupKind startKind) {
+ switch( startKind) {
+ case STARTUP:
+ return ServiceStartKind.STARTUP;
+ case LAZY:
+ return ServiceStartKind.LAZY;
+ default:
+ return ServiceStartKind.STARTUP;
+ }
+ }
+
+ /**
+ * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
+ * @param serviceDesc
+ * @return
+ */
+ public static ServiceDescriptor toServiceDescriptor(AliasIdDesc serviceDesc) {
+
+ return new AliasDescriptor(serviceDesc.getName(), serviceDesc.getAliasedService(), serviceDesc.getPriority());
+ }
+
+ /**
+ * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
+ * @param serviceIdDesc
+ * @return
+ */
+ public static ServiceDescriptor toServiceDescriptor(ServiceDesc serviceIdDesc) {
+
+ ServiceStartKind serviceStartKind = transformToServiceStartKind(serviceIdDesc.getStartKind());
+ return new ServiceDescriptor(serviceIdDesc.getName(), serviceIdDesc.getClassname(), serviceStartKind, serviceIdDesc.getPriority(), serviceIdDesc.getDependsOnIds());
+ }
+
+ /**
+ *
+ * @param startKind
+ * @return
+ */
+ private static ServiceStartKind transformToServiceStartKind(org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.StartupKind startKind) {
+ switch( startKind) {
+ case STARTUP:
+ return ServiceStartKind.STARTUP;
+ case LAZY:
+ return ServiceStartKind.LAZY;
+ default:
+ return ServiceStartKind.STARTUP;
+ }
+ }
+
+ /**
+ * Create a {@link ServiceDescriptor} from a {@link AbstractServiceIdDesc}.
+ * @param serviceDesc
+ * @return
+ */
+ public static ServiceDescriptor toServiceDescriptor(AliasDesc serviceDesc) {
+
+ return new AliasDescriptor(serviceDesc.getName(), serviceDesc.getAliasedServiceId(), serviceDesc.getPriority());
+ }
+
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorsWithIdProviderCollection.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorsWithIdProviderCollection.java
index dee8bbd..946e53c 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorsWithIdProviderCollection.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceDescriptorsWithIdProviderCollection.java
@@ -1,257 +1,257 @@
-/*****************************************************************************
- * Copyright (c) 2012 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AbstractServiceIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.RegistryIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceSetIdDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServicedescriptorswithidFactory;
-
-
-/**
- * A collection of DescriptorsProviders.
- * This provide nearly the same method as DescriptorsProviders, but the search is done over
- * a collection of DescriptorsProviders.
- *
- * @author cedric dumoulin
- *
- * TODO : complete
- */
-public class ServiceDescriptorsWithIdProviderCollection /*implements IServiceDescriptorsWithIdProvider*/ {
-
- protected List<IServiceDescriptorsWithIdProvider> descriptorsProviders;
-
-
-
- /**
- *
- * Constructor.
- *
- */
- public ServiceDescriptorsWithIdProviderCollection() {
- descriptorsProviders = new ArrayList<IServiceDescriptorsWithIdProvider>();
- }
-
- /**
- * Add all the provided {@link IServiceDescriptorsWithIdProvider} to the list of providers to use.
- * @param declaredDescriptorProviders
- */
- public void addAll(IServiceDescriptorsWithIdProvider ... declaredDescriptorProviders) {
-
- for( IServiceDescriptorsWithIdProvider provider : declaredDescriptorProviders) {
- descriptorsProviders.add(provider);
- }
-
- }
-
- /**
- * Get the descriptor for the specified registry.
- * If the registry is found more than one, throw an exception.
- * If the registry is not found, throws an exception.
- *
- * @param registryName The name of the registry for which the descriptor is required.
- *
- * @return The registry descriptor
- * @throws DeclarationException If an error occur while reading declarations.
- *
- */
- public RegistryIdDesc getRegistryIdDesc(String registryName) throws DeclarationException {
-
- RegistryIdDesc found = null;
- for( IServiceDescriptorsWithIdProvider provider : descriptorsProviders) {
-
- RegistryIdDesc res = provider.getRegistryDescriptor(registryName);
- if( found != null && res != null) {
- throw new DeclarationException("Registry '" + registryName + "' is declared more than once in declarations.");
- }
- found = res;
- }
-
- if( found == null ) {
- throw new DeclarationNotFoundException("Can't find registry named '" + registryName + "'.");
- }
-
- return found;
- }
-
- /**
- * Get the descriptor for the specified registry, with all inheritance resolved. This mean that
- * the returned descriptor has no inheritance, but the found inheritance are added in the inner properties
- * (sets, parents).
- *
- * @param registryName
- * @return
- * @throws DeclarationException
- */
- public RegistryIdDesc getResolvedRegistryIdDesc(String registryName) throws DeclarationException {
-
- // Get the original registry desc
- RegistryIdDesc registryIdDesc = getRegistryIdDesc(registryName);
-
- // Is there some inheritance ?
- if( registryIdDesc.getExtends().size() == 0) {
- // Remove doubles
- removeDoubleName( registryIdDesc.getParents() );
- removeDoubleName( registryIdDesc.getSets() );
- return registryIdDesc;
- }
-
- // There is some inheritance
- // Create a new desc, and set single values
- RegistryIdDesc resolvedDesc = ServicedescriptorswithidFactory.eINSTANCE.createRegistryIdDesc();
- resolvedDesc.setName(registryName);
- resolvedDesc.setDescription(registryIdDesc.getDescription());
- resolvedDesc.setIsUnique(registryIdDesc.isUnique());
- resolvedDesc.getSets().addAll( registryIdDesc.getSets());
- resolvedDesc.getParents().addAll( registryIdDesc.getParents());
-
- // Remove doubles from the list of directly inherited registry
- removeDoubleName( registryIdDesc.getExtends() );
-
- // Concat sets and parents from inherited descs
- for( String inheritedRegName : registryIdDesc.getExtends()) {
- // Get the inherited desc
- RegistryIdDesc inheritedReg = getResolvedRegistryIdDesc(inheritedRegName);
- // Concat sets and parents
- resolvedDesc.getSets().addAll( inheritedReg.getSets());
- resolvedDesc.getParents().addAll( inheritedReg.getParents());
-
- }
-
- // Remove doubles
- removeDoubleName( registryIdDesc.getParents() );
- removeDoubleName( registryIdDesc.getSets() );
-
- return resolvedDesc;
- }
-
- /**
- * Get the descriptor for the specified ServiceSetIdDesc, with all inheritance resolved. This mean that
- * the returned {@link ServiceSetIdDesc} has no inheritance. All services found from inherited sets are added in the set,
- * according to the following rules:
- * <ul>
- * <li>Names found in children hides names in parent (overloading)</li>
- * <li></li>
- * <li></li>
- * </ul>
- * @param setName
- * @return
- * @throws DeclarationException
- * @throws DeclarationNotFoundException If the set is not found
- */
- public ServiceSetIdDesc getResolvedServiceSetIdDesc(String setName) throws DeclarationException {
-
-
- ServiceSetIdDesc serviceSetIdDesc = getServiceSet(setName);
- // if no parent, return it directly
- if( serviceSetIdDesc.getExtends().size() == 0) {
- return serviceSetIdDesc;
- }
-
- // Create ServiceSetIdDesc
- ServiceSetIdDesc res = ServicedescriptorswithidFactory.eINSTANCE.createServiceSetIdDesc();
-
- res.setName(serviceSetIdDesc.getName());
- res.setDescription(serviceSetIdDesc.getDescription());
- res.getServiceDescriptors().addAll(serviceSetIdDesc.getServiceDescriptors());
-
- // Collect all parent's services
- for( String extendsName : serviceSetIdDesc.getExtends() ) {
- collectMissingServices( res, getResolvedServiceSetIdDesc(extendsName) );
- }
-
- return res;
- }
-
- /**
- * Collect the services that are set in the parent, but not found in the collect.
- * @param res
- * @param resolvedServiceSet
- */
- private void collectMissingServices(ServiceSetIdDesc collect, ServiceSetIdDesc parent) {
-
- for( AbstractServiceIdDesc desc : parent.getServiceDescriptors()) {
- if( ! collect.containsService(desc) ) {
- collect.getServiceDescriptors().add(desc);
- }
- }
-
- }
-
- /**
- * Get the {@link ServiceSetIdDesc} concatenating all fragments declaring a part of the ServiceSetIdDesc.
- *
- *
- * @param setName
- * @return
- * @throws DeclarationNotFoundException
- */
- public ServiceSetIdDesc getServiceSet(String serviceSetName) throws DeclarationException {
- ServiceSetIdDesc result = null;
-
-
- for( IServiceDescriptorsWithIdProvider provider : descriptorsProviders) {
-
- List<ServiceSetIdDesc> fragments = provider.getServiceSetFragments(serviceSetName);
- for( ServiceSetIdDesc fragment : fragments) {
- // Create the result ServiceSetIdDesc if needed
- if( result == null) {
- result = ServicedescriptorswithidFactory.eINSTANCE.createServiceSetIdDesc();
- result.setName(serviceSetName);
- }
- result.getExtends().addAll(fragment.getExtends());
- result.getServiceDescriptors().addAll(fragment.getServiceDescriptors());
-
- }
- }
-
- if( result == null ) {
- throw new DeclarationNotFoundException("Can't find ServiceSetIdDesc named '" + serviceSetName + "'.");
- }
- // Remove doubles
- removeDoubleName(result.getExtends());
-
- return result;
- }
-
- /**
- * Remove double names from the provided list.
- * @param list
- */
- private void removeDoubleName(List<String> list) {
-
- for( int i=0; i<list.size(); i++) {
- String ref = list.get(i);
-
- for( int j = i+1; j<list.size(); ) {
- // If we found the same name, remove the second one, and then check the same index
- // If the string are different, check the next index.
- if( ref.equals( list.get(j))) {
- // Remove it
- list.remove(j);
- }
- else {
- j++;
- }
- } // end j
- } // end i
-
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.AbstractServiceIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.RegistryIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServiceSetIdDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptorswithid.ServicedescriptorswithidFactory;
+
+
+/**
+ * A collection of DescriptorsProviders.
+ * This provide nearly the same method as DescriptorsProviders, but the search is done over
+ * a collection of DescriptorsProviders.
+ *
+ * @author cedric dumoulin
+ *
+ * TODO : complete
+ */
+public class ServiceDescriptorsWithIdProviderCollection /*implements IServiceDescriptorsWithIdProvider*/ {
+
+ protected List<IServiceDescriptorsWithIdProvider> descriptorsProviders;
+
+
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public ServiceDescriptorsWithIdProviderCollection() {
+ descriptorsProviders = new ArrayList<IServiceDescriptorsWithIdProvider>();
+ }
+
+ /**
+ * Add all the provided {@link IServiceDescriptorsWithIdProvider} to the list of providers to use.
+ * @param declaredDescriptorProviders
+ */
+ public void addAll(IServiceDescriptorsWithIdProvider ... declaredDescriptorProviders) {
+
+ for( IServiceDescriptorsWithIdProvider provider : declaredDescriptorProviders) {
+ descriptorsProviders.add(provider);
+ }
+
+ }
+
+ /**
+ * Get the descriptor for the specified registry.
+ * If the registry is found more than one, throw an exception.
+ * If the registry is not found, throws an exception.
+ *
+ * @param registryName The name of the registry for which the descriptor is required.
+ *
+ * @return The registry descriptor
+ * @throws DeclarationException If an error occur while reading declarations.
+ *
+ */
+ public RegistryIdDesc getRegistryIdDesc(String registryName) throws DeclarationException {
+
+ RegistryIdDesc found = null;
+ for( IServiceDescriptorsWithIdProvider provider : descriptorsProviders) {
+
+ RegistryIdDesc res = provider.getRegistryDescriptor(registryName);
+ if( found != null && res != null) {
+ throw new DeclarationException("Registry '" + registryName + "' is declared more than once in declarations."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ found = res;
+ }
+
+ if( found == null ) {
+ throw new DeclarationNotFoundException("Can't find registry named '" + registryName + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return found;
+ }
+
+ /**
+ * Get the descriptor for the specified registry, with all inheritance resolved. This mean that
+ * the returned descriptor has no inheritance, but the found inheritance are added in the inner properties
+ * (sets, parents).
+ *
+ * @param registryName
+ * @return
+ * @throws DeclarationException
+ */
+ public RegistryIdDesc getResolvedRegistryIdDesc(String registryName) throws DeclarationException {
+
+ // Get the original registry desc
+ RegistryIdDesc registryIdDesc = getRegistryIdDesc(registryName);
+
+ // Is there some inheritance ?
+ if( registryIdDesc.getExtends().size() == 0) {
+ // Remove doubles
+ removeDoubleName( registryIdDesc.getParents() );
+ removeDoubleName( registryIdDesc.getSets() );
+ return registryIdDesc;
+ }
+
+ // There is some inheritance
+ // Create a new desc, and set single values
+ RegistryIdDesc resolvedDesc = ServicedescriptorswithidFactory.eINSTANCE.createRegistryIdDesc();
+ resolvedDesc.setName(registryName);
+ resolvedDesc.setDescription(registryIdDesc.getDescription());
+ resolvedDesc.setIsUnique(registryIdDesc.isUnique());
+ resolvedDesc.getSets().addAll( registryIdDesc.getSets());
+ resolvedDesc.getParents().addAll( registryIdDesc.getParents());
+
+ // Remove doubles from the list of directly inherited registry
+ removeDoubleName( registryIdDesc.getExtends() );
+
+ // Concat sets and parents from inherited descs
+ for( String inheritedRegName : registryIdDesc.getExtends()) {
+ // Get the inherited desc
+ RegistryIdDesc inheritedReg = getResolvedRegistryIdDesc(inheritedRegName);
+ // Concat sets and parents
+ resolvedDesc.getSets().addAll( inheritedReg.getSets());
+ resolvedDesc.getParents().addAll( inheritedReg.getParents());
+
+ }
+
+ // Remove doubles
+ removeDoubleName( registryIdDesc.getParents() );
+ removeDoubleName( registryIdDesc.getSets() );
+
+ return resolvedDesc;
+ }
+
+ /**
+ * Get the descriptor for the specified ServiceSetIdDesc, with all inheritance resolved. This mean that
+ * the returned {@link ServiceSetIdDesc} has no inheritance. All services found from inherited sets are added in the set,
+ * according to the following rules:
+ * <ul>
+ * <li>Names found in children hides names in parent (overloading)</li>
+ * <li></li>
+ * <li></li>
+ * </ul>
+ * @param setName
+ * @return
+ * @throws DeclarationException
+ * @throws DeclarationNotFoundException If the set is not found
+ */
+ public ServiceSetIdDesc getResolvedServiceSetIdDesc(String setName) throws DeclarationException {
+
+
+ ServiceSetIdDesc serviceSetIdDesc = getServiceSet(setName);
+ // if no parent, return it directly
+ if( serviceSetIdDesc.getExtends().size() == 0) {
+ return serviceSetIdDesc;
+ }
+
+ // Create ServiceSetIdDesc
+ ServiceSetIdDesc res = ServicedescriptorswithidFactory.eINSTANCE.createServiceSetIdDesc();
+
+ res.setName(serviceSetIdDesc.getName());
+ res.setDescription(serviceSetIdDesc.getDescription());
+ res.getServiceDescriptors().addAll(serviceSetIdDesc.getServiceDescriptors());
+
+ // Collect all parent's services
+ for( String extendsName : serviceSetIdDesc.getExtends() ) {
+ collectMissingServices( res, getResolvedServiceSetIdDesc(extendsName) );
+ }
+
+ return res;
+ }
+
+ /**
+ * Collect the services that are set in the parent, but not found in the collect.
+ * @param res
+ * @param resolvedServiceSet
+ */
+ private void collectMissingServices(ServiceSetIdDesc collect, ServiceSetIdDesc parent) {
+
+ for( AbstractServiceIdDesc desc : parent.getServiceDescriptors()) {
+ if( ! collect.containsService(desc) ) {
+ collect.getServiceDescriptors().add(desc);
+ }
+ }
+
+ }
+
+ /**
+ * Get the {@link ServiceSetIdDesc} concatenating all fragments declaring a part of the ServiceSetIdDesc.
+ *
+ *
+ * @param setName
+ * @return
+ * @throws DeclarationNotFoundException
+ */
+ public ServiceSetIdDesc getServiceSet(String serviceSetName) throws DeclarationException {
+ ServiceSetIdDesc result = null;
+
+
+ for( IServiceDescriptorsWithIdProvider provider : descriptorsProviders) {
+
+ List<ServiceSetIdDesc> fragments = provider.getServiceSetFragments(serviceSetName);
+ for( ServiceSetIdDesc fragment : fragments) {
+ // Create the result ServiceSetIdDesc if needed
+ if( result == null) {
+ result = ServicedescriptorswithidFactory.eINSTANCE.createServiceSetIdDesc();
+ result.setName(serviceSetName);
+ }
+ result.getExtends().addAll(fragment.getExtends());
+ result.getServiceDescriptors().addAll(fragment.getServiceDescriptors());
+
+ }
+ }
+
+ if( result == null ) {
+ throw new DeclarationNotFoundException("Can't find ServiceSetIdDesc named '" + serviceSetName + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ // Remove doubles
+ removeDoubleName(result.getExtends());
+
+ return result;
+ }
+
+ /**
+ * Remove double names from the provided list.
+ * @param list
+ */
+ private void removeDoubleName(List<String> list) {
+
+ for( int i=0; i<list.size(); i++) {
+ String ref = list.get(i);
+
+ for( int j = i+1; j<list.size(); ) {
+ // If we found the same name, remove the second one, and then check the same index
+ // If the string are different, check the next index.
+ if( ref.equals( list.get(j))) {
+ // Remove it
+ list.remove(j);
+ }
+ else {
+ j++;
+ }
+ } // end j
+ } // end i
+
+ }
+
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceException.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceException.java
index 2b82444..8ed9c31 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceException.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceException.java
@@ -1,57 +1,67 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-/**
- * Root Exception of Services Exception.
- *
- * @author dumoulin
- *
- */
-public class ServiceException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor.
- */
- public ServiceException() {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * Constructor.
- *
- * @param message
- */
- public ServiceException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * Constructor.
- *
- * @param cause
- */
- public ServiceException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * Constructor.
- *
- * @param message
- * @param cause
- */
- public ServiceException(String message, Throwable cause) {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+/**
+ * Root Exception of Services Exception.
+ *
+ * @author dumoulin
+ *
+ */
+public class ServiceException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ */
+ public ServiceException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public ServiceException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause
+ */
+ public ServiceException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ */
+ public ServiceException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceMultiException.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceMultiException.java
index faec7d6..4bfaca5 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceMultiException.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceMultiException.java
@@ -1,139 +1,149 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * An exception encapsulating multiple exceptions. This exception is thrown when
- * an operation performed on several Services fails on one or more of these
- * Service. The exception contains all the exceptions encoutered while
- * opertating on Services.
- *
- * @author cedric dumoulin
- *
- */
-public class ServiceMultiException extends ServiceException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * List of encountered exceptions.
- */
- List<Throwable> encounteredExceptions = new ArrayList<Throwable>();
-
- /**
- * List of identifiers corresponding to exceptions.
- */
- List<Object> serviceIdentifiers = new ArrayList<Object>();
-
- /**
- * @return the encounteredExceptions
- */
- public List<Throwable> getExceptions() {
- return encounteredExceptions;
- }
-
- /**
- * Constructor.
- *
- */
- public ServiceMultiException() {
- super("Multiple exceptions");
- }
-
- /**
- * Constructor.
- *
- * @param message
- */
- public ServiceMultiException(String message) {
- super(message);
- }
-
- /**
- * Return the first exception.
- *
- * @see java.lang.Throwable#getCause()
- *
- * @return
- */
- @Override
- public Throwable getCause() {
- return (encounteredExceptions.size() > 0 ? encounteredExceptions.get(0) : null);
- }
-
- /**
- * Return the message if any, or the message of the first exception.
- *
- * @see java.lang.Throwable#getMessage()
- *
- * @return
- */
- @Override
- public String getMessage() {
-
- StringBuffer buffer = new StringBuffer();
-
- String message = super.getMessage();
- if(message != null)
- buffer.append(message).append('\n');
-
- buffer.append("----- exceptions : ----------\n");
- for(int i = 0; i < encounteredExceptions.size(); i++) {
- Throwable exception = encounteredExceptions.get(i);
- Object identifierMsg = serviceIdentifiers.get(i);
-
- if(identifierMsg != null)
- buffer.append(identifierMsg.toString()).append(" : ");
- String msg = exception.getMessage();
- if(msg != null)
- buffer.append(msg).append('\n');
- }
- buffer.append("----------------------------- \n");
-
- return buffer.toString();
- // // Check for first exception
- // if( encounteredExceptions.size() > 1)
- // return encounteredExceptions.get(0).getMessage();
- //
- // // default
- // return null;
- }
-
- /**
- * Add an exception to the list of exceptions.
- *
- * @param exception
- */
- public void addException(Throwable exception) {
- addException("unknown", exception);
- }
-
- /**
- * Add an exception to the list of exceptions. Also record the corresponding
- * model identifier if any.
- *
- * @param exception
- */
- public void addException(Object identifier, Throwable exception) {
- encounteredExceptions.add(exception);
- serviceIdentifiers.add(identifier);
- }
-
- /**
- * Merge both exceptions
- *
- * @param e
- */
- public void addAll(ServiceMultiException e) {
- encounteredExceptions.addAll(e.encounteredExceptions);
- serviceIdentifiers.addAll(serviceIdentifiers);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An exception encapsulating multiple exceptions. This exception is thrown when
+ * an operation performed on several Services fails on one or more of these
+ * Service. The exception contains all the exceptions encoutered while
+ * opertating on Services.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ServiceMultiException extends ServiceException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * List of encountered exceptions.
+ */
+ List<Throwable> encounteredExceptions = new ArrayList<Throwable>();
+
+ /**
+ * List of identifiers corresponding to exceptions.
+ */
+ List<Object> serviceIdentifiers = new ArrayList<Object>();
+
+ /**
+ * @return the encounteredExceptions
+ */
+ public List<Throwable> getExceptions() {
+ return encounteredExceptions;
+ }
+
+ /**
+ * Constructor.
+ *
+ */
+ public ServiceMultiException() {
+ super("Multiple exceptions"); //$NON-NLS-1$
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public ServiceMultiException(String message) {
+ super(message);
+ }
+
+ /**
+ * Return the first exception.
+ *
+ * @see java.lang.Throwable#getCause()
+ *
+ * @return
+ */
+ @Override
+ public Throwable getCause() {
+ return (encounteredExceptions.size() > 0 ? encounteredExceptions.get(0) : null);
+ }
+
+ /**
+ * Return the message if any, or the message of the first exception.
+ *
+ * @see java.lang.Throwable#getMessage()
+ *
+ * @return
+ */
+ @Override
+ public String getMessage() {
+
+ StringBuffer buffer = new StringBuffer();
+
+ String message = super.getMessage();
+ if(message != null)
+ buffer.append(message).append('\n');
+
+ buffer.append("----- exceptions : ----------\n");
+ for(int i = 0; i < encounteredExceptions.size(); i++) {
+ Throwable exception = encounteredExceptions.get(i);
+ Object identifierMsg = serviceIdentifiers.get(i);
+
+ if(identifierMsg != null)
+ buffer.append(identifierMsg.toString()).append(" : ");
+ String msg = exception.getMessage();
+ if(msg != null)
+ buffer.append(msg).append('\n');
+ }
+ buffer.append("----------------------------- \n");
+
+ return buffer.toString();
+ // // Check for first exception
+ // if( encounteredExceptions.size() > 1)
+ // return encounteredExceptions.get(0).getMessage();
+ //
+ // // default
+ // return null;
+ }
+
+ /**
+ * Add an exception to the list of exceptions.
+ *
+ * @param exception
+ */
+ public void addException(Throwable exception) {
+ addException("unknown", exception);
+ }
+
+ /**
+ * Add an exception to the list of exceptions. Also record the corresponding
+ * model identifier if any.
+ *
+ * @param exception
+ */
+ public void addException(Object identifier, Throwable exception) {
+ encounteredExceptions.add(exception);
+ serviceIdentifiers.add(identifier);
+ }
+
+ /**
+ * Merge both exceptions
+ *
+ * @param e
+ */
+ public void addAll(ServiceMultiException e) {
+ encounteredExceptions.addAll(e.encounteredExceptions);
+ serviceIdentifiers.addAll(serviceIdentifiers);
+ }
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceNotFoundException.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceNotFoundException.java
index b3dc075..2e4e890 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceNotFoundException.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceNotFoundException.java
@@ -1,51 +1,64 @@
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-/**
- * Service is not found.
- *
- * @author dumoulin
- *
- */
-public class ServiceNotFoundException extends ServiceException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor.
- */
- public ServiceNotFoundException() {
- super();
- }
-
- /**
- * Constructor.
- *
- * @param message
- * @param cause
- */
- public ServiceNotFoundException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Constructor.
- *
- * @param message
- */
- public ServiceNotFoundException(String message) {
- super(message);
- }
-
- /**
- * Constructor.
- *
- * @param cause
- */
- public ServiceNotFoundException(Throwable cause) {
- super(cause);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+/**
+ * Service is not found.
+ *
+ * @author dumoulin
+ *
+ */
+public class ServiceNotFoundException extends ServiceException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ */
+ public ServiceNotFoundException() {
+ super();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ */
+ public ServiceNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public ServiceNotFoundException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause
+ */
+ public ServiceNotFoundException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceRegistryFactory.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceRegistryFactory.java
index 00c8cd1..574a52b 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceRegistryFactory.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceRegistryFactory.java
@@ -1,226 +1,226 @@
-/*****************************************************************************
- * Copyright (c) 2012 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AbstractServiceDesc;
-import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.RegistryDesc;
-
-
-/**
- * @author cedric dumoulin
- *
- */
-public class ServiceRegistryFactory {
-
- /**
- * Repository of single registries.
- */
- protected Map<String, ServicesRegistry> singleRegistries;
-
- /**
- * DescriptorProviders access point.
- */
- protected DescriptorsCache descriptorProviders;
-
- /**
- * Constructor.
- *
- */
- public ServiceRegistryFactory(DescriptorsCache descriptorProviders) {
- this.descriptorProviders = descriptorProviders;
- }
-
- /**
- * Constructor.
- *
- * @param declaredDescriptorProviders Array of providers to be used by the {@link ServiceDescriptorsWithIdProviderCollection}.
- */
- public ServiceRegistryFactory(IServiceDescriptorsWithIdProvider ... declaredDescriptorProviders ) {
-
- descriptorProviders = new DescriptorsCache();
- descriptorProviders.addAll(declaredDescriptorProviders);
- }
-
- /**
- * Create a {@link ServicesRegistry} from the specified description.
- * The description is searched in the associated {@link ServiceDescriptorsWithIdProviderCollection}.
- *
- * @param registryName The name of the description used to initialized the ServicesRegistry.
- *
- * @return The requested {@link ServicesRegistry}
- * @throws DeclarationException
- */
- public ServicesRegistry getServicesRegistry( String registryName ) throws DeclarationException {
-
- RegistryDesc registryIdDesc = descriptorProviders.getRegistryDesc( registryName);
-
- return getServicesRegistry(registryIdDesc);
- }
-
- /**
- * Get a {@link ServicesRegistry} corresponding to the specified descriptor. Also create recursively referenced
- * registries and services.
- *
- * If the registry is "unique", lookup for an already existing instance, and return it if found.
- * If the registry is not unique, create a new instance corresponding to the descriptor.
- * Referenced descriptions are searched in the associated ConfigurationProvider.
- *
- * @param registryIdDesc The descriptor used to initialized the ServicesRegistry.
- *
- * @return The requested {@link ServicesRegistry}
- * @throws DeclarationException
- */
- protected ServicesRegistry getServicesRegistry( RegistryDesc registryIdDesc ) throws DeclarationException {
-
- ServicesRegistry registry;
-
- if(registryIdDesc.isUnique() ) {
- // lookup for an instance
- registry = getSingleRegistry(registryIdDesc);
- if( registry != null )
- return registry;
- // Not found: create it
- }
-
- // create a new Registry
- List<DeclarationException> errors = new ArrayList<DeclarationException>();
- registry = new ServicesRegistry();
- // Initialize it
- // add parents
- for(RegistryDesc parentName: registryIdDesc.getParents()) {
- try {
- ServicesRegistry parent = getServicesRegistry(parentName);
- registry.addParentRegistry(parent);
- } catch (DeclarationException e) {
- errors.add(e);
- }
- }
-
- // Add services
- for(AbstractServiceDesc serviceDesc: registryIdDesc.getServices()) {
-
- registry.add(ServiceDescriptorUtils.toServiceDescriptor(serviceDesc) );
- }
-
- // Throw exceptions if pb encountered
- if(errors.size() >0) {
- if(errors.size() == 1) {
- throw errors.get(0);
- }
- else {
- // TODO: throw a multi exception
- throw new DeclarationException("Somme services are not started (first is shown)", errors.get(0));
- }
- }
-
- return registry;
- }
-
- /**
- * Extends the specified registry with all services and parents declared in the specified descriptor.
- * Only missing services and parents are added.
- * <br>If both the original registry and the additional registry contain a service with the same name,
- * the service from the original registry is conserved.
- *
- * @param registry The registry to extends.
- * @param extendsWithRegistryName The name of the descriptor used to extends the registry.
- * @return
- * @throws DeclarationException
- */
- public ServicesRegistry extendsServicesRegistry( ServicesRegistry registry, String extendsWithRegistryName ) throws DeclarationException {
-
- RegistryDesc registryDesc = descriptorProviders.getRegistryDesc( extendsWithRegistryName);
-
- return extendsServicesRegistry(registry, registryDesc);
- }
-
- /**
- * Extends the specified registry with all services and parents declared in the specified descriptor.
- * Only missing services and parents are added.
- * <br>If both the original registry and the additional registry contain a service with the same name,
- * the service from the original registry is conserved.
- *
- * @param extendRegistryDesc The descriptor used to initialized the ServicesRegistry.
- *
- * @return The requested {@link ServicesRegistry}
- * @throws DeclarationException
- */
- protected ServicesRegistry extendsServicesRegistry( ServicesRegistry registry, RegistryDesc extendRegistryDesc ) throws DeclarationException {
-
- // create a new Registry
- List<Throwable> errors = new ArrayList<Throwable>();
-
- // add missing parents
- //
- if( extendRegistryDesc.getParents().size()>0) {
- throw new UnsupportedOperationException("Registry extension with parents not yet implemented.");
- }
-// for(RegistryDesc newExtend: extendRegistryDesc.getParents()) {
-// try {
-// if( !registry.containsParent(newExtend.getName()) ) {
-// ServicesRegistry parent = getServicesRegistry(newExtend.getName());
-// registry.addParentRegistry(parent);
-// }
-//
-// } catch (DeclarationException e) {
-// errors.add(e);
-// }
-// }
-
-
- // Add missing services
- for( AbstractServiceDesc idDesc : extendRegistryDesc.getServices() ) {
- try {
- if( ! registry.isStarted(idDesc.getName(), false)) {
- registry.add(ServiceDescriptorUtils.toServiceDescriptor(idDesc) );
- }
- } catch (ServiceNotFoundException e) {
- errors.add(e);
- }
- }
-
- // Throw exceptions if pb encountered
- if(errors.size() >0) {
- if(errors.size() == 1) {
- throw new DeclarationException(errors.get(0));
- }
- else {
- // TODO: throw a multi exception
- throw new DeclarationMultiException("Somme services are not started.", errors);
- }
- }
-
- return registry;
- }
-
- /**
- * Get the specified single registry by its name.
- * Return null if not found or if the repository do not exist.
- *
- * @param registryIdDesc
- * @return
- */
- private ServicesRegistry getSingleRegistry(RegistryDesc registryIdDesc) {
- if( singleRegistries == null)
- return null;
- return singleRegistries.get( registryIdDesc.getName() );
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.AbstractServiceDesc;
+import org.eclipse.papyrus.infra.core.serviceregistry.servicedescriptors.RegistryDesc;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class ServiceRegistryFactory {
+
+ /**
+ * Repository of single registries.
+ */
+ protected Map<String, ServicesRegistry> singleRegistries;
+
+ /**
+ * DescriptorProviders access point.
+ */
+ protected DescriptorsCache descriptorProviders;
+
+ /**
+ * Constructor.
+ *
+ */
+ public ServiceRegistryFactory(DescriptorsCache descriptorProviders) {
+ this.descriptorProviders = descriptorProviders;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param declaredDescriptorProviders Array of providers to be used by the {@link ServiceDescriptorsWithIdProviderCollection}.
+ */
+ public ServiceRegistryFactory(IServiceDescriptorsWithIdProvider ... declaredDescriptorProviders ) {
+
+ descriptorProviders = new DescriptorsCache();
+ descriptorProviders.addAll(declaredDescriptorProviders);
+ }
+
+ /**
+ * Create a {@link ServicesRegistry} from the specified description.
+ * The description is searched in the associated {@link ServiceDescriptorsWithIdProviderCollection}.
+ *
+ * @param registryName The name of the description used to initialized the ServicesRegistry.
+ *
+ * @return The requested {@link ServicesRegistry}
+ * @throws DeclarationException
+ */
+ public ServicesRegistry getServicesRegistry( String registryName ) throws DeclarationException {
+
+ RegistryDesc registryIdDesc = descriptorProviders.getRegistryDesc( registryName);
+
+ return getServicesRegistry(registryIdDesc);
+ }
+
+ /**
+ * Get a {@link ServicesRegistry} corresponding to the specified descriptor. Also create recursively referenced
+ * registries and services.
+ *
+ * If the registry is "unique", lookup for an already existing instance, and return it if found.
+ * If the registry is not unique, create a new instance corresponding to the descriptor.
+ * Referenced descriptions are searched in the associated ConfigurationProvider.
+ *
+ * @param registryIdDesc The descriptor used to initialized the ServicesRegistry.
+ *
+ * @return The requested {@link ServicesRegistry}
+ * @throws DeclarationException
+ */
+ protected ServicesRegistry getServicesRegistry( RegistryDesc registryIdDesc ) throws DeclarationException {
+
+ ServicesRegistry registry;
+
+ if(registryIdDesc.isUnique() ) {
+ // lookup for an instance
+ registry = getSingleRegistry(registryIdDesc);
+ if( registry != null )
+ return registry;
+ // Not found: create it
+ }
+
+ // create a new Registry
+ List<DeclarationException> errors = new ArrayList<DeclarationException>();
+ registry = new ServicesRegistry();
+ // Initialize it
+ // add parents
+ for(RegistryDesc parentName: registryIdDesc.getParents()) {
+ try {
+ ServicesRegistry parent = getServicesRegistry(parentName);
+ registry.addParentRegistry(parent);
+ } catch (DeclarationException e) {
+ errors.add(e);
+ }
+ }
+
+ // Add services
+ for(AbstractServiceDesc serviceDesc: registryIdDesc.getServices()) {
+
+ registry.add(ServiceDescriptorUtils.toServiceDescriptor(serviceDesc) );
+ }
+
+ // Throw exceptions if pb encountered
+ if(errors.size() >0) {
+ if(errors.size() == 1) {
+ throw errors.get(0);
+ }
+ else {
+ // TODO: throw a multi exception
+ throw new DeclarationException("Somme services are not started (first is shown)", errors.get(0)); //$NON-NLS-1$
+ }
+ }
+
+ return registry;
+ }
+
+ /**
+ * Extends the specified registry with all services and parents declared in the specified descriptor.
+ * Only missing services and parents are added.
+ * <br>If both the original registry and the additional registry contain a service with the same name,
+ * the service from the original registry is conserved.
+ *
+ * @param registry The registry to extends.
+ * @param extendsWithRegistryName The name of the descriptor used to extends the registry.
+ * @return
+ * @throws DeclarationException
+ */
+ public ServicesRegistry extendsServicesRegistry( ServicesRegistry registry, String extendsWithRegistryName ) throws DeclarationException {
+
+ RegistryDesc registryDesc = descriptorProviders.getRegistryDesc( extendsWithRegistryName);
+
+ return extendsServicesRegistry(registry, registryDesc);
+ }
+
+ /**
+ * Extends the specified registry with all services and parents declared in the specified descriptor.
+ * Only missing services and parents are added.
+ * <br>If both the original registry and the additional registry contain a service with the same name,
+ * the service from the original registry is conserved.
+ *
+ * @param extendRegistryDesc The descriptor used to initialized the ServicesRegistry.
+ *
+ * @return The requested {@link ServicesRegistry}
+ * @throws DeclarationException
+ */
+ protected ServicesRegistry extendsServicesRegistry( ServicesRegistry registry, RegistryDesc extendRegistryDesc ) throws DeclarationException {
+
+ // create a new Registry
+ List<Throwable> errors = new ArrayList<Throwable>();
+
+ // add missing parents
+ //
+ if( extendRegistryDesc.getParents().size()>0) {
+ throw new UnsupportedOperationException("Registry extension with parents not yet implemented."); //$NON-NLS-1$
+ }
+// for(RegistryDesc newExtend: extendRegistryDesc.getParents()) {
+// try {
+// if( !registry.containsParent(newExtend.getName()) ) {
+// ServicesRegistry parent = getServicesRegistry(newExtend.getName());
+// registry.addParentRegistry(parent);
+// }
+//
+// } catch (DeclarationException e) {
+// errors.add(e);
+// }
+// }
+
+
+ // Add missing services
+ for( AbstractServiceDesc idDesc : extendRegistryDesc.getServices() ) {
+ try {
+ if( ! registry.isStarted(idDesc.getName(), false)) {
+ registry.add(ServiceDescriptorUtils.toServiceDescriptor(idDesc) );
+ }
+ } catch (ServiceNotFoundException e) {
+ errors.add(e);
+ }
+ }
+
+ // Throw exceptions if pb encountered
+ if(errors.size() >0) {
+ if(errors.size() == 1) {
+ throw new DeclarationException(errors.get(0));
+ }
+ else {
+ // TODO: throw a multi exception
+ throw new DeclarationMultiException("Somme services are not started.", errors);
+ }
+ }
+
+ return registry;
+ }
+
+ /**
+ * Get the specified single registry by its name.
+ * Return null if not found or if the repository do not exist.
+ *
+ * @param registryIdDesc
+ * @return
+ */
+ private ServicesRegistry getSingleRegistry(RegistryDesc registryIdDesc) {
+ if( singleRegistries == null)
+ return null;
+ return singleRegistries.get( registryIdDesc.getName() );
+ }
+
+
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceStartKind.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceStartKind.java
index 9071b2b..9be909b 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceStartKind.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceStartKind.java
@@ -1,18 +1,28 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-/**
- * Kind of possible start method for a service. LAZY - The service start when it
- * is requested for the first time. STARTUP - The service start as soon as the
- * registry is started, or when the service is added is the registry is already
- * started.
- *
- * @author dumoulin
- *
- */
-public enum ServiceStartKind {
-
- LAZY, STARTUP;
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+/**
+ * Kind of possible start method for a service. LAZY - The service start when it
+ * is requested for the first time. STARTUP - The service start as soon as the
+ * registry is started, or when the service is added is the registry is already
+ * started.
+ *
+ * @author dumoulin
+ *
+ */
+public enum ServiceStartKind {
+
+ LAZY, STARTUP;
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceState.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceState.java
index 409a9bc..2f75143 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceState.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServiceState.java
@@ -1,14 +1,24 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-/**
- * The different states that a service can have.
- *
- * @author dumoulin
- *
- */
-public enum ServiceState {
- registered, created, initialized, starting, started, disposed, error
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+/**
+ * The different states that a service can have.
+ *
+ * @author dumoulin
+ *
+ */
+public enum ServiceState {
+ registered, created, initialized, starting, started, disposed, error
+}
diff --git a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServicesRegistry.java b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServicesRegistry.java
index c46bc43..1525420 100644
--- a/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServicesRegistry.java
+++ b/plugins/infra/core/serviceregistry/org.eclipse.papyrus.infra.core.serviceregistry/src/org/eclipse/papyrus/infra/core/serviceregistry/ServicesRegistry.java
@@ -1,1368 +1,1378 @@
-/**
- *
- */
-package org.eclipse.papyrus.infra.core.serviceregistry;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.eclipse.papyrus.infra.core.serviceregistry.ServiceDescriptor.ServiceTypeKind;
-import org.eclipse.papyrus.infra.core.serviceregistry.internal.AliasServiceEntry;
-import org.eclipse.papyrus.infra.core.serviceregistry.internal.LazyStartupEntry;
-import org.eclipse.papyrus.infra.core.serviceregistry.internal.PojoServiceEntry;
-import org.eclipse.papyrus.infra.core.serviceregistry.internal.ServiceEntry;
-import org.eclipse.papyrus.infra.core.serviceregistry.internal.ServiceFactoryEntry;
-import org.eclipse.papyrus.infra.core.serviceregistry.internal.ServiceStartupEntry;
-import org.eclipse.papyrus.infra.core.serviceregistry.internal.ServiceTypeEntry;
-import org.eclipse.papyrus.infra.core.serviceregistry.internal.StartStartupEntry;
-
-/**
- * A registry of services. This registry allows to get a service by its
- * identifier. The identifier is generally the classname of the service.
- * Services can be added using the Eclipse extension mechanism (if you use {@link ExtensionServicesRegistry}). <br>
- * A Service is a class providing operations. The ServiceRegistry is used to
- * share objects (i.e. services) between nested editors and also the core main
- * editor.
- *
- * <br>
- * In this implementation, services should be added to the registry before the
- * call to createServices(). If a service is added after the call, it will not
- * be started (except if it is a lazy service). <br>
- * A typical usage is:
- *
- * <pre>
- * <code>
- * ServicesRegistry serviceRegistry = new ServiceRegistry();
- * // Add your services
- * serviceRegistry.add( ...);
- * serviceRegistry.add( ...);
- *
- * // start the services
- * serviceRegistry.startRegistry();
- *
- * // Retrieve a service
- * myService = serviceRegistry.getService( serviceKey );
- * </code>
- * </pre>
- *
- * It is possible to register new services after the serviceRegistry has been
- * started. In this case, you need to start them explicitly if they are of type
- * ServiceStartKind.STARTUP.
- *
- * <pre>
- * <code>
- * // Add your new services
- * serviceRegistry.add( key1, ...);
- * serviceRegistry.add( key2, ...);
- *
- * // start the new services
- * serviceRegistry.startRegistry(key1, key2);
- * </code>
- * </pre>
- *
- * <ul>
- * <li></li>
- * <li></li>
- * </ul>
- *
- * @author cedric dumoulin
- *
- *
- */
-public class ServicesRegistry {
-
- /** Log object */
- protected Logger log = Logger.getLogger(getClass().getName());
-
- /**
- * Map of existing services.
- */
- // private Map<Object, AbstractServiceEntry> services;
-
- /**
- * A Map of services added to the register (thow the addXxx() methods), but
- * not yet registered. They will be registered after a call to startXxx().
- */
- private Map<String, ServiceStartupEntry> addedServices = new HashMap<String, ServiceStartupEntry>();
-
- /**
- * Map of services registered with a name.
- */
- private Map<String, ServiceStartupEntry> namedServices = new HashMap<String, ServiceStartupEntry>();
-
- /**
- * Map of services registered without a name (anonymous). Such services
- * can't be retrieved.
- */
- private List<ServiceStartupEntry> anonymousServices = new ArrayList<ServiceStartupEntry>();
-
- /**
- * List of parents used as fallback if the service is not found in this registry.
- */
- private List<ServicesRegistry> parents = new ArrayList<ServicesRegistry>();
-
- /**
- * Constructor.
- */
- public ServicesRegistry() {
- }
-
- /**
- * Add a service by its ServiceDescriptor.
- *
- * @param serviceDescriptor
- * Descriptor describing the service.
- * @throws ServiceException
- * If an error occurs while initializing service.
- */
- public void add(ServiceDescriptor serviceDescriptor) {
- // Check if the service already exist.
- ServiceStartupEntry service = addedServices.get(serviceDescriptor.getKey());
- if(service != null) {
- if(service.getDescriptor().getPriority() > serviceDescriptor.getPriority())
- return;
- else if(service.getDescriptor().getPriority() == serviceDescriptor.getPriority()) {
- log.warning("Two services with same priority (" + serviceDescriptor.getPriority() + ") are declared under key '" + service.getDescriptor().getKey() + "'. Keep the first encountered only. (bundles: " + service.getDescriptor().getClassBundleID() + ", " + serviceDescriptor.getClassBundleID() + ")");
- }
- }
-
- // Compute the service type entry
- ServiceTypeEntry serviceTypeEntry;
- ServiceTypeKind typeKind = serviceDescriptor.getServiceTypeKind();
- switch( typeKind) {
- case service:
- serviceTypeEntry = new ServiceEntry(serviceDescriptor);
- break;
- case serviceFactory:
- serviceTypeEntry = new ServiceFactoryEntry(serviceDescriptor);
- break;
- case pojo:
- serviceTypeEntry = new PojoServiceEntry(serviceDescriptor);
- break;
- case alias:
- serviceTypeEntry = new AliasServiceEntry(serviceDescriptor);
- break;
- default:
- // Add as pojo
- // Should better throw an exception. (MalformedDescriptor ?)
- serviceTypeEntry = new PojoServiceEntry(serviceDescriptor);
- }
-
- // Create the entry
- ServiceStartupEntry serviceEntry;
- switch(serviceDescriptor.getServiceStartKind()) {
- case STARTUP:
- serviceEntry = new StartStartupEntry(serviceTypeEntry);
- break;
- case LAZY:
- serviceEntry = new LazyStartupEntry(serviceTypeEntry, this);
- break;
- default:
- // Add as LAZY
- // Should better throw an exception. (MalformedDescriptor ?)
- serviceEntry = new LazyStartupEntry(serviceTypeEntry, this);
- }
-
- // Add the entry
- addedServices.put(serviceDescriptor.getKey(), serviceEntry);
- }
-
- /**
- * Add a service. The descriptor will be created.
- *
- * @param key
- * Service key
- * @param priority
- * service priority
- * @param serviceInstance
- * The instance of the service
- */
- public void add(String key, int priority, IService serviceInstance) {
- add(key, priority, serviceInstance, ServiceStartKind.STARTUP);
- }
-
- /**
- * Add a service. The descriptor will be created.
- *
- * @param key
- * Service key
- * @param priority
- * service priority
- * @param serviceInstance
- * The instance of the service
- */
- public void add(Class<?> key, int priority, IService serviceInstance) {
- add(key.getName(), priority, serviceInstance, ServiceStartKind.STARTUP);
- }
-
- /**
- * Add a service. The descriptor will be created.
- *
- * @param key
- * Service key
- * @param priority
- * service priority
- * @param serviceInstance
- * The instance of the service
- */
- public void add(String key, int priority, IService serviceInstance, ServiceStartKind startKind) {
- // Check if the service already exist.
- ServiceStartupEntry service = addedServices.get(key);
- if(service != null) {
- if(service.getDescriptor().getPriority() > priority)
- return;
- else if(service.getDescriptor().getPriority() == priority)
- log.warning("Two services with same priority (" + priority + ") are declared under key '" + service.getDescriptor().getKey() + "'. Keep the first encountered only.");
- }
-
- // Create descriptor and add service.
- ServiceDescriptor descriptor = new ServiceDescriptor(key, serviceInstance.getClass().getName(), startKind, priority);
-
- if(startKind == ServiceStartKind.STARTUP)
- addedServices.put(key, new StartStartupEntry(new ServiceEntry(descriptor, serviceInstance)));
- else
- addedServices.put(key, new LazyStartupEntry(new ServiceEntry(descriptor, serviceInstance), this));
- }
-
- /**
- * Add a service. The descriptor will be created.
- *
- * @param key
- * Service key Class used as key. The classname is used as key.
- * @param priority
- * service priority
- * @param serviceInstance
- * The instance of the service
- */
- public void add(Class<?> key, int priority, IService serviceInstance, ServiceStartKind startKind) {
-
- add(key.getName(), priority, serviceInstance, startKind);
- }
-
- /**
- * Add an already instanciated pojo (Plain Old Java Object) as Service. The
- * descriptor will be created. No life cycle methods are called on the
- * service.
- *
- * @param key
- * Service key
- * @param priority
- * service priority
- * @param serviceInstance
- * The instance of the service
- */
- public void add(Class<?> key, int priority, Object serviceInstance) {
- add(key, priority, serviceInstance, ServiceStartKind.STARTUP);
- }
-
- /**
- * Add an already instanciated pojo (Plain Old Java Object) as Service. The
- * descriptor will be created. No life cycle methods are called on the
- * service.
- *
- * @param key
- * Service key
- * @param priority
- * service priority
- * @param serviceInstance
- * The instance of the service
- * @param startKind
- *
- */
- public void add(String key, int priority, Object serviceInstance, ServiceStartKind startKind) {
- // Check if the service already exist.
- ServiceStartupEntry service = addedServices.get(key);
- if(service != null) {
- if(service.getDescriptor().getPriority() > priority)
- return;
- else if(service.getDescriptor().getPriority() == priority)
- log.warning("Two services with same priority (" + priority + ") are declared under key '" + service.getDescriptor().getKey() + "'. Keep the first encountered only.");
- }
-
- // Create descriptor and add service.
- ServiceDescriptor descriptor = new ServiceDescriptor(key, serviceInstance.getClass().getName(), startKind, priority);
-
- if(startKind == ServiceStartKind.STARTUP)
- addedServices.put(key, new StartStartupEntry(new PojoServiceEntry(descriptor, serviceInstance)));
- else
- addedServices.put(key, new LazyStartupEntry(new PojoServiceEntry(descriptor, serviceInstance), this));
-
- }
-
- /**
- * Add an already instanciated pojo (Plain Old Java Object) as Service. The
- * descriptor will be created. No life cycle methods are called on the
- * service.
- *
- * @param key
- * Service key Class used as key. The classname is used as key.
- * @param priority
- * service priority
- * @param serviceInstance
- * The instance of the service
- * @param startKind
- *
- */
- public void add(Class<?> key, int priority, Object serviceInstance, ServiceStartKind startKind) {
-
- add(key.getName(), priority, serviceInstance, startKind);
- }
-
- /**
- * Remove the specified Registry as parent of this registry.
- * .
- * @param parentRegistry
- */
- public void addParentRegistry(ServicesRegistry parentRegistry) {
-
- if( parentRegistry == null) {
- return;
- }
- parents.add(parentRegistry);
- }
-
- /**
- *
- * @param parentRegistry
- */
- public void removeParentRegistry(ServicesRegistry parentRegistry) {
-
- if( parentRegistry == null) {
- return;
- }
- parents.remove(parentRegistry);
- }
-
-
- /**
- * Remove the specified service from the registry.
- *
- * @param key
- */
- public void remove(ServiceDescriptor serviceDescriptor) throws ServiceException {
- remove(serviceDescriptor.getKey());
- }
-
- /**
- * Remove the specified service from the registry.
- *
- * @param key
- */
- public void remove(Object key) throws ServiceException {
- ServiceStartupEntry service = namedServices.remove(key);
- if(service == null) {
- return;
- }
-
- // Stop the service
- service.disposeService();
- }
-
- /**
- * Get the requested service by its key. The key is usually the classname of
- * the service.
- *
- * @param serviceClass
- * @return
- * @throws ServiceException
- * If servive can't be started
- */
- public Object getService(Object key) throws ServiceException {
- ServiceStartupEntry serviceEntry = namedServices.get(key);
- if(serviceEntry == null) {
- // Check if we can find it in parents
- Object service = getServiceFromParents(key);
- if(service != null) {
- // Found in parent, return it
- return service;
- }
-
- // Not found in parents. Throw an exception
- // throw an appropriate exception (If added, say it).
- serviceEntry = addedServices.get(key);
- if(serviceEntry != null)
- throw new BadStateException("Registry should be started before.", serviceEntry.getState(), serviceEntry.getDescriptor());
- else
- throw new ServiceNotFoundException("No service registered under '" + key + "'");
- }
-
- return serviceEntry.getServiceInstance();
- }
-
- /**
- * Get the requested service by its class (the service has to be registered
- * by its class object).
- *
- * @param key
- * The service class.
- * @return The service.
- * @throws ServiceException
- * If service can't be started
- */
- @SuppressWarnings("unchecked")
- public <S> S getService(Class<S> key) throws ServiceException {
-
- String realKey = key.getName();
- ServiceStartupEntry serviceEntry = namedServices.get(realKey);
-
- // Lookup in parents if not found
- if( serviceEntry == null) {
-
- // Check if we can find it in parents
- S service = (S)getServiceFromParents(realKey);
- if(service != null) {
- // Found in parent, return it
- return service;
- }
-
- // Not found in parents. Throw an exception
- // throw an appropriate exception (If added, say it).
- serviceEntry = addedServices.get(realKey);
- if(serviceEntry != null)
- throw new BadStateException("Registry should be started before.", serviceEntry.getState(), serviceEntry.getDescriptor());
- else
- throw new ServiceNotFoundException("No service registered under '" + key + "'");
- }
-
- // Service found, return it.
- return (S)serviceEntry.getServiceInstance();
- }
-
- /**
- * Get the requested service by its class (the service has to be registered
- * by its class object).
- *
- * @param key
- * The service class.
- * @return The service.
- * @throws ServiceException
- * If service can't be started
- */
- private Object getServiceFromParents(Object key) throws ServiceException {
-
- Object foundService;
-
- for( ServicesRegistry parent : parents) {
- foundService = parent.getServiceUnchecked(key);
- // Check if we have found the service
- if( foundService != null) {
- // Found, return it
- return foundService;
- }
- }
- // Not found
- return null;
- }
-
- /**
- * Get the requested service by its key. The key is usually the classname of
- * the service.
- * Return the service, or null if not found.
- * This is for internal use.
- *
- * @param serviceClass
- * @return The service, or null if not found.
- * @throws ServiceException
- * If servive can't be started
- */
- protected Object getServiceUnchecked(Object key) throws ServiceException {
- ServiceStartupEntry service = namedServices.get(key);
- if(service == null) {
- return null;
- }
-
- return service.getServiceInstance();
- }
-
- /**
- * Try to get the {@link ServiceStartupEntry} of the specified service.
- * Search in local namedServices.
- * Also lookup in parents. Return null if not found.
- * The returned entry should not be modified by caller.
- *
- * @param key
- * @return The requested entry, or null if not found.
- */
- protected ServiceStartupEntry getServiceStartupEntry( Object key ) {
-
- return getServiceStartupEntry(key, true);
- }
-
- /**
- * Try to get the {@link ServiceStartupEntry} of the specified service.
- * Search in local namedServices.
- * Also lookup in parents. Return null if not found.
- * The returned entry should not be modified by caller.
- *
- * @param key
- * @param searchInParent True if we should search in parent, false if search take place in this registry only.
- * @return The requested entry, or null if not found.
- */
- protected ServiceStartupEntry getServiceStartupEntry( Object key, boolean searchInParent ) {
-
- ServiceStartupEntry service = namedServices.get(key);
- if( service != null) {
- return service;
- }
-
- // Check in new services
- service = addedServices.get(key);
- if( service != null) {
- return service;
- }
-
- if( searchInParent ) {
- // Lookup in parents
- for(ServicesRegistry registry : parents) {
- service = registry.getServiceStartupEntry(key);
- if( service != null) {
- return service;
- }
- }
- }
-
- // Not found
- return null;
- }
-
- /**
- * Return true if the service is instantiated. Return false otherwise.
- *
- * @return
- */
- public boolean isStarted(Object key) throws ServiceNotFoundException {
- return isStarted(key, true);
- }
-
- /**
- * Return true if the service is instantiated. Return false otherwise.
- *
- * @return
- */
- public boolean isStarted(Object key, boolean searchInParents) throws ServiceNotFoundException {
- ServiceStartupEntry service = getServiceStartupEntry(key, searchInParents);
- if(service == null) {
- throw new ServiceNotFoundException("No service registered under '" + key + "'");
- }
-
- return service.isStarted();
- }
-
- /**
- * Return true if the service is instantiated. Return false otherwise.
- * The service type is converted to its name, then the method is performed.
- * @see #isStarted(Class)
- *
- * @return
- */
- public boolean isStarted(Class<?> serviceType) throws ServiceNotFoundException {
- return isStarted(serviceType.getName(), true);
- }
-
- /**
- * Return true if the service is instantiated. Return false otherwise.
- * The service type is converted to its name, then the method is performed.
- * @see #isStarted(Class)
- *
- * @return
- */
- public boolean isStarted(Class<?> serviceType, boolean searchInParents) throws ServiceNotFoundException {
- return isStarted(serviceType.getName(), searchInParents);
- }
-
- /**
- * Return the state of the specified service.
- *
- * @return
- */
- public ServiceState serviceState(Object key) throws ServiceNotFoundException {
- return serviceState(key, true);
- }
-
- /**
- * Return the state of the specified service.
- * @param key
- * @param searchInParents
- * @return
- * @throws ServiceNotFoundException
- */
- public ServiceState serviceState(Object key, boolean searchInParents ) throws ServiceNotFoundException {
- ServiceStartupEntry service = getServiceStartupEntry(key, searchInParents);
- if(service == null) {
- throw new ServiceNotFoundException("No service registered under '" + key + "'");
- }
-
- return service.getState();
- }
-
- /**
- * Return the state of the specified service.
- *
- * @return
- */
- public ServiceState serviceState(Class<?> serviceType) throws ServiceNotFoundException {
- return serviceState(serviceType.getName(), true);
- }
-
- /**
- * Return the state of the specified service.
- *
- * @return
- */
- public ServiceState serviceState(Class<?> serviceType, boolean searchInParents) throws ServiceNotFoundException {
- return serviceState(serviceType.getName(), searchInParents);
- }
-
- /**
- * Start services newly added.
- * Start all services marked as start = STARTUP.
- * All services are first created, then initialized and finally
- * started. If an error occur on a service during one of this step, the
- * service is removed from the registry and and the error is logged.
-
- * @throws ServiceMultiException
- *
- * @throws ServiceException
- * If a service can't be started.
- *
- */
- public void startNewServices() throws ServiceMultiException {
- // Build the lookup maps
- LookupMap localSpace = new LookupMap(addedServices, namedServices);
- // search space including parents
- LookupMap fullSpace = new LookupMap(addedServices, namedServices, parents);
-
- // Check if all dependencies exist.
- checkDependencies(addedServices.values(), fullSpace);
-
- // Get all roots : LAZY and START
- Collection<ServiceStartupEntry> roots = getServiceRoots(addedServices.values(), localSpace);
- // showServices(" Roots:", roots);
- // Detect cycles
- checkCycle(roots, localSpace);
-
- // Order services in the order we should start them.
- // Lazy services are taken into account, as they can be in a chain of start.
- List<ServiceStartupEntry> toStart = buildTopologicalListOfServicesToStart(roots, localSpace);
-
- // Retain only services with startupkind == START
- //
- roots = retainsToStartServices(roots);
-
- if(Activator.log.isDebugEnabled()) {
- showServices(" Services to start:", toStart);
- }
-
- // Create an object to collect errors if any.
- ServiceMultiException errors = new ServiceMultiException();
-
- createServices(toStart, errors);
- // Register all new services : lazy and start
- registerServices(addedServices.values());
- initServices(toStart, errors);
- startServices(toStart, errors);
-
- // Report errors if any
- if(errors.getExceptions().size() > 0)
- throw errors;
-
-
- }
-
- /**
- * Start the registry. Start all services marked as start = STARTUP are
- * started. All services are first created, then initialized and finally
- * started. If an error occur on a service during one of this step, the
- * service is removed from the registry and and the error is logged.
- *
- * @throws ServiceMultiException
- *
- * @throws ServiceException
- * If a service can't be started.
- *
- * @deprecated Use {@link #startNewServices()}
- */
- protected void startRegistry() throws ServiceMultiException {
-
- startNewServices();
- }
-
- /**
- * Start the specified services, and their required services. The specifies
- * services should be in the addServices or already registered. Start all
- * services marked as start = STARTUP . All eligible services are first
- * created, then initialized and finally started. If an error occur on a
- * service during one of this step, the service is removed from the registry
- * and and the error is logged.
- *
- * @param serviceKeys
- * Keys of services to start.
- * @throws ServiceMultiException
- * @throws ServiceNotFoundException
- * If a service can't be retrieved by its key.
- *
- * @throws ServiceException
- * If a service can't be started.
- */
- public void startServices(List<String> serviceKeys) throws ServiceMultiException, ServiceNotFoundException {
-
- // Build the lookup maps
- LookupMap map = new LookupMap(addedServices, namedServices);
-
- // Get the services
- List<ServiceStartupEntry> services = keysToServices(serviceKeys, map);
-
- // Start them
- startServices(services, map);
- }
-
- /**
- * Same as {@link #startServices(List)}, but with an array as input.
- *
- * @see #startServices(List)
- *
- * @param serviceKeys
- * Keys of services to start.
- * @throws ServiceMultiException
- * @throws ServiceNotFoundException
- * If a service can't be retrieved by its key.
- *
- * @throws ServiceException
- * If a service can't be started.
- */
- public void startServices(String... serviceKeys) throws ServiceMultiException, ServiceNotFoundException {
-
- List<String> serviceKeysList = Arrays.asList(serviceKeys);
- startServices(serviceKeysList);
- }
-
- /**
- * Start the specified services, and their required services. The specifies
- * services should be in the addServices or already registered. Start all
- * services marked as start = STARTUP . All eligible services are first
- * created, then initialized and finally started. If an error occur on a
- * service during one of this step, the service is removed from the registry
- * and and the error is logged.
- *
- * @param serviceKeys
- * Keys of services to start. Keys will be translated to the
- * classname.
- * @throws ServiceMultiException
- * @throws ServiceNotFoundException
- * If a service can't be retrieved by its key.
- *
- * @throws ServiceException
- * If a service can't be started.
- */
- public void startServicesByClassKeys(List<Class<?>> serviceKeys) throws ServiceMultiException, ServiceNotFoundException {
-
- // Build the lookup maps
- LookupMap map = new LookupMap(addedServices, namedServices);
-
- // Get the services
- List<ServiceStartupEntry> services = classKeysToServices(serviceKeys, map);
-
- // Start them
- startServices(services, map);
- }
-
- /**
- * Same as {@link #startServicesByClassKeys(List)}, but with an array as
- * input.
- *
- * @see #startServices(List)
- *
- * @param serviceKeys
- * Keys of services to start.
- * @throws ServiceMultiException
- * @throws ServiceNotFoundException
- * If a service can't be retrieved by its key.
- *
- * @throws ServiceException
- * If a service can't be started.
- */
- public void startServicesByClassKeys(Class<?>... serviceKeys) throws ServiceMultiException, ServiceNotFoundException {
-
- List<Class<?>> serviceKeysList = Arrays.asList(serviceKeys);
- startServicesByClassKeys(serviceKeysList);
- }
-
- /**
- * Start the specified services, and their required services. The specifies
- * services should be in the specified map. The map is also used to resolves
- * dependencies. Start all services marked as start = STARTUP . All eligible
- * services are first created, then initialized and finally started. If an
- * error occur on a service during one of this step, the service is removed
- * from the registry and and the error is logged.
- *
- * @param services
- * Services to start
- * @param map
- * a table of (key, service) used to get a service by its key.
- * @throws ServiceMultiException
- * If a service can't be started.
- */
- private void startServices(List<ServiceStartupEntry> services, LookupMap map) throws ServiceMultiException {
- // Check if all dependencies exist.
- checkDependencies(services, map);
-
- // Get all roots : LAZY and START
- Collection<ServiceStartupEntry> roots = getServiceRoots(services, map);
- if(Activator.log.isDebugEnabled()) {
- showServices(" Roots:", roots);
- }
- // Detect cycles
- checkCycle(roots, map);
- // Retain only services with startupkind == START and state ==
- // REGISTERED
- roots = retainsToStartServices(roots);
- //
- List<ServiceStartupEntry> toStart = buildTopologicalListOfServicesToStart(roots, map);
-
- // Remove already started services
- toStart = retainsToStartServices(toStart);
-
- // if( log.isLoggable(Level.FINE))
- // {
- showServices(" Services to start:", toStart);
- // }
-
- // Create an object to collect errors if any.
- ServiceMultiException errors = new ServiceMultiException();
-
- createServices(toStart, errors);
- // Register all started services
- registerServices(toStart);
- initServices(toStart, errors);
- startServices(toStart, errors);
-
- // Report errors if any
- if(errors.getExceptions().size() > 0)
- throw errors;
- }
-
- /**
- * Return a list of services from a list of services keys.
- *
- * @param serviceKeys
- * @param map
- * @return
- * @throws ServiceNotFoundException
- * If a service can't be retrieved by its key.
- */
- private List<ServiceStartupEntry> keysToServices(List<String> serviceKeys, LookupMap map) throws ServiceNotFoundException {
-
- List<ServiceStartupEntry> result = new ArrayList<ServiceStartupEntry>(serviceKeys.size());
-
- for(String key : serviceKeys) {
- result.add(map.getChecked(key));
- }
- return result;
- }
-
- /**
- * Return a list of services from a list of services keys.
- *
- * @param serviceKeys
- * @param map
- * @return
- * @throws ServiceNotFoundException
- * If a service can't be retrieved by its key.
- */
- private List<ServiceStartupEntry> classKeysToServices(List<Class<?>> serviceKeys, LookupMap map) throws ServiceNotFoundException {
-
- List<ServiceStartupEntry> result = new ArrayList<ServiceStartupEntry>(serviceKeys.size());
-
- for(Class<?> key : serviceKeys) {
- result.add(map.getChecked(key.getName()));
- }
- return result;
- }
-
- /**
- * Print the services. For debug purpose
- *
- * @param roots
- */
- private void showServices(String message, Collection<ServiceStartupEntry> roots) {
- StringBuffer buffer = new StringBuffer();
- buffer.append("--------------------------\n");
- buffer.append(message);
- buffer.append("\n");
- for(ServiceStartupEntry service : roots) {
- buffer.append(" ");
- buffer.append(service.getDescriptor().toString());
- buffer.append("\n");
- }
- buffer.append("--------- done -----------\n");
- Activator.log.debug(buffer.toString());
- }
-
- /**
- * Check if all dependencies exist. Throw an error if a declared dependency
- * has no corresponding service.
- *
- * @param services
- * Services to check
- * @param map
- * Map of services by keys.
- * @throws ServiceMultiException
- */
- private void checkDependencies(Collection<ServiceStartupEntry> services, LookupMap map) throws ServiceMultiException {
-
- ServiceMultiException errors = new ServiceMultiException();
-
- // Walk each service and check if its required services exist.
- for(ServiceStartupEntry service : services) {
- ServiceDescriptor desc = service.getDescriptor();
-
- // Check each required service
- for(String key : desc.getRequiredServiceKeys()) {
-
- // Check if service can be found
- try {
- map.getChecked(key);
- } catch (ServiceNotFoundException e) {
- errors.addException(desc.getKey(), e);
- }
- }
- }
-
- // Throw errors if any
- if(errors.getExceptions().size() > 0)
- throw errors;
- }
-
- /**
- * Retains only the services that should be started. Retains only services
- * with startupkind = START and state == REGISTERED
- *
- * @param services
- * Collection to filter
- * @return a new Collection containing the services to start.
- */
- private List<ServiceStartupEntry> retainsToStartServices(Collection<ServiceStartupEntry> services) {
-
- List<ServiceStartupEntry> result = new ArrayList<ServiceStartupEntry>();
- for(ServiceStartupEntry service : services) {
- ServiceDescriptor desc = service.getDescriptor();
- if(service.getState() == ServiceState.registered && desc.isStartAtStartup()) {
- result.add(service);
- }
- }
-
- return result;
- }
-
- /**
- * Check for cycles. Throws an exception if a cycle is discovered. Each root
- * is checked to see if it contains a cycle.
- *
- * @param roots
- * @param map
- */
- private void checkCycle(Collection<ServiceStartupEntry> roots, LookupMap map) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * Build a list of services to start, in the topological order (right
- * order). The required services are placed before the dependent services in
- * the list. Services already started are disguarded.
- *
- * @param roots
- * @param map
- * Map used to resolve the entry by their key.
- * @return
- */
- private List<ServiceStartupEntry> buildTopologicalListOfServicesToStart(Collection<ServiceStartupEntry> roots, LookupMap map) {
-
- List<ServiceStartupEntry> result = new ArrayList<ServiceStartupEntry>();
-
- // Each root represent a graph. Walk the root and its child in the list,
- // in the right order.
- for(ServiceStartupEntry root : roots) {
- walkGraphDepthFirst(result, root, map);
- }
-
- return result;
- }
-
- /**
- * Add recursively the provided node, and then its direct children.
- *
- * @param result
- * The list where the node are added
- * @param node
- * The node to add
- * @param map
- */
- private void walkGraphDepthFirst(List<ServiceStartupEntry> result, ServiceStartupEntry node, LookupMap map) {
-
- // Do not add already added or started node.
- if(result.contains(node) || node.isStarted())
- return;
-
- // add direct child
- for(String serviceKey : node.getDescriptor().getRequiredServiceKeys()) {
- try {
- ServiceStartupEntry child = map.getChecked(serviceKey);
- walkGraphDepthFirst(result, child, map);
- } catch (ServiceNotFoundException e) {
- // Do nothing, we have already reported the problems with
- // checkServices;
- }
- }
-
- // Now add the node
- result.add(node);
- }
-
- /**
- * Create a List of the root services. The roots are services that are not
- * required by any service.
- *
- * @param addedServices
- * A collection from which roots are required. The collection is
- * unmodified.
- * @param map
- * @return
- */
- private Collection<ServiceStartupEntry> getServiceRoots(Collection<ServiceStartupEntry> addedServices, LookupMap keyServiceMap) {
-
- // Create a copy of the list of services
- Collection<ServiceStartupEntry> services = new ArrayList<ServiceStartupEntry>(addedServices);
-
- List<ServiceStartupEntry> allRequired = new ArrayList<ServiceStartupEntry>();
-
- // The roots are services that are not required by any service.
- // Build a list of the services required by all other services.
- for(ServiceStartupEntry service : services) {
- // Add each child to the list of required
- for(String serviceKey : service.getDescriptor().getRequiredServiceKeys()) {
- try {
-
- ServiceStartupEntry child = keyServiceMap.getChecked(serviceKey);
- allRequired.add(child);
- } catch (ServiceNotFoundException e) {
- // Do nothing, we have already reported the problems with
- // checkServices;
- }
- }
-
- }
-
- // Roots are those that are not required.
- // So it is the original list minus the required.
- services.removeAll(allRequired);
-
- return services;
- }
-
- /**
- * Dispose all services for this registry and its parents.
- *
- * @throws ServiceMultiException
- */
- public void disposeRegistry() throws ServiceMultiException {
-
- disposeRegistry(true);
- }
-
- /**
- * Dispose all services, and parent registries if any.
- *
- * @throws ServiceMultiException
- */
- public void disposeRegistry(boolean isRecursive) throws ServiceMultiException {
-
- // List of keys of service in error.
- ServiceMultiException errors = new ServiceMultiException();
- disposeRegistry(errors, isRecursive);
- // Report errors if any
- if(errors.getExceptions().size() > 0)
- throw errors;
- }
-
- /**
- * Dispose all services, and parent registries if any.
- *
- * @throws ServiceMultiException
- */
- protected void disposeRegistry(ServiceMultiException errors, boolean isRecursive) throws ServiceMultiException {
-
- // List of keys of service in error.
- disposeServices(namedServices.values(), errors);
- disposeServices(anonymousServices, errors);
-
- // Clean up properties to help GC
- addedServices.clear();
- addedServices = null;
- anonymousServices.clear();
- anonymousServices = null;
- namedServices.clear();
- namedServices = null;
-
- // Do parents
- if( isRecursive ) {
- for( ServicesRegistry parent : parents) {
- parent.disposeRegistry( errors, true);
- }
- }
- }
-
- /**
- * Create all services provided in the list
- *
- * @param toStart
- * List of services to create.
- * @param errors
- * Exception to collect errors.
- *
- * @throws ServiceMultiException
- * If an error occure during the creation
- *
- * @throws ServiceException
- * If a service can't be started.
- */
- private void createServices(List<ServiceStartupEntry> toStart, ServiceMultiException errors) throws ServiceMultiException {
-
- // Loop on all services
- for(ServiceStartupEntry serviceEntry : toStart) {
- try {
-
- serviceEntry.createService();
- } catch (ServiceException e) {
- log.log(Level.SEVERE, "Can't create service '" + serviceEntry + "'", e);
-
- errors.addException(serviceEntry.getDescriptor().getKey(), e);
- }
- }
-
- }
-
- /**
- * Register all services provided in the list. After this operation,
- * services are available thru {@link #getService(Class)}.
- *
- * @param toStart
- * List of services to register.
- *
- * @throws ServiceException
- * If a service can't be started.
- */
- private void registerServices(Collection<ServiceStartupEntry> toStart) {
-
- // Loop on all services
- for(ServiceStartupEntry serviceEntry : toStart) {
- ServiceDescriptor desc = serviceEntry.getDescriptor();
- if(desc.isAnonymous()) {
- anonymousServices.add(serviceEntry);
- } else {
- namedServices.put(desc.getKey(), serviceEntry);
- }
- }
- }
-
- /**
- * Init all services provided in the list
- *
- * @param toStart
- * List of services to init.
- * @param errors
- *
- * @throws ServiceMultiException
- * If an error occure during the process
- *
- * @throws ServiceException
- * If a service can't be started.
- */
- private void initServices(List<ServiceStartupEntry> toStart, ServiceMultiException errors) throws ServiceMultiException {
-
- // Loop on all services
- for(ServiceStartupEntry serviceEntry : toStart) {
- try {
-
- serviceEntry.initService(this);
- } catch (ServiceException e) {
- log.log(Level.SEVERE, "Can't initialize service '" + serviceEntry + "'", e);
- errors.addException(serviceEntry.getDescriptor().getKey(), e);
- }
- }
-
- }
-
- /**
- * Init all services provided in the list
- *
- * @param toStart
- * List of services to init.
- * @param errors
- *
- * @throws ServiceMultiException
- * If an error occure during the process
- *
- * @throws ServiceException
- * If a service can't be started.
- */
- private void startServices(List<ServiceStartupEntry> toStart, ServiceMultiException errors) throws ServiceMultiException {
-
- // Loop on all services
- for(ServiceStartupEntry serviceEntry : toStart) {
- try {
-
- serviceEntry.startService();
- } catch (ServiceException e) {
- log.log(Level.SEVERE, "Can't start service '" + serviceEntry + "'", e);
-
- errors.addException(serviceEntry.getDescriptor().getKey(), e);
- }
- }
-
- }
-
- /**
- * Dispose all started services.
- * Services are disposed in creation reverse order
- *
- * @throws ServiceMultiException
- *
- * @throws ServiceException
- * If a service can't be started.
- */
- private void disposeServices(Collection<ServiceStartupEntry> services, ServiceMultiException errors) {
-
- // Dispose services
- for(ServiceStartupEntry serviceEntry : services) {
- try {
- serviceEntry.disposeService();
- } catch (ServiceException e) {
- log.log(Level.SEVERE, "Can't dispose service '" + serviceEntry.getDescriptor().getKey() + "'", e);
- errors.addException(serviceEntry.getDescriptor(), e);
- }
- }
- }
-
- /**
- * This class represents a union of two maps of <String,
- * ServiceStartupEntry>. It provide specific methods to retrieve a {@link ServiceStartupEntry} by its key.
- * <br>
- * This class is used to lookup {@link ServiceStartupEntry} in multiple namespaces (2 maps, and then registries).
- *
- *
- * @author cedric dumoulin
- *
- */
- private class LookupMap {
-
- Map<String, ServiceStartupEntry> map1;
-
- Map<String, ServiceStartupEntry> map2;
-
- // additional service registries into which we should search
- List<ServicesRegistry> registries;
-
- /**
- *
- * Constructor. Build a union of two maps.
- *
- * @param map1
- * @param map2
- */
- public LookupMap(Map<String, ServiceStartupEntry> map1, Map<String, ServiceStartupEntry> map2) {
- this.map1 = map1;
- this.map2 = map2;
- }
-
- public LookupMap(Map<String, ServiceStartupEntry> space1, Map<String, ServiceStartupEntry> space2, List<ServicesRegistry> registries) {
- this( space1, space2);
- this.registries = registries;
- }
-
- /**
- *
- * Constructor. Build a union of one map (sic).
- *
- * @param map
- */
- @SuppressWarnings("unused")
- public LookupMap(Map<String, ServiceStartupEntry> map) {
- this(map, null);
- }
-
- /**
- * Get a service by its key.
- *
- * @param key
- * @return the service or null if not found.
- */
- @SuppressWarnings("unused")
- public ServiceStartupEntry get(String key) {
-
- ServiceStartupEntry res = map1.get(key);
- if(res != null)
- return res;
- if(map2 != null) {
- res = map2.get(key);
- }
- if( res == null && registries != null) {
- // lookup in registries
- res = getFromRegistries(key);
- }
-
- return res;
- }
-
- /**
- * Get a service by its key.
- *
- * @param key
- * @return The requested service.
- * @throws ServiceNotFoundException
- * if the service can't be found.
- */
- public ServiceStartupEntry getChecked(String key) throws ServiceNotFoundException {
-
- ServiceStartupEntry res = map1.get(key);
- if(res != null)
- return res;
- if(map2 != null)
- res = map2.get(key);
- if( res == null && registries != null) {
- // lookup in registries
- res = getFromRegistries(key);
- }
- if(res != null)
- return res;
-
- throw new ServiceNotFoundException("No service found under key '" + key.toString() + "'");
- }
-
- /**
- * Try to get the entry from the registries.
- * @param key
- * @return
- */
- private ServiceStartupEntry getFromRegistries(String key) {
-
- ServiceStartupEntry service;
- // Lookup in parents
- for(ServicesRegistry registry : registries) {
- service = registry.getServiceStartupEntry(key);
- if( service != null) {
- return service;
- }
- }
-
- return null;
- }
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 LIFL and others.
+ *
+ *
+ * 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:
+ * LIFL - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.serviceregistry;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.papyrus.infra.core.serviceregistry.ServiceDescriptor.ServiceTypeKind;
+import org.eclipse.papyrus.infra.core.serviceregistry.internal.AliasServiceEntry;
+import org.eclipse.papyrus.infra.core.serviceregistry.internal.LazyStartupEntry;
+import org.eclipse.papyrus.infra.core.serviceregistry.internal.PojoServiceEntry;
+import org.eclipse.papyrus.infra.core.serviceregistry.internal.ServiceEntry;
+import org.eclipse.papyrus.infra.core.serviceregistry.internal.ServiceFactoryEntry;
+import org.eclipse.papyrus.infra.core.serviceregistry.internal.ServiceStartupEntry;
+import org.eclipse.papyrus.infra.core.serviceregistry.internal.ServiceTypeEntry;
+import org.eclipse.papyrus.infra.core.serviceregistry.internal.StartStartupEntry;
+
+/**
+ * A registry of services. This registry allows to get a service by its
+ * identifier. The identifier is generally the classname of the service.
+ * Services can be added using the Eclipse extension mechanism (if you use {@link ExtensionServicesRegistry}). <br>
+ * A Service is a class providing operations. The ServiceRegistry is used to
+ * share objects (i.e. services) between nested editors and also the core main
+ * editor.
+ *
+ * <br>
+ * In this implementation, services should be added to the registry before the
+ * call to createServices(). If a service is added after the call, it will not
+ * be started (except if it is a lazy service). <br>
+ * A typical usage is:
+ *
+ * <pre>
+ * <code>
+ * ServicesRegistry serviceRegistry = new ServiceRegistry();
+ * // Add your services
+ * serviceRegistry.add( ...);
+ * serviceRegistry.add( ...);
+ *
+ * // start the services
+ * serviceRegistry.startRegistry();
+ *
+ * // Retrieve a service
+ * myService = serviceRegistry.getService( serviceKey );
+ * </code>
+ * </pre>
+ *
+ * It is possible to register new services after the serviceRegistry has been
+ * started. In this case, you need to start them explicitly if they are of type
+ * ServiceStartKind.STARTUP.
+ *
+ * <pre>
+ * <code>
+ * // Add your new services
+ * serviceRegistry.add( key1, ...);
+ * serviceRegistry.add( key2, ...);
+ *
+ * // start the new services
+ * serviceRegistry.startRegistry(key1, key2);
+ * </code>
+ * </pre>
+ *
+ * <ul>
+ * <li></li>
+ * <li></li>
+ * </ul>
+ *
+ * @author cedric dumoulin
+ *
+ *
+ */
+public class ServicesRegistry {
+
+ /** Log object */
+ protected Logger log = Logger.getLogger(getClass().getName());
+
+ /**
+ * Map of existing services.
+ */
+ // private Map<Object, AbstractServiceEntry> services;
+
+ /**
+ * A Map of services added to the register (thow the addXxx() methods), but
+ * not yet registered. They will be registered after a call to startXxx().
+ */
+ private Map<String, ServiceStartupEntry> addedServices = new HashMap<String, ServiceStartupEntry>();
+
+ /**
+ * Map of services registered with a name.
+ */
+ private Map<String, ServiceStartupEntry> namedServices = new HashMap<String, ServiceStartupEntry>();
+
+ /**
+ * Map of services registered without a name (anonymous). Such services
+ * can't be retrieved.
+ */
+ private List<ServiceStartupEntry> anonymousServices = new ArrayList<ServiceStartupEntry>();
+
+ /**
+ * List of parents used as fallback if the service is not found in this registry.
+ */
+ private List<ServicesRegistry> parents = new ArrayList<ServicesRegistry>();
+
+ /**
+ * Constructor.
+ */
+ public ServicesRegistry() {
+ }
+
+ /**
+ * Add a service by its ServiceDescriptor.
+ *
+ * @param serviceDescriptor
+ * Descriptor describing the service.
+ * @throws ServiceException
+ * If an error occurs while initializing service.
+ */
+ public void add(ServiceDescriptor serviceDescriptor) {
+ // Check if the service already exist.
+ ServiceStartupEntry service = addedServices.get(serviceDescriptor.getKey());
+ if(service != null) {
+ if(service.getDescriptor().getPriority() > serviceDescriptor.getPriority())
+ return;
+ else if(service.getDescriptor().getPriority() == serviceDescriptor.getPriority()) {
+ log.warning("Two services with same priority (" + serviceDescriptor.getPriority() + ") are declared under key '" + service.getDescriptor().getKey() + "'. Keep the first encountered only. (bundles: " + service.getDescriptor().getClassBundleID() + ", " + serviceDescriptor.getClassBundleID() + ")");
+ }
+ }
+
+ // Compute the service type entry
+ ServiceTypeEntry serviceTypeEntry;
+ ServiceTypeKind typeKind = serviceDescriptor.getServiceTypeKind();
+ switch( typeKind) {
+ case service:
+ serviceTypeEntry = new ServiceEntry(serviceDescriptor);
+ break;
+ case serviceFactory:
+ serviceTypeEntry = new ServiceFactoryEntry(serviceDescriptor);
+ break;
+ case pojo:
+ serviceTypeEntry = new PojoServiceEntry(serviceDescriptor);
+ break;
+ case alias:
+ serviceTypeEntry = new AliasServiceEntry(serviceDescriptor);
+ break;
+ default:
+ // Add as pojo
+ // Should better throw an exception. (MalformedDescriptor ?)
+ serviceTypeEntry = new PojoServiceEntry(serviceDescriptor);
+ }
+
+ // Create the entry
+ ServiceStartupEntry serviceEntry;
+ switch(serviceDescriptor.getServiceStartKind()) {
+ case STARTUP:
+ serviceEntry = new StartStartupEntry(serviceTypeEntry);
+ break;
+ case LAZY:
+ serviceEntry = new LazyStartupEntry(serviceTypeEntry, this);
+ break;
+ default:
+ // Add as LAZY
+ // Should better throw an exception. (MalformedDescriptor ?)
+ serviceEntry = new LazyStartupEntry(serviceTypeEntry, this);
+ }
+
+ // Add the entry
+ addedServices.put(serviceDescriptor.getKey(), serviceEntry);
+ }
+
+ /**
+ * Add a service. The descriptor will be created.
+ *
+ * @param key
+ * Service key
+ * @param priority
+ * service priority
+ * @param serviceInstance
+ * The instance of the service
+ */
+ public void add(String key, int priority, IService serviceInstance) {
+ add(key, priority, serviceInstance, ServiceStartKind.STARTUP);
+ }
+
+ /**
+ * Add a service. The descriptor will be created.
+ *
+ * @param key
+ * Service key
+ * @param priority
+ * service priority
+ * @param serviceInstance
+ * The instance of the service
+ */
+ public void add(Class<?> key, int priority, IService serviceInstance) {
+ add(key.getName(), priority, serviceInstance, ServiceStartKind.STARTUP);
+ }
+
+ /**
+ * Add a service. The descriptor will be created.
+ *
+ * @param key
+ * Service key
+ * @param priority
+ * service priority
+ * @param serviceInstance
+ * The instance of the service
+ */
+ public void add(String key, int priority, IService serviceInstance, ServiceStartKind startKind) {
+ // Check if the service already exist.
+ ServiceStartupEntry service = addedServices.get(key);
+ if(service != null) {
+ if(service.getDescriptor().getPriority() > priority)
+ return;
+ else if(service.getDescriptor().getPriority() == priority)
+ log.warning("Two services with same priority (" + priority + ") are declared under key '" + service.getDescriptor().getKey() + "'. Keep the first encountered only."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Create descriptor and add service.
+ ServiceDescriptor descriptor = new ServiceDescriptor(key, serviceInstance.getClass().getName(), startKind, priority);
+
+ if(startKind == ServiceStartKind.STARTUP)
+ addedServices.put(key, new StartStartupEntry(new ServiceEntry(descriptor, serviceInstance)));
+ else
+ addedServices.put(key, new LazyStartupEntry(new ServiceEntry(descriptor, serviceInstance), this));
+ }
+
+ /**
+ * Add a service. The descriptor will be created.
+ *
+ * @param key
+ * Service key Class used as key. The classname is used as key.
+ * @param priority
+ * service priority
+ * @param serviceInstance
+ * The instance of the service
+ */
+ public void add(Class<?> key, int priority, IService serviceInstance, ServiceStartKind startKind) {
+
+ add(key.getName(), priority, serviceInstance, startKind);
+ }
+
+ /**
+ * Add an already instanciated pojo (Plain Old Java Object) as Service. The
+ * descriptor will be created. No life cycle methods are called on the
+ * service.
+ *
+ * @param key
+ * Service key
+ * @param priority
+ * service priority
+ * @param serviceInstance
+ * The instance of the service
+ */
+ public void add(Class<?> key, int priority, Object serviceInstance) {
+ add(key, priority, serviceInstance, ServiceStartKind.STARTUP);
+ }
+
+ /**
+ * Add an already instanciated pojo (Plain Old Java Object) as Service. The
+ * descriptor will be created. No life cycle methods are called on the
+ * service.
+ *
+ * @param key
+ * Service key
+ * @param priority
+ * service priority
+ * @param serviceInstance
+ * The instance of the service
+ * @param startKind
+ *
+ */
+ public void add(String key, int priority, Object serviceInstance, ServiceStartKind startKind) {
+ // Check if the service already exist.
+ ServiceStartupEntry service = addedServices.get(key);
+ if(service != null) {
+ if(service.getDescriptor().getPriority() > priority)
+ return;
+ else if(service.getDescriptor().getPriority() == priority)
+ log.warning("Two services with same priority (" + priority + ") are declared under key '" + service.getDescriptor().getKey() + "'. Keep the first encountered only."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Create descriptor and add service.
+ ServiceDescriptor descriptor = new ServiceDescriptor(key, serviceInstance.getClass().getName(), startKind, priority);
+
+ if(startKind == ServiceStartKind.STARTUP)
+ addedServices.put(key, new StartStartupEntry(new PojoServiceEntry(descriptor, serviceInstance)));
+ else
+ addedServices.put(key, new LazyStartupEntry(new PojoServiceEntry(descriptor, serviceInstance), this));
+
+ }
+
+ /**
+ * Add an already instanciated pojo (Plain Old Java Object) as Service. The
+ * descriptor will be created. No life cycle methods are called on the
+ * service.
+ *
+ * @param key
+ * Service key Class used as key. The classname is used as key.
+ * @param priority
+ * service priority
+ * @param serviceInstance
+ * The instance of the service
+ * @param startKind
+ *
+ */
+ public void add(Class<?> key, int priority, Object serviceInstance, ServiceStartKind startKind) {
+
+ add(key.getName(), priority, serviceInstance, startKind);
+ }
+
+ /**
+ * Remove the specified Registry as parent of this registry.
+ * .
+ * @param parentRegistry
+ */
+ public void addParentRegistry(ServicesRegistry parentRegistry) {
+
+ if( parentRegistry == null) {
+ return;
+ }
+ parents.add(parentRegistry);
+ }
+
+ /**
+ *
+ * @param parentRegistry
+ */
+ public void removeParentRegistry(ServicesRegistry parentRegistry) {
+
+ if( parentRegistry == null) {
+ return;
+ }
+ parents.remove(parentRegistry);
+ }
+
+
+ /**
+ * Remove the specified service from the registry.
+ *
+ * @param key
+ */
+ public void remove(ServiceDescriptor serviceDescriptor) throws ServiceException {
+ remove(serviceDescriptor.getKey());
+ }
+
+ /**
+ * Remove the specified service from the registry.
+ *
+ * @param key
+ */
+ public void remove(Object key) throws ServiceException {
+ ServiceStartupEntry service = namedServices.remove(key);
+ if(service == null) {
+ return;
+ }
+
+ // Stop the service
+ service.disposeService();
+ }
+
+ /**
+ * Get the requested service by its key. The key is usually the classname of
+ * the service.
+ *
+ * @param serviceClass
+ * @return
+ * @throws ServiceException
+ * If servive can't be started
+ */
+ public Object getService(Object key) throws ServiceException {
+ ServiceStartupEntry serviceEntry = namedServices.get(key);
+ if(serviceEntry == null) {
+ // Check if we can find it in parents
+ Object service = getServiceFromParents(key);
+ if(service != null) {
+ // Found in parent, return it
+ return service;
+ }
+
+ // Not found in parents. Throw an exception
+ // throw an appropriate exception (If added, say it).
+ serviceEntry = addedServices.get(key);
+ if(serviceEntry != null)
+ throw new BadStateException("Registry should be started before.", serviceEntry.getState(), serviceEntry.getDescriptor()); //$NON-NLS-1$
+ else
+ throw new ServiceNotFoundException("No service registered under '" + key + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return serviceEntry.getServiceInstance();
+ }
+
+ /**
+ * Get the requested service by its class (the service has to be registered
+ * by its class object).
+ *
+ * @param key
+ * The service class.
+ * @return The service.
+ * @throws ServiceException
+ * If service can't be started
+ */
+ @SuppressWarnings("unchecked")
+ public <S> S getService(Class<S> key) throws ServiceException {
+
+ String realKey = key.getName();
+ ServiceStartupEntry serviceEntry = namedServices.get(realKey);
+
+ // Lookup in parents if not found
+ if( serviceEntry == null) {
+
+ // Check if we can find it in parents
+ S service = (S)getServiceFromParents(realKey);
+ if(service != null) {
+ // Found in parent, return it
+ return service;
+ }
+
+ // Not found in parents. Throw an exception
+ // throw an appropriate exception (If added, say it).
+ serviceEntry = addedServices.get(realKey);
+ if(serviceEntry != null)
+ throw new BadStateException("Registry should be started before.", serviceEntry.getState(), serviceEntry.getDescriptor()); //$NON-NLS-1$
+ else
+ throw new ServiceNotFoundException("No service registered under '" + key + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Service found, return it.
+ return (S)serviceEntry.getServiceInstance();
+ }
+
+ /**
+ * Get the requested service by its class (the service has to be registered
+ * by its class object).
+ *
+ * @param key
+ * The service class.
+ * @return The service.
+ * @throws ServiceException
+ * If service can't be started
+ */
+ private Object getServiceFromParents(Object key) throws ServiceException {
+
+ Object foundService;
+
+ for( ServicesRegistry parent : parents) {
+ foundService = parent.getServiceUnchecked(key);
+ // Check if we have found the service
+ if( foundService != null) {
+ // Found, return it
+ return foundService;
+ }
+ }
+ // Not found
+ return null;
+ }
+
+ /**
+ * Get the requested service by its key. The key is usually the classname of
+ * the service.
+ * Return the service, or null if not found.
+ * This is for internal use.
+ *
+ * @param serviceClass
+ * @return The service, or null if not found.
+ * @throws ServiceException
+ * If servive can't be started
+ */
+ protected Object getServiceUnchecked(Object key) throws ServiceException {
+ ServiceStartupEntry service = namedServices.get(key);
+ if(service == null) {
+ return null;
+ }
+
+ return service.getServiceInstance();
+ }
+
+ /**
+ * Try to get the {@link ServiceStartupEntry} of the specified service.
+ * Search in local namedServices.
+ * Also lookup in parents. Return null if not found.
+ * The returned entry should not be modified by caller.
+ *
+ * @param key
+ * @return The requested entry, or null if not found.
+ */
+ protected ServiceStartupEntry getServiceStartupEntry( Object key ) {
+
+ return getServiceStartupEntry(key, true);
+ }
+
+ /**
+ * Try to get the {@link ServiceStartupEntry} of the specified service.
+ * Search in local namedServices.
+ * Also lookup in parents. Return null if not found.
+ * The returned entry should not be modified by caller.
+ *
+ * @param key
+ * @param searchInParent True if we should search in parent, false if search take place in this registry only.
+ * @return The requested entry, or null if not found.
+ */
+ protected ServiceStartupEntry getServiceStartupEntry( Object key, boolean searchInParent ) {
+
+ ServiceStartupEntry service = namedServices.get(key);
+ if( service != null) {
+ return service;
+ }
+
+ // Check in new services
+ service = addedServices.get(key);
+ if( service != null) {
+ return service;
+ }
+
+ if( searchInParent ) {
+ // Lookup in parents
+ for(ServicesRegistry registry : parents) {
+ service = registry.getServiceStartupEntry(key);
+ if( service != null) {
+ return service;
+ }
+ }
+ }
+
+ // Not found
+ return null;
+ }
+
+ /**
+ * Return true if the service is instantiated. Return false otherwise.
+ *
+ * @return
+ */
+ public boolean isStarted(Object key) throws ServiceNotFoundException {
+ return isStarted(key, true);
+ }
+
+ /**
+ * Return true if the service is instantiated. Return false otherwise.
+ *
+ * @return
+ */
+ public boolean isStarted(Object key, boolean searchInParents) throws ServiceNotFoundException {
+ ServiceStartupEntry service = getServiceStartupEntry(key, searchInParents);
+ if(service == null) {
+ throw new ServiceNotFoundException("No service registered under '" + key + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return service.isStarted();
+ }
+
+ /**
+ * Return true if the service is instantiated. Return false otherwise.
+ * The service type is converted to its name, then the method is performed.
+ * @see #isStarted(Class)
+ *
+ * @return
+ */
+ public boolean isStarted(Class<?> serviceType) throws ServiceNotFoundException {
+ return isStarted(serviceType.getName(), true);
+ }
+
+ /**
+ * Return true if the service is instantiated. Return false otherwise.
+ * The service type is converted to its name, then the method is performed.
+ * @see #isStarted(Class)
+ *
+ * @return
+ */
+ public boolean isStarted(Class<?> serviceType, boolean searchInParents) throws ServiceNotFoundException {
+ return isStarted(serviceType.getName(), searchInParents);
+ }
+
+ /**
+ * Return the state of the specified service.
+ *
+ * @return
+ */
+ public ServiceState serviceState(Object key) throws ServiceNotFoundException {
+ return serviceState(key, true);
+ }
+
+ /**
+ * Return the state of the specified service.
+ * @param key
+ * @param searchInParents
+ * @return
+ * @throws ServiceNotFoundException
+ */
+ public ServiceState serviceState(Object key, boolean searchInParents ) throws ServiceNotFoundException {
+ ServiceStartupEntry service = getServiceStartupEntry(key, searchInParents);
+ if(service == null) {
+ throw new ServiceNotFoundException("No service registered under '" + key + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return service.getState();
+ }
+
+ /**
+ * Return the state of the specified service.
+ *
+ * @return
+ */
+ public ServiceState serviceState(Class<?> serviceType) throws ServiceNotFoundException {
+ return serviceState(serviceType.getName(), true);
+ }
+
+ /**
+ * Return the state of the specified service.
+ *
+ * @return
+ */
+ public ServiceState serviceState(Class<?> serviceType, boolean searchInParents) throws ServiceNotFoundException {
+ return serviceState(serviceType.getName(), searchInParents);
+ }
+
+ /**
+ * Start services newly added.
+ * Start all services marked as start = STARTUP.
+ * All services are first created, then initialized and finally
+ * started. If an error occur on a service during one of this step, the
+ * service is removed from the registry and and the error is logged.
+
+ * @throws ServiceMultiException
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ *
+ */
+ public void startNewServices() throws ServiceMultiException {
+ // Build the lookup maps
+ LookupMap localSpace = new LookupMap(addedServices, namedServices);
+ // search space including parents
+ LookupMap fullSpace = new LookupMap(addedServices, namedServices, parents);
+
+ // Check if all dependencies exist.
+ checkDependencies(addedServices.values(), fullSpace);
+
+ // Get all roots : LAZY and START
+ Collection<ServiceStartupEntry> roots = getServiceRoots(addedServices.values(), localSpace);
+ // showServices(" Roots:", roots);
+ // Detect cycles
+ checkCycle(roots, localSpace);
+
+ // Order services in the order we should start them.
+ // Lazy services are taken into account, as they can be in a chain of start.
+ List<ServiceStartupEntry> toStart = buildTopologicalListOfServicesToStart(roots, localSpace);
+
+ // Retain only services with startupkind == START
+ //
+ roots = retainsToStartServices(roots);
+
+ if(Activator.log.isDebugEnabled()) {
+ showServices(" Services to start:", toStart);
+ }
+
+ // Create an object to collect errors if any.
+ ServiceMultiException errors = new ServiceMultiException();
+
+ createServices(toStart, errors);
+ // Register all new services : lazy and start
+ registerServices(addedServices.values());
+ initServices(toStart, errors);
+ startServices(toStart, errors);
+
+ // Report errors if any
+ if(errors.getExceptions().size() > 0)
+ throw errors;
+
+
+ }
+
+ /**
+ * Start the registry. Start all services marked as start = STARTUP are
+ * started. All services are first created, then initialized and finally
+ * started. If an error occur on a service during one of this step, the
+ * service is removed from the registry and and the error is logged.
+ *
+ * @throws ServiceMultiException
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ *
+ * @deprecated Use {@link #startNewServices()}
+ */
+ protected void startRegistry() throws ServiceMultiException {
+
+ startNewServices();
+ }
+
+ /**
+ * Start the specified services, and their required services. The specifies
+ * services should be in the addServices or already registered. Start all
+ * services marked as start = STARTUP . All eligible services are first
+ * created, then initialized and finally started. If an error occur on a
+ * service during one of this step, the service is removed from the registry
+ * and and the error is logged.
+ *
+ * @param serviceKeys
+ * Keys of services to start.
+ * @throws ServiceMultiException
+ * @throws ServiceNotFoundException
+ * If a service can't be retrieved by its key.
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ */
+ public void startServices(List<String> serviceKeys) throws ServiceMultiException, ServiceNotFoundException {
+
+ // Build the lookup maps
+ LookupMap map = new LookupMap(addedServices, namedServices);
+
+ // Get the services
+ List<ServiceStartupEntry> services = keysToServices(serviceKeys, map);
+
+ // Start them
+ startServices(services, map);
+ }
+
+ /**
+ * Same as {@link #startServices(List)}, but with an array as input.
+ *
+ * @see #startServices(List)
+ *
+ * @param serviceKeys
+ * Keys of services to start.
+ * @throws ServiceMultiException
+ * @throws ServiceNotFoundException
+ * If a service can't be retrieved by its key.
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ */
+ public void startServices(String... serviceKeys) throws ServiceMultiException, ServiceNotFoundException {
+
+ List<String> serviceKeysList = Arrays.asList(serviceKeys);
+ startServices(serviceKeysList);
+ }
+
+ /**
+ * Start the specified services, and their required services. The specifies
+ * services should be in the addServices or already registered. Start all
+ * services marked as start = STARTUP . All eligible services are first
+ * created, then initialized and finally started. If an error occur on a
+ * service during one of this step, the service is removed from the registry
+ * and and the error is logged.
+ *
+ * @param serviceKeys
+ * Keys of services to start. Keys will be translated to the
+ * classname.
+ * @throws ServiceMultiException
+ * @throws ServiceNotFoundException
+ * If a service can't be retrieved by its key.
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ */
+ public void startServicesByClassKeys(List<Class<?>> serviceKeys) throws ServiceMultiException, ServiceNotFoundException {
+
+ // Build the lookup maps
+ LookupMap map = new LookupMap(addedServices, namedServices);
+
+ // Get the services
+ List<ServiceStartupEntry> services = classKeysToServices(serviceKeys, map);
+
+ // Start them
+ startServices(services, map);
+ }
+
+ /**
+ * Same as {@link #startServicesByClassKeys(List)}, but with an array as
+ * input.
+ *
+ * @see #startServices(List)
+ *
+ * @param serviceKeys
+ * Keys of services to start.
+ * @throws ServiceMultiException
+ * @throws ServiceNotFoundException
+ * If a service can't be retrieved by its key.
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ */
+ public void startServicesByClassKeys(Class<?>... serviceKeys) throws ServiceMultiException, ServiceNotFoundException {
+
+ List<Class<?>> serviceKeysList = Arrays.asList(serviceKeys);
+ startServicesByClassKeys(serviceKeysList);
+ }
+
+ /**
+ * Start the specified services, and their required services. The specifies
+ * services should be in the specified map. The map is also used to resolves
+ * dependencies. Start all services marked as start = STARTUP . All eligible
+ * services are first created, then initialized and finally started. If an
+ * error occur on a service during one of this step, the service is removed
+ * from the registry and and the error is logged.
+ *
+ * @param services
+ * Services to start
+ * @param map
+ * a table of (key, service) used to get a service by its key.
+ * @throws ServiceMultiException
+ * If a service can't be started.
+ */
+ private void startServices(List<ServiceStartupEntry> services, LookupMap map) throws ServiceMultiException {
+ // Check if all dependencies exist.
+ checkDependencies(services, map);
+
+ // Get all roots : LAZY and START
+ Collection<ServiceStartupEntry> roots = getServiceRoots(services, map);
+ if(Activator.log.isDebugEnabled()) {
+ showServices(" Roots:", roots);
+ }
+ // Detect cycles
+ checkCycle(roots, map);
+ // Retain only services with startupkind == START and state ==
+ // REGISTERED
+ roots = retainsToStartServices(roots);
+ //
+ List<ServiceStartupEntry> toStart = buildTopologicalListOfServicesToStart(roots, map);
+
+ // Remove already started services
+ toStart = retainsToStartServices(toStart);
+
+ // if( log.isLoggable(Level.FINE))
+ // {
+ showServices(" Services to start:", toStart);
+ // }
+
+ // Create an object to collect errors if any.
+ ServiceMultiException errors = new ServiceMultiException();
+
+ createServices(toStart, errors);
+ // Register all started services
+ registerServices(toStart);
+ initServices(toStart, errors);
+ startServices(toStart, errors);
+
+ // Report errors if any
+ if(errors.getExceptions().size() > 0)
+ throw errors;
+ }
+
+ /**
+ * Return a list of services from a list of services keys.
+ *
+ * @param serviceKeys
+ * @param map
+ * @return
+ * @throws ServiceNotFoundException
+ * If a service can't be retrieved by its key.
+ */
+ private List<ServiceStartupEntry> keysToServices(List<String> serviceKeys, LookupMap map) throws ServiceNotFoundException {
+
+ List<ServiceStartupEntry> result = new ArrayList<ServiceStartupEntry>(serviceKeys.size());
+
+ for(String key : serviceKeys) {
+ result.add(map.getChecked(key));
+ }
+ return result;
+ }
+
+ /**
+ * Return a list of services from a list of services keys.
+ *
+ * @param serviceKeys
+ * @param map
+ * @return
+ * @throws ServiceNotFoundException
+ * If a service can't be retrieved by its key.
+ */
+ private List<ServiceStartupEntry> classKeysToServices(List<Class<?>> serviceKeys, LookupMap map) throws ServiceNotFoundException {
+
+ List<ServiceStartupEntry> result = new ArrayList<ServiceStartupEntry>(serviceKeys.size());
+
+ for(Class<?> key : serviceKeys) {
+ result.add(map.getChecked(key.getName()));
+ }
+ return result;
+ }
+
+ /**
+ * Print the services. For debug purpose
+ *
+ * @param roots
+ */
+ private void showServices(String message, Collection<ServiceStartupEntry> roots) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("--------------------------\n");
+ buffer.append(message);
+ buffer.append("\n");
+ for(ServiceStartupEntry service : roots) {
+ buffer.append(" ");
+ buffer.append(service.getDescriptor().toString());
+ buffer.append("\n");
+ }
+ buffer.append("--------- done -----------\n");
+ Activator.log.debug(buffer.toString());
+ }
+
+ /**
+ * Check if all dependencies exist. Throw an error if a declared dependency
+ * has no corresponding service.
+ *
+ * @param services
+ * Services to check
+ * @param map
+ * Map of services by keys.
+ * @throws ServiceMultiException
+ */
+ private void checkDependencies(Collection<ServiceStartupEntry> services, LookupMap map) throws ServiceMultiException {
+
+ ServiceMultiException errors = new ServiceMultiException();
+
+ // Walk each service and check if its required services exist.
+ for(ServiceStartupEntry service : services) {
+ ServiceDescriptor desc = service.getDescriptor();
+
+ // Check each required service
+ for(String key : desc.getRequiredServiceKeys()) {
+
+ // Check if service can be found
+ try {
+ map.getChecked(key);
+ } catch (ServiceNotFoundException e) {
+ errors.addException(desc.getKey(), e);
+ }
+ }
+ }
+
+ // Throw errors if any
+ if(errors.getExceptions().size() > 0)
+ throw errors;
+ }
+
+ /**
+ * Retains only the services that should be started. Retains only services
+ * with startupkind = START and state == REGISTERED
+ *
+ * @param services
+ * Collection to filter
+ * @return a new Collection containing the services to start.
+ */
+ private List<ServiceStartupEntry> retainsToStartServices(Collection<ServiceStartupEntry> services) {
+
+ List<ServiceStartupEntry> result = new ArrayList<ServiceStartupEntry>();
+ for(ServiceStartupEntry service : services) {
+ ServiceDescriptor desc = service.getDescriptor();
+ if(service.getState() == ServiceState.registered && desc.isStartAtStartup()) {
+ result.add(service);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Check for cycles. Throws an exception if a cycle is discovered. Each root
+ * is checked to see if it contains a cycle.
+ *
+ * @param roots
+ * @param map
+ */
+ private void checkCycle(Collection<ServiceStartupEntry> roots, LookupMap map) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Build a list of services to start, in the topological order (right
+ * order). The required services are placed before the dependent services in
+ * the list. Services already started are disguarded.
+ *
+ * @param roots
+ * @param map
+ * Map used to resolve the entry by their key.
+ * @return
+ */
+ private List<ServiceStartupEntry> buildTopologicalListOfServicesToStart(Collection<ServiceStartupEntry> roots, LookupMap map) {
+
+ List<ServiceStartupEntry> result = new ArrayList<ServiceStartupEntry>();
+
+ // Each root represent a graph. Walk the root and its child in the list,
+ // in the right order.
+ for(ServiceStartupEntry root : roots) {
+ walkGraphDepthFirst(result, root, map);
+ }
+
+ return result;
+ }
+
+ /**
+ * Add recursively the provided node, and then its direct children.
+ *
+ * @param result
+ * The list where the node are added
+ * @param node
+ * The node to add
+ * @param map
+ */
+ private void walkGraphDepthFirst(List<ServiceStartupEntry> result, ServiceStartupEntry node, LookupMap map) {
+
+ // Do not add already added or started node.
+ if(result.contains(node) || node.isStarted())
+ return;
+
+ // add direct child
+ for(String serviceKey : node.getDescriptor().getRequiredServiceKeys()) {
+ try {
+ ServiceStartupEntry child = map.getChecked(serviceKey);
+ walkGraphDepthFirst(result, child, map);
+ } catch (ServiceNotFoundException e) {
+ // Do nothing, we have already reported the problems with
+ // checkServices;
+ }
+ }
+
+ // Now add the node
+ result.add(node);
+ }
+
+ /**
+ * Create a List of the root services. The roots are services that are not
+ * required by any service.
+ *
+ * @param addedServices
+ * A collection from which roots are required. The collection is
+ * unmodified.
+ * @param map
+ * @return
+ */
+ private Collection<ServiceStartupEntry> getServiceRoots(Collection<ServiceStartupEntry> addedServices, LookupMap keyServiceMap) {
+
+ // Create a copy of the list of services
+ Collection<ServiceStartupEntry> services = new ArrayList<ServiceStartupEntry>(addedServices);
+
+ List<ServiceStartupEntry> allRequired = new ArrayList<ServiceStartupEntry>();
+
+ // The roots are services that are not required by any service.
+ // Build a list of the services required by all other services.
+ for(ServiceStartupEntry service : services) {
+ // Add each child to the list of required
+ for(String serviceKey : service.getDescriptor().getRequiredServiceKeys()) {
+ try {
+
+ ServiceStartupEntry child = keyServiceMap.getChecked(serviceKey);
+ allRequired.add(child);
+ } catch (ServiceNotFoundException e) {
+ // Do nothing, we have already reported the problems with
+ // checkServices;
+ }
+ }
+
+ }
+
+ // Roots are those that are not required.
+ // So it is the original list minus the required.
+ services.removeAll(allRequired);
+
+ return services;
+ }
+
+ /**
+ * Dispose all services for this registry and its parents.
+ *
+ * @throws ServiceMultiException
+ */
+ public void disposeRegistry() throws ServiceMultiException {
+
+ disposeRegistry(true);
+ }
+
+ /**
+ * Dispose all services, and parent registries if any.
+ *
+ * @throws ServiceMultiException
+ */
+ public void disposeRegistry(boolean isRecursive) throws ServiceMultiException {
+
+ // List of keys of service in error.
+ ServiceMultiException errors = new ServiceMultiException();
+ disposeRegistry(errors, isRecursive);
+ // Report errors if any
+ if(errors.getExceptions().size() > 0)
+ throw errors;
+ }
+
+ /**
+ * Dispose all services, and parent registries if any.
+ *
+ * @throws ServiceMultiException
+ */
+ protected void disposeRegistry(ServiceMultiException errors, boolean isRecursive) throws ServiceMultiException {
+
+ // List of keys of service in error.
+ disposeServices(namedServices.values(), errors);
+ disposeServices(anonymousServices, errors);
+
+ // Clean up properties to help GC
+ addedServices.clear();
+ addedServices = null;
+ anonymousServices.clear();
+ anonymousServices = null;
+ namedServices.clear();
+ namedServices = null;
+
+ // Do parents
+ if( isRecursive ) {
+ for( ServicesRegistry parent : parents) {
+ parent.disposeRegistry( errors, true);
+ }
+ }
+ }
+
+ /**
+ * Create all services provided in the list
+ *
+ * @param toStart
+ * List of services to create.
+ * @param errors
+ * Exception to collect errors.
+ *
+ * @throws ServiceMultiException
+ * If an error occure during the creation
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ */
+ private void createServices(List<ServiceStartupEntry> toStart, ServiceMultiException errors) throws ServiceMultiException {
+
+ // Loop on all services
+ for(ServiceStartupEntry serviceEntry : toStart) {
+ try {
+
+ serviceEntry.createService();
+ } catch (ServiceException e) {
+ log.log(Level.SEVERE, "Can't create service '" + serviceEntry + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
+
+ errors.addException(serviceEntry.getDescriptor().getKey(), e);
+ }
+ }
+
+ }
+
+ /**
+ * Register all services provided in the list. After this operation,
+ * services are available thru {@link #getService(Class)}.
+ *
+ * @param toStart
+ * List of services to register.
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ */
+ private void registerServices(Collection<ServiceStartupEntry> toStart) {
+
+ // Loop on all services
+ for(ServiceStartupEntry serviceEntry : toStart) {
+ ServiceDescriptor desc = serviceEntry.getDescriptor();
+ if(desc.isAnonymous()) {
+ anonymousServices.add(serviceEntry);
+ } else {
+ namedServices.put(desc.getKey(), serviceEntry);
+ }
+ }
+ }
+
+ /**
+ * Init all services provided in the list
+ *
+ * @param toStart
+ * List of services to init.
+ * @param errors
+ *
+ * @throws ServiceMultiException
+ * If an error occure during the process
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ */
+ private void initServices(List<ServiceStartupEntry> toStart, ServiceMultiException errors) throws ServiceMultiException {
+
+ // Loop on all services
+ for(ServiceStartupEntry serviceEntry : toStart) {
+ try {
+
+ serviceEntry.initService(this);
+ } catch (ServiceException e) {
+ log.log(Level.SEVERE, "Can't initialize service '" + serviceEntry + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
+ errors.addException(serviceEntry.getDescriptor().getKey(), e);
+ }
+ }
+
+ }
+
+ /**
+ * Init all services provided in the list
+ *
+ * @param toStart
+ * List of services to init.
+ * @param errors
+ *
+ * @throws ServiceMultiException
+ * If an error occure during the process
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ */
+ private void startServices(List<ServiceStartupEntry> toStart, ServiceMultiException errors) throws ServiceMultiException {
+
+ // Loop on all services
+ for(ServiceStartupEntry serviceEntry : toStart) {
+ try {
+
+ serviceEntry.startService();
+ } catch (ServiceException e) {
+ log.log(Level.SEVERE, "Can't start service '" + serviceEntry + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
+
+ errors.addException(serviceEntry.getDescriptor().getKey(), e);
+ }
+ }
+
+ }
+
+ /**
+ * Dispose all started services.
+ * Services are disposed in creation reverse order
+ *
+ * @throws ServiceMultiException
+ *
+ * @throws ServiceException
+ * If a service can't be started.
+ */
+ private void disposeServices(Collection<ServiceStartupEntry> services, ServiceMultiException errors) {
+
+ // Dispose services
+ for(ServiceStartupEntry serviceEntry : services) {
+ try {
+ serviceEntry.disposeService();
+ } catch (ServiceException e) {
+ log.log(Level.SEVERE, "Can't dispose service '" + serviceEntry.getDescriptor().getKey() + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
+ errors.addException(serviceEntry.getDescriptor(), e);
+ }
+ }
+ }
+
+ /**
+ * This class represents a union of two maps of <String,
+ * ServiceStartupEntry>. It provide specific methods to retrieve a {@link ServiceStartupEntry} by its key.
+ * <br>
+ * This class is used to lookup {@link ServiceStartupEntry} in multiple namespaces (2 maps, and then registries).
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+ private class LookupMap {
+
+ Map<String, ServiceStartupEntry> map1;
+
+ Map<String, ServiceStartupEntry> map2;
+
+ // additional service registries into which we should search
+ List<ServicesRegistry> registries;
+
+ /**
+ *
+ * Constructor. Build a union of two maps.
+ *
+ * @param map1
+ * @param map2
+ */
+ public LookupMap(Map<String, ServiceStartupEntry> map1, Map<String, ServiceStartupEntry> map2) {
+ this.map1 = map1;
+ this.map2 = map2;
+ }
+
+ public LookupMap(Map<String, ServiceStartupEntry> space1, Map<String, ServiceStartupEntry> space2, List<ServicesRegistry> registries) {
+ this( space1, space2);
+ this.registries = registries;
+ }
+
+ /**
+ *
+ * Constructor. Build a union of one map (sic).
+ *
+ * @param map
+ */
+ @SuppressWarnings("unused")
+ public LookupMap(Map<String, ServiceStartupEntry> map) {
+ this(map, null);
+ }
+
+ /**
+ * Get a service by its key.
+ *
+ * @param key
+ * @return the service or null if not found.
+ */
+ @SuppressWarnings("unused")
+ public ServiceStartupEntry get(String key) {
+
+ ServiceStartupEntry res = map1.get(key);
+ if(res != null)
+ return res;
+ if(map2 != null) {
+ res = map2.get(key);
+ }
+ if( res == null && registries != null) {
+ // lookup in registries
+ res = getFromRegistries(key);
+ }
+
+ return res;
+ }
+
+ /**
+ * Get a service by its key.
+ *
+ * @param key
+ * @return The requested service.
+ * @throws ServiceNotFoundException
+ * if the service can't be found.
+ */
+ public ServiceStartupEntry getChecked(String key) throws ServiceNotFoundException {
+
+ ServiceStartupEntry res = map1.get(key);
+ if(res != null)
+ return res;
+ if(map2 != null)
+ res = map2.get(key);
+ if( res == null && registries != null) {
+ // lookup in registries
+ res = getFromRegistries(key);
+ }
+ if(res != null)
+ return res;
+
+ throw new ServiceNotFoundException("No service found under key '" + key.toString() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Try to get the entry from the registries.
+ * @param key
+ * @return
+ */
+ private ServiceStartupEntry getFromRegistries(String key) {
+
+ ServiceStartupEntry service;
+ // Lookup in parents
+ for(ServicesRegistry registry : registries) {
+ service = registry.getServiceStartupEntry(key);
+ if( service != null) {
+ return service;
+ }
+ }
+
+ return null;
+ }
+ }
+
+}