if (changeSummary.isLogging())
((ChangeSummaryImpl) changeSummary).summarize();
ChangeDescription changeDescription = (ChangeDescription) changeSummary;
Iterator createdDataObjects = changeDescription.getObjectsToDetach().iterator();
deletedDataObjects = changeDescription.getObjectsToAttach();
EMap objectChanges = changeDescription.getObjectChanges();
modifiedDataObjects = objectChanges.keySet(); // may contain DO(s) from createdDataObjects and/or deletedDataObjects
/*
* 6-2. Prepare to compute (X)Path
* input: changeSummary
* output: rootResource
*/
/*not to support DataGraph 3-3
Object dataGraph = changeSummary.getDataGraph();
if (dataGraph == null) {
DataObject rootObject = changeSummary.getRootObject();
// assert rootObject != null;
rootResource = rootObject.getContainer() == null ? ((EObject) rootObject).eResource() // Can be null since this *StAX* writer does NOT
// require rootObject contained by an *EMF* Resource
: null; // eResource() direct content may not necessarily always be the XML document
} else
// assert dataGraph instanceof DataGraphImpl;
rootResource = ((org.apache.tuscany.sdo.impl.DataGraphImpl) dataGraph).getRootResource(); */
/*
* 6-2. Start ChangeSummary element
* input: writer, options, elementCS, changeSummary & changeDescription (6-1)
*/
nsPrefixSuffix = 0;
this.writer = writer;
this.options = options;
lineBreak = "";
indent = margin = pathRootObject = STRING_OPTION;
nest = 0;
changeSummaryElementNS = changeSummaryElement.getNamespaceURI();
changeSummaryElementName = changeSummaryElement.getLocalPart();
writeStartElement(changeSummaryElement.getPrefix(), changeSummaryElementNS, changeSummaryElementName);
lineBreak = STRING_OPTION;
rootObject = changeSummary.getRootObject();
extendedMetaData = (ExtendedMetaData) options.get(XMLResource.OPTION_EXTENDED_META_DATA);
if (extendedMetaData == null)
{
extendedMetaData = ExtendedMetaData.INSTANCE;
xsdHelper = XSDHelper.INSTANCE;
}
else
xsdHelper = new XSDHelperImpl(extendedMetaData, null);
Property declaration = changeSummaryElementNS == null
? rootObject.getType().getProperty(changeSummaryElementName)
: xsdHelper.getGlobalProperty(changeSummaryElementNS, changeSummaryElementName, true);
if (declaration != null)
{
EClassifier type = changeDescription.eClass();
if (type != declaration.getType() && type != CHANGE_SUMMARY)
writeGlobalAttribute(ExtendedMetaData.XSI_PREFIX, ExtendedMetaData.XSI_URI, XMLResource.TYPE, new StringBuffer(prefix(extendedMetaData.getNamespace(type), null))
.append(':').append(extendedMetaData.getName(type)).toString());
}
/*
* 6-3. "create" attribute
* input: createdDataObjects (6-1), rootResource (6-2), changeSummary & writer
*/
rootElementNS = null;
this.changeSummary = changeSummary;
if (createdDataObjects.hasNext()) {
StringBuffer buffer = new StringBuffer();
while (true) {
dataObject = (DataObject) createdDataObjects.next();
buffer.append(ref());
if (!createdDataObjects.hasNext())
break;
buffer.append(' ');
}
writer.writeAttribute(CREATE_ATTRIBUTE, buffer.toString());
}
/*
* 6-4. "delete" attribute
* input: deletedDataObjects (6-1), modifiedDataObjects (6-1) & writer
*/
Iterator iterator = deletedDataObjects.iterator();
if (iterator.hasNext()) {
lengthDeleted = -1;
StringBuffer buffer = null;
do {
dataObject = (DataObject) iterator.next();
if (skipDeletedModification(changeSummary.getOldContainer(dataObject)))
continue;
if (buffer == null)
buffer = new StringBuffer();
else
buffer.append(' ');
buffer.append(refDeleted());
} while (iterator.hasNext());
writer.writeAttribute(DELETE_ATTRIBUTE, buffer.toString());
}
/*
* 6-5. "logging" attribute
* input: changeSummary & writer
*/
writer.writeAttribute(LOGGING_ATTRIBUTE, changeSummary.isLogging() ? "true" : "false");
/*
* 6-6. Modified DataObjects
* input: modifiedDataObjects (6-1), rootResource (6-2), changeSummary & writer
*/
iterator = modifiedDataObjects.iterator();
if (iterator.hasNext()) {
boolean optimizeList;
if (options == null)
optimizeList = false;
else
{
Object option = options.get(OPTION_OPTIMIZE_LIST);
optimizeList = option == null ? false : ((Boolean)option).booleanValue();
}
prefix(SDOAnnotations.COMMONJ_SDO_NS, SDOPackage.eNS_PREFIX);
do {
DataObject dataObject = (DataObject) iterator.next();
if (skipDeletedModification(dataObject))
continue;
Property containmentProperty = dataObject.getContainmentProperty();
if (containmentProperty == null) {
++nest;
startElement();
rootElementName();
writer.writeStartElement(rootElementNS, rootElementName);
} else
writeStartElement(containmentProperty);
this.dataObject = dataObject;
writeRef();
String lineBreak = null;
Collection oldValues = (Collection) objectChanges.get(dataObject); // changeSummary.getOldValues repeats Sequence changes
Iterator settings = oldValues.iterator();
if (settings.hasNext()) {
do {
ChangeSummary.Setting oldValue = (ChangeSummary.Setting) settings.next();
if (oldValue.isSet())