예제 #1
0
 @Override
 public void visitInvocable(final Invocable invocable) {
   // TODO: check invocable.
   Class resClass = invocable.getHandler().getHandlerClass();
   if (resClass != null && !checkedClasses.contains(resClass)) {
     checkedClasses.add(resClass);
     final boolean provider = Providers.isProvider(resClass);
     int counter = 0;
     for (Annotation annotation : resClass.getAnnotations()) {
       if (SCOPE_ANNOTATIONS.contains(annotation.annotationType())) {
         counter++;
       }
     }
     if (counter == 0 && provider) {
       Errors.warning(
           resClass,
           LocalizationMessages.RESOURCE_IMPLEMENTS_PROVIDER(
               resClass, Providers.getProviderContracts(resClass)));
     } else if (counter > 1) {
       Errors.fatal(resClass, LocalizationMessages.RESOURCE_MULTIPLE_SCOPE_ANNOTATIONS(resClass));
     }
   }
 }
  private ResourceMethodInvoker(
      Provider<RoutingContext> routingContextFactory,
      Provider<ProcessingContext> invocationContextFactory,
      ResourceMethodDispatcher.Provider dispatcherProvider,
      ResourceMethodInvocationHandlerProvider invocationHandlerProvider,
      ResourceMethod method,
      MultivaluedMap<Class<? extends Annotation>, ContainerRequestFilter> nameBoundRequestFilters,
      MultivaluedMap<Class<? extends Annotation>, ContainerResponseFilter> nameBoundResponseFilters,
      Collection<ReaderInterceptor> globalReaderInterceptors,
      Collection<WriterInterceptor> globalWriterInterceptors,
      MultivaluedMap<Class<? extends Annotation>, ReaderInterceptor> nameBoundReaderInterceptors,
      MultivaluedMap<Class<? extends Annotation>, WriterInterceptor> nameBoundWriterInterceptors,
      Collection<DynamicBinder> dynamicBinders) {

    this.routingContextFactory = routingContextFactory;
    this.invocationContextFactory = invocationContextFactory;

    this.method = method;
    final Invocable invocable = method.getInvocable();
    this.dispatcher =
        dispatcherProvider.create(invocable, invocationHandlerProvider.create(invocable));

    this.resourceMethod = invocable.getHandlingMethod();
    this.resourceClass = invocable.getHandler().getHandlerClass();

    List<ReaderInterceptor> _readerInterceptors = new LinkedList<ReaderInterceptor>();
    List<WriterInterceptor> _writerInterceptors = new LinkedList<WriterInterceptor>();

    for (DynamicBinder dynamicBinder : dynamicBinders) {
      Object boundProvider = dynamicBinder.getBoundProvider(this);

      // TODO: should be based on the type arg. value rather than instanceof?
      if (boundProvider instanceof WriterInterceptor) {
        _writerInterceptors.add((WriterInterceptor) boundProvider);
      }

      if (boundProvider instanceof ReaderInterceptor) {
        _readerInterceptors.add((ReaderInterceptor) boundProvider);
      }

      if (boundProvider instanceof ContainerRequestFilter) {
        this.requestFilters.add((ContainerRequestFilter) boundProvider);
      }

      if (boundProvider instanceof ContainerResponseFilter) {
        this.responseFilters.add((ContainerResponseFilter) boundProvider);
      }
    }

    _readerInterceptors.addAll(globalReaderInterceptors);
    _writerInterceptors.addAll(globalWriterInterceptors);

    if (resourceMethod != null) {
      addNameBoundFiltersAndInterceptors(
          nameBoundRequestFilters,
          nameBoundResponseFilters,
          nameBoundReaderInterceptors,
          nameBoundWriterInterceptors,
          this.requestFilters,
          this.responseFilters,
          _readerInterceptors,
          _writerInterceptors,
          method);
    }

    Collections.sort(
        _readerInterceptors,
        new PriorityComparator<ReaderInterceptor>(PriorityComparator.Order.ASCENDING));
    Collections.sort(
        _writerInterceptors,
        new PriorityComparator<WriterInterceptor>(PriorityComparator.Order.ASCENDING));

    this.readerInterceptors = Collections.unmodifiableList(_readerInterceptors);
    this.writerInterceptors = Collections.unmodifiableList(_writerInterceptors);
  }