JacORBPRODelegate.java

00001 
00025 package org.objectweb.jonas_lib.naming;
00026 
00027 import java.rmi.Remote;
00028 import java.rmi.RemoteException;
00029 
00030 import javax.rmi.CORBA.Tie;
00031 import javax.rmi.CORBA.Util;
00032 
00033 import org.jacorb.poa.RequestProcessor;
00034 import org.omg.PortableServer.Servant;
00035 
00036 import org.objectweb.carol.jndi.spi.JacORBIIOPContext;
00037 
00038 import org.objectweb.jonas_ejb.container.JHome;
00039 import org.objectweb.jonas_ejb.container.JRemote;
00040 
00045 public class JacORBPRODelegate extends org.objectweb.carol.rmi.multi.JacORBPRODelegate {
00046 
00047 
00055     public void exportObject(Remote obj) throws RemoteException {
00056 
00057         // For JacORB, we need first to unexport object as it is not associated
00058         // to an ORB
00059         try {
00060             unexportObject(obj);
00061         } catch (Exception eee) {
00062             // Nothing
00063         }
00064 
00065         /* Now export it */
00066         try {
00067             super.exportObject(obj);
00068         } catch (Exception ee) {
00069             // Nothing
00070         }
00071 
00072 
00073         // Connect all EJB Home and Remote interfaces, and objectweb components (JOTM, JORAM, ...)
00074         if (obj instanceof JHome || obj instanceof JRemote || obj.getClass().getName().indexOf("org.objectweb") != -1) {
00075 
00076             Tie theTie = Util.getTie(obj);
00077 
00078             // Then connect it to the ORB
00079             if (theTie != null) {
00080                 theTie.orb(JacORBIIOPContext.getOrb());
00081             }
00082         }
00083 
00084 
00085 
00086     }
00087 
00096     public Object narrow(Object narrowFrom, Class narrowTo) throws ClassCastException {
00097         // Save old classloader
00098         ClassLoader old = Thread.currentThread().getContextClassLoader();
00099 
00100         try {
00101             // Try to get EJB classloader
00102             Thread currentThread = Thread.currentThread();
00103             if (currentThread != null && (currentThread instanceof RequestProcessor)) {
00104                 RequestProcessor rp = (RequestProcessor) currentThread;
00105                 if (rp != null) {
00106                     Servant servant = rp.getServant();
00107                     if (servant != null) {
00108                         Tie tie = null;
00109                         if (servant instanceof Tie) {
00110                             tie = (Tie) servant;
00111                             Remote target = tie.getTarget();
00112                             if (target instanceof JHome) {
00113                                 JHome jHome = (JHome) target;
00114                                 ClassLoader cll = jHome.getBf().myClassLoader();
00115                                 Thread.currentThread().setContextClassLoader(cll);
00116                             } else if (target instanceof JRemote) {
00117                                 JRemote jRemote = (JRemote) target;
00118                                 ClassLoader cll = jRemote.getBf().myClassLoader();
00119                                 Thread.currentThread().setContextClassLoader(cll);
00120                             }
00121                         }
00122                     }
00123                 }
00124             }
00125         } catch (Exception e) {
00126             // nothing
00127         } catch (Error e) {
00128             // nothing
00129         }
00130 
00131         // Call super method with right classloader
00132         Object narrowResult = null;
00133         try {
00134             narrowResult = super.narrow(narrowFrom, narrowTo);
00135         } finally {
00136             // reset to old classloader
00137             Thread.currentThread().setContextClassLoader(old);
00138         }
00139 
00140         return narrowResult;
00141     }
00142 
00143 }

Generated on Tue Feb 15 15:05:56 2005 for JOnAS by  doxygen 1.3.9.1