Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2018-11-13 09:05:05 -0500
committerPatrick Tessier2018-11-19 08:01:52 -0500
commiteaee6e41760014b48b0795fef6941642d8d1a753 (patch)
tree96af29292a0ffc34233618145903cf447d09c52a
parente077fba586fdbe9b10cf8f63940b86911dd47262 (diff)
downloadorg.eclipse.papyrus-eaee6e41760014b48b0795fef6941642d8d1a753.tar.gz
org.eclipse.papyrus-eaee6e41760014b48b0795fef6941642d8d1a753.tar.xz
org.eclipse.papyrus-eaee6e41760014b48b0795fef6941642d8d1a753.zip
Bug 541087: [Profile] ProfileServiceDefinition generates an NPE when we create a new model
Change-Id: I6a99b6d283622445a878e2b48ad75636389a0210 Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml9
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/ProfileDefinitionService.java87
2 files changed, 72 insertions, 24 deletions
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml
index 0544c78bff3..78dd48f7c21 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/pom.xml
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.eclipse.papyrus</groupId>
- <artifactId>org.eclipse.papyrus.uml-tools</artifactId>
- <version>0.0.1-SNAPSHOT</version>
+ <groupId>org.eclipse.papyrus</groupId>
+ <artifactId>org.eclipse.papyrus.uml-tools</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.tools</artifactId>
<version>4.1.0-SNAPSHOT</version>
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/ProfileDefinitionService.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/ProfileDefinitionService.java
index 886d1270243..804644265d8 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/ProfileDefinitionService.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/service/ProfileDefinitionService.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* Copyright (c) 2018 CEA LIST.
- *
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -10,6 +10,7 @@
*
* Contributors:
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ * Vincent LORENZO (CEA-LIST) vincent.lorenzo@cea.fr - bug 541087
*****************************************************************************/
package org.eclipse.papyrus.uml.tools.service;
@@ -17,8 +18,12 @@ package org.eclipse.papyrus.uml.tools.service;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.NotFoundException;
import org.eclipse.papyrus.infra.core.services.IService;
@@ -33,12 +38,13 @@ import org.eclipse.papyrus.uml.tools.model.ExtendedUmlModel;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants;
import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.util.UMLUtil;
/**
* Implementation of Profile Definition service.
- *
+ *
* @author Gabriel Pascual
* @since 4.1
*/
@@ -49,7 +55,7 @@ public class ProfileDefinitionService implements IService, IProfileDefinitionSer
private ModelSet modelSet = null;
/** The map instance. */
- private static Map<Profile, IPapyrusMarker> mapInstance = new HashMap<Profile, IPapyrusMarker>();
+ private static Map<Profile, IPapyrusMarker> mapInstance = new HashMap<>();
/**
* Constructor.
@@ -79,36 +85,77 @@ public class ProfileDefinitionService implements IService, IProfileDefinitionSer
@Override
public void startService() throws ServiceException {
- UmlModel umlModel = (UmlModel) modelSet.getModel(ExtendedUmlModel.MODEL_ID);
+ final UmlModel umlModel = (UmlModel) modelSet.getModel(ExtendedUmlModel.MODEL_ID);
try {
- EObject rootElement = umlModel.lookupRoot();
-
-
- if (rootElement instanceof Profile) {
- EAnnotation umlAnnotation = ((Profile) rootElement).getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI);
- if (null != umlAnnotation && !umlAnnotation.getEAnnotations().isEmpty()) {
- EAnnotation emptyAnnotation = umlAnnotation.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
- if (null != emptyAnnotation) {
- PapyrusDefinitionAnnotation parsedAnnotation = PapyrusDefinitionAnnotation.parseEAnnotation(emptyAnnotation);
- if (PapyrusDefinitionAnnotation.UNDEFINED_ANNOTATION.equals(parsedAnnotation)) {
- DecorationService decorationService = ServiceUtilsForEObject.getInstance().getService(DecorationService.class, rootElement);
- decorationService.addDecoration(getMarker((Profile) rootElement), rootElement);
+ if (null != umlModel.getResource() && umlModel.getResource().getContents().isEmpty()) {
+ final Resource res = umlModel.getResource();
+ final Adapter waitingForRootAdapter = new AdapterImpl() {
+
+ /**
+ * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param msg
+ */
+ @Override
+ public void notifyChanged(final Notification msg) {
+ if (msg.getNewValue() instanceof Element && Notification.ADD == msg.getEventType()) {
+ // it seems we add a root to the resource
+ // but we check more
+ if (res.getContents().size() > 0) {
+ try {
+ addRootProfileDecorationIfRequired(umlModel);
+ } catch (NotFoundException | ServiceException e) {
+ Activator.log.error(e);
+ } finally {
+ res.eAdapters().remove(this);
+ }
+ }
}
}
+ };
- }
+ res.eAdapters().add(waitingForRootAdapter);
+
+ } else {
+
+ addRootProfileDecorationIfRequired(umlModel);
}
+
} catch (NotFoundException e) {
Activator.log.error(e);
} catch (ServiceException e) {
Activator.log.error(e);
}
+ }
+ /**
+ *
+ * @param umlModel
+ * the umlModel object
+ * @throws NotFoundException
+ * @throws ServiceException
+ */
+ private final void addRootProfileDecorationIfRequired(final UmlModel umlModel) throws NotFoundException, ServiceException {
+ final EObject rootElement = umlModel.lookupRoot();
+ if (rootElement instanceof Profile) {
+ EAnnotation umlAnnotation = ((Profile) rootElement).getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI);
+ if (null != umlAnnotation && !umlAnnotation.getEAnnotations().isEmpty()) {
+ EAnnotation emptyAnnotation = umlAnnotation.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ if (null != emptyAnnotation) {
+ PapyrusDefinitionAnnotation parsedAnnotation = PapyrusDefinitionAnnotation.parseEAnnotation(emptyAnnotation);
+ if (PapyrusDefinitionAnnotation.UNDEFINED_ANNOTATION.equals(parsedAnnotation)) {
+ DecorationService decorationService = ServiceUtilsForEObject.getInstance().getService(DecorationService.class, rootElement);
+ decorationService.addDecoration(getMarker((Profile) rootElement), rootElement);
+ }
+ }
-
+ }
+ }
}
+
+
/**
* @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
*
@@ -123,7 +170,7 @@ public class ProfileDefinitionService implements IService, IProfileDefinitionSer
/**
* {@inheritDoc}
- *
+ *
* @see org.eclipse.papyrus.uml.tools.service.IProfileDefinitionService#getMarker(org.eclipse.uml2.uml.Profile)
*
* @param profile
@@ -144,7 +191,7 @@ public class ProfileDefinitionService implements IService, IProfileDefinitionSer
/**
* {@inheritDoc }
- *
+ *
* @see org.eclipse.papyrus.uml.tools.service.IProfileDefinitionService#disposeMarker(org.eclipse.uml2.uml.Profile)
*
* @param profile

Back to the top