Class BeanPropertySetterRule


  • public class BeanPropertySetterRule
    extends Rule

    Rule implements sets a bean property on the top object to the body text.

    The property set:

    • can be specified when the rule is created
    • or can match the current element when the rule is called.

    Using the second method and the ExtendedBaseRules child match pattern, all the child elements can be automatically mapped to properties on the parent object.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String bodyText
      The body text used to set the property.
      private java.lang.String propertyName
      Set this property on the top object.
      private java.lang.String propertyNameFromAttribute
      Extract the property name from attribute
    • Constructor Summary

      Constructors 
      Constructor Description
      BeanPropertySetterRule()
      Construct rule that automatically sets a property from the body text.
      BeanPropertySetterRule​(java.lang.String propertyName)
      Construct rule that sets the given property from the body text.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void begin​(java.lang.String namespace, java.lang.String name, org.xml.sax.Attributes attributes)
      This method is called when the beginning of a matching XML element is encountered.
      void body​(java.lang.String namespace, java.lang.String name, java.lang.String text)
      This method is called when the body of a matching XML element is encountered.
      void end​(java.lang.String namespace, java.lang.String name)
      This method is called when the end of a matching XML element is encountered.
      void finish()
      This method is called after all parsing methods have been called, to allow Rules to remove temporary data.
      protected java.lang.String getBodyText()
      Returns the body text used to set the property.
      java.lang.String getPropertyName()
      Returns the property name associated to this setter rule.
      void setPropertyNameFromAttribute​(java.lang.String propertyNameFromAttribute)
      Sets the attribute name from which the property name has to be extracted.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • propertyName

        private java.lang.String propertyName
        Set this property on the top object.
      • propertyNameFromAttribute

        private java.lang.String propertyNameFromAttribute
        Extract the property name from attribute
      • bodyText

        private java.lang.String bodyText
        The body text used to set the property.
    • Constructor Detail

      • BeanPropertySetterRule

        public BeanPropertySetterRule​(java.lang.String propertyName)

        Construct rule that sets the given property from the body text.

        Parameters:
        propertyName - name of property to set
      • BeanPropertySetterRule

        public BeanPropertySetterRule()

        Construct rule that automatically sets a property from the body text.

        This construct creates a rule that sets the property on the top object named the same as the current element.

    • Method Detail

      • getPropertyName

        public java.lang.String getPropertyName()
        Returns the property name associated to this setter rule.
        Returns:
        The property name associated to this setter rule
      • setPropertyNameFromAttribute

        public void setPropertyNameFromAttribute​(java.lang.String propertyNameFromAttribute)
        Sets the attribute name from which the property name has to be extracted.
        Parameters:
        propertyNameFromAttribute - the attribute name from which the property name has to be extracted.
        Since:
        3.0
      • getBodyText

        protected java.lang.String getBodyText()
        Returns the body text used to set the property.
        Returns:
        The body text used to set the property
      • begin

        public void begin​(java.lang.String namespace,
                          java.lang.String name,
                          org.xml.sax.Attributes attributes)
                   throws java.lang.Exception
        This method is called when the beginning of a matching XML element is encountered.
        Overrides:
        begin in class Rule
        Parameters:
        namespace - the namespace URI of the matching element, or an empty string if the parser is not namespace aware or the element has no namespace
        name - the local name if the parser is namespace aware, or just the element name otherwise
        attributes - The attribute list of this element
        Throws:
        java.lang.Exception - if any error occurs
      • body

        public void body​(java.lang.String namespace,
                         java.lang.String name,
                         java.lang.String text)
                  throws java.lang.Exception
        This method is called when the body of a matching XML element is encountered. If the element has no body, this method is called with an empty string as the body text.
        Overrides:
        body in class Rule
        Parameters:
        namespace - the namespace URI of the matching element, or an empty string if the parser is not namespace aware or the element has no namespace
        name - the local name if the parser is namespace aware, or just the element name otherwise
        text - The text of the body of this element
        Throws:
        java.lang.Exception - if any error occurs
      • end

        public void end​(java.lang.String namespace,
                        java.lang.String name)
                 throws java.lang.Exception
        This method is called when the end of a matching XML element is encountered.
        Overrides:
        end in class Rule
        Parameters:
        namespace - the namespace URI of the matching element, or an empty string if the parser is not namespace aware or the element has no namespace
        name - the local name if the parser is namespace aware, or just the element name otherwise
        Throws:
        java.lang.Exception - if any error occurs
      • finish

        public void finish()
                    throws java.lang.Exception
        This method is called after all parsing methods have been called, to allow Rules to remove temporary data.
        Overrides:
        finish in class Rule
        Throws:
        java.lang.Exception - if any error occurs
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object