001/*
002 * Copyright 2002-2015 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.aop.aspectj.annotation;
018
019import java.lang.reflect.Method;
020import java.util.List;
021
022import org.aopalliance.aop.Advice;
023
024import org.springframework.aop.Advisor;
025import org.springframework.aop.aspectj.AspectJExpressionPointcut;
026import org.springframework.aop.framework.AopConfigException;
027
028/**
029 * Interface for factories that can create Spring AOP Advisors from classes
030 * annotated with AspectJ annotation syntax.
031 *
032 * @author Rod Johnson
033 * @author Juergen Hoeller
034 * @since 2.0
035 * @see AspectMetadata
036 * @see org.aspectj.lang.reflect.AjTypeSystem
037 */
038public interface AspectJAdvisorFactory {
039
040        /**
041         * Determine whether or not the given class is an aspect, as reported
042         * by AspectJ's {@link org.aspectj.lang.reflect.AjTypeSystem}.
043         * <p>Will simply return {@code false} if the supposed aspect is
044         * invalid (such as an extension of a concrete aspect class).
045         * Will return true for some aspects that Spring AOP cannot process,
046         * such as those with unsupported instantiation models.
047         * Use the {@link #validate} method to handle these cases if necessary.
048         * @param clazz the supposed annotation-style AspectJ class
049         * @return whether or not this class is recognized by AspectJ as an aspect class
050         */
051        boolean isAspect(Class<?> clazz);
052
053        /**
054         * Is the given class a valid AspectJ aspect class?
055         * @param aspectClass the supposed AspectJ annotation-style class to validate
056         * @throws AopConfigException if the class is an invalid aspect
057         * (which can never be legal)
058         * @throws NotAnAtAspectException if the class is not an aspect at all
059         * (which may or may not be legal, depending on the context)
060         */
061        void validate(Class<?> aspectClass) throws AopConfigException;
062
063        /**
064         * Build Spring AOP Advisors for all annotated At-AspectJ methods
065         * on the specified aspect instance.
066         * @param aspectInstanceFactory the aspect instance factory
067         * (not the aspect instance itself in order to avoid eager instantiation)
068         * @return a list of advisors for this class
069         */
070        List<Advisor> getAdvisors(MetadataAwareAspectInstanceFactory aspectInstanceFactory);
071
072        /**
073         * Build a Spring AOP Advisor for the given AspectJ advice method.
074         * @param candidateAdviceMethod the candidate advice method
075         * @param aspectInstanceFactory the aspect instance factory
076         * @param declarationOrder the declaration order within the aspect
077         * @param aspectName the name of the aspect
078         * @return {@code null} if the method is not an AspectJ advice method
079         * or if it is a pointcut that will be used by other advice but will not
080         * create a Spring advice in its own right
081         */
082        Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory,
083                        int declarationOrder, String aspectName);
084
085        /**
086         * Build a Spring AOP Advice for the given AspectJ advice method.
087         * @param candidateAdviceMethod the candidate advice method
088         * @param expressionPointcut the AspectJ expression pointcut
089         * @param aspectInstanceFactory the aspect instance factory
090         * @param declarationOrder the declaration order within the aspect
091         * @param aspectName the name of the aspect
092         * @return {@code null} if the method is not an AspectJ advice method
093         * or if it is a pointcut that will be used by other advice but will not
094         * create a Spring advice in its own right
095         * @see org.springframework.aop.aspectj.AspectJAroundAdvice
096         * @see org.springframework.aop.aspectj.AspectJMethodBeforeAdvice
097         * @see org.springframework.aop.aspectj.AspectJAfterAdvice
098         * @see org.springframework.aop.aspectj.AspectJAfterReturningAdvice
099         * @see org.springframework.aop.aspectj.AspectJAfterThrowingAdvice
100         */
101        Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut,
102                        MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName);
103
104}