| 1 |
772 |
jeremybenn |
/* MBeanConstructorInfo.java -- Information about a bean's constructor.
|
| 2 |
|
|
Copyright (C) 2006 Free Software Foundation, Inc.
|
| 3 |
|
|
|
| 4 |
|
|
This file is part of GNU Classpath.
|
| 5 |
|
|
|
| 6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
| 7 |
|
|
it under the terms of the GNU General Public License as published by
|
| 8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
| 9 |
|
|
any later version.
|
| 10 |
|
|
|
| 11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
| 12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
|
|
General Public License for more details.
|
| 15 |
|
|
|
| 16 |
|
|
You should have received a copy of the GNU General Public License
|
| 17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
| 18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
| 19 |
|
|
02110-1301 USA.
|
| 20 |
|
|
|
| 21 |
|
|
Linking this library statically or dynamically with other modules is
|
| 22 |
|
|
making a combined work based on this library. Thus, the terms and
|
| 23 |
|
|
conditions of the GNU General Public License cover the whole
|
| 24 |
|
|
combination.
|
| 25 |
|
|
|
| 26 |
|
|
As a special exception, the copyright holders of this library give you
|
| 27 |
|
|
permission to link this library with independent modules to produce an
|
| 28 |
|
|
executable, regardless of the license terms of these independent
|
| 29 |
|
|
modules, and to copy and distribute the resulting executable under
|
| 30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
| 31 |
|
|
independent module, the terms and conditions of the license of that
|
| 32 |
|
|
module. An independent module is a module which is not derived from
|
| 33 |
|
|
or based on this library. If you modify this library, you may extend
|
| 34 |
|
|
this exception to your version of the library, but you are not
|
| 35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
| 36 |
|
|
exception statement from your version. */
|
| 37 |
|
|
|
| 38 |
|
|
package javax.management;
|
| 39 |
|
|
|
| 40 |
|
|
import java.lang.reflect.Constructor;
|
| 41 |
|
|
import java.lang.reflect.Type;
|
| 42 |
|
|
|
| 43 |
|
|
import java.util.Arrays;
|
| 44 |
|
|
|
| 45 |
|
|
/**
|
| 46 |
|
|
* Describes the constructors of a management bean.
|
| 47 |
|
|
* The information in this class is immutable as standard.
|
| 48 |
|
|
* Of course, subclasses may change this, but this
|
| 49 |
|
|
* behaviour is not recommended.
|
| 50 |
|
|
*
|
| 51 |
|
|
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
| 52 |
|
|
* @since 1.5
|
| 53 |
|
|
*/
|
| 54 |
|
|
public class MBeanConstructorInfo
|
| 55 |
|
|
extends MBeanFeatureInfo
|
| 56 |
|
|
implements Cloneable
|
| 57 |
|
|
{
|
| 58 |
|
|
|
| 59 |
|
|
/**
|
| 60 |
|
|
* Compatible with JDK 1.5
|
| 61 |
|
|
*/
|
| 62 |
|
|
private static final long serialVersionUID = 4433990064191844427L;
|
| 63 |
|
|
|
| 64 |
|
|
/**
|
| 65 |
|
|
* The signature of the constructor i.e. the argument types.
|
| 66 |
|
|
*/
|
| 67 |
|
|
private MBeanParameterInfo[] signature;
|
| 68 |
|
|
|
| 69 |
|
|
/**
|
| 70 |
|
|
* Constructs a @link{MBeanConstructorInfo} with the specified
|
| 71 |
|
|
* description using the given constructor. Each parameter is
|
| 72 |
|
|
* described merely by its type; the name and description are
|
| 73 |
|
|
* <code>null</code>.
|
| 74 |
|
|
*
|
| 75 |
|
|
* @param desc a description of the attribute.
|
| 76 |
|
|
* @param cons the constructor.
|
| 77 |
|
|
*/
|
| 78 |
|
|
// API issue with lack of <?> on Constructor
|
| 79 |
|
|
@SuppressWarnings("unchecked")
|
| 80 |
|
|
public MBeanConstructorInfo(String desc, Constructor cons)
|
| 81 |
|
|
{
|
| 82 |
|
|
super(cons.getName(), desc);
|
| 83 |
|
|
Type[] paramTypes = cons.getGenericParameterTypes();
|
| 84 |
|
|
signature = new MBeanParameterInfo[paramTypes.length];
|
| 85 |
|
|
for (int a = 0; a < paramTypes.length; ++a)
|
| 86 |
|
|
{
|
| 87 |
|
|
Type t = paramTypes[a];
|
| 88 |
|
|
if (t instanceof Class)
|
| 89 |
|
|
signature[a] = new MBeanParameterInfo(null,
|
| 90 |
|
|
((Class<?>) t).getName(),
|
| 91 |
|
|
null);
|
| 92 |
|
|
else
|
| 93 |
|
|
signature[a] = new MBeanParameterInfo(null, t.toString(), null);
|
| 94 |
|
|
}
|
| 95 |
|
|
}
|
| 96 |
|
|
|
| 97 |
|
|
/**
|
| 98 |
|
|
* Constructs a @link{MBeanConstructorInfo} with the specified
|
| 99 |
|
|
* name, description and parameter information. A <code>null</code>
|
| 100 |
|
|
* value for the parameter information is the same as passing in
|
| 101 |
|
|
* an empty array. A copy of the parameter array is taken, so
|
| 102 |
|
|
* later changes have no effect.
|
| 103 |
|
|
*
|
| 104 |
|
|
* @param name the name of the constructor.
|
| 105 |
|
|
* @param desc a description of the constructor.
|
| 106 |
|
|
* @param sig the signature of the constructor, as a series
|
| 107 |
|
|
* of {@link MBeanParameterInfo} objects, one for
|
| 108 |
|
|
* each parameter.
|
| 109 |
|
|
*/
|
| 110 |
|
|
public MBeanConstructorInfo(String name, String desc,
|
| 111 |
|
|
MBeanParameterInfo[] sig)
|
| 112 |
|
|
{
|
| 113 |
|
|
super(name, desc);
|
| 114 |
|
|
if (sig == null)
|
| 115 |
|
|
signature = new MBeanParameterInfo[0];
|
| 116 |
|
|
else
|
| 117 |
|
|
{
|
| 118 |
|
|
signature = new MBeanParameterInfo[sig.length];
|
| 119 |
|
|
System.arraycopy(sig, 0, signature, 0, sig.length);
|
| 120 |
|
|
}
|
| 121 |
|
|
}
|
| 122 |
|
|
|
| 123 |
|
|
/**
|
| 124 |
|
|
* Returns a clone of this instance. The clone is created
|
| 125 |
|
|
* using just the method provided by {@link java.lang.Object}.
|
| 126 |
|
|
* Thus, the clone is just a shallow clone as returned by
|
| 127 |
|
|
* that method, and does not contain any deeper cloning based
|
| 128 |
|
|
* on the subject of this class.
|
| 129 |
|
|
*
|
| 130 |
|
|
* @return a clone of this instance.
|
| 131 |
|
|
* @see java.lang.Cloneable
|
| 132 |
|
|
*/
|
| 133 |
|
|
public Object clone()
|
| 134 |
|
|
{
|
| 135 |
|
|
try
|
| 136 |
|
|
{
|
| 137 |
|
|
return super.clone();
|
| 138 |
|
|
}
|
| 139 |
|
|
catch (CloneNotSupportedException e)
|
| 140 |
|
|
{
|
| 141 |
|
|
/* This shouldn't happen; we implement Cloneable */
|
| 142 |
|
|
throw new IllegalStateException("clone() called on " +
|
| 143 |
|
|
"non-cloneable object.");
|
| 144 |
|
|
}
|
| 145 |
|
|
}
|
| 146 |
|
|
|
| 147 |
|
|
/**
|
| 148 |
|
|
* Compares this feature with the supplied object. This returns
|
| 149 |
|
|
* true iff the object is an instance of {@link
|
| 150 |
|
|
* MBeanConstructorInfo}, {@link Object#equals()} returns true for a
|
| 151 |
|
|
* comparison of both the name and description of this notification
|
| 152 |
|
|
* with that of the specified object (performed by the superclass),
|
| 153 |
|
|
* and the two signature arrays contain the same elements in the
|
| 154 |
|
|
* same order (but one may be longer than the other).
|
| 155 |
|
|
*
|
| 156 |
|
|
* @param obj the object to compare.
|
| 157 |
|
|
* @return true if the object is a {@link MBeanConstructorInfo}
|
| 158 |
|
|
* instance,
|
| 159 |
|
|
* <code>name.equals(object.getName())</code>,
|
| 160 |
|
|
* <code>description.equals(object.getDescription())</code>
|
| 161 |
|
|
* and the corresponding elements of the signature arrays are
|
| 162 |
|
|
* equal.
|
| 163 |
|
|
*/
|
| 164 |
|
|
public boolean equals(Object obj)
|
| 165 |
|
|
{
|
| 166 |
|
|
if (!(obj instanceof MBeanConstructorInfo))
|
| 167 |
|
|
return false;
|
| 168 |
|
|
if (!(super.equals(obj)))
|
| 169 |
|
|
return false;
|
| 170 |
|
|
MBeanConstructorInfo o = (MBeanConstructorInfo) obj;
|
| 171 |
|
|
MBeanParameterInfo[] sig = o.getSignature();
|
| 172 |
|
|
for (int a = 0; a < signature.length; ++a)
|
| 173 |
|
|
{
|
| 174 |
|
|
if (a == sig.length)
|
| 175 |
|
|
return true;
|
| 176 |
|
|
if (!(signature[a].equals(sig[a])))
|
| 177 |
|
|
return false;
|
| 178 |
|
|
}
|
| 179 |
|
|
return true;
|
| 180 |
|
|
}
|
| 181 |
|
|
|
| 182 |
|
|
/**
|
| 183 |
|
|
* Returns the constructor's signature, in the form of
|
| 184 |
|
|
* information on each parameter. Each parameter is
|
| 185 |
|
|
* described by an instance of {@link MBeanParameterInfo}.
|
| 186 |
|
|
* The returned array is a shallow copy of the array used
|
| 187 |
|
|
* by this instance, so changing which elements are stored
|
| 188 |
|
|
* in the array won't affect the array used by this, but
|
| 189 |
|
|
* changing the actual elements will affect the ones used
|
| 190 |
|
|
* here.
|
| 191 |
|
|
*
|
| 192 |
|
|
* @return an array of {@link MBeanParameterInfo} objects,
|
| 193 |
|
|
* describing the constructor parameters.
|
| 194 |
|
|
*/
|
| 195 |
|
|
public MBeanParameterInfo[] getSignature()
|
| 196 |
|
|
{
|
| 197 |
|
|
return (MBeanParameterInfo[]) signature.clone();
|
| 198 |
|
|
}
|
| 199 |
|
|
|
| 200 |
|
|
/**
|
| 201 |
|
|
* Returns the hashcode of the constructor information as the sum
|
| 202 |
|
|
* of the hashcode of the superclass and the hashcode of the parameter
|
| 203 |
|
|
* array.
|
| 204 |
|
|
*
|
| 205 |
|
|
* @return the hashcode of the constructor information.
|
| 206 |
|
|
*/
|
| 207 |
|
|
public int hashCode()
|
| 208 |
|
|
{
|
| 209 |
|
|
return super.hashCode() + Arrays.hashCode(signature);
|
| 210 |
|
|
}
|
| 211 |
|
|
|
| 212 |
|
|
/**
|
| 213 |
|
|
* <p>
|
| 214 |
|
|
* Returns a textual representation of this instance. This
|
| 215 |
|
|
* is constructed using the class name
|
| 216 |
|
|
* (<code>javax.management.MBeanConstructorInfo</code>),
|
| 217 |
|
|
* the name and description of the constructor and the
|
| 218 |
|
|
* contents of the array of parameters.
|
| 219 |
|
|
* </p>
|
| 220 |
|
|
* <p>
|
| 221 |
|
|
* As instances of this class are immutable, the return value
|
| 222 |
|
|
* is computed just once for each instance and reused
|
| 223 |
|
|
* throughout its life.
|
| 224 |
|
|
* </p>
|
| 225 |
|
|
*
|
| 226 |
|
|
* @return a @link{java.lang.String} instance representing
|
| 227 |
|
|
* the instance in textual form.
|
| 228 |
|
|
*/
|
| 229 |
|
|
public String toString()
|
| 230 |
|
|
{
|
| 231 |
|
|
if (string == null)
|
| 232 |
|
|
{
|
| 233 |
|
|
super.toString();
|
| 234 |
|
|
string = string.substring(0, string.length() - 1)
|
| 235 |
|
|
+ ",signature=" + Arrays.toString(signature)
|
| 236 |
|
|
+ "]";
|
| 237 |
|
|
}
|
| 238 |
|
|
return string;
|
| 239 |
|
|
}
|
| 240 |
|
|
|
| 241 |
|
|
}
|