/** * Creates a new {@link DefaultProcessorWrapper} with the given {@link ResourceProcessor}. * * @param processor must not be {@literal null}. */ public DefaultProcessorWrapper(ResourceProcessor<?> processor) { Assert.notNull(processor); this.processor = processor; this.targetType = ResolvableType.forClass(ResourceProcessor.class, processor.getClass()).getGeneric(0); }
/** * Creates a new {@link ResourceProcessorInvoker} to consider the given {@link ResourceProcessor} * to post-process the controller methods return value to before invoking the delegate. * * @param processors the {@link ResourceProcessor}s to be considered, must not be {@literal null}. */ public ResourceProcessorInvoker(Collection<ResourceProcessor<?>> processors) { Assert.notNull(processors, "ResourceProcessors must not be null!"); this.processors = new ArrayList<ProcessorWrapper>(); for (ResourceProcessor<?> processor : processors) { ResolvableType processorType = ResolvableType.forClass(ResourceProcessor.class, processor.getClass()); Class<?> rawType = processorType.getGeneric(0).resolve(); if (Resource.class.isAssignableFrom(rawType)) { this.processors.add(new ResourceProcessorWrapper(processor)); } else if (Resources.class.isAssignableFrom(rawType)) { this.processors.add(new ResourcesProcessorWrapper(processor)); } else { this.processors.add(new DefaultProcessorWrapper(processor)); } } Collections.sort(this.processors, AnnotationAwareOrderComparator.INSTANCE); }