Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenn Hussey2011-09-29 20:25:56 +0000
committerKenn Hussey2011-09-29 20:25:56 +0000
commit813b5c115bb0cee7e60399030538ea315a9523de (patch)
tree73d2244e5f82f3c62af3294834514ca5c5b3983b /plugins/org.eclipse.uml2.uml
parentbeca36e30f02c2921dd3711b5650b6ff9abfe955 (diff)
downloadorg.eclipse.uml2.test-813b5c115bb0cee7e60399030538ea315a9523de.tar.gz
org.eclipse.uml2.test-813b5c115bb0cee7e60399030538ea315a9523de.tar.xz
org.eclipse.uml2.test-813b5c115bb0cee7e60399030538ea315a9523de.zip
[327039] Ensuring nsPrefix and nsURI tags are properly (de)serialized
for profiles.
Diffstat (limited to 'plugins/org.eclipse.uml2.uml')
-rw-r--r--plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/CMOF2UMLSaveImpl.java34
-rw-r--r--plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/XMI2UMLSaveImpl.java61
-rw-r--r--plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/resource/CMOF2UMLResourceHandler.java44
3 files changed, 104 insertions, 35 deletions
diff --git a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/CMOF2UMLSaveImpl.java b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/CMOF2UMLSaveImpl.java
index bdabc331..d8c3d168 100644
--- a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/CMOF2UMLSaveImpl.java
+++ b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/CMOF2UMLSaveImpl.java
@@ -13,6 +13,7 @@
*/
package org.eclipse.uml2.uml.internal.resource;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -28,6 +29,8 @@ import org.eclipse.emf.ecore.xmi.XMLHelper;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.EMOFExtendedMetaData;
import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl;
+
+import org.eclipse.uml2.common.util.UML2Util;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.EnumerationLiteral;
@@ -159,6 +162,11 @@ public class CMOF2UMLSaveImpl
}
@Override
+ protected Object writeTopObject(EObject top) {
+ return writeTopObjects(Collections.singletonList(top));
+ }
+
+ @Override
public Object writeTopObjects(List<? extends EObject> contents) {
if (!toDOM) {
@@ -336,51 +344,49 @@ public class CMOF2UMLSaveImpl
} else if (eObject instanceof org.eclipse.uml2.uml.Package) {
org.eclipse.uml2.uml.Package package_ = (org.eclipse.uml2.uml.Package) eObject;
- Object nsPrefix = UMLUtil.getTaggedValue(package_,
+ String nsPrefix = (String) UMLUtil.getTaggedValue(package_,
UMLUtil.PROFILE__ECORE + NamedElement.SEPARATOR
+ UMLUtil.STEREOTYPE__E_PACKAGE,
UMLUtil.TAG_DEFINITION__NS_PREFIX);
-
+
if (nsPrefix == null) {
nsPrefix = package_.getName();
}
- if (nsPrefix instanceof String) {
+ if (!UML2Util.isEmpty(nsPrefix)) {
doc.startElement(CMOF2UMLExtendedMetaData.CMOF_TAG);
doc.addAttribute(idAttributeName, "_" + index++); //$NON-NLS-1$
doc.addAttribute(
CMOF2UMLExtendedMetaData.CMOF_TAG_NAME,
CMOF2UMLExtendedMetaData.XMI_TAG__NS_PREFIX);
doc.addAttribute(
- CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE,
- (String) nsPrefix);
+ CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE, nsPrefix);
doc.addAttribute(
- CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT, helper
- .getIDREF(package_));
+ CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT,
+ helper.getIDREF(package_));
doc.endEmptyElement();
}
- Object nsURI = UMLUtil.getTaggedValue(package_,
+ String nsURI = (String) UMLUtil.getTaggedValue(package_,
UMLUtil.PROFILE__ECORE + NamedElement.SEPARATOR
+ UMLUtil.STEREOTYPE__E_PACKAGE,
UMLUtil.TAG_DEFINITION__NS_URI);
-
+
if (nsURI == null) {
nsURI = package_.getURI();
}
- if (nsURI instanceof String) {
+ if (!UML2Util.isEmpty(nsURI)) {
doc.startElement(CMOF2UMLExtendedMetaData.CMOF_TAG);
doc.addAttribute(idAttributeName, "_" + index++); //$NON-NLS-1$
doc.addAttribute(
CMOF2UMLExtendedMetaData.CMOF_TAG_NAME,
CMOF2UMLExtendedMetaData.XMI_TAG__NS_URI);
doc.addAttribute(
- CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE,
- (String) nsURI);
+ CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE, nsURI);
doc.addAttribute(
- CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT, helper
- .getIDREF(package_));
+ CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT,
+ helper.getIDREF(package_));
doc.endEmptyElement();
}
}
diff --git a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/XMI2UMLSaveImpl.java b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/XMI2UMLSaveImpl.java
index dcb2f66b..0156b8f0 100644
--- a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/XMI2UMLSaveImpl.java
+++ b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/resource/XMI2UMLSaveImpl.java
@@ -12,6 +12,7 @@
*/
package org.eclipse.uml2.uml.internal.resource;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -28,9 +29,12 @@ import org.eclipse.emf.ecore.xmi.impl.EMOFExtendedMetaData;
import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl;
import org.eclipse.uml2.common.util.UML2Util;
+import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.CMOF2UMLExtendedMetaData;
+import org.eclipse.uml2.uml.resource.CMOF2UMLResource;
+import org.eclipse.uml2.uml.util.UMLUtil;
public class XMI2UMLSaveImpl
extends UMLSaveImpl {
@@ -57,11 +61,27 @@ public class XMI2UMLSaveImpl
}
+ protected static final String CMOF_XMLNS = XMLResource.XML_NS + ':'
+ + CMOF2UMLResource.CMOF_METAMODEL_NS_PREFIX;
+
+ protected static final String CMOF_URI = CMOF2UMLResource.CMOF_METAMODEL_NS_URI;
+
+ protected boolean declareCMOF = false;
+
public XMI2UMLSaveImpl(XMLHelper helper) {
super(helper);
}
@Override
+ public void addNamespaceDeclarations() {
+ super.addNamespaceDeclarations();
+
+ if (declareCMOF) {
+ doc.addAttribute(CMOF_XMLNS, CMOF_URI);
+ }
+ }
+
+ @Override
protected void init(XMLResource resource, Map<?, ?> options) {
super.init(resource, options);
@@ -84,6 +104,11 @@ public class XMI2UMLSaveImpl
}
@Override
+ protected Object writeTopObject(EObject top) {
+ return writeTopObjects(Collections.singletonList(top));
+ }
+
+ @Override
public Object writeTopObjects(List<? extends EObject> contents) {
if (!toDOM) {
@@ -120,37 +145,53 @@ public class XMI2UMLSaveImpl
if (eObject instanceof Profile) {
Profile profile = (Profile) eObject;
- String nsPrefix = profile.getName();
+ String nsPrefix = (String) UMLUtil.getTaggedValue(profile,
+ UMLUtil.PROFILE__ECORE + NamedElement.SEPARATOR
+ + UMLUtil.STEREOTYPE__E_PACKAGE,
+ UMLUtil.TAG_DEFINITION__NS_PREFIX);
+
+ if (nsPrefix == null) {
+ nsPrefix = profile.getName();
+ }
if (!UML2Util.isEmpty(nsPrefix)) {
+ declareCMOF = true;
+
doc.startElement(CMOF2UMLExtendedMetaData.CMOF_TAG);
doc.addAttribute(idAttributeName, "_" + index++); //$NON-NLS-1$
doc.addAttribute(
CMOF2UMLExtendedMetaData.CMOF_TAG_NAME,
CMOF2UMLExtendedMetaData.XMI_TAG__NS_PREFIX);
doc.addAttribute(
- CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE,
- nsPrefix);
+ CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE, nsPrefix);
doc.addAttribute(
- CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT, helper
- .getIDREF(profile));
+ CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT,
+ helper.getIDREF(profile));
doc.endEmptyElement();
}
- String nsURI = profile.getName();
+ String nsURI = (String) UMLUtil.getTaggedValue(profile,
+ UMLUtil.PROFILE__ECORE + NamedElement.SEPARATOR
+ + UMLUtil.STEREOTYPE__E_PACKAGE,
+ UMLUtil.TAG_DEFINITION__NS_URI);
+
+ if (nsURI == null) {
+ nsURI = profile.getURI();
+ }
if (!UML2Util.isEmpty(nsURI)) {
+ declareCMOF = true;
+
doc.startElement(CMOF2UMLExtendedMetaData.CMOF_TAG);
doc.addAttribute(idAttributeName, "_" + index++); //$NON-NLS-1$
doc.addAttribute(
CMOF2UMLExtendedMetaData.CMOF_TAG_NAME,
CMOF2UMLExtendedMetaData.XMI_TAG__NS_URI);
doc.addAttribute(
- CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE,
- nsURI);
+ CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE, nsURI);
doc.addAttribute(
- CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT, helper
- .getIDREF(profile));
+ CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT,
+ helper.getIDREF(profile));
doc.endEmptyElement();
}
}
diff --git a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/resource/CMOF2UMLResourceHandler.java b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/resource/CMOF2UMLResourceHandler.java
index 2a0a80ae..f7d6f1fc 100644
--- a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/resource/CMOF2UMLResourceHandler.java
+++ b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/resource/CMOF2UMLResourceHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2008 IBM Corporation, Embarcadero Technologies, and others.
+ * Copyright (c) 2007, 2011 IBM Corporation, Embarcadero Technologies, CEA, 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
@@ -8,8 +8,8 @@
* Contributors:
* Kenn Hussey (IBM Corporation, Embarcadero Technologies) - initial API and implementation
* Kenn Hussey (Embarcadero Technologies) - 213903
+ * Kenn Hussey (CEA) - 327039
*
- * $Id: CMOF2UMLResourceHandler.java,v 1.2 2008/03/06 04:30:02 khussey Exp $
*/
package org.eclipse.uml2.uml.resource;
@@ -357,9 +357,21 @@ public class CMOF2UMLResourceHandler
CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT, false);
if (element instanceof org.eclipse.uml2.uml.Package) {
- ((org.eclipse.uml2.uml.Package) element)
- .setURI((String) getValue(tag.getAnyAttribute(),
- CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE));
+ org.eclipse.uml2.uml.Package package_ = (org.eclipse.uml2.uml.Package) element;
+ String packageURI = package_.getURI();
+
+ String nsURI = (String) getValue(tag.getAnyAttribute(),
+ CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE);
+
+ if (packageURI == null) {
+ package_.setURI(nsURI);
+ } else if (!packageURI.equals(nsURI)) {
+ UMLUtil.setTaggedValue(
+ package_,
+ getEcoreStereotype(package_,
+ UMLUtil.STEREOTYPE__E_PACKAGE),
+ UMLUtil.TAG_DEFINITION__NS_URI, nsURI);
+ }
}
tagsToRemove.add(tag);
@@ -370,12 +382,22 @@ public class CMOF2UMLResourceHandler
CMOF2UMLExtendedMetaData.CMOF_TAG_ELEMENT, false);
if (element instanceof org.eclipse.uml2.uml.Package) {
- UMLUtil.setTaggedValue((Element) element,
- getEcoreStereotype(element,
- UMLUtil.STEREOTYPE__E_PACKAGE),
- UMLUtil.TAG_DEFINITION__NS_PREFIX, getValue(tag
- .getAnyAttribute(),
- CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE));
+ org.eclipse.uml2.uml.Package package_ = (org.eclipse.uml2.uml.Package) element;
+ String packageName = package_.getName();
+
+ String nsPrefix = (String) getValue(
+ tag.getAnyAttribute(),
+ CMOF2UMLExtendedMetaData.CMOF_TAG_VALUE);
+
+ if (packageName == null) {
+ package_.setName(nsPrefix);
+ } else if (!packageName.equals(nsPrefix)) {
+ UMLUtil.setTaggedValue(
+ package_,
+ getEcoreStereotype(package_,
+ UMLUtil.STEREOTYPE__E_PACKAGE),
+ UMLUtil.TAG_DEFINITION__NS_PREFIX, nsPrefix);
+ }
}
tagsToRemove.add(tag);

Back to the top