Universal Robots Forum

Add ProgramNode from another URCaps bundle to ProgramTree

Hi all,
is there a possibility to generate a new URCapProgramNode with createURCapProgramNode() that is defined in another URCaps OSGI bundle? WITHOUT knowing it on compile time?

Background : I want to add via URCaps new ProgramNode to the ProgramTree where the ProgramNodeService and the ProgramNodeContribution was defined in another URcaps bundle.

I am able to load the other Jar into my Classloader. But when i call createURCapProgramNode i get the Exception

java.lang.IllegalArgumentException: Argument must implement ProgramNodeService or SwingProgramNodeService
at com.ur.urcap.domain.program.ProgramNodeFactoryImpl.createURCapProgramNode_aroundBody0(ProgramNodeFactoryImpl.java:131)
at com.ur.urcap.domain.program.ProgramNodeFactoryImpl$AjcClosure1.run(ProgramNodeFactoryImpl.java:1)
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)

The loaded class definitly implements the ProgramNodeService interface.
I am not the experienced one in OSGI but is there a way to maybe resister the other osgi bundle in by own bundle context?

i Know this question is maybe more Java classloading and osgi related than urcaps but i also ton not understand how createURCapProgramNode() determine it a loaded class implements the correct interface.

Thank You
Jan

Hi Jan,

this should be possible.

You can use the bundleContext reference from the Activator class to find other registered OSGi Bundles with bundleContext.getService().
This way, having an interface for giving you the (programNode)Service reference from the other urcap, you can add it to your tree.
There are some more things to do to get this interface running. you have to export your service classes from the other urcap (or the whole package) to get access.

You can do it with:
<Export-Package>
com.yourcompany.yoururcap
</Export-Package>

in your maven-bundle-plugin configuration in your urcaps’s pom file.

Best,
Michael

2 Likes

Hi Michael,
thank you for your suggestion. I tried it yesterday and if worked perfekt.
With a little bit extra Java reflection magic everything is configurable.
Thanks
Best,
Jan

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.