1 4 package org.objectweb.jonas.jtests.beans.j2eeca; 5 6 import javax.ejb.CreateException ; 7 import javax.ejb.SessionBean ; 8 import javax.ejb.SessionContext ; 9 import javax.naming.InitialContext ; 10 import javax.resource.cci.ConnectionMetaData ; 11 import javax.resource.spi.ConnectionEvent ; 12 13 import org.objectweb.jonas.common.Log; 14 import org.objectweb.util.monolog.api.BasicLevel; 15 import org.objectweb.util.monolog.api.Logger; 16 17 import fictional.resourceadapter.CommonClient; 18 import fictional.resourceadapter.ConnectionImpl; 19 import fictional.resourceadapter.JtestInteraction; 20 import fictional.resourceadapter.JtestResourceAdapter; 21 22 25 public class connectorCASLR implements SessionBean { 26 27 static private Logger logger = null; 28 SessionContext ejbContext; 29 private CommonClient cccf = null; private JtestResourceAdapter mcf = null; private CommonClient csp = null; private ConnectionImpl conn = null; 33 InitialContext ic=null; 34 JtestInteraction i = null; 35 ConnectionMetaData cMetaData = null; 36 String cName = "connectorCASLR"; 37 38 42 43 public void setSessionContext(SessionContext ctx) { 44 if (logger == null) { 45 logger = Log.getLogger("org.objectweb.jonas.jtests.j2eeca"); 46 } 47 logger.log(BasicLevel.DEBUG, cName+".setSessionContext"); 48 ejbContext = ctx; 49 } 50 51 52 public void ejbRemove() { 53 logger.log(BasicLevel.DEBUG, cName+".ejbRemove"); 54 } 55 56 57 public void ejbCreate() throws CreateException { 58 logger.log(BasicLevel.DEBUG, cName+".ejbCreate"); 59 } 60 61 public void ejbPassivate() { 62 logger.log(BasicLevel.DEBUG, cName+".ejbPassivate"); 63 } 64 65 public void ejbActivate() { 66 logger.log(BasicLevel.DEBUG, cName+".ejbActivate"); 67 } 68 69 75 public void method1(String rar_jndi_name, String testName) 76 throws Exception 77 { 78 logger.log(BasicLevel.DEBUG, "============================ "+testName); 79 try { 80 ic = new InitialContext (); 81 } catch (Exception e1) { 82 logger.log(BasicLevel.DEBUG, cName+".method1 error: InitialContext failed"); 83 throw e1; 84 } 85 try { 86 cccf = (CommonClient)ic.lookup(rar_jndi_name); 87 logger.log(BasicLevel.DEBUG, cName+".method1 : found "+rar_jndi_name); 88 } catch (Exception e2) { 89 logger.log(BasicLevel.DEBUG, cName+".method1 error: lookup failed for "+rar_jndi_name); 90 throw e2; 91 } 92 93 try { 94 csp = new CommonClient(); logger.log(BasicLevel.DEBUG, cName 96 +".method1 : ConnectionSpec o.k."); 97 98 } catch (Exception e3) { 99 logger.log(BasicLevel.DEBUG, cName+".method1 : new connection spec failed"); 100 throw e3; 101 } 102 try { 103 conn = (ConnectionImpl)cccf.getConnection(); 104 logger.log(BasicLevel.DEBUG, cName+".method1 : getConnection conn="+conn); 105 if (conn==null) { 106 logger.log(BasicLevel.DEBUG, cName+".method1 error: getConnection returned null connection."); 107 throw new Exception (""); 108 } 109 } catch (Exception e4) { 110 logger.log(BasicLevel.DEBUG, cName+".method1 error: getConnection failed " 111 +e4.toString()); 112 throw e4; 113 } 114 try { 115 i = (JtestInteraction)conn.createInteraction(); 116 } catch (Exception e5) { 117 logger.log(BasicLevel.DEBUG, cName+".method1 error: create interaction failed"); 118 throw e5; 119 } 120 try { 121 cMetaData = (ConnectionMetaData )conn.getMetaData(); 122 } catch (Exception e6) { 123 logger.log(BasicLevel.DEBUG, cName+".method1 : get ConnectionMetaData failed"); 124 throw e6; 125 } 126 127 } 128 129 132 public void closeUp(int w) { 133 try { 134 if (w>0) { 135 conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED); 138 logger.log(BasicLevel.DEBUG, cName+".closeUp : closed physical connection"); 139 } else { 140 conn.close(); 143 logger.log(BasicLevel.DEBUG, cName+".closeUp : closed connection"); 144 } 145 } catch (Exception e) { 146 logger.log(BasicLevel.DEBUG, cName+".closeUp error: close handle/physical connection failed"); 147 } 148 } 149 152 public boolean isConnectionSpec() { 153 if (csp==null) return false; 154 else return true; 155 } 156 public boolean isConnection() { 157 if (conn==null) return false; 158 else return true; 159 } 160 public boolean isInteraction() { 161 if (i==null) return false; 162 else return true; 163 } 164 public String getConnectionProduct() 165 throws Exception 166 { 167 String s; 168 try { 169 s = cMetaData.getEISProductName(); 170 logger.log(BasicLevel.DEBUG, cName+".getConnectionProduct : ConnectionMetaData.product="+s); 171 } catch (Exception e) { 172 logger.log(BasicLevel.DEBUG, cName+".getConnectionProduct error: ConnectionMetaData.getEISProductName() failed"); 173 throw e; 174 } 175 return s; 176 } 177 186 public String getServerName() 187 throws Exception 188 { 189 logger.log(BasicLevel.DEBUG, cName+".getServerName"); 190 mcf = (JtestResourceAdapter) cccf.getMcf(); String cp1 = "null"; 192 if (mcf==null) return cp1; 193 try { 194 cp1 = mcf.getServerName(); 195 } catch (Exception e) { 196 logger.log(BasicLevel.DEBUG, cName+".getConfigurationProperty error: failed"); 197 throw e; 198 } 199 return cp1; 200 } 201 public String getProtocolProperty() 202 throws Exception 203 { 204 logger.log(BasicLevel.DEBUG, cName+".getProtocolProperty"); 205 mcf = (JtestResourceAdapter) cccf.getMcf(); String p = "null"; 207 if (mcf==null) return p; 208 try { 209 p = mcf.getProtocol(); 210 } catch (Exception e) { 211 logger.log(BasicLevel.DEBUG, cName+".getProtocolProperty error: failed"); 212 throw e; 213 } 214 return p; 215 } 216 221 public boolean getCMInstance() 222 { 223 mcf = (JtestResourceAdapter) cccf.getMcf(); if (mcf.getCM()==null) { logger.log(BasicLevel.DEBUG, cName+".getCMInstance error: ConnectionManager is null"); 226 return false; 227 } 228 else { 229 logger.log(BasicLevel.DEBUG, cName+".getCMInstance ConnectionManager is o.k."); 230 return true; 231 } 232 } 233 public int getMCF_Pwriter() 234 { 235 int here=2; 236 mcf = (JtestResourceAdapter) cccf.getMcf(); try { 238 if (mcf.getLogWriter()==null) { logger.log(BasicLevel.DEBUG, cName+".getMCF_Pwriter No PrintWriter registered"); 240 here=0; 241 } 242 else { 243 logger.log(BasicLevel.DEBUG, cName+".getMCF_Pwriter PrintWriter is o.k."); 244 here=1; 245 } 246 } catch (Exception e) { 247 logger.log(BasicLevel.DEBUG, cName+ 248 ".getMCF_Pwriter error: "+e.toString()); 249 } 250 return here; 251 } 252 public int getMC_Pwriter() 253 { 254 int here=2; 255 ConnectionImpl conni = (ConnectionImpl)conn; 256 try { 257 JtestResourceAdapter mc = (JtestResourceAdapter)conni.getMC(); if (mc.getLogWriter()==null) { logger.log(BasicLevel.DEBUG, cName+ 260 ".getMC_Pwriter No PrintWriter registered in ManagedConnection"); 261 here=0; 262 } 263 else { 264 logger.log(BasicLevel.DEBUG, cName+ 265 ".getMC_Pwriter PrintWriter in ManagedConnection is o.k."); 266 here=1; 267 } 268 } catch (Exception e) { 269 logger.log(BasicLevel.DEBUG, cName+ 270 ".getMC_Pwriter error: "+e.toString()); 271 } 272 return here; 273 } 274 public void setMatchNull(boolean b) { 275 mcf = (JtestResourceAdapter) cccf.getMcf(); mcf.setMatchNull(b); 277 } 278 public int cntListeners() 279 { 280 int i = 0; 281 ConnectionImpl conni = (ConnectionImpl)conn; 282 try { 283 JtestResourceAdapter mc = (JtestResourceAdapter)conni.getMC(); i = mc.cntListeners(); 285 logger.log(BasicLevel.DEBUG, cName+".cntListeners cnt="+i); 286 } catch (Exception e) { 287 logger.log(BasicLevel.DEBUG, cName+".cntListeners error: failed to count Listeners"); 288 } 289 return i; 290 } 291 } 292 293 | Popular Tags |