use of org.apache.derby.iapi.sql.dictionary.OptionalTool in project derby by apache.
the class Java5SystemProcedures method SYSCS_REGISTER_TOOL.
// /////////////////////////////////////////////////////////////////////////////////
//
// PUBLIC BEHAVIOR
//
// /////////////////////////////////////////////////////////////////////////////////
/**
* <p>
* Load or unload an optional tool package. If the tool name is the special
* CUSTOM_TOOL_CLASS_NAME tool, then the first optionalArg is the name
* of a user-supplied class which implements OptionalTool.
* </p>
*
* @param toolName Name of the tool package.
* @param register True if the package should be loaded, false otherwise.
* @param optionalArgs Tool-specific configuration parameters.
*/
public static void SYSCS_REGISTER_TOOL(String toolName, boolean register, String... optionalArgs) throws SQLException {
try {
ClassFactoryContext cfc = (ClassFactoryContext) 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.getConstructor().newInstance();
} catch (InstantiationException ie) {
throw wrap(ie);
} catch (IllegalAccessException iae) {
throw wrap(iae);
} catch (NoSuchMethodException ie) {
throw wrap(ie);
} catch (java.lang.reflect.InvocationTargetException 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);
}
}
Aggregations