private String getClientId(AnnotationValue<Client> clientAnn) { String clientId = clientAnn.getValue(String.class).orElse(null); if (clientId == null) { throw new HttpClientException("Either the id or value of the @Client annotation must be specified"); } return clientId; }
/** * Get the value of the {@code value} member of the annotation. * * @param argument The argument * @param <T> The type * @return The result */ public final <T> Optional<T> getValue(Argument<T> argument) { return getValue(ConversionContext.of(argument)); }
/** * Get the value of the {@code value} member of the annotation. * * @param type The type * @param <T> The type * @return The result */ public final <T> Optional<T> getValue(Class<T> type) { return getValue(ConversionContext.of(type)); }
/** * Resolve the template for the client annotation. * * @param clientAnnotation client annotation reference * @param templateString template to be applied * @return resolved template contents */ private String resolveTemplate(AnnotationValue<Client> clientAnnotation, String templateString) { String path = clientAnnotation.get("path", String.class).orElse(null); if (StringUtils.isNotEmpty(path)) { return path + templateString; } else { String value = clientAnnotation.getValue(String.class).orElse(null); if (StringUtils.isNotEmpty(value)) { if (value.startsWith("/")) { return value + templateString; } } return templateString; } }
String[] patterns = filterAnn.getValue(String[].class).orElse(StringUtils.EMPTY_STRING_ARRAY); if (patterns.length == 0) { filterList.add(filter);
throw new DependencyInjectionException(resolutionContext, argument, "ClientScope called with invalid bean provider"); String value = annotation.getValue(String.class).orElseThrow(() -> new DependencyInjectionException(resolutionContext, argument, "No value specified for @Client") );
String clientId = clientAnnotation.getValue(String.class).orElse(null); String path = clientAnnotation.get("path", String.class).orElse(null); String clientKey = computeClientKey(clientId, path); for (AnnotationValue<Header> headerAnnotation : headerAnnotations) { String headerName = headerAnnotation.get("name", String.class).orElse(null); String headerValue = headerAnnotation.getValue(String.class).orElse(null); if (StringUtils.isNotEmpty(headerName) && StringUtils.isNotEmpty(headerValue)) { headers.put(headerName, headerValue); .flatMap(versionAnnotation -> versionAnnotation.getValue(String.class)) .filter(StringUtils::isNotEmpty) .ifPresent(version -> { for (AnnotationValue<RequestAttribute> attributeAnnotation : attributeAnnotations) { String attributeName = attributeAnnotation.get("name", String.class).orElse(null); Object attributeValue = attributeAnnotation.getValue(Object.class).orElse(null); if (StringUtils.isNotEmpty(attributeName) && attributeValue != null) { attributes.put(attributeName, attributeValue); String serviceId = clientAnnotation.getValue(String.class).orElse(null); Argument<?> errorType = clientAnnotation.get("errorType", Class.class).map((Function<Class, Argument>) Argument::of).orElse(HttpClient.DEFAULT_ERROR_TYPE); request.setAttribute(HttpAttributes.SERVICE_ID, serviceId);
private String computePath(AnnotationValue<Annotation> annotation) { return annotation.getValue(String.class).orElseGet(() -> annotation.get("path", String.class).orElse("/")); } }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final boolean lazy = annotation.getValue(Boolean.class).orElse(true); if (!lazy) { return Collections.singletonList( AnnotationValue.builder(Context.class).build() ); } return Collections.emptyList(); } }
/** * Default constructor. * @param delegate The parameter to delegate to */ RouteParameterElement(ParameterElement delegate) { this.delegate = delegate; this.name = delegate.findAnnotation(Bindable.class).flatMap(av -> av.getValue(String.class)).orElse(delegate.getName()); }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final AnnotationValueBuilder<Async> builder = AnnotationValue.builder(Async.class); annotation.getValue(String.class).ifPresent(builder::value); return Collections.singletonList(builder.build()); } }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { Optional<String[]> value = annotation.getValue(String[].class); return value.<List<AnnotationValue<?>>>map(strings -> Collections.singletonList( AnnotationValue.builder(Requires.class) .member("env", strings).build() )).orElse(Collections.emptyList()); }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final Optional<String> value = annotation.getValue(String.class); if (value.isPresent()) { return Collections.singletonList( AnnotationValue.builder(Value.class) .value(value.get()) .build() ); } return Collections.emptyList(); } }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final Optional<String> value = annotation.getValue(String.class); if (value.isPresent()) { return Collections.singletonList( AnnotationValue.builder(Named.class) .value(value.get()) .build() ); } return Collections.emptyList(); } }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final AnnotationValueBuilder<Error> builder = AnnotationValue.builder(Error.class); annotation.getValue(AnnotationClassValue.class).ifPresent(annotationClassValue -> builder.member("value", annotationClassValue)); return Collections.singletonList( builder .build() ); }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final boolean required = annotation.getValue(Boolean.class).orElse(true); List<AnnotationValue<?>> annotations = new ArrayList<>(2); annotations.add(AnnotationValue.builder(Inject.class).build()); if (!required) { annotations.add(AnnotationValue.builder(Nullable.class).build()); } return annotations; } }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final String[] cacheNames = annotation.getValue(String[].class).orElseGet(() -> annotation.get("cacheNames", String[].class).orElse(null)); if (cacheNames != null) { final AnnotationValueBuilder<?> builder = buildAnnotation() .member("value", cacheNames) .member("cacheNames", cacheNames); return Collections.singletonList(builder.build()); } return Collections.emptyList(); }
@Override public boolean matches(ConditionContext context) { final Class<?> type = context.getComponent().findAnnotation(RequiresSingleCandidate.class).flatMap(ann -> ann.getValue(Class.class)).orElse(null); if (type != null) { final BeanContext beanContext = context.getBeanContext(); return beanContext.findBeanDefinition(type).isPresent(); } return true; } }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { try { final String code = annotation.getValue(String.class).orElse(annotation.get("code", String.class).orElse(null)); final HttpStatus status = HttpStatus.valueOf(code); return Collections.singletonList( AnnotationValue.builder(Status.class).value(status).build() ); } catch (IllegalArgumentException e) { // ignore } return Collections.emptyList(); } }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final Optional<String> beanName = annotation.getValue(String.class); List<AnnotationValue<?>> mappedAnnotations = new ArrayList<>(2); mappedAnnotations.add(AnnotationValue.builder(Bean.class).build()); mappedAnnotations.add(AnnotationValue.builder(DefaultScope.class) .value(Singleton.class) .build()); beanName.ifPresent(s -> mappedAnnotations.add(AnnotationValue.builder(Named.class).value(s).build())); return mappedAnnotations; } }