001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.proxy.ejb;
023:
024: import java.io.IOException;
025: import java.io.ObjectInputStream;
026: import java.io.ObjectOutputStream;
027: import java.io.Serializable;
028: import java.rmi.RemoteException;
029: import javax.ejb.EJBObject;
030: import javax.ejb.Handle;
031: import javax.ejb.spi.HandleDelegate;
032: import javax.rmi.PortableRemoteObject;
033:
034: import org.jboss.iiop.CorbaORB;
035: import org.jboss.proxy.ejb.handle.HandleDelegateImpl;
036:
037: /**
038: * A CORBA-based EJBObject handle implementation.
039: *
040: * @author <a href="mailto:rickard.oberg@telkel.com">Rickard Öberg</a>.
041: * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
042: * @author <a href="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
043: * @version $Revision: 57194 $
044: */
045: public class HandleImplIIOP implements Handle, Serializable {
046: /** @since 4.0.0 */
047: static final long serialVersionUID = -501170775289648475L;
048:
049: /**
050: * This handle encapsulates an stringfied CORBA reference for an
051: * <code>EJBObject</code>.
052: */
053: private String ior;
054:
055: /**
056: * Constructs an <code>HandleImplIIOP</code>.
057: *
058: * @param ior An stringfied CORBA reference for an <code>EJBObject</code>.
059: */
060: public HandleImplIIOP(String ior) {
061: this .ior = ior;
062: }
063:
064: /**
065: * Constructs an <tt>HandleImplIIOP</tt>.
066: *
067: * @param obj An <code>EJBObject</code>.
068: */
069: public HandleImplIIOP(EJBObject obj) {
070: this ((org.omg.CORBA.Object) obj);
071: }
072:
073: /**
074: * Constructs an <tt>HandleImplIIOP</tt>.
075: *
076: * @param obj A CORBA reference for an <code>EJBObject</code>.
077: */
078: public HandleImplIIOP(org.omg.CORBA.Object obj) {
079: this .ior = CorbaORB.getInstance().object_to_string(obj);
080: }
081:
082: // Public --------------------------------------------------------
083:
084: // Handle implementation -----------------------------------------
085:
086: /**
087: * Obtains the <code>EJBObject</code> represented by this handle.
088: *
089: * @return a reference to an <code>EJBObject</code>.
090: *
091: * @throws RemoteException
092: */
093: public EJBObject getEJBObject() throws RemoteException {
094: try {
095: return (EJBObject) PortableRemoteObject.narrow(CorbaORB
096: .getInstance().string_to_object(ior),
097: EJBObject.class);
098: } catch (Exception e) {
099: throw new RemoteException(
100: "Could not get EJBObject from Handle");
101: }
102: }
103:
104: private void writeObject(ObjectOutputStream oostream)
105: throws IOException {
106: HandleDelegate delegate = HandleDelegateImpl.getDelegate();
107: delegate.writeEJBObject(getEJBObject(), oostream);
108: }
109:
110: private void readObject(ObjectInputStream oistream)
111: throws IOException, ClassNotFoundException {
112: HandleDelegate delegate = HandleDelegateImpl.getDelegate();
113: EJBObject obj = delegate.readEJBObject(oistream);
114: this .ior = CorbaORB.getInstance().object_to_string(
115: (org.omg.CORBA.Object) obj);
116: }
117: }
|