1 /* 2 * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.management; 27 28 import java.util.Objects; 29 30 /** 31 * Describes an argument of an operation exposed by an MBean. 32 * Instances of this class are immutable. Subclasses may be mutable 33 * but this is not recommended. 34 * 35 * @since 1.5 36 */ 37 public class MBeanParameterInfo extends MBeanFeatureInfo implements Cloneable { 38 39 /* Serial version */ 40 static final long serialVersionUID = 7432616882776782338L; 41 42 /* All zero-length arrays are interchangeable. */ 43 static final MBeanParameterInfo[] NO_PARAMS = new MBeanParameterInfo[0]; 44 45 /** 46 * @serial The type or class name of the data. 47 */ 48 private final String type; 49 50 51 /** 52 * Constructs an <CODE>MBeanParameterInfo</CODE> object. 53 * 54 * @param name The name of the data 55 * @param type The type or class name of the data 56 * @param description A human readable description of the data. Optional. 57 */ 58 public MBeanParameterInfo(String name, 59 String type, 60 String description) { 61 this(name, type, description, (Descriptor) null); 62 } 63 64 /** 65 * Constructs an <CODE>MBeanParameterInfo</CODE> object. 66 * 67 * @param name The name of the data 68 * @param type The type or class name of the data 69 * @param description A human readable description of the data. Optional. 70 * @param descriptor The descriptor for the operation. This may be null 71 * which is equivalent to an empty descriptor. 72 * 73 * @since 1.6 74 */ 75 public MBeanParameterInfo(String name, 76 String type, 77 String description, 78 Descriptor descriptor) { 79 super(name, description, descriptor); 80 81 this.type = type; 82 } 83 84 85 /** 86 * <p>Returns a shallow clone of this instance. 87 * The clone is obtained by simply calling <tt>super.clone()</tt>, 88 * thus calling the default native shallow cloning mechanism 89 * implemented by <tt>Object.clone()</tt>. 90 * No deeper cloning of any internal field is made.</p> 91 * 92 * <p>Since this class is immutable, cloning is chiefly of 93 * interest to subclasses.</p> 94 */ 95 public Object clone () { 96 try { 97 return super.clone() ; 98 } catch (CloneNotSupportedException e) { 99 // should not happen as this class is cloneable 100 return null; 101 } 102 } 103 104 /** 105 * Returns the type or class name of the data. 106 * 107 * @return the type string. 108 */ 109 public String getType() { 110 return type; 111 } 112 113 public String toString() { 114 return 115 getClass().getName() + "[" + 116 "description=" + getDescription() + ", " + 117 "name=" + getName() + ", " + 118 "type=" + getType() + ", " + 119 "descriptor=" + getDescriptor() + 120 "]"; 121 } 122 123 /** 124 * Compare this MBeanParameterInfo to another. 125 * 126 * @param o the object to compare to. 127 * 128 * @return true if and only if <code>o</code> is an MBeanParameterInfo such 129 * that its {@link #getName()}, {@link #getType()}, 130 * {@link #getDescriptor()}, and {@link 131 * #getDescription()} values are equal (not necessarily identical) 132 * to those of this MBeanParameterInfo. 133 */ 134 public boolean equals(Object o) { 135 if (o == this) 136 return true; 137 if (!(o instanceof MBeanParameterInfo)) 138 return false; 139 MBeanParameterInfo p = (MBeanParameterInfo) o; 140 return (p.getName().equals(getName()) && 141 p.getType().equals(getType()) && 142 p.getDescription().equals(getDescription()) && 143 p.getDescriptor().equals(getDescriptor())); 144 } 145 146 public int hashCode() { 147 return Objects.hash(getName(), getType()); 148 } 149 }