1 23 24 29 30 package com.sun.enterprise.management.support; 31 32 import java.util.Set ; 33 34 import javax.management.ObjectName ; 35 import javax.management.MBeanServer ; 36 import javax.management.Attribute ; 37 import javax.management.AttributeList ; 38 import javax.management.InstanceNotFoundException ; 39 import javax.management.AttributeNotFoundException ; 40 import javax.management.InvalidAttributeValueException ; 41 import javax.management.ReflectionException ; 42 import javax.management.MBeanException ; 43 import javax.management.MBeanParameterInfo ; 44 import javax.management.MBeanOperationInfo ; 45 46 import com.sun.appserv.management.base.AMXDebug; 47 48 import com.sun.appserv.management.util.jmx.JMXUtil; 49 import com.sun.appserv.management.util.misc.ArrayConversion; 50 import com.sun.appserv.management.util.misc.Output; 51 52 55 public abstract class DelegateBase implements Delegate 56 { 57 private Set mAttributeNames; 58 private DelegateOwner mOwner; 59 private Output mDebug; 60 private final String mID; 61 62 65 protected void 66 unimplementedOperation( String operation ) 67 { 68 debug( "unimplemented operation: " + operation ); 69 throw new UnsupportedOperationException ( operation ); 70 } 71 72 public 73 DelegateBase( final String id, DelegateOwner owner ) 74 { 75 mID = id; 76 mAttributeNames = null; 77 mOwner = owner; 78 mDebug = null; 79 } 80 81 public void 82 setDebugOutput( final Output debugOutput ) 83 { 84 mDebug = debugOutput; 85 } 86 87 protected final void 88 debug(final Object o) 89 { 90 if ( mDebug != null ) 91 { 92 mDebug.println( o ); 93 } 94 } 95 96 97 public final String getID() { return mID; } 98 99 public void 100 setOwner( final DelegateOwner owner ) 101 { 102 mOwner = owner; 103 } 104 105 public DelegateOwner 106 getOwner() 107 { 108 return( mOwner ); 109 } 110 111 115 public AttributeList 116 getAttributes( final String [] attrNames ) 117 { 118 final AttributeList attrs = new AttributeList (); 119 120 for( int i = 0; i < attrNames.length; ++i ) 121 { 122 try 123 { 124 final String attrName = attrNames[ i ]; 125 126 final Attribute attr = 127 new Attribute ( attrName, getAttribute( attrName ) ); 128 attrs.add( attr ); 129 } 130 catch( Exception e ) 131 { 132 } 134 } 135 136 return( attrs ); 137 } 138 139 140 144 public AttributeList 145 setAttributes( final AttributeList attrs ) 146 { 147 final int numAttrs = attrs.size(); 148 final AttributeList successList = new AttributeList (); 149 150 for( int i = 0; i < numAttrs; ++i ) 151 { 152 final Attribute attr = (Attribute )attrs.get( i ); 153 try 154 { 155 setAttribute( attr ); 156 157 successList.add( attr ); 158 } 159 catch( AttributeNotFoundException e ) 160 { 161 } 163 catch( InvalidAttributeValueException e ) 164 { 165 } 167 } 168 return( successList ); 169 } 170 171 172 173 176 private boolean 177 typesMatch( 178 final String [] types, 179 final MBeanParameterInfo [] paramInfos ) 180 { 181 boolean matches = false; 182 final int numTypes = types == null ? 0 : types.length; 183 final int numParams = paramInfos == null ? 0 : paramInfos.length; 184 185 if ( numTypes == numParams ) 186 { 187 matches = true; 188 189 for( int i = 0; i < numTypes; ++i ) 190 { 191 if ( ! types[ i ].equals( paramInfos[ i ].getType() ) ) 192 { 193 matches = false; 194 break; 195 } 196 } 197 } 198 199 return( matches ); 200 } 201 202 public synchronized boolean 203 supportsAttribute( String attrName ) 204 { 205 if ( mAttributeNames == null ) 206 { 207 final String [] attrNames = 208 JMXUtil.getAttributeNames( getMBeanInfo().getAttributes() ); 209 210 mAttributeNames = ArrayConversion.arrayToSet( attrNames ); 211 } 212 213 return( mAttributeNames.contains( attrName ) ); 214 } 215 216 public boolean 217 supportsOperation( 218 String operationName, 219 Object [] args, 220 String [] types ) 221 { 222 boolean supports = false; 223 224 final MBeanOperationInfo [] opInfos = getMBeanInfo().getOperations(); 225 226 for( int i = 0; i < opInfos.length; ++i ) 227 { 228 final MBeanOperationInfo info = opInfos[ i ]; 229 230 if ( info.getName().equals( operationName ) ) 231 { 232 if ( typesMatch( types, info.getSignature() ) ) 233 { 234 supports = true; 235 break; 236 } 237 } 238 } 239 240 return( supports ); 241 } 242 243 } 244 245 246 247 248 249 250 251 252 | Popular Tags |