Search in sources :

Example 1 with MagicCommandFunctionality

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());
    }
}
Also used : MagicCommandOutput(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput) MagicCommandFunctionality(com.twosigma.beakerx.kernel.magic.command.MagicCommandFunctionality) MagicCommandType(com.twosigma.beakerx.kernel.magic.command.MagicCommandType)

Aggregations

MagicCommandFunctionality (com.twosigma.beakerx.kernel.magic.command.MagicCommandFunctionality)1 MagicCommandType (com.twosigma.beakerx.kernel.magic.command.MagicCommandType)1 MagicCommandOutput (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput)1