Formatterpublic final class Formatter extends Object implements StringSourceEscapes/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.String | format(java.lang.String key, java.lang.Object[] objects)Format the objects into a String using the pattern specified by 'key'.
return( MessageFormat.format( getString( key ), prepare( objects ) ) );
| public java.lang.String | format(java.lang.String key, java.lang.Object o1)
return( format( key, new Object[] { o1 } ) );
| public java.lang.String | format(java.lang.String key, java.lang.Object o1, java.lang.Object o2)
return( format( key, new Object[] { o1, o2 } ) );
| public java.lang.String | format(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.String | format(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.String | getString(java.lang.String id, java.lang.String defaultValue)
return( mStringSource.getString( id, defaultValue ) );
| public java.lang.String | getString(java.lang.String id)
return( mStringSource.getString( id ) );
| public java.lang.Object | prepare(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 );
|
|