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.io.IOException;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.Serializable;
0N/Aimport java.io.StreamCorruptedException;
0N/A
0N/A/**
0N/A * <p>Provides general information for an MBean descriptor object.
0N/A * The feature described can be an attribute, an operation, a
0N/A * parameter, or a notification. Instances of this class are
0N/A * immutable. Subclasses may be mutable but this is not
0N/A * recommended.</p>
0N/A *
0N/A * @since 1.5
0N/A */
0N/Apublic class MBeanFeatureInfo implements Serializable, DescriptorRead {
0N/A
0N/A
0N/A /* Serial version */
0N/A static final long serialVersionUID = 3952882688968447265L;
0N/A
0N/A /**
0N/A * The name of the feature. It is recommended that subclasses call
0N/A * {@link #getName} rather than reading this field, and that they
0N/A * not change it.
0N/A *
0N/A * @serial The name of the feature.
0N/A */
0N/A protected String name;
0N/A
0N/A /**
0N/A * The human-readable description of the feature. It is
0N/A * recommended that subclasses call {@link #getDescription} rather
0N/A * than reading this field, and that they not change it.
0N/A *
0N/A * @serial The human-readable description of the feature.
0N/A */
0N/A protected String description;
0N/A
0N/A /**
0N/A * @serial The Descriptor for this MBeanFeatureInfo. This field
0N/A * can be null, which is equivalent to an empty Descriptor.
0N/A */
0N/A private transient Descriptor descriptor;
0N/A
0N/A
0N/A /**
0N/A * Constructs an <CODE>MBeanFeatureInfo</CODE> object. This
0N/A * constructor is equivalent to {@code MBeanFeatureInfo(name,
0N/A * description, (Descriptor) null}.
0N/A *
0N/A * @param name The name of the feature.
0N/A * @param description A human readable description of the feature.
0N/A */
0N/A public MBeanFeatureInfo(String name, String description) {
0N/A this(name, description, null);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <CODE>MBeanFeatureInfo</CODE> object.
0N/A *
0N/A * @param name The name of the feature.
0N/A * @param description A human readable description of the feature.
0N/A * @param descriptor The descriptor for the feature. 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 MBeanFeatureInfo(String name, String description,
0N/A Descriptor descriptor) {
0N/A this.name = name;
0N/A this.description = description;
0N/A this.descriptor = descriptor;
0N/A }
0N/A
0N/A /**
0N/A * Returns the name of the feature.
0N/A *
0N/A * @return the name of the feature.
0N/A */
0N/A public String getName() {
0N/A return name;
0N/A }
0N/A
0N/A /**
0N/A * Returns the human-readable description of the feature.
0N/A *
0N/A * @return the human-readable description of the feature.
0N/A */
0N/A public String getDescription() {
0N/A return description;
0N/A }
0N/A
0N/A /**
0N/A * Returns the descriptor for the feature. Changing the returned value
0N/A * will have no affect on the original descriptor.
0N/A *
0N/A * @return a descriptor that is either immutable or a copy of the original.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public Descriptor getDescriptor() {
0N/A return (Descriptor) ImmutableDescriptor.nonNullDescriptor(descriptor).clone();
0N/A }
0N/A
0N/A /**
0N/A * Compare this MBeanFeatureInfo 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 MBeanFeatureInfo such
0N/A * that its {@link #getName()}, {@link #getDescription()}, and
0N/A * {@link #getDescriptor()}
0N/A * values are equal (not necessarily identical) to those of this
0N/A * MBeanFeatureInfo.
0N/A */
0N/A public boolean equals(Object o) {
0N/A if (o == this)
0N/A return true;
0N/A if (!(o instanceof MBeanFeatureInfo))
0N/A return false;
0N/A MBeanFeatureInfo p = (MBeanFeatureInfo) o;
0N/A return (p.getName().equals(getName()) &&
0N/A p.getDescription().equals(getDescription()) &&
0N/A p.getDescriptor().equals(getDescriptor()));
0N/A }
0N/A
0N/A public int hashCode() {
0N/A return getName().hashCode() ^ getDescription().hashCode() ^
0N/A getDescriptor().hashCode();
0N/A }
0N/A
0N/A /**
0N/A * Serializes an {@link MBeanFeatureInfo} to an {@link ObjectOutputStream}.
0N/A * @serialData
0N/A * For compatibility reasons, an object of this class is serialized as follows.
0N/A * <ul>
0N/A * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()}
0N/A * is called first to serialize the object except the field {@code descriptor}
0N/A * which is declared as transient. The field {@code descriptor} is serialized
0N/A * as follows:
0N/A * <ul>
0N/A * <li>If {@code descriptor} is an instance of the class
0N/A * {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write
0N/A * write(int val)} is called to write a byte with the value {@code 1},
0N/A * then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)}
0N/A * is called twice to serialize the field names and the field values of the
0N/A * {@code descriptor}, respectively as a {@code String[]} and an
0N/A * {@code Object[]};</li>
0N/A * <li>Otherwise, the method {@link ObjectOutputStream#write write(int val)}
0N/A * is called to write a byte with the value {@code 0}, then the method
0N/A * {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called
0N/A * to serialize directly the field {@code descriptor}.
0N/A * </ul>
0N/A * </ul>
0N/A * @since 1.6
0N/A */
0N/A private void writeObject(ObjectOutputStream out) throws IOException {
0N/A out.defaultWriteObject();
0N/A
0N/A if (descriptor != null &&
0N/A descriptor.getClass() == ImmutableDescriptor.class) {
0N/A
0N/A out.write(1);
0N/A
0N/A final String[] names = descriptor.getFieldNames();
0N/A
0N/A out.writeObject(names);
0N/A out.writeObject(descriptor.getFieldValues(names));
0N/A } else {
0N/A out.write(0);
0N/A
0N/A out.writeObject(descriptor);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Deserializes an {@link MBeanFeatureInfo} from an {@link ObjectInputStream}.
0N/A * @serialData
0N/A * For compatibility reasons, an object of this class is deserialized as follows.
0N/A * <ul>
0N/A * The method {@link ObjectInputStream#defaultReadObject defaultReadObject()}
0N/A * is called first to deserialize the object except the field
0N/A * {@code descriptor}, which is not serialized in the default way. Then the method
0N/A * {@link ObjectInputStream#read read()} is called to read a byte, the field
0N/A * {@code descriptor} is deserialized according to the value of the byte value:
0N/A * <ul>
0N/A * <li>1. The method {@link ObjectInputStream#readObject readObject()}
0N/A * is called twice to obtain the field names (a {@code String[]}) and
0N/A * the field values (a {@code Object[]}) of the {@code descriptor}.
0N/A * The two obtained values then are used to construct
0N/A * an {@link ImmutableDescriptor} instance for the field
0N/A * {@code descriptor};</li>
0N/A * <li>0. The value for the field {@code descriptor} is obtained directly
0N/A * by calling the method {@link ObjectInputStream#readObject readObject()}.
0N/A * If the obtained value is null, the field {@code descriptor} is set to
0N/A * {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};</li>
0N/A * <li>-1. This means that there is no byte to read and that the object is from
0N/A * an earlier version of the JMX API. The field {@code descriptor} is set
0N/A * to {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}</li>
0N/A * <li>Any other value. A {@link StreamCorruptedException} is thrown.</li>
0N/A * </ul>
0N/A * </ul>
0N/A * @since 1.6
0N/A */
0N/A private void readObject(ObjectInputStream in)
0N/A throws IOException, ClassNotFoundException {
0N/A
0N/A in.defaultReadObject();
0N/A
0N/A switch (in.read()) {
0N/A case 1:
0N/A final String[] names = (String[])in.readObject();
0N/A
0N/A if (names.length == 0) {
0N/A descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
0N/A } else {
0N/A final Object[] values = (Object[])in.readObject();
0N/A descriptor = new ImmutableDescriptor(names, values);
0N/A }
0N/A
0N/A break;
0N/A case 0:
0N/A descriptor = (Descriptor)in.readObject();
0N/A
0N/A if (descriptor == null) {
0N/A descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
0N/A }
0N/A
0N/A break;
0N/A case -1: // from an earlier version of the JMX API
0N/A descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
0N/A
0N/A break;
0N/A default:
0N/A throw new StreamCorruptedException("Got unexpected byte.");
0N/A }
0N/A }
0N/A}