KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2005 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.AbstractPoolingTargetSource;
21 import org.springframework.aop.target.CommonsPoolTargetSource;
22
23 /**
24  * Convenient superclass for TargetSource creators that create pooling TargetSources.
25  *
26  * @author Rod Johnson
27  * @author Juergen Hoeller
28  * @see org.springframework.aop.target.AbstractPoolingTargetSource
29  * @see org.springframework.aop.target.CommonsPoolTargetSource
30  */

31 public abstract class AbstractPoolingTargetSourceCreator extends AbstractBeanFactoryBasedTargetSourceCreator {
32
33     protected final AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
34             Class JavaDoc beanClass, String JavaDoc beanName) {
35
36         PoolingAttribute poolingAttribute = getPoolingAttribute(beanClass, beanName);
37         if (poolingAttribute == null) {
38             // no pooling attribute
39
return null;
40         }
41         else {
42             AbstractPoolingTargetSource targetSource = newPoolingTargetSource(poolingAttribute);
43             targetSource.setMaxSize(poolingAttribute.getSize());
44             return targetSource;
45         }
46     }
47     
48     /**
49      * Create a new AbstractPoolingTargetSource. This implementation creates a
50      * CommonsPoolTargetSource, but subclasses may wish to override that behavior
51      * (potentially even using different pools for specific PoolingAttribute subclasses).
52      * <p>The created AbstractPoolingTargetSource does not have to be configured,
53      * This will all be handled by this TargetSourceCreator and its base class.
54      * @see org.springframework.aop.target.CommonsPoolTargetSource
55      */

56     protected AbstractPoolingTargetSource newPoolingTargetSource(PoolingAttribute poolingAttribute) {
57         return new CommonsPoolTargetSource();
58     }
59
60     /**
61      * Create a PoolingAttribute for the given bean, if any.
62      * @param beanClass the class of the bean to create a TargetSource for
63      * @param beanName the name of the bean
64      * @return the PoolingAttribute, or null for no pooling
65      */

66     protected abstract PoolingAttribute getPoolingAttribute(Class JavaDoc beanClass, String JavaDoc beanName);
67
68 }
69
Popular Tags