// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package test;

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

import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;

public class Test {
    public static void main(String[] args) {
        System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
        System.setProperty("java.naming.factory.url.pkgs", "org.jnp.interfaces");
        System.setProperty("java.naming.provider.url", "localhost:1099");
        try {
            Context ctx = new InitialContext();
            Object temp;
            temp = ctx.lookup("ejb/TestSession");
            TestSessionHome shome = (TestSessionHome) PortableRemoteObject.narrow(temp, TestSessionHome.class);
            TestSession sbean = shome.create();
            System.out.println(sbean.dup("a"));
            System.out.println(sbean.dup("bb"));
            System.out.println(sbean.dup("ccc"));
            temp = ctx.lookup("ejb/TestEntity");
            TestEntityHome ehome = (TestEntityHome) PortableRemoteObject.narrow(temp, TestEntityHome.class);
            Iterator it = ehome.findAll().iterator();
            while (it.hasNext()) {
                TestEntity ebean = (TestEntity) it.next();
                System.out.println(ebean.getF1() + " " + ebean.getF2());
            }
        } catch (ClassCastException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (NamingException e) {
            e.printStackTrace();
        } catch (CreateException e) {
            e.printStackTrace();
        } catch (FinderException e) {
            e.printStackTrace();
        }
    }
}
