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.bm.ejb3guice.inject;
16:
17: import com.bm.ejb3guice.matcher.Matcher;
18:
19: import java.lang.reflect.Method;
20: import java.util.ArrayList;
21: import java.util.List;
22: import org.aopalliance.intercept.MethodInterceptor;
23:
24: /**
25: * Creates a {@link ProxyFactory}.
26: *
27: * @author crazybob@google.com (Bob Lee)
28: */
29: class ProxyFactoryBuilder {
30:
31: final List<MethodAspect> methodAspects = new ArrayList<MethodAspect>();
32:
33: /**
34: * Applies the given method interceptor to the methods matched by the class
35: * and method matchers.
36: *
37: * @param classMatcher matches classes the interceptor should apply to. For
38: * example: {@code only(Runnable.class)}.
39: * @param methodMatcher matches methods the interceptor should apply to. For
40: * example: {@code annotatedWith(Transactional.class)}.
41: * @param interceptors to apply
42: */
43: public ProxyFactoryBuilder intercept(
44: Matcher<? super Class<?>> classMatcher,
45: Matcher<? super Method> methodMatcher,
46: MethodInterceptor... interceptors) {
47: methodAspects.add(new MethodAspect(classMatcher, methodMatcher,
48: interceptors));
49: return this ;
50: }
51:
52: /**
53: * Creates a {@code ProxyFactory}.
54: */
55: public ProxyFactory create() {
56: return new ProxyFactory(new ArrayList<MethodAspect>(
57: methodAspects));
58: }
59: }
|