use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext in project mule by mulesoft.
the class MuleExtensionUtils method toMap.
public static Map<String, Object> toMap(ResolverSet resolverSet, CoreEvent event) throws MuleException {
final ValueResolvingContext ctx = from(event);
ImmutableMap.Builder<String, Object> map = ImmutableMap.builder();
for (Entry<String, ValueResolver<?>> entry : resolverSet.getResolvers().entrySet()) {
Object value = entry.getValue().resolve(ctx);
if (value != null) {
map.put(entry.getKey(), value);
}
}
return map.build();
}
use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext in project mule by mulesoft.
the class SourceConfigurer method configure.
/**
* Performs the configuration of the given {@code source} and returns the result
*
* @param source a {@link Source}
* @param config the {@link ConfigurationInstance config instance} associated to {@code this} source object.
* @return the configured instance
* @throws MuleException
*/
public Source configure(Source source, Optional<ConfigurationInstance> config) throws MuleException {
ResolverSetBasedObjectBuilder<Source> builder = new ResolverSetBasedObjectBuilder<Source>(source.getClass(), model, resolverSet) {
@Override
protected Source instantiateObject() {
return source;
}
@Override
public Source build(ValueResolvingContext context) throws MuleException {
Source source = build(resolverSet.resolve(context));
injectDefaultEncoding(model, source, muleContext.getConfiguration().getDefaultEncoding());
injectComponentLocation(source, componentLocation);
config.ifPresent(c -> injectRefName(source, c.getName(), getReflectionCache()));
return source;
}
};
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent(muleContext);
Source configuredSource = builder.build(from(initialiserEvent, config));
if (configuredSource instanceof PollingSource) {
Scheduler scheduler = (Scheduler) resolverSet.getResolvers().get(SCHEDULING_STRATEGY_PARAMETER_NAME).resolve(ValueResolvingContext.from(initialiserEvent));
configuredSource = new PollingSourceWrapper((PollingSource) configuredSource, scheduler);
}
return configuredSource;
} catch (Exception e) {
throw new MuleRuntimeException(createStaticMessage("Exception was found trying to configure source of type " + source.getClass().getName()), e);
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
}
use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext 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);
}
Aggregations