01: /**
02: * Copyright (C) 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */package com.google.inject;
16:
17: import com.google.inject.matcher.Matcher;
18: import java.lang.reflect.Method;
19: import java.util.ArrayList;
20: import java.util.List;
21: import org.aopalliance.intercept.MethodInterceptor;
22:
23: /**
24: * Creates a {@link ProxyFactory}.
25: *
26: * @author crazybob@google.com (Bob Lee)
27: */
28: class ProxyFactoryBuilder {
29:
30: final List<MethodAspect> methodAspects = new ArrayList<MethodAspect>();
31:
32: /**
33: * Applies the given method interceptor to the methods matched by the class
34: * and method matchers.
35: *
36: * @param classMatcher matches classes the interceptor should apply to. For
37: * example: {@code only(Runnable.class)}.
38: * @param methodMatcher matches methods the interceptor should apply to. For
39: * example: {@code annotatedWith(Transactional.class)}.
40: * @param interceptors to apply
41: */
42: public ProxyFactoryBuilder intercept(
43: Matcher<? super Class<?>> classMatcher,
44: Matcher<? super Method> methodMatcher,
45: MethodInterceptor... interceptors) {
46: methodAspects.add(new MethodAspect(classMatcher, methodMatcher,
47: interceptors));
48: return this ;
49: }
50:
51: /**
52: * Creates a {@code ProxyFactory}.
53: */
54: public ProxyFactory create() {
55: return new ProxyFactory(new ArrayList<MethodAspect>(
56: methodAspects));
57: }
58: }
|