FileDocCategorySizeDatePackage
LogFormatter.javaAPI DocGlassfish v2 API5372Fri May 04 22:36:44 BST 2007com.sun.jts.utils

LogFormatter

public class LogFormatter extends Object
This class is used to format the trace record.
author
K Venugopal
version
1.0

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringconvertPropsToString(java.util.Properties prop)
Helper method to convert properties to string.

param
prop a Properties value
return
a String value

        if(prop==null){
	    return "{null}";
        }
        StringBuffer strBuf =  new StringBuffer("{ ");
        for(Enumeration enum1 = prop.propertyNames(); enum1.hasMoreElements(); )
        {
            Object obj = enum1.nextElement();
            strBuf.append("[ ").append(obj).append("->");
            Object val=prop.getProperty((String)obj);
            if(val==null)
	        strBuf.append("null");
            else
                strBuf.append((String)val);        
            strBuf.append(" ] ");
        }        
        strBuf.append("}");
        return strBuf.toString();
    
public static java.lang.StringconvertToString(byte[] byteArray)
Helper method to convert a byte arror to string. This is typically used for printing Xids.

param
byteArray a byte[] value
return
a String value

        int i;
        StringBuffer strBuf=new StringBuffer();
        for(i = 0; i < byteArray.length; i++)
         {
            strBuf.append(byteArray[i]);    
        }    
        return strBuf.toString();
    
public static java.lang.StringconvertXidArrayToString(javax.transaction.xa.Xid[] xidArray)
Converts an array of xids to string that can be printed. Its a helper method.

param
xidArray a Xid[] value
return
a String value

	if(xidArray.length != 0)
	{
        	int i;
        	StringBuffer strBuf = new StringBuffer("Xid class name is " + xidArray[0].getClass().getName() + " Number of Xids are " + xidArray.length + " [ ");
        	for(i = 0; i < xidArray.length - 1; i++)
        	{
            		strBuf.append(xidArray[i]).append("\n");
        	}
        	strBuf.append(xidArray[xidArray.length - 1]).append(" ]");
        	return strBuf.toString();
	}
	else
		return " null ";
    
public static java.lang.StringgetLocalizedMessage(java.util.logging.Logger logger, java.lang.String key)
getLocalizedMessage is used to localize the messages being used in exceptions

		try{
			ResourceBundle rb = logger.getResourceBundle();
			String message = rb.getString(key);
			return message;
		}catch ( Exception ex){
			logger.log(Level.FINE,"JTS:Error while localizing the log message");
			return key;
		}
	
public static java.lang.StringgetLocalizedMessage(java.util.logging.Logger logger, java.lang.String key, java.lang.Object[] args)
getLocalizedMessage is used to localize the messages being used in exceptions with arguments inserted appropriately.

		try{
			ResourceBundle rb = logger.getResourceBundle();
			String message = rb.getString(key);
			return MessageFormat.format(message,args);
		}catch ( Exception ex){
				logger.log(Level.FINE,"JTS:Error while localizing the log message");
			return key;
		}