@Override public Object execute(CommandSession session) throws Exception { try { return super.execute(session); } finally { ungetServices(); } }
public void complete(final Completer completer, final String buffer, final int cursor) { assert completer != null; this.cursor = completer.complete(buffer, cursor, candidates); } }
public String getValue(final String key) { for (HelpProvider hp : providers) { String result = hp.getHelp(session, key); if (result != null) { return removeNewLine(result); } } return null; } });
public int complete(String buffer, int cursor, List<String> candidates) { if (session == null) { session = CommandSessionHolder.getSession(); } checkData(); int res = new StringsCompleter(commands).complete(buffer, cursor, candidates); Collections.sort(candidates); return res; }
@Override public Action createNewAction() { Action action = (Action) blueprintContainer.getComponentInstance(actionId); if (action instanceof BlueprintContainerAware) { ((BlueprintContainerAware) action).setBlueprintContainer(blueprintContainer); } if (action instanceof BundleContextAware) { BundleContext context = (BundleContext) blueprintContainer.getComponentInstance("blueprintBundleContext"); ((BundleContextAware) action).setBundleContext(context); } return action; }
public CommandsCompleter() { this(CommandSessionHolder.getSession()); }
private String[] getNames(CommandSession session, String scopedCommand) { String command = NameScoping.getCommandNameWithoutGlobalPrefix(session, scopedCommand); String[] s = command.split(":"); if (s.length == 1) { return s; } else { return new String[] { command, s[1] }; } }
protected <T> T getService(Class<T> clazz) { ServiceReference<T> sr = getBundleContext().getServiceReference(clazz); if (sr != null) { return getService(clazz, sr); } else { return null; } }
protected void ungetServices() { if (usedReferences != null) { for (ServiceReference<?> ref : usedReferences) { getBundleContext().ungetService(ref); } } }
public Object execute(CommandSession session) throws Exception { this.session = session; return doExecute(); }
protected <T> List<T> getAllServices(Class<T> clazz) { try { return getAllServices(clazz, null); } catch (InvalidSyntaxException e) { throw new IllegalStateException(e); } }
@Override public int complete(String buffer, int cursor, List<String> candidates) { ServiceReference<? extends Completer> ref = context.getServiceReference(clazz); if (ref != null) { Completer completer = context.getService(ref); if (completer != null) { try { return completer.complete(buffer, cursor, candidates); } finally { context.ungetService(ref); } } } return -1; } }
public Action createNewAction() { Action action = (Action) blueprintContainer.getComponentInstance(actionId); if (action instanceof BlueprintContainerAware) { ((BlueprintContainerAware) action).setBlueprintContainer(blueprintContainer); } if (action instanceof BundleContextAware) { BundleContext context = (BundleContext) blueprintContainer.getComponentInstance("blueprintBundleContext"); ((BundleContextAware) action).setBundleContext(context); } return action; }
public CommandNamesCompleter() { this(CommandSessionHolder.getSession()); }
private String[] getNames(CommandSession session, String scopedCommand) { String command = NameScoping.getCommandNameWithoutGlobalPrefix(session, scopedCommand); String[] s = command.split(":"); if (s.length == 1) { return s; } else { return new String[] { command, s[1] }; } }
protected <T> List<T> getAllServices(Class<T> clazz, String filter) throws InvalidSyntaxException { Collection<ServiceReference<T>> references = getBundleContext().getServiceReferences(clazz, filter); List<T> services = new ArrayList<>(); if (references != null) { for (ServiceReference<T> ref : references) { T t = getService(clazz, ref); services.add(t); } } return services; }
protected <T> T getService(Class<T> clazz, ServiceReference<T> reference) { T t = getBundleContext().getService(reference); if (t != null) { if (usedReferences == null) { usedReferences = new ArrayList<>(); } usedReferences.add(reference); } return t; }
@Override public int complete(String buffer, int cursor, List<String> candidates) { ServiceReference<? extends Completer> ref = context.getServiceReference(clazz); if (ref != null) { Completer completer = context.getService(ref); if (completer != null) { try { return completer.complete(buffer, cursor, candidates); } finally { context.ungetService(ref); } } } return -1; } }
private String[] getNames(CommandSession session, String scopedCommand) { String command = NameScoping.getCommandNameWithoutGlobalPrefix(session, scopedCommand); String[] s = command.split(":"); if (s.length == 1) { return s; } else { return new String[] { command, s[1] }; } }
protected boolean verifyCompleter(Completer completer, String argument) { List<String> candidates = new ArrayList<>(); return completer.complete(argument, argument.length(), candidates) != -1 && !candidates.isEmpty(); }