FileDocCategorySizeDatePackage
Formatter.javaAPI DocGlassfish v2 API4583Fri May 04 22:31:06 BST 2007com.sun.appserv.management.util.misc

Formatter

public final class Formatter extends Object implements StringSource
Escapes/unescapes strings

Fields Summary
final StringSource
mStringSource
final com.sun.appserv.management.util.stringifier.StringifierRegistry
mRegistry
Constructors Summary
public Formatter(StringSource source)

		mStringSource	= source;
		mRegistry		= StringifierRegistryImpl.DEFAULT;
	
Methods Summary
public java.lang.Stringformat(java.lang.String key, java.lang.Object[] objects)
Format the objects into a String using the pattern specified by 'key'.

param
key key used to look up the pattern
param
objects array of objects to insert into the pattern

		return( MessageFormat.format( getString( key ), prepare( objects ) ) );
	
public java.lang.Stringformat(java.lang.String key, java.lang.Object o1)

		return( format( key, new Object[] { o1 } ) );
	
public java.lang.Stringformat(java.lang.String key, java.lang.Object o1, java.lang.Object o2)

		return( format( key, new Object[] { o1, o2 } ) );
	
public java.lang.Stringformat(java.lang.String key, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)

		return( format( key, new Object[] { o1, o2, o3} ) );
	
public java.lang.Stringformat(java.lang.String key, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4)

		return( format( key, new Object[] { o1, o2, o3, o4 } ) );
	
public java.lang.StringgetString(java.lang.String id, java.lang.String defaultValue)

		return( mStringSource.getString( id, defaultValue ) );
	
public java.lang.StringgetString(java.lang.String id)

		return( mStringSource.getString( id ) );
	
public java.lang.Objectprepare(java.lang.Object o)

		Object	result	= o;
		
		if ( mRegistry.lookup( o.getClass() ) != null ||
			ClassUtil.objectIsArray( o ) )
		{
			result	= SmartStringifier.toString( o );
		}
		
		return( result );
	
private java.lang.Object[]prepare(java.lang.Object[] objects)
Prepare objects for formatting. Certain objects are not properly handled by MesageFormat (such as Sets and arrays). We'll intercept these types, but leave dates and numbers to MessageFormat.

		final Object[]	results	= new Object[ objects.length ];
		
		for( int i = 0; i < objects.length; ++i )
		{
			results[ i ]	= prepare( objects[ i ] );
		}
		
		return( results );