1 23 package com.sun.appserv.management.helper; 24 25 import java.util.Set ; 26 import java.util.HashSet ; 27 28 import javax.management.ObjectName ; 29 30 import com.sun.appserv.management.base.Util; 31 import com.sun.appserv.management.base.AMX; 32 import com.sun.appserv.management.DomainRoot; 33 import com.sun.appserv.management.base.QueryMgr; 34 import com.sun.appserv.management.base.BulkAccess; 35 36 39 public class Helper 40 { 41 protected final DomainRoot mDomainRoot; 42 protected final QueryMgr mQueryMgr; 43 protected final BulkAccess mBulkAccess; 44 45 public 46 Helper( final AMX proxy ) 47 { 48 mDomainRoot = proxy.getDomainRoot(); 49 mQueryMgr = mDomainRoot.getQueryMgr(); 50 mBulkAccess = mDomainRoot.getBulkAccess(); 51 } 52 53 public DomainRoot 54 getDomainRoot() 55 { 56 return( mDomainRoot ); 57 } 58 59 protected <T extends AMX> Set <T> 60 propsQuery( final String props ) 61 { 62 final Set <T> results = mQueryMgr.queryPropsSet( props ); 63 return( results ); 64 } 65 66 protected <T extends AMX> Set <T> 67 propsQuery( 68 final String props1, 69 final String props2 ) 70 { 71 final String props = Util.concatenateProps( props1, props2 ); 72 73 return( propsQuery( props ) ); 74 } 75 76 96 public Set <ObjectName > 97 filterByAttributeValue( 98 final Set <ObjectName > objectNameSet, 99 final String attributeName, 100 final Object valueToMatch ) 101 { 102 final ObjectName [] objectNames = new ObjectName [ objectNameSet.size() ]; 103 objectNameSet.toArray( objectNames ); 104 105 final Object [] values = mBulkAccess.bulkGetAttribute( objectNames, attributeName ); 106 107 final Set <ObjectName > filtered = new HashSet <ObjectName >(); 108 for( int i = 0; i < values.length; ++i ) 109 { 110 final Object idxValue = values[ i ]; 111 112 boolean matches = false; 113 114 if ( valueToMatch == null && idxValue == null ) 115 { 116 matches = true; 117 } 118 else if ( valueToMatch instanceof Class && 119 ((Class <?>)valueToMatch).isAssignableFrom( idxValue.getClass() ) ) 120 { 121 matches = true; 122 } 123 else if ( valueToMatch != null && valueToMatch.equals( idxValue ) ) 124 { 125 matches = true; 126 } 127 else 128 { 129 } 131 132 if ( matches ) 133 { 134 filtered.add( objectNames[ i ] ); 135 } 136 } 137 138 return( filtered ); 139 } 140 141 } 142 143 144 | Popular Tags |