package sk.yonban.core.aspectchanges;

import org.springframework.validation.Validator;
import sk.yonban.core.web.SimpleDetailController;

public aspect PouzivatelInfoValidatorAspect {
	private pointcut controllerInitialization(SimpleDetailController controller) :
		execution(void sk.yonban.core.web.SimpleDetailController.afterPropertiesSet())
		&& target(controller);
	
	after(SimpleDetailController controller) : controllerInitialization(controller)
	{
		if (!controller.getBeanName().equals("pouzivatelInfoController")) {
			return;
		}
		addValidator(controller);
	}
	
	private void addValidator(sk.yonban.core.web.SimpleDetailController controller) {
		Validator validators[] = controller.getValidators();
		Validator newValidators[] = new Validator[validators.length+1];
		for (int i=0; i<validators.length; i++) {
			newValidators[i] = validators[i];
		}
		newValidators[newValidators.length-1] = new PouzivatelInfoValidator();
		controller.setValidators(newValidators);
	}

}
