Class BeanParserUtils


  • public final class BeanParserUtils
    extends java.lang.Object
    Utilities class that contains methods useful for spring namespace BeanDefinitionParser.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Optional<java.lang.String> getAttributeValue​(org.w3c.dom.Node node, java.lang.String attributeName)
      Gets an attribute's value if it exists.
      static java.util.Optional<org.w3c.dom.Element> getChild​(org.w3c.dom.Element parent, java.lang.String nodeName, int index)
      Gets a child element of specified name if it exists.
      static java.lang.Iterable<org.w3c.dom.Element> getChildren​(org.w3c.dom.Element parent)
      Gets all children of type Element from specified parent element.
      static java.util.List<org.w3c.dom.Element> getChildren​(org.w3c.dom.Element parent, java.lang.String nodeName)
      Gets all children from specified element of provided name.
      static java.lang.Iterable<org.w3c.dom.Node> getChildren​(org.w3c.dom.Element parent, java.util.function.Predicate<org.w3c.dom.Node> filter)
      Gets all children from specified parent element that satisfies provided condition.
      static java.util.List<org.w3c.dom.Node> getChildrenNodes​(org.w3c.dom.Element parent)
      Gets all children from specified parent element.
      static <V,​M>
      java.util.function.Consumer<V>
      getConsumer​(java.util.function.Function<V,​M> mapper, java.util.function.Consumer<M> consumer)
      Creates a consumer that processes provided value and passes its result to provided consumer.
      static <V,​M>
      java.util.function.Consumer<V>
      getConsumer​(java.util.function.Function<V,​M> mapper, java.util.function.Consumer<M> consumer, java.util.function.Predicate<M> filter)
      Creates a consumer that processes provided value and passes its result to provided consumer if it matches provided restrictions.
      static java.util.Optional<org.w3c.dom.Element> getFirstChild​(org.w3c.dom.Element parent, java.lang.String nodeName)
      Gets first child element of specified name if it exists.
      static <V,​M>
      void
      mapAndConsume​(java.util.Optional<V> value, java.util.function.Function<V,​M> mapper, java.util.function.Consumer<M> consumer)
      Method for all situations matching the following flow: check if value is present in Optional object if value is present, then process it somehow pass processed value to final consumer
      static <V,​M>
      void
      mapAndConsume​(java.util.Optional<V> value, java.util.function.Function<V,​M> mapper, java.util.function.Consumer<M> consumer, java.util.function.Predicate<M> filter)
      Method for all situations matching the following flow: check if value is present in Optional object if value is present, then process it somehow check if process result meets some restrictions pass processed value to final consumer
      • Methods inherited from class java.lang.Object

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

      • mapAndConsume

        public static <V,​M> void mapAndConsume​(java.util.Optional<V> value,
                                                     java.util.function.Function<V,​M> mapper,
                                                     java.util.function.Consumer<M> consumer)
        Method for all situations matching the following flow:
        • check if value is present in Optional object
        • if value is present, then process it somehow
        • pass processed value to final consumer

        Most common use case is - acquire a Node, get it's value if exists, parse it, change bean definition with parse result.

        Type Parameters:
        V - type of original value
        M - type of processed value
        Parameters:
        value - value to be processed and consumed
        mapper - processing function
        consumer - final value consumer
      • mapAndConsume

        public static <V,​M> void mapAndConsume​(java.util.Optional<V> value,
                                                     java.util.function.Function<V,​M> mapper,
                                                     java.util.function.Consumer<M> consumer,
                                                     java.util.function.Predicate<M> filter)
        Method for all situations matching the following flow:
        • check if value is present in Optional object
        • if value is present, then process it somehow
        • check if process result meets some restrictions
        • pass processed value to final consumer

        Most common use case is - acquire a Node, get it's value if exists, parse it, check some condition, change bean definition with parse result if condition is satisfied.

        Type Parameters:
        V - type of original value
        M - type of processed value
        Parameters:
        value - value to be processed and consumed
        mapper - processing function
        filter - condition that needs to be satisfied by processed value for it to be consumed
        consumer - final value consumer
      • getConsumer

        public static <V,​M> java.util.function.Consumer<V> getConsumer​(java.util.function.Function<V,​M> mapper,
                                                                             java.util.function.Consumer<M> consumer)
        Creates a consumer that processes provided value and passes its result to provided consumer.
        Type Parameters:
        V - type of original value
        M - type of processed value
        Parameters:
        mapper - processing method
        consumer - final value consumer
        Returns:
        consumer
      • getConsumer

        public static <V,​M> java.util.function.Consumer<V> getConsumer​(java.util.function.Function<V,​M> mapper,
                                                                             java.util.function.Consumer<M> consumer,
                                                                             java.util.function.Predicate<M> filter)
        Creates a consumer that processes provided value and passes its result to provided consumer if it matches provided restrictions.
        Type Parameters:
        V - type of original value
        M - type of processed value
        Parameters:
        mapper - processing method
        consumer - final value consumer
        filter - condition that needs to be satisfied by processed value for it to be consumed
        Returns:
        consumer
      • getAttributeValue

        public static java.util.Optional<java.lang.String> getAttributeValue​(org.w3c.dom.Node node,
                                                                             java.lang.String attributeName)
        Gets an attribute's value if it exists.
        Parameters:
        node - element which attribute is to be read
        attributeName - name of attribute to read
        Returns:
        a value of attribute or empty if not available
      • getFirstChild

        public static java.util.Optional<org.w3c.dom.Element> getFirstChild​(org.w3c.dom.Element parent,
                                                                            java.lang.String nodeName)
        Gets first child element of specified name if it exists.
        Parameters:
        parent - parent element
        nodeName - name of child
        Returns:
        a child element or empty if not available
      • getChild

        public static java.util.Optional<org.w3c.dom.Element> getChild​(org.w3c.dom.Element parent,
                                                                       java.lang.String nodeName,
                                                                       int index)
        Gets a child element of specified name if it exists.
        Parameters:
        parent - parent element
        nodeName - name of child
        index - index of a child among all children of this name
        Returns:
        a child element or empty if not available
      • getChildrenNodes

        public static java.util.List<org.w3c.dom.Node> getChildrenNodes​(org.w3c.dom.Element parent)
        Gets all children from specified parent element.
        Parameters:
        parent - parent element
        Returns:
        list of children
      • getChildren

        public static java.util.List<org.w3c.dom.Element> getChildren​(org.w3c.dom.Element parent,
                                                                      java.lang.String nodeName)
        Gets all children from specified element of provided name.
        Parameters:
        parent - parent element
        nodeName - name of children to be found
        Returns:
        list of children
      • getChildren

        public static java.lang.Iterable<org.w3c.dom.Element> getChildren​(org.w3c.dom.Element parent)
        Gets all children of type Element from specified parent element.
        Parameters:
        parent - parent element
        Returns:
        list of children
      • getChildren

        public static java.lang.Iterable<org.w3c.dom.Node> getChildren​(org.w3c.dom.Element parent,
                                                                       java.util.function.Predicate<org.w3c.dom.Node> filter)
        Gets all children from specified parent element that satisfies provided condition.
        Parameters:
        parent - parent element
        filter - condition that must be satisfied by child node
        Returns:
        list of children