KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > inject > ProxyFactoryBuilder


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  */

16
17 package com.google.inject;
18
19 import com.google.inject.matcher.Matcher;
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23 import org.aopalliance.intercept.MethodInterceptor;
24
25 /**
26  * Creates a {@link ProxyFactory}.
27  *
28  * @author crazybob@google.com (Bob Lee)
29  */

30 class ProxyFactoryBuilder {
31
32   final List JavaDoc<MethodAspect> methodAspects = new ArrayList JavaDoc<MethodAspect>();
33
34   /**
35    * Applies the given method interceptor to the methods matched by the class
36    * and method matchers.
37    *
38    * @param classMatcher matches classes the interceptor should apply to. For
39    * example: {@code only(Runnable.class)}.
40    * @param methodMatcher matches methods the interceptor should apply to. For
41    * example: {@code annotatedWith(Transactional.class)}.
42    * @param interceptors to apply
43    */

44   public ProxyFactoryBuilder intercept(Matcher<? super Class JavaDoc<?>> classMatcher,
45       Matcher<? super Method JavaDoc> methodMatcher,
46       MethodInterceptor... interceptors) {
47     methodAspects.add(
48         new MethodAspect(classMatcher, methodMatcher, interceptors));
49     return this;
50   }
51
52   /**
53    * Creates a {@code ProxyFactory}.
54    */

55   public ProxyFactory create() {
56     return new ProxyFactory(new ArrayList JavaDoc<MethodAspect>(methodAspects));
57   }
58 }
59
Popular Tags