KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
28 import java.rmi.RemoteException JavaDoc;
29 import javax.ejb.EJBObject JavaDoc;
30 import javax.ejb.Handle 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 EJBObject 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 HandleImplIIOP implements Handle JavaDoc, Serializable JavaDoc
46 {
47    /** @since 4.0.0 */
48    static final long serialVersionUID = -501170775289648475L;
49
50    /**
51     * This handle encapsulates an stringfied CORBA reference for an
52     * <code>EJBObject</code>.
53     */

54    private String JavaDoc ior;
55    
56    /**
57     * Constructs an <code>HandleImplIIOP</code>.
58     *
59     * @param ior An stringfied CORBA reference for an <code>EJBObject</code>.
60     */

61    public HandleImplIIOP(String JavaDoc ior)
62    {
63       this.ior = ior;
64    }
65    
66    /**
67     * Constructs an <tt>HandleImplIIOP</tt>.
68     *
69     * @param obj An <code>EJBObject</code>.
70     */

71    public HandleImplIIOP(EJBObject JavaDoc obj)
72    {
73       this((org.omg.CORBA.Object JavaDoc)obj);
74    }
75    
76    /**
77     * Constructs an <tt>HandleImplIIOP</tt>.
78     *
79     * @param obj A CORBA reference for an <code>EJBObject</code>.
80     */

81    public HandleImplIIOP(org.omg.CORBA.Object JavaDoc obj)
82    {
83       this.ior = CorbaORB.getInstance().object_to_string(obj);
84    }
85    
86    // Public --------------------------------------------------------
87

88    // Handle implementation -----------------------------------------
89

90    /**
91     * Obtains the <code>EJBObject</code> represented by this handle.
92     *
93     * @return a reference to an <code>EJBObject</code>.
94     *
95     * @throws RemoteException
96     */

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