* internal reference to single copy of Document Roots array
*/
private VAMSAS[] _VamsasRoots=null;
+ /**
+ * set if the client has corrupted the Vamsas Document structure somehow.
+ * if this is set the document will never be written back to the session unless the corruption is fixed.
+ */
+ private boolean invalidModification=false;
protected void updateDocumentRoots() {
if (doc==null) {
* verify that newr version is really an intact version of the
* @param newVersion (may be modified)
* @param oldVersion
+ * @param modflag
* @return true if newVersion is a valid root that preserves original references
*/
- private boolean isValidUpdate(VAMSAS newVersion, final VAMSAS oldVersion) {
+ private boolean isValidUpdate(VAMSAS newVersion, final VAMSAS oldVersion, ClientDocument modflag) {
// ideal - this cascades down the two structures, ensuring that all ID'd objects in one are present in the other.
if (oldVersion==newVersion) {
// may be a virgin root element.
if (!newVersion.isRegistered())
- _registerObject(newVersion); // TODO: check - this call hasn't been tested.
- // Should retrieve original version and compare - unless local hashes can be used to determine if resultSet has been truncated.
+ {
+ _registerObject(newVersion); // TODO: check - this call hasn't been tested. (seems to work now)
+ modflag.isModified=true;
+ }
+ // TODO: Should attempt to repair document if client app has deleted/broken bits of it
+ if (oldVersion.is__stored_in_document()) {
+ // retrieve compare hashCodes to detect update.
+ if (oldVersion.get__last_hash()!=oldVersion.hashCode())
+ {
+ log.debug("Modified hashcode for vamsas root "+oldVersion.getVorbaId());
+ modflag.isModified = true;
+ } else {
+ log.debug("Unmodified vamsas root "+oldVersion.getVorbaId());
+ }
+ }
// just do internal validation for moment.
try {
- newVersion.validate();
+ if (getSimpleClientConfig().validateUpdatedRoots())
+ {
+ newVersion.validate();
+ }
return true;
}
catch (Exception e)
{
log.error("Validation Exception for new vamsas root :"+newVersion.getVorbaId(),e);
+ modflag.invalidModification=true;
}
return false;
} else {
// redundant ? if (oldVersion.is__stored_in_document())
if (!newVersion.isRegistered())
+ {
_registerObject(newVersion);
+ modflag.isModified=true;
+ }
try {
- newVersion.validate();
+ if (getSimpleClientConfig().validateMergedRoots())
+ {
+ newVersion.validate();
+ }
+ modflag.isModified=true;
return true;
}
catch (Exception e)
}
}*/
}
+ private SimpleClientConfig getSimpleClientConfig() {
+ return sclient.getSimpleClientConfig();
+}
/**
* merge old and new root vectors
* @param newr This array may be written to
*/
private VAMSAS[] _combineRoots(VAMSAS[] newr, final VAMSAS[] original, ClientDocument modflag) {
Vector rts = new Vector();
- boolean modified=false;
for (int i=0,j=original.length; i<j; i++) {
int k = _contains(original[i], newr);
if (k>-1) {
- if (isValidUpdate(newr[k], original[i])) {
- modified=true;
+ if (isValidUpdate(newr[k], original[i], modflag)) {
+ // set by isValidUpdate if the hashcodes were really different from last store
rts.add(newr[k]);
newr[k]=null;
} else {
for (int i=0,j=newr.length; i<j; i++) {
if (newr[i]!=null) {
rts.add(newr[i]);
- modified=true;
+ modflag.isModified=true;
}
}
newr = new VAMSAS[rts.size()];
for (int i=0,j=rts.size(); i<j; i++)
newr[i] = (VAMSAS) rts.get(i);
- if (modflag!=null)
- modflag.isModified = modified;
return newr;
}
throw new java.io.IOException("Document is closed.");
}
if (iohandler==null) {
- log.warn("updateSessionDocument called document iohandler handler.");
+ log.warn("updateSessionDocument called on null document iohandler handler.");
throw new java.io.IOException("Document is closed.");
}
doc = null;
}
// disengage from client
- if (sclient!=null)
+ if (sclient!=null && sclient.cdocument==this)
sclient.cdocument = null;
sclient=null;
// TODO: WALK through the document objects calling the update mechanism for each one, or just pass this vector back to client ?return updatedObjects;
return null;
}
+ /**
+ * if this is set the document will never be written back to the session unless the corruption is fixed.
+ * @return the invalidModification
+ */
+ public boolean isInvalidModification() {
+ return invalidModification;
+ }
+ /**
+ * set if the client has corrupted the Vamsas Document structure somehow.
+ * if this is set the document will never be written back to the session unless the corruption is fixed.
+ * @param invalidModification the invalidModification to set
+ */
+ public void setInvalidModification(boolean invalidModification) {
+ this.invalidModification = invalidModification;
+ }
}