KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openuss > utility > HomeInterfaceFactory


1 /**
2  * Title: OpenUSS - Open Source University Support System
3  * Description: Utility for OpenUSS
4  * Copyright: Copyright (c) B. Lofi Dewanto
5  * Company: University of Muenster
6  * @author B. Lofi Dewanto
7  * @version 1.0
8  */

9 package org.openuss.utility;
10
11 import java.io.*;
12
13 import java.rmi.RemoteException JavaDoc;
14
15 import java.util.*;
16
17 //import javax.ejb.*;
18

19 import javax.naming.*;
20
21 import javax.rmi.*;
22
23 //import javax.transaction.UserTransaction;
24

25
26 /**
27  * Factory for all home interfaces use in OpenUSS.
28  *
29  * @author B. Lofi Dewanto
30  * @version 1.0
31  */

32 public class HomeInterfaceFactory {
33     // Context
34
private static Context initialContext = null;
35
36     /**
37      * Get the home interface.
38      */

39     public static Object JavaDoc create(Class JavaDoc homeClass, String JavaDoc homeName) {
40         // Get JNDI initial context
41
// System.out.println("Getting an initial context from JNDI");
42
// Check the initial context first
43
if (initialContext == null) {
44             // No initial context, create
45
try {
46                 initialContext = new InitialContext();
47             } catch (Exception JavaDoc e) {
48                 System.out.println("Error getting initial context from JNDI: " +
49                                    e.toString());
50             }
51         }
52
53         // Connecting to Home thru JNDI
54
// System.out.println("Connecting to the " + homeName);
55
Object JavaDoc home = null;
56
57         try {
58             home = PortableRemoteObject.narrow(initialContext.lookup(homeName),
59                                                homeClass);
60         } catch (Exception JavaDoc e) {
61             System.out.println("Error getting home object: " + e.toString());
62         }
63
64         // give the home back
65
return home;
66     }
67 }
Popular Tags