use of com.twosigma.beakerx.kernel.magic.command.MagicCommandFunctionality in project beakerx by twosigma.
the class LoadMagicMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] split = splitPath(command);
if (split.length != 2) {
return new MagicCommandOutput(ERROR, WRONG_FORMAT_MSG + LOAD_MAGIC);
}
String clazzName = split[1];
try {
Class<?> aClass = this.kernel.loadClass(clazzName);
Object instance = aClass.newInstance();
if (instance instanceof MagicCommandFunctionality) {
MagicCommandFunctionality commandFunctionality = (MagicCommandFunctionality) instance;
kernel.registerMagicCommandType(new MagicCommandType(commandFunctionality.getMagicCommandName(), "", commandFunctionality));
return new MagicCommandOutput(OK, "Magic command " + commandFunctionality.getMagicCommandName() + " was successfully added.");
} else {
return new MagicCommandOutput(ERROR, "Magic command have to implement " + MagicCommandFunctionality.class + " interface.");
}
} catch (Exception e) {
return new MagicCommandOutput(ERROR, e.toString());
}
}
Aggregations