Exemple #1
0
 private BundleContext bundleContextOfCommand(final Class<Object> implementationClass) {
   for (final BeanEntry<Annotation, Injector> beanEntry :
       beanLocator.locate(Key.get(Injector.class))) {
     final Injector injector = beanEntry.getValue();
     try {
       injector.getBinding(implementationClass);
       // if we passed above it means that injector is the one for the implementation class
       return injector.getInstance(BundleContext.class);
     } catch (ConfigurationException ignore) {
     }
   }
   return null;
 }
Exemple #2
0
 private void registerFunction(final BeanEntry<Annotation, Object> beanEntry) {
   final Class<Object> implementationClass = beanEntry.getImplementationClass();
   final BindingProcessor processor = getBindingProcessor(implementationClass);
   if (processor != null) {
     final FunctionDescriptor descriptor = processor.process(beanEntry);
     final Properties commandProperties = new Properties();
     commandProperties.setProperty("osgi.command.scope", descriptor.getScope());
     commandProperties.setProperty("osgi.command.function", descriptor.getName());
     commandProperties.setProperty("implementationClass", implementationClass.getName());
     final BundleContext commandBundleContext = bundleContextOfCommand(implementationClass);
     if (commandBundleContext != null) {
       final ServiceRegistration serviceRegistration =
           commandBundleContext.registerService(
               new String[] {Function.class.getName(), CompletableFunction.class.getName()},
               descriptor.getFunction(),
               commandProperties);
       commands.put(
           beanEntry,
           new Holder(descriptor.getScope(), descriptor.getName(), serviceRegistration));
     }
     logger.debug(
         "Registered command '{}' in scope '{}'", descriptor.getName(), descriptor.getScope());
   }
 }