commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Sullivan <sulli...@web.de>
Subject betwixt: can it round-trip a tree structure?
Date Mon, 07 Nov 2005 15:30:37 GMT

Hi,

I am trying to model a budget as a tree structure.  

For example:

A1       [parent] Eligible costs
A1.1     [parent] Personnel
A1.2     [parent] Travel and accomodation
A1.2.1   [parent] Travel
A1.2.1.1 [Leaf]   Travel - London Brussels 19/11/2005   
A1.2.1.2 [Leaf]   Travel - Amsterdam Brussels 21/11/2005


Expense-categories are non-leaf items in the tree (modelled by the java class BudgetNonLeafItemImpl)
and individual expense items are leaves (BudgetLeafItemImpl ).


Both types of node have many fields and operations in common which they inherit from a common
base class (BaseBudgetItemImpl).

A simplified skeleton of the source code looks like the follows:

public  abstract class BaseBudgetItemImpl   {
    public abstract boolean isLeafItemType();
    //…
}

public class BudgetLeafItemImpl extends BaseBudgetItemImpl {
    /** Is this an item at the extremity of the tree - yes always */
    public boolean isLeafItemType() { return true; }
    //…
}


public class BudgetNonLeafItemImpl extends BaseBudgetItemImpl {

    /** Is this an item at the extremity of the tree - no never */
    public boolean isLeafItemType() { return false; }

    public List getChildren() { …}

   public BaseBudgetItemImpl addChild(BaseBudgetItemImpl child) { …}

   private ArrayList children = new ArrayList();  // holds references to leaf- or non-leaf
items !
   //…
}


Does it make sense to try to use Betwixt to read/write (round-trip) such a structure or would
another tool (Castor ?) be better for the job ?

I started trying to write the xml and this works fine (see actual output from an attempted
round-trip of the more complex real classes below).  I managed to read  back the root node
but none of the children get restored.

The basic question is if Betwixt can handle the recursive relationship - the root node will
be of type non-leaf and this will contain a mixture of leaf and non-leaf items in the "children"
collection.  The non-leaf nodes may of course then themselves have children of both types.

Thanks,
Richard SULLIVAN



 
XML output:
===========

<?xml version="1.0"?>  <budgetNonLeafItemImpl id="1">
    <child id="2">
      <basicLayoutInfo id="3">
        <attachTo/>
        <table>false</table>
      </basicLayoutInfo>
      <canAddOnlyLeaves>false</canAddOnlyLeaves>
      <descriptions/>
      <leafItemType>false</leafItemType>
      <mandatory>true</mandatory>
      <optionalId/>
      <title>A1.1 Personnel</title>
      <toolTipText/>
      <usageNotes/>
      <valid>true</valid>
    </child>
    <child id="4">
      <child id="5">
        <child id="6">
          <basicLayoutInfo id="7">
            <attachTo/>
            <table>false</table>
          </basicLayoutInfo>
          <descriptions/>
          <leafItemType>true</leafItemType>
          <mandatory>false</mandatory>
          <optionalId/>
          <title>A1.2.1.1 Travel - London Brussels</title>
          <valid>false</valid>
          <values>
            <value>London</value>
            <value>Brussels</value>
            <value>Air</value>
            <value>132.11</value>
            <value>3</value>
          </values>
        </child>
        <child id="8">
          <basicLayoutInfo id="9">
            <attachTo/>
            <table>false</table>
          </basicLayoutInfo>
          <descriptions/>
          <leafItemType>true</leafItemType>
          <mandatory>false</mandatory>
          <optionalId/>
          <title>A1.2.1.2 Travel - Amsterdam Brussels</title>
          <valid>false</valid>
          <values>
            <value/>
            <value/>
            <value/>
            <value>100.0</value>
            <value>1</value>
          </values>
        </child>
        <basicLayoutInfo id="10">
          <attachTo/>
          <table>true</table>
        </basicLayoutInfo>
        <canAddOnlyLeaves>true</canAddOnlyLeaves>
        <descriptions>
          <description>London-Brussels</description>
          <description>Brussels-London</description>
          <description>Method</description>
          <description>Cost per person</description>
          <description>Nr. Persons</description>
        </descriptions>
        <leafItemType>false</leafItemType>
        <mandatory>false</mandatory>
        <optionalId/>
        <title>A1.2.1 Travel</title>
        <toolTipText/>
        <usageNotes/>
        <valid>true</valid>
      </child>
      <basicLayoutInfo id="11">
        <attachTo/>
        <table>false</table>
      </basicLayoutInfo>
      <canAddOnlyLeaves>false</canAddOnlyLeaves>
      <descriptions/>
      <leafItemType>false</leafItemType>
      <mandatory>false</mandatory>
      <optionalId/>
      <title>A1.2 Travel and accomodation</title>
      <toolTipText/>
      <usageNotes/>
      <valid>true</valid>
    </child>
    <child id="12">
      <child id="13">
        <child id="14">
          <basicLayoutInfo id="15">
            <attachTo/>
            <table>false</table>
          </basicLayoutInfo>
          <descriptions>
            <description>English</description>
            <description>French</description>
            <description>Cost per page (Euro)</description>
            <description>Nr. pages</description>
          </descriptions>
          <leafItemType>true</leafItemType>
          <mandatory>false</mandatory>
          <optionalId/>
          <title>A1.3.1.1 Translation of questionaire for all member states</title>
          <valid>true</valid>
          <values>
            <value/>
            <value/>
            <value>10.5</value>
            <value>10</value>
          </values>
        </child>
        <child id="16">
          <basicLayoutInfo id="17">
            <attachTo/>
            <table>false</table>
          </basicLayoutInfo>
          <descriptions>
            <description>English</description>
            <description>French</description>
            <description>Cost per page (Euro)</description>
            <description>Nr. pages</description>
          </descriptions>
          <leafItemType>true</leafItemType>
          <mandatory>false</mandatory>
          <optionalId/>
          <title>A1.3.1.1 Translation of questionaire for all member states</title>
          <valid>true</valid>
          <values>
            <value/>
            <value/>
            <value>10.5</value>
            <value>10</value>
          </values>
        </child>
        <basicLayoutInfo id="18">
          <attachTo/>
          <table>false</table>
        </basicLayoutInfo>
        <canAddOnlyLeaves>false</canAddOnlyLeaves>
        <descriptions/>
        <leafItemType>false</leafItemType>
        <mandatory>false</mandatory>
        <optionalId/>
        <title>A1.3.1 Implementation costs - Translations</title>
        <toolTipText/>
        <usageNotes/>
        <valid>true</valid>
      </child>
      <basicLayoutInfo id="19">
        <attachTo/>
        <table>false</table>
      </basicLayoutInfo>
      <canAddOnlyLeaves>false</canAddOnlyLeaves>
      <descriptions/>
      <leafItemType>false</leafItemType>
      <mandatory>false</mandatory>
      <optionalId/>
      <title>A1.3 Implementation costs</title>
      <toolTipText/>
      <usageNotes/>
      <valid>true</valid>
    </child>
    <child id="20">
      <child id="21">
        <basicLayoutInfo id="22">
          <attachTo/>
          <table>false</table>
        </basicLayoutInfo>
        <descriptions>
          <description>Audit fees</description>
        </descriptions>
        <leafItemType>true</leafItemType>
        <mandatory>false</mandatory>
        <optionalId/>
        <title>A1.4.1 Audit reports</title>
        <valid>true</valid>
        <values>
          <value>0.0</value>
        </values>
      </child>
      <child id="23">
        <basicLayoutInfo id="24">
          <attachTo/>
          <table>false</table>
        </basicLayoutInfo>
        <descriptions>
          <description>Cost of obtaining financial guarantee</description>
        </descriptions>
        <leafItemType>true</leafItemType>
        <mandatory>false</mandatory>
        <optionalId/>
        <title>A1.4.2 Financial guarantee</title>
        <valid>true</valid>
        <values>
          <value>0.0</value>
        </values>
      </child>
      <basicLayoutInfo id="25">
        <attachTo/>
        <table>false</table>
      </basicLayoutInfo>
      <canAddOnlyLeaves>true</canAddOnlyLeaves>
      <descriptions/>
      <leafItemType>false</leafItemType>
      <mandatory>false</mandatory>
      <optionalId/>
      <title>A1.4 Frais résultant d'exigences de la convention</title>
      <toolTipText/>
      <usageNotes/>
      <valid>true</valid>
    </child>
    <child id="26">
      <child id="27">
        <basicLayoutInfo id="28">
          <attachTo/>
          <table>false</table>
        </basicLayoutInfo>
        <descriptions>
          <description>General expenses</description>
        </descriptions>
        <leafItemType>true</leafItemType>
        <mandatory>false</mandatory>
        <optionalId/>
        <title>A1.7.1 General expenses</title>
        <valid>true</valid>
        <values>
          <value>0.0</value>
        </values>
      </child>
      <basicLayoutInfo id="29">
        <attachTo/>
        <table>false</table>
      </basicLayoutInfo>
      <canAddOnlyLeaves>true</canAddOnlyLeaves>
      <descriptions/>
      <leafItemType>false</leafItemType>
      <mandatory>false</mandatory>
      <optionalId/>
      <title>A1.7 Indirect and other costs (max 7% of eligible costs)</title>
      <toolTipText/>
      <usageNotes/>
      <valid>true</valid>
    </child>
    <basicLayoutInfo id="30">
      <attachTo/>
      <table>false</table>
    </basicLayoutInfo>
    <canAddOnlyLeaves>false</canAddOnlyLeaves>
    <descriptions/>
    <leafItemType>false</leafItemType>
    <mandatory>false</mandatory>
    <optionalId/>
    <title>A1 Eligible costs</title>
    <toolTipText/>
    <usageNotes/>
    <valid>true</valid>
  </budgetNonLeafItemImpl>



XML parsed back to object then regenerated:
===========================================

<?xml version="1.0"?>  <budgetNonLeafItemImpl id="1">
    <basicLayoutInfo id="2">
      <attachTo/>
      <table>false</table>
    </basicLayoutInfo>
    <canAddOnlyLeaves>false</canAddOnlyLeaves>
    <descriptions/>
    <leafItemType>false</leafItemType>
    <mandatory>false</mandatory>
    <optionalId/>
    <title>A1 Eligible costs</title>
    <toolTipText/>
    <usageNotes/>
    <valid>true</valid>
  </budgetNonLeafItemImpl>



______________________________________________________________________
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!		
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message