001// Copyright 2009, 2011 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007// http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry5.ioc;
016
017import java.lang.annotation.Annotation;
018import java.lang.reflect.Method;
019
020/**
021 * Interface used with service advisor methods to define advice. Allows advice on specific methods, or on all methods.
022 */
023public interface MethodAdviceReceiver extends AnnotationAccess
024{
025    /**
026     * Adds advice for a specific method of the aspect interceptor being constructed.
027     * 
028     * @param method
029     *            method (of the interface for which an interceptor is being constructed) to be advised. Multiple
030     *            advice is allowed for a single method; the advice will be executed in the order it is added.
031     * @param advice
032     *            the advice for this particular method. Advice must be threadsafe.
033     * @deprecated Deprecated in 5.3, to be removed in 5.4. Replaced with
034     *             {@link #adviseMethod(Method, org.apache.tapestry5.plastic.MethodAdvice)}
035     */
036    void adviseMethod(Method method, MethodAdvice advice);
037
038    /**
039     * Advises <em>all</em> methods of the interface with the given advice.
040     * 
041     * @deprecated Deprecated in 5.3, to be removed in 5.4. Replaced with
042     *             {@link #adviseAllMethods(org.apache.tapestry5.plastic.MethodAdvice)}.
043     */
044    void adviseAllMethods(MethodAdvice advice);
045
046    /**
047     * Adds advice for a specific method of the aspect interceptor being constructed.
048     * 
049     * @param method
050     *            method (of the interface for which an interceptor is being constructed) to be advised. Multiple
051     *            advice is allowed for a single method; the advice will be executed in the order it is added.
052     * @param advice
053     *            the advice for this particular method. Advice must be threadsafe.
054     * @since 5.3
055     */
056    void adviseMethod(Method method, org.apache.tapestry5.plastic.MethodAdvice advice);
057
058    /**
059     * Advises <em>all</em> methods of the interface with the given advice.
060     * 
061     * @since 5.3
062     */
063    void adviseAllMethods(org.apache.tapestry5.plastic.MethodAdvice advice);
064
065    /**
066     * Returns the interface for which methods may be advised.
067     * 
068     * @see org.apache.tapestry5.ioc.services.MethodIterator
069     * @since 5.1.0.0
070     */
071    Class getInterface();
072
073    /**
074     * Gets an annotation from a method, via {@link AnnotationAccess#getMethodAnnotationProvider(String, Class...)}.
075     * 
076     * @param <T>
077     *            type of annotation
078     * @param method
079     *            method to search
080     * @param annotationType
081     *            type of annotation
082     * @return the annotation found on the underlying implementation class (if known) or service interface, or null if
083     *         not found
084     */
085    <T extends Annotation> T getMethodAnnotation(Method method, Class<T> annotationType);
086}