001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JHandleIIOP.java 6072 2005-01-12 14:40:21Z pelletib $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.svc;
025:
026: import java.io.IOException;
027: import java.io.Serializable;
028: import java.rmi.Remote;
029: import java.rmi.RemoteException;
030: import java.util.logging.Level;
031: import java.util.logging.Logger;
032:
033: import javax.ejb.EJBObject;
034: import javax.ejb.Handle;
035: import javax.ejb.spi.HandleDelegate;
036: import javax.naming.NamingException;
037: import javax.rmi.PortableRemoteObject;
038: import javax.rmi.CORBA.Util;
039:
040: import org.omg.PortableServer.Servant;
041:
042: /**
043: * This class implements javax.ejb.Handle interface.
044: * @author Philippe Coq
045: */
046: public class JHandleIIOP implements Handle, Serializable {
047:
048: /**
049: * JDK logger to be portable
050: */
051: private static Logger logger = Logger
052: .getLogger("org.objectweb.jonas_ejb.svc");
053:
054: /**
055: * CORBA ref
056: * @serial
057: */
058: private String ior = null;
059:
060: /**
061: * constructor
062: * @param r remote ref
063: */
064: public JHandleIIOP(Remote r) {
065: try {
066: logger.log(Level.FINE, "r=" + r);
067: Servant servant = (Servant) Util.getTie(r);
068: org.omg.CORBA.Object o = servant._this _object();
069: this .ior = Utility.getORB().object_to_string(o);
070: logger.log(Level.FINE, "ior=" + ior);
071: } catch (Exception e) {
072: logger.log(Level.SEVERE, "cannot get Handle: ", e);
073: }
074: }
075:
076: /**
077: * Obtains the EJB object represented by this handle.
078: * @return The EJB object
079: * @throws RemoteException The EJB object could not be obtained because of a
080: * system-level failure.
081: */
082: public EJBObject getEJBObject() throws RemoteException {
083: logger.log(Level.FINE, "");
084: try {
085: return (EJBObject) PortableRemoteObject.narrow(Utility
086: .getORB().string_to_object(ior), EJBObject.class);
087: } catch (Exception e) {
088: throw new RemoteException("JHandle.getEJBObject(): " + e, e);
089: }
090: }
091:
092: /**
093: * Specific implementation of serialization.
094: * Must call HandleDelegate.writeEJBObject, as specified in 19.5.5.1 of spec EJB 2.1
095: * @param out The output stream used to write object
096: * @throws IOException error when writing object.
097: */
098: private void writeObject(java.io.ObjectOutputStream out)
099: throws IOException {
100: HandleDelegate hdld;
101: logger.log(Level.FINE, "");
102: try {
103: hdld = Utility.getHandleDelegate();
104: } catch (NamingException e) {
105: throw new IOException("Cannot get HandleDelegate");
106: }
107: hdld.writeEJBObject(getEJBObject(), out);
108: }
109:
110: /**
111: * Specific implementation of deserialization.
112: * Must call HandleDelegate.readEJBObject, as specified in 19.5.5.1 of spec EJB 2.1
113: * @param in The input Stream from where is read the object.
114: * @throws IOException error when reading object.
115: * @throws ClassNotFoundException -
116: */
117: private void readObject(java.io.ObjectInputStream in)
118: throws IOException, ClassNotFoundException {
119: HandleDelegate hdld;
120: logger.log(Level.FINE, "");
121: try {
122: hdld = Utility.getHandleDelegate();
123: } catch (NamingException e) {
124: throw new IOException("Cannot get HandleDelegate");
125: }
126: EJBObject obj = hdld.readEJBObject(in);
127: try {
128: this .ior = Utility.getORB().object_to_string(
129: (org.omg.CORBA.Object) obj);
130:
131: } catch (Exception e) {
132: throw new RemoteException("JHandle.readObject(): " + e, e);
133: }
134: }
135:
136: }
|