/** * The value of the annotation as a Class. * * @param annotation The annotation * @return An {@link Optional} class */ default @Nonnull Optional<Class> classValue(@Nonnull String annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return classValue(annotation, VALUE_MEMBER); }
@Override default @Nonnull Optional<Class> classValue(@Nonnull String annotation, @Nonnull String member) { return getAnnotationMetadata().classValue(annotation, member); }
/** * The value of the annotation as a Class. * * @param annotation The annotation * @return An {@link Optional} class */ default @Nonnull Optional<Class> classValue(@Nonnull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return classValue(annotation.getName()); }
@Override default @Nonnull Optional<Class> classValue(@Nonnull String annotation) { return getAnnotationMetadata().classValue(annotation); }
@Override default @Nonnull Optional<Class> classValue(@Nonnull Class<? extends Annotation> annotation) { return getAnnotationMetadata().classValue(annotation); }
@Override default @Nonnull Optional<Class> classValue(@Nonnull Class<? extends Annotation> annotation, @Nonnull String member) { return getAnnotationMetadata().classValue(annotation, member); }
/** * The value of the annotation as a Class. * * @param annotation The annotation * @param member The annotation member * @return An {@link Optional} class */ default @Nonnull Optional<Class> classValue(@Nonnull Class<? extends Annotation> annotation, @Nonnull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return classValue(annotation.getName(), member); }
@Override public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) { Optional<Class> viewClass = request.getAttribute(HttpAttributes.ROUTE_MATCH, AnnotationMetadata.class) .flatMap(ann -> ann.classValue(JsonView.class)); final Publisher<MutableHttpResponse<?>> responsePublisher = chain.proceed(request); if (viewClass.isPresent()) { return Flowable.fromPublisher(responsePublisher).switchMap(response -> { final Optional<?> body = response.getBody(); if (body.isPresent()) { MediaTypeCodec codec = codecFactory.resolveJsonViewCodec(viewClass.get()); return Flowable.fromCallable(() -> { final byte[] encoded = codec.encode(body.get()); ((MutableHttpResponse) response).body(encoded); return response; }).subscribeOn(Schedulers.from(executorService)); } else { return Flowable.just(response); } }); } else { return responsePublisher; } } }
/** * <p>Build a qualifier for the given annotation. This qualifier will match a candidate under the following * circumstances:</p> * * <ul> * <li>If the <tt>type</tt> parameter is {@link Named} then the value of the {@link Named} annotation within the metadata is used to match the candidate by name</li> * <li>If the <tt>type</tt> parameter is {@link Type} then the value of the {@link Type} annotation is used to match the candidate by type</li> * </ul> * * @param metadata The metadata * @param type The annotation type * @param <T> The component type * @return The qualifier */ public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, String type) { if (Type.class.getName().equals(type)) { Optional<Class> aClass = metadata.classValue(type); if (aClass.isPresent()) { return byType(aClass.get()); } } else if (Named.class.getName().equals(type)) { Optional<String> value = metadata.getValue(type, String.class); if (value.isPresent()) { return byName(value.get()); } } return new AnnotationMetadataQualifier<>(metadata, type); }
/** * <p>Build a qualifier for the given annotation. This qualifier will match a candidate under the following * circumstances:</p> * * <ul> * <li>If the <tt>type</tt> parameter is {@link Named} then the value of the {@link Named} annotation within the metadata is used to match the candidate by name</li> * <li>If the <tt>type</tt> parameter is {@link Type} then the value of the {@link Type} annotation is used to match the candidate by type</li> * </ul> * * @param metadata The metadata * @param type The annotation type * @param <T> The component type * @return The qualifier */ public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, String type) { if (Type.class.getName().equals(type)) { Optional<Class> aClass = metadata.classValue(type); if (aClass.isPresent()) { return byType(aClass.get()); } } else if (Named.class.getName().equals(type)) { Optional<String> value = metadata.getValue(type, String.class); if (value.isPresent()) { return byName(value.get()); } } return new AnnotationMetadataQualifier<>(metadata, type); }
/** * Build a qualifier for the given annotation. * * @param metadata The metadata * @param type The annotation type * @param <T> The component type * @return The qualifier */ public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, Class<? extends Annotation> type) { if (Type.class == type) { Optional<Class> aClass = metadata.classValue(type); if (aClass.isPresent()) { return byType(aClass.get()); } } else if (Named.class == type) { Optional<String> value = metadata.getValue(type, String.class); if (value.isPresent()) { return byName(value.get()); } } return new AnnotationMetadataQualifier<>(metadata, type); }
/** * Build a qualifier for the given annotation. * * @param metadata The metadata * @param type The annotation type * @param <T> The component type * @return The qualifier */ public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, Class<? extends Annotation> type) { if (Type.class == type) { Optional<Class> aClass = metadata.classValue(type); if (aClass.isPresent()) { return byType(aClass.get()); } } else if (Named.class == type) { Optional<String> value = metadata.getValue(type, String.class); if (value.isPresent()) { return byName(value.get()); } } return new AnnotationMetadataQualifier<>(metadata, type); }