/
CMOF202UMLHandler.java
119 lines (98 loc) · 3.78 KB
/
CMOF202UMLHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright (c) 2007, 2018 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 v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Kenn Hussey (IBM Corporation, Embarcadero Technologies) - initial API and implementation
* Kenn Hussey (Embarcadero Technologies) - 218388
* Kenn Hussey (CEA) - 327039, 418466, 437716
* Kenn Hussey - 366349, 369268, 535301
*
*/
package org.eclipse.uml2.uml.internal.resource;
import java.util.Map;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.xmi.XMIResource;
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.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.CMOF2UMLResource;
import org.eclipse.uml2.uml.resource.UML212UMLResource;
import org.eclipse.uml2.uml.resource.UML302UMLResource;
import org.eclipse.uml2.uml.resource.UML402UMLResource;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.eclipse.uml2.uml.resource.XMI2UMLResource;
public class CMOF202UMLHandler
extends XMI2UMLHandler {
protected static final String UML_EXTENSION_TYPE = "umlExtension"; //$NON-NLS-1$
protected static final String XMI_IDREF = "idref"; //$NON-NLS-1$
protected static final String IDREF_ATTRIB = XMIResource.XMI_NS + ':'
+ XMI_IDREF;
public CMOF202UMLHandler(XMLResource xmiResource, XMLHelper helper,
Map<?, ?> options) {
super(xmiResource, helper, options);
}
@Override
protected void processElement(String name, String prefix, String localName) {
String extender = attribs
.getValue(EMOFExtendedMetaData.XMI_EXTENDER_ATTRIBUTE);
if (EMOFExtendedMetaData.EXTENSION.equals(localName)
&& XMI2UMLResource.XMI_2_1_NS_URI.equals(helper.getURI(prefix))
&& attribs != null
&& (UML212UMLResource.UML_METAMODEL_NS_URI.equals(extender)
|| UML302UMLResource.UML_METAMODEL_NS_URI.equals(extender)
|| UML402UMLResource.UML_METAMODEL_NS_URI.equals(extender) || UMLPackage.eNS_URI
.equals(extender))) {
types.push(UML_EXTENSION_TYPE);
} else {
super.processElement(name, prefix, localName);
}
}
@Override
public void endElement(String uri, String localName, String name) {
if (types.peek() == UML_EXTENSION_TYPE) {
elements.pop();
types.pop();
helper.popContext();
mixedTargets.pop();
} else {
super.endElement(uri, localName, name);
}
}
@Override
protected void setAttribValue(EObject object, String name, String value) {
if (IDREF_ATTRIB.equals(name)
&& (!recordUnknownFeature || types.peek() != UNKNOWN_FEATURE_TYPE)) {
handleProxy((InternalEObject) object, '#' + value);
} else {
super.setAttribValue(object, name, value);
}
}
@Override
protected void handleProxy(InternalEObject proxy, String uriLiteral) {
if (uriLiteral
.startsWith(CMOF2UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_2_0_URI)) {
if (uriLiteral.endsWith(PRIMITIVE_TYPE_BOOLEAN)) {
uriLiteral = PRIMITIVE_TYPE_BOOLEAN_URI;
} else if (uriLiteral.endsWith(PRIMITIVE_TYPE_INTEGER)) {
uriLiteral = PRIMITIVE_TYPE_INTEGER_URI;
} else if (uriLiteral.endsWith(PRIMITIVE_TYPE_STRING)) {
uriLiteral = PRIMITIVE_TYPE_STRING_URI;
} else if (uriLiteral.endsWith(PRIMITIVE_TYPE_UNLIMITED_NATURAL)) {
uriLiteral = PRIMITIVE_TYPE_UNLIMITED_NATURAL_URI;
} else {
int index = uriLiteral.indexOf('#');
uriLiteral = UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI
+ (index == -1
? "#_0" //$NON-NLS-1$
: uriLiteral.substring(index));
}
}
super.handleProxy(proxy, uriLiteral);
}
}