001    /**
002     *   GRANITE DATA SERVICES
003     *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004     *
005     *   This file is part of the Granite Data Services Platform.
006     *
007     *   Granite Data Services is free software; you can redistribute it and/or
008     *   modify it under the terms of the GNU Lesser General Public
009     *   License as published by the Free Software Foundation; either
010     *   version 2.1 of the License, or (at your option) any later version.
011     *
012     *   Granite Data Services is distributed in the hope that it will be useful,
013     *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
015     *   General Public License for more details.
016     *
017     *   You should have received a copy of the GNU Lesser General Public
018     *   License along with this library; if not, write to the Free Software
019     *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
020     *   USA, or see <http://www.gnu.org/licenses/>.
021     */
022    package org.granite.tide.spring;
023    
024    import java.io.Serializable;
025    import java.lang.reflect.Method;
026    
027    import org.aopalliance.aop.Advice;
028    import org.granite.tide.data.DataEnabled;
029    import org.springframework.aop.Pointcut;
030    import org.springframework.aop.support.AbstractPointcutAdvisor;
031    import org.springframework.aop.support.StaticMethodMatcherPointcut;
032    import org.springframework.aop.support.annotation.AnnotationClassFilter;
033    
034    
035    public class TideDataPublishingAdvisor extends AbstractPointcutAdvisor {
036            
037            private static final long serialVersionUID = 1L;
038            
039    
040            private TideDataPublishingInterceptor dataPublishingInterceptor;
041    
042            private final TideDataPublishingPointcut pointcut = new TideDataPublishingPointcut();
043    
044    
045            public TideDataPublishingAdvisor() {
046                    pointcut.setClassFilter(new AnnotationClassFilter(DataEnabled.class));
047            }
048    
049            public TideDataPublishingAdvisor(TideDataPublishingInterceptor interceptor) {
050                    setDataPublishingInterceptor(interceptor);
051            }
052    
053            public void setDataPublishingInterceptor(TideDataPublishingInterceptor interceptor) {
054                    this.dataPublishingInterceptor = interceptor;
055            }
056    
057    
058            public Advice getAdvice() {
059                    return this.dataPublishingInterceptor;
060            }
061    
062            public Pointcut getPointcut() {
063                    return this.pointcut;
064            }
065    
066    
067            private class TideDataPublishingPointcut extends StaticMethodMatcherPointcut implements Serializable {
068    
069                    private static final long serialVersionUID = 1L;
070    
071                    public boolean matches(Method method, Class<?> targetClass) {
072                            return targetClass.isAnnotationPresent(DataEnabled.class) && targetClass.getAnnotation(DataEnabled.class).useInterceptor();
073                    }
074            }
075    
076    }