in impl/src/main/java/org/apache/tuscany/sdo/util/DataGraphResourceFactoryImpl.java [301:413]
public void traverse(List contents)
{
if (contents.size() >= 1 && contents.get(0) instanceof DataGraphImpl)
{
eDataGraph = (DataGraphImpl)contents.get(0);
Object datagraphMark = null;
if (!toDOM)
{
if (declareXML)
{
doc.add("<?xml version=\"" + xmlVersion + "\" encoding=\"" + encoding + "\"?>");
doc.addLine();
}
String elementName = helper.getQName(eDataGraph.eClass());
doc.startElement(elementName);
datagraphMark = doc.mark();
}
else
{
helper.populateNameInfo(nameInfo, eDataGraph.eClass());
currentNode = document.createElementNS(nameInfo.getNamespaceURI(), nameInfo.getQualifiedName());
document.appendChild(currentNode);
// not calling handler since there is no corresponding EObject
}
if (eDataGraph.eResource() != null && eDataGraph.eResource().getResourceSet() != null)
{
List ePackages = new ArrayList();
for (Iterator i = eDataGraph.eResource().getResourceSet().getResources().iterator(); i.hasNext();)
{
List resourceContents = ((Resource)i.next()).getContents();
if (resourceContents.size() == 1 && resourceContents.get(0) instanceof EPackage)
{
ePackages.add(resourceContents.get(0));
}
}
if (!ePackages.isEmpty())
{
if (!toDOM)
{
doc.startElement("models");
doc.addAttribute("xmlns", "");
}
else
{
currentNode = currentNode.appendChild(document.createElementNS(null, "models"));
((Element)currentNode).setAttributeNS(ExtendedMetaData.XMLNS_URI, ExtendedMetaData.XMLNS_PREFIX, "");
// not calling handler since there is no corresponding EObject
}
for (Iterator i = ePackages.iterator(); i.hasNext();)
{
writeTopObject((EPackage)i.next());
}
if (!toDOM)
{
doc.endElement();
}
else
{
currentNode = currentNode.getParentNode();
}
}
}
// use namespace declarations defined in the document (if any)
EObject eRootObject = eDataGraph.getERootObject();
EReference xmlnsPrefixMapFeature = extendedMetaData.getXMLNSPrefixMapFeature(eRootObject.eClass());
if (xmlnsPrefixMapFeature != null)
{
EMap xmlnsPrefixMap = (EMap)eRootObject.eGet(xmlnsPrefixMapFeature);
helper.setPrefixToNamespaceMap(xmlnsPrefixMap);
}
ChangeSummary changeSummary = eDataGraph.getEChangeSummary();
if (changeSummary != null)
{
helper.setMustHavePrefix(true);
if (changeSummary.isLogging())
{
((ChangeSummaryImpl)changeSummary).summarize();
writeTopObject((EObject)changeSummary);
}
else
{
writeTopObject((EObject)changeSummary);
}
helper.setMustHavePrefix(false);
}
if (eRootObject != null && writeTopObject(eRootObject) == null && !toDOM)
{
doc.addLine();
doc.setMixed(false);
}
if (!toDOM)
{
doc.endElement();
// reset to add namespace declarations
//
doc.resetToMark(datagraphMark);
}
else
{
currentNode = document.getFirstChild();
}
addNamespaceDeclarations();
}
else
{
super.traverse(contents);
}
}