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.AbstractPrototypeBasedTargetSourceCreator;
  19. import org.springframework.aop.target.AbstractPrototypeBasedTargetSource;
  20. import org.springframework.aop.target.PrototypeTargetSource;
  21. import org.springframework.beans.factory.BeanFactory;
  22. import org.springframework.metadata.Attributes;
  23. /**
  24. * PrototypeTargetSourceCreator driven by metadata. Creates a prototype
  25. * only if there's a PrototypeAttribute associated with the class.
  26. * @author Rod Johnson
  27. * @version $Id: AttributesPrototypeTargetSourceCreator.java,v 1.5 2004/04/21 11:54:20 jhoeller Exp $
  28. * @see org.springframework.aop.target.PrototypeTargetSource
  29. */
  30. public class AttributesPrototypeTargetSourceCreator extends AbstractPrototypeBasedTargetSourceCreator {
  31. private final Attributes attributes;
  32. public AttributesPrototypeTargetSourceCreator(Attributes attributes) {
  33. this.attributes = attributes;
  34. }
  35. protected AbstractPrototypeBasedTargetSource createPrototypeTargetSource(Object bean, String beanName,
  36. BeanFactory bf) {
  37. Class beanClass = bean.getClass();
  38. // See if there's a pooling attribute
  39. Collection atts = attributes.getAttributes(beanClass, PrototypeAttribute.class);
  40. if (atts.isEmpty()) {
  41. // No pooling attribute: don't create a custom TargetSource
  42. return null;
  43. }
  44. else {
  45. return new PrototypeTargetSource();
  46. }
  47. }
  48. }