1 10 package fictional.resourceadapter; 11 12 import javax.naming.Reference; 13 import javax.naming.NamingException; 14 import javax.resource.ResourceException; 15 import javax.resource.NotSupportedException; 16 import javax.resource.spi.ConnectionManager; 17 import javax.resource.spi.ManagedConnectionFactory; 18 import javax.resource.spi.ConnectionRequestInfo; 19 import javax.resource.cci.ConnectionFactory; 21 import javax.resource.cci.Connection; 22 import javax.resource.cci.ConnectionSpec; import javax.resource.cci.RecordFactory; 24 import javax.resource.cci.ResourceAdapterMetaData; 25 import java.io.Serializable; 26 import javax.resource.Referenceable; 27 import org.objectweb.jonas.common.Log; 29 import org.objectweb.util.monolog.api.Logger; 30 import org.objectweb.util.monolog.api.BasicLevel; 31 37 public class CommonClient 38 implements 39 ConnectionFactory, 40 ConnectionSpec, ResourceAdapterMetaData, 42 Referenceable, 43 Serializable 44 45 { 46 Reference reference; 47 private ConnectionManager cm; 48 private ManagedConnectionFactory mcf; private CommonClient cs; protected boolean managed = true; 51 private Logger logger = null; 52 private String userName = ""; 53 private String passWord = ""; 54 String cName = ""; 55 56 public CommonClient() { 57 if (logger == null) { 58 logger = Log.getLogger("fictional.resourceadapter"); 59 } 60 } 61 public void setUserName(String u) { 67 userName=u; 68 cName = "ConnectionSpec"; 69 logger.log(BasicLevel.DEBUG, cName+".setUserName="+u); 70 } 71 public void setPassword(String p) { 72 passWord=p; 73 cName = "ConnectionSpec"; 74 logger.log(BasicLevel.DEBUG, cName+".setPassword="+p); 75 } 76 public String getUserName() { 77 cName = "ConnectionSpec"; 78 logger.log(BasicLevel.DEBUG, cName+".getUserName="+userName); 79 return userName; 80 } 81 public String getPassword() { 82 cName = "ConnectionSpec"; 83 logger.log(BasicLevel.DEBUG, cName+".getPassword="+passWord); 84 return passWord; 85 } 86 public CommonClient(ManagedConnectionFactory mcf, ConnectionManager cm) { 98 if (logger == null) { 99 logger = Log.getLogger("fictional.resourceadapter"); 100 } 101 this.mcf=mcf; 102 this.cm=cm; 103 104 } 105 private String impl(Object obj) { 106 if (obj instanceof ConnectionFactory) { 107 return "ConnectionFactory"; 108 } else if (obj instanceof ConnectionSpec) { 109 return "ConnectionSpec"; 110 } else if (obj instanceof ResourceAdapterMetaData) { 111 return "ResourceAdapterMetaData"; 112 } else 113 return "CommonClient. Is this an error"; 114 115 } 116 public Connection getConnection() 124 throws ResourceException 125 { 126 cName = "ConnectionFactory"; 127 logger.log(BasicLevel.DEBUG, cName+".getConnection"+" (Container Managed Sign-on)"); 128 Connection conn = null; 129 try { 130 conn = (Connection)getConnection(null); 131 return conn; 132 } catch (ResourceException ex) { 133 throw ex; 134 } 135 } 136 public Connection getConnection(ConnectionSpec connectionspec) 144 throws ResourceException 145 { 146 cName = "ConnectionFactory"; 147 JtestResourceAdapter jmcf = (JtestResourceAdapter)mcf; Connection conn = null; 149 CommonClient cs; JtestResourceAdapter jcri=null; 152 if (connectionspec==null) { 153 jmcf.setRes_Auth("Container"); 154 logger.log(BasicLevel.DEBUG, cName+".getConnection detected res-auth='"+jmcf.getRes_Auth()+"'"); 155 } else { 158 jmcf.setRes_Auth("Application"); 159 logger.log(BasicLevel.DEBUG, cName+".getConnection detected res-auth='"+jmcf.getRes_Auth()+"'"); 160 cs = (CommonClient)connectionspec; 161 jcri = new JtestResourceAdapter(); jcri.setUserName(cs.getUserName()); 164 jcri.setPassword(cs.getPassword()); 165 166 } 167 logger.log(BasicLevel.DEBUG, cName+".getConnection calling cm.allocateConnection"); 168 try { 169 ConnectionRequestInfo cri = (ConnectionRequestInfo) jcri; 170 conn = (Connection)cm.allocateConnection(mcf, cri); 171 if (conn==null) { 172 logger.log(BasicLevel.DEBUG, cName+". getConnection, cm.allocateConnection" 173 +" error: Null connection object returned"); 174 throw new ResourceException("Null connection object returned by allocateConnection"); 175 } 176 return conn; 177 } catch (IllegalStateException is) { 178 logger.log(BasicLevel.DEBUG, cName+".getConnection IllegalStateException"+is); 179 throw is; 180 } catch (ResourceException re) { 181 logger.log(BasicLevel.DEBUG, cName+".getConnection ResourceException="+re); 182 throw re; 183 } 184 } 185 186 public RecordFactory getRecordFactory() 187 throws ResourceException 188 { 189 cName = "ConnectionFactory"; 190 logger.log(BasicLevel.DEBUG, cName+".getRecordFactory"); 191 NotSupportedException nse = new NotSupportedException( 192 "RecordFactory is not currently supported"); 193 throw nse; 194 } 195 196 public ResourceAdapterMetaData getMetaData() 197 throws ResourceException 198 { 199 cName = "ConnectionFactory"; 200 logger.log(BasicLevel.DEBUG, cName+".getMetaData"); 201 ResourceAdapterMetaData rd = null; return rd; 203 } 204 public ManagedConnectionFactory getMcf() { 205 ManagedConnectionFactory MCF = (ManagedConnectionFactory)mcf; 206 return MCF; 207 } 208 216 public void setReference(javax.naming.Reference ref) 217 { 218 this.reference = ref; 219 } 220 221 224 public Reference getReference() 225 throws NamingException 226 { 227 return reference; 228 } 229 public String getAdapterVersion() { 235 return "1.0"; 236 } 237 public String getAdapterVendorName() { 238 return "Bull"; 239 } 240 public String getAdapterName() { 241 return "JOnAS Test Resource Adapter"; 242 } 243 public String getAdapterShortDescription() { 244 return "Test JOnAS Application Server compliance to J2EE Java Community Process (JSR112)"; 245 } 246 public String getSpecVersion() { 247 return "J2EE Java Community Process (JSR112)"; 248 } 249 public String[] getInteractionSpecsSupported() { 250 String[]s = {"JSR016","JSR112"}; 251 return s; 252 } 253 public boolean supportsExecuteWithInputAndOutputRecord() { 254 return true; 255 } 256 public boolean supportsExecuteWithInputRecordOnly() { 257 return true; 258 } 259 public boolean supportsLocalTransactionDemarcation() { 260 return false; 261 } 262 } 263 | Popular Tags |