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     *
031     * @since 5.3
032     */
033    void adviseAllMethods(MethodAdvice advice);
034
035    /**
036     * Adds advice for a specific method of the aspect interceptor being constructed.
037     *
038     * @param method method (of the interface for which an interceptor is being constructed) to be advised. Multiple
039     *               advice is allowed for a single method; the advice will be executed in the order it is added.
040     * @param advice the advice for this particular method. Advice must be threadsafe.
041     * @since 5.3
042     */
043    void adviseMethod(Method method, MethodAdvice advice);
044
045    /**
046     * Returns the interface for which methods may be advised.
047     *
048     * @since 5.1.0.0
049     */
050    Class getInterface();
051
052    /**
053     * Gets an annotation from a method, via {@link AnnotationAccess#getMethodAnnotationProvider(String, Class...)}.
054     *
055     * @param <T>            type of annotation
056     * @param method         method to search
057     * @param annotationType type of annotation
058     * @return the annotation found on the underlying implementation class (if known) or service interface, or null if
059     *         not found
060     */
061    <T extends Annotation> T getMethodAnnotation(Method method, Class<T> annotationType);
062}