How to create ComponentPort and ComponentExchange for LogicalComponent?

Hi All,
I want to create some component ports and component exchanges for lc by p4c, I used the following code:

cp = ComponentPort()
cp.set_name('aaaa')

lc.get_contained_component_ports().add(cp)

but I got some error:

java.lang.UnsupportedOperationException
	at org.eclipse.emf.common.util.BasicEList$UnmodifiableEList.add(BasicEList.java:908)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
	at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
	at py4j.Gateway.invoke(Gateway.java:282)
	at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
	at py4j.commands.CallCommand.execute(CallCommand.java:79)
	at py4j.ClientServerConnection.sendCommand(ClientServerConnection.java:244)
	at py4j.CallbackClient.sendCommand(CallbackClient.java:384)
	at py4j.CallbackClient.sendCommand(CallbackClient.java:356)
	at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:106)
	at jdk.proxy10/jdk.proxy10.$Proxy23.executeScript(Unknown Source)
	at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.internalExecute(Py4jScriptEngine.java:240)
	at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.execute(Py4jScriptEngine.java:227)
	at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:189)
	at org.eclipse.ease.AbstractScriptEngine.run(AbstractScriptEngine.java:242)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Anyone knows how to create the componentports and componentexchanges correctly?

The containedComponentPorts feature is derived. To add a port you need to add it as input or output port. There is no Python API provided but you can use the Java API:

lc.get_java_object().setSource(cp.get_java_object())

or

lc.get_java_object().setTarget(cp.get_java_object())

Hello Yvan,

I have the same problem as Jayden, but when I try to use Java API, its functions doesn’t exist. It looks like it is not imported:

org.eclipse.ease.ScriptExecutionException: Traceback (most recent call last):
File “workspace://CreateCapa/VOBC.py”, line 67, in
File “C:\Users\consultant\Desktop\Capella\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\java_gateway.py”, line 1321, in call
return_value = get_return_value(
File “C:\Users\consultant\Desktop\Capella\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\protocol.py”, line 330, in get_return_value
raise Py4JError(
py4j.protocol.Py4JError: An error occurred while calling o35.setTarget. Trace:
py4j.Py4JException: Method setTarget([class org.polarsys.capella.core.data.fa.impl.ComponentPortImpl]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
at py4j.Gateway.invoke(Gateway.java:274)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.ClientServerConnection.sendCommand(ClientServerConnection.java:244)
at py4j.CallbackClient.sendCommand(CallbackClient.java:384)
at py4j.CallbackClient.sendCommand(CallbackClient.java:356)
at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:106)
at com.sun.proxy.$Proxy25.executeScript(Unknown Source)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.internalExecute(Py4jScriptEngine.java:240)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.execute(Py4jScriptEngine.java:227)
at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:189)
at org.eclipse.ease.AbstractScriptEngine.run(AbstractScriptEngine.java:242)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Can you help me with that please ?

Thx

`

The setSource() and setTarget() are on the ComponentExchange not the LogicalComponent itself.

myComponentExchange.get_java_object().setSource(cp.get_java_object())

Then you can add the ComponentExchange to your LogicalComponent for instance:

lc.get_java_object().getOwnedComponentExchanges().add(myComponentExchange.get_java_object())