1 23 package com.sun.enterprise.iiop; 24 25 import java.rmi.Remote ; 26 import java.rmi.RemoteException ; 27 import java.net.URL ; 28 import java.util.*; 29 import java.io.File ; 30 31 import javax.rmi.PortableRemoteObject ; 32 import javax.rmi.CORBA.*; 33 import javax.transaction.*; 34 import javax.ejb.EJBException ; 35 import javax.ejb.NoSuchObjectLocalException ; 36 import javax.ejb.TransactionRolledbackLocalException ; 37 import javax.ejb.TransactionRequiredLocalException ; 38 import javax.ejb.ConcurrentAccessException ; 39 import javax.naming.*; 40 41 import org.omg.CORBA.*; 42 43 import com.sun.enterprise.*; 44 import com.sun.enterprise.deployment.*; 45 import com.sun.enterprise.util.*; 46 import com.sun.enterprise.log.Log; 47 import com.sun.enterprise.server.*; 48 import com.sun.ejb.*; 49 import com.sun.ejb.containers.InternalEJBContainerException; 50 import com.sun.ejb.containers.ParallelAccessException; 51 52 import com.sun.enterprise.security.SecurityContext; 53 54 import org.omg.CosNaming.NamingContext ; 55 56 import com.sun.corba.ee.spi.oa.rfm.ReferenceFactoryManager ; 57 import com.sun.corba.ee.spi.presentation.rmi.PresentationManager; 58 import com.sun.corba.ee.spi.presentation.rmi.DynamicStub; 59 import com.sun.corba.ee.spi.presentation.rmi.StubAdapter; 60 import com.sun.corba.ee.spi.extension.ServantCachingPolicy; 61 import com.sun.corba.ee.spi.ior.*; 62 63 import com.sun.corba.ee.impl.naming.cosnaming.TransientNameService; 64 import com.sun.corba.ee.impl.orbutil.ORBConstants; 65 66 import java.util.logging.*; 67 import com.sun.logging.*; 68 69 70 78 79 public final class POAProtocolMgr extends org.omg.CORBA.LocalObject 80 implements ProtocolManager 81 { 82 private static Logger _logger=null; 83 static{ 84 _logger=LogDomains.getLogger(LogDomains.CORBA_LOGGER); 85 } 86 private static final int MAPEXCEPTION_CODE = 9998; 87 private static final String InitialObjectsDb = "initial.db"; 88 89 private static final String ORG_OMG_STUB_PREFIX = "org.omg.stub."; 90 91 private ORB orb; 92 private Switch theSwitch; 93 private ContainerFactory containerFactory; 94 private PresentationManager presentationMgr; 95 96 public POAProtocolMgr(ORB o) 97 { 98 this.orb = (ORB)o; 99 100 theSwitch = Switch.getSwitch(); 101 containerFactory = theSwitch.getContainerFactory(); 102 this.presentationMgr = 103 ((com.sun.corba.ee.spi.orb.ORB) orb).getPresentationManager(); 104 } 105 106 107 public void initializePOAs() 109 throws Exception 110 { 111 ReferenceFactoryManager rfm = 113 (ReferenceFactoryManager)orb.resolve_initial_references( 114 ORBConstants.REFERENCE_FACTORY_MANAGER ) ; 115 rfm.activate() ; 116 _logger.log(Level.FINE, "POAProtocolMgr.initializePOAs: RFM resolved and activated"); 117 } 118 119 120 public ORB getORB() 121 { 122 return orb; 123 } 124 125 private ContainerFactory getContainerFactory() 126 { 127 if ( containerFactory == null ) 128 containerFactory = theSwitch.getContainerFactory(); 129 return containerFactory; 130 } 131 132 public void initializeNaming(File dbDir, int orbInitialPort) throws Exception 134 { 135 TransientNameService nameService = new 137 TransientNameService((com.sun.corba.ee.spi.orb.ORB)orb); 138 _logger.log(Level.FINE, "POAProtocolMgr.initializeNaming: complete"); 139 } 140 141 142 146 public RemoteReferenceFactory getRemoteReferenceFactory 147 (Container container, boolean remoteHomeView, String id) 148 { 149 RemoteReferenceFactory factory = new POARemoteReferenceFactory 150 (container, this, orb, remoteHomeView, id); 151 152 return factory; 154 } 155 156 159 public void connectObject(Remote remoteObj) 160 throws RemoteException 161 { 162 StubAdapter.connect 163 (remoteObj, (com.sun.corba.ee.spi.orb.ORB)ORBManager.getORB()); 164 } 165 166 170 public boolean isIdentical(Remote obj1, Remote obj2) 171 { 172 org.omg.CORBA.Object corbaObj1 = (org.omg.CORBA.Object )obj1; 173 org.omg.CORBA.Object corbaObj2 = (org.omg.CORBA.Object )obj2; 174 175 return corbaObj1._is_equivalent(corbaObj2); 176 } 177 178 public void validateTargetObjectInterfaces(Remote targetObj) { 179 180 if( targetObj != null ) { 181 Tie tie = presentationMgr.getTie(); 185 tie.setTarget(targetObj); 186 } else { 187 throw new IllegalArgumentException 188 ("null passed to validateTargetObjectInterfaces"); 189 } 190 191 } 192 193 194 197 public Throwable mapException(Throwable exception) { 198 199 boolean mapped = true; 200 Throwable mappedException = null; 201 202 if ( exception instanceof java.rmi.NoSuchObjectException 203 || exception instanceof NoSuchObjectLocalException ) 204 { 205 mappedException = new OBJECT_NOT_EXIST(MAPEXCEPTION_CODE, 206 CompletionStatus.COMPLETED_MAYBE); 207 } else if ( exception instanceof java.rmi.AccessException 208 || exception instanceof javax.ejb.AccessLocalException ) 209 { 210 mappedException = new NO_PERMISSION(MAPEXCEPTION_CODE, 211 CompletionStatus.COMPLETED_MAYBE); 212 } else if ( exception instanceof java.rmi.MarshalException ) { 213 mappedException = new MARSHAL(MAPEXCEPTION_CODE, 214 CompletionStatus.COMPLETED_MAYBE); 215 } else if ( exception instanceof javax.transaction.TransactionRolledbackException 216 || exception instanceof TransactionRolledbackLocalException ) 217 { 218 mappedException = new TRANSACTION_ROLLEDBACK(MAPEXCEPTION_CODE, 219 CompletionStatus.COMPLETED_MAYBE); 220 } else if ( exception instanceof javax.transaction.TransactionRequiredException 221 || exception instanceof TransactionRequiredLocalException ) 222 { 223 mappedException = new TRANSACTION_REQUIRED(MAPEXCEPTION_CODE, 224 CompletionStatus.COMPLETED_MAYBE); 225 } else if ( exception instanceof javax.transaction.InvalidTransactionException ) { 226 mappedException = new INVALID_TRANSACTION(MAPEXCEPTION_CODE, 227 CompletionStatus.COMPLETED_MAYBE); 228 } else if (exception instanceof ConcurrentAccessException ) { 229 ConcurrentAccessException ex = (ConcurrentAccessException ) exception; 230 exception = new ParallelAccessException(ex.getMessage(), ex); 231 mapped = false; 232 } else if ( exception instanceof EJBException ) { 233 EJBException ex = (EJBException ) exception; 234 exception = new RemoteException (ex.getMessage(), 235 ex.getCausedByException()); 236 mapped = false; 237 } else { 238 mapped = false; 239 } 240 241 return (mapped) 242 ? mappedException.initCause(exception) 243 : exception; 244 } 245 246 247 250 public EjbDescriptor getEjbDescriptor(byte[] ejbKey) 251 { 252 EjbDescriptor result = null; 253 try { 254 if(_logger.isLoggable(Level.FINE)) { 255 _logger.log(Level.FINE, "POAProtocolMgr.getEjbDescriptor->: " 256 + ejbKey); 257 } 258 259 if ( ejbKey.length < POARemoteReferenceFactory.EJBID_OFFSET + 8 ) { 260 if(_logger.isLoggable(Level.FINE)) { 261 _logger.log(Level.FINE, "POAProtocolMgr.getEjbDescriptor: " 262 + ejbKey 263 + ": " + ejbKey.length + " < " 264 + POARemoteReferenceFactory.EJBID_OFFSET + 8); 265 } 266 return null; 267 } 268 269 long ejbId = 270 Utility.bytesToLong(ejbKey, 271 POARemoteReferenceFactory.EJBID_OFFSET); 272 273 if(_logger.isLoggable(Level.FINE)) { 274 _logger.log(Level.FINE, "POAProtocolMgr.getEjbDescriptor: " 275 + ejbKey + ": ejbId: " + ejbId); 276 } 277 278 if ( getContainerFactory() != null ) { 279 result = containerFactory.getEjbDescriptor(ejbId); 280 } else { 281 if(_logger.isLoggable(Level.FINE)) { 282 _logger.log(Level.FINE, "POAProtocolMgr.getEjbDescriptor: " 283 + ejbKey + ": no container factory"); 284 } 285 } 286 287 return result; 288 } finally { 289 if(_logger.isLoggable(Level.FINE)) { 290 _logger.log(Level.FINE, "POAProtocolMgr.getEjbDescriptor<-: " 291 + ejbKey + ": " + result); 292 } 293 } 294 } 295 } 296 | Popular Tags |