*
* @param out The stream to write the object contents to
* @throws IOException
*/
public void writeExternal(ObjectOutput o) throws IOException {
SafeObjectOutputStream out = SafeObjectOutputStream.install(o);
//---------------------------------------------------------
// in order to handle future changes to the message
// context definition, be sure to maintain the
// object level identifiers
//---------------------------------------------------------
// serialization version ID
out.writeLong(serialVersionUID);
// revision ID
out.writeInt(revisionID);
//---------------------------------------------------------
// various simple fields
//---------------------------------------------------------
out.writeLong(getLastTouchedTime());
out.writeBoolean(isComplete);
out.writeObject(key);
out.writeObject(logCorrelationIDString);
//---------------------------------------------------------
// properties
//---------------------------------------------------------
out.writeUTF("properties"); // write marker
out.writeMap(getProperties());
//---------------------------------------------------------
// AxisOperation axisOperation
//---------------------------------------------------------
out.writeUTF("metaAxisOperation"); // write marker
metaAxisOperation = null;
if (axisOperation != null) {
metaAxisOperation = new MetaDataEntry(axisOperation.getClass().getName(),
axisOperation.getName().toString());
}
out.writeObject(metaAxisOperation);
//---------------------------------------------------------
// AxisOperation axisService
//---------------------------------------------------------
// save the meta data for the corresponding axis service to better
// match up the axis operation
out.writeUTF("metaAxisService"); // write marker
metaAxisService = null;
AxisService axisService = axisOperation.getAxisService();
if (axisService != null) {
String serviceAndPortNames = ActivateUtils.getAxisServiceExternalizeExtraName(axisService);
// If there is a service & port QName stored on the AxisService then write it out so
// it can be used during deserialization to hook up the message context to the
// correct AxisService.
metaAxisService =
new MetaDataEntry(axisService.getClass().getName(), axisService.getName(),
serviceAndPortNames);
}
out.writeObject(metaAxisService);
//---------------------------------------------------------
// parent
//---------------------------------------------------------
out.writeUTF("parent"); // write marker
out.writeObject(this.getServiceContext());
//---------------------------------------------------------
// HashMap messageContexts table
//---------------------------------------------------------
// NOTES: The assumption is that the table contains message contexts
// that are in the OperationContext hierarchy. To reduce overlap
// of object information that is being saved, extract the
// message context objects from the hierachy before saving.
// When the OperationContext is restored, the "slimmed down"
// message context objects are plugged back into the hierachy
// using the restored OperationContext as a basis.
// first deal with the original messageContexts table
HashMap tmpMsgCtxMap = null;
if ((messageContexts != null) && (!messageContexts.isEmpty())) {
// create a table of the non-isolated message contexts
workingSet = new HashMap();
tmpMsgCtxMap = new HashMap();
Set keySet = messageContexts.keySet();
Iterator itKeys = keySet.iterator();
while (itKeys.hasNext()) {
// expect the key to be a string
String keyObj = (String) itKeys.next();
// get the message context associated with that label
MessageContext value = (MessageContext) messageContexts.get(keyObj);
boolean addToWorkingSet = true;
// check to see if this message context was isolated
if (isolatedMessageContexts != null) {
if (!isolatedMessageContexts.isEmpty()) {
// see if the message context was previously isolated
MessageContext valueIsolated =
(MessageContext) isolatedMessageContexts.get(keyObj);
if (valueIsolated != null) {
String idIsol = valueIsolated.getMessageID();
if (idIsol != null) {
if (idIsol.equals(value.getMessageID())) {
// don't add to working set
addToWorkingSet = false;
}
}
}
}
}
if (addToWorkingSet) {
// put the meta data entry in the list
workingSet.put(keyObj, value);
}
}
// now we have a working set
Set keySet2 = workingSet.keySet();
Iterator itKeys2 = keySet2.iterator();
while (itKeys2.hasNext()) {
// expect the key to be a string
String keyObj2 = (String) itKeys2.next();
// get the message context associated with that label
MessageContext mc = (MessageContext) workingSet.get(keyObj2);
// construct a copy of the message context
// that has been extracted from the object hierarchy
MessageContext copyMC = mc.extractCopyMessageContext();
// Don't persist the message of the other message contexts
copyMC.setEnvelope(null);
// put the modified entry in the list
tmpMsgCtxMap.put(keyObj2, copyMC);
// trace point
if (log.isTraceEnabled()) {
log.trace(getLogCorrelationIDString() +
":writeExternal(): getting working set entry key [" + keyObj2 +
"] message context ID[" + copyMC.getMessageID() + "]");
}
}
}
out.writeUTF("messagecontexts"); // write marker
out.writeMap(tmpMsgCtxMap);
out.writeUTF("metaMessageContextMap");
out.writeMap(metaMessageContextMap);
//---------------------------------------------------------
// done
//---------------------------------------------------------