package org.jboss.resource.adapter.jdbc.vendor;
import java.lang.reflect.Method;
import javax.management.ObjectName;
import javax.transaction.xa.XAException;
import org.jboss.system.ServiceMBeanSupport;
import org.jboss.tm.XAExceptionFormatter;
import org.jboss.logging.Logger;
public class OracleXAExceptionFormatter
extends ServiceMBeanSupport
implements XAExceptionFormatter, OracleXAExceptionFormatterMBean
{
private static final String EXCEPTION_CLASS_NAME = "oracle.jdbc.xa.OracleXAException";
private static final Object[] NOARGS = {};
private ObjectName transactionManagerService;
private Class oracleXAExceptionClass;
private Method getXAError;
private Method getXAErrorMessage;
private Method getOracleError;
private Method getOracleSQLError;
public OracleXAExceptionFormatter() {
}
public ObjectName getTransactionManagerService()
{
return transactionManagerService;
}
public void setTransactionManagerService(ObjectName transactionManagerService)
{
this.transactionManagerService = transactionManagerService;
}
protected void startService() throws Exception
{
oracleXAExceptionClass = Thread.currentThread().getContextClassLoader().loadClass(EXCEPTION_CLASS_NAME);
getXAError = oracleXAExceptionClass.getMethod("getXAError", new Class[] {});
getXAErrorMessage = oracleXAExceptionClass.getMethod("getXAErrorMessage",
new Class[] {getXAError.getReturnType()});
getOracleError = oracleXAExceptionClass.getMethod("getOracleError", new Class[] {});
getOracleSQLError = oracleXAExceptionClass.getMethod("getOracleSQLError", new Class[] {});
getServer().invoke(transactionManagerService,
"registerXAExceptionFormatter",
new Object[] {oracleXAExceptionClass, this},
new String[] {Class.class.getName(), XAExceptionFormatter.class.getName()});
}
protected void stopService() throws Exception
{
getServer().invoke(transactionManagerService,
"unregisterXAExceptionFormatter",
new Object[] {oracleXAExceptionClass},
new String[] {Class.class.getName()});
oracleXAExceptionClass = null;
getXAError = null;
getXAErrorMessage = null;
getOracleError = null;
getOracleSQLError = null;
}
public void formatXAException(XAException xae, Logger log)
{
try
{
log.warn(
"xa error: "
+ getXAError.invoke(xae, NOARGS)
+ " (" + getXAErrorMessage.invoke(xae, new Object[] {getXAError.invoke(xae, NOARGS)}) + "); "
+ "oracle error: " + getOracleError.invoke(xae, NOARGS) + "; "
+ "oracle sql error: " + getOracleSQLError.invoke(xae, NOARGS) + ";", xae);
}
catch (Exception e)
{
log.info("Problem trying to format XAException: ", e);
}
}
}