Search in sources :

Example 6 with IdempotentDeclarationWalker

use of org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker 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 7 with IdempotentDeclarationWalker

use of org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker in project mule by mulesoft.

the class ErrorsDeclarationEnricher method collectErrorOperations.

private List<Pair<ComponentDeclaration, MethodElement>> collectErrorOperations(ExtensionDeclaration declaration) {
    List<Pair<ComponentDeclaration, MethodElement>> operations = new LinkedList<>();
    new IdempotentDeclarationWalker() {

        @Override
        public void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
            addComponent(declaration);
        }

        @Override
        protected void onConstruct(ConstructDeclaration declaration) {
            addComponent(declaration);
        }

        private void addComponent(ComponentDeclaration<?> declaration) {
            declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class).ifPresent(implementingMethodModelProperty -> operations.add(new Pair<>(declaration, implementingMethodModelProperty.getOperationMethod())));
        }
    }.walk(declaration);
    return operations;
}
Also used : MuleExtensionUtils.getExtensionsNamespace(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getExtensionsNamespace) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) MuleErrors(org.mule.runtime.extension.api.error.MuleErrors) ConstructDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclaration) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) Pair(org.mule.runtime.api.util.Pair) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) LinkedList(java.util.LinkedList) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) ComponentDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ComponentDeclaration) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) DeclarationEnricherPhase(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Throws(org.mule.runtime.extension.api.annotation.error.Throws) String.format(java.lang.String.format) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) List(java.util.List) Stream(java.util.stream.Stream) ErrorTypeProvider(org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider) Optional(java.util.Optional) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) INITIALIZE(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.INITIALIZE) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ConstructDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclaration) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) LinkedList(java.util.LinkedList) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) Pair(org.mule.runtime.api.util.Pair)

Aggregations

ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)7 IdempotentDeclarationWalker (org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker)7 SourceDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)5 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)4 Optional (java.util.Optional)3 ObjectType (org.mule.metadata.api.model.ObjectType)3 ImportedTypeModel (org.mule.runtime.api.meta.model.ImportedTypeModel)3 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)3 Reference (org.mule.runtime.api.util.Reference)3 DeclarationEnricher (org.mule.runtime.extension.api.loader.DeclarationEnricher)3 DeclarationEnricherPhase (org.mule.runtime.extension.api.loader.DeclarationEnricherPhase)3 ExtensionLoadingContext (org.mule.runtime.extension.api.loader.ExtensionLoadingContext)3 String.format (java.lang.String.format)2 List (java.util.List)2 Optional.ofNullable (java.util.Optional.ofNullable)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)2 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)2 ParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)2