XAMCFImpl.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): Eric HARDESTY
00022  * --------------------------------------------------------------------------
00023  * $Id: XAMCFImpl.java,v 1.5 2004/12/14 16:13:51 ehardesty Exp $
00024  * --------------------------------------------------------------------------
00025  */
00026 package org.objectweb.jonas.jdbc;
00027 
00028 
00029 import java.sql.SQLException;
00030 
00031 import javax.resource.ResourceException;
00032 import javax.resource.spi.ConnectionRequestInfo;
00033 import javax.resource.spi.ManagedConnection;
00034 import javax.resource.spi.ResourceAllocationException;
00035 import javax.resource.spi.security.PasswordCredential;
00036 import javax.security.auth.Subject;
00037 import javax.sql.XADataSource;
00038 
00039 public class XAMCFImpl
00040         extends ManagedConnectionFactoryImpl { 
00041 
00042     XADataSource ds = null;
00043 
00044     public ManagedConnection createManagedConnection(Subject subject, 
00045                                                       ConnectionRequestInfo cxReq)
00046               throws ResourceException {
00047                   
00048       PasswordCredential pc = Utility.getPasswordCredential(this, subject, cxReq, pw);
00049       if(ds == null) {
00050           try {
00051               ds = (XADataSource) Utility.getDataSource(this, pc, trace);
00052           } catch(Exception ex) {
00053               throw new ResourceException(ex.getMessage());
00054           }
00055       }
00056       javax.sql.XAConnection xaConnection = null;
00057       java.sql.Connection connection = null;
00058       try {
00059           if(cxReq != null) {
00060               ConnectionRequestInfoImpl cx = (ConnectionRequestInfoImpl) cxReq; 
00061               xaConnection = ds.getXAConnection(cx.getUser(), cx.getPassword());
00062           } else if (pc != null){
00063               xaConnection = ds.getXAConnection(pc.getUserName(), new String(pc.getPassword()));
00064           } else if (mcfData.getMCFData(MCFData.USER).length() > 0){
00065               xaConnection = ds.getXAConnection(mcfData.getMCFData(MCFData.USER), 
00066                                               mcfData.getMCFData(MCFData.PASSWORD));
00067           } else {
00068               xaConnection = ds.getXAConnection();
00069           }
00070           if (xaConnection != null) {
00071               connection = xaConnection.getConnection();
00072           }
00073       }
00074       catch(SQLException sqle)
00075       {
00076           throw new ResourceAllocationException("The connection could not be allocated: " + sqle.getMessage());
00077       }
00078       return new ManagedConnectionImpl(this, pc, connection, null, xaConnection, null);
00079     }
00080 
00081     /* Determine if the factories are equal
00082      */
00083     public boolean equals(Object obj) {
00084         if (obj instanceof XAMCFImpl) {
00085             return mcfData.equals(((XAMCFImpl)obj).mcfData);
00086         }
00087         else {
00088             return false;
00089         }
00090     }
00091 
00092     // JOnAS JDBC RA DataSource config properties
00093     public String getDatabaseName()
00094     {
00095         return mcfData.getMCFData(MCFData.DATABASENAME);
00096     }
00097 
00098     public void setDatabaseName(String val)
00099     {
00100         mcfData.setMCFData(MCFData.DATABASENAME, val);
00101     }
00102 
00103     public String getDescription()
00104     {
00105         return mcfData.getMCFData(MCFData.DESCRIPTION);
00106     }
00107 
00108     public void setDescription(String val)
00109     {
00110         mcfData.setMCFData(MCFData.DESCRIPTION, val);
00111     }
00112 
00113     public String getPortNumber()
00114     {
00115         return mcfData.getMCFData(MCFData.PORTNUMBER);
00116     }
00117 
00118     public void setPortNumber(String val)
00119     {
00120         mcfData.setMCFData(MCFData.PORTNUMBER, val);
00121     }
00122 
00123     public String getServerName()
00124     {
00125         return mcfData.getMCFData(MCFData.SERVERNAME);
00126     }
00127 
00128     public void setServerName(String val)
00129     {
00130         mcfData.setMCFData(MCFData.SERVERNAME, val);
00131     }
00132 
00133 }

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