1 23 24 28 package com.sun.jts.utils; 29 30 31 import org.omg.CosTransactions.*; 32 import javax.transaction.xa.*; 33 import java.util.*; 34 import java.util.logging.*; 35 import java.text.*; 36 37 43 public class LogFormatter 44 { 45 51 52 public static String convertToString(byte[] byteArray) 53 { 54 int i; 55 StringBuffer strBuf=new StringBuffer (); 56 for(i = 0; i < byteArray.length; i++) 57 { 58 strBuf.append(byteArray[i]); 59 } 60 return strBuf.toString(); 61 } 62 63 69 public static String convertXidArrayToString(Xid[] xidArray) 70 { 71 if(xidArray.length != 0) 72 { 73 int i; 74 StringBuffer strBuf = new StringBuffer ("[ "); 75 for(i = 0; i < xidArray.length - 1; i++) 76 { 77 strBuf.append(xidArray[i].getGlobalTransactionId()).append(", "); 78 } 79 strBuf.append(xidArray[xidArray.length - 1]).append(" ]"); 80 return strBuf.toString(); 81 } 82 else 83 return " null "; 84 } 85 86 92 public static String convertPropsToString(Properties prop) 93 { 94 if(prop==null){ 95 return "{null}"; 96 } 97 StringBuffer strBuf = new StringBuffer ("{ "); 98 for(Enumeration e = prop.propertyNames(); e.hasMoreElements(); ) 99 { 100 Object obj = e.nextElement(); 101 strBuf.append("[ ").append(obj).append("->"); 102 Object val=prop.getProperty((String )obj); 103 if(val==null) 104 strBuf.append("null"); 105 else 106 strBuf.append((String )val); 107 strBuf.append(" ] "); 108 } 109 strBuf.append("}"); 110 return strBuf.toString(); 111 } 112 113 117 118 public static String getLocalizedMessage(Logger logger , String key){ 119 try{ 120 ResourceBundle rb = logger.getResourceBundle(); 121 String message = rb.getString(key); 122 return message; 123 }catch ( Exception ex){ 124 logger.log(Level.FINE,"JTS:Error while localizing the log message"); 125 return key; 126 } 127 } 128 129 133 134 public static String getLocalizedMessage(Logger logger , String key, 135 Object [] args){ 136 try{ 137 ResourceBundle rb = logger.getResourceBundle(); 138 String message = rb.getString(key); 139 return MessageFormat.format(message,args); 140 }catch ( Exception ex){ 141 logger.log(Level.FINE,"JTS:Error while localizing the log message"); 142 return key; 143 } 144 } 145 } 146 | Popular Tags |