KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jdbc > vendor > OracleXAExceptionFormatter


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.resource.adapter.jdbc.vendor;
23
24 import java.lang.reflect.Method JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import javax.transaction.xa.XAException JavaDoc;
27 import org.jboss.system.ServiceMBeanSupport;
28 import org.jboss.tm.XAExceptionFormatter;
29 import org.jboss.logging.Logger;
30
31 /**
32  * OracleXAExceptionFormatter
33  *
34  * @todo this does not belong in the resource adapter
35  * @author <a HREF="mailto:igorfie at yahoo dot com">Igor Fedorenko</a>.
36  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
37  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
38  * @version $Revision: 38332 $
39  */

40 public class OracleXAExceptionFormatter extends ServiceMBeanSupport implements XAExceptionFormatter, OracleXAExceptionFormatterMBean
41 {
42    private static final String JavaDoc EXCEPTION_CLASS_NAME = "oracle.jdbc.xa.OracleXAException";
43
44    private static final Object JavaDoc[] NOARGS = {};
45
46    private ObjectName JavaDoc transactionManagerService;
47
48    private Class JavaDoc oracleXAExceptionClass;
49
50    private Method JavaDoc getXAError;
51
52    private Method JavaDoc getXAErrorMessage;
53
54    private Method JavaDoc getOracleError;
55
56    private Method JavaDoc getOracleSQLError;
57
58    public OracleXAExceptionFormatter()
59    {
60    }
61
62    public ObjectName JavaDoc getTransactionManagerService()
63    {
64       return transactionManagerService;
65    }
66
67    public void setTransactionManagerService(ObjectName JavaDoc transactionManagerService)
68    {
69       this.transactionManagerService = transactionManagerService;
70    }
71
72    protected void startService() throws Exception JavaDoc
73    {
74       oracleXAExceptionClass = Thread.currentThread().getContextClassLoader().loadClass(EXCEPTION_CLASS_NAME);
75       getXAError = oracleXAExceptionClass.getMethod("getXAError", new Class JavaDoc[] {});
76       getXAErrorMessage = oracleXAExceptionClass.getMethod("getXAErrorMessage", new Class JavaDoc[] { getXAError.getReturnType() });
77       getOracleError = oracleXAExceptionClass.getMethod("getOracleError", new Class JavaDoc[] {});
78       getOracleSQLError = oracleXAExceptionClass.getMethod("getOracleSQLError", new Class JavaDoc[] {});
79
80       getServer().invoke(transactionManagerService, "registerXAExceptionFormatter", new Object JavaDoc[] { oracleXAExceptionClass, this}, new String JavaDoc[] { Class JavaDoc.class.getName(), XAExceptionFormatter.class.getName() });
81    }
82
83    protected void stopService() throws Exception JavaDoc
84    {
85       getServer().invoke(transactionManagerService, "unregisterXAExceptionFormatter", new Object JavaDoc[] { oracleXAExceptionClass }, new String JavaDoc[] { Class JavaDoc.class.getName() });
86
87       oracleXAExceptionClass = null;
88
89       getXAError = null;
90       getXAErrorMessage = null;
91       getOracleError = null;
92       getOracleSQLError = null;
93    }
94
95    public void formatXAException(XAException JavaDoc xae, Logger log)
96    {
97       try
98       {
99          log.warn("xa error: " + getXAError.invoke(xae, NOARGS) + " (" + getXAErrorMessage.invoke(xae, new Object JavaDoc[]
100          {getXAError.invoke(xae, NOARGS)}) + "); " + "oracle error: " + getOracleError.invoke(xae, NOARGS) + "; "
101                + "oracle sql error: " + getOracleSQLError.invoke(xae, NOARGS) + ";", xae);
102       }
103       catch (Exception JavaDoc e)
104       {
105          log.warn("Problem trying to format XAException: ", e);
106       }
107
108    }
109 }
110
Popular Tags