Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Creating connector
Creating connector [message #559816] Sun, 19 September 2010 06:30 Go to next message
123star  is currently offline 123star
Messages: 70
Registered: June 2010
Member
Hi,

I need to create a Connector between two ports, I listened to the notification on the model when I create a Connector by hand and I discovered that the Connector is owned by the Class and not by the Port and that no notification is fired from Port, so I don't know if this code is right:

//port1, port2 are the ports to be connected

Connector conn = UMLFactory.eINSTANCE.createConnector();
port1.getEnds().add(conn.createEnd());
port2.getEnds().add(conn.createEnd());

Is it right?

Thanks in advance, 123star



Re: Creating connector [message #559822 is a reply to message #559816] Sun, 19 September 2010 12:11 Go to previous message
Rafael Chaves is currently offline Rafael Chaves
Messages: 161
Registered: July 2009
Senior Member
I would expect you to have to add the connector to some parent in the model.

StructuredClassifier#createOwnedConnector(String) would do that for you:

StructuredClassifier parent = (StructuredClassifier) port1.getNamespace();
Connector conn = parent.createOwnedConnector(null);


Re: linking connector end with the port - what you are doing should work, but in the end, adding to the ends collection will result on setRole(port) on the connection end. IOW:

port1.getEnds().add(conn.createEnd());


is equivalent to:

ConnectorEnd end1 = conn.createEnd();
end1.setRole(port1);


But I haven't tried any of the code above. Cheers,

Rafael
http://abstratt.com/blog

Previous Topic:Problem adding comment
Next Topic:Problem adding comment
Goto Forum:
  


Current Time: Fri Aug 29 06:32:54 EDT 2014

Powered by FUDForum. Page generated in 0.02526 seconds