Search in sources :

Example 1 with BaseJdmpviewCommand

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;
}
Also used : ICommand(com.ibm.java.diagnostics.utils.commands.ICommand) Method(java.lang.reflect.Method) BaseJdmpviewCommand(com.ibm.jvm.dtfjview.commands.BaseJdmpviewCommand) URISyntaxException(java.net.URISyntaxException) CommandException(com.ibm.java.diagnostics.utils.commands.CommandException) ParseException(java.text.ParseException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Aggregations

CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 CommandException (com.ibm.java.diagnostics.utils.commands.CommandException)1 ICommand (com.ibm.java.diagnostics.utils.commands.ICommand)1 BaseJdmpviewCommand (com.ibm.jvm.dtfjview.commands.BaseJdmpviewCommand)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1