FileDocCategorySizeDatePackage
ExternExampleEvolvedClass.javaAPI DocExample6353Wed Apr 19 11:21:16 BST 2000None

ExternExampleEvolvedClass

public class ExternExampleEvolvedClass extends Object
This is a continuation of the Externalizable Persistence Example. This file contains the evolved version of the ExternVersioningClass. Of course, normally, the evolved class would actually take place of the original class but we just keep both of them to demonstrate the evolution For information on how to run, see file ExternExampleOriginalClass.java

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)
There are two options: either a user can serialize an object or deserialize it. (using the -s or -d flag). These options allow for the demonstration of bidirection readability and writeability between the original and the evolved class. In other words, one can serialize an object here and deserialize it with the evolved class or vice versa.

  
	
	boolean serialize = false;
	boolean deserialize = false;
	
	ExternVersioningClass wobj = new ExternVersioningClass
	    (1, "evolvedclass", true, 1.23);
	ExternVersioningClass robj = null;
	/* 
	 * see if we are serializing or deserializing.
	 * The ability to deserialize or serialize allows
	 * us to see the bidirectional readability and writeability
	 */
	if (args.length == 1) {
	    if (args[0].equals("-d")) {
		deserialize = true;
		} else if (args[0].equals("-s")) {
		    serialize = true;
		} else {
		    usage();
		    System.exit(0);
		}
	} else {
	    usage();
	    System.exit(0);
	}
	
	/* 
	 * serialize, if that's the chosen option
	 */
	if (serialize) {
	    try {
		FileOutputStream fo = new FileOutputStream("evolve.tmp");
		ObjectOutputStream so = new ObjectOutputStream(fo);
		so.writeObject(wobj);
		so.flush();
	    } catch (Exception e) {
		System.out.println(e);
		System.exit(1);
	    }
	}
	
	/* 
	 * deserialize, if that's the chosen option
	 */
	if (deserialize) {
	    try {
		FileInputStream fi = new FileInputStream("evolve.tmp");
		ObjectInputStream si = new ObjectInputStream(fi);
		robj = (ExternVersioningClass) si.readObject();
	    } catch (Exception e) {
		System.out.println(e);
		System.exit(1);
	    }
	}
    
static voidusage()
Prints out the usage

	System.out.println("Usage:");
	System.out.println("      -s (in order to serialize)");
	System.out.println("      -d (in order to deserialize)");