1 25 26 package org.objectweb.easybeans.examples.statelessbean; 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 ClientStateless { 39 40 43 private static final String DEFAULT_INITIAL_CONTEXT_FACTORY = "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory"; 44 45 48 private ClientStateless() { 49 50 } 51 52 57 public static void main(final String [] args) throws Exception { 58 59 Context initialContext = getInitialContext(); 60 61 StatelessRemote statelessBean = (StatelessRemote) initialContext 62 .lookup("org.objectweb.easybeans.examples.statelessbean.StatelessBean" 63 + "_" + StatelessRemote.class.getName() + "@Remote"); 64 65 System.out.println("Calling helloWorld method..."); 66 statelessBean.helloWorld(); 67 68 System.out.println("Add 1 + 2..."); 69 int resultAdd = statelessBean.add(1, 2); 70 System.out.println("Sum = '" + resultAdd + "'."); 71 72 75 } 76 77 81 private static Context getInitialContext() throws NamingException { 82 83 Hashtable <String , Object > env = new Hashtable <String , Object >(); 87 env.put(Context.INITIAL_CONTEXT_FACTORY, getInitialContextFactory()); 88 89 92 return new InitialContext (env); 93 } 94 95 100 private static String getInitialContextFactory() { 101 String prop = System.getProperty("easybeans.client.initial-context-factory"); 102 if (prop == null) { 104 prop = DEFAULT_INITIAL_CONTEXT_FACTORY; 105 } 106 return prop; 107 } 108 109 110 } 111 | Popular Tags |