KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > proxy > ejb > HomeHandleImplIIOP


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.proxy.ejb;
23
24 import java.io.IOException JavaDoc;
25 import java.io.ObjectInputStream JavaDoc;
26 import java.io.ObjectOutputStream JavaDoc;
27 import java.rmi.RemoteException JavaDoc;
28
29 import javax.ejb.EJBHome JavaDoc;
30 import javax.ejb.HomeHandle JavaDoc;
31 import javax.ejb.spi.HandleDelegate JavaDoc;
32 import javax.rmi.PortableRemoteObject JavaDoc;
33
34 import org.jboss.iiop.CorbaORB;
35 import org.jboss.proxy.ejb.handle.HandleDelegateImpl;
36
37 /**
38  * A CORBA-based EJB home handle implementation.
39  *
40  * @author <a HREF="mailto:rickard.oberg@telkel.com">Rickard ??berg</a>.
41  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
42  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
43  * @version $Revision: 37459 $
44  */

45 public class HomeHandleImplIIOP
46       implements HomeHandle JavaDoc
47 {
48    /**
49     * This handle encapsulates an stringfied CORBA reference for an
50     * <code>EJBHome</code>.
51     */

52    private String JavaDoc ior;
53    
54    /**
55     * Constructs a <code>HomeHandleImplIIOP</code>.
56     *
57     * @param ior An stringfied CORBA reference for an <code>EJBHome</code>.
58     */

59    public HomeHandleImplIIOP(String JavaDoc ior)
60    {
61       this.ior = ior;
62    }
63    
64    /**
65     * Constructs a <tt>HomeHandleImplIIOP</tt>.
66     *
67     * @param home An <code>EJBHome</code>.
68     */

69    public HomeHandleImplIIOP(EJBHome JavaDoc home)
70    {
71       this((org.omg.CORBA.Object JavaDoc)home);
72    }
73    
74    /**
75     * Constructs a <tt>HomeHandleImplIIOP</tt>.
76     *
77     * @param home A CORBA reference for an <code>EJBHome</code>.
78     */

79    public HomeHandleImplIIOP(org.omg.CORBA.Object JavaDoc home)
80    {
81       this.ior = CorbaORB.getInstance().object_to_string(home);
82    }
83    
84    // Public --------------------------------------------------------
85

86    // Handle implementation -----------------------------------------
87

88    /**
89     * Obtains the <code>EJBHome</code> represented by this home handle.
90     *
91     * @return a reference to an <code>EJBHome</code>.
92     *
93     * @throws RemoteException
94     */

95    public EJBHome JavaDoc getEJBHome()
96          throws RemoteException JavaDoc
97    {
98       try
99       {
100          return (EJBHome JavaDoc)PortableRemoteObject.narrow(
101                                   CorbaORB.getInstance().string_to_object(ior),
102                                   EJBHome JavaDoc.class);
103       }
104       catch (Exception JavaDoc e)
105       {
106          throw new RemoteException JavaDoc("Could not get EJBHome from HomeHandle");
107       }
108    }
109    
110
111    public void writeObject(ObjectOutputStream JavaDoc oostream) throws IOException JavaDoc
112    {
113       HandleDelegate JavaDoc delegate = HandleDelegateImpl.getDelegate();
114       delegate.writeEJBHome(getEJBHome(), oostream);
115    }
116
117    public void readObject(ObjectInputStream JavaDoc oistream) throws IOException JavaDoc, ClassNotFoundException JavaDoc
118    {
119       HandleDelegate JavaDoc delegate = HandleDelegateImpl.getDelegate();
120       EJBHome JavaDoc obj = delegate.readEJBHome(oistream);
121       this.ior = CorbaORB.getInstance().object_to_string((org.omg.CORBA.Object JavaDoc) obj);
122    }
123 }
124
Popular Tags