1 23 24 29 package com.sun.enterprise.admin.dottedname.valueaccessor; 30 31 32 import com.sun.enterprise.admin.dottedname.DottedNameStrings; 33 34 import javax.management.Attribute ; 35 import javax.management.AttributeList ; 36 import javax.management.ObjectName ; 37 import javax.management.MBeanServerConnection ; 38 import javax.management.ReflectionException ; 39 import javax.management.MBeanException ; 40 import javax.management.InstanceNotFoundException ; 41 import javax.management.AttributeNotFoundException ; 42 import javax.management.RuntimeOperationsException ; 43 import javax.management.JMException ; 44 45 import javax.management.MBeanServerConnection ; 46 47 public abstract class PropertyValueAccessorBase extends PrefixedValueAccessorBase 48 { 49 abstract String getGetPropertyMethodName(); 50 abstract String getSetPropertyMethodName(); 51 abstract String getGetPropertiesMethodName(); 52 53 54 public PropertyValueAccessorBase(MBeanServerConnection conn, String prefix) 55 { 56 super( conn, prefix); 57 } 58 59 public Attribute getValue( ObjectName objectName, String valueName ) 60 throws java.io.IOException , ReflectionException , InstanceNotFoundException , 61 AttributeNotFoundException 62 { 63 Attribute result = null; 64 try 65 { 66 final Object value = getMBS().invoke( objectName, 67 getGetPropertyMethodName(), new Object [] { valueName }, 68 new String [] { "java.lang.String" } ); 69 result = new Attribute ( valueName, value ); 70 } 71 catch( MBeanException e ) 72 { 73 throw new AttributeNotFoundException ( DottedNameStrings.getString(DottedNameStrings.ATTRIBUTE_NOT_FOUND_KEY, valueName )); 75 } 76 catch( ReflectionException e ) 77 { 78 throw new AttributeNotFoundException ( DottedNameStrings.getString(DottedNameStrings.ATTRIBUTE_NOT_FOUND_KEY, valueName )); 80 } 81 return( result ); 82 } 83 84 public Attribute 85 setValue( final ObjectName objectName, final Attribute attr ) throws Exception 86 { 87 90 getMBS().invoke( objectName, 92 getSetPropertyMethodName(), new Object [] { attr }, 93 new String [] { "javax.management.Attribute" } ); 94 95 return( attr ); 96 } 97 98 99 public String [] getAllPropertyNames(ObjectName objectName ) 100 throws java.io.IOException , ReflectionException , InstanceNotFoundException 101 { 102 return getAllPropertyNames( objectName, false ); 103 } 104 public String [] getAllPropertyNames(ObjectName objectName, boolean bIncludingPrefix ) 105 throws java.io.IOException , ReflectionException , InstanceNotFoundException 106 { 107 String [] names = null; 108 109 try 110 { 111 final AttributeList props = (AttributeList )getMBS().invoke( objectName, 112 getGetPropertiesMethodName(), null, 113 null ); 114 names = new String [ props.size() ]; 115 for( int i = 0; i < names.length; ++i ) 116 { 117 final Attribute attr = (Attribute )props.get( i ); 118 if(bIncludingPrefix) 119 names[ i ] = getDottedNamePrefix() + attr.getName(); 120 else 121 names[ i ] = attr.getName(); 122 } 123 } 124 catch( MBeanException e ) 129 { 130 names = new String [ 0 ]; 131 } 132 catch( RuntimeOperationsException e ) 133 { 134 names = new String [ 0 ]; 135 } 136 catch( ReflectionException e ) 137 { 138 names = new String [ 0 ]; 139 } 140 141 return( names ); 142 } 143 144 145 } 146 147 148 | Popular Tags |