1 4 package org.objectweb.jonas.jtests.beans.jca15; 5 6 import java.rmi.RemoteException ; 7 import javax.ejb.CreateException ; 8 import javax.ejb.EJBException ; 9 import javax.ejb.RemoveException ; 10 import javax.ejb.EJBObject ; 11 import javax.ejb.SessionBean ; 12 import javax.ejb.SessionContext ; 13 import javax.naming.Context ; 14 import javax.naming.InitialContext ; 15 import javax.naming.NamingException ; 16 import javax.resource.cci.Connection ; 17 import javax.resource.cci.ConnectionMetaData ; 18 import javax.resource.spi.ManagedConnection ; 19 import ersatz.resourceadapter.*; 20 import javax.resource.spi.ConnectionEvent ; 21 22 25 public class ConnectorCASLR implements SessionBean { 26 27 SessionContext ejbContext; 28 private ConnectionFactoryImpl cccf = null; private ManagedConnectionFactoryImpl mcf = null; private ConnectionSpecImpl csp = null; private ConnectionImpl conn = null; 32 InitialContext ic=null; 33 InteractionImpl i = null; 34 ConnectionMetaDataImpl cMetaData = null; 35 String cName = "ConnectorCASLR"; 36 37 41 42 public void setSessionContext(SessionContext ctx) { 43 Utility.log(cName+".setSessionContext"); 44 ejbContext = ctx; 45 } 46 47 48 public void ejbRemove() { 49 Utility.log(cName+".ejbRemove"); 50 } 51 52 53 public void ejbCreate() throws CreateException { 54 Utility.log(cName+".ejbCreate"); 55 } 56 57 public void ejbPassivate() { 58 Utility.log(cName+".ejbPassivate"); 59 } 60 61 public void ejbActivate() { 62 Utility.log(cName+".ejbActivate"); 63 } 64 65 71 public void method1(String rar_jndi_name, String testName) 72 throws Exception 73 { 74 Utility.log("============================ "+testName); 75 try { 76 ic = new InitialContext (); 77 } catch (Exception e1) { 78 Utility.log(cName+".method1 error: InitialContext failed"); 79 throw e1; 80 } 81 try { 82 cccf = (ConnectionFactoryImpl)ic.lookup(rar_jndi_name); 83 Utility.log(cName+".method1 : found "+rar_jndi_name); 84 } catch (Exception e2) { 85 Utility.log(cName+".method1 error: lookup failed for "+rar_jndi_name); 86 throw e2; 87 } 88 89 try { 90 csp = new ConnectionSpecImpl(); Utility.log(cName 92 +".method1 : ConnectionSpec o.k."); 93 94 } catch (Exception e3) { 95 Utility.log(cName+".method1 : new connection spec failed"); 96 throw e3; 97 } 98 try { 99 conn = (ConnectionImpl)cccf.getConnection(); 100 Utility.log(cName+".method1 : getConnection conn="+conn); 101 if (conn==null) { 102 Utility.log(cName+".method1 error: getConnection returned null connection."); 103 throw new Exception (""); 104 } 105 } catch (Exception e4) { 106 Utility.log(cName+".method1 error: getConnection failed " 107 +e4.toString()); 108 throw e4; 109 } 110 try { 111 i = (InteractionImpl)conn.createInteraction(); 112 } catch (Exception e5) { 113 Utility.log(cName+".method1 error: create interaction failed"); 114 throw e5; 115 } 116 try { 117 cMetaData = (ConnectionMetaDataImpl)conn.getMetaData(); 118 } catch (Exception e6) { 119 Utility.log(cName+".method1 : get ConnectionMetaData failed"); 120 throw e6; 121 } 122 123 } 124 125 128 public void closeUp(int w) { 129 try { 130 if (w>0) { 131 conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED); 134 Utility.log(cName+".closeUp : closed physical connection"); 135 } else { 136 conn.close(); 139 Utility.log(cName+".closeUp : closed connection"); 140 } 141 } catch (Exception e) { 142 Utility.log(cName+".closeUp error: close handle/physical connection failed"); 143 } 144 } 145 148 public boolean isConnectionSpec() { 149 if (csp==null) return false; 150 else return true; 151 } 152 public boolean isConnection() { 153 if (conn==null) return false; 154 else return true; 155 } 156 public boolean isInteraction() { 157 if (i==null) return false; 158 else return true; 159 } 160 public String getConnectionProduct() 161 throws Exception 162 { 163 String s; 164 try { 165 s = cMetaData.getEISProductName(); 166 Utility.log(cName+".getConnectionProduct : ConnectionMetaData.product="+s); 167 } catch (Exception e) { 168 Utility.log(cName+".getConnectionProduct error: ConnectionMetaData.getEISProductName() failed"); 169 throw e; 170 } 171 return s; 172 } 173 182 public String getServerName() 183 throws Exception 184 { 185 Utility.log(cName+".getServerName"); 186 mcf = (ManagedConnectionFactoryImpl) cccf.getMcf(); String cp1 = "null"; 188 if (mcf==null) return cp1; 189 try { 190 cp1 = mcf.getServerName(); 191 } catch (Exception e) { 192 Utility.log(cName+".getConfigurationProperty error: failed"); 193 throw e; 194 } 195 return cp1; 196 } 197 public String getProtocolProperty() 198 throws Exception 199 { 200 Utility.log(cName+".getProtocolProperty"); 201 mcf = (ManagedConnectionFactoryImpl) cccf.getMcf(); String p = "null"; 203 if (mcf==null) return p; 204 try { 205 p = mcf.getProtocol(); 206 } catch (Exception e) { 207 Utility.log(cName+".getProtocolProperty error: failed"); 208 throw e; 209 } 210 return p; 211 } 212 217 public boolean getCMInstance() 218 { 219 mcf = (ManagedConnectionFactoryImpl) cccf.getMcf(); if (mcf.getCM()==null) { Utility.log(cName+".getCMInstance error: ConnectionManager is null"); 222 return false; 223 } 224 else { 225 Utility.log(cName+".getCMInstance ConnectionManager is o.k."); 226 return true; 227 } 228 } 229 public int getMCF_Pwriter() 230 { 231 int here=2; 232 mcf = (ManagedConnectionFactoryImpl) cccf.getMcf(); try { 234 if (mcf.getLogWriter()==null) { Utility.log(cName+".getMCF_Pwriter No PrintWriter registered"); 236 here=0; 237 } 238 else { 239 Utility.log(cName+".getMCF_Pwriter PrintWriter is o.k."); 240 here=1; 241 } 242 } catch (Exception e) { 243 Utility.log(cName+ 244 ".getMCF_Pwriter error: "+e.toString()); 245 } 246 return here; 247 } 248 public int getMC_Pwriter() 249 { 250 int here=2; 251 ConnectionImpl conni = (ConnectionImpl)conn; 252 try { 253 ManagedConnectionImpl mc = (ManagedConnectionImpl)conni.getMC(); if (mc.getLogWriter()==null) { Utility.log(cName+ 256 ".getMC_Pwriter No PrintWriter registered in ManagedConnection"); 257 here=0; 258 } 259 else { 260 Utility.log(cName+ 261 ".getMC_Pwriter PrintWriter in ManagedConnection is o.k."); 262 here=1; 263 } 264 } catch (Exception e) { 265 Utility.log(cName+ 266 ".getMC_Pwriter error: "+e.toString()); 267 } 268 return here; 269 } 270 public void setMatchNull(boolean b) { 271 mcf = (ManagedConnectionFactoryImpl) cccf.getMcf(); mcf.setMatchNull(b); 273 } 274 public int cntListeners() 275 { 276 int i = 0; 277 ConnectionImpl conni = (ConnectionImpl)conn; 278 try { 279 ManagedConnectionImpl mc = (ManagedConnectionImpl)conni.getMC(); i = mc.cntListeners(); 281 Utility.log(cName+".cntListeners cnt="+i); 282 } catch (Exception e) { 283 Utility.log(cName+".cntListeners error: failed to count Listeners"); 284 } 285 return i; 286 } 287 } 288 289 | Popular Tags |