/*
   * (non-Javadoc)
   * @see org.springframework.data.mapping.model.ParameterValueProvider#getParameterValue(org.springframework.data.mapping.PreferredConstructor.Parameter)
   */
  @SuppressWarnings("unchecked")
  public <T> T getParameterValue(Parameter<T, P> parameter) {

    PreferredConstructor<?, P> constructor = entity.getPersistenceConstructor();

    if (constructor.isEnclosingClassParameter(parameter)) {
      return (T) parent;
    }

    P property = entity.getPersistentProperty(parameter.getName());

    if (property == null) {
      throw new MappingException(
          String.format(
              "No property %s found on entity %s to bind constructor parameter to!",
              parameter.getName(), entity.getType()));
    }

    return provider.getPropertyValue(property);
  }