KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > framework > autoproxy > target > QuickTargetSourceCreator


1 /*
2  * Copyright 2002-2006 the original author or authors.
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 org.springframework.aop.framework.autoproxy.target;
18
19 import org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource;
20 import org.springframework.aop.target.CommonsPoolTargetSource;
21 import org.springframework.aop.target.PrototypeTargetSource;
22 import org.springframework.aop.target.ThreadLocalTargetSource;
23
24 /**
25  * Convenient TargetSourceCreator using bean name prefixes to create one of three
26  * well-known TargetSource types:
27  * <li>: CommonsPoolTargetSource
28  * <li>% ThreadLocalTargetSource
29  * <li>! PrototypeTargetSource
30  *
31  * @author Rod Johnson
32  * @see org.springframework.aop.target.CommonsPoolTargetSource
33  * @see org.springframework.aop.target.ThreadLocalTargetSource
34  * @see org.springframework.aop.target.PrototypeTargetSource
35  */

36 public class QuickTargetSourceCreator extends AbstractBeanFactoryBasedTargetSourceCreator {
37
38     public static final String JavaDoc PREFIX_COMMONS_POOL = ":";
39     public static final String JavaDoc PREFIX_THREAD_LOCAL = "%";
40     public static final String JavaDoc PREFIX_PROTOTYPE = "!";
41
42     protected final AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
43             Class JavaDoc beanClass, String JavaDoc beanName) {
44
45         if (beanName.startsWith(PREFIX_COMMONS_POOL)) {
46             CommonsPoolTargetSource cpts = new CommonsPoolTargetSource();
47             cpts.setMaxSize(25);
48             return cpts;
49         }
50         else if (beanName.startsWith(PREFIX_THREAD_LOCAL)) {
51             return new ThreadLocalTargetSource();
52         }
53         else if (beanName.startsWith(PREFIX_PROTOTYPE)) {
54             return new PrototypeTargetSource();
55         }
56         else {
57             // No match. Don't create a custom target source.
58
return null;
59         }
60     }
61     
62 }
63
Popular Tags