01: /*
02: * Copyright 2002-2006 the original author or authors.
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: */
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
37: AbstractBeanFactoryBasedTargetSourceCreator {
38:
39: public static final String PREFIX_COMMONS_POOL = ":";
40: public static final String PREFIX_THREAD_LOCAL = "%";
41: public static final String PREFIX_PROTOTYPE = "!";
42:
43: protected final AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
44: Class beanClass, String beanName) {
45:
46: if (beanName.startsWith(PREFIX_COMMONS_POOL)) {
47: CommonsPoolTargetSource cpts = new CommonsPoolTargetSource();
48: cpts.setMaxSize(25);
49: return cpts;
50: } else if (beanName.startsWith(PREFIX_THREAD_LOCAL)) {
51: return new ThreadLocalTargetSource();
52: } else if (beanName.startsWith(PREFIX_PROTOTYPE)) {
53: return new PrototypeTargetSource();
54: } else {
55: // No match. Don't create a custom target source.
56: return null;
57: }
58: }
59:
60: }
|