import java.util.*;
import java.io.*;
import java.rmi.*;

public class PIMServer {

  public static void main(String[] args) {
	try {
	  PIMCollection c = readCollection("pimdata");

	  ArrayList a = new ArrayList(c);
	  for (int i=0;i<a.size();i++) {
		System.out.println(a.get(i));
	  }

	  RemotePIMCollectionImpl p = new RemotePIMCollectionImpl(c);

	// tell the registry about the object
	  Naming.rebind("RemotePIM",p);
	  System.out.println("Registered as RemotePIM");

	} catch (Exception e) {
	  e.printStackTrace();
	}
  }

  public static PIMCollection readCollection(String filename) 
	throws IOException, ClassNotFoundException {

	PIMCollection c;

	ObjectInputStream ois = new ObjectInputStream( new FileInputStream(filename) );
	c = (PIMCollection) ois.readObject();
	ois.close();
	return(c);
  }

}

