001 // Copyright 2008, 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
015 package org.apache.tapestry5.ioc.services;
016
017 import org.apache.tapestry5.ioc.AnnotationAccess;
018 import org.apache.tapestry5.ioc.MethodAdvice;
019
020 /**
021 * A decorator used to create an interceptor that delegates each method's invocation to an
022 * {@link org.apache.tapestry5.ioc.MethodAdvice} for advice. Advice can inspect or change method parameters, inspect or
023 * change
024 * the method's return value, and inspect and change thrown exceptions (checked and unchecked).
025 */
026 public interface AspectDecorator
027 {
028 /**
029 * Intercepts method invocations on the delegate and passes them through the provided aspect. Note that the advice
030 * <em>must</em> be thread-safe.
031 *
032 * @param serviceInterface
033 * defines the interface of the interceptor and delegate
034 * @param delegate
035 * the object on which methods will be invoked
036 * @param advice
037 * intercepts the method invocations on the delegate
038 * @param description
039 * used as the toString() of the returned interceptor, unless toString() is part of the
040 * service interface
041 * @return the interceptor, wrapping the delegate with all the advice
042 */
043 <T> T build(Class<T> serviceInterface, T delegate, MethodAdvice advice, String description);
044
045 /**
046 * Creates a builder that can be used to create the interceptor. This is used when only some of the methods need to
047 * be advised, or when different methods need to receive different advice, or when multiple advice is to be
048 * applied.
049 *
050 * @param serviceInterface
051 * defines the interface of the interceptor and the delegate
052 * @param delegate
053 * the object on which methods will be invokes
054 * @param description
055 * used as the toString() of the interceptor unless toString() is part of the service
056 * interface
057 * @return a builder that can be used to generate the final interceptor
058 */
059 <T> AspectInterceptorBuilder<T> createBuilder(Class<T> serviceInterface, T delegate, String description);
060
061 /**
062 * Creates a builder that can be used to create the interceptor. This is used when only some of the methods need to
063 * be advised, or when different methods need to receive different advice, or when multiple advice is to be
064 * applied.
065 *
066 * @param serviceInterface
067 * defines the interface of the interceptor and the delegate
068 * @param delegate
069 * the object on which methods will be invokes
070 * @param annotationAccess
071 * provides access to combined annotations of the underlying service
072 * and service interface
073 * @param description
074 * used as the toString() of the interceptor unless toString() is part of the service
075 * interface
076 * @return a builder that can be used to generate the final interceptor
077 */
078 <T> AspectInterceptorBuilder<T> createBuilder(Class<T> serviceInterface, T delegate,
079 AnnotationAccess annotationAccess, String description);
080 }