001: /*
002: * Copyright 2002-2007 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: * http://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:
017: package org.springframework.aop.aspectj.annotation;
018:
019: import java.lang.reflect.Method;
020: import java.util.List;
021:
022: import org.aopalliance.aop.Advice;
023:
024: import org.springframework.aop.Advisor;
025: import org.springframework.aop.aspectj.AspectJExpressionPointcut;
026: import 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: */
038: public 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</code> 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 aif the aspect instance factory (not the aspect instance itself
067: * in order to avoid eager instantiation)
068: * @return a list of advisors for this class
069: */
070: List<Advisor> getAdvisors(MetadataAwareAspectInstanceFactory aif);
071:
072: /**
073: * Build a Spring AOP Advisor for the given AspectJ advice method.
074: * @param candidateAdviceMethod the candidate advice method
075: * @param aif the aspect instance factory
076: * @param declarationOrderInAspect the declaration order within the aspect
077: * @param aspectName the name of the aspect
078: * @return <code>null</code> 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,
083: MetadataAwareAspectInstanceFactory aif,
084: int declarationOrderInAspect, String aspectName);
085:
086: /**
087: * Build a Spring AOP Advice for the given AspectJ advice method.
088: * @param candidateAdviceMethod the candidate advice method
089: * @param pointcut the corresponding AspectJ expression pointcut
090: * @param aif the aspect instance factory
091: * @param declarationOrderInAspect the declaration order within the aspect
092: * @param aspectName the name of the aspect
093: * @return <code>null</code> if the method is not an AspectJ advice method
094: * or if it is a pointcut that will be used by other advice but will not
095: * create a Spring advice in its own right
096: * @see org.springframework.aop.aspectj.AspectJAroundAdvice
097: * @see org.springframework.aop.aspectj.AspectJMethodBeforeAdvice
098: * @see org.springframework.aop.aspectj.AspectJAfterAdvice
099: * @see org.springframework.aop.aspectj.AspectJAfterReturningAdvice
100: * @see org.springframework.aop.aspectj.AspectJAfterThrowingAdvice
101: */
102: Advice getAdvice(Method candidateAdviceMethod,
103: AspectJExpressionPointcut pointcut,
104: MetadataAwareAspectInstanceFactory aif,
105: int declarationOrderInAspect, String aspectName);
106:
107: }
|