1 package org.sapia.soto.jmx.config; 2 3 import org.sapia.soto.ConfigurationException; 4 import org.sapia.soto.jmx.AttributeDescriptor; 5 import org.sapia.soto.jmx.MBeanDescriptor; 6 7 import java.util.ArrayList ; 8 import java.util.List ; 9 10 import javax.management.IntrospectionException ; 11 12 13 22 public class Attributes { 23 private List _includes = new ArrayList (); 24 private List _excludes = new ArrayList (); 25 26 29 public Attributes() { 30 super(); 31 } 32 33 public void init(MBeanDescriptor mbean) 34 throws IntrospectionException , ConfigurationException { 35 Attribute attr; 36 AttributeDescriptor desc; 37 List includes = new ArrayList (); 38 List descs; 39 40 for (int i = 0; i < _includes.size(); i++) { 41 attr = (Attribute) _includes.get(i); 42 43 if (attr.getName() == null) { 44 throw new ConfigurationException( 45 "'name' attribute not specified on 'include' element"); 46 } 47 48 includes.addAll(descs = mbean.getAttributeDescriptorsFor(attr.getName(), 49 attr.getType())); 50 51 for (int j = 0; j < descs.size(); j++) { 52 desc = (AttributeDescriptor) descs.get(j); 53 desc.setDescription(attr.getDescription()); 54 55 if (desc.getWriteMethod() != null) { 56 desc.setWritable(attr.isWritable()); 57 } 58 } 59 } 60 61 for (int i = 0; i < _excludes.size(); i++) { 62 attr = (Attribute) _excludes.get(i); 63 64 if (attr.getName() == null) { 65 throw new ConfigurationException( 66 "'name' attribute not specified on 'exclude' element"); 67 } 68 69 mbean.removeAttributeDescriptorsFor(attr.getName(), attr.getType()); 70 } 71 72 for (int i = 0; i < includes.size(); i++) { 73 mbean.addAttributeDescriptor((AttributeDescriptor) includes.get(i)); 74 } 75 } 76 77 public Attribute createInclude() { 78 Attribute attr = new Attribute(); 79 _includes.add(attr); 80 81 return attr; 82 } 83 84 public Attribute createExclude() { 85 Attribute attr = new Attribute(); 86 _excludes.add(attr); 87 88 return attr; 89 } 90 } 91 | Popular Tags |