ObjectNameStringifierpublic final class ObjectNameStringifier extends Object implements com.sun.appserv.management.util.stringifier.StringifierStringifier 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 boolean | getOmitDomain()
return( mOmitDomain );
| private static synchronized java.util.List | getPROPS()
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.List | getProps()
return( mOrderedProps );
| private java.lang.String | makeProp(java.lang.String name, java.lang.String value)
return( name + "=" + value );
| public void | setOmitDomain(boolean omit)
mOmitDomain = omit;
| public void | setProps(java.util.List props)
mOrderedProps = props;
| public java.lang.String | stringify(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 );
|
|