FileDocCategorySizeDatePackage
ObjectNameStringifier.javaAPI DocGlassfish v2 API5723Fri May 04 22:31:06 BST 2007com.sun.appserv.management.util.jmx.stringifier

ObjectNameStringifier

public final class ObjectNameStringifier extends Object implements com.sun.appserv.management.util.stringifier.Stringifier
Stringifier for an ObjectName which sorts the properties in the ObjectName for more consistent and readable output.

Fields Summary
public static final ObjectNameStringifier
DEFAULT
private static List
PROPS
private List
mOrderedProps
private boolean
mOmitDomain
Constructors Summary
public ObjectNameStringifier()

		this( getPROPS() );
	
public ObjectNameStringifier(List props)

		mOrderedProps	= props;
		mOmitDomain	= false;
	
public ObjectNameStringifier(String[] props)

		this( ListUtil.newListFromArray( props ) );
	
Methods Summary
public booleangetOmitDomain()

		return( mOmitDomain );
	
private static synchronized java.util.ListgetPROPS()

	
		   
	
	
		if ( PROPS == null )
		{
		PROPS	= Collections.unmodifiableList( ListUtil.newListFromArray( new String[]
			{
				"j2eeType","type",
				"name",
				
				"J2EEDomain",
				"J2EEServer",
				"JVM",
				"Node",
				"J2EEApplication",
				
				"AppClientModule",
				
				"EJBModule",
				"EntityBean",
				"StatefulSessionBean",
				"StatelessSessionBean",
				"MessageDrivenBean",
				
				"WebModule", "Servlet",
				
				"ResourceAdapterModule",
				"JavaMailResource",
				"JCAResource",
				"JCAConnectionFactory",
				"JCAManagedConnectionFactory",
				"JDBCResource",
				"JDBCDataSource",
				"JDBCDriver",
				"JMSResource",
				"JNDIResource",
				"JTAResource",
				"RMI_IIOPResource",
				"URL_Resource",
				
			} ));
		}
		return( PROPS );
	
public java.util.ListgetProps()

		return( mOrderedProps );
	
private java.lang.StringmakeProp(java.lang.String name, java.lang.String value)

	    return( name + "=" + value );
	
public voidsetOmitDomain(boolean omit)

		mOmitDomain	= omit;
	
public voidsetProps(java.util.List props)

		mOrderedProps	= props;
	
public java.lang.Stringstringify(java.lang.Object o)

		if ( o == null )
		{
			return( "null" );
		}


		final ObjectName	on	= (ObjectName)o;
		
		final StringBuffer	buf	= new StringBuffer();
		if ( ! mOmitDomain )
		{
			buf.append( on.getDomain() + ":" );
		}
		
		final Map<String,String>	props	= TypeCast.asMap( on.getKeyPropertyList() );
		
		final List<String>	ordered	= new ArrayList<String>( mOrderedProps );
		ordered.retainAll( props.keySet() );
		
		// go through each ordered property, and if it exists, emit it
		final Iterator	iter	= ordered.iterator();
		while ( iter.hasNext() && props.keySet().size() >= 2 )
		{
			final String	key		= (String)iter.next();
			final String	value	= (String)props.get( key );
			if ( value != null )
			{
				buf.append( makeProp( key, value ) + "," );
				props.remove( key );
			}
		}
		
		// emit all remaining properties in order
		final Set<String>		remainingSet = props.keySet();
		final String[]	remaining	= new String[ remainingSet.size() ];
		remainingSet.toArray( remaining );
		Arrays.sort( remaining );
		
		for( int i = 0; i < remaining.length; ++i )
		{
			final String	key		= remaining[ i ];
			final String	value	= (String)props.get( key );
			buf.append( makeProp( key, value )  + "," );
		}
		
		final String	result	= StringUtil.stripSuffix( buf.toString(), "," );

		return( result );