* @param topLevelComp
*/
private void createXmlComponent(AbstractComponent mctComp,
ComponentListType xmlComponentList, boolean topLevelComp) {
ComponentType xmlComp = objFactory.createComponentType();
// Set flag to show which component(s) are at the top level in the
// structure tree of the MCT component(s) which were chosen for export.
// Needed for import.
if (topLevelComp) {
xmlComp.setToplevel(true);
} else {
xmlComp.setToplevel(false);
}
xmlComp.setComponentId(mctComp.getId());
xmlComp.setComponentType(mctComp.getClass().getName());
xmlComp.setCreator(mctComp.getCreator());
xmlComp.setName(mctComp.getDisplayName());
xmlComp.setExternalKey(mctComp.getExternalKey());
xmlComp.setOwner(mctComp.getOwner());
// Convert from Date to XMLGregorianCalendar
XMLGregorianCalendar xmlGCDate = Utilities
.convertToXMLGregorianCalendar(mctComp.getCreationDate());
xmlComp.setCreationDate(xmlGCDate);
marshalModelState(mctComp, xmlComp);
marshalViewState(mctComp, xmlComp);
// xmlComp must be added to the list before the children are processed,
// in case there is a case of A being the parent of B being the parent of A.
xmlComponentList.getComponent().add(xmlComp);
// Recursively get children
if (mctComp.getComponents() != null) {
for (AbstractComponent child : mctComp.getComponents()) {
updateProgressBar();
if (isExportable(child)) {
if (exportAsReference(child)) {
// Add child to XML file as a reference
// (ComponentRefType)
ComponentRefType compReference = objFactory
.createComponentRefType();
compReference.setComponentId(child.getId());
compReference.setExternalKey(child.getExternalKey());
compReference.setClassType(child.getClass().getName());
xmlComp.getComponentRefs().add(compReference);
} else {
// Add child to XML file as a component (write all of
// its data)
if (isNewComponent(child, xmlComponentList)) {
// Recursive call to add child component as a
// top-level component in the XML file
createXmlComponent(child, xmlComponentList, false);
}
// Add child's component ID to associatedComponents
AssociatedComponentType assocComp = objFactory
.createAssociatedComponentType();
assocComp.setId(child.getId());
xmlComp.getAssociatedComponents().add(assocComp);
}
} else {
// Child is not exportable
unexportableComps.add(child);