I have been trying to build a CustomTool extending AbstractTool to populate data to my custom master.
I made a CustomToolContext class extending the ToolContext for that…
@BeanDefinition
public class CustomToolContext extends ToolContext {
/**
- The Custom master.
*/
@PropertyDefinition
private CustomMaster _customMaster;
…
…
and I have added a custom toolcontext part in the toolcontext-xxx.ini file in the config.
My aim was to access the custom master in the Custom tool created myself by the following code.
customToolContext.getCustomMaster();
Everyting seemed to be ok from the coding perspective but sucked with a class cast error.
tracking this class cast error I reached the code in ToolContextUtils.java
after a close watch I smelled something in the line 90’s in the function
public static ToolContext getToolContext(String configResourceLocation, Class<? extends ToolContext> toolContextClazz, List classifierChain)
…
ComponentManager manager = new ComponentManager(“toolcontext”);
manager.start(configResourceLocation);
ComponentRepository repo = manager.getRepository();
return repo.getInstance(ToolContext.class, “tool”);
…
I made a build to the OG-Component after changing the return statement to
return repo.getInstance(toolContextClazz, "tool");
working fine for me in the particular case when we create custom tool context I believe.
so far I could not find any side effect for the change, though I am not sure this is the solution.