import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import test.*;

public class TestOrionClient
{
	private static final String NAME_SERVICE_STR = "com.evermind.server.ApplicationClientInitialContextFactory";
	private static final String PROVIDER_URL_STR = "ormi://localhost/test";
	private static final String USERNAME = "admin";	
	private static final String PASSWORD = "123";		

	private static InitialContext	init_ctx;

	private static InitialContext getInitialContext() throws NamingException {
		if (init_ctx == null) {
			Properties 			properties = new Properties();

			// get location of name service
			properties.put(javax.naming.Context.PROVIDER_URL,PROVIDER_URL_STR);
			// get name of initial context factory
			properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,NAME_SERVICE_STR);
			properties.put("java.naming.security.principal",USERNAME);			
			properties.put("java.naming.security.credentials",PASSWORD);						
			init_ctx = new InitialContext(properties);
		}

		return init_ctx;
	}

	public static void main(String args[]) {
		InitialContext		ctx;
		Object				homeObject;
		TestSessHomeIF		testSessHome;
		TestSessIF			testSess;
		
		try {
			ctx = getInitialContext();
			homeObject = ctx.lookup("java:comp/env/TestSess");			
			testSessHome = (TestSessHomeIF) PortableRemoteObject.narrow(homeObject, TestSessHomeIF.class);			

			testSess = testSessHome.create();		
			System.out.println("Env value for " + args[0] + " is: " + testSess.getEnvValue(args[0]));
		}
		catch( Exception ex ) {
			ex.printStackTrace();
		}
	}
}