FileDocCategorySizeDatePackage
StatisticStringifier.javaAPI DocGlassfish v2 API4465Fri May 04 22:31:04 BST 2007com.sun.appserv.management.util.j2ee.stringifier

StatisticStringifier

public class StatisticStringifier extends Object implements com.sun.appserv.management.util.stringifier.Stringifier
Stringifier for javax.management.j2ee.Statistic

Fields Summary
public static final StatisticStringifier
DEFAULT
private static final String
DELIM
private static final String
GET
private static final String[]
ORDERED_VALUES
Constructors Summary
public StatisticStringifier()

	
		
	 
	
	
Methods Summary
private static java.lang.StringcreateNameValuePair(java.lang.String name, java.lang.Object value)

	
		  
	       
	
		final String valueString	= value instanceof String ?
			StringUtil.quote( (String)value ) : SmartStringifier.toString( value );
			
		return name + "=" + valueString;
	
public java.lang.Stringstringify(java.lang.Object o)
Stringify by accessing all public getXXX() methods that return a value and don't throw exceptions.

		final Statistic		statistic	= (Statistic)o;
		
		final StringBuffer	buf	= new StringBuffer();
		
		buf.append( statistic.getName() + ": " );
		
		final SortedMap<String,Object> pairs =
		    new TreeMap<String,Object>( J2EEUtil.statisticToMap( statistic ) );
		
		// first emit the standard value names in a proscribed order
		for( int i = 0; i < ORDERED_VALUES.length; ++i )
		{
			final String	name	= ORDERED_VALUES[ i ];
			if ( pairs.containsKey( name ) )
			{
				final Object value	= pairs.get( name );
				buf.append( createNameValuePair( name, value ) );
				buf.append( DELIM );
				pairs.remove( name );
			}
		}
		
		
		final Iterator	iter	= pairs.keySet().iterator();
		while ( iter.hasNext() )
		{	
			final String	name	= (String)iter.next();
			final Object	value	= pairs.get( name );
			
			buf.append( createNameValuePair( name, value ) );
			buf.append( DELIM );
			
		}
		
		String	result	= buf.toString();
		if ( result.endsWith( DELIM ) )
		{
			result	= result.substring( 0, result.length() - DELIM.length() );
		}
		
		
		return( result );