Missing references [message #1759999] |
Fri, 21 April 2017 01:37  |
Eclipse User |
|
|
|
Hi Experts ,
One of my models element in Model_A is referring an element present in Fragment_x of Model_B . So for Model_A I have imported the respective Element (Using Add UML -> Releationship -> Element Import ) which corresponds to the Fragment_x .
During my validation , I am retrieving the Packaged Elements of Model_A and as well its imported elements and checking the applied profiles . I am able to retrieve the imported element corresponding to Fragment_x but its eContainer is null along with its parent package and also the applied profiles .
I understood in this case , I could not traverse from Fragment_x to its base model Model_B and loosing the information from Model_B . When I absorbed the Fragment_x into Model_B and re imported the required Elements , then everything worked well .
The same validations passed well when I triggered them through eclipse IDE . So I hope this is a valid use case .
Problem is seen even after I made sure that ResourceSet is properly updated and resolved the model .
So problem is something wrong with the initialization of the model Model_A ? How should the connection between the Fragment_x and Model_B retained ?
Thanks,
Pavan
|
|
|
|
|
Re: Missing references [message #1760821 is a reply to message #1759999] |
Wed, 03 May 2017 06:16   |
Eclipse User |
|
|
|
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 101 times)
|
|
|
|
Re: Missing references [message #1760908 is a reply to message #1759999] |
Thu, 04 May 2017 05:18  |
Eclipse User |
|
|
|
Thanks for your reply .
I will redirect this to UML forum .
The null values are expected in this case , but as said in the above message , to perform some validations on model elements I am finding the ways to traverse from imported element to the parent package and further of its own model (TestProject2) to get information like applied profiles etc.,
For example if I absorb the fragment , and re import like below referring the element through emx file , I could get all the information of the parent packages and other model information when I am dealing with the imported element .
<elementImport xmi:id="_kjXMwDCREee9a7um1aNiYg">
<importedElement xmi:type="uml:Package" href="platform:/resource/TestProject2/IFM.emx#_HFdcYCtDEeeSw-dHyXRF1g?ReproToImport/Package1?"/>
</elementImport>
In my problematic case it look something like this
<elementImport xmi:id="_zQY58CtDEeeCxpJ1Lm0y_w">
<importedElement xmi:type="uml:Package" href="platform:/resource/TestProject2/subfolder1/subfolder2/Package1.efx#_HFdcYCtDEeeSw-dHyXRF1g?ReproToImport/Package1?"/>
</elementImport>
I wish to have the similar possibility to get the information from the base model when element is imported from the fragment . In short wanted to know if some
mapping could be created between the fragment and its base model , in cases like
one of the fragments element is imported in loaded through other model .
|
|
|
Powered by
FUDForum. Page generated in 0.04072 seconds