/*
* This example is from the book "Java Enterprise in a Nutshell".
* Copyright (c) 1999 by O'Reilly & Associates.
* You may distribute this source code for non-commercial purposes only.
* You may study, modify, and use this example for any purpose, as long as
* this notice is retained. Note that this example is provided "as is",
* WITHOUT WARRANTY of any kind either expressed or implied.
*/
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
// Sample implementation of the AccountManager interface. This simple
// example simply registers each account with the local registry, and does the
// lookup for the remote client when getAccount() is called.
public class AccountManagerImpl
extends UnicastRemoteObject implements AccountManager {
public AccountManagerImpl() throws RemoteException {}
public Account getAccount(String name) throws RemoteException {
Registry reg = LocateRegistry.getRegistry();
Account a = null;
try {
a = (Account)reg.lookup(name);
}
catch (Exception e) {}
return a;
}
public boolean newAccount(Account a) throws RemoteException {
Registry reg = LocateRegistry.getRegistry();
System.out.print("Registering new account...");
reg.rebind(a.getName(), a);
System.out.println("done.");
return true;
}
}
|