1 7 25 26 27 28 package javax.management.modelmbean; 29 30 import java.io.IOException ; 31 import java.io.ObjectInputStream ; 32 import java.io.ObjectOutputStream ; 33 import java.io.ObjectStreamField ; 34 import java.security.AccessController ; 35 import java.security.PrivilegedAction ; 36 37 import javax.management.Descriptor ; 38 import javax.management.DescriptorAccess ; 39 import javax.management.*; 40 import java.lang.reflect.*; 41 42 import com.sun.jmx.mbeanserver.GetPropertyAction; 43 import com.sun.jmx.trace.Trace; 44 45 46 76 77 public class ModelMBeanOperationInfo extends MBeanOperationInfo 78 implements DescriptorAccess 79 { 80 81 private static final long oldSerialVersionUID = 9087646304346171239L; 89 private static final long newSerialVersionUID = 6532732096650090465L; 92 private static final ObjectStreamField [] oldSerialPersistentFields = 95 { 96 new ObjectStreamField ("operationDescriptor", Descriptor .class), 97 new ObjectStreamField ("currClass", String .class) 98 }; 99 private static final ObjectStreamField [] newSerialPersistentFields = 102 { 103 new ObjectStreamField ("operationDescriptor", Descriptor .class) 104 }; 105 private static final long serialVersionUID; 108 111 private static final ObjectStreamField [] serialPersistentFields; 112 private static boolean compat = false; 113 static { 114 try { 115 PrivilegedAction act = new GetPropertyAction("jmx.serial.form"); 116 String form = (String ) AccessController.doPrivileged(act); 117 compat = (form != null && form.equals("1.0")); 118 } catch (Exception e) { 119 } 121 if (compat) { 122 serialPersistentFields = oldSerialPersistentFields; 123 serialVersionUID = oldSerialVersionUID; 124 } else { 125 serialPersistentFields = newSerialPersistentFields; 126 serialVersionUID = newSerialVersionUID; 127 } 128 } 129 132 135 private Descriptor operationDescriptor = createDefaultDescriptor(); 136 137 private static final String currClass = "ModelMBeanOperationInfo"; 138 139 147 148 public ModelMBeanOperationInfo(String description, 149 Method operationMethod) 150 { 151 super(description, operationMethod); 152 if (tracing()) 154 { 155 trace("ModelMBeanOperationInfo(String,Method)","Executed"); 156 } 157 operationDescriptor = createDefaultDescriptor(); 158 159 160 } 161 162 184 185 public ModelMBeanOperationInfo(String description, 186 Method operationMethod, 187 Descriptor descriptor) 188 { 189 190 super(description, operationMethod); 191 if (tracing()) 192 { 193 trace("ModelMBeanOperationInfo(String,Method,Descriptor)","Executed"); 194 } 195 if (descriptor == null) 196 { 197 if (tracing()) 198 { 199 trace("ModelMBeanOperationInfo()","Received null for new descriptor value, setting descriptor to default values"); 200 } 201 operationDescriptor = createDefaultDescriptor(); 202 } else 203 { 204 if (isValid(descriptor)) 205 { 206 operationDescriptor = (Descriptor ) descriptor.clone(); 207 } else 208 { 209 operationDescriptor = createDefaultDescriptor(); 210 throw new RuntimeOperationsException(new IllegalArgumentException ("Invalid descriptor passed in parameter"), ("Exception occured in ModelMBeanOperationInfo constructor")); 211 } 212 } 213 } 214 215 224 225 public ModelMBeanOperationInfo(String name, 226 String description, 227 MBeanParameterInfo[] signature, 228 String type, 229 int impact) 230 { 231 232 super(name, description, signature, type, impact); 233 if (tracing()) 235 { 236 trace("ModelMBeanOperationInfo(String,String,MBeanParameterInfo[],String,int)","Executed"); 237 } 238 operationDescriptor = createDefaultDescriptor(); 239 240 } 241 242 259 260 public ModelMBeanOperationInfo(String name, 261 String description, 262 MBeanParameterInfo[] signature, 263 String type, 264 int impact, 265 Descriptor descriptor) 266 { 267 super(name, description, signature, type, impact); 268 if (tracing()) 269 { 270 trace("ModelMBeanOperationInfo(String,String,MBeanParameterInfo[],String,int,Descriptor)","Executed"); 271 } 272 if (descriptor == null) 273 { 274 if (tracing()) 275 { 276 trace("ModelMBeanOperationInfo()","Received null for new descriptor value, setting descriptor to default values"); 277 } 278 operationDescriptor = createDefaultDescriptor(); 279 } else 280 { 281 if (isValid(descriptor)) 282 { 283 operationDescriptor = (Descriptor ) descriptor.clone(); 284 } else 285 { 286 operationDescriptor = createDefaultDescriptor(); 287 throw new RuntimeOperationsException(new IllegalArgumentException ("Invalid descriptor passed in parameter"), ("Exception occured in ModelMBeanOperationInfo constructor")); 288 } 289 290 } 291 } 292 293 299 300 public ModelMBeanOperationInfo(ModelMBeanOperationInfo inInfo) 301 { 302 super(inInfo.getName(), 303 inInfo.getDescription(), 304 inInfo.getSignature(), 305 inInfo.getReturnType(), 306 inInfo.getImpact()); 307 if (tracing()) 308 { 309 trace("ModelMBeanOperationInfo(ModelMBeanOperationInfo)","Executed"); 310 } 311 Descriptor newDesc = inInfo.getDescriptor(); 312 if (newDesc == null) 313 { 314 operationDescriptor = createDefaultDescriptor(); 315 } else 316 { 317 if (isValid(newDesc)) 318 { 319 operationDescriptor = (Descriptor ) newDesc.clone(); 320 } else 321 { 322 operationDescriptor = createDefaultDescriptor(); 323 throw new RuntimeOperationsException(new IllegalArgumentException ("Invalid descriptor passed in parameter"), ("Exception occured in ModelMBeanOperationInfo constructor")); 324 } 325 326 } 327 } 328 329 333 334 public Object clone () 335 { 336 if (tracing()) 337 { 338 trace("ModelMBeanOperationInfo.clone()","Executed"); 339 } 340 return(new ModelMBeanOperationInfo (this)) ; 341 } 342 343 352 353 public Descriptor getDescriptor() 354 { 355 if (tracing()) 356 { 357 trace("ModelMBeanOperationInfo.getDescriptor()","Executed"); 358 } 359 if (operationDescriptor == null) 360 { 361 operationDescriptor = createDefaultDescriptor(); 362 } 363 364 return((Descriptor ) operationDescriptor.clone()); 365 } 366 367 384 public void setDescriptor(Descriptor inDescriptor) 385 { 386 if (tracing()) 387 { 388 trace("ModelMBeanOperationInfo.setDescriptor(Descriptor)","Executed"); 389 } 390 if (inDescriptor == null) 391 { 392 if (tracing()) 393 { 394 trace("ModelMBeanOperationInfo.setDescriptor()","Received null for new descriptor value, setting descriptor to default values"); 395 } 396 operationDescriptor = createDefaultDescriptor(); 397 } else 398 { 399 if (isValid(inDescriptor)) 400 { 401 operationDescriptor = (Descriptor ) inDescriptor.clone(); 402 } else 403 { 404 throw new RuntimeOperationsException(new IllegalArgumentException ("Invalid descriptor passed in parameter"), ("Exception occured in ModelMBeanOperationInfo setDescriptor")); 405 } 406 } 407 } 408 409 412 public String toString() 413 { 414 if (tracing()) 415 { 416 trace("ModelMBeanConstructorInfo.toString()","Executed"); 417 } 418 String retStr = 419 "ModelMBeanOperationInfo: " + this.getName() + 420 " ; Description: " + this.getDescription() + 421 " ; Descriptor: " + this.getDescriptor() + 422 " ; ReturnType: " + this.getReturnType() + 423 " ; Signature: "; 424 MBeanParameterInfo[] pTypes = this.getSignature(); 425 for (int i=0; i < pTypes.length; i++) 426 { 427 retStr = retStr.concat((pTypes[i]).getType() + ", "); 428 } 429 return retStr; 430 } 431 435 private Descriptor createDefaultDescriptor() 436 { 437 if (tracing()) 438 { 439 trace("ModelMBeanOperationInfo.createDefaultDescriptor()","Executed"); 440 } 441 return new DescriptorSupport (new String [] {"descriptorType=operation", 442 ("name=" + this.getName()), 443 "role=operation", 444 ("displayname=" + this.getName())}); 445 } 446 447 448 458 private boolean isValid(Descriptor inDesc) 459 { 460 boolean results = true; 461 String badField = "none"; 462 if (inDesc == null) 466 { 467 results = false; 468 } 469 470 else if (!inDesc.isValid()) 471 { results = false; 475 } else 476 { 477 if (! ((String )inDesc.getFieldValue("name")).equalsIgnoreCase(this.getName())) 478 { 479 results = false; 480 } 481 if (! ((String )inDesc.getFieldValue("descriptorType")).equalsIgnoreCase("operation")) 482 { 483 results = false; 484 } 485 Object roleValue = inDesc.getFieldValue("role"); 486 if (roleValue == null) 487 { 488 inDesc.setField("role","operation"); 489 } else { 490 final String role = (String )roleValue; 491 if (!(role.equalsIgnoreCase("operation") 492 || role.equalsIgnoreCase("setter") 493 || role.equalsIgnoreCase("getter"))) { 494 results = false; 495 badField="role"; 496 } 497 } 498 499 Object targetValue = inDesc.getFieldValue("targetType"); 500 if (targetValue != null) { 501 if (!(targetValue instanceof java.lang.String )) { 502 results = false; 503 badField="targetType"; 504 505 } 506 } 507 if ((inDesc.getFieldValue("displayName")) == null) 508 { 509 inDesc.setField("displayName",this.getName()); 510 } 511 } 512 if (tracing()) trace("isValid()",("Returning " + results + ": Invalid field is " + badField)); 513 return results; 514 } 515 516 private boolean tracing() 518 { 519 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MODELMBEAN); 521 } 522 523 private void trace(String inClass, String inMethod, String inText) 524 { 525 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MODELMBEAN, inClass, 527 inMethod, Integer.toHexString(this.hashCode()) + " " + inText); 528 } 529 530 private void trace(String inMethod, String inText) 531 { 532 trace(currClass, inMethod, inText); 533 } 534 535 538 private void readObject(ObjectInputStream in) 539 throws IOException , ClassNotFoundException { 540 in.defaultReadObject(); 542 } 543 544 545 548 private void writeObject(ObjectOutputStream out) 549 throws IOException { 550 if (compat) 551 { 552 ObjectOutputStream.PutField fields = out.putFields(); 555 fields.put("operationDescriptor", operationDescriptor); 556 fields.put("currClass", currClass); 557 out.writeFields(); 558 } 559 else 560 { 561 out.defaultWriteObject(); 564 } 565 } 566 567 } 568 | Popular Tags |