01: /**
02: * Title: OpenUSS - Open Source University Support System
03: * Description: Utility for OpenUSS
04: * Copyright: Copyright (c) B. Lofi Dewanto
05: * Company: University of Muenster
06: * @author B. Lofi Dewanto
07: * @version 1.0
08: */package org.openuss.utility;
09:
10: import java.io.*;
11:
12: import java.rmi.RemoteException;
13:
14: import java.util.*;
15:
16: //import javax.ejb.*;
17:
18: import javax.naming.*;
19:
20: import javax.rmi.*;
21:
22: //import javax.transaction.UserTransaction;
23:
24: /**
25: * Factory for all home interfaces use in OpenUSS.
26: *
27: * @author B. Lofi Dewanto
28: * @version 1.0
29: */
30: public class HomeInterfaceFactory {
31: // Context
32: private static Context initialContext = null;
33:
34: /**
35: * Get the home interface.
36: */
37: public static Object create(Class homeClass, String homeName) {
38: // Get JNDI initial context
39: // System.out.println("Getting an initial context from JNDI");
40: // Check the initial context first
41: if (initialContext == null) {
42: // No initial context, create
43: try {
44: initialContext = new InitialContext();
45: } catch (Exception e) {
46: System.out
47: .println("Error getting initial context from JNDI: "
48: + e.toString());
49: }
50: }
51:
52: // Connecting to Home thru JNDI
53: // System.out.println("Connecting to the " + homeName);
54: Object home = null;
55:
56: try {
57: home = PortableRemoteObject.narrow(initialContext
58: .lookup(homeName), homeClass);
59: } catch (Exception e) {
60: System.out.println("Error getting home object: "
61: + e.toString());
62: }
63:
64: // give the home back
65: return home;
66: }
67: }
|