From: Juergen H. <jho...@us...> - 2008-10-27 21:06:56
|
Update of /cvsroot/springframework/spring/src/org/springframework/beans/factory/xml In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14943/src/org/springframework/beans/factory/xml Modified Files: BeanDefinitionParserDelegate.java Log Message: polishing Index: BeanDefinitionParserDelegate.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** BeanDefinitionParserDelegate.java 21 Oct 2008 10:35:49 -0000 1.59 --- BeanDefinitionParserDelegate.java 27 Oct 2008 21:06:44 -0000 1.60 *************** *** 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,231 **** --- 228,232 ---- public static final String DEFAULT_DESTROY_METHOD_ATTRIBUTE = "default-destroy-method"; + protected final Log logger = LogFactory.getLog(getClass()); *************** *** 237,242 **** /** ! * Stores all used bean names so we can enforce uniqueness on a per file ! * basis. */ private final Set usedNames = new HashSet(); --- 238,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,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}. */ --- 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}. */ *************** *** 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"); } } --- 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"); } } *************** *** 393,398 **** try { if (containingBean != null) { ! beanName = BeanDefinitionReaderUtils.generateBeanName(beanDefinition, ! this.readerContext.getRegistry(), true); } else { --- 392,397 ---- try { if (containingBean != null) { ! beanName = BeanDefinitionReaderUtils.generateBeanName( ! beanDefinition, this.readerContext.getRegistry(), true); } else { *************** *** 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 + "]"); } } --- 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 + "]"); } } *************** *** 426,431 **** /** ! * Validate that the specified bean name and aliases have not been used ! * already. */ protected void checkNameUniqueness(String beanName, List aliases, Element beanElement) { --- 425,429 ---- /** ! * Validate that the specified bean name and aliases have not been used already. */ protected void checkNameUniqueness(String beanName, List aliases, Element beanElement) { *************** *** 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)); --- 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)); *************** *** 468,472 **** parseBeanDefinitionAttributes(ele, beanName, containingBean, bd); - bd.setDescription(DomUtils.getChildElementValueByTagName(ele, DESCRIPTION_ELEMENT)); --- 466,469 ---- *************** *** 501,512 **** /** ! * 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, --- 498,506 ---- /** ! * 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, *************** *** 606,621 **** /** * 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()); } --- 600,613 ---- /** * 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()); } *************** *** 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); --- 765,769 ---- 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); *************** *** 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. --- 867,877 ---- /** ! * 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. *************** *** 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,885 ---- 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) { *************** *** 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); } --- 894,901 ---- 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); } *************** *** 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 --- 931,934 ---- *************** *** 1012,1019 **** /** * Return a typed String value Object for the given 'idref' element. - * - * @param ele - * @param bd - * @return */ public Object parseIdRefElement(Element ele) { --- 1004,1007 ---- *************** *** 1039,1046 **** /** * 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) { --- 1027,1030 ---- *************** *** 1062,1066 **** /** * Build a typed String value Object for the given raw value. - * * @see org.springframework.beans.factory.config.TypedStringValue */ --- 1046,1049 ---- *************** *** 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) { --- 1151,1162 ---- 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) { *************** *** 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) { --- 1180,1191 ---- 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) { *************** *** 1230,1234 **** /** * Build a typed String value Object for the given raw value. - * * @see org.springframework.beans.factory.config.TypedStringValue */ --- 1214,1217 ---- *************** *** 1319,1324 **** } ! public BeanDefinitionHolder decorateBeanDefinitionIfRequired(Element ele, BeanDefinitionHolder definitionHolder, ! BeanDefinition containingBd) { BeanDefinitionHolder finalDefinition = definitionHolder; --- 1302,1307 ---- } ! public BeanDefinitionHolder decorateBeanDefinitionIfRequired( ! Element ele, BeanDefinitionHolder definitionHolder, BeanDefinition containingBd) { BeanDefinitionHolder finalDefinition = definitionHolder; *************** *** 1342,1347 **** } ! private BeanDefinitionHolder decorateIfRequired(Node node, BeanDefinitionHolder originalDef, ! BeanDefinition containingBd) { String namespaceUri = node.getNamespaceURI(); --- 1325,1330 ---- } ! private BeanDefinitionHolder decorateIfRequired( ! Node node, BeanDefinitionHolder originalDef, BeanDefinition containingBd) { String namespaceUri = node.getNamespaceURI(); *************** *** 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); } } --- 1354,1369 ---- 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); } + } |