Java Code Examples for io.micronaut.core.reflect.InstantiationUtils

The following examples show how to use io.micronaut.core.reflect.InstantiationUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: micronaut-data   Source File: AbstractPersistentEntity.java    License: Apache License 2.0 6 votes vote down vote up
@NonNull
private Optional<NamingStrategy> getNamingStrategy(String name) {
    NamingStrategy namingStrategy = NAMING_STRATEGIES.get(name);
    if (namingStrategy != null) {
        return Optional.of(namingStrategy);
    } else {

        Object o = InstantiationUtils.tryInstantiate(name, getClass().getClassLoader()).orElse(null);
        if (o instanceof NamingStrategy) {
            NamingStrategy ns = (NamingStrategy) o;
            NAMING_STRATEGIES.put(name, ns);
            return Optional.of(ns);
        }
        return Optional.empty();
    }
}
 
Example 2
Source Project: micronaut-aws   Source File: AnnotatedRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
default boolean canHandle(HandlerInput handlerInput) {
    final Class<? extends AnnotatedRequestHandler> type = getClass();
    final String annotationMetadata = type.getPackage().getName() + ".$" + type.getSimpleName() + "DefinitionClass";
    final AnnotationMetadata metadata = ClassUtils.forName(annotationMetadata, type.getClassLoader()).flatMap(aClass -> {
        final Object o = InstantiationUtils.tryInstantiate(aClass).orElse(null);
        if (o instanceof AnnotationMetadataProvider) {
            return Optional.of(((AnnotationMetadataProvider) o).getAnnotationMetadata());
        }
        return Optional.empty();
    }).orElse(AnnotationMetadata.EMPTY_METADATA);
    final String[] names = metadata.getValue(IntentHandler.class, String[].class).orElse(StringUtils.EMPTY_STRING_ARRAY);
    return Arrays.stream(names).anyMatch(n -> handlerInput.matches(intentName(n)));
}
 
Example 3
Source Project: micronaut-data   Source File: MappedEntityVisitor.java    License: Apache License 2.0 5 votes vote down vote up
private NamingStrategy resolveNamingStrategy(ClassElement element) {
    return element.stringValue(MappedEntity.class, "namingStrategy")
            .flatMap(new Function<String, Optional<NamingStrategy>>() {
                @Override
                public Optional<NamingStrategy> apply(String s) {
                    Object o = InstantiationUtils.tryInstantiate(s, getClass().getClassLoader()).orElse(null);
                    if (o instanceof NamingStrategy) {
                        return Optional.of((NamingStrategy) o);
                    }
                    return Optional.empty();
                }
            }).orElseGet(NamingStrategies.UnderScoreSeparatedLowerCase::new);
}
 
Example 4
Source Project: micronaut-data   Source File: AbstractPersistentEntity.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
private NamingStrategy getNamingStrategy(AnnotationMetadata annotationMetadata) {
    return annotationMetadata
            .classValue(MappedEntity.class, "namingStrategy")
            .flatMap(aClass -> {
                @SuppressWarnings("unchecked")
                Object o = InstantiationUtils.tryInstantiate(aClass).orElse(null);
                if (o instanceof NamingStrategy) {
                    return Optional.of((NamingStrategy) o);
                }
                return Optional.empty();
            }).orElseGet(() -> annotationMetadata.stringValue(MappedEntity.class, "namingStrategy").flatMap(this::getNamingStrategy).orElse(new NamingStrategies.UnderScoreSeparatedLowerCase()));
}
 
Example 5
Source Project: micronaut-kafka   Source File: KafkaSubstitutions.java    License: Apache License 2.0 4 votes vote down vote up
@Substitute
public Checksum create() {
    return (Checksum) InstantiationUtils.instantiate("java.util.zip.CRC32C", getClass().getClassLoader());
}