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 org.apache.tapestry5.plastic.MethodAdvice;
018
019import java.lang.annotation.Annotation;
020import java.lang.reflect.Method;
021
022/**
023 * Interface used with service advisor methods to define advice. Allows advice on specific methods, or on all methods.
024 */
025public interface MethodAdviceReceiver extends AnnotationAccess
026{
027
028    /**
029     * Advises <em>all</em> methods of the interface with the given advice.
030     * @param advice the method advice to be applied.
031     *
032     * @since 5.3
033     */
034    void adviseAllMethods(MethodAdvice advice);
035
036    /**
037     * Adds advice for a specific method of the aspect interceptor being constructed.
038     *
039     * @param method method (of the interface for which an interceptor is being constructed) to be advised. Multiple
040     *               advice is allowed for a single method; the advice will be executed in the order it is added.
041     * @param advice the advice for this particular method. Advice must be threadsafe.
042     * @since 5.3
043     */
044    void adviseMethod(Method method, MethodAdvice advice);
045
046    /**
047     * Returns the interface for which methods may be advised.
048     * @return the interface class instance.
049     *
050     * @since 5.1.0.0
051     */
052    Class getInterface();
053
054    /**
055     * Gets an annotation from a method, via {@link AnnotationAccess#getMethodAnnotationProvider(String, Class...)}.
056     *
057     * @param <T>            type of annotation
058     * @param method         method to search
059     * @param annotationType type of annotation
060     * @return the annotation found on the underlying implementation class (if known) or service interface, or null if
061     *         not found
062     */
063    <T extends Annotation> T getMethodAnnotation(Method method, Class<T> annotationType);
064}