Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Fasani2017-07-26 10:06:26 +0000
committerLaurent Fasani2017-08-01 14:07:47 +0000
commit1172e363c75c5d2d8e46a53859221b4038cb81ca (patch)
treec6f7aa5dedc9461c946d62e4f83234c1f06a8238
parent88f65f8b97038d39d3172aba0c6c912ae12a03c1 (diff)
downloadorg.eclipse.sirius-1172e363c75c5d2d8e46a53859221b4038cb81ca.tar.gz
org.eclipse.sirius-1172e363c75c5d2d8e46a53859221b4038cb81ca.tar.xz
org.eclipse.sirius-1172e363c75c5d2d8e46a53859221b4038cb81ca.zip
[516669] Use DRepresentation.uid to suffix the rep resource URI
Bug: 516669 Change-Id: If158559ad1969744b8055b2f1795275acbb16e69 Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java85
1 files changed, 16 insertions, 69 deletions
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java
index 1572659e5e..b87cbf51c5 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java
@@ -13,9 +13,7 @@ package org.eclipse.sirius.business.internal.representation;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.sirius.business.api.dialect.DialectManager;
@@ -51,7 +49,8 @@ public class DRepLocationRuleForLocalResource implements DRepresentationLocation
/**
* Create the representation resource URI so that the representation can be stored in a specific resource.<br/>
- * The URI is based on the aird resource URI. Only the last part of the segment is changed.
+ * The URI is based on the aird resource URI. Only the last part of the segment is changed. It will include the name
+ * of the RepresentationDescription and a unique id as suffix
*
* @param airdResource
* the aird resource
@@ -60,43 +59,23 @@ public class DRepLocationRuleForLocalResource implements DRepresentationLocation
* @return the representation URI
*/
protected URI getDedicatedRepResourceURI(DRepresentation representation, Resource airdResource) {
- int count = 1;
- ResourceSet resourceSet = airdResource.getResourceSet();
- String suffix = getSuffix();
- URI repUri = createRepURI(airdResource, representation, suffix, count++);
- while (!isUsableURI(repUri, resourceSet, representation)) {
- repUri = createRepURI(airdResource, representation, suffix, count++);
- }
- return repUri;
- }
+ // create the representation URI segment
+ RepresentationDescription description = DialectManager.INSTANCE.getDescription(representation);
+ String repSegmentName = description.getName();
+ String suffix = representation.getUid();
+ repSegmentName += "_" + suffix; //$NON-NLS-1$
+ repSegmentName = URI.encodeSegment(repSegmentName, true);
- protected String getSuffix() {
- return null;
- }
+ // create all the segments of the rep resource URI
+ URI airdURI = airdResource.getURI();
+ List<String> srmFileSegments = new ArrayList<>(airdURI.segmentsList());
+ srmFileSegments.remove(srmFileSegments.size() - 1);
+ srmFileSegments.add(SiriusUtil.REPRESENTATIONS_FOLDER_NAME);
+ srmFileSegments.add(repSegmentName + "." + SiriusUtil.REPRESENTATION_FILE_EXTENSION); //$NON-NLS-1$
- private boolean isUsableURI(URI repUri, ResourceSet resourceSet, DRepresentation representation) {
- boolean usableURI = true;
- Resource resource = resourceSet.getResource(repUri, false);
- // A usable URI is when the resource is not already in the resourceSet or does not exist, that is, is not
- // loadable
- usableURI = resource == null && !existsResource(repUri, resourceSet);
+ // return the URI
+ return URI.createHierarchicalURI(airdURI.scheme(), airdURI.authority(), airdURI.device(), srmFileSegments.toArray(new String[srmFileSegments.size()]), airdURI.query(), airdURI.fragment());
- // We consider the URI usable if the representation is already in the resource
- if (resource != null) {
- TreeIterator<EObject> allContents = resource.getAllContents();
- while (allContents.hasNext()) {
- EObject object = allContents.next();
- if (object instanceof DRepresentation) {
- if (representation.equals(object)) {
- usableURI = true;
- break;
- } else {
- allContents.prune();
- }
- }
- }
- }
- return usableURI;
}
/**
@@ -112,38 +91,6 @@ public class DRepLocationRuleForLocalResource implements DRepresentationLocation
return resourceSet.getURIConverter().exists(repUri, null);
}
- /**
- * Create the representation URI based on the aird resource URI.</br>
- * Only the last part of the segment is changed. It will include the name of the RepresentationDescription
- *
- * @param airdResource
- * the aird resource
- * @param representation
- * the representation
- * @param providedSuffix
- * suffix to add to the URI. If null, the count is used instead
- * @param count
- * the counter that may be used to have an unique URI
- * @return the representation URI
- */
- protected URI createRepURI(Resource airdResource, DRepresentation representation, String providedSuffix, int count) {
- // get the representation URI fragment
- RepresentationDescription description = DialectManager.INSTANCE.getDescription(representation);
- String repName = description.getName();
- String suffix = providedSuffix != null ? providedSuffix : String.valueOf(count);
- repName += "_" + suffix; //$NON-NLS-1$
- repName = URI.encodeSegment(repName, true);
- URI airdURI = airdResource.getURI();
-
- List<String> srmFileSegments = new ArrayList<>(airdURI.segmentsList());
- srmFileSegments.remove(srmFileSegments.size() - 1);
- srmFileSegments.add(SiriusUtil.REPRESENTATIONS_FOLDER_NAME);
- srmFileSegments.add(repName + "." + SiriusUtil.REPRESENTATION_FILE_EXTENSION); //$NON-NLS-1$
-
- // return the URI
- return URI.createHierarchicalURI(airdURI.scheme(), airdURI.authority(), airdURI.device(), srmFileSegments.toArray(new String[srmFileSegments.size()]), airdURI.query(), airdURI.fragment());
- }
-
@Override
public Boolean isARepresentationFileExtension(String fileExtension) {
return SiriusUtil.REPRESENTATION_FILE_EXTENSION.equals(fileExtension);

Back to the top