KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > container > JHomeHandle


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JHomeHandle.java,v 1.13 2005/04/28 16:52:59 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.container;
27
28 import java.io.Serializable JavaDoc;
29 import java.rmi.RemoteException JavaDoc;
30
31 import javax.ejb.EJBHome JavaDoc;
32 import javax.ejb.HomeHandle JavaDoc;
33 import javax.naming.Context JavaDoc;
34 import javax.naming.InitialContext JavaDoc;
35 import javax.naming.NamingException JavaDoc;
36 import javax.rmi.PortableRemoteObject JavaDoc;
37
38 import org.objectweb.util.monolog.api.BasicLevel;
39
40 /**
41  * This class implements javax.ejb.HomeHandle interface. A handle is an
42  * abstraction of a network reference to a home object. A handle is intended to
43  * be used as a "robust" persistent reference to a home object.
44  * @author Philippe Durieux, Philippe Coq
45  */

46 public class JHomeHandle implements HomeHandle JavaDoc, Serializable JavaDoc {
47
48     /**
49      * Name of the home
50      */

51     private String JavaDoc homename = null;
52
53     /**
54      * EjbHome class
55      */

56     private EJBHome JavaDoc ejbHome = null;
57
58     /**
59      * constructor
60      * @param hname JNDI name of the Home
61      */

62     public JHomeHandle(String JavaDoc hname) {
63         homename = hname;
64     }
65
66     // -----------------------------------------------------------------------
67
// HomeHandle implementation
68
// -----------------------------------------------------------------------
69

70     /**
71      * Obtains the home object represented by this handle.
72      * @throws RemoteException The home object could not be obtained because of
73      * a system-level failure.
74      * @return The EJBHome object
75      */

76     public EJBHome JavaDoc getEJBHome() throws RemoteException JavaDoc {
77         if (TraceEjb.isDebugIc()) {
78             TraceEjb.interp.log(BasicLevel.DEBUG, homename);
79         }
80         Context JavaDoc ic = null;
81         if (ejbHome == null) {
82             try {
83                 ic = new InitialContext JavaDoc();
84                 Object JavaDoc o = ic.lookup(homename);
85                 ejbHome = (EJBHome JavaDoc) PortableRemoteObject.narrow(o, EJBHome JavaDoc.class);
86             } catch (NamingException JavaDoc e) {
87                 throw new RemoteException JavaDoc("getEJBHome", e);
88             }
89         }
90         return ejbHome;
91     }
92 }
93
94
95
Popular Tags