use of org.mule.runtime.api.meta.model.ComponentModel 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.api.meta.model.ComponentModel in project mule by mulesoft.
the class ConfigurationProviderToolingAdapter method addComponentKeys.
private void addComponentKeys(List<? extends ComponentModel> components, MetadataContext metadataContext, MetadataKeysContainerBuilder keysBuilder) throws MetadataResolvingException, ConnectionException {
for (ComponentModel component : components) {
TypeKeysResolver keysResolver = getMetadataResolverFactory(component).getKeyResolver();
String categoryName = keysResolver.getCategoryName();
if (!NULL_CATEGORY_NAME.equals(categoryName) && !keysBuilder.containsCategory(categoryName)) {
keysBuilder.add(categoryName, keysResolver.getKeys(metadataContext));
}
}
}
use of org.mule.runtime.api.meta.model.ComponentModel in project mule by mulesoft.
the class ComponentMessageProcessor method createComponentExecutor.
private ComponentExecutor<T> createComponentExecutor() {
Map<String, Object> params = new HashMap<>();
LazyValue<Optional<ConfigurationInstance>> staticConfiguration = new LazyValue<>(this::getStaticConfiguration);
LazyValue<ValueResolvingContext> resolvingContext = new LazyValue<>(() -> {
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent();
return from(initialiserEvent, staticConfiguration.get());
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
});
componentModel.getParameterGroupModels().stream().forEach(group -> {
if (group.getName().equals(DEFAULT_GROUP_NAME)) {
group.getParameterModels().stream().filter(p -> p.getModelProperty(FieldOperationParameterModelProperty.class).isPresent()).forEach(p -> {
ValueResolver<?> resolver = resolverSet.getResolvers().get(p.getName());
if (resolver != null) {
try {
params.put(getMemberName(p), resolveValue(resolver, resolvingContext.get()));
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
});
} else {
ParameterGroupDescriptor groupDescriptor = group.getModelProperty(ParameterGroupModelProperty.class).map(g -> g.getDescriptor()).orElse(null);
if (groupDescriptor == null) {
return;
}
List<ParameterModel> fieldParameters = getGroupsOfFieldParameters(group);
if (fieldParameters.isEmpty()) {
return;
}
ObjectBuilder groupBuilder = createFieldParameterGroupBuilder(groupDescriptor, fieldParameters);
try {
params.put(((Field) groupDescriptor.getContainer()).getName(), groupBuilder.build(resolvingContext.get()));
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
});
return getOperationExecutorFactory(componentModel).createExecutor(componentModel, params);
}
use of org.mule.runtime.api.meta.model.ComponentModel in project mule by mulesoft.
the class ExtensionConnectionSupplier method getTransactedConnectionHandler.
private <T extends TransactionalConnection> ConnectionHandler<T> getTransactedConnectionHandler(ExecutionContextAdapter<? extends ComponentModel> executionContext, TransactionConfig transactionConfig) throws ConnectionException, TransactionException {
if (!transactionConfig.isTransacted()) {
return getTransactionlessConnectionHandler(executionContext);
}
ExtensionModel extensionModel = executionContext.getExtensionModel();
ComponentModel componentModel = executionContext.getComponentModel();
ConfigurationInstance configuration = executionContext.getConfiguration().orElseThrow(() -> new IllegalStateException(format("%s '%s' of extension '%s' cannot participate in a transaction because it doesn't have a config", getComponentModelTypeName(componentModel), componentModel.getName(), extensionModel.getName())));
final ExtensionTransactionKey txKey = new ExtensionTransactionKey(configuration);
TransactionBindingDelegate transactionBindingDelegate = new TransactionBindingDelegate(extensionModel, componentModel);
return transactionBindingDelegate.getBoundResource(transactionConfig, txKey, () -> getTransactionlessConnectionHandler(executionContext));
}
use of org.mule.runtime.api.meta.model.ComponentModel in project mule by mulesoft.
the class DefaultExtensionManager method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
public Optional<ConfigurationInstance> getConfiguration(ExtensionModel extensionModel, ComponentModel componentModel, CoreEvent muleEvent) {
ConfigurationInstance instance = getConfigurationProvider(extensionModel, componentModel).map(p -> p.get(muleEvent)).orElse(null);
if (instance != null) {
return of(instance);
}
Optional<ConfigurationModel> configurationModel = getConfigurationModelForExtension(extensionModel, getConfigurationForComponent(extensionModel, componentModel));
if (configurationModel.isPresent()) {
createImplicitConfiguration(extensionModel, configurationModel.get(), muleEvent);
return of(getConfiguration(getImplicitConfigurationProviderName(extensionModel, configurationModel.get()), muleEvent));
}
return empty();
}
Aggregations