BeanLDOM

BeanLDOM is a small Java package allowing a tree of Java Beans to be accessed via a DOM tree.

Aims and Assumptions

Mapping

The following example shows all the mapping rules. This article helped me feel better about the mapping I had already decided upon.

Constructing a tree of NameBean objects:

NameBean jane = new NameBean("Jane", "Smith");
NameBean john = new NameBean("John", "Smith");
NameBean daisy = new NameBean("Daisy", "Smith");
NameBean prince = new NameBean(null, "Prince");
NameBean[] children = {daisy, prince, null};
String[] aka = {"Janey", "", null};
jane.setChildren(children);
jane.setPartner(john);
jane.setAka(aka);
john.setChildren(new NameBean[] {});

Creating a BeanLDOM document to translate the root bean jane:

// create a new document with root element named "root"
DocumentImpl doc = new DocumentImpl("root");

// append a child element ("person") to the root element
doc.appendObject("person", jane);

This all gives:

<root>
    <person firstName="Jane" lastName="Smith">
        <aka>
            <entry>Janey</entry>
            <entry></entry>
            <null/>
        </aka>
        <partner firstName="John" lastName="Smith">
            <children/>
        </partner>
        <children>
            <entry firstName="Daisy" lastName="Smith"/>
            <entry firstName="" lastName="Prince"/>
            <null/>
        </children>
    </person>
</root>

Notes on mapping

Requirements

Known Problems and Limitations

Im sure there are lots more but I cant think of them just now.

Related software

Some good software that does similar things (sorry if/when this gets out of date):