package net.javajigi.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class UserLoggingAdvice implements MethodInterceptor {
	protected final Log logger = LogFactory.getLog(getClass());

	public Object invoke(MethodInvocation invocation) throws Throwable {
		String className = invocation.getThis().getClass().getName();

		if (logger.isDebugEnabled()) {
			logger.debug(className + "." + invocation.getMethod().getName() + "()"
					+ " ½ÃÀÛ!!");
			Object[] args = invocation.getArguments();
			if ((args != null) && (args.length > 0)) {
				for (int i = 0; i < args.length; i++) {
					logger.debug("Argument[" + i + "] : " + args[i]);
				}
			}
		}

		//Target Å¬·¡½ºÀÇ ¸Þ½áµå¸¦ ½ÇÇàÇÑ´Ù.
		Object retVal = invocation.proceed();

		if (logger.isDebugEnabled()) {
			logger.debug(className + "." + invocation.getMethod().getName() + "()"
					+ " Á¾·á!!");
		}

		return retVal;

	}
}
