/** * Get the value of the {@code value} member of the annotation. * * @param conversionContext The conversion context * @param <T> The type * @return The result */ public <T> Optional<T> getValue(ArgumentConversionContext<T> conversionContext) { return get(AnnotationMetadata.VALUE_MEMBER, conversionContext); }
/** * Gets a list of {@link AnnotationValue} for the given member. * * @param member The member * @param type The type * @param <T> The type * @throws IllegalStateException If no member is available that conforms to the given name and type * @return The result */ public @Nonnull final <T extends Annotation> List<AnnotationValue<T>> getAnnotations(String member, Class<T> type) { AnnotationValue[] values = get(member, AnnotationValue[].class).orElse(null); if (ArrayUtils.isNotEmpty(values)) { List<AnnotationValue<T>> list = new ArrayList<>(values.length); String typeName = type.getName(); for (AnnotationValue value : values) { if (value == null) { continue; } if (value.getAnnotationName().equals(typeName)) { //noinspection unchecked list.add(value); } } return list; } return Collections.emptyList(); }
/** * 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; } }
if (Closeable.class == declaringType || AutoCloseable.class == declaringType) { String clientId = clientAnnotation.getValue(String.class).orElse(null); String path = clientAnnotation.get("path", String.class).orElse(null); String clientKey = computeClientKey(clientId, path); clients.remove(clientKey); String headerName = headerAnnotation.get("name", String.class).orElse(null); String headerValue = headerAnnotation.getValue(String.class).orElse(null); if (StringUtils.isNotEmpty(headerName) && StringUtils.isNotEmpty(headerValue)) { String attributeName = attributeAnnotation.get("name", String.class).orElse(null); Object attributeValue = attributeAnnotation.getValue(Object.class).orElse(null); if (StringUtils.isNotEmpty(attributeName) && attributeValue != 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);
if (filterOpt.isPresent()) { AnnotationValue<Filter> filterAnn = filterOpt.get(); String[] clients = filterAnn.get("serviceId", String[].class).orElse(null); if (!clientIdentifiers.isEmpty() && ArrayUtils.isNotEmpty(clients)) { if (Arrays.stream(clients).noneMatch(id -> clientIdentifiers.contains(id))) { io.micronaut.http.HttpMethod[] methods = filterAnn.get("methods", io.micronaut.http.HttpMethod[].class, null); if (ArrayUtils.isNotEmpty(methods)) { if (!Arrays.asList(methods).contains(method)) {
/** * Get the value of the {@code value} member of the annotation. * * @param member The member * @param type The type * @param <T> The type * @throws IllegalStateException If no member is available that conforms to the given name and type * @return The result */ public @Nonnull final <T> T getRequiredValue(String member, Class<T> type) { return get(member, ConversionContext.of(type)).orElseThrow(() -> new IllegalStateException("No value available for annotation member @" + annotationName + "[" + member + "] of type: " + type)); }
String annotationPath = annotation.get("path", String.class).orElse(null); if (StringUtils.isNotEmpty(annotationPath)) { contextPath = annotationPath; Class<?> configurationClass = annotation.get("configuration", Class.class).orElse(HttpClientConfiguration.class); Object bean = beanContext.getBean(configurationClass);
List<? extends AnnotationValue<? extends Annotation>> values = getAnnotationValuesByType(annotation); if (!values.isEmpty()) { return values.iterator().next().get(member, requiredType); } else { return Optional.empty(); Optional<T> value = values.flatMap(av -> av.get(member, requiredType)); if (!value.isPresent()) { if (hasStereotype(annotation)) {
@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(); }
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @param requiredType The required type * @param <T> The value * @return An {@link Optional} of the value */ default @Nonnull <T> Optional<T> getValue(@Nonnull String annotation, @Nonnull String member, @Nonnull Argument<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); ArgumentUtils.requireNonNull("requiredType", requiredType); Optional<T> value = findAnnotation(annotation).flatMap(av -> av.get(member, requiredType)); if (!value.isPresent()) { if (hasStereotype(annotation)) { return getDefaultValue(annotation, member, requiredType); } } return value; }
String path = clientAnn.get("path", String.class).orElse(null); String clientKey = computeClientKey(clientId, path); if (clientKey == null) { Qualifiers.byName(clientId) ); Class<HttpClientConfiguration> defaultConfiguration = clientAnn.get("configuration", Class.class).orElse(HttpClientConfiguration.class); configuration = clientSpecificConfig.orElseGet(() -> beanContext.getBean(defaultConfiguration)); HttpClient client = beanContext.createBean(HttpClient.class, loadBalancer, configuration, contextPath); SerializationFeature[] enabledSerializationFeatures = jacksonFeatures.get("enabledSerializationFeatures", SerializationFeature[].class).orElse(null); if (enabledSerializationFeatures != null) { for (SerializationFeature serializationFeature : enabledSerializationFeatures) { DeserializationFeature[] enabledDeserializationFeatures = jacksonFeatures.get("enabledDeserializationFeatures", DeserializationFeature[].class).orElse(null); SerializationFeature[] disabledSerializationFeatures = jacksonFeatures.get("disabledSerializationFeatures", SerializationFeature[].class).orElse(null); if (disabledSerializationFeatures != null) { for (SerializationFeature serializationFeature : disabledSerializationFeatures) { DeserializationFeature[] disabledDeserializationFeatures = jacksonFeatures.get("disabledDeserializationFeatures", DeserializationFeature[].class).orElse(null);
private String[] resolveCacheNames(AnnotationValue<CacheConfig> defaultConfig, AnnotationValue<Cacheable> cacheConfig) { String[] cacheNames = cacheConfig.get(MEMBER_CACHE_NAMES, String[].class).orElse(null); if (ArrayUtils.isEmpty(cacheNames)) { cacheNames = defaultConfig.get(MEMBER_CACHE_NAMES, String[].class).orElse(StringUtils.EMPTY_STRING_ARRAY); } return cacheNames; }
private CacheKeyGenerator resolveKeyGenerator(CacheKeyGenerator defaultKeyGenerator, AnnotationValue<Cacheable> cacheConfig) { CacheKeyGenerator keyGenerator = defaultKeyGenerator; Class<? extends CacheKeyGenerator> alternateKeyGen = cacheConfig.get(MEMBER_KEY_GENERATOR, Class.class).orElse(null); if (alternateKeyGen != null && keyGenerator.getClass() != alternateKeyGen) { keyGenerator = resolveKeyGenerator(alternateKeyGen); } return keyGenerator; }
private String[] getCacheNames(String[] cacheNames) { if (ArrayUtils.isEmpty(cacheNames)) { return defaultConfig.get(MEMBER_CACHE_NAMES, String[].class).orElse(StringUtils.EMPTY_STRING_ARRAY); } else { return cacheNames; } }
@SuppressWarnings("unchecked") private Set<Class<? extends Throwable>> resolveIncludes(AnnotationValue<Retryable> retry, String includes) { return retry .get(includes, Argument.of(Set.class, Argument.of(Class.class, Throwable.class))) .orElse(Collections.emptySet()); } }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final Optional<String> id = annotation.get("id", String.class); if (id.isPresent()) { final AnnotationValueBuilder<?> builder = AnnotationValue.builder("io.micronaut.management.endpoint.annotation.Endpoint"); final Boolean enableByDefault = annotation.get("enableByDefault", boolean.class).orElse(true); builder.value(id.get()); builder.member("id",id.get()); builder.member("defaultEnabled", enableByDefault); return Collections.singletonList(builder.build()); } return Collections.emptyList(); }
private void processCachePut(MethodInvocationContext<?, ?> context, ValueWrapper wrapper, AnnotationValue<CachePut> cacheConfig, CacheOperation cacheOperation) { String[] cacheNames = cacheOperation.getCachePutNames(cacheConfig); CacheKeyGenerator keyGenerator = cacheOperation.getCachePutKeyGenerator(cacheConfig); String[] parameterNames = cacheConfig.get(MEMBER_PARAMETERS, String[].class, StringUtils.EMPTY_STRING_ARRAY); Object[] parameterValues = resolveParams(context, parameterNames); boolean isAsync = cacheConfig.get(MEMBER_ASYNC, Boolean.class, false); processCachePut(context, wrapper, cacheNames, keyGenerator, parameterValues, isAsync); }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final String[] produces = annotation.get("produces", String[].class).orElse(null); final AnnotationValue<?> readOp = AnnotationValue.builder("io.micronaut.management.endpoint.annotation." + operationName()).build(); List<AnnotationValue<?>> annotationValues = new ArrayList<>(2); annotationValues.add(readOp); if (produces != null) { final AnnotationValue<Produces> producesAnn = AnnotationValue.builder(Produces.class).member("value", produces).build(); annotationValues.add(producesAnn); } return annotationValues; }
private boolean matchesPresenceOfBeans(ConditionContext context, AnnotationValue<Requires> requirements) { Class[] beans = requirements.get("beans", Class[].class).orElse(null); if (ArrayUtils.isNotEmpty(beans)) { BeanContext beanContext = context.getBeanContext(); for (Class type : beans) { if (!beanContext.containsBean(type)) { context.fail("No bean of type [" + type + "] present within context"); return false; } } } return true; }
private boolean matchesPresenceOfBeans(ConditionContext context, AnnotationValue<Requires> requirements) { Class[] beans = requirements.get("beans", Class[].class).orElse(null); if (ArrayUtils.isNotEmpty(beans)) { BeanContext beanContext = context.getBeanContext(); for (Class type : beans) { if (!beanContext.containsBean(type)) { context.fail("No bean of type [" + type + "] present within context"); return false; } } } return true; }