simpleclient.java

来自「21天学学会J2EE的源码1 是一本非常不错的书」· Java 代码 · 共 64 行

JAVA
64
字号
package client;

import agency.*;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import java.util.*;

public class SimpleClient
{
    private static String agencyJNDI = "java:comp/env/ejb/Agency";

    public static void main(String[] args) {
        if (args.length == 1)
            agencyJNDI = args[0];
        else if (args.length > 1) {
            System.err.println("Usage: SimpleClient [ AgencyJNDI ]");
            System.exit(1);
        }

        try {
            InitialContext ic = new InitialContext();

            Object lookup = ic.lookup(agencyJNDI);

            AgencyHome home = (AgencyHome)PortableRemoteObject.narrow(lookup, AgencyHome.class);

            Agency agency = home.create();

            System.out.println("Welcome to: "+agency.getAgencyName());

            System.out.println("Customer list: "+agency.getAgencyName());
            Collection customers = agency.getCustomers();
            Iterator it = customers.iterator();
            while (it.hasNext())
            {
                String name = (String)it.next();
                System.out.println(name);
            }
            System.out.println("\nDone\n");
            agency.remove();
        }
        catch (NamingException ex) {
            System.err.println(ex);
        }
        catch (ClassCastException ex) {
            System.err.println(ex);
        }
        catch (CreateException ex) {
            System.err.println(ex);
        }
        catch (RemoteException ex) {
            System.err.println(ex);
        }
        catch (RemoveException ex) {
            System.err.println(ex);
        }
    }

}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?