1 16 17 18 package org.apache.commons.modeler; 19 20 21 import java.io.Serializable ; 22 23 import javax.management.Descriptor ; 24 import javax.management.MBeanParameterInfo ; 25 import javax.management.modelmbean.ModelMBeanOperationInfo ; 26 27 28 35 36 public class OperationInfo extends FeatureInfo implements Serializable { 37 static final long serialVersionUID = 4418342922072614875L; 38 40 41 44 public OperationInfo() { 45 46 super(); 47 48 } 49 50 51 60 public OperationInfo(String name, boolean getter, String type) { 61 62 super(); 63 setName(name); 64 if (getter) { 65 setDescription("Attribute getter method"); 66 setImpact("INFO"); 67 setReturnType(type); 68 setRole("getter"); 69 } else { 70 setDescription("Attribute setter method"); 71 setImpact("ACTION"); 72 setReturnType("void"); 73 setRole("setter"); 74 addParameter(new ParameterInfo("value", type, 75 "New attribute value")); 76 } 77 78 } 79 80 81 83 84 88 transient ModelMBeanOperationInfo info = null; 89 protected String impact = "UNKNOWN"; 90 protected String role = "operation"; 91 protected String returnType = "void"; protected ParameterInfo parameters[] = new ParameterInfo[0]; 93 94 95 97 98 103 public void setDescription(String description) { 104 super.setDescription(description); 105 this.info = null; 106 } 107 108 109 114 public void setName(String name) { 115 super.setName(name); 116 this.info = null; 117 } 118 119 120 124 public String getImpact() { 125 return (this.impact); 126 } 127 128 public void setImpact(String impact) { 129 if (impact == null) 130 this.impact = null; 131 else 132 this.impact = impact.toUpperCase(); 133 } 134 135 136 140 public String getRole() { 141 return (this.role); 142 } 143 144 public void setRole(String role) { 145 this.role = role; 146 } 147 148 149 153 public String getReturnType() { 154 return (this.returnType); 155 } 156 157 public void setReturnType(String returnType) { 158 this.returnType = returnType; 159 } 160 161 164 public ParameterInfo[] getSignature() { 165 return (this.parameters); 166 } 167 168 170 171 176 public void addParameter(ParameterInfo parameter) { 177 178 synchronized (parameters) { 179 ParameterInfo results[] = new ParameterInfo[parameters.length + 1]; 180 System.arraycopy(parameters, 0, results, 0, parameters.length); 181 results[parameters.length] = parameter; 182 parameters = results; 183 this.info = null; 184 } 185 186 } 187 188 189 193 public ModelMBeanOperationInfo createOperationInfo() { 194 195 if (info != null) 197 return (info); 198 199 ParameterInfo params[] = getSignature(); 201 MBeanParameterInfo parameters[] = 202 new MBeanParameterInfo [params.length]; 203 for (int i = 0; i < params.length; i++) 204 parameters[i] = params[i].createParameterInfo(); 205 int impact = ModelMBeanOperationInfo.UNKNOWN; 206 if ("ACTION".equals(getImpact())) 207 impact = ModelMBeanOperationInfo.ACTION; 208 else if ("ACTION_INFO".equals(getImpact())) 209 impact = ModelMBeanOperationInfo.ACTION_INFO; 210 else if ("INFO".equals(getImpact())) 211 impact = ModelMBeanOperationInfo.INFO; 212 213 info = new ModelMBeanOperationInfo 214 (getName(), getDescription(), parameters, 215 getReturnType(), impact); 216 Descriptor descriptor = info.getDescriptor(); 217 descriptor.removeField("class"); 218 descriptor.setField("role", getRole()); 219 addFields(descriptor); 220 info.setDescriptor(descriptor); 221 return (info); 222 223 } 224 225 226 229 public String toString() { 230 231 StringBuffer sb = new StringBuffer ("OperationInfo["); 232 sb.append("name="); 233 sb.append(name); 234 sb.append(", description="); 235 sb.append(description); 236 sb.append(", returnType="); 237 sb.append(returnType); 238 sb.append(", parameters="); 239 sb.append(parameters.length); 240 sb.append("]"); 241 return (sb.toString()); 242 243 } 244 245 246 } 247 | Popular Tags |