*/
public static void writeObject(java.io.ObjectOutputStream out,
PersistentObjectItf sp, long[] fieldIds) throws IOException {
StateItf state;
boolean pmAllocated = false;
POManagerItf pm = null;
if (sp.speedoIsActive()) {
// Fetch the PersistenceManager
pm = sp.speedoGetHome().getPOManagerFactory().lookup();
if (pm == null) {
// Allocate a new PersistenceManager to close at the end
pm = (POManagerItf) sp.speedoGetHome().getPOManagerFactory()
.getPOManager();
pmAllocated = true;
}
try {
state = sp.speedoGetHome().readIntention(sp, fieldIds);
} catch (Exception e) {
// Close the PersistenceManager if it has been allocated localy
if (pmAllocated) {
pm.closePOManager();
}
throw new IOException(e.getMessage());
}
} else {
state = sp.speedoGetReferenceState();
}
try {
out.writeObject(state);
out.defaultWriteObject();
} finally {
// Close the PersistenceManager if it has been allocated localy
if (pmAllocated) {
pm.closePOManager();
}
}
}