|
|
|
Re: Missing references [message #1760821 is a reply to message #1759999] |
Wed, 03 May 2017 10:16 |
Pavan Muthoju Messages: 3 Registered: April 2017 |
Junior Member |
|
|
Hi all ,
I have trimmed with the required and the error is reproduced with the below . I have attached the RSA RTE models (TestProject1 and TestProject2) .
In short , for model in TestProject1 a package from TestProject2 is imported , the package comes from an fragment (.efx) of TestProject 2 as below.
<elementImport xmi:id="_zQY58CtDEeeCxpJ1Lm0y_w">
<importedElement xmi:type="uml:Package" href="platform:/resource/TestProject2/subfolder1/subfolder2/Package1.efx#_HFdcYCtDEeeSw-dHyXRF1g?ReproToImport/Package1?"/>
</elementImport>
I have created the resourceSet and loaded the model in TestProject1 as below .
It is very clear that imported package is an indirect reference of the model , so I could not further get the econtainer/model/expected parent package from model2 of the respective package .
But I need opinion on how to establish the connection between the fragment and its base model (TestProject2) when I am dealing with package imports of the fragment .
How could this be done or am I missing something ?
private static void loadModelAndReproduceIssue() {
String inModelFile = "/home/TestProject1/Repro.emx";
ResourceSet rs = new ResourceSetImpl();
URI modelUri = URI.createFileURI(inModelFile);
Registry packageRegistry = rs.getPackageRegistry();
packageRegistry.put("http://schema.omg.org/spec/XMI/2.0", UMLPackage.eINSTANCE);
packageRegistry.put("http://schema.omg.org/spec/UML/3.0", UMLPackage.eINSTANCE);
packageRegistry.put("http://www.eclipse.org/uml2/3.0.0/UML", UMLPackage.eINSTANCE);
final Map<String, Object> extensionToFactoryMap = rs.getResourceFactoryRegistry().getExtensionToFactoryMap();
extensionToFactoryMap.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
extensionToFactoryMap.put("emx", UMLResource.Factory.INSTANCE);
extensionToFactoryMap.put("efx", UMLResource.Factory.INSTANCE);
extensionToFactoryMap.put("uml2", UML22UMLResource.Factory.INSTANCE);
HashMap<String, String> uriStringMappingMap = new HashMap<>();
uriStringMappingMap.put("platform:/resource/TestProject1/", "file://home/TestProject1/");
uriStringMappingMap.put("platform:/resource/TestProject2/", "file://home/TestProject2/");
uriStringMappingMap.put("platform:/resource/TestProject2/subfolder1/subfolder2/",
"file:/home/TestProject2/subfolder1/subfolder2/");
final Map<URI, URI> uri_map = rs.getURIConverter().getURIMap();
for (Map.Entry<String, String> entry : uriStringMappingMap.entrySet()) {
uri_map.put(URI.createURI(entry.getKey()), URI.createURI(entry.getValue()));
}
// EVen added the dependant model in resorceSet
String inModelFile2 = "/home/TestProject2/IFM.emx";
URI modelUri2 = URI.createFileURI(inModelFile2);
Resource dependantModelResource = rs.createResource(modelUri2);
rs.getResources().add(dependantModelResource);
// Now work on the emx URI
UMLResource umlModelResource = (UMLResource) rs.getResource(modelUri, true);
Package modelPackage = (org.eclipse.uml2.uml.Package) EcoreUtil.getObjectByType(umlModelResource.getContents(),
UMLPackage.Literals.PACKAGE);
reproduceFault(modelPackage);
}
private static void reproduceFault(Package model) {
for (Element child : model.getOwnedElements()) {
if (child instanceof Package) {
reproduceFault((Package) child);
}
if (child instanceof ElementImport) {
Element importedElement = ((ElementImport) child).getImportedElement();
if (importedElement instanceof Package) {
// Problem is here !!!
if (importedElement.getModel() == null) {
System.out.println("Unable to fetch the UML model of the imported element :"
+ importedElement.getNearestPackage().getName());
}
if (importedElement.eContainer() == null) {
System.out.println("Unable to fetch the eContainer of the imported element :"
+ importedElement.getNearestPackage().getName());
}
}
}
}
}
-
Attachment: ToUpload.7z
(Size: 35.61KB, Downloaded 81 times)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03286 seconds