Search in sources :

Example 6 with ExtensionDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer in project mule by mulesoft.

the class SourceModelLoaderDelegate method declareMessageSource.

void declareMessageSource(ExtensionDeclarer extensionDeclarer, HasSourceDeclarer declarer, SourceElement sourceType, boolean supportsConfig) {
    // TODO: MULE-9220 - Add a syntax validator which checks that the sourceType doesn't implement
    if (isLifecycle(sourceType)) {
        throw new IllegalSourceModelDefinitionException(format("Source class '%s' implements a lifecycle interface. Sources are not allowed to", sourceType.getName()));
    }
    final Optional<ExtensionParameter> configParameter = loader.getConfigParameter(sourceType);
    final Optional<ExtensionParameter> connectionParameter = loader.getConnectionParameter(sourceType);
    if (loader.isInvalidConfigSupport(supportsConfig, configParameter, connectionParameter)) {
        throw new IllegalSourceModelDefinitionException(format("Source '%s' is defined at the extension level but it requires a config parameter. " + "Remove such parameter or move the source to the proper config", sourceType.getName()));
    }
    HasSourceDeclarer actualDeclarer = (HasSourceDeclarer) loader.selectDeclarerBasedOnConfig(extensionDeclarer, (Declarer) declarer, configParameter, connectionParameter);
    SourceDeclarer existingDeclarer = sourceDeclarers.get(sourceType);
    if (existingDeclarer != null) {
        actualDeclarer.withMessageSource(existingDeclarer);
        return;
    }
    SourceDeclarer sourceDeclarer = actualDeclarer.withMessageSource(sourceType.getAlias());
    sourceDeclarer.withModelProperty(new ExtensionTypeDescriptorModelProperty(sourceType));
    List<Type> sourceGenerics = sourceType.getSuperClassGenerics();
    if (sourceGenerics.size() != 2) {
        // TODO: MULE-9220: Add a syntax validator for this
        throw new IllegalModelDefinitionException(format("Message source class '%s' was expected to have 2 generic types " + "(one for the Payload type and another for the Attributes type) but %d were found", sourceType.getName(), sourceGenerics.size()));
    }
    sourceDeclarer.hasResponse(sourceType.isAnnotatedWith(EmitsResponse.class)).requiresConnection(connectionParameter.isPresent());
    sourceType.getDeclaringClass().ifPresent(clazz -> sourceDeclarer.withModelProperty(new SourceFactoryModelProperty(new DefaultSourceFactory((Class<? extends Source>) clazz))).withModelProperty(new ImplementingTypeModelProperty(clazz)));
    processMimeType(sourceDeclarer, sourceType);
    processComponentConnectivity(sourceDeclarer, sourceType, sourceType);
    resolveOutputTypes(sourceDeclarer, sourceType);
    loader.addExceptionEnricher(sourceType, sourceDeclarer);
    declareSourceParameters(sourceType, sourceDeclarer);
    declareSourceCallback(sourceType, sourceDeclarer);
    sourceDeclarers.put(sourceType, sourceDeclarer);
}
Also used : ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) IllegalSourceModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalSourceModelDefinitionException) HasSourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasSourceDeclarer) SourceFactoryModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.SourceFactoryModelProperty) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) DefaultSourceFactory(org.mule.runtime.module.extension.internal.runtime.source.DefaultSourceFactory) SourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclarer) HasSourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasSourceDeclarer) SourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclarer) HasSourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasSourceDeclarer) ParameterizedDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclarer) ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)

Example 7 with ExtensionDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer in project mule by mulesoft.

the class PollingSourceDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ClassTypeLoader loader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
    ExtensionDeclarer extensionDeclarer = extensionLoadingContext.getExtensionDeclarer();
    Reference<Boolean> thereArePollingSources = new Reference<>(false);
    new IdempotentDeclarationWalker() {

        @Override
        protected void onSource(SourceDeclaration source) {
            extractType(source).ifPresent(type -> {
                if (type.isAssignableTo(PollingSource.class)) {
                    source.setRunsOnPrimaryNodeOnly(true);
                    ParameterDeclaration parameter = new ParameterDeclaration(SCHEDULING_STRATEGY_PARAMETER_NAME);
                    parameter.setDescription(SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION);
                    parameter.setRequired(true);
                    parameter.setType(loader.load(Scheduler.class), false);
                    parameter.setExpressionSupport(NOT_SUPPORTED);
                    parameter.addModelProperty(new InfrastructureParameterModelProperty(10));
                    parameter.addModelProperty(new QNameModelProperty(new QName(CORE_NAMESPACE, SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER, CORE_PREFIX)));
                    parameter.setDslConfiguration(ParameterDslConfiguration.builder().allowsInlineDefinition(true).allowsReferences(false).allowTopLevelDefinition(false).build());
                    thereArePollingSources.set(true);
                    source.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter);
                }
            });
        }
    }.walk(extensionDeclarer.getDeclaration());
    if (thereArePollingSources.get() && !isSchedulerAlreadyImported(extensionDeclarer.getDeclaration())) {
        ClassTypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
        extensionDeclarer.withImportedType(new ImportedTypeModel((ObjectType) typeLoader.load(Scheduler.class)));
    }
}
Also used : InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) QNameModelProperty(org.mule.runtime.extension.api.property.QNameModelProperty) CORE_NAMESPACE(org.mule.runtime.internal.dsl.DslConstants.CORE_NAMESPACE) DEFAULT_GROUP_NAME(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME) MetadataTypeUtils.getTypeId(org.mule.metadata.api.utils.MetadataTypeUtils.getTypeId) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) ParameterDslConfiguration(org.mule.runtime.api.meta.model.ParameterDslConfiguration) SCHEDULING_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.SCHEDULING_STRATEGY_PARAMETER_NAME) ObjectType(org.mule.metadata.api.model.ObjectType) 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) STRUCTURE(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.STRUCTURE) SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION(org.mule.runtime.extension.api.ExtensionConstants.SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) Reference(org.mule.runtime.api.util.Reference) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) QName(javax.xml.namespace.QName) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) QNameModelProperty(org.mule.runtime.extension.api.property.QNameModelProperty) Reference(org.mule.runtime.api.util.Reference) QName(javax.xml.namespace.QName) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) ObjectType(org.mule.metadata.api.model.ObjectType) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)

Example 8 with ExtensionDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer in project mule by mulesoft.

the class JavaExportedTypesDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    Optional<ExtensionTypeDescriptorModelProperty> modelProperty = extensionLoadingContext.getExtensionDeclarer().getDeclaration().getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    modelProperty.map(ExtensionTypeDescriptorModelProperty::getType).flatMap(type -> type.getValueFromAnnotation(Export.class)).ifPresent(exportAnnotation -> {
        ExtensionDeclarer declarer = extensionLoadingContext.getExtensionDeclarer();
        exportAnnotation.getClassArrayValue(Export::classes).stream().map(Type::asMetadataType).forEach(type -> registerType(declarer, type));
        exportAnnotation.getArrayValue(Export::resources).forEach(declarer::withResource);
    });
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) DeclarationEnricherPhase(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) Export(org.mule.runtime.extension.api.annotation.Export) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) ArrayType(org.mule.metadata.api.model.ArrayType) IntersectionType(org.mule.metadata.api.model.IntersectionType) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) UnionType(org.mule.metadata.api.model.UnionType) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) INITIALIZE(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.INITIALIZE) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)

Example 9 with ExtensionDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer in project mule by mulesoft.

the class JavaPrivilegedExportedTypesDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclarer extensionDeclarer = extensionLoadingContext.getExtensionDeclarer();
    extensionDeclarer.getDeclaration().getModelProperty(ExtensionTypeDescriptorModelProperty.class).map(ExtensionTypeDescriptorModelProperty::getType).flatMap(type -> type.getValueFromAnnotation(PrivilegedExport.class)).ifPresent(valueFetcher -> {
        valueFetcher.getArrayValue(PrivilegedExport::artifacts).forEach(extensionDeclarer::withPrivilegedArtifact);
        valueFetcher.getArrayValue(PrivilegedExport::packages).forEach(extensionDeclarer::withPrivilegedPackage);
    });
}
Also used : ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) PrivilegedExport(org.mule.runtime.extension.api.annotation.PrivilegedExport) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)

Example 10 with ExtensionDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer in project mule by mulesoft.

the class JavaXmlDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    Xml xml = extractAnnotation(extensionLoadingContext.getExtensionDeclarer().getDeclaration(), Xml.class);
    ExtensionDeclarer declarer = extensionLoadingContext.getExtensionDeclarer();
    ExtensionDeclaration extensionDeclaration = declarer.getDeclaration();
    declarer.withXmlDsl(getXmlLanguageModel(xml, extensionDeclaration));
}
Also used : Xml(org.mule.runtime.extension.api.annotation.dsl.xml.Xml) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)

Aggregations

ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)35 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)15 Test (org.junit.Test)14 SmallTest (org.mule.tck.size.SmallTest)14 DefaultExtensionLoadingContext (org.mule.runtime.extension.internal.loader.DefaultExtensionLoadingContext)8 MetadataType (org.mule.metadata.api.model.MetadataType)6 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)6 Before (org.junit.Before)5 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)5 HeisenbergExtension (org.mule.test.heisenberg.extension.HeisenbergExtension)5 Declarer (org.mule.runtime.api.meta.model.declaration.fluent.Declarer)4 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)4 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)4 ObjectType (org.mule.metadata.api.model.ObjectType)3 ConfigurationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration)3 HasOperationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer)3 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)3 ExtensionLoadingContext (org.mule.runtime.extension.api.loader.ExtensionLoadingContext)3 DefaultJavaModelLoaderDelegate (org.mule.runtime.module.extension.internal.loader.java.DefaultJavaModelLoaderDelegate)3 ImplementingMethodModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty)3