/* * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package javax.management; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.io.StreamCorruptedException; import java.util.Objects; /** *
Provides general information for an MBean descriptor object. * The feature described can be an attribute, an operation, a * parameter, or a notification. Instances of this class are * immutable. Subclasses may be mutable but this is not * recommended.
* * @since 1.5 */ public class MBeanFeatureInfo implements Serializable, DescriptorRead { /* Serial version */ static final long serialVersionUID = 3952882688968447265L; /** * The name of the feature. It is recommended that subclasses call * {@link #getName} rather than reading this field, and that they * not change it. * * @serial The name of the feature. */ protected String name; /** * The human-readable description of the feature. It is * recommended that subclasses call {@link #getDescription} rather * than reading this field, and that they not change it. * * @serial The human-readable description of the feature. */ protected String description; /** * @serial The Descriptor for this MBeanFeatureInfo. This field * can be null, which is equivalent to an empty Descriptor. */ private transient Descriptor descriptor; /** * Constructs anMBeanFeatureInfo
object. This
* constructor is equivalent to {@code MBeanFeatureInfo(name,
* description, (Descriptor) null}.
*
* @param name The name of the feature.
* @param description A human readable description of the feature.
*/
public MBeanFeatureInfo(String name, String description) {
this(name, description, null);
}
/**
* Constructs an MBeanFeatureInfo
object.
*
* @param name The name of the feature.
* @param description A human readable description of the feature.
* @param descriptor The descriptor for the feature. This may be null
* which is equivalent to an empty descriptor.
*
* @since 1.6
*/
public MBeanFeatureInfo(String name, String description,
Descriptor descriptor) {
this.name = name;
this.description = description;
this.descriptor = descriptor;
}
/**
* Returns the name of the feature.
*
* @return the name of the feature.
*/
public String getName() {
return name;
}
/**
* Returns the human-readable description of the feature.
*
* @return the human-readable description of the feature.
*/
public String getDescription() {
return description;
}
/**
* Returns the descriptor for the feature. Changing the returned value
* will have no affect on the original descriptor.
*
* @return a descriptor that is either immutable or a copy of the original.
*
* @since 1.6
*/
public Descriptor getDescriptor() {
return (Descriptor) ImmutableDescriptor.nonNullDescriptor(descriptor).clone();
}
/**
* Compare this MBeanFeatureInfo to another.
*
* @param o the object to compare to.
*
* @return true if and only if o
is an MBeanFeatureInfo such
* that its {@link #getName()}, {@link #getDescription()}, and
* {@link #getDescriptor()}
* values are equal (not necessarily identical) to those of this
* MBeanFeatureInfo.
*/
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof MBeanFeatureInfo))
return false;
MBeanFeatureInfo p = (MBeanFeatureInfo) o;
return (Objects.equals(p.getName(), getName()) &&
Objects.equals(p.getDescription(), getDescription()) &&
Objects.equals(p.getDescriptor(), getDescriptor()));
}
public int hashCode() {
return getName().hashCode() ^ getDescription().hashCode() ^
getDescriptor().hashCode();
}
/**
* Serializes an {@link MBeanFeatureInfo} to an {@link ObjectOutputStream}.
* @serialData
* For compatibility reasons, an object of this class is serialized as follows.
* * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()} * is called first to serialize the object except the field {@code descriptor} * which is declared as transient. The field {@code descriptor} is serialized * as follows: *
* The method {@link ObjectInputStream#defaultReadObject defaultReadObject()} * is called first to deserialize the object except the field * {@code descriptor}, which is not serialized in the default way. Then the method * {@link ObjectInputStream#read read()} is called to read a byte, the field * {@code descriptor} is deserialized according to the value of the byte value: *