hi ryan that's quite a cool example :)
if you'd fancy contributing it to the betwixt documentation please submit a patch. (you'll find information about how to do this by browsing http://jakarta.apache.com/commons http://jakarta.apache.org and http://www.apache.org/dev. please attach patches to http://issues.apache.org/bugzilla since the mailing list usually strips them.) - robert On Mon, 2005-11-07 at 10:16 -0600, Ryan McGuinness wrote: > Richard, > > I had a similar issue, but was able to resolve it with .betwixt files, and > a simple collections class. > > The example if for a reflexive questionaire: > > Questionnaire > QuestionaireInfo > QuestionGroup > Question > QuestionGroup > Question... > /QuestionGroup > /Question > Question > QuestionGroup... > > > Questions: > import java.util.ArrayList; > import java.util.Iterator; > import java.util.List; > > Questionnaire: > ... > Questions questions = new Questions(); > ... > addQuestion(Question q) { > questions.add(q); > } > > Questionnare Betwixt: > <?xml version='1.0'?> > <info> > <element name='rq:questionnaire'> > <attribute name="xmlns:rq" value="some namespace" /> > <element name='rq:questionnaireInfo' > property='questionnaireInfo' /> > <element name='rq:questionGroup' property='questions'/> > </element> > </info> > > Question: > ... > Questions questions = new Questions(); > ... > addQuestion(Question q) { > questions.add(q); > } > > Question Betwixt: > <?xml version='1.0'?> > <info> > <element name='rq:question'> > ... > <element name='rq:questionGroup' property='questions' /> > </element> > </info> > > public class Questions { > private List questions = new ArrayList(); > public Iterator getQuestions() { > return questions.iterator(); > } > public void addQuestion(Question question) { > questions.add(question); > } > public int size() { > return questions.size(); > } > } > > Questions Betwixt: > <?xml version='1.0'?> > <info> > <element name='rq:questionGroup'> > <element property='questions' > updater='addQuestion' /> > </element> > </info> > > > This could be applied to your objects quite easily. > Hope this helps. > > Ryan - > > > > > > > > > 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: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > -- "Imagination is more important than knowledge" - Albert Einstein. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
