package com.javahonk;
import java.util.*;
import javax.naming.InitialContext;
import javax.naming.Context;

public class PersonClient {
	public static void main(String args[]) {

		try {
			int choice = 1;
			Properties properties = new Properties();
			properties.put(Context.INITIAL_CONTEXT_FACTORY,
					"org.jnp.interfaces.NamingContextFactory");
			properties.put(Context.URL_PKG_PREFIXES,
					"org.jboss.naming:org.jnp.interfaces");
			
			
			//You could use two option URL for context URL 
			//Option 1: use below 
			//properties.put(Context.PROVIDER_URL, "localhost");
			
			//Option 2: use below 
			properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
			
			InitialContext ctx = new InitialContext(properties);

			PersonHome home = (PersonHome) ctx.lookup("JNDIName_Peron");

			Person bean = home.create();
			Scanner scanner = new Scanner(System.in);
			while (choice != 2) {
				String bname;
				System.out.println("Enter value 1 to Add Person and 2 to come Out");
				choice = scanner.nextInt();
				if (choice == 1) {
					System.out.println("Enter person name");
					bname = scanner.next();
					bean.addPerson(bname);
				} else if (choice == 2) {
					break;
				}
			}

			Vector vector = bean.getPerson();

			System.out.println("Total size of vector \t" + vector.size());
			for (int i = 0; i < vector.size(); ++i) {
				System.out.println((String) vector.elementAt(i));
			}

		} catch (Exception exception) {
			System.out.println(exception);
		}
	}
}