001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.test.aspects;
016    
017    import com.liferay.portal.kernel.util.ReflectionUtil;
018    
019    import org.aspectj.lang.ProceedingJoinPoint;
020    import org.aspectj.lang.annotation.Around;
021    import org.aspectj.lang.annotation.Aspect;
022    
023    /**
024     * @author Shuyang Zhou
025     */
026    @Aspect
027    public class ReflectionUtilAdvice {
028    
029            public static void setDeclaredFieldThrowable(
030                    Throwable declaredFieldThrowable) {
031    
032                    _declaredFieldThrowable = declaredFieldThrowable;
033            }
034    
035            public static void setDeclaredMethodThrowable(
036                            Throwable declaredMethodThrowable)
037                    throws ClassNotFoundException {
038    
039                    Class.forName(
040                            ReflectionUtil.class.getName(), true,
041                            ReflectionUtil.class.getClassLoader());
042    
043                    _declaredMethodThrowable = declaredMethodThrowable;
044            }
045    
046            @Around(
047                    "execution(public static java.lang.reflect.Field " +
048                            "com.liferay.portal.kernel.util.ReflectionUtil." +
049                                    "getDeclaredField(Class, String))")
050            public Object getDeclaredField(ProceedingJoinPoint proceedingJoinPoint)
051                    throws Throwable {
052    
053                    if (_declaredFieldThrowable != null) {
054                            throw _declaredFieldThrowable;
055                    }
056    
057                    return proceedingJoinPoint.proceed();
058            }
059    
060            @Around(
061                    "execution(public static java.lang.reflect.Method " +
062                            "com.liferay.portal.kernel.util.ReflectionUtil." +
063                                    "getDeclaredMethod(Class, String, Class...))")
064            public Object getDeclaredMethod(ProceedingJoinPoint proceedingJoinPoint)
065                    throws Throwable {
066    
067                    if (_declaredMethodThrowable != null) {
068                            throw _declaredMethodThrowable;
069                    }
070    
071                    return proceedingJoinPoint.proceed();
072            }
073    
074            private static Throwable _declaredFieldThrowable;
075            private static Throwable _declaredMethodThrowable;
076    
077    }