Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2013-02-22 17:19:35 +0000
committercletavernie2013-02-22 17:19:35 +0000
commitc5fa6c6d3fd2e03a8e34580a56030dd5c83f3267 (patch)
tree9baa7300ee7a5dbf5ce74f8d101f78d257bbc4d0
parent6d34623b466243192d0e495ce48d6b44f9533bb6 (diff)
downloadorg.eclipse.papyrus-c5fa6c6d3fd2e03a8e34580a56030dd5c83f3267.tar.gz
org.eclipse.papyrus-c5fa6c6d3fd2e03a8e34580a56030dd5c83f3267.tar.xz
org.eclipse.papyrus-c5fa6c6d3fd2e03a8e34580a56030dd5c83f3267.zip
375214: org.eclipse.emf.ecore.xmi.DanglingHREFException must be handeled during save in a controlled manner
https://bugs.eclipse.org/bugs/show_bug.cgi?id=375214 400825: [Editor] Diagrams of models with filenames containing characters with accents cannot be opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=400825
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java1
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java55
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModelWithSharedResource.java28
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java24
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/notation/NotationModel.java11
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java13
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java16
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.history/src/org/eclipse/papyrus/infra/services/controlmode/history/HistoryModel.java1
-rw-r--r--plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/EMFFacetNattableModel.java8
-rw-r--r--plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/PapyrusNattableModel.java8
10 files changed, 113 insertions, 52 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java
index 8bc825c0d91..1e262f2f7b4 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java
@@ -554,6 +554,7 @@ public class CoreMultiDiagramEditor extends AbstractMultiPageSashEditor implemen
}
protected void warnUser(ModelMultiException e) {
+ Activator.log.error(e);
MessageDialog.openError(getSite().getShell(), "Error", String.format("Your model is corrupted, invalid links have been found :\n"
+ "%s"
+ "It is recommended to fix it before editing it", e.getMessage()));
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java
index d4ae1f9dc34..e11add50846 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractBaseModel.java
@@ -4,6 +4,8 @@
package org.eclipse.papyrus.infra.core.resource;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
@@ -22,6 +24,8 @@ import org.eclipse.emf.ecore.xmi.XMIResource;
*/
public abstract class AbstractBaseModel implements IModel {
+ public static final String ENCODING = "UTF-8"; //$NON-NLS-1$
+
/**
* The associated ModelManager.
*/
@@ -118,6 +122,14 @@ public abstract class AbstractBaseModel implements IModel {
// Create Resource of appropriate type
resource = getModelManager().createResource(resourceURI);
+ configureResource(resource);
+ }
+
+ protected void configureResource(Resource resource) {
+ if(resource instanceof XMIResource) {
+ ((XMIResource)resource).getDefaultSaveOptions().putAll(getSaveOptions());
+ ((XMIResource)resource).setEncoding(ENCODING);
+ }
}
/**
@@ -151,30 +163,26 @@ public abstract class AbstractBaseModel implements IModel {
* @param fullPathWithoutExtension
*/
public void loadModel(IPath fullPathWithoutExtension) {
-
// Compute model URI
- RuntimeException error = null ;
+ RuntimeException error = null;
resourceURI = getPlatformURI(fullPathWithoutExtension.addFileExtension(getModelFileExtension()));
// Create Resource of appropriate type
- try{
+ try {
resource = modelSet.getResource(resourceURI, true);
- }
- catch (WrappedException e){
- if (ModelUtils.isDegradedModeAllowed(e.getCause())){
+ } catch (WrappedException e) {
+ if(ModelUtils.isDegradedModeAllowed(e.getCause())) {
// only this case is managed in degraded mode
resource = modelSet.getResource(resourceURI, false);
}
- error = e ;
- }
- //see bug 397987: [Core][Save] The referenced plugin models are saved using relative path
- if(resource instanceof XMIResource){
- ((XMIResource) resource).getDefaultSaveOptions().put(XMIResource.OPTION_URI_HANDLER, new org.eclipse.emf.ecore.xmi.impl.URIHandlerImpl.PlatformSchemeAware());
+ error = e;
}
+
+ configureResource(resource);
// call registered snippets
snippets.performStart(this);
- if (error != null){
- throw error ;
+ if(error != null) {
+ throw error;
}
}
@@ -195,8 +203,7 @@ public abstract class AbstractBaseModel implements IModel {
*
*/
public void saveModel() throws IOException {
- if (!getModelManager().getTransactionalEditingDomain().isReadOnly(resource)
- && !ModelUtils.resourceFailedOnLoad(resource)) {
+ if(!getModelManager().getTransactionalEditingDomain().isReadOnly(resource) && !ModelUtils.resourceFailedOnLoad(resource)) {
resource.save(null);
}
}
@@ -240,4 +247,22 @@ public abstract class AbstractBaseModel implements IModel {
snippets.add(snippet);
}
+ protected Map<Object, Object> getSaveOptions() {
+ Map<Object, Object> saveOptions = new HashMap<Object, Object>();
+
+ // default save options.
+ saveOptions.put(XMIResource.OPTION_DECLARE_XML, Boolean.TRUE);
+ saveOptions.put(XMIResource.OPTION_PROCESS_DANGLING_HREF, XMIResource.OPTION_PROCESS_DANGLING_HREF_DISCARD);
+ saveOptions.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
+ saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
+ saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE);
+ saveOptions.put(XMIResource.OPTION_SKIP_ESCAPE_URI, Boolean.FALSE);
+ saveOptions.put(XMIResource.OPTION_ENCODING, "UTF-8");
+
+ //see bug 397987: [Core][Save] The referenced plugin models are saved using relative path
+ saveOptions.put(XMIResource.OPTION_URI_HANDLER, new org.eclipse.emf.ecore.xmi.impl.URIHandlerImpl.PlatformSchemeAware());
+
+ return saveOptions;
+ }
+
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModelWithSharedResource.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModelWithSharedResource.java
index 281c63ece7d..2720e605f06 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModelWithSharedResource.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModelWithSharedResource.java
@@ -5,7 +5,9 @@ package org.eclipse.papyrus.infra.core.resource;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.ecore.EObject;
@@ -66,9 +68,12 @@ public abstract class AbstractModelWithSharedResource<T extends EObject> extends
// Look for the resource
lookupResource(fullPathWithoutExtension);
+
// Check if model is loaded.
- if(resourceIsSet())
+ if(resourceIsSet()) {
+ configureResource(resource);
return;
+ }
// model is not loaded, do it.
super.loadModel(fullPathWithoutExtension);
}
@@ -85,9 +90,12 @@ public abstract class AbstractModelWithSharedResource<T extends EObject> extends
// Look for the resource
lookupResource(fullPath);
+
// Check if model is loaded.
- if(resourceIsSet())
+ if(resourceIsSet()) {
+ configureResource(resource);
return;
+ }
// model is not loaded, do it.
super.createModel(fullPath);
}
@@ -118,8 +126,9 @@ public abstract class AbstractModelWithSharedResource<T extends EObject> extends
public void saveModel() throws IOException {
// Do nothing if we are a slave
- if(modelKind == ModelKind.slave)
+ if(modelKind == ModelKind.slave) {
return;
+ }
// Do the save
super.saveModel();
@@ -157,8 +166,9 @@ public abstract class AbstractModelWithSharedResource<T extends EObject> extends
List<T> roots = new ArrayList<T>();
for(EObject object : getResource().getContents()) {
- if(isModelRoot(object))
+ if(isModelRoot(object)) {
roots.add((T)object);
+ }
}
return roots;
@@ -181,4 +191,14 @@ public abstract class AbstractModelWithSharedResource<T extends EObject> extends
public void addModelRoot(T root) {
getResource().getContents().add(root);
}
+
+ @Override
+ protected Map<Object, Object> getSaveOptions() {
+ if(modelKind == ModelKind.master) {
+ return super.getSaveOptions();
+ } else {
+ return Collections.emptyMap();
+ }
+ }
+
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
index e47242ab6fa..4bf20569443 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
@@ -33,10 +33,12 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.EditingDomainManager;
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
+import org.eclipse.papyrus.infra.core.Activator;
import org.eclipse.papyrus.infra.core.resource.additional.AdditionalResourcesModel;
/**
@@ -93,8 +95,15 @@ public class ModelSet extends ResourceSetImpl {
public ModelSet() {
registerModel(additional);
this.setURIResourceMap(new HashMap<URI, Resource>());
- getLoadOptions().put(XMLResource.OPTION_DEFER_ATTACHMENT, true);
- getLoadOptions().put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
+ }
+
+ @Override
+ public Map<Object, Object> getLoadOptions() {
+ Map<Object, Object> loadOptions = super.getLoadOptions();
+ loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT, true);
+ loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
+ loadOptions.put(XMIResource.OPTION_LAX_FEATURE_PROCESSING, Boolean.TRUE);
+ return loadOptions;
}
/**
@@ -457,9 +466,14 @@ public class ModelSet extends ResourceSetImpl {
try {
// Walk all registered models
for(IModel model : modelList) {
- if(!(model instanceof AdditionalResourcesModel)) {
- model.saveModel();
- monitor.worked(1);
+ try {
+ if(!(model instanceof AdditionalResourcesModel)) {
+ model.saveModel();
+ monitor.worked(1);
+ }
+ } catch (Exception ex) {
+ //TODO: What happens when a save fails? Most of the time, it can be ignored (dangling href, ...)
+ Activator.log.error(ex);
}
}
additional.saveModel();
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/notation/NotationModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/notation/NotationModel.java
index c5a94a17c9c..62d2ad25f1f 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/notation/NotationModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/notation/NotationModel.java
@@ -6,7 +6,6 @@ package org.eclipse.papyrus.infra.core.resource.notation;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.core.resource.AbstractBaseModel;
import org.eclipse.papyrus.infra.core.resource.IModel;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
/**
* @author dumoulin
@@ -33,16 +32,6 @@ public class NotationModel extends AbstractBaseModel implements IModel {
}
- // Initialize stuff in the model.
- @Override
- public void init(ModelSet modelManager) {
- super.init(modelManager);
- // Specify the factory to use to create the resource.
- // GMFResourceFactory gmfFactory = new GMFResourceFactory();
- // getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().put(NOTATION_FILE_EXTENSION, gmfFactory);
-
- }
-
/**
* Get the file extension used for this model.
*
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java
index 572648401bf..994e4a145ca 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java
@@ -3,6 +3,9 @@
*/
package org.eclipse.papyrus.infra.core.resource.sasheditor;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.papyrus.infra.core.resource.AbstractBaseModel;
import org.eclipse.papyrus.infra.core.resource.IModel;
@@ -51,4 +54,14 @@ public class DiModel extends AbstractBaseModel implements IModel {
return MODEL_FILE_EXTENSION;
}
+ @Override
+ protected Map<Object, Object> getSaveOptions() {
+ Map<Object, Object> saveOptions = super.getSaveOptions();
+
+ saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.FALSE);
+ saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.FALSE);
+
+ return saveOptions;
+ }
+
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
index 8a999d98f93..5950fc9a654 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
@@ -3,7 +3,10 @@
*/
package org.eclipse.papyrus.infra.core.resource.sasheditor;
+import java.util.Map;
+
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource;
import org.eclipse.papyrus.infra.core.resource.IModel;
import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource.ModelKind;
@@ -12,7 +15,8 @@ import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource.M
* Model for the sash system. <br>
* This model can share its resource with other model. This model is declared as {@link ModelKind#master}. Other model whishing to share the resource
* should
- * subclass {@link AbstractModelWithSharedResource}, be declared as {@link ModelKind#slave} (which is the default.), and set {@link #getModelFileExtension()} to return the same file extension as this
+ * subclass {@link AbstractModelWithSharedResource}, be declared as {@link ModelKind#slave} (which is the default.), and set
+ * {@link #getModelFileExtension()} to return the same file extension as this
* model ({@link #MODEL_FILE_EXTENSION}).
*
* @author cedric dumoulin
@@ -68,4 +72,14 @@ public class SashModel extends AbstractModelWithSharedResource<org.eclipse.papyr
return object instanceof org.eclipse.papyrus.infra.core.sashwindows.di.SashModel;
}
+ @Override
+ protected Map<Object, Object> getSaveOptions() {
+ Map<Object, Object> saveOptions = super.getSaveOptions();
+
+ saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.FALSE);
+ saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.FALSE);
+
+ return saveOptions;
+ }
+
}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.history/src/org/eclipse/papyrus/infra/services/controlmode/history/HistoryModel.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.history/src/org/eclipse/papyrus/infra/services/controlmode/history/HistoryModel.java
index 943ded823a3..1bc246814ae 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.history/src/org/eclipse/papyrus/infra/services/controlmode/history/HistoryModel.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode.history/src/org/eclipse/papyrus/infra/services/controlmode/history/HistoryModel.java
@@ -62,6 +62,7 @@ public class HistoryModel extends AbstractModelWithSharedResource<ControledResou
* @param object
* @return
*/
+ @Override
protected boolean isModelRoot(EObject object) {
return object instanceof ControledResource;
}
diff --git a/plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/EMFFacetNattableModel.java b/plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/EMFFacetNattableModel.java
index 9e2600f3fd8..df44916fee1 100644
--- a/plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/EMFFacetNattableModel.java
+++ b/plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/EMFFacetNattableModel.java
@@ -18,7 +18,6 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableInstance;
import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource;
import org.eclipse.papyrus.infra.core.resource.IModel;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
@@ -58,13 +57,6 @@ public class EMFFacetNattableModel extends /* AbstractBaseModel */AbstractModelW
}
- // Initialize stuff in the model.
- @Override
- public void init(ModelSet modelManager) {
- super.init(modelManager);
- // nothing to do now
- }
-
/**
* Get the file extension used for this model.
*
diff --git a/plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/PapyrusNattableModel.java b/plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/PapyrusNattableModel.java
index 02334b1d8b2..aed70db5dd5 100644
--- a/plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/PapyrusNattableModel.java
+++ b/plugins/infra/table/org.eclipse.papyrus.infra.table.common/src/org/eclipse/papyrus/infra/table/common/modelresource/PapyrusNattableModel.java
@@ -18,7 +18,6 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableInstance;
import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource;
import org.eclipse.papyrus.infra.core.resource.IModel;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
@@ -59,13 +58,6 @@ public class PapyrusNattableModel extends AbstractModelWithSharedResource<TableI
}
- // Initialize stuff in the model.
- @Override
- public void init(ModelSet modelManager) {
- super.init(modelManager);
- // nothing to do now
- }
-
/**
* Get the file extension used for this model.
*

Back to the top