Im hoping someone can help me, as I'm trying to create a port with provided and required interfaces and save as XMI. I essentially have three problems:
1. The problem is that the code serializes ports in XMI as <ownedAttribute> but I would like this to be <ownedPort> , how can I do this?
2. I cannot get it to work with required interfaces, as it reports UnsupportedException. I found a posting indicating that I must specify some additional classifier information, but I was not sure exactly how to do that, any additional information is appreciated.
3. The XMI produced uses the xsi: prefix instead of the xmi: prefix, how can I change that?
My code snippet is as follows:
// create the port
Port p = UMLFactory.eINSTANCE.createPort();
p.setName(portName);
Interface i = UMLFactory.eINSTANCE.createInterface();
i.setName(iName);
port.getProvideds().add(i);
// TODO - add provides interfaces
// create the component
Component component = UMLFactory.eINSTANCE.createComponent();
component.setName(compName);
component.getOwnedPorts().add(port);
// populate the model
model.getPackagedElements().add(component);
// save it as XMI
ResourceSet resourceSet = new ResourceSetImpl();
UMLFactory factory = UMLFactory.eINSTANCE;
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
URI fileURI = URI.createFileURI(new File("c:\\temp\\exported_model.xmi").getAbsolutePath());
Resource resource = resourceSet.createResource(fileURI);
resource.getContents().add(model);
resource.save(out, Collections.EMPTY_MAP);
The output XMI file is:
<?xml version="1.0" encoding="ASCII"?>
<uml:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML">
<packagedElement xsi:type="uml:Package" name="Test4">
<packagedElement xsi:type="uml:Component" name="c1">
<ownedAttribute xsi:type="uml:Port" name="p" visibility="public" aggregation="composite"/>
</packagedElement>
<packagedElement xsi:type="uml:Component" name="c2">
<ownedAttribute xsi:type="uml:Port" name="p" visibility="public" aggregation="composite"/>
</packagedElement>
</packagedElement>
</uml:Model>
Thanks
Bill