crazyboblee | 62fcdde | 2007-02-03 02:10:13 +0000 | [diff] [blame] | 1 | /** |
| 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 | */ |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 16 | |
crazyboblee | 10a3b02 | 2007-02-10 01:49:38 +0000 | [diff] [blame] | 17 | package com.google.inject; |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 18 | |
kevinb9n | cad2c2b | 2007-05-15 17:28:03 +0000 | [diff] [blame] | 19 | import com.google.inject.internal.Objects; |
crazyboblee | 4f79e40 | 2007-02-14 02:11:47 +0000 | [diff] [blame] | 20 | import com.google.inject.matcher.Matcher; |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 21 | import java.lang.reflect.Method; |
crazyboblee | 62fcdde | 2007-02-03 02:10:13 +0000 | [diff] [blame] | 22 | import java.util.Arrays; |
kevinb9n | a99dca7 | 2007-02-11 04:48:57 +0000 | [diff] [blame] | 23 | import java.util.List; |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 24 | import java.util.Collection; |
| 25 | import java.util.ArrayList; |
| 26 | |
kevinb9n | a99dca7 | 2007-02-11 04:48:57 +0000 | [diff] [blame] | 27 | import org.aopalliance.intercept.MethodInterceptor; |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 28 | |
| 29 | /** |
crazyboblee | 33ce069 | 2007-02-13 23:53:46 +0000 | [diff] [blame] | 30 | * Ties a matcher to a method interceptor. |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 31 | * |
| 32 | * @author crazybob@google.com (Bob Lee) |
| 33 | */ |
| 34 | class MethodAspect { |
| 35 | |
crazyboblee | 33ce069 | 2007-02-13 23:53:46 +0000 | [diff] [blame] | 36 | final Matcher<? super Class<?>> classMatcher; |
| 37 | final Matcher<? super Method> methodMatcher; |
crazyboblee | 62fcdde | 2007-02-03 02:10:13 +0000 | [diff] [blame] | 38 | final List<MethodInterceptor> interceptors; |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 39 | |
crazyboblee | 33ce069 | 2007-02-13 23:53:46 +0000 | [diff] [blame] | 40 | MethodAspect(Matcher<? super Class<?>> classMatcher, |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 41 | Matcher<? super Method> methodMatcher, List<MethodInterceptor> interceptors) { |
crazyboblee | 33ce069 | 2007-02-13 23:53:46 +0000 | [diff] [blame] | 42 | this.classMatcher = Objects.nonNull(classMatcher, "class matcher"); |
| 43 | this.methodMatcher = Objects.nonNull(methodMatcher, "method matcher"); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 44 | this.interceptors = Objects.nonNull(interceptors, "interceptors"); |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | boolean matches(Class<?> clazz) { |
crazyboblee | 33ce069 | 2007-02-13 23:53:46 +0000 | [diff] [blame] | 48 | return classMatcher.matches(clazz); |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | boolean matches(Method method) { |
crazyboblee | 33ce069 | 2007-02-13 23:53:46 +0000 | [diff] [blame] | 52 | return methodMatcher.matches(method); |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 53 | } |
| 54 | |
crazyboblee | 62fcdde | 2007-02-03 02:10:13 +0000 | [diff] [blame] | 55 | List<MethodInterceptor> interceptors() { |
| 56 | return interceptors; |
crazyboblee | 1b82a8f | 2007-02-02 23:30:42 +0000 | [diff] [blame] | 57 | } |
| 58 | } |