コード例 #1
0
 /**
  * Creates {@link TaskDescriptor} for given Task's bean entry class. To be used for tasks without
  * descriptors, it will create one on the fly with defaults.
  */
 private <T extends Task> TaskDescriptor<T> createTaskDescriptor(
     final BeanEntry<Named, Task> taskBeanEntry) {
   final String taskName =
       taskBeanEntry.getDescription() != null
           ? taskBeanEntry.getDescription()
           : taskBeanEntry.getImplementationClass().getSimpleName();
   // by default, tasks w/o descriptors are not exposed, and not visible while run/scheduled
   return new TaskDescriptorSupport<T>(
       (Class<T>) taskBeanEntry.getImplementationClass(), taskName, false, false) {};
 }
コード例 #2
0
 @Override
 public Object createResource(
     final HttpRequest request,
     final HttpResponse response,
     final ResteasyProviderFactory factory) {
   final Object resource = entry.getValue();
   propertyInjector.inject(request, response, resource);
   return resource;
 }
コード例 #3
0
 @Override
 public <T extends Task> T createTaskInstance(final TaskConfiguration taskConfiguration)
     throws IllegalArgumentException {
   checkNotNull(taskConfiguration);
   taskConfiguration.validate();
   log.debug("Creating task by hint: {}", taskConfiguration);
   final TaskDescriptor<T> taskDescriptor =
       getTaskDescriptorByTypeId(taskConfiguration.getTypeId());
   for (BeanEntry<Named, Task> entry : tasks) {
     if (entry.getImplementationClass().equals(taskDescriptor.getType())) {
       final T task = (T) entry.getProvider().get();
       task.configure(taskConfiguration);
       return task;
     }
   }
   throw new IllegalArgumentException(
       "No Task of type \'" + taskConfiguration.getTypeId() + "\' found");
 }
コード例 #4
0
 @Override
 public <T extends Task> TaskDescriptor<T> resolveTaskDescriptorByTypeId(final String taskTypeId) {
   // look for descriptors first
   for (TaskDescriptor<?> taskDescriptor : taskDescriptors) {
     if (taskDescriptor.getId().equals(taskTypeId)) {
       return (TaskDescriptor<T>) taskDescriptor;
     }
   }
   // not found by descriptor, try tasks directly
   for (BeanEntry<Named, Task> entry : tasks) {
     // checks: task FQCN, task SimpleName or @Named
     if (entry.getImplementationClass().getName().equals(taskTypeId)
         || entry.getImplementationClass().getSimpleName().equals(taskTypeId)
         || entry.getKey().value().equals(taskTypeId)) {
       return (TaskDescriptor<T>) findTaskDescriptor(entry);
     }
   }
   return null;
 }
コード例 #5
0
 /**
  * Returns {@link TaskDescriptor} by given Task's bean entry. Will perform a search for provided
  * task descriptors, and if not found, will create one using {@link
  * #createTaskDescriptor(BeanEntry)}.
  */
 private <T extends Task> TaskDescriptor<T> findTaskDescriptor(
     final BeanEntry<Named, Task> taskBeanEntry) {
   // look for descriptor first
   for (TaskDescriptor<?> taskDescriptor : taskDescriptors) {
     if (taskDescriptor.getType().equals(taskBeanEntry.getImplementationClass())) {
       return (TaskDescriptor<T>) taskDescriptor;
     }
   }
   // not found by descriptor, create one for it
   return (TaskDescriptor<T>) createTaskDescriptor(taskBeanEntry);
 }
コード例 #6
0
 /**
  * Returns a map with "typeId" Task descriptor mapping for all existing tasks. For tasks without
  * descriptors, descriptor will be created.
  */
 private Map<String, TaskDescriptor<?>> allTaskDescriptors() {
   // TODO: consistency checks? a) task : descriptors are 1:1, b) descriptor IDs are unique?
   // TODO: we might emit warning if some of those does not stand
   // using task class as "key" to detect tasks w/ descriptor vs tasks w/o descriptor
   final Map<Class<? extends Task>, TaskDescriptor<?>> descriptorMap = Maps.newHashMap();
   for (TaskDescriptor<?> taskDescriptor : taskDescriptors) {
     descriptorMap.put(taskDescriptor.getType(), taskDescriptor);
   }
   for (BeanEntry<Named, Task> entry : tasks) {
     if (!descriptorMap.containsKey(entry.getImplementationClass())) {
       final TaskDescriptor<?> taskDescriptor = createTaskDescriptor(entry);
       descriptorMap.put(taskDescriptor.getType(), taskDescriptor);
     }
   }
   // repack the map into result map keyed by typeId
   final Map<String, TaskDescriptor<?>> result = Maps.newHashMap();
   for (TaskDescriptor<?> taskDescriptor : descriptorMap.values()) {
     result.put(taskDescriptor.getId(), taskDescriptor);
   }
   return result;
 }
コード例 #7
0
    @Override
    public void add(final BeanEntry<Named, Action> beanEntry, final BundleContext bundleContext)
        throws Exception {
      Command command = beanEntry.getImplementationClass().getAnnotation(Command.class);
      if (command != null) {
        // TODO: warn if @Singleton is present, this is probably not desired due to
        // @Option/@Argument processing ?

        Dictionary<String, ?> config = CommandHelper.config(command);
        log.debug("Adding action: {}, config: {}", beanEntry, config);
        bundleContext.registerService(
            Function.class, new BeanEntryCommand(beanLocator, beanEntry), config);
      } else {
        log.warn("Missing @Command annotation on action: {}", beanEntry);
      }
    }
コード例 #8
0
 public void add(final BeanEntry<Marked, Item> bean, final MarkedItemWatcher watcher)
     throws Exception {
   assertNull(watcher.items.put(Integer.valueOf(bean.getKey().value()), bean.getValue()));
 }
コード例 #9
0
 public void remove(
     final BeanEntry<javax.inject.Named, Item> bean, final NamedItemWatcher watcher)
     throws Exception {
   assertEquals(watcher.items.remove(bean.getKey().value()), bean.getValue());
 }
コード例 #10
0
 public void add(final BeanEntry<javax.inject.Named, Item> bean, final NamedItemWatcher watcher)
     throws Exception {
   assertNull(watcher.items.put(bean.getKey().value(), bean.getValue()));
 }
コード例 #11
0
 public void remove(final BeanEntry<Annotation, Item> bean, final AnnotatedItemWatcher watcher)
     throws Exception {
   assertEquals(watcher.items.remove(bean.getKey()), bean.getValue());
 }
コード例 #12
0
 public void add(final BeanEntry<Annotation, Item> bean, final AnnotatedItemWatcher watcher)
     throws Exception {
   assertNull(watcher.items.put(bean.getKey(), bean.getValue()));
 }
コード例 #13
0
 public void remove(final BeanEntry<Marked, Item> bean, final MarkedItemWatcher watcher)
     throws Exception {
   assertEquals(watcher.items.remove(Integer.valueOf(bean.getKey().value())), bean.getValue());
 }
コード例 #14
0
 @Override
 public Class<?> getScannableClass() {
   return entry.getImplementationClass();
 }
コード例 #15
0
 public void remove(
     final BeanEntry<Named, RepositoryTypeDescriptor> entry,
     final RepositoryTypeRegistry registry) {
   registry.unregisterRepositoryTypeDescriptors(entry.getValue());
 }
コード例 #16
0
 public void add(final BeanEntry<Named, Filter> entry, final FilterChainManager manager) {
   manager.addFilter(entry.getKey().value(), entry.getValue(), true);
 }