1 25 26 package org.objectweb.easybeans.examples.entitybean; 27 28 import java.util.Hashtable ; 29 30 import javax.naming.Context ; 31 import javax.naming.InitialContext ; 32 import javax.naming.NamingException ; 33 34 38 public final class Client { 39 40 43 private static final String DEFAULT_INITIAL_CONTEXT_FACTORY = "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory"; 44 45 48 private Client() { 49 50 } 51 52 57 public static void main(final String [] args) throws Exception { 58 59 Context initialContext = getInitialContext(); 61 SessionFacadeRemote facadeBean = (SessionFacadeRemote) initialContext.lookup( 62 "org.objectweb.easybeans.examples.entitybean.SessionFacade" 63 + "_" + SessionFacadeRemote.class.getName() + "@Remote"); 64 65 Employee florent = facadeBean.findEmployee(1); 67 if (florent == null) { 68 facadeBean.addEmployee(1, "Florent"); 69 } 70 Employee whale = facadeBean.findEmployee(2); 71 if (whale == null) { 72 facadeBean.addEmployee(2, "Whale"); 73 } 74 75 Employee employee = facadeBean.findEmployee(1); 77 System.out.println("Employee with id 1 = " + employee.getName()); 78 79 employee = facadeBean.findEmployee(2); 81 System.out.println("Employee with id 2 = " + employee.getName()); 82 83 } 84 85 89 private static Context getInitialContext() throws NamingException { 90 91 Hashtable <String , Object > env = new Hashtable <String , Object >(); 95 env.put(Context.INITIAL_CONTEXT_FACTORY, getInitialContextFactory()); 96 97 100 return new InitialContext (env); 101 } 102 103 108 private static String getInitialContextFactory() { 109 String prop = System.getProperty("easybeans.client.initial-context-factory"); 110 if (prop == null) { 112 prop = DEFAULT_INITIAL_CONTEXT_FACTORY; 113 } 114 return prop; 115 } 116 117 } 118 | Popular Tags |