use of com.ibm.jvm.dtfjview.commands.BaseJdmpviewCommand in project openj9 by eclipse.
the class CombinedContext method initJdmpviewCommand.
/*
* Commands / plugins that inherit from the BaseJdmpviewCommand class need to have
* their initialisation methods fired, which validates the context type and sets
* up various instance level fields. Commands that directly implement the DTFJ
* plugin interfaces will be ignored.
*/
private boolean initJdmpviewCommand(CommandParser parser, PrintStream out) throws CommandException {
for (ICommand command : commands) {
if (command.recognises(parser.getCommand(), this)) {
try {
/*
* This work-around is needed because the BaseJdmpviewCommand is loaded in both the
* CombinedContext classloader and in the classloader which is running the command. This
* means that a simple instanceof check will not work
* i.e. (command instanceof BaseJdmpviewCommand) fails as it's comparing the base command from
* two different classloaders. Solution is to use the same classloader as the command
* to get the BaseJdmpviewCommand class and then use reflection to invoke it.
*/
Class<?> base = command.getClass().getClassLoader().loadClass(BaseJdmpviewCommand.class.getName());
if (base.isAssignableFrom(command.getClass())) {
Method method = base.getMethod("initCommand", new Class<?>[] { String.class, String[].class, IContext.class, PrintStream.class });
Object result = method.invoke(command, parser.getCommand(), parser.getArguments(), this, out);
return (Boolean) result;
}
} catch (Exception e) {
out.println("Error initialising command : " + parser.getOriginalLine() + " (" + e.getMessage() + ")");
logger.log(Level.FINE, "Error initialising command : " + parser.getOriginalLine(), e);
}
}
}
return false;
}
Aggregations