Search in sources :

Example 1 with ParameterizableTypeWrapper

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

the class ValueProvidersParameterDeclarationEnricher method enrichParameter.

/**
 * Enriches a parameter that has an associated {@link ValueProvider}
 *
 * @param resolverClass           the class of the {@link ValueProvider}
 * @param paramDeclaration        {@link ParameterDeclaration} or {@link ParameterGroupDeclaration} paramDeclaration
 * @param containerParameterNames parameters container's names
 */
private void enrichParameter(OfValues resolverClass, BaseDeclaration paramDeclaration, Consumer<ValueProviderModel> valueProviderModelConsumer, Integer partOrder, Map<String, String> containerParameterNames, String name) {
    ValueProviderFactoryModelPropertyBuilder propertyBuilder = ValueProviderFactoryModelProperty.builder(resolverClass.value());
    ParameterizableTypeWrapper resolverClassWrapper = new ParameterizableTypeWrapper(resolverClass.value(), new DefaultExtensionsTypeLoaderFactory().createTypeLoader());
    List<ExtensionParameter> resolverParameters = resolverClassWrapper.getParametersAnnotatedWith(Parameter.class);
    resolverParameters.forEach(param -> propertyBuilder.withInjectableParameter(param.getName(), param.getType().asMetadataType(), param.isRequired()));
    Reference<Boolean> requiresConfiguration = new Reference<>(false);
    Reference<Boolean> requiresConnection = new Reference<>(false);
    enrichWithConnection(propertyBuilder, resolverClassWrapper).ifPresent(field -> requiresConnection.set(true));
    enrichWithConfiguration(propertyBuilder, resolverClassWrapper).ifPresent(field -> requiresConfiguration.set(true));
    paramDeclaration.addModelProperty(propertyBuilder.build());
    valueProviderModelConsumer.accept(new ValueProviderModel(getRequiredParametersAliases(resolverParameters, containerParameterNames), requiresConfiguration.get(), requiresConnection.get(), resolverClass.open(), partOrder, name));
}
Also used : ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ParameterizableTypeWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.ParameterizableTypeWrapper) Reference(org.mule.runtime.api.util.Reference) DefaultExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.DefaultExtensionsTypeLoaderFactory) ValueProviderFactoryModelPropertyBuilder(org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.ValueProviderFactoryModelPropertyBuilder) ValueProviderModel(org.mule.runtime.api.meta.model.parameter.ValueProviderModel)

Aggregations

ValueProviderModel (org.mule.runtime.api.meta.model.parameter.ValueProviderModel)1 Reference (org.mule.runtime.api.util.Reference)1 DefaultExtensionsTypeLoaderFactory (org.mule.runtime.extension.api.declaration.type.DefaultExtensionsTypeLoaderFactory)1 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)1 ValueProviderFactoryModelPropertyBuilder (org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.ValueProviderFactoryModelPropertyBuilder)1 ParameterizableTypeWrapper (org.mule.runtime.module.extension.internal.loader.java.type.runtime.ParameterizableTypeWrapper)1