KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jdbc > XAMCFImpl


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Eric HARDESTY
22  * --------------------------------------------------------------------------
23  * $Id: XAMCFImpl.java,v 1.5 2004/12/14 16:13:51 ehardesty Exp $
24  * --------------------------------------------------------------------------
25  */

26 package org.objectweb.jonas.jdbc;
27
28
29 import java.sql.SQLException JavaDoc;
30
31 import javax.resource.ResourceException JavaDoc;
32 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
33 import javax.resource.spi.ManagedConnection JavaDoc;
34 import javax.resource.spi.ResourceAllocationException JavaDoc;
35 import javax.resource.spi.security.PasswordCredential JavaDoc;
36 import javax.security.auth.Subject JavaDoc;
37 import javax.sql.XADataSource JavaDoc;
38
39 public class XAMCFImpl
40         extends ManagedConnectionFactoryImpl {
41
42     XADataSource JavaDoc ds = null;
43
44     public ManagedConnection JavaDoc createManagedConnection(Subject JavaDoc subject,
45                                                       ConnectionRequestInfo JavaDoc cxReq)
46               throws ResourceException JavaDoc {
47                   
48       PasswordCredential JavaDoc pc = Utility.getPasswordCredential(this, subject, cxReq, pw);
49       if(ds == null) {
50           try {
51               ds = (XADataSource JavaDoc) Utility.getDataSource(this, pc, trace);
52           } catch(Exception JavaDoc ex) {
53               throw new ResourceException JavaDoc(ex.getMessage());
54           }
55       }
56       javax.sql.XAConnection JavaDoc xaConnection = null;
57       java.sql.Connection JavaDoc connection = null;
58       try {
59           if(cxReq != null) {
60               ConnectionRequestInfoImpl cx = (ConnectionRequestInfoImpl) cxReq;
61               xaConnection = ds.getXAConnection(cx.getUser(), cx.getPassword());
62           } else if (pc != null){
63               xaConnection = ds.getXAConnection(pc.getUserName(), new String JavaDoc(pc.getPassword()));
64           } else if (mcfData.getMCFData(MCFData.USER).length() > 0){
65               xaConnection = ds.getXAConnection(mcfData.getMCFData(MCFData.USER),
66                                               mcfData.getMCFData(MCFData.PASSWORD));
67           } else {
68               xaConnection = ds.getXAConnection();
69           }
70           if (xaConnection != null) {
71               connection = xaConnection.getConnection();
72           }
73       }
74       catch(SQLException JavaDoc sqle)
75       {
76           throw new ResourceAllocationException JavaDoc("The connection could not be allocated: " + sqle.getMessage());
77       }
78       return new ManagedConnectionImpl(this, pc, connection, null, xaConnection, null);
79     }
80
81     /* Determine if the factories are equal
82      */

83     public boolean equals(Object JavaDoc obj) {
84         if (obj instanceof XAMCFImpl) {
85             return mcfData.equals(((XAMCFImpl)obj).mcfData);
86         }
87         else {
88             return false;
89         }
90     }
91
92     // JOnAS JDBC RA DataSource config properties
93
public String JavaDoc getDatabaseName()
94     {
95         return mcfData.getMCFData(MCFData.DATABASENAME);
96     }
97
98     public void setDatabaseName(String JavaDoc val)
99     {
100         mcfData.setMCFData(MCFData.DATABASENAME, val);
101     }
102
103     public String JavaDoc getDescription()
104     {
105         return mcfData.getMCFData(MCFData.DESCRIPTION);
106     }
107
108     public void setDescription(String JavaDoc val)
109     {
110         mcfData.setMCFData(MCFData.DESCRIPTION, val);
111     }
112
113     public String JavaDoc getPortNumber()
114     {
115         return mcfData.getMCFData(MCFData.PORTNUMBER);
116     }
117
118     public void setPortNumber(String JavaDoc val)
119     {
120         mcfData.setMCFData(MCFData.PORTNUMBER, val);
121     }
122
123     public String JavaDoc getServerName()
124     {
125         return mcfData.getMCFData(MCFData.SERVERNAME);
126     }
127
128     public void setServerName(String JavaDoc val)
129     {
130         mcfData.setMCFData(MCFData.SERVERNAME, val);
131     }
132
133 }
Popular Tags