From: Costin L. <cos...@us...> - 2008-10-21 10:36:03
|
Update of /cvsroot/springframework/spring/src/org/springframework/beans/factory/xml In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9018/src/org/springframework/beans/factory/xml Modified Files: BeanDefinitionParserDelegate.java Log Message: + break some big parsing methods into smaller pieces to allow reuse Index: BeanDefinitionParserDelegate.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** BeanDefinitionParserDelegate.java 14 Oct 2008 15:14:15 -0000 1.58 --- BeanDefinitionParserDelegate.java 21 Oct 2008 10:35:49 -0000 1.59 *************** *** 67,75 **** /** ! * Stateful delegate class used to parse XML bean definitions. ! * Intended for use by both the main parser and any extension * {@link BeanDefinitionParser BeanDefinitionParsers} or * {@link BeanDefinitionDecorator BeanDefinitionDecorators}. ! * * @author Rob Harrop * @author Juergen Hoeller --- 67,75 ---- /** ! * Stateful delegate class used to parse XML bean definitions. Intended for use ! * by both the main parser and any extension * {@link BeanDefinitionParser BeanDefinitionParsers} or * {@link BeanDefinitionDecorator BeanDefinitionDecorators}. ! * * @author Rob Harrop * @author Juergen Hoeller *************** *** 87,92 **** /** ! * Value of a T/F attribute that represents true. ! * Anything else represents false. Case seNsItive. */ public static final String TRUE_VALUE = "true"; --- 87,92 ---- /** ! * Value of a T/F attribute that represents true. Anything else represents ! * false. Case seNsItive. */ public static final String TRUE_VALUE = "true"; *************** *** 228,232 **** public static final String DEFAULT_DESTROY_METHOD_ATTRIBUTE = "default-destroy-method"; - protected final Log logger = LogFactory.getLog(getClass()); --- 228,231 ---- *************** *** 238,242 **** /** ! * Stores all used bean names so we can enforce uniqueness on a per file basis. */ private final Set usedNames = new HashSet(); --- 237,242 ---- /** ! * Stores all used bean names so we can enforce uniqueness on a per file ! * basis. */ private final Set usedNames = new HashSet(); *************** *** 244,249 **** /** ! * Create a new BeanDefinitionParserDelegate associated with the ! * supplied {@link XmlReaderContext}. */ public BeanDefinitionParserDelegate(XmlReaderContext readerContext) { --- 244,249 ---- /** ! * Create a new BeanDefinitionParserDelegate associated with the supplied ! * {@link XmlReaderContext}. */ public BeanDefinitionParserDelegate(XmlReaderContext readerContext) { *************** *** 259,266 **** } - /** ! * Invoke the {@link org.springframework.beans.factory.parsing.SourceExtractor} to pull the ! * source metadata from the supplied {@link Element}. */ protected Object extractSource(Element ele) { --- 259,266 ---- } /** ! * Invoke the ! * {@link org.springframework.beans.factory.parsing.SourceExtractor} to pull ! * the source metadata from the supplied {@link Element}. */ protected Object extractSource(Element ele) { *************** *** 289,296 **** } - /** * Initialize the default lazy-init, autowire, dependency check settings, * init-method, destroy-method and merge settings. * @see #getDefaults() */ --- 289,296 ---- } /** * Initialize the default lazy-init, autowire, dependency check settings, * init-method, destroy-method and merge settings. + * * @see #getDefaults() */ *************** *** 325,330 **** /** ! * Return the default settings for bean definitions as indicated within ! * the attributes of the top-level <code><beans/></code> element. */ public BeanDefinitionDefaults getBeanDefinitionDefaults() { --- 325,330 ---- /** ! * Return the default settings for bean definitions as indicated within the ! * attributes of the top-level <code><beans/></code> element. */ public BeanDefinitionDefaults getBeanDefinitionDefaults() { *************** *** 349,356 **** } - /** ! * Parses the supplied <code><bean></code> element. May return <code>null</code> ! * if there were errors during parse. Errors are reported to the * {@link org.springframework.beans.factory.parsing.ProblemReporter}. */ --- 349,356 ---- } /** ! * Parses the supplied <code><bean></code> element. May return ! * <code>null</code> if there were errors during parse. Errors are ! * reported to the * {@link org.springframework.beans.factory.parsing.ProblemReporter}. */ *************** *** 360,365 **** /** ! * Parses the supplied <code><bean></code> element. May return <code>null</code> ! * if there were errors during parse. Errors are reported to the * {@link org.springframework.beans.factory.parsing.ProblemReporter}. */ --- 360,366 ---- /** ! * Parses the supplied <code><bean></code> element. May return ! * <code>null</code> if there were errors during parse. Errors are ! * reported to the * {@link org.springframework.beans.factory.parsing.ProblemReporter}. */ *************** *** 378,383 **** beanName = (String) aliases.remove(0); if (logger.isDebugEnabled()) { ! logger.debug("No XML 'id' specified - using '" + beanName + ! "' as bean name and " + aliases + " as aliases"); } } --- 379,384 ---- beanName = (String) aliases.remove(0); if (logger.isDebugEnabled()) { ! logger.debug("No XML 'id' specified - using '" + beanName + "' as bean name and " + aliases ! + " as aliases"); } } *************** *** 392,397 **** try { if (containingBean != null) { ! beanName = BeanDefinitionReaderUtils.generateBeanName( ! beanDefinition, this.readerContext.getRegistry(), true); } else { --- 393,398 ---- try { if (containingBean != null) { ! beanName = BeanDefinitionReaderUtils.generateBeanName(beanDefinition, ! this.readerContext.getRegistry(), true); } else { *************** *** 401,413 **** // This is expected for Spring 1.2/2.0 backwards compatibility. String beanClassName = beanDefinition.getBeanClassName(); ! if (beanClassName != null && ! beanName.startsWith(beanClassName) && beanName.length() > beanClassName.length() && ! !this.readerContext.getRegistry().isBeanNameInUse(beanClassName)) { aliases.add(beanClassName); } } if (logger.isDebugEnabled()) { ! logger.debug("Neither XML 'id' nor 'name' specified - " + ! "using generated bean name [" + beanName + "]"); } } --- 402,414 ---- // This is expected for Spring 1.2/2.0 backwards compatibility. String beanClassName = beanDefinition.getBeanClassName(); ! if (beanClassName != null && beanName.startsWith(beanClassName) ! && beanName.length() > beanClassName.length() ! && !this.readerContext.getRegistry().isBeanNameInUse(beanClassName)) { aliases.add(beanClassName); } } if (logger.isDebugEnabled()) { ! logger.debug("Neither XML 'id' nor 'name' specified - " + "using generated bean name [" ! + beanName + "]"); } } *************** *** 425,429 **** /** ! * Validate that the specified bean name and aliases have not been used already. */ protected void checkNameUniqueness(String beanName, List aliases, Element beanElement) { --- 426,431 ---- /** ! * Validate that the specified bean name and aliases have not been used ! * already. */ protected void checkNameUniqueness(String beanName, List aliases, Element beanElement) { *************** *** 445,453 **** /** ! * Parse the bean definition itself, without regard to name or aliases. May return ! * <code>null</code> if problems occured during the parse of the bean definition. */ ! public AbstractBeanDefinition parseBeanDefinitionElement( ! Element ele, String beanName, BeanDefinition containingBean) { this.parseState.push(new BeanEntry(beanName)); --- 447,455 ---- /** ! * Parse the bean definition itself, without regard to name or aliases. May ! * return <code>null</code> if problems occured during the parse of the ! * bean definition. */ ! public AbstractBeanDefinition parseBeanDefinitionElement(Element ele, String beanName, BeanDefinition containingBean) { this.parseState.push(new BeanEntry(beanName)); *************** *** 465,555 **** AbstractBeanDefinition bd = createBeanDefinition(className, parent); ! if (ele.hasAttribute(SCOPE_ATTRIBUTE)) { ! // Spring 2.x "scope" attribute ! bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE)); ! if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) { ! error("Specify either 'scope' or 'singleton', not both", ele); ! } ! } ! else if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) { ! // Spring 1.x "singleton" attribute ! bd.setScope(TRUE_VALUE.equals(ele.getAttribute(SINGLETON_ATTRIBUTE)) ? ! BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE); ! } ! else if (containingBean != null) { ! // Take default from containing bean in case of an inner bean definition. ! bd.setScope(containingBean.getScope()); ! } ! ! if (ele.hasAttribute(ABSTRACT_ATTRIBUTE)) { ! bd.setAbstract(TRUE_VALUE.equals(ele.getAttribute(ABSTRACT_ATTRIBUTE))); ! } ! ! String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE); ! if (DEFAULT_VALUE.equals(lazyInit) && bd.isSingleton()) { ! // Just apply default to singletons, as lazy-init has no meaning for prototypes. ! lazyInit = this.defaults.getLazyInit(); ! } ! bd.setLazyInit(TRUE_VALUE.equals(lazyInit)); ! ! String autowire = ele.getAttribute(AUTOWIRE_ATTRIBUTE); ! bd.setAutowireMode(getAutowireMode(autowire)); ! ! String dependencyCheck = ele.getAttribute(DEPENDENCY_CHECK_ATTRIBUTE); ! bd.setDependencyCheck(getDependencyCheck(dependencyCheck)); ! ! if (ele.hasAttribute(DEPENDS_ON_ATTRIBUTE)) { ! String dependsOn = ele.getAttribute(DEPENDS_ON_ATTRIBUTE); ! bd.setDependsOn(StringUtils.tokenizeToStringArray(dependsOn, BEAN_NAME_DELIMITERS)); ! } ! ! String autowireCandidate = ele.getAttribute(AUTOWIRE_CANDIDATE_ATTRIBUTE); ! if ("".equals(autowireCandidate) || DEFAULT_VALUE.equals(autowireCandidate)) { ! String candidatePattern = this.defaults.getAutowireCandidates(); ! if (candidatePattern != null) { ! String[] patterns = StringUtils.commaDelimitedListToStringArray(candidatePattern); ! bd.setAutowireCandidate(PatternMatchUtils.simpleMatch(patterns, beanName)); ! } ! } ! else { ! bd.setAutowireCandidate(TRUE_VALUE.equals(autowireCandidate)); ! } ! ! if (ele.hasAttribute(PRIMARY_ATTRIBUTE)) { ! bd.setPrimary(TRUE_VALUE.equals(ele.getAttribute(PRIMARY_ATTRIBUTE))); ! } ! ! if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) { ! String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE); ! if (!"".equals(initMethodName)) { ! bd.setInitMethodName(initMethodName); ! } ! } ! else { ! if (this.defaults.getInitMethod() != null) { ! bd.setInitMethodName(this.defaults.getInitMethod()); ! bd.setEnforceInitMethod(false); ! } ! } ! ! if (ele.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) { ! String destroyMethodName = ele.getAttribute(DESTROY_METHOD_ATTRIBUTE); ! if (!"".equals(destroyMethodName)) { ! bd.setDestroyMethodName(destroyMethodName); ! } ! } ! else { ! if (this.defaults.getDestroyMethod() != null) { ! bd.setDestroyMethodName(this.defaults.getDestroyMethod()); ! bd.setEnforceDestroyMethod(false); ! } ! } ! ! if (ele.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) { ! bd.setFactoryMethodName(ele.getAttribute(FACTORY_METHOD_ATTRIBUTE)); ! } ! if (ele.hasAttribute(FACTORY_BEAN_ATTRIBUTE)) { ! bd.setFactoryBeanName(ele.getAttribute(FACTORY_BEAN_ATTRIBUTE)); ! } bd.setDescription(DomUtils.getChildElementValueByTagName(ele, DESCRIPTION_ELEMENT)); --- 467,471 ---- AbstractBeanDefinition bd = createBeanDefinition(className, parent); ! parseBeanDefinitionAttributes(ele, beanName, containingBean, bd); bd.setDescription(DomUtils.getChildElementValueByTagName(ele, DESCRIPTION_ELEMENT)); *************** *** 585,599 **** /** * Create a bean definition for the given class name and parent name. * @param className the name of the bean class * @param parentName the name of the bean's parent bean * @return the newly created bean definition ! * @throws ClassNotFoundException if bean class resolution was attempted but failed */ protected AbstractBeanDefinition createBeanDefinition(String className, String parentName) throws ClassNotFoundException { ! return BeanDefinitionReaderUtils.createBeanDefinition( ! parentName, className, this.readerContext.getBeanClassLoader()); } --- 501,621 ---- /** + * Apply the attributes of the given bean element to the given bean + * definition. + * + * @param ele bean declaration element + * @param beanName bean name + * @param containingBean containing bean definition + * @return a bean definition initialized according to the bean element + * attributes + */ + public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String beanName, + BeanDefinition containingBean, AbstractBeanDefinition bd) { + + if (ele.hasAttribute(SCOPE_ATTRIBUTE)) { + // Spring 2.x "scope" attribute + bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE)); + if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) { + error("Specify either 'scope' or 'singleton', not both", ele); + } + } + else if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) { + // Spring 1.x "singleton" attribute + bd.setScope(TRUE_VALUE.equals(ele.getAttribute(SINGLETON_ATTRIBUTE)) ? BeanDefinition.SCOPE_SINGLETON + : BeanDefinition.SCOPE_PROTOTYPE); + } + else if (containingBean != null) { + // Take default from containing bean in case of an inner bean definition. + bd.setScope(containingBean.getScope()); + } + + if (ele.hasAttribute(ABSTRACT_ATTRIBUTE)) { + bd.setAbstract(TRUE_VALUE.equals(ele.getAttribute(ABSTRACT_ATTRIBUTE))); + } + + String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE); + if (DEFAULT_VALUE.equals(lazyInit) && bd.isSingleton()) { + // Just apply default to singletons, as lazy-init has no meaning for prototypes. + lazyInit = this.defaults.getLazyInit(); + } + bd.setLazyInit(TRUE_VALUE.equals(lazyInit)); + + String autowire = ele.getAttribute(AUTOWIRE_ATTRIBUTE); + bd.setAutowireMode(getAutowireMode(autowire)); + + String dependencyCheck = ele.getAttribute(DEPENDENCY_CHECK_ATTRIBUTE); + bd.setDependencyCheck(getDependencyCheck(dependencyCheck)); + + if (ele.hasAttribute(DEPENDS_ON_ATTRIBUTE)) { + String dependsOn = ele.getAttribute(DEPENDS_ON_ATTRIBUTE); + bd.setDependsOn(StringUtils.tokenizeToStringArray(dependsOn, BEAN_NAME_DELIMITERS)); + } + + String autowireCandidate = ele.getAttribute(AUTOWIRE_CANDIDATE_ATTRIBUTE); + if ("".equals(autowireCandidate) || DEFAULT_VALUE.equals(autowireCandidate)) { + String candidatePattern = this.defaults.getAutowireCandidates(); + if (candidatePattern != null) { + String[] patterns = StringUtils.commaDelimitedListToStringArray(candidatePattern); + bd.setAutowireCandidate(PatternMatchUtils.simpleMatch(patterns, beanName)); + } + } + else { + bd.setAutowireCandidate(TRUE_VALUE.equals(autowireCandidate)); + } + + if (ele.hasAttribute(PRIMARY_ATTRIBUTE)) { + bd.setPrimary(TRUE_VALUE.equals(ele.getAttribute(PRIMARY_ATTRIBUTE))); + } + + if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) { + String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE); + if (!"".equals(initMethodName)) { + bd.setInitMethodName(initMethodName); + } + } + else { + if (this.defaults.getInitMethod() != null) { + bd.setInitMethodName(this.defaults.getInitMethod()); + bd.setEnforceInitMethod(false); + } + } + + if (ele.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) { + String destroyMethodName = ele.getAttribute(DESTROY_METHOD_ATTRIBUTE); + if (!"".equals(destroyMethodName)) { + bd.setDestroyMethodName(destroyMethodName); + } + } + else { + if (this.defaults.getDestroyMethod() != null) { + bd.setDestroyMethodName(this.defaults.getDestroyMethod()); + bd.setEnforceDestroyMethod(false); + } + } + + if (ele.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) { + bd.setFactoryMethodName(ele.getAttribute(FACTORY_METHOD_ATTRIBUTE)); + } + if (ele.hasAttribute(FACTORY_BEAN_ATTRIBUTE)) { + bd.setFactoryBeanName(ele.getAttribute(FACTORY_BEAN_ATTRIBUTE)); + } + + return bd; + } + + /** * Create a bean definition for the given class name and parent name. + * * @param className the name of the bean class * @param parentName the name of the bean's parent bean * @return the newly created bean definition ! * @throws ClassNotFoundException if bean class resolution was attempted but ! * failed */ protected AbstractBeanDefinition createBeanDefinition(String className, String parentName) throws ClassNotFoundException { ! return BeanDefinitionReaderUtils.createBeanDefinition(parentName, className, ! this.readerContext.getBeanClassLoader()); } *************** *** 751,755 **** this.parseState.push(new ConstructorArgumentEntry(index)); Object value = parsePropertyValue(ele, bd, null); ! ConstructorArgumentValues.ValueHolder valueHolder = new ConstructorArgumentValues.ValueHolder(value); if (StringUtils.hasLength(typeAttr)) { valueHolder.setType(typeAttr); --- 773,778 ---- this.parseState.push(new ConstructorArgumentEntry(index)); Object value = parsePropertyValue(ele, bd, null); ! ConstructorArgumentValues.ValueHolder valueHolder = new ConstructorArgumentValues.ValueHolder( ! value); if (StringUtils.hasLength(typeAttr)) { valueHolder.setType(typeAttr); *************** *** 853,863 **** /** ! * Get the value of a property element. May be a list etc. ! * Also used for constructor arguments, "propertyName" being null in this case. */ public Object parsePropertyValue(Element ele, BeanDefinition bd, String propertyName) { ! String elementName = (propertyName != null) ? ! "<property> element for property '" + propertyName + "'" : ! "<constructor-arg> element"; // Should only have one child element: ref, value, list, etc. --- 876,885 ---- /** ! * Get the value of a property element. May be a list etc. Also used for ! * constructor arguments, "propertyName" being null in this case. */ public Object parsePropertyValue(Element ele, BeanDefinition bd, String propertyName) { ! String elementName = (propertyName != null) ? "<property> element for property '" + propertyName + "'" ! : "<constructor-arg> element"; // Should only have one child element: ref, value, list, etc. *************** *** 866,871 **** for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); ! if (node instanceof Element && !DomUtils.nodeNameEquals(node, DESCRIPTION_ELEMENT) && ! !DomUtils.nodeNameEquals(node, META_ELEMENT)) { // Child element is what we're looking for. if (subElement != null) { --- 888,893 ---- for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); ! if (node instanceof Element && !DomUtils.nodeNameEquals(node, DESCRIPTION_ELEMENT) ! && !DomUtils.nodeNameEquals(node, META_ELEMENT)) { // Child element is what we're looking for. if (subElement != null) { *************** *** 880,887 **** boolean hasRefAttribute = ele.hasAttribute(REF_ATTRIBUTE); boolean hasValueAttribute = ele.hasAttribute(VALUE_ATTRIBUTE); ! if ((hasRefAttribute && hasValueAttribute) || ! ((hasRefAttribute || hasValueAttribute) && subElement != null)) { ! error(elementName + ! " is only allowed to contain either 'ref' attribute OR 'value' attribute OR sub-element", ele); } --- 902,908 ---- boolean hasRefAttribute = ele.hasAttribute(REF_ATTRIBUTE); boolean hasValueAttribute = ele.hasAttribute(VALUE_ATTRIBUTE); ! if ((hasRefAttribute && hasValueAttribute) || ((hasRefAttribute || hasValueAttribute) && subElement != null)) { ! error(elementName ! + " is only allowed to contain either 'ref' attribute OR 'value' attribute OR sub-element", ele); } *************** *** 917,920 **** --- 938,942 ---- * Parse a value, ref or collection sub-element of a property or * constructor-arg element. + * * @param ele subelement of property element; we don't know which yet * @param defaultTypeClassName the default type (class name) for any *************** *** 958,993 **** } else if (DomUtils.nodeNameEquals(ele, IDREF_ELEMENT)) { ! // A generic reference to any name of any bean. ! String refName = ele.getAttribute(BEAN_REF_ATTRIBUTE); ! if (!StringUtils.hasLength(refName)) { ! // A reference to the id of another bean in the same XML file. ! refName = ele.getAttribute(LOCAL_REF_ATTRIBUTE); ! if (!StringUtils.hasLength(refName)) { ! error("Either 'bean' or 'local' is required for <idref> element", ele); ! return null; ! } ! } ! if (!StringUtils.hasText(refName)) { ! error("<idref> element contains empty target attribute", ele); ! return null; ! } ! RuntimeBeanNameReference ref = new RuntimeBeanNameReference(refName); ! ref.setSource(extractSource(ele)); ! return ref; } else if (DomUtils.nodeNameEquals(ele, VALUE_ELEMENT)) { ! // It's a literal value. ! String value = DomUtils.getTextValue(ele); ! String typeClassName = ele.getAttribute(TYPE_ATTRIBUTE); ! if (!StringUtils.hasText(typeClassName)) { ! typeClassName = defaultTypeClassName; ! } ! try { ! return buildTypedStringValue(value, typeClassName, ele); ! } ! catch (ClassNotFoundException ex) { ! error("Type class [" + typeClassName + "] not found for <value> element", ele, ex); ! return value; ! } } else if (DomUtils.nodeNameEquals(ele, NULL_ELEMENT)) { --- 980,987 ---- } else if (DomUtils.nodeNameEquals(ele, IDREF_ELEMENT)) { ! return parseIdRefElement(ele); } else if (DomUtils.nodeNameEquals(ele, VALUE_ELEMENT)) { ! return parseValueElement(ele, defaultTypeClassName); } else if (DomUtils.nodeNameEquals(ele, NULL_ELEMENT)) { *************** *** 1017,1021 **** --- 1011,1066 ---- /** + * Return a typed String value Object for the given 'idref' element. + * + * @param ele + * @param bd + * @return + */ + public Object parseIdRefElement(Element ele) { + // A generic reference to any name of any bean. + String refName = ele.getAttribute(BEAN_REF_ATTRIBUTE); + if (!StringUtils.hasLength(refName)) { + // A reference to the id of another bean in the same XML file. + refName = ele.getAttribute(LOCAL_REF_ATTRIBUTE); + if (!StringUtils.hasLength(refName)) { + error("Either 'bean' or 'local' is required for <idref> element", ele); + return null; + } + } + if (!StringUtils.hasText(refName)) { + error("<idref> element contains empty target attribute", ele); + return null; + } + RuntimeBeanNameReference ref = new RuntimeBeanNameReference(refName); + ref.setSource(extractSource(ele)); + return ref; + } + + /** + * Return a typed String value Object for the given value element. + * + * @param ele element + * @param defaultTypeClassName type class name + * @return typed String value Object + */ + public Object parseValueElement(Element ele, String defaultTypeClassName) { + // It's a literal value. + String value = DomUtils.getTextValue(ele); + String typeClassName = ele.getAttribute(TYPE_ATTRIBUTE); + if (!StringUtils.hasText(typeClassName)) { + typeClassName = defaultTypeClassName; + } + try { + return buildTypedStringValue(value, typeClassName, ele); + } + catch (ClassNotFoundException ex) { + error("Type class [" + typeClassName + "] not found for <value> element", ele, ex); + return value; + } + } + + /** * Build a typed String value Object for the given raw value. + * * @see org.springframework.beans.factory.config.TypedStringValue */ *************** *** 1123,1134 **** boolean hasKeyAttribute = entryEle.hasAttribute(KEY_ATTRIBUTE); boolean hasKeyRefAttribute = entryEle.hasAttribute(KEY_REF_ATTRIBUTE); ! if ((hasKeyAttribute && hasKeyRefAttribute) || ! ((hasKeyAttribute || hasKeyRefAttribute)) && keyEle != null) { ! error("<entry> element is only allowed to contain either " + ! "a 'key' attribute OR a 'key-ref' attribute OR a <key> sub-element", entryEle); } if (hasKeyAttribute) { ! key = buildTypedStringValueForMap( ! entryEle.getAttribute(KEY_ATTRIBUTE), defaultKeyTypeClassName, entryEle); } else if (hasKeyRefAttribute) { --- 1168,1178 ---- boolean hasKeyAttribute = entryEle.hasAttribute(KEY_ATTRIBUTE); boolean hasKeyRefAttribute = entryEle.hasAttribute(KEY_REF_ATTRIBUTE); ! if ((hasKeyAttribute && hasKeyRefAttribute) || ((hasKeyAttribute || hasKeyRefAttribute)) && keyEle != null) { ! error("<entry> element is only allowed to contain either " ! + "a 'key' attribute OR a 'key-ref' attribute OR a <key> sub-element", entryEle); } if (hasKeyAttribute) { ! key = buildTypedStringValueForMap(entryEle.getAttribute(KEY_ATTRIBUTE), defaultKeyTypeClassName, ! entryEle); } else if (hasKeyRefAttribute) { *************** *** 1152,1163 **** boolean hasValueAttribute = entryEle.hasAttribute(VALUE_ATTRIBUTE); boolean hasValueRefAttribute = entryEle.hasAttribute(VALUE_REF_ATTRIBUTE); ! if ((hasValueAttribute && hasValueRefAttribute) || ! ((hasValueAttribute || hasValueRefAttribute)) && valueEle != null) { ! error("<entry> element is only allowed to contain either " + ! "'value' attribute OR 'value-ref' attribute OR <value> sub-element", entryEle); } if (hasValueAttribute) { ! value = buildTypedStringValueForMap( ! entryEle.getAttribute(VALUE_ATTRIBUTE), defaultValueTypeClassName, entryEle); } else if (hasValueRefAttribute) { --- 1196,1207 ---- boolean hasValueAttribute = entryEle.hasAttribute(VALUE_ATTRIBUTE); boolean hasValueRefAttribute = entryEle.hasAttribute(VALUE_REF_ATTRIBUTE); ! if ((hasValueAttribute && hasValueRefAttribute) || ((hasValueAttribute || hasValueRefAttribute)) ! && valueEle != null) { ! error("<entry> element is only allowed to contain either " ! + "'value' attribute OR 'value-ref' attribute OR <value> sub-element", entryEle); } if (hasValueAttribute) { ! value = buildTypedStringValueForMap(entryEle.getAttribute(VALUE_ATTRIBUTE), defaultValueTypeClassName, ! entryEle); } else if (hasValueRefAttribute) { *************** *** 1186,1189 **** --- 1230,1234 ---- /** * Build a typed String value Object for the given raw value. + * * @see org.springframework.beans.factory.config.TypedStringValue */ *************** *** 1274,1279 **** } ! public BeanDefinitionHolder decorateBeanDefinitionIfRequired( ! Element ele, BeanDefinitionHolder definitionHolder, BeanDefinition containingBd) { BeanDefinitionHolder finalDefinition = definitionHolder; --- 1319,1324 ---- } ! public BeanDefinitionHolder decorateBeanDefinitionIfRequired(Element ele, BeanDefinitionHolder definitionHolder, ! BeanDefinition containingBd) { BeanDefinitionHolder finalDefinition = definitionHolder; *************** *** 1297,1302 **** } ! private BeanDefinitionHolder decorateIfRequired( ! Node node, BeanDefinitionHolder originalDef, BeanDefinition containingBd) { String namespaceUri = node.getNamespaceURI(); --- 1342,1347 ---- } ! private BeanDefinitionHolder decorateIfRequired(Node node, BeanDefinitionHolder originalDef, ! BeanDefinition containingBd) { String namespaceUri = node.getNamespaceURI(); *************** *** 1326,1341 **** BeanDefinition innerDefinition = parseCustomElement(ele, containingBd); if (innerDefinition == null) { ! error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " + ! "This tag cannot be used nested inside <property>.", ele); return null; } ! String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + ! ObjectUtils.getIdentityHexString(innerDefinition); if (logger.isDebugEnabled()) { ! logger.debug("Using generated bean name [" + id + ! "] for nested custom element '" + ele.getNodeName() + "'"); } return new BeanDefinitionHolder(innerDefinition, id); } - } --- 1371,1384 ---- BeanDefinition innerDefinition = parseCustomElement(ele, containingBd); if (innerDefinition == null) { ! error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " ! + "This tag cannot be used nested inside <property>.", ele); return null; } ! String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR ! + ObjectUtils.getIdentityHexString(innerDefinition); if (logger.isDebugEnabled()) { ! logger.debug("Using generated bean name [" + id + "] for nested custom element '" + ele.getNodeName() + "'"); } return new BeanDefinitionHolder(innerDefinition, id); } } |