BeanDefinitionParserUtils.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. *
  3. */
  4. package org.acegisecurity.util;
  5. import org.springframework.beans.factory.config.RuntimeBeanNameReference;
  6. import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
  7. import org.springframework.beans.factory.support.RootBeanDefinition;
  8. import org.springframework.util.StringUtils;
  9. import org.w3c.dom.Element;
  10. /**
  11. * @author Vishal Puri
  12. *
  13. */
  14. public class BeanDefinitionParserUtils {
  15. /**
  16. * Prevents instantiation
  17. */
  18. private BeanDefinitionParserUtils() {
  19. }
  20. public static void setConstructorArgumentIfAvailable(int index, Element element, String attribute,
  21. boolean isRunTimeBeanReference, RootBeanDefinition definition) {
  22. String propertyValue = element.getAttribute(attribute);
  23. if (StringUtils.hasText(propertyValue)) {
  24. if(!isRunTimeBeanReference){
  25. definition.getConstructorArgumentValues().addIndexedArgumentValue(index, propertyValue);
  26. } else {
  27. definition.getConstructorArgumentValues().addIndexedArgumentValue(index, new RuntimeBeanNameReference(propertyValue));
  28. }
  29. }
  30. }
  31. public static void setPropertyIfAvailable(Element element, String attribute, String property,
  32. RootBeanDefinition definition) {
  33. String propertyValue = element.getAttribute(attribute);
  34. if (StringUtils.hasText(propertyValue)) {
  35. definition.getPropertyValues().addPropertyValue(property, propertyValue);
  36. }
  37. }
  38. }