Example of a readVersion<EXTERNALIZATION_VERSION_UID> Method
A method is generated for each line in the version/uid mapping table, but the body is only generated for the uid that matches the current release version. In this example, the current release version is Windchill R9.0, so its method body will be generated. The current release version is stored in release.properties, which is stored in SystemGeneration.jar. The property cannot be overridden by configuring it in user.properties.
The preserve=maybe tag has been introduced with this automated evolvability generation to support the generator making the decision regarding whether to preserve the method body. As with other methods, a particular method can be permanently taken over by the developer by changing it to preserve=yes.
With these externalization methods generated to be release specific, support for class evolution is automated but there are still issues that developers will need to manage. The first is when an attribute (field) is removed from a release. This case is easy, since the old externalization methods will no longer compile, since they reference non-existent fields. The developer will need to modify the code to not set field, but the old field must still be read off the stream, or it will throw a runtime exception. For example, if the title field is removed from the class, the previous readVersion<EXTERNALIZATION_VERSION_UID> methods will need to change the line that reads the title, as follows.
/*title = (String)*/input.readObject(); // field to assign no longer exists
The second scenario is when attributes (fields) are added. In this case, there will be no compile error and the code will deserialize without problem, but the object could possibly be left in an invalid state. The developer should be aware of this possibility and ensure that the object will be initialized to a valid state.
private boolean readVersion6676079877272797361L( ObjectInput input, long
readSerialVersionUID, boolean superDone )

throws IOException, ClassNotFoundException {

//##begin readVersion6676079877272797361L%readVersion6676079877272797361L.body
preserve=maybe

if ( !superDone ) // if not doing backward compatibility

super.readExternal( input ); // handle super class

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.EnumeratedTypeUtil.toEnumeratedType
( size_string_value
); }

catch( wt.util.WTInvalidParameterException e ) { // old format

size = MySize.toMySize( size_string_value );

}

theOneMoreReference = (ObjectReference)input.readObject();

timeline = (Timeline)input.readObject();

work = (MyAddress)input.readObject();

return true;

//##end readVersion6676079877272797361L%readVersion6676079877272797361L.body

}
도움이 되셨나요?