| 1 package org.sapia.soto.jmx.config; 2 3 import org.sapia.soto.ConfigurationException; 4 import org.sapia.soto.jmx.MBeanDescriptor; 5 import org.sapia.soto.jmx.OperationDescriptor; 6 import org.sapia.soto.jmx.ParameterDescriptor; 7 8 import java.util.ArrayList ; 9 import java.util.List ; 10 11 import javax.management.IntrospectionException ; 12 13 14 23 public class Operations { 24 private List _includes = new ArrayList (); 25 private List _excludes = new ArrayList (); 26 27 30 public Operations() { 31 super(); 32 } 33 34 public void init(MBeanDescriptor mbean) 35 throws IntrospectionException , ConfigurationException { 36 Operation operation; 37 OperationDescriptor desc; 38 List includes = new ArrayList (); 39 List descs; 40 41 for (int i = 0; i < _includes.size(); i++) { 42 operation = (Operation) _includes.get(i); 43 44 if (operation.getName() == null) { 45 throw new ConfigurationException( 46 "'name' attribute not specified on 'include' element from JMX operation"); 47 } 48 49 includes.addAll(descs = mbean.getOperationDescriptorsFor( 50 operation.getName(), operation.getSig())); 51 52 for (int j = 0; j < descs.size(); j++) { 53 desc = (OperationDescriptor) descs.get(j); 54 55 if (operation.getDescription() != null) { 56 desc.setDescription(operation.getDescription()); 57 } 58 59 List paramDescs = desc.getParameters(); 60 List params = operation.getParams(); 61 Param param; 62 ParameterDescriptor paramDesc; 63 64 if (paramDescs.size() == params.size()) { 65 for (int k = 0; k < params.size(); k++) { 66 param = (Param) params.get(k); 67 paramDesc = (ParameterDescriptor) paramDescs.get(k); 68 69 if (param.getDescription() != null) { 70 paramDesc.setDescription(param.getDescription()); 71 } 72 73 if (param.getName() != null) { 74 paramDesc.setName(param.getName()); 75 } 76 } 77 } 78 } 79 } 80 81 for (int i = 0; i < _excludes.size(); i++) { 82 operation = (Operation) _excludes.get(i); 83 84 if (operation.getName() == null) { 85 throw new ConfigurationException( 86 "'name' attribute not specified on 'include' element from JMX operation"); 87 } 88 89 mbean.removeOperationDescriptorsFor(operation.getName(), 90 operation.getSig()); 91 } 92 93 for (int i = 0; i < includes.size(); i++) { 94 mbean.addOperationDescriptor((OperationDescriptor) includes.get(i)); 95 } 96 } 97 98 public Operation createInclude() { 99 Operation op = new Operation(); 100 _includes.add(op); 101 102 return op; 103 } 104 105 public Operation createExclude() { 106 Operation op = new Operation(); 107 _excludes.add(op); 108 109 return op; 110 } 111 112 private static void initParams(Operation op, List paramDescs) { 113 ParameterDescriptor desc; 114 List params = op.getParams(); 115 Param p; 116 117 for (int i = 0; i < params.size(); i++) { 118 p = (Param) params.get(i); 119 desc = (ParameterDescriptor) paramDescs.get(i); 120 desc.setDescription(p.getDescription()); 121 desc.setName(p.getName()); 122 } 123 } 124 } 125 | Popular Tags |