KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > framework > autoproxy > metadata > AttributesPoolingTargetSourceCreator


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.metadata;
18
19 import java.util.Collection JavaDoc;
20
21 import org.springframework.aop.framework.autoproxy.target.AbstractPoolingTargetSourceCreator;
22 import org.springframework.aop.framework.autoproxy.target.PoolingAttribute;
23 import org.springframework.beans.factory.BeanDefinitionStoreException;
24 import org.springframework.metadata.Attributes;
25
26 /**
27  * PoolingTargetSourceCreator driven by metadata.
28  *
29  * @author Rod Johnson
30  */

31 public class AttributesPoolingTargetSourceCreator extends AbstractPoolingTargetSourceCreator {
32
33     /**
34      * Underlying Attributes implementation that we're using.
35      */

36     private Attributes attributes;
37
38     /**
39      * Create a new AttributesPoolingTargetSourceCreator.
40      * @see #setAttributes
41      */

42     public AttributesPoolingTargetSourceCreator() {
43     }
44
45     /**
46      * Create a new AttributesPrototypeTargetSourceCreator.
47      * @param attributes the Attributes implementation to use
48      */

49     public AttributesPoolingTargetSourceCreator(Attributes attributes) {
50         if (attributes == null) {
51             throw new IllegalArgumentException JavaDoc("Attributes is required");
52         }
53         this.attributes = attributes;
54     }
55
56     /**
57      * Set the Attributes implementation to use.
58      */

59     public void setAttributes(Attributes attributes) {
60         this.attributes = attributes;
61     }
62
63     public void afterPropertiesSet() {
64         if (this.attributes == null) {
65             throw new IllegalArgumentException JavaDoc("'attributes' is required");
66         }
67     }
68
69     protected PoolingAttribute getPoolingAttribute(Class JavaDoc beanClass, String JavaDoc beanName) {
70         // See if there's a pooling attribute.
71
Collection JavaDoc atts = this.attributes.getAttributes(beanClass, PoolingAttribute.class);
72         if (atts.isEmpty()) {
73             // No pooling attribute found.
74
return null;
75         }
76         else if (atts.size() > 1) {
77             throw new BeanDefinitionStoreException(
78                     "Cannot have more than one pooling attribute on [" + beanClass.getName() + "]");
79         }
80         else {
81             return (PoolingAttribute) atts.iterator().next();
82         }
83     }
84
85 }
86
Popular Tags