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