Java tutorial
/* * Copyright 2012 Eng Kam Hon (kamhon@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.kamhon.ieagle.aop; import java.lang.reflect.Method; import net.kamhon.ieagle.exception.ValidatorException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.aspectj.lang.ProceedingJoinPoint; import org.springframework.aop.MethodBeforeAdvice; import org.springframework.aop.ThrowsAdvice; /** * <p> * This clase used for following purpose : * </p> * * <ol> * <li>log Unexpected Exception when calling DWR request</li> * <li>log DWR request</li> * </ol> * * @author kamhon * */ public class DwrDelegateAdvice implements ThrowsAdvice, MethodBeforeAdvice { private static final Log log = LogFactory.getLog(DwrDelegateAdvice.class); public DwrDelegateAdvice() { log.debug("Creating...DwrDelegateAdvice()"); } public void before(Method method, Object[] args, Object target) throws Throwable { log.debug("method = " + method + " ,target = " + target); } public void afterThrowing(Throwable throwable) { if (!(throwable instanceof ValidatorException)) { log.error(throwable, throwable.fillInStackTrace()); } } public Object invoke(ProceedingJoinPoint pjp) throws Throwable { log.debug(pjp.toLongString()); Object retVal = null; try { retVal = pjp.proceed(); } catch (Exception ex) { if (!(ex instanceof ValidatorException)) { log.error(ex, ex.fillInStackTrace()); } throw ex; } return retVal; } }