protected ServiceRegistration<?> newProcessor(ThreadIO tio, BundleContext context) { processor = new CommandProcessorImpl(tio); try { processor.addListener(new EventAdminListener(context)); } catch (NoClassDefFoundError error) { // Ignore the listener if EventAdmin package isn't present } // Setup the variables and commands exposed in an OSGi environment. processor.addConstant(CONTEXT, context); processor.addCommand("osgi", processor, "addCommand"); processor.addCommand("osgi", processor, "removeCommand"); processor.addCommand("osgi", processor, "eval"); return context.registerService(CommandProcessor.class.getName(), processor, null); }
@Override public Converter addingService(ServiceReference<Converter> reference) { Converter converter = super.addingService(reference); processor.addConverter(converter); return converter; }
@Override public void removedService(ServiceReference<Object> reference, List<Object> service) { Object scope = reference.getProperty(CommandProcessor.COMMAND_SCOPE); Object function = reference.getProperty(CommandProcessor.COMMAND_FUNCTION); if (scope != null && function != null) { Map<String, CommandProxy> proxyMap = proxies.remove(reference); for (Map.Entry<String, CommandProxy> entry : proxyMap.entrySet()) { processor.removeCommand(scope.toString(), entry.getKey(), entry.getValue()); } } super.removedService(reference, service); } };
public void addCommand(String scope, Object target, Class<?> functions, int ranking) { if (target == null) { return; } String[] names = getFunctions(functions); for (String function : names) { addCommand(scope, target, function, ranking); } }
tio.start(); try { CommandProcessorImpl processor = new CommandProcessorImpl(tio); Context context = new MyContext(); Shell shell = new Shell(context, processor, tio, null); processor.addCommand("gogo", processor, "addCommand"); processor.addCommand("gogo", processor, "removeCommand"); processor.addCommand("gogo", processor, "eval"); processor.addConverter(new BaseConverters()); register(processor, new Builtin(), Builtin.functions); register(processor, new Procedural(), Procedural.functions); CommandSession session = processor.createSession(in, out, out); session.put(Shell.VAR_CONTEXT, context); session.put(Shell.VAR_TERMINAL, terminal);
static void register(CommandProcessorImpl processor, Object target, String[] functions) { for (String function : functions) { processor.addCommand("gogo", target, function); } }
List<String> commands = Lists.newArrayList(commandProcessor.getCommands()); Collections.sort(commands); if (!commands.contains(args[0])) { CommandSession session = commandProcessor.createSession(in, out, err); session.put("USER", user); session.put("APPLICATION", application);
sessionFactory.getCommandProcessor().addConverter(new Converters(context)); sessionFactory.getCommandProcessor().addConstant(".context", context.getBundle(0).getBundleContext()); LoggingCommandSessionListener loggingCommandSessionListener = new LoggingCommandSessionListener(); loggingCommandSessionListener.setFilters(listeners); sessionFactory.getCommandProcessor().addListener(loggingCommandSessionListener); sessionFactory.getCommandProcessor().addListener(listener); eventAdminListener = listener; } catch (NoClassDefFoundError error) {
return processor.getCommands(); return processor.getCommand(name, variables.get("SCOPE"));
/** * Use this method when the shell is being executed as a top level shell. * * @param args * @throws Exception */ public void run(String args[]) throws Exception { ThreadIOImpl threadio = new ThreadIOImpl(); threadio.start(); ClassLoader cl = Main.class.getClassLoader(); //This is a workaround for windows machines struggling with long class paths. loadJarsFromPath(new File(System.getProperty(KARAF_HOME), "system")); loadJarsFromPath(new File(System.getProperty(KARAF_HOME), "deploy")); CommandProcessorImpl commandProcessor = new CommandProcessorImpl(threadio); discoverCommands(commandProcessor, cl); InputStream in = unwrap(System.in); PrintStream out = wrap(unwrap(System.out)); PrintStream err = wrap(unwrap(System.err)); run(commandProcessor, args, in, out, err); }
@Override public void removedService(ServiceReference<Converter> reference, Converter service) { processor.removeConverter(service); super.removedService(reference, service); } };
@Override public void removedService(ServiceReference reference, Object service) { processor.removeListener((CommandSessionListener) service); super.removedService(reference, service); } };
@Override public CommandSessionListener addingService(ServiceReference<CommandSessionListener> reference) { CommandSessionListener listener = super.addingService(reference); processor.addListener(listener); return listener; }
public void addCommand(String scope, Object target, String function) { addCommand(scope, target, function, 0); }
public void addCommand(String scope, Object target, Class<?> functions, int ranking) { if (target == null) { return; } String[] names = getFunctions(functions); for (String function : names) { addCommand(scope, target, function, ranking); } }
commandProcessor.getCommands()); Collections.sort(commands); if (!commands.contains(args[0])) { CommandSession session = commandProcessor.createSession(in, out, err); session.put("USER", user); session.put("APPLICATION", application);
sessionFactory.getCommandProcessor().addConverter(new Converters(context)); sessionFactory.getCommandProcessor().addConstant(".context", context.getBundle(0).getBundleContext()); LoggingCommandSessionListener loggingCommandSessionListener = new LoggingCommandSessionListener(); loggingCommandSessionListener.setFilters(listeners); sessionFactory.getCommandProcessor().addListener(loggingCommandSessionListener); sessionFactory.getCommandProcessor().addListener(listener); eventAdminListener = listener; } catch (NoClassDefFoundError error) {
return processor.getCommands(); return processor.getCommand(name, variables.get("SCOPE"));
/** * Use this method when the shell is being executed as a top level shell. * * @param args * @throws Exception */ public void run(String args[]) throws Exception { ThreadIOImpl threadio = new ThreadIOImpl(); threadio.start(); ClassLoader cl = Main.class.getClassLoader(); //This is a workaround for windows machines struggling with long class paths. loadJarsFromPath(new File(System.getProperty(KARAF_HOME), "system")); loadJarsFromPath(new File(System.getProperty(KARAF_HOME), "deploy")); CommandProcessorImpl commandProcessor = new CommandProcessorImpl(threadio); discoverCommands(commandProcessor, cl); InputStream in = unwrap(System.in); PrintStream out = wrap(unwrap(System.out)); PrintStream err = wrap(unwrap(System.err)); run(commandProcessor, args, in, out, err); }
@Override public void removedService(ServiceReference<Converter> reference, Converter service) { processor.removeConverter(service); super.removedService(reference, service); } };