package test.org.itscool.commons.aop2;
import org.itscool.commons.aop.ProxyMethodHandler;
import org.itscool.commons.aop.ProxyMethodInvocator;

public class IntegerCheckAdvice implements ProxyMethodHandler{
	public Object invoke(ProxyMethodInvocator invocator) throws Throwable{
		Object[] args = invocator.getArgs();
		Object arg1 = args[0];
		Object arg2 = args[1];
		
		try{
			Integer.parseInt(arg1.toString());
		}catch(NumberFormatException nfe){
			System.out.println("引数1に数値以外の値が指定された");
			args[0] = "0";
		}
		try{
			Integer.parseInt(arg2.toString());
		}catch(NumberFormatException nfe){
			System.out.println("引数2に数値以外の値が指定された");
			args[1] = "0";
		}
		invocator.setArgs(args);
		Object obj = invocator.proceed();
		
		return obj;
	}
}
