1 22 package org.jboss.resource.adapter.jdbc.vendor; 23 24 import java.lang.reflect.Method ; 25 import javax.management.ObjectName ; 26 import javax.transaction.xa.XAException ; 27 import org.jboss.system.ServiceMBeanSupport; 28 import org.jboss.tm.XAExceptionFormatter; 29 import org.jboss.logging.Logger; 30 31 40 public class OracleXAExceptionFormatter extends ServiceMBeanSupport implements XAExceptionFormatter, OracleXAExceptionFormatterMBean 41 { 42 private static final String EXCEPTION_CLASS_NAME = "oracle.jdbc.xa.OracleXAException"; 43 44 private static final Object [] NOARGS = {}; 45 46 private ObjectName transactionManagerService; 47 48 private Class oracleXAExceptionClass; 49 50 private Method getXAError; 51 52 private Method getXAErrorMessage; 53 54 private Method getOracleError; 55 56 private Method getOracleSQLError; 57 58 public OracleXAExceptionFormatter() 59 { 60 } 61 62 public ObjectName getTransactionManagerService() 63 { 64 return transactionManagerService; 65 } 66 67 public void setTransactionManagerService(ObjectName transactionManagerService) 68 { 69 this.transactionManagerService = transactionManagerService; 70 } 71 72 protected void startService() throws Exception 73 { 74 oracleXAExceptionClass = Thread.currentThread().getContextClassLoader().loadClass(EXCEPTION_CLASS_NAME); 75 getXAError = oracleXAExceptionClass.getMethod("getXAError", new Class [] {}); 76 getXAErrorMessage = oracleXAExceptionClass.getMethod("getXAErrorMessage", new Class [] { getXAError.getReturnType() }); 77 getOracleError = oracleXAExceptionClass.getMethod("getOracleError", new Class [] {}); 78 getOracleSQLError = oracleXAExceptionClass.getMethod("getOracleSQLError", new Class [] {}); 79 80 getServer().invoke(transactionManagerService, "registerXAExceptionFormatter", new Object [] { oracleXAExceptionClass, this}, new String [] { Class .class.getName(), XAExceptionFormatter.class.getName() }); 81 } 82 83 protected void stopService() throws Exception 84 { 85 getServer().invoke(transactionManagerService, "unregisterXAExceptionFormatter", new Object [] { oracleXAExceptionClass }, new String [] { Class .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 xae, Logger log) 96 { 97 try 98 { 99 log.warn("xa error: " + getXAError.invoke(xae, NOARGS) + " (" + getXAErrorMessage.invoke(xae, new Object [] 100 {getXAError.invoke(xae, NOARGS)}) + "); " + "oracle error: " + getOracleError.invoke(xae, NOARGS) + "; " 101 + "oracle sql error: " + getOracleSQLError.invoke(xae, NOARGS) + ";", xae); 102 } 103 catch (Exception e) 104 { 105 log.warn("Problem trying to format XAException: ", e); 106 } 107 108 } 109 } 110 | Popular Tags |