use of org.mule.runtime.module.extension.internal.runtime.objectbuilder.ResolverSetBasedObjectBuilder 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();
}
}
}
Aggregations