Search in sources :

Example 1 with AnnotationValueFetcher

use of org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher in project mule by mulesoft.

the class MuleExtensionAnnotationParser method parseRepeatableAnnotation.

public static <T extends Annotation> List<AnnotationValueFetcher<T>> parseRepeatableAnnotation(Type extensionType, Class<T> annotation, Function<Annotation, T[]> containerConsumer) {
    List<AnnotationValueFetcher<T>> annotationDeclarations = ImmutableList.of();
    Repeatable repeatableContainer = annotation.getAnnotation(Repeatable.class);
    if (repeatableContainer != null) {
        Optional<? extends AnnotationValueFetcher<? extends Annotation>> container = extensionType.getValueFromAnnotation(repeatableContainer.value());
        if (container.isPresent()) {
            annotationDeclarations = container.get().getInnerAnnotations((Function) containerConsumer);
        }
    }
    Optional<AnnotationValueFetcher<T>> singleDeclaration = extensionType.getValueFromAnnotation(annotation);
    if (singleDeclaration.isPresent()) {
        annotationDeclarations = Collections.singletonList(singleDeclaration.get());
    }
    return annotationDeclarations;
}
Also used : Repeatable(java.lang.annotation.Repeatable) Function(java.util.function.Function) AnnotationValueFetcher(org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher)

Example 2 with AnnotationValueFetcher

use of org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher in project mule by mulesoft.

the class SubTypesDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclarer declarer = extensionLoadingContext.getExtensionDeclarer();
    ExtensionDeclaration extensionDeclaration = declarer.getDeclaration();
    Optional<ExtensionTypeDescriptorModelProperty> implementingType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    if (!implementingType.isPresent()) {
        return;
    }
    Type type = implementingType.get().getType();
    List<AnnotationValueFetcher<SubTypeMapping>> typeMappings = parseRepeatableAnnotation(type, SubTypeMapping.class, c -> ((SubTypesMapping) c).value());
    if (!typeMappings.isEmpty()) {
        declareSubTypesMapping(declarer, typeMappings, extensionDeclaration.getName());
    }
}
Also used : Type(org.mule.runtime.module.extension.api.loader.java.type.Type) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) AnnotationValueFetcher(org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher)

Example 3 with AnnotationValueFetcher

use of org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher in project mule by mulesoft.

the class ImportedTypesDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclarer descriptor = extensionLoadingContext.getExtensionDeclarer();
    ExtensionDeclaration extensionDeclaration = descriptor.getDeclaration();
    final Optional<ExtensionTypeDescriptorModelProperty> extensionType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    if (!extensionType.isPresent()) {
        return;
    }
    Type type = extensionType.get().getType();
    final List<AnnotationValueFetcher<Import>> importTypes = parseRepeatableAnnotation(type, Import.class, c -> ((ImportedTypes) c).value());
    if (!importTypes.isEmpty()) {
        if (importTypes.stream().map(annotation -> annotation.getClassValue(Import::type)).distinct().collect(toList()).size() != importTypes.size()) {
            throw new IllegalModelDefinitionException(format("There should be only one Import declaration for any given type in extension [%s]." + " Multiple imports of the same type are not allowed", extensionDeclaration.getName()));
        }
        importTypes.forEach(imported -> {
            MetadataType importedType = imported.getClassValue(Import::type).asMetadataType();
            if (!(importedType instanceof ObjectType)) {
                throw new IllegalArgumentException(format("Type '%s' is not complex. Only complex types can be imported from other extensions.", type.getTypeName()));
            }
            extensionDeclaration.addImportedType(new ImportedTypeModel((ObjectType) importedType));
        });
    }
}
Also used : IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ObjectType(org.mule.metadata.api.model.ObjectType) ObjectType(org.mule.metadata.api.model.ObjectType) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) AnnotationValueFetcher(org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher)

Aggregations

AnnotationValueFetcher (org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher)3 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)2 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)2 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)2 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)2 Repeatable (java.lang.annotation.Repeatable)1 Function (java.util.function.Function)1 MetadataType (org.mule.metadata.api.model.MetadataType)1 ObjectType (org.mule.metadata.api.model.ObjectType)1 ImportedTypeModel (org.mule.runtime.api.meta.model.ImportedTypeModel)1 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)1