001    /**
002     * Copyright (c) 2000-2013 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.spring.aop;
016    
017    import com.liferay.portal.kernel.spring.aop.Skip;
018    
019    import java.lang.annotation.Annotation;
020    
021    import java.util.Collections;
022    
023    import org.aopalliance.intercept.MethodInterceptor;
024    import org.aopalliance.intercept.MethodInvocation;
025    
026    /**
027     * @author Shuyang Zhou
028     */
029    public class SkipAdvice extends AnnotationChainableMethodAdvice<Skip> {
030    
031            @Override
032            public Object before(MethodInvocation methodInvocation) throws Throwable {
033                    Skip skip = findAnnotation(methodInvocation);
034    
035                    if (skip != _nullSkip) {
036                            MethodInterceptorsBag methodInterceptorsBag =
037                                    serviceBeanAopCacheManager.getMethodInterceptorsBag(
038                                            methodInvocation);
039    
040                            MethodInterceptorsBag newMethodInterceptorsBag =
041                                    new MethodInterceptorsBag(
042                                            methodInterceptorsBag.getClassLevelMethodInterceptors(),
043                                            Collections.<MethodInterceptor>emptyList());
044    
045                            serviceBeanAopCacheManager.putMethodInterceptorsBag(
046                                    methodInvocation, newMethodInterceptorsBag);
047    
048                            ServiceBeanMethodInvocation serviceBeanMethodInvocation =
049                                    (ServiceBeanMethodInvocation)methodInvocation;
050    
051                            serviceBeanMethodInvocation.setMethodInterceptors(
052                                    Collections.<MethodInterceptor>emptyList());
053                    }
054    
055                    return null;
056            }
057    
058            @Override
059            public Skip getNullAnnotation() {
060                    return _nullSkip;
061            }
062    
063            private static Skip _nullSkip = new Skip() {
064    
065                    @Override
066                    public Class<? extends Annotation> annotationType() {
067                            return Skip.class;
068                    }
069    
070            };
071    
072    }