try {
ClassFactoryContext cfc = (ClassFactoryContext) ContextService.getContext( ClassFactoryContext.CONTEXT_ID );
ClassFactory classFactory = cfc.getClassFactory();
String toolClassName = findToolClassName( toolName, optionalArgs );
OptionalTool tool = null;
Class<?> toolClass;
try {
toolClass = classFactory.loadApplicationClass( toolClassName );
}
catch (ClassNotFoundException cnfe) { throw wrap( cnfe ); }
if (!OptionalTool.class.isAssignableFrom(toolClass)) {
throw badCustomTool(toolClassName);
}
try {
tool = (OptionalTool) toolClass.newInstance();
}
catch (InstantiationException ie) { throw wrap( ie ); }
catch (IllegalAccessException iae) { throw wrap( iae ); }
// Strip the custom tool class name from the optional args as necessary
if ( CUSTOM_TOOL_CLASS_NAME.equals( toolName ) )
{
optionalArgs = stripCustomClassName( optionalArgs );
}
if ( register ) { tool.loadTool( optionalArgs ); }
else { tool.unloadTool( optionalArgs ); }
}
catch (StandardException se) { throw PublicAPI.wrapStandardException( se ); }
}