All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickntap.tool.bean.BeanValidator Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package com.clickntap.tool.bean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.clickntap.tool.script.ScriptEngine;

@SuppressWarnings("unchecked")
public class BeanValidator implements Validator {
	private BeanInfo beanInfo;

	private ScriptEngine viewEngine;

	private String validationGroup;

	private BeanManager beanManager;

	public BeanValidator(BeanInfo beanInfo, ScriptEngine viewEngine, String validationGroup, BeanManager beanManager) {
		this.beanInfo = beanInfo;
		this.viewEngine = viewEngine;
		this.validationGroup = validationGroup;
		this.beanManager = beanManager;
	}

	public boolean supports(Class clazz) {
		return true;
	}

	public void validate(Object target, Errors errors) {
		Map context = new HashMap();
		try {
			context.put("target", target);
			context.put("this", new BeanErrors(target, errors, beanManager));

			List scriptList = beanInfo.getValidationInfo().getValidationScriptList(validationGroup);
			for (String script : scriptList)
				viewEngine.evalScript(context, script);

		} catch (Exception e) {
			errors.reject("validation", e.getMessage());
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy