private Profile generateProfileFromModel(TreeModel dtm){
Profile p = new Profile();
DefaultMutableTreeNode theProfileRoot = (DefaultMutableTreeNode)dtm.getRoot();
//get the profile attributes
//children List
//id String
//parent String
//regAuthority String
//revisionNotes List
//securityType String
//statusID String
//type String
//version String
TreeNode theProfAttrRoot = theProfileRoot.getChildAt(0);
TreeNode theProfAttr_Children = theProfAttrRoot.getChildAt(0);
addElementsFromTreeNode(theProfAttr_Children,p.getProfileAttributes().getChildren());
TreeNode theProfAttr_IDRoot = theProfAttrRoot.getChildAt(1);
DefaultMutableTreeNode theProfAttr_ID = (DefaultMutableTreeNode)theProfAttr_IDRoot.getChildAt(0);
p.getProfileAttributes().setID((String)theProfAttr_ID.getUserObject());
TreeNode theProfAttr_ParentRoot = theProfAttrRoot.getChildAt(2);
DefaultMutableTreeNode theProfAttr_Parent = (DefaultMutableTreeNode)theProfAttr_ParentRoot.getChildAt(0);
p.getProfileAttributes().setParent((String)theProfAttr_Parent.getUserObject());
TreeNode theProfAttr_RegAuthorityRoot = theProfAttrRoot.getChildAt(3);
DefaultMutableTreeNode theProfAttr_RegAuthority = (DefaultMutableTreeNode)theProfAttr_RegAuthorityRoot.getChildAt(0);
p.getProfileAttributes().setRegAuthority((String)theProfAttr_RegAuthority.getUserObject());
TreeNode theProfAttr_revNotes = theProfAttrRoot.getChildAt(4);
addElementsFromTreeNode(theProfAttr_revNotes,p.getProfileAttributes().getRevisionNotes());
TreeNode theProfAttr_SecurityTypeRoot = theProfAttrRoot.getChildAt(5);
DefaultMutableTreeNode theProfAttr_SecurityType = (DefaultMutableTreeNode)theProfAttr_SecurityTypeRoot.getChildAt(0);
p.getProfileAttributes().setSecurityType((String)theProfAttr_SecurityType.getUserObject());
TreeNode theProfAttr_StatusIDRoot = theProfAttrRoot.getChildAt(6);
DefaultMutableTreeNode theProfAttr_StatusID = (DefaultMutableTreeNode)theProfAttr_StatusIDRoot.getChildAt(0);
p.getProfileAttributes().setStatusID((String)theProfAttr_StatusID.getUserObject());
TreeNode theProfAttr_TypeRoot = theProfAttrRoot.getChildAt(7);
DefaultMutableTreeNode theProfAttr_Type = (DefaultMutableTreeNode)theProfAttr_TypeRoot.getChildAt(0);
p.getProfileAttributes().setType((String)theProfAttr_Type.getUserObject());
TreeNode theProfAttr_VersionRoot = theProfAttrRoot.getChildAt(8);
DefaultMutableTreeNode theProfAttr_Version = (DefaultMutableTreeNode)theProfAttr_VersionRoot.getChildAt(0);
p.getProfileAttributes().setVersion((String)theProfAttr_Version.getUserObject());
//resource attributes
//aggregation - string
//class - string
//contexts - list
//contributors - list
//coverages - list
//creators - list
//dates - list
//description - string
//formats - list
//identifier - string
//languages - list
//locations - list
//publishers - list
//relations - list
//rights - list
//sources - list
//subjects - list
//title - string
//types - list
TreeNode theResAttrRoot = theProfileRoot.getChildAt(1);
TreeNode ra_aggRoot=theResAttrRoot.getChildAt(0);
TreeNode ra_classRoot=theResAttrRoot.getChildAt(1);
TreeNode ra_contextRoot=theResAttrRoot.getChildAt(2);
TreeNode ra_contribRoot=theResAttrRoot.getChildAt(3);
TreeNode ra_coverageRoot=theResAttrRoot.getChildAt(4);
TreeNode ra_creatorRoot=theResAttrRoot.getChildAt(5);
TreeNode ra_datesRoot=theResAttrRoot.getChildAt(6);
TreeNode ra_descRoot=theResAttrRoot.getChildAt(7);
TreeNode ra_formatsRoot=theResAttrRoot.getChildAt(8);
TreeNode ra_identifierRoot=theResAttrRoot.getChildAt(9);
TreeNode ra_langRoot=theResAttrRoot.getChildAt(10);
TreeNode ra_locationRoot=theResAttrRoot.getChildAt(11);
TreeNode ra_publishersRoot=theResAttrRoot.getChildAt(12);
TreeNode ra_relationsRoot=theResAttrRoot.getChildAt(13);
TreeNode ra_rightsRoot=theResAttrRoot.getChildAt(14);
TreeNode ra_sourcesRoot=theResAttrRoot.getChildAt(15);
TreeNode ra_subjectsRoot=theResAttrRoot.getChildAt(16);
TreeNode ra_titleRoot=theResAttrRoot.getChildAt(17);
TreeNode ra_typesRoot=theResAttrRoot.getChildAt(18);
DefaultMutableTreeNode ra_agg = (DefaultMutableTreeNode)ra_aggRoot.getChildAt(0);
DefaultMutableTreeNode ra_class = (DefaultMutableTreeNode)ra_classRoot.getChildAt(0);
p.getResourceAttributes().setResAggregation((String)ra_agg.getUserObject());
p.getResourceAttributes().setResClass((String)ra_class.getUserObject());
addElementsFromTreeNode(ra_contextRoot,p.getResourceAttributes().getResContexts());
addElementsFromTreeNode(ra_contribRoot,p.getResourceAttributes().getContributors());
addElementsFromTreeNode(ra_coverageRoot,p.getResourceAttributes().getCoverages());
addElementsFromTreeNode(ra_creatorRoot,p.getResourceAttributes().getCreators());
addElementsFromTreeNode(ra_datesRoot,p.getResourceAttributes().getDates());
DefaultMutableTreeNode ra_desc = (DefaultMutableTreeNode)ra_descRoot.getChildAt(0);
DefaultMutableTreeNode ra_identifier = (DefaultMutableTreeNode)ra_identifierRoot.getChildAt(0);
p.getResourceAttributes().setDescription((String)ra_desc.getUserObject());
p.getResourceAttributes().setIdentifier((String)ra_identifier.getUserObject());
addElementsFromTreeNode(ra_formatsRoot,p.getResourceAttributes().getFormats());
addElementsFromTreeNode(ra_langRoot,p.getResourceAttributes().getLanguages());
addElementsFromTreeNode(ra_locationRoot,p.getResourceAttributes().getResLocations());
addElementsFromTreeNode(ra_publishersRoot,p.getResourceAttributes().getPublishers());
addElementsFromTreeNode(ra_relationsRoot,p.getResourceAttributes().getRelations());
addElementsFromTreeNode(ra_rightsRoot,p.getResourceAttributes().getRights());
addElementsFromTreeNode(ra_sourcesRoot,p.getResourceAttributes().getSources());
addElementsFromTreeNode(ra_subjectsRoot,p.getResourceAttributes().getSubjects());
addElementsFromTreeNode(ra_typesRoot,p.getResourceAttributes().getTypes());
DefaultMutableTreeNode ra_title = (DefaultMutableTreeNode)ra_titleRoot.getChildAt(0);
p.getResourceAttributes().setTitle((String)ra_title.getUserObject());
//handle profile elements here
TreeNode theProfElemRoot = theProfileRoot.getChildAt(2);
for(Enumeration e = theProfElemRoot.children(); e.hasMoreElements(); ){
DefaultMutableTreeNode profElemN_Root = (DefaultMutableTreeNode)e.nextElement();
System.out.println("Got Profile Element "+(String)profElemN_Root.getUserObject());
ProfileElement profElem = makeProfileElementFromTreeNode(p,profElemN_Root);
if(profElem != null){
System.out.println("Making profile element");
System.out.println(profElem.toString());
p.getProfileElements().put((String)profElemN_Root.getUserObject(),profElem);
}
}