01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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 6673 2005-04-28 16:53:00Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.objectweb.jonas_ejb.container;
25:
26: import java.io.Serializable;
27: import java.rmi.RemoteException;
28:
29: import javax.ejb.EJBHome;
30: import javax.ejb.HomeHandle;
31: import javax.naming.Context;
32: import javax.naming.InitialContext;
33: import javax.naming.NamingException;
34: import javax.rmi.PortableRemoteObject;
35:
36: import org.objectweb.util.monolog.api.BasicLevel;
37:
38: /**
39: * This class implements javax.ejb.HomeHandle interface. A handle is an
40: * abstraction of a network reference to a home object. A handle is intended to
41: * be used as a "robust" persistent reference to a home object.
42: * @author Philippe Durieux, Philippe Coq
43: */
44: public class JHomeHandle implements HomeHandle, Serializable {
45:
46: /**
47: * Name of the home
48: */
49: private String homename = null;
50:
51: /**
52: * EjbHome class
53: */
54: private EJBHome ejbHome = null;
55:
56: /**
57: * constructor
58: * @param hname JNDI name of the Home
59: */
60: public JHomeHandle(String hname) {
61: homename = hname;
62: }
63:
64: // -----------------------------------------------------------------------
65: // HomeHandle implementation
66: // -----------------------------------------------------------------------
67:
68: /**
69: * Obtains the home object represented by this handle.
70: * @throws RemoteException The home object could not be obtained because of
71: * a system-level failure.
72: * @return The EJBHome object
73: */
74: public EJBHome getEJBHome() throws RemoteException {
75: if (TraceEjb.isDebugIc()) {
76: TraceEjb.interp.log(BasicLevel.DEBUG, homename);
77: }
78: Context ic = null;
79: if (ejbHome == null) {
80: try {
81: ic = new InitialContext();
82: Object o = ic.lookup(homename);
83: ejbHome = (EJBHome) PortableRemoteObject.narrow(o,
84: EJBHome.class);
85: } catch (NamingException e) {
86: throw new RemoteException("getEJBHome", e);
87: }
88: }
89: return ejbHome;
90: }
91: }
|