Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Trouble Creating Ports and Interfaces (Need help creating provides and requires interfaces on Ports and saving as XMI.)
Trouble Creating Ports and Interfaces [message #532702] Mon, 10 May 2010 21:31
William Koscho is currently offline William Koscho
Messages: 10
Registered: May 2010
Junior Member
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
Previous Topic:how to transform the .profile.uml to .ecore files
Next Topic:Trouble Creating Ports and Interfaces
Goto Forum:
  


Current Time: Sat Oct 25 11:32:41 GMT 2014

Powered by FUDForum. Page generated in 0.02508 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software