Search in sources :

Example 11 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty 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 12 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.

the class BackPressureDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    final ExtensionDeclaration extensionDeclaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    new IdempotentDeclarationWalker() {

        @Override
        protected void onSource(SourceDeclaration sourceDeclaration) {
            BackPressureStrategyModelProperty property;
            Optional<ExtensionTypeDescriptorModelProperty> extensionTypeDescriptorModelProperty = sourceDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
            if (extensionTypeDescriptorModelProperty.isPresent()) {
                Type sourceType = extensionTypeDescriptorModelProperty.get().getType();
                property = sourceType.getAnnotation(BackPressure.class).map(BackPressureStrategyModelProperty::of).orElseGet(BackPressureStrategyModelProperty::getDefault);
                sourceDeclaration.addModelProperty(property);
                if (property.getSupportedModes().size() > 1) {
                    addBackPressureParameter(extensionDeclaration, sourceDeclaration, property);
                }
            }
        }
    }.walk(extensionDeclaration);
}
Also used : Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) BackPressureStrategyModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.BackPressureStrategyModelProperty) Optional(java.util.Optional) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)

Example 13 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.

the class DefaultJavaModelLoaderDelegate method declare.

/**
 * {@inheritDoc}
 */
@Override
public ExtensionDeclarer declare(ExtensionLoadingContext context) {
    ExtensionDeclarer declarer = context.getExtensionDeclarer().named(extensionElement.getName()).onVersion(version).fromVendor(extensionElement.getVendor()).withCategory(extensionElement.getCategory()).withModelProperty(new ExtensionTypeDescriptorModelProperty(extensionElement));
    // TODO MULE-14517: This workaround should be replaced for a better and more complete mechanism
    context.getParameter("COMPILATION_MODE").ifPresent(m -> declarer.withModelProperty(new CompileTimeModelProperty()));
    extensionElement.getDeclaringClass().ifPresent(extensionClass -> declarer.withModelProperty(new ImplementingTypeModelProperty(extensionClass)));
    processLicenseRequirements(declarer);
    parseExternalLibs(extensionElement, declarer);
    addExceptionEnricher(extensionElement, declarer);
    configLoaderDelegate.declareConfigurations(declarer, extensionElement);
    connectionProviderModelLoaderDelegate.declareConnectionProviders(declarer, extensionElement);
    if (!isEmpty(extensionElement.getConfigurations())) {
        operationLoaderDelegate.declareOperations(declarer, declarer, null, extensionElement.getOperations(), false);
        functionModelLoaderDelegate.declareFunctions(declarer, declarer, null, extensionElement.getFunctions());
        extensionElement.getSources().forEach(source -> sourceModelLoaderDelegate.declareMessageSource(declarer, declarer, source, false));
    }
    return declarer;
}
Also used : ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) CompileTimeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.CompileTimeModelProperty) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)

Example 14 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.

the class ErrorsDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclaration declaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    String extensionNamespace = getExtensionsNamespace(declaration);
    Optional<ExtensionTypeDescriptorModelProperty> implementingType = declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    ErrorsModelFactory errorModelDescriber = new ErrorsModelFactory(extensionNamespace);
    errorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
    if (implementingType.isPresent() && implementingType.get().getType().getDeclaringClass().isPresent()) {
        Type extensionElement = implementingType.get().getType();
        Optional<ErrorTypes> errorAnnotation = extensionElement.getAnnotation(ErrorTypes.class);
        List<Pair<ComponentDeclaration, MethodElement>> errorOperations = collectErrorOperations(declaration);
        if (errorAnnotation.isPresent()) {
            ErrorTypeDefinition<?>[] errorTypes = (ErrorTypeDefinition<?>[]) errorAnnotation.get().value().getEnumConstants();
            if (errorTypes.length > 0) {
                ErrorsModelFactory operationErrorModelDescriber = new ErrorsModelFactory(errorTypes, extensionNamespace);
                operationErrorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
                errorOperations.stream().forEach(pair -> registerOperationErrorTypes(pair.getSecond(), pair.getFirst(), operationErrorModelDescriber, errorTypes, extensionElement));
            } else {
                handleNoErrorTypes(extensionElement, errorOperations);
            }
        } else {
            handleNoErrorTypes(extensionElement, errorOperations);
        }
    }
}
Also used : ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) Pair(org.mule.runtime.api.util.Pair)

Example 15 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty 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

ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)15 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)9 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)6 MetadataType (org.mule.metadata.api.model.MetadataType)5 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)5 ImplementingTypeModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)4 Optional (java.util.Optional)3 ObjectType (org.mule.metadata.api.model.ObjectType)3 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)3 ExtensionLoadingContext (org.mule.runtime.extension.api.loader.ExtensionLoadingContext)3 ArrayType (org.mule.metadata.api.model.ArrayType)2 DeclarationEnricherPhase (org.mule.runtime.extension.api.loader.DeclarationEnricherPhase)2 INITIALIZE (org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.INITIALIZE)2 AnnotationValueFetcher (org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher)2 ParameterDeclarationContext (org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext)2 String.format (java.lang.String.format)1 Arrays.stream (java.util.Arrays.stream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1