class SpringValidator<T> implements Validator<T>, InitializingBean {

	private org.springframework.validation.Validator validator;

	/**
	 * @see Validator#validate(Object)
	 */
	@Override
	public void validate(T item) throws ValidationException {

		if (!validator.supports(item.getClass())) {
			throw new ValidationException("Validation failed for " + item + ": " + item.getClass().getName()
					+ " class is not supported by validator.");
		}

		BeanPropertyBindingResult errors = new BeanPropertyBindingResult(item, "item");

		validator.validate(item, errors);

		if (errors.hasErrors()) {
			throw new ValidationException("Validation failed for " + item + ": " + errorsToString(errors),
					new BindException(errors));
		}
	}

	/**
	 * @return string of field errors followed by global errors.
	 */
	private String errorsToString(Errors errors) {
		StringBuilder builder = new StringBuilder();

		appendCollection(errors.getFieldErrors(), builder);
		appendCollection(errors.getGlobalErrors(), builder);

		return builder.toString();
	}

	/**
	 * Append the string representation of elements of the collection (separated by new
	 * lines) to the given StringBuilder.
	 */
	private void appendCollection(Collection<?> collection, StringBuilder builder) {<FILL_FUNCTION_BODY>}

	public void setValidator(org.springframework.validation.Validator validator) {
		this.validator = validator;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		Assert.state(validator != null, "validator must be set");

	}

}

		for (Object value : collection) {
			builder.append("\n");
			builder.append(value.toString());
		}
	
<no_super_class>