Search in sources :

Example 1 with ValueProviderFactoryModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty in project mule by mulesoft.

the class ValueProviderMediator method getValues.

/**
 * Given the name of a parameter or parameter group, and if the parameter supports it, this will try to resolve
 * the {@link Value values} for the parameter.
 *
 * @param parameterName          the name of the parameter to resolve their possible {@link Value values}
 * @param parameterValueResolver parameter resolver required if the associated {@link ValueProvider} requires
 *                               the value of parameters from the same parameter container.
 * @param connectionSupplier     supplier of connection instances related to the container and used, if necessary, by the
 *                               {@link ValueProvider}
 * @param configurationSupplier  supplier of connection instances related to the container and used, if necessary, by the
 *                               {@link ValueProvider}
 * @return a {@link Set} of {@link Value} correspondent to the given parameter
 * @throws ValueResolvingException if an error occurs resolving {@link Value values}
 */
public Set<Value> getValues(String parameterName, ParameterValueResolver parameterValueResolver, Supplier<Object> connectionSupplier, Supplier<Object> configurationSupplier) throws ValueResolvingException {
    List<ParameterModel> parameters = getParameters(parameterName);
    if (parameters.isEmpty()) {
        throw new ValueResolvingException(format("Unable to find model for parameter or parameter group with name '%s'.", parameterName), INVALID_VALUE_RESOLVER_NAME);
    }
    ParameterModel parameterModel = parameters.get(0);
    ValueProviderFactoryModelProperty factoryModelProperty = parameterModel.getModelProperty(ValueProviderFactoryModelProperty.class).orElseThrow(() -> new ValueResolvingException(format("The parameter with name '%s' is not an Values Provider", parameterName), INVALID_VALUE_RESOLVER_NAME));
    try {
        return resolveValues(parameters, factoryModelProperty, parameterValueResolver, connectionSupplier, configurationSupplier);
    } catch (Exception e) {
        throw new ValueResolvingException(format("An error occurred trying to resolve the Values for parameter '%s' of component '%s'", parameterName, containerModel.getName()), UNKNOWN, e);
    }
}
Also used : ValueProviderFactoryModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ValueResolvingException(org.mule.runtime.extension.api.values.ValueResolvingException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ValueResolvingException(org.mule.runtime.extension.api.values.ValueResolvingException)

Aggregations

InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)1 ValueResolvingException (org.mule.runtime.extension.api.values.ValueResolvingException)1 ValueProviderFactoryModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty)1