1. /*
  2. * Copyright 2002-2004 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. package org.springframework.aop.framework.autoproxy.metadata;
  17. import java.util.Collection;
  18. import org.springframework.aop.framework.autoproxy.target.AbstractPoolingTargetSourceCreator;
  19. import org.springframework.aop.framework.autoproxy.target.PoolingAttribute;
  20. import org.springframework.beans.factory.BeanDefinitionStoreException;
  21. import org.springframework.beans.factory.BeanFactory;
  22. import org.springframework.metadata.Attributes;
  23. /**
  24. * PoolingTargetSourceCreator driven by metadata.
  25. * @author Rod Johnson
  26. * @version $Id: AttributesPoolingTargetSourceCreator.java,v 1.3 2004/03/18 02:46:08 trisberg Exp $
  27. */
  28. public class AttributesPoolingTargetSourceCreator extends AbstractPoolingTargetSourceCreator {
  29. private final Attributes attributes;
  30. public AttributesPoolingTargetSourceCreator(Attributes attributes) {
  31. this.attributes = attributes;
  32. }
  33. protected PoolingAttribute getPoolingAttribute(Object bean, String beanName, BeanFactory beanFactory) {
  34. Class beanClass = bean.getClass();
  35. // See if there's a pooling attribute
  36. Collection atts = attributes.getAttributes(beanClass, PoolingAttribute.class);
  37. if (atts.isEmpty()) {
  38. // No pooling attribute
  39. return null;
  40. }
  41. else if (atts.size() > 1) {
  42. throw new BeanDefinitionStoreException("Cannot have more than one pooling attribute on " + beanClass);
  43. }
  44. else {
  45. return (PoolingAttribute) atts.iterator().next();
  46. }
  47. }
  48. }