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                            if (methodInterceptorsBag == null) {
041                                    return null;
042                            }
043    
044                            MethodInterceptorsBag newMethodInterceptorsBag =
045                                    new MethodInterceptorsBag(
046                                            methodInterceptorsBag.getClassLevelMethodInterceptors(),
047                                            Collections.<MethodInterceptor>emptyList());
048    
049                            serviceBeanAopCacheManager.putMethodInterceptorsBag(
050                                    methodInvocation, newMethodInterceptorsBag);
051    
052                            ServiceBeanMethodInvocation serviceBeanMethodInvocation =
053                                    (ServiceBeanMethodInvocation)methodInvocation;
054    
055                            serviceBeanMethodInvocation.setMethodInterceptors(
056                                    Collections.<MethodInterceptor>emptyList());
057                    }
058    
059                    return null;
060            }
061    
062            @Override
063            public Skip getNullAnnotation() {
064                    return _nullSkip;
065            }
066    
067            private static Skip _nullSkip = new Skip() {
068    
069                    @Override
070                    public Class<? extends Annotation> annotationType() {
071                            return Skip.class;
072                    }
073    
074            };
075    
076    }