URCap Custom NodeFactory

Hey,
I am working on a URCap with several Nodes and I would like to configure them before I insert them in the tree.
Is it possible to have a custom ProgramNodeFactory for my Nodes? I have not found any examples and I cannot figure out a way looking through the API.

Currently, the solution I have is that my nodes implement my custom Api and then I can use that api after I insert the node.
Example:

TreeNode treeNode = parent.addChild(nf.createURCapProgramNode(MyURCapService.class));
URCapProgramNode programNode = (URCapProgramNode) treeNode.getProgramNode();
MyURCapApi myApi = programNode.getAs(MyURCapApi.class); // only works after the node has been added to the tree
myApi.setFlag(true);

Is this the only way to do it? Or would the factory basically do the same thing anyway?

Thank you

2 Likes