0N/A/*
2362N/A * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.management;
0N/A
0N/Aimport java.util.Arrays;
0N/A
0N/A/**
0N/A * <p>The <CODE>MBeanNotificationInfo</CODE> class is used to describe the
0N/A * characteristics of the different notification instances
0N/A * emitted by an MBean, for a given Java class of notification.
0N/A * If an MBean emits notifications that can be instances of different Java classes,
0N/A * then the metadata for that MBean should provide an <CODE>MBeanNotificationInfo</CODE>
0N/A * object for each of these notification Java classes.</p>
0N/A *
0N/A * <p>Instances of this class are immutable. Subclasses may be
0N/A * mutable but this is not recommended.</p>
0N/A *
0N/A * <p>This class extends <CODE>javax.management.MBeanFeatureInfo</CODE>
0N/A * and thus provides <CODE>name</CODE> and <CODE>description</CODE> fields.
0N/A * The <CODE>name</CODE> field should be the fully qualified Java class name of
0N/A * the notification objects described by this class.</p>
0N/A *
0N/A * <p>The <CODE>getNotifTypes</CODE> method returns an array of
0N/A * strings containing the notification types that the MBean may
0N/A * emit. The notification type is a dot-notation string which
0N/A * describes what the emitted notification is about, not the Java
0N/A * class of the notification. A single generic notification class can
0N/A * be used to send notifications of several types. All of these types
0N/A * are returned in the string array result of the
0N/A * <CODE>getNotifTypes</CODE> method.
0N/A *
0N/A * @since 1.5
0N/A */
0N/Apublic class MBeanNotificationInfo extends MBeanFeatureInfo implements Cloneable {
0N/A
0N/A /* Serial version */
0N/A static final long serialVersionUID = -3888371564530107064L;
0N/A
0N/A private static final String[] NO_TYPES = new String[0];
0N/A
0N/A static final MBeanNotificationInfo[] NO_NOTIFICATIONS =
0N/A new MBeanNotificationInfo[0];
0N/A
0N/A /**
0N/A * @serial The different types of the notification.
0N/A */
0N/A private final String[] types;
0N/A
0N/A /** @see MBeanInfo#arrayGettersSafe */
0N/A private final transient boolean arrayGettersSafe;
0N/A
0N/A /**
0N/A * Constructs an <CODE>MBeanNotificationInfo</CODE> object.
0N/A *
0N/A * @param notifTypes The array of strings (in dot notation)
0N/A * containing the notification types that the MBean may emit.
0N/A * This may be null with the same effect as a zero-length array.
0N/A * @param name The fully qualified Java class name of the
0N/A * described notifications.
0N/A * @param description A human readable description of the data.
0N/A */
0N/A public MBeanNotificationInfo(String[] notifTypes,
0N/A String name,
0N/A String description) {
0N/A this(notifTypes, name, description, null);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <CODE>MBeanNotificationInfo</CODE> object.
0N/A *
0N/A * @param notifTypes The array of strings (in dot notation)
0N/A * containing the notification types that the MBean may emit.
0N/A * This may be null with the same effect as a zero-length array.
0N/A * @param name The fully qualified Java class name of the
0N/A * described notifications.
0N/A * @param description A human readable description of the data.
0N/A * @param descriptor The descriptor for the notifications. This may be null
0N/A * which is equivalent to an empty descriptor.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public MBeanNotificationInfo(String[] notifTypes,
0N/A String name,
0N/A String description,
0N/A Descriptor descriptor) {
0N/A super(name, description, descriptor);
0N/A
0N/A /* We do not validate the notifTypes, since the spec just says
0N/A they are dot-separated, not that they must look like Java
0N/A classes. E.g. the spec doesn't forbid "sun.prob.25" as a
0N/A notifType, though it doesn't explicitly allow it
0N/A either. */
0N/A
0N/A if (notifTypes == null)
0N/A notifTypes = NO_TYPES;
0N/A this.types = notifTypes;
0N/A this.arrayGettersSafe =
0N/A MBeanInfo.arrayGettersSafe(this.getClass(),
0N/A MBeanNotificationInfo.class);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a shallow clone of this instance.
0N/A * The clone is obtained by simply calling <tt>super.clone()</tt>,
0N/A * thus calling the default native shallow cloning mechanism
0N/A * implemented by <tt>Object.clone()</tt>.
0N/A * No deeper cloning of any internal field is made.
0N/A */
0N/A public Object clone () {
0N/A try {
0N/A return super.clone() ;
0N/A } catch (CloneNotSupportedException e) {
0N/A // should not happen as this class is cloneable
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the array of strings (in dot notation) containing the
0N/A * notification types that the MBean may emit.
0N/A *
0N/A * @return the array of strings. Changing the returned array has no
0N/A * effect on this MBeanNotificationInfo.
0N/A */
0N/A public String[] getNotifTypes() {
0N/A if (types.length == 0)
0N/A return NO_TYPES;
0N/A else
0N/A return types.clone();
0N/A }
0N/A
0N/A private String[] fastGetNotifTypes() {
0N/A if (arrayGettersSafe)
0N/A return types;
0N/A else
0N/A return getNotifTypes();
0N/A }
0N/A
0N/A public String toString() {
0N/A return
0N/A getClass().getName() + "[" +
0N/A "description=" + getDescription() + ", " +
0N/A "name=" + getName() + ", " +
0N/A "notifTypes=" + Arrays.asList(fastGetNotifTypes()) + ", " +
0N/A "descriptor=" + getDescriptor() +
0N/A "]";
0N/A }
0N/A
0N/A /**
0N/A * Compare this MBeanNotificationInfo to another.
0N/A *
0N/A * @param o the object to compare to.
0N/A *
0N/A * @return true if and only if <code>o</code> is an MBeanNotificationInfo
0N/A * such that its {@link #getName()}, {@link #getDescription()},
0N/A * {@link #getDescriptor()},
0N/A * and {@link #getNotifTypes()} values are equal (not necessarily
0N/A * identical) to those of this MBeanNotificationInfo. Two
0N/A * notification type arrays are equal if their corresponding
0N/A * elements are equal. They are not equal if they have the same
0N/A * elements but in a different order.
0N/A */
0N/A public boolean equals(Object o) {
0N/A if (o == this)
0N/A return true;
0N/A if (!(o instanceof MBeanNotificationInfo))
0N/A return false;
0N/A MBeanNotificationInfo p = (MBeanNotificationInfo) o;
0N/A return (p.getName().equals(getName()) &&
0N/A p.getDescription().equals(getDescription()) &&
0N/A p.getDescriptor().equals(getDescriptor()) &&
0N/A Arrays.equals(p.fastGetNotifTypes(), fastGetNotifTypes()));
0N/A }
0N/A
0N/A public int hashCode() {
0N/A int hash = getName().hashCode();
0N/A for (int i = 0; i < types.length; i++)
0N/A hash ^= types[i].hashCode();
0N/A return hash;
0N/A }
0N/A}