1 package org.sapia.soto.jmx; 2 3 import org.sapia.soto.util.Type; 4 5 import java.lang.reflect.Method ; 6 7 import javax.management.IntrospectionException ; 8 import javax.management.MBeanAttributeInfo ; 9 10 11 26 public class AttributeDescriptor { 27 private String _desc = MBeanDescriptor.DEFAULT_DESC; 28 private String _name; 29 private boolean _isIs; 30 private Method _readable; 31 private Method _writable; 32 33 36 public AttributeDescriptor() { 37 super(); 38 } 39 40 45 public void setDescription(String desc) { 46 _desc = desc; 47 } 48 49 55 public String getAttributeName() { 56 return _name; 57 } 58 59 66 public Method getReadMethod() { 67 return _readable; 68 } 69 70 77 public Method getWriteMethod() { 78 return _writable; 79 } 80 81 public void setWritable(boolean writable) { 82 if (!writable) { 83 _writable = null; 84 } 85 } 86 87 93 public MBeanAttributeInfo getInfo() throws IntrospectionException { 94 return new MBeanAttributeInfo (_name, _desc, _readable, _writable); 95 } 96 97 102 void setAttributeName(String name) { 103 _name = name; 104 } 105 106 112 void setBoolean(boolean bool) { 113 _isIs = bool; 114 } 115 116 122 void setWritable(Method writable) { 123 _writable = writable; 124 } 125 126 131 public String getType() { 132 if (_readable != null) { 133 if (Type.hasTypeForTypeName(_readable.getReturnType().getName())) { 134 return Type.getTypeForTypeName(_readable.getReturnType().getName()) 135 .getName(); 136 } else { 137 return _readable.getReturnType().getName(); 138 } 139 } else { 140 if (Type.hasTypeForTypeName(_writable.getParameterTypes()[0].getName())) { 141 return Type.getTypeForTypeName(_writable.getParameterTypes()[0].getName()) 142 .getName(); 143 } else { 144 return _writable.getParameterTypes()[0].getName(); 145 } 146 } 147 } 148 149 155 void setReadable(Method readable) { 156 _readable = readable; 157 } 158 159 public String toString() { 160 return "[ name=" + _name + ", description=" + _desc + ", isIs=" + _isIs + 161 ", readable=" + _readable + ", writable=" + _writable + " ]"; 162 } 163 } 164 | Popular Tags |