jdk/src/java.management/share/classes/javax/management/modelmbean/ModelMBeanNotificationInfo.java
changeset 43235 da1786d695b6
parent 25859 3317bb8137f4
child 44858 7183899b064b
equal deleted inserted replaced
43234:cb2a6851b837 43235:da1786d695b6
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    36 import java.io.IOException;
    36 import java.io.IOException;
    37 import java.io.ObjectInputStream;
    37 import java.io.ObjectInputStream;
    38 import java.io.ObjectOutputStream;
    38 import java.io.ObjectOutputStream;
    39 import java.io.ObjectStreamField;
    39 import java.io.ObjectStreamField;
    40 import java.security.AccessController;
    40 import java.security.AccessController;
    41 import java.util.logging.Level;
    41 import java.lang.System.Logger.Level;
    42 
    42 
    43 import javax.management.Descriptor;
    43 import javax.management.Descriptor;
    44 import javax.management.DescriptorAccess;
    44 import javax.management.DescriptorAccess;
    45 import javax.management.MBeanNotificationInfo;
    45 import javax.management.MBeanNotificationInfo;
    46 import javax.management.RuntimeOperationsException;
    46 import javax.management.RuntimeOperationsException;
   197     public ModelMBeanNotificationInfo(String[] notifTypes,
   197     public ModelMBeanNotificationInfo(String[] notifTypes,
   198                                       String name,
   198                                       String name,
   199                                       String description,
   199                                       String description,
   200                                       Descriptor descriptor) {
   200                                       Descriptor descriptor) {
   201         super(notifTypes, name, description);
   201         super(notifTypes, name, description);
   202         if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   202         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   203             MODELMBEAN_LOGGER.logp(Level.FINER,
   203             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   204                     ModelMBeanNotificationInfo.class.getName(),
       
   205                     "ModelMBeanNotificationInfo", "Entry");
       
   206         }
   204         }
   207         notificationDescriptor = validDescriptor(descriptor);
   205         notificationDescriptor = validDescriptor(descriptor);
   208     }
   206     }
   209 
   207 
   210     /**
   208     /**
   223     /**
   221     /**
   224      * Creates and returns a new ModelMBeanNotificationInfo which is a
   222      * Creates and returns a new ModelMBeanNotificationInfo which is a
   225      * duplicate of this ModelMBeanNotificationInfo.
   223      * duplicate of this ModelMBeanNotificationInfo.
   226      **/
   224      **/
   227     public Object clone () {
   225     public Object clone () {
   228         if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   226         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   229             MODELMBEAN_LOGGER.logp(Level.FINER,
   227             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   230                     ModelMBeanNotificationInfo.class.getName(),
       
   231                     "clone()", "Entry");
       
   232         }
   228         }
   233         return(new ModelMBeanNotificationInfo(this));
   229         return(new ModelMBeanNotificationInfo(this));
   234     }
   230     }
   235 
   231 
   236     /**
   232     /**
   241      * ModelMBeanNotificationInfo object.
   237      * ModelMBeanNotificationInfo object.
   242      *
   238      *
   243      * @see #setDescriptor
   239      * @see #setDescriptor
   244      **/
   240      **/
   245     public Descriptor getDescriptor() {
   241     public Descriptor getDescriptor() {
   246         if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   242         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   247             MODELMBEAN_LOGGER.logp(Level.FINER,
   243             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   248                     ModelMBeanNotificationInfo.class.getName(),
       
   249                     "getDescriptor()", "Entry");
       
   250         }
   244         }
   251 
   245 
   252         if (notificationDescriptor == null) {
   246         if (notificationDescriptor == null) {
   253             // Dead code. Should never happen.
   247             // Dead code. Should never happen.
   254             if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   248             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   255                 MODELMBEAN_LOGGER.logp(Level.FINER,
   249                 MODELMBEAN_LOGGER.log(Level.TRACE,
   256                         ModelMBeanNotificationInfo.class.getName(),
   250                         "Descriptor value is null, " +
   257                         "getDescriptor()", "Descriptor value is null, " +
       
   258                         "setting descriptor to default values");
   251                         "setting descriptor to default values");
   259             }
   252             }
   260             notificationDescriptor = validDescriptor(null);
   253             notificationDescriptor = validDescriptor(null);
   261         }
   254         }
   262 
   255 
   279      * {@link IllegalArgumentException} for invalid Descriptor.
   272      * {@link IllegalArgumentException} for invalid Descriptor.
   280      *
   273      *
   281      * @see #getDescriptor
   274      * @see #getDescriptor
   282      **/
   275      **/
   283     public void setDescriptor(Descriptor inDescriptor) {
   276     public void setDescriptor(Descriptor inDescriptor) {
   284         if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   277         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   285             MODELMBEAN_LOGGER.logp(Level.FINER,
   278             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   286                     ModelMBeanNotificationInfo.class.getName(),
       
   287                     "setDescriptor(Descriptor)", "Entry");
       
   288         }
   279         }
   289         notificationDescriptor = validDescriptor(inDescriptor);
   280         notificationDescriptor = validDescriptor(inDescriptor);
   290     }
   281     }
   291 
   282 
   292     /**
   283     /**
   294      * ModelMBeanNotificationInfo.
   285      * ModelMBeanNotificationInfo.
   295      *
   286      *
   296      * @return a string describing this object.
   287      * @return a string describing this object.
   297      **/
   288      **/
   298     public String toString() {
   289     public String toString() {
   299         if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   290         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   300             MODELMBEAN_LOGGER.logp(Level.FINER,
   291             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   301                     ModelMBeanNotificationInfo.class.getName(),
       
   302                     "toString()", "Entry");
       
   303         }
   292         }
   304 
   293 
   305         final StringBuilder retStr = new StringBuilder();
   294         final StringBuilder retStr = new StringBuilder();
   306 
   295 
   307         retStr.append("ModelMBeanNotificationInfo: ")
   296         retStr.append("ModelMBeanNotificationInfo: ")
   340     private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
   329     private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
   341         Descriptor clone;
   330         Descriptor clone;
   342         boolean defaulted = (in == null);
   331         boolean defaulted = (in == null);
   343         if (defaulted) {
   332         if (defaulted) {
   344             clone = new DescriptorSupport();
   333             clone = new DescriptorSupport();
   345             MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
   334             MODELMBEAN_LOGGER.log(Level.TRACE, "Null Descriptor, creating new.");
   346         } else {
   335         } else {
   347             clone = (Descriptor) in.clone();
   336             clone = (Descriptor) in.clone();
   348         }
   337         }
   349 
   338 
   350         //Setting defaults.
   339         //Setting defaults.
   351         if (defaulted && clone.getFieldValue("name")==null) {
   340         if (defaulted && clone.getFieldValue("name")==null) {
   352             clone.setField("name", this.getName());
   341             clone.setField("name", this.getName());
   353             MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
   342             MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor name to " + this.getName());
   354         }
   343         }
   355         if (defaulted && clone.getFieldValue("descriptorType")==null) {
   344         if (defaulted && clone.getFieldValue("descriptorType")==null) {
   356             clone.setField("descriptorType", "notification");
   345             clone.setField("descriptorType", "notification");
   357             MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"notification\"");
   346             MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting descriptorType to \"notification\"");
   358         }
   347         }
   359         if (clone.getFieldValue("displayName") == null) {
   348         if (clone.getFieldValue("displayName") == null) {
   360             clone.setField("displayName",this.getName());
   349             clone.setField("displayName",this.getName());
   361             MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName());
   350             MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor displayName to " + this.getName());
   362         }
   351         }
   363         if (clone.getFieldValue("severity") == null) {
   352         if (clone.getFieldValue("severity") == null) {
   364             clone.setField("severity", "6");
   353             clone.setField("severity", "6");
   365             MODELMBEAN_LOGGER.finer("Defaulting Descriptor severity field to 6");
   354             MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor severity field to 6");
   366         }
   355         }
   367 
   356 
   368         //Checking validity
   357         //Checking validity
   369         if (!clone.isValid()) {
   358         if (!clone.isValid()) {
   370              throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
   359              throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),