KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > server > EJBUtils


1 package sellwin.server;
2
3
4 import java.util.*;
5 import java.rmi.*;
6
7 import javax.ejb.*;
8 import javax.naming.*;
9 import javax.rmi.PortableRemoteObject JavaDoc;
10
11 // SellWin http://sourceforge.net/projects/sellwincrm
12
//Contact support@open-app.com for commercial help with SellWin
13
//This software is provided "AS IS", without a warranty of any kind.
14

15 /**
16  * This class offers some routines that help establish
17  * an EJB client-server connection. These routines
18  * are used by the GUI when logging into the sellwin
19  * server and also for the sync process.
20  */

21 public class EJBUtils {
22     public final static String JavaDoc JNDI_NAME="SellwinSessionHome";
23     public final static String JavaDoc WEBLOGIC_URL="t3://localhost:7001";
24     /**
25     * Using a Properties object will work on JDK 1.1.x and Java2
26     * clients
27     */

28     public static Context getInitialContext() throws NamingException {
29
30         try {
31             // Get an InitialContext
32
Properties h = new Properties();
33             h.put(Context.INITIAL_CONTEXT_FACTORY,
34                 "weblogic.jndi.WLInitialContextFactory");
35             h.put(Context.PROVIDER_URL, WEBLOGIC_URL);
36             return new InitialContext(h);
37         } catch (NamingException ne) {
38             System.out.println("We were unable to get a connection to the WebLogic server at "+WEBLOGIC_URL);
39             System.out.println("Please make sure that the server is running.");
40             throw ne;
41         }
42     }
43
44     /**
45      * RMI/IIOP clients should use this narrow function
46      */

47     public static Object JavaDoc narrow(Object JavaDoc ref, Class JavaDoc c) {
48         return PortableRemoteObject.narrow(ref, c);
49     }
50
51     public static SellwinSession ejbConnect()
52         throws NamingException, CreateException, RemoteException {
53
54         String JavaDoc JNDI_NAME = "SellwinSessionHome";
55
56         Context ctx = getInitialContext();
57
58         Object JavaDoc home = ctx.lookup(JNDI_NAME);
59         SellwinSessionHome sellwinHome = (SellwinSessionHome)narrow(home, SellwinSessionHome.class);
60         System.out.println("found sellwin session home in jndi");
61
62         SellwinSession sellwin = (SellwinSession)narrow(sellwinHome.create(), SellwinSession.class);
63         System.out.println("created SellwinSession remote reference");
64         return sellwin;
65
66     }
67
68 }
69
Popular Tags