1 22 23 package org.jboss.mx.metadata.xb; 24 25 import javax.management.Descriptor ; 26 import javax.management.NotCompliantMBeanException ; 27 import javax.management.modelmbean.ModelMBeanAttributeInfo ; 28 import javax.management.modelmbean.DescriptorSupport ; 29 import javax.xml.namespace.QName ; 30 31 import org.jboss.xb.binding.GenericValueContainer; 32 import org.jboss.xb.binding.JBossXBRuntimeException; 33 import org.jboss.logging.Logger; 34 import org.jboss.mx.modelmbean.ModelMBeanConstants; 35 36 41 public class ModelMBeanAttributeInfoContainer 42 implements GenericValueContainer 43 { 44 private static final Logger log = Logger.getLogger(ModelMBeanAttributeInfoContainer.class); 45 private String name; 46 private String type; 47 private String access; 48 private String getMethod; 49 private String setMethod; 50 private String description; 51 private Object value; 52 private Object defaultValue; 53 private Descriptor descriptor; 54 55 public Object getValue() 56 { 57 return value; 58 } 59 60 public void setValue(Object value) 61 { 62 this.value = value; 63 } 64 65 public Object getDefaultValue() 66 { 67 return defaultValue; 68 } 69 70 public void setDefaultValue(Object defaultValue) 71 { 72 this.defaultValue = defaultValue; 73 } 74 75 public String getType() 76 { 77 return type; 78 } 79 80 public void setType(String type) 81 { 82 this.type = type; 83 } 84 85 public String getAccess() 86 { 87 return access; 88 } 89 90 public void setAccess(String access) 91 { 92 this.access = access; 93 } 94 95 public String getGetMethod() 96 { 97 return getMethod; 98 } 99 100 public void setGetMethod(String getMethod) 101 { 102 this.getMethod = getMethod; 103 } 104 105 public String getSetMethod() 106 { 107 return setMethod; 108 } 109 110 public void setSetMethod(String setMethod) 111 { 112 this.setMethod = setMethod; 113 } 114 115 public Descriptor getDescriptors() 116 { 117 return descriptor; 118 } 119 public void setDescriptors(Descriptor descriptor) 120 { 121 this.descriptor = descriptor; 122 } 123 124 public Object instantiate() 125 { 126 try 127 { 128 ModelMBeanAttributeInfo info = buildAttributeInfo(); 129 return info; 130 } 131 catch(NotCompliantMBeanException e) 132 { 133 throw new JBossXBRuntimeException(e); 134 } 135 } 136 137 public void addChild(QName name, Object value) 138 { 139 log.debug("addChild, " + name + "," + value); 140 String localName = name.getLocalPart(); 141 if("name".equals(localName)) 142 { 143 this.name = (String ) value; 144 } 145 if("type".equals(localName)) 146 { 147 this.type = (String ) value; 148 } 149 if("access".equals(localName)) 150 { 151 this.access = (String ) value; 152 } 153 if("getMethod".equals(localName)) 154 { 155 this.getMethod = (String ) value; 156 } 157 if("setMethod".equals(localName)) 158 { 159 this.setMethod = (String ) value; 160 } 161 if("value".equals(localName)) 162 { 163 this.value = value; 164 } 165 if("default".equals(localName)) 166 { 167 this.defaultValue = value; 168 } 169 if("description".equals(localName)) 170 { 171 this.description = (String ) value; 172 } 173 } 174 public Class getTargetClass() 175 { 176 return ModelMBeanAttributeInfo .class; 177 } 178 179 protected ModelMBeanAttributeInfo buildAttributeInfo() 180 throws NotCompliantMBeanException 181 { 182 if (descriptor == null) 183 { 184 descriptor = new DescriptorSupport (); 185 } 186 if (descriptor.getFieldValue(ModelMBeanConstants.NAME) == null) 187 { 188 descriptor.setField(ModelMBeanConstants.NAME, name); 189 } 190 if (descriptor.getFieldValue(ModelMBeanConstants.DESCRIPTOR_TYPE) == null) 191 { 192 descriptor.setField(ModelMBeanConstants.DESCRIPTOR_TYPE, ModelMBeanConstants.ATTRIBUTE_DESCRIPTOR); 193 } 194 195 if (value != null) 196 { 197 descriptor.setField(ModelMBeanConstants.CACHED_VALUE, value); 198 } 199 if (defaultValue != null) 200 { 201 descriptor.setField(ModelMBeanConstants.DEFAULT, defaultValue); 202 } 203 204 if (getMethod != null) 205 { 206 descriptor.setField(ModelMBeanConstants.GET_METHOD, getMethod); 207 } 208 if (setMethod != null) 209 { 210 descriptor.setField(ModelMBeanConstants.SET_METHOD, setMethod); 211 } 212 213 boolean isReadable = true; 215 boolean isWritable = true; 216 if (access.equalsIgnoreCase("read-only")) 217 { 218 isWritable = false; 219 } 220 else if (access.equalsIgnoreCase("write-only")) 221 { 222 isReadable = false; 223 } 224 225 ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo ( 226 name, type, description, isReadable, isWritable, false, descriptor 227 ); 228 return info; 229 } 230 231 } 232 | Popular Tags |