blob: 26e0e7504666772a49c004e3677559f3c508b798 [file] [log] [blame]
crazyboblee62fcdde2007-02-03 02:10:13 +00001/**
2 * Copyright (C) 2006 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
crazyboblee1b82a8f2007-02-02 23:30:42 +000016
crazyboblee10a3b022007-02-10 01:49:38 +000017package com.google.inject;
crazyboblee1b82a8f2007-02-02 23:30:42 +000018
kevinb9ncad2c2b2007-05-15 17:28:03 +000019import com.google.inject.internal.Objects;
crazyboblee4f79e402007-02-14 02:11:47 +000020import com.google.inject.matcher.Matcher;
crazyboblee1b82a8f2007-02-02 23:30:42 +000021import java.lang.reflect.Method;
crazyboblee62fcdde2007-02-03 02:10:13 +000022import java.util.Arrays;
kevinb9na99dca72007-02-11 04:48:57 +000023import java.util.List;
limpbizkit3d58d6b2008-03-08 16:11:47 +000024import java.util.Collection;
25import java.util.ArrayList;
26
kevinb9na99dca72007-02-11 04:48:57 +000027import org.aopalliance.intercept.MethodInterceptor;
crazyboblee1b82a8f2007-02-02 23:30:42 +000028
29/**
crazyboblee33ce0692007-02-13 23:53:46 +000030 * Ties a matcher to a method interceptor.
crazyboblee1b82a8f2007-02-02 23:30:42 +000031 *
32 * @author crazybob@google.com (Bob Lee)
33 */
34class MethodAspect {
35
crazyboblee33ce0692007-02-13 23:53:46 +000036 final Matcher<? super Class<?>> classMatcher;
37 final Matcher<? super Method> methodMatcher;
crazyboblee62fcdde2007-02-03 02:10:13 +000038 final List<MethodInterceptor> interceptors;
crazyboblee1b82a8f2007-02-02 23:30:42 +000039
crazyboblee33ce0692007-02-13 23:53:46 +000040 MethodAspect(Matcher<? super Class<?>> classMatcher,
limpbizkit3d58d6b2008-03-08 16:11:47 +000041 Matcher<? super Method> methodMatcher, List<MethodInterceptor> interceptors) {
crazyboblee33ce0692007-02-13 23:53:46 +000042 this.classMatcher = Objects.nonNull(classMatcher, "class matcher");
43 this.methodMatcher = Objects.nonNull(methodMatcher, "method matcher");
limpbizkit3d58d6b2008-03-08 16:11:47 +000044 this.interceptors = Objects.nonNull(interceptors, "interceptors");
crazyboblee1b82a8f2007-02-02 23:30:42 +000045 }
46
47 boolean matches(Class<?> clazz) {
crazyboblee33ce0692007-02-13 23:53:46 +000048 return classMatcher.matches(clazz);
crazyboblee1b82a8f2007-02-02 23:30:42 +000049 }
50
51 boolean matches(Method method) {
crazyboblee33ce0692007-02-13 23:53:46 +000052 return methodMatcher.matches(method);
crazyboblee1b82a8f2007-02-02 23:30:42 +000053 }
54
crazyboblee62fcdde2007-02-03 02:10:13 +000055 List<MethodInterceptor> interceptors() {
56 return interceptors;
crazyboblee1b82a8f2007-02-02 23:30:42 +000057 }
58}