Commons Betwixt
  1. Commons Betwixt
  2. BETWIXT-42

Enhancement on the documentation for non-public classes and inner classes

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0 Alpha
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      Hi All,

      This is the doc I wrote about using inner classes / non-public classes. The
      inners classes approach is not so important but the other one I believe is of a
      great value because the Betwixt engine quietly ignores the attributes as it
      falls in the IllegalAccessException and I believe it will help a lot if it's
      well documented.

      If some native english speaker could review I'd thank very much as I'm from
      Brazil and my english is far from perfect.

      --------------------------------------------------------------------------------
      WORKING WITH INNER CLASSES:

      When using a public inner class, static or not, the name of the element obey
      the Inner Classes naming semantics (using $).

      The example bellow show this behaviour:

      public class BetWixtWriter {

      public class TallTreeBean {

      private float heightOfTree;

      public TallTreeBean(float height)

      { setHeightOfTree(height); }

      public float getHeightOfTree()

      { return heightOfTree; }

      public void setHeightOfTree(float heightOfTree)

      { this.heightOfTree = heightOfTree; }

      }

      public static final void main(String args[]) throws Exception

      { // create write and set basic properties BeanWriter writer = new BeanWriter(); writer.getXMLIntrospector().setAttributesForPrimitives (true); writer.enablePrettyPrint(); writer.setWriteIDs(false); // set a custom name mapper for attributes writer.getXMLIntrospector().setAttributeNameMapper(new HyphenatedNameMapper()); // set a custom name mapper for elements writer.getXMLIntrospector().setElementNameMapper(new DecapitalizeNameMapper()); // write out the bean writer.write(new BetWixtWriter().new TallTreeBean (15.1f)); System.out.println(""); }

      }

      Now, the application should print out an xml fragment which looks like:

      <betWixtWriter$TallTreeBean height-of-tree="15.1"/>

      --------------------------------------------------------------------------------
      WORKING WITH NON-PUBLIC CLASSES:

      When working with a non-public inner/normal class, it's attributes are not
      acessible even if the methods are public:

      public class BetWixtWriter {

      public static final void main(String args[]) throws Exception

      { // create write and set basic properties BeanWriter writer = new BeanWriter(); writer.getXMLIntrospector().setAttributesForPrimitives(true); writer.enablePrettyPrint(); writer.setWriteIDs(false); // set a custom name mapper for attributes writer.getXMLIntrospector().setAttributeNameMapper(new HyphenatedNameMapper()); // set a custom name mapper for elements writer.getXMLIntrospector().setElementNameMapper(new DecapitalizeNameMapper()); // write out the bean TallTreeBean ttb = new TallTreeBean(15.1f); writer.write(ttb); System.out.println(""); }

      }

      class TallTreeBean {

      private float heightOfTree;

      public TallTreeBean(float height)

      { setHeightOfTree(height); }

      public float getHeightOfTree()

      { return heightOfTree; }

      public void setHeightOfTree(float heightOfTree)

      { this.heightOfTree = heightOfTree; }

      }

      Now, the application should print out an xml fragment which looks like the
      following, so only the name of the class is present, without the attribute:

      <tallTreeBean/>

      So, be aware when using non-public JavaBeans classes.

        Activity

        Hide
        rdonkin@apache.org added a comment -

        I've committed additions to the user guide along the lines you proposed.

        Many thanks especially since documentation patches are so valuable.

        Robert

        Show
        rdonkin@apache.org added a comment - I've committed additions to the user guide along the lines you proposed. Many thanks especially since documentation patches are so valuable. Robert

          People

          • Assignee:
            Unassigned
            Reporter:
            Daniel C. Amadei
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development