Search in sources :

Example 1 with ValueResolvingException

use of org.mule.runtime.module.extension.internal.runtime.ValueResolvingException in project mule by mulesoft.

the class ObjectBasedParameterValueResolver method getParameterValue.

@Override
public Object getParameterValue(String parameterName) throws ValueResolvingException {
    try {
        Optional<Field> field = getField(object.getClass(), parameterName, reflectionCache);
        if (field.isPresent()) {
            return getFieldValue(object, parameterName, reflectionCache);
        } else {
            for (ParameterGroupModel parameterGroupModel : parameterizedModel.getParameterGroupModels()) {
                Optional<ParameterGroupModelProperty> modelProperty = parameterGroupModel.getModelProperty(ParameterGroupModelProperty.class);
                if (modelProperty.isPresent()) {
                    ParameterGroupModelProperty property = modelProperty.get();
                    Field container = (Field) property.getDescriptor().getContainer();
                    Object parameterGroup = getFieldValue(object, container.getName(), reflectionCache);
                    Optional<Field> desiredField = getField(parameterGroup.getClass(), parameterName, reflectionCache);
                    if (desiredField.isPresent()) {
                        return getFieldValue(parameterGroup, parameterName, reflectionCache);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new ValueResolvingException("An error occurred trying to obtain the value for the parameter: " + parameterName);
    }
    throw new ValueResolvingException("Unable to resolve value for the parameter: " + parameterName);
}
Also used : IntrospectionUtils.getField(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getField) Field(java.lang.reflect.Field) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) ValueResolvingException(org.mule.runtime.module.extension.internal.runtime.ValueResolvingException) ValueResolvingException(org.mule.runtime.module.extension.internal.runtime.ValueResolvingException)

Aggregations

Field (java.lang.reflect.Field)1 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)1 ParameterGroupModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty)1 ValueResolvingException (org.mule.runtime.module.extension.internal.runtime.ValueResolvingException)1 IntrospectionUtils.getField (org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getField)1