How to set the xmi:id in the generated XML based file [message #1015760] |
Sat, 02 March 2013 11:45 |
Philipp El Messages: 14 Registered: September 2012 |
Junior Member |
|
|
Hi,
the code below adds a new node "SemanticElement" to the domain.
public final String fileSource = "models/PhilippDA.brms";
public final String fileDest = "models/PhilippDA_gen.brms";
Resource resource = ModelUtils.loadFileResource(new File(fileSource));
Domain domain = ModelUtils.getDomain(resource);
Diagram diagram = ModelUtils.getDiagram(resource);
SemanticElement se = CmFactory.eINSTANCE.createSemanticElement();
se.setName("test");
ModelUtils.addToDomain(se, domain, null).execute();
ModelUtils.saveToFile(domain, new File(fileDest));
in the generated file it looks as follows:
<contains xsi:type="cm:SemanticElement" name="test"/>
My first question: How can is set the xmi:id attribute, so that it looks as follow:
<contains xsi:type="cm:SemanticElement" xmi:id="_BG05gI3wEeG4R6fg5itl5w" name="test"/>
My second question: How can i add the SemanticElement to the diagram, so that it looks as follows:
<children xmi:id="_BG380I3wEeG4R6fg5itl5w" type="2002" element="_BG05gI3wEeG4R6fg5itl5w">
<children xsi:type="notation:DecorationNode" xmi:id="_BG4j4I3wEeG4R6fg5itl5w" type="5002"/>
<styles xsi:type="notation:DescriptionStyle" xmi:id="_BG380Y3wEeG4R6fg5itl5w"/>
<styles xsi:type="notation:FontStyle" xmi:id="_BG380o3wEeG4R6fg5itl5w" fontName="Segoe UI"/>
<styles xsi:type="notation:FillStyle" xmi:id="_BG38043wEeG4R6fg5itl5w"/>
<styles xsi:type="notation:HintedDiagramLinkStyle" xmi:id="_BG381I3wEeG4R6fg5itl5w"/>
<layoutConstraint xsi:type="notation:Bounds" xmi:id="_BG381Y3wEeG4R6fg5itl5w" x="624" y="108"/>
</children>
Thank you very much!
Best regards,
Philipp
[Updated on: Sat, 02 March 2013 11:47] Report message to a moderator
|
|
|
|
Re: How to set the xmi:id in the generated XML based file [message #1016443 is a reply to message #1015764] |
Wed, 06 March 2013 13:25 |
Philipp El Messages: 14 Registered: September 2012 |
Junior Member |
|
|
Andreas Muelder wrote on Sat, 02 March 2013 08:06Hi Philipp,
your first question:
the used resource implementation is responsible for generating and persisting the xmi ids. I don't know the class ModelUtils you are using to get the resource implementation, but normally, if you receive a Resource implementation via a ResourceSet, the class ResourceFactoryRegistryImpl is used to map the file extension to a resource implementation.
Ensure, that your file extension 'brms' is registered to a resource implementation that returns true in the method protected boolean useUUIDs(). (For example the GMFResourceImpl)
your second question:
You can add your semantic element to the diagram via diagram.setElement(semanticElement).
Best regards,
Andreas
Hi Andreas,
the first problem is fixed, but the second one doesn't work so.
My code looks as follows:
SemanticElement se = CmFactory.eINSTANCE.createSemanticElement();
se.setName("Test");
diagram.setElement(se);
....
The position (x,y) of the element should be a constant value, for example (0,0).
Thank you very much!
Best regards,
Philipp
|
|
|
|
Powered by
FUDForum. Page generated in 0.03451 seconds