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 Detail

      • propertyName

        protected java.lang.String propertyName
        Set this property on the top object.
      • bodyText

        protected 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

      • body

        public void body​(java.lang.String namespace,
                         java.lang.String name,
                         java.lang.String text)
                  throws java.lang.Exception
        Process the body text of this element.
        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
      • end

        public void end​(java.lang.String namespace,
                        java.lang.String name)
                 throws java.lang.Exception
        Process the end of this element.
        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.NoSuchMethodException - if the bean does not have a writeable property of the specified name
        java.lang.Exception
      • finish

        public void finish()
                    throws java.lang.Exception
        Clean up after parsing is complete.
        Overrides:
        finish in class Rule
        Throws:
        java.lang.Exception
      • toString

        public java.lang.String toString()
        Render a printable version of this Rule.
        Overrides:
        toString in class java.lang.Object