// SessionClientSample.java

// Sample program showing session bean usage.
// 

import javax.naming.*;
import javax.rmi.*;
import javax.ejb.*;
import java.util.*;
import java.io.*;
import stocks.*;

public class SessionClientSample {
    
    static public void main( String[] args )
    {
        try {
            // Obtain the EJB home
            Properties env = new Properties();
            env.put( "java.naming.factory.initial",
                "desisoft.ejb.client.JRMPFactory" );
            env.put( "desisoft.ejb.nameServer1",
                "localhost:2050" );
            Context ctx = new InitialContext( env );
            StockQuotesHome home = (StockQuotesHome) PortableRemoteObject.narrow( ctx.lookup( "StockQuotes" ), StockQuotesHome.class );
            BufferedReader input = new BufferedReader( new InputStreamReader( System.in ));
            for (;;) {
                System.out.print( "Stock symbol: " );
                String stock = input.readLine();
                if ( stock.equals( "" ))
                    continue;
                if ( stock.equalsIgnoreCase( "quit" ))
                    break;
                StockQuotes bean = home.create( stock );
                try {
                    System.out.println( "Price = " + bean.getPrice());
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
