Class NamespaceUtils


  • public abstract class NamespaceUtils
    extends java.lang.Object
    Shared utility methods for namespace parsers.
    Author:
    Mark Pollack, Dave Syer, Gary Russell
    • Constructor Summary

      Constructors 
      Constructor Description
      NamespaceUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addConstructorArgBooleanValueIfAttributeDefined​(BeanDefinitionBuilder builder, org.w3c.dom.Element element, java.lang.String attributeName, boolean defaultValue)
      Populates the bean definition constructor argument with the boolean value of that attribute if it is defined in the given element or else uses the default provided.
      static boolean addConstructorArgParentRefIfAttributeDefined​(BeanDefinitionBuilder builder, org.w3c.dom.Element element, java.lang.String attributeName)
      Populates the bean definition constructor argument with a reference to a bean with parent id equal to the attribute if it is defined in the given element.
      static boolean addConstructorArgRefIfAttributeDefined​(BeanDefinitionBuilder builder, org.w3c.dom.Element element, java.lang.String attributeName)
      Populates the bean definition constructor argument with a reference to a bean with id equal to the attribute if it is defined in the given element.
      static boolean addConstructorArgValueIfAttributeDefined​(BeanDefinitionBuilder builder, org.w3c.dom.Element element, java.lang.String attributeName)
      Populates the bean definition constructor argument with the value of that attribute if it is defined in the given element.
      static java.lang.String createElementDescription​(org.w3c.dom.Element element)
      Provides a user friendly description of an element based on its node name and, if available, its "id" attribute value.
      static BeanDefinition createExpressionDefIfAttributeDefined​(java.lang.String expressionElementName, org.w3c.dom.Element element)  
      static BeanDefinition createExpressionDefinitionFromValueOrExpression​(java.lang.String valueElementName, java.lang.String expressionElementName, ParserContext parserContext, org.w3c.dom.Element element, boolean oneRequired)  
      static boolean isAttributeDefined​(org.w3c.dom.Element element, java.lang.String attributeName)
      Checks the attribute to see if it is defined in the given element.
      static void parseDeclarationControls​(org.w3c.dom.Element element, BeanDefinitionBuilder builder)
      Parses 'auto-declare' and 'declared-by' attributes.
      static boolean setReferenceIfAttributeDefined​(BeanDefinitionBuilder builder, org.w3c.dom.Element element, java.lang.String attributeName)
      Populates the bean definition property corresponding to the specified attributeName with the reference to a bean identified by the value of that attribute if the attribute is defined in the given element.
      static boolean setReferenceIfAttributeDefined​(BeanDefinitionBuilder builder, org.w3c.dom.Element element, java.lang.String attributeName, java.lang.String propertyName)
      Populates the specified bean definition property with the reference to a bean.
      static boolean setValueIfAttributeDefined​(BeanDefinitionBuilder builder, org.w3c.dom.Element element, java.lang.String attributeName)
      Populates the bean definition property corresponding to the specified attributeName with the value of that attribute if it is defined in the given element.
      static boolean setValueIfAttributeDefined​(BeanDefinitionBuilder builder, org.w3c.dom.Element element, java.lang.String attributeName, java.lang.String propertyName)
      Populates the specified bean definition property with the value of the attribute whose name is provided if that attribute is defined in the given element.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NamespaceUtils

        public NamespaceUtils()
    • Method Detail

      • setValueIfAttributeDefined

        public static boolean setValueIfAttributeDefined​(BeanDefinitionBuilder builder,
                                                         org.w3c.dom.Element element,
                                                         java.lang.String attributeName,
                                                         java.lang.String propertyName)
        Populates the specified bean definition property with the value of the attribute whose name is provided if that attribute is defined in the given element.
        Parameters:
        builder - the bean definition builder to be configured
        element - the XML element where the attribute should be defined
        attributeName - the name of the attribute whose value will be used to populate the property
        propertyName - the name of the property to be populated
        Returns:
        true if defined.
      • setValueIfAttributeDefined

        public static boolean setValueIfAttributeDefined​(BeanDefinitionBuilder builder,
                                                         org.w3c.dom.Element element,
                                                         java.lang.String attributeName)
        Populates the bean definition property corresponding to the specified attributeName with the value of that attribute if it is defined in the given element.

        The property name will be the camel-case equivalent of the lower case hyphen separated attribute (e.g. the "foo-bar" attribute would match the "fooBar" property).

        Parameters:
        builder - the bean definition builder to be configured
        element - the XML element where the attribute should be defined
        attributeName - the name of the attribute whose value will be set on the property
        Returns:
        true if defined.
        See Also:
        Conventions.attributeNameToPropertyName(String)
      • isAttributeDefined

        public static boolean isAttributeDefined​(org.w3c.dom.Element element,
                                                 java.lang.String attributeName)
        Checks the attribute to see if it is defined in the given element.
        Parameters:
        element - the XML element where the attribute should be defined
        attributeName - the name of the attribute whose value will be used as a constructor argument
        Returns:
        true if defined.
      • addConstructorArgValueIfAttributeDefined

        public static boolean addConstructorArgValueIfAttributeDefined​(BeanDefinitionBuilder builder,
                                                                       org.w3c.dom.Element element,
                                                                       java.lang.String attributeName)
        Populates the bean definition constructor argument with the value of that attribute if it is defined in the given element.
        Parameters:
        builder - the bean definition builder to be configured
        element - the XML element where the attribute should be defined
        attributeName - the name of the attribute whose value will be used as a constructor argument
        Returns:
        true if defined.
      • addConstructorArgBooleanValueIfAttributeDefined

        public static void addConstructorArgBooleanValueIfAttributeDefined​(BeanDefinitionBuilder builder,
                                                                           org.w3c.dom.Element element,
                                                                           java.lang.String attributeName,
                                                                           boolean defaultValue)
        Populates the bean definition constructor argument with the boolean value of that attribute if it is defined in the given element or else uses the default provided.
        Parameters:
        builder - the bean definition builder to be configured
        element - the XML element where the attribute should be defined
        attributeName - the name of the attribute whose value will be used as a constructor argument
        defaultValue - the default value to use if the attirbute is not set
      • addConstructorArgRefIfAttributeDefined

        public static boolean addConstructorArgRefIfAttributeDefined​(BeanDefinitionBuilder builder,
                                                                     org.w3c.dom.Element element,
                                                                     java.lang.String attributeName)
        Populates the bean definition constructor argument with a reference to a bean with id equal to the attribute if it is defined in the given element.
        Parameters:
        builder - the bean definition builder to be configured
        element - the XML element where the attribute should be defined
        attributeName - the name of the attribute whose value will be used to set the reference
        Returns:
        true if defined.
      • addConstructorArgParentRefIfAttributeDefined

        public static boolean addConstructorArgParentRefIfAttributeDefined​(BeanDefinitionBuilder builder,
                                                                           org.w3c.dom.Element element,
                                                                           java.lang.String attributeName)
        Populates the bean definition constructor argument with a reference to a bean with parent id equal to the attribute if it is defined in the given element.
        Parameters:
        builder - the bean definition builder to be configured
        element - the XML element where the attribute should be defined
        attributeName - the name of the attribute whose value will be used to set the reference
        Returns:
        true if defined.
      • setReferenceIfAttributeDefined

        public static boolean setReferenceIfAttributeDefined​(BeanDefinitionBuilder builder,
                                                             org.w3c.dom.Element element,
                                                             java.lang.String attributeName,
                                                             java.lang.String propertyName)
        Populates the specified bean definition property with the reference to a bean. The bean reference is identified by the value from the attribute whose name is provided if that attribute is defined in the given element.
        Parameters:
        builder - the bean definition builder to be configured
        element - the XML element where the attribute should be defined
        attributeName - the name of the attribute whose value will be used as a bean reference to populate the property
        propertyName - the name of the property to be populated
        Returns:
        true if the attribute is present and has text
      • setReferenceIfAttributeDefined

        public static boolean setReferenceIfAttributeDefined​(BeanDefinitionBuilder builder,
                                                             org.w3c.dom.Element element,
                                                             java.lang.String attributeName)
        Populates the bean definition property corresponding to the specified attributeName with the reference to a bean identified by the value of that attribute if the attribute is defined in the given element.

        The property name will be the camel-case equivalent of the lower case hyphen separated attribute (e.g. the "foo-bar" attribute would match the "fooBar" property).

        Parameters:
        builder - the bean definition builder to be configured
        element - the XML element where the attribute should be defined
        attributeName - the name of the attribute whose value will be used as a bean reference to populate the property
        Returns:
        true if defined.
        See Also:
        Conventions.attributeNameToPropertyName(String)
      • createElementDescription

        public static java.lang.String createElementDescription​(org.w3c.dom.Element element)
        Provides a user friendly description of an element based on its node name and, if available, its "id" attribute value. This is useful for creating error messages from within bean definition parsers.
        Parameters:
        element - The element.
        Returns:
        The description.
      • parseDeclarationControls

        public static void parseDeclarationControls​(org.w3c.dom.Element element,
                                                    BeanDefinitionBuilder builder)
        Parses 'auto-declare' and 'declared-by' attributes.
        Parameters:
        element - The element.
        builder - The builder.
      • createExpressionDefinitionFromValueOrExpression

        public static BeanDefinition createExpressionDefinitionFromValueOrExpression​(java.lang.String valueElementName,
                                                                                     java.lang.String expressionElementName,
                                                                                     ParserContext parserContext,
                                                                                     org.w3c.dom.Element element,
                                                                                     boolean oneRequired)
      • createExpressionDefIfAttributeDefined

        public static BeanDefinition createExpressionDefIfAttributeDefined​(java.lang.String expressionElementName,
                                                                           org.w3c.dom.Element element)