use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class DefaultExtensionBuildingDefinitionProvider method registerTopLevelParameter.
private void registerTopLevelParameter(final MetadataType parameterType, Builder definitionBuilder, ClassLoader extensionClassLoader, DslSyntaxResolver dslSyntaxResolver, ExtensionParsingContext parsingContext, ReflectionCache reflectionCache) {
Optional<DslElementSyntax> dslElement = dslSyntaxResolver.resolve(parameterType);
if (!dslElement.isPresent() || parsingContext.isRegistered(dslElement.get().getElementName(), dslElement.get().getPrefix()) || !IntrospectionUtils.isInstantiable(parameterType, reflectionCache)) {
return;
}
parameterType.accept(new MetadataTypeVisitor() {
@Override
public void visitObject(ObjectType objectType) {
DslElementSyntax pojoDsl = dslElement.get();
if (pojoDsl.supportsTopLevelDeclaration() || (pojoDsl.supportsChildDeclaration() && pojoDsl.isWrapped()) || getSubstitutionGroup(objectType).isPresent() || parsingContext.getAllSubTypes().contains(objectType)) {
parseWith(new ObjectTypeParameterParser(definitionBuilder, objectType, extensionClassLoader, dslSyntaxResolver, parsingContext));
}
registerSubTypes(objectType, definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
}
@Override
public void visitArrayType(ArrayType arrayType) {
registerTopLevelParameter(arrayType.getType(), definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
}
@Override
public void visitUnion(UnionType unionType) {
unionType.getTypes().forEach(type -> type.accept(this));
}
});
}
use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class AbstractComponentDefinitionParser method doParse.
@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
Builder finalBuilder = definitionBuilder.withIdentifier(operationDsl.getElementName()).withTypeDefinition(fromType(getMessageProcessorType())).withObjectFactoryType(getMessageProcessorFactoryType()).withConstructorParameterDefinition(fromFixedValue(extensionModel).build()).withConstructorParameterDefinition(fromFixedValue(componentModel).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withConstructorParameterDefinition(fromReferenceObject(Registry.class).build()).withConstructorParameterDefinition(fromReferenceObject(PolicyManager.class).build()).withSetterParameterDefinition(TARGET_PARAMETER_NAME, fromSimpleParameter(TARGET_PARAMETER_NAME).build()).withSetterParameterDefinition(TARGET_VALUE_PARAMETER_NAME, fromSimpleParameter(TARGET_VALUE_PARAMETER_NAME).build()).withSetterParameterDefinition(CONFIG_PROVIDER_ATTRIBUTE_NAME, fromSimpleReferenceParameter(CONFIG_ATTRIBUTE_NAME).build()).withSetterParameterDefinition(CURSOR_PROVIDER_FACTORY_FIELD_NAME, fromChildConfiguration(CursorProviderFactory.class).build()).withSetterParameterDefinition("retryPolicyTemplate", fromChildConfiguration(RetryPolicyTemplate.class).build());
Optional<? extends NestableElementModel> nestedChain = componentModel.getNestedComponents().stream().filter(c -> c instanceof NestedChainModel).findFirst();
if (nestedChain.isPresent()) {
// TODO MULE-13483: improve parsers to support things like [source, chainOfProcessors, errorHandler]
// or [chainOfProcessors, errorHandler]
finalBuilder = finalBuilder.withSetterParameterDefinition("nestedProcessors", fromChildCollectionConfiguration(Processor.class).build());
parseParameters(componentModel.getAllParameterModels());
} else {
List<ParameterGroupModel> inlineGroups = getInlineGroups(componentModel);
parseParameters(getFlatParameters(inlineGroups, componentModel.getAllParameterModels()));
for (ParameterGroupModel group : inlineGroups) {
parseInlineParameterGroup(group);
}
// TODO MULE-13483
parseNestedComponents(componentModel.getNestedComponents());
}
return finalBuilder;
}
use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class ExtensionDefinitionParser method parse.
/**
* Creates a list of {@link ComponentBuildingDefinition} built on copies of {@link #baseDefinitionBuilder}. It also sets the
* parsed parsed parameters on the backing {@link AbstractExtensionObjectFactory}
*
* @return a list with the generated {@link ComponentBuildingDefinition}
* @throws ConfigurationException if a parsing error occurs
*/
public final List<ComponentBuildingDefinition> parse() throws ConfigurationException {
Builder builder = baseDefinitionBuilder;
builder = doParse(builder);
AttributeDefinition parametersDefinition = fromFixedValue(new HashMap<>()).build();
if (!parameters.isEmpty()) {
KeyAttributeDefinitionPair[] attributeDefinitions = parameters.entrySet().stream().map(entry -> newBuilder().withAttributeDefinition(entry.getValue().build()).withKey(entry.getKey()).build()).toArray(KeyAttributeDefinitionPair[]::new);
parametersDefinition = fromMultipleDefinitions(attributeDefinitions).build();
}
builder = builder.withSetterParameterDefinition("parameters", parametersDefinition);
addDefinition(builder.build());
return parsedDefinitions;
}
use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class ConfigurationDefinitionParser method doParse.
@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
Builder finalBuilder = definitionBuilder.withIdentifier(configDsl.getElementName()).withTypeDefinition(fromType(ConfigurationProvider.class)).withObjectFactoryType(ConfigurationProviderObjectFactory.class).withConstructorParameterDefinition(fromSimpleParameter("name").build()).withConstructorParameterDefinition(fromFixedValue(extensionModel).build()).withConstructorParameterDefinition(fromFixedValue(configurationModel).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withSetterParameterDefinition("expirationPolicy", fromChildConfiguration(ExpirationPolicy.class).build());
parseParameters(configurationModel);
finalBuilder = parseConnectionProvider(finalBuilder);
return finalBuilder;
}
use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class ConnectionProviderDefinitionParser method doParse.
@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
Builder finalBuilder = definitionBuilder.withIdentifier(connectionDsl.getElementName()).withTypeDefinition(fromType(ConnectionProviderResolver.class)).withObjectFactoryType(ConnectionProviderObjectFactory.class).withConstructorParameterDefinition(fromFixedValue(providerModel).build()).withConstructorParameterDefinition(fromFixedValue(extensionModel).build()).withConstructorParameterDefinition(fromReferenceObject(ExtensionsOAuthManager.class).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withSetterParameterDefinition("reconnectionConfig", fromChildConfiguration(ReconnectionConfig.class).build()).withSetterParameterDefinition("poolingProfile", fromChildConfiguration(PoolingProfile.class).build());
parseParameters(providerModel);
return finalBuilder;
}
Aggregations