FileDocCategorySizeDatePackage
Helper.javaAPI DocGlassfish v2 API5051Fri May 04 22:30:50 BST 2007com.sun.appserv.management.helper

Helper

public class Helper extends Object
Base class for Helpers, useable alone as well.

Fields Summary
protected final com.sun.appserv.management.DomainRoot
mDomainRoot
protected final com.sun.appserv.management.base.QueryMgr
mQueryMgr
protected final com.sun.appserv.management.base.BulkAccess
mBulkAccess
Constructors Summary
public Helper(com.sun.appserv.management.base.AMX proxy)

		mDomainRoot	= proxy.getDomainRoot();
		mQueryMgr		= mDomainRoot.getQueryMgr();
		mBulkAccess	= mDomainRoot.getBulkAccess();
	
Methods Summary
public java.util.SetfilterByAttributeValue(java.util.Set objectNameSet, java.lang.String attributeName, java.lang.Object valueToMatch)
Filter ObjectNames based on the value of a particular Attribute. The value may be null or anything else. This is essentially a crude form of using the QueryMgr. A value which is a Class object succeeds if the result is an object whose class is assignable to the specfied class. Typically this is used to detect a thrown Exception.

For example, to select all MBeans which have a [bB]oolean Attribute named "Enabled", which is set to true, call:

filterByAttributeValue( objectNameSet, "Enabled", Boolean.TRUE)

The query for the Attribute value is performed as a bulk operation; thus this routine may be used with confidence that it is fast.

param
objectNameSet Set of ObjectName
param
attributeName
param
valueToMatch an Object whose value must be null, or equals() to the result
return
Set of ObjectName which have Enabled flag matching

		final ObjectName[]	objectNames	= new ObjectName[ objectNameSet.size() ];
		objectNameSet.toArray( objectNames );
		
		final Object[]	values	= mBulkAccess.bulkGetAttribute( objectNames, attributeName );
		
		final Set<ObjectName>	filtered	= new HashSet<ObjectName>();
		for( int i = 0; i < values.length; ++i )
		{
			final Object	idxValue	= values[ i ];
			
			boolean	matches	= false;
			
			if ( valueToMatch == null && idxValue == null )
			{
				matches	= true;
			}
			else if ( valueToMatch instanceof Class &&
					((Class<?>)valueToMatch).isAssignableFrom( idxValue.getClass() ) )
			{
				matches	= true;
			}
			else if ( valueToMatch != null && valueToMatch.equals( idxValue ) )
			{
				matches	= true;
			}
			else
			{
				// no match
			}
			
			if ( matches )
			{
				filtered.add( objectNames[ i ] );
			}
		}
		
		return( filtered );
	
public com.sun.appserv.management.DomainRootgetDomainRoot()

		return( mDomainRoot );
	
protected java.util.SetpropsQuery(java.lang.String props)

		final Set<T>		results	= mQueryMgr.queryPropsSet( props );
		return( results );
	
protected java.util.SetpropsQuery(java.lang.String props1, java.lang.String props2)

		final String	props	= Util.concatenateProps( props1, props2 );
		
		return( propsQuery( props ) );