readOldVersion 方法示例
此方法的生成几乎与 readVersion <EXTERBALIZATION_VERSION_UID> 完全相同,以支持向后兼容性。为支持多个发行版本的向后兼容性,在方法中,每个受支持的旧版本应包含一个条件块。每个条件都应检查在该版本的类中使用的版本 UID,并且读取字段的块应与用于该版本的一组读取调用相同。生成的 OLD_FORMAT_VERSION_UID 常量仅对该类的 R4 实例有效。可以读取和丢弃不再存在的字段 (未分配)。对于该版本不存在的字段,可以按照将对象置于有效状态所需的方式进行初始化。
private boolean readOldVersion( ObjectInput input,
long readSerialVersionUID, boolean passThrough, boolean superDone )
throws IOException, ClassNotFoundException {
//##begin readOldVersion%readOldVersion.body preserve=no
boolean success = true;
// handle previous version
if ( readSerialVersionUID == OLD_FORMAT_VERSION_UID ) {
a1 = (String)input.readObject();
a2 = (Date)input.readObject();
a3 = (Xyz)input.readObject();
list = (Vector)input.readObject();
String size_string_value = (String)input.readObject();
try { size = (MySize)wt.fc.EnumeratedType.toEnumeratedType(
size_string_value ); }
// in case it was old format
catch( wt.util.WTInvalidParameterException e ) {
size = MySize.toMySize( size_string_value );
}
theOneMoreReference = (ObjectReference)input.readObject();
timeline = (Timeline)input.readObject();
work = (MyAddress)input.readObject();
}
else if ( !superDone ) {
success = super.readVersion( this, input,
readSerialVersionUID, false, false ); // reformatted stream-
if ( success && !passThrough && // forced pass through to
skip me
// I have been inserted into hierarchy
readSerialVersionUID != super.EXTERNALIZATION_VERSION_UID )
// try mine again
readVersion( this, input, input.readLong(), false, true );
}
else
throw new java.io.InvalidClassException( CLASSNAME,
"Local class not compatible:"
+ " stream classdesc externalizationVersionUID=
" + readSerialVersionUID
+ " local class externalizationVersionUID=
" + EXTERNALIZATION_VERSION_UID );
return success;
//##end readOldVersion%readOldVersion.body
}