Search in sources :

Example 1 with Closure

use of org.apache.felix.gogo.runtime.Closure in project karaf by apache.

the class SecuredCommand method execute.

@Override
public Object execute(final CommandSession commandSession, List<Object> arguments) throws Exception {
    // TODO: remove the hack for .session
    Session session = (Session) commandSession.get(".session");
    // When need to translate closures to a compatible type for the command
    for (int i = 0; i < arguments.size(); i++) {
        Object v = arguments.get(i);
        if (v instanceof Closure) {
            final Closure closure = (Closure) v;
            arguments.set(i, new VersatileFunction(closure));
        }
        if (v instanceof Token) {
            arguments.set(i, v.toString());
        }
    }
    return execute(session, arguments);
}
Also used : Closure(org.apache.felix.gogo.runtime.Closure) Token(org.apache.felix.gogo.runtime.Token) Session(org.apache.karaf.shell.api.console.Session) CommandSession(org.apache.felix.service.command.CommandSession)

Example 2 with Closure

use of org.apache.felix.gogo.runtime.Closure in project karaf by apache.

the class CommandWrapper method execute.

@Override
public Object execute(final CommandSession commandSession, List<Object> arguments) throws Exception {
    // TODO: remove the hack for .session
    Session session = (Session) commandSession.get(".session");
    // When need to translate closures to a compatible type for the command
    for (int i = 0; i < arguments.size(); i++) {
        Object v = arguments.get(i);
        if (v instanceof Closure) {
            final Closure closure = (Closure) v;
            arguments.set(i, (org.apache.karaf.shell.api.console.Function) (s, a) -> closure.execute(commandSession, a));
        }
    }
    return command.execute(session, arguments);
}
Also used : Session(org.apache.karaf.shell.api.console.Session) List(java.util.List) Closure(org.apache.felix.gogo.runtime.Closure) Function(org.apache.felix.service.command.Function) CommandSession(org.apache.felix.service.command.CommandSession) Command(org.apache.karaf.shell.api.console.Command) Closure(org.apache.felix.gogo.runtime.Closure) Session(org.apache.karaf.shell.api.console.Session) CommandSession(org.apache.felix.service.command.CommandSession)

Aggregations

Closure (org.apache.felix.gogo.runtime.Closure)2 CommandSession (org.apache.felix.service.command.CommandSession)2 Session (org.apache.karaf.shell.api.console.Session)2 List (java.util.List)1 Token (org.apache.felix.gogo.runtime.Token)1 Function (org.apache.felix.service.command.Function)1 Command (org.apache.karaf.shell.api.console.Command)1