1 /* MBeanConstructorInfo.java -- Information about a bean's constructor.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
38 package javax.management;
40 import java.lang.reflect.Constructor;
42 import java.util.Arrays;
45 * Describes the constructors of a management bean.
46 * The information in this class is immutable as standard.
47 * Of course, subclasses may change this, but this
48 * behaviour is not recommended.
50 * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
53 public class MBeanConstructorInfo
54 extends MBeanFeatureInfo
59 * Compatible with JDK 1.5
61 private static final long serialVersionUID = 4433990064191844427L;
64 * The signature of the constructor i.e. the argument types.
66 private MBeanParameterInfo[] signature;
69 * Constructs a @link{MBeanConstructorInfo} with the specified
70 * description using the given constructor. Each parameter is
71 * described merely by its type; the name and description are
74 * @param desc a description of the attribute.
75 * @param cons the constructor.
77 public MBeanConstructorInfo(String desc, Constructor cons)
79 super(cons.getName(), desc);
80 Class[] paramTypes = cons.getParameterTypes();
81 signature = new MBeanParameterInfo[paramTypes.length];
82 for (int a = 0; a < paramTypes.length; ++a)
83 signature[a] = new MBeanParameterInfo(null,
84 paramTypes[a].getName(),
89 * Constructs a @link{MBeanConstructorInfo} with the specified
90 * name, description and parameter information. A <code>null</code>
91 * value for the parameter information is the same as passing in
94 * @param name the name of the constructor.
95 * @param desc a description of the attribute.
96 * @param sig the signature of the constructor, as a series
97 * of {@link MBeanParameterInfo} objects, one for
100 public MBeanConstructorInfo(String name, String desc,
101 MBeanParameterInfo[] sig)
105 signature = new MBeanParameterInfo[0];
111 * Returns a clone of this instance. The clone is created
112 * using just the method provided by {@link java.lang.Object}.
113 * Thus, the clone is just a shallow clone as returned by
114 * that method, and does not contain any deeper cloning based
115 * on the subject of this class.
117 * @return a clone of this instance.
118 * @see java.lang.Cloneable
120 public Object clone()
124 return super.clone();
126 catch (CloneNotSupportedException e)
128 /* This shouldn't happen; we implement Cloneable */
129 throw new IllegalStateException("clone() called on " +
130 "non-cloneable object.");
135 * Compares this feature with the supplied object. This returns
136 * true iff the object is an instance of {@link
137 * MBeanConstructorInfo}, {@link Object#equals()} returns true for a
138 * comparison of both the name and description of this notification
139 * with that of the specified object (performed by the superclass),
140 * and the two signature arrays contain the same elements in the
141 * same order (but one may be longer than the other).
143 * @param obj the object to compare.
144 * @return true if the object is a {@link MBeanConstructorInfo}
146 * <code>name.equals(object.getName())</code>,
147 * <code>description.equals(object.getDescription())</code>
148 * and the corresponding elements of the signature arrays are
151 public boolean equals(Object obj)
153 if (!(obj instanceof MBeanConstructorInfo))
155 if (!(super.equals(obj)))
157 MBeanConstructorInfo o = (MBeanConstructorInfo) obj;
158 MBeanParameterInfo[] sig = o.getSignature();
159 for (int a = 0; a < signature.length; ++a)
163 if (!(signature[a].equals(sig[a])))
170 * Returns the constructor's signature, in the form of
171 * information on each parameter. Each parameter is
172 * described by an instance of {@link MBeanParameterInfo}.
173 * The returned array is a shallow copy of the array used
174 * by this instance, so changing which elements are stored
175 * in the array won't affect the array used by this, but
176 * changing the actual elements will affect the ones used
179 * @return an array of {@link MBeanParameterInfo} objects,
180 * describing the constructor parameters.
182 public MBeanParameterInfo[] getSignature()
184 return (MBeanParameterInfo[]) signature.clone();
188 * Returns the hashcode of the constructor information as the sum
189 * of the hashcode of the superclass and the hashcode of the parameter
192 * @return the hashcode of the constructor information.
194 public int hashCode()
196 return super.hashCode() + Arrays.hashCode(signature);
201 * Returns a textual representation of this instance. This
202 * is constructed using the class name
203 * (<code>javax.management.MBeanConstructorInfo</code>),
204 * the name and description of the constructor and the
205 * contents of the array of parameters.
208 * As instances of this class are immutable, the return value
209 * is computed just once for each instance and reused
210 * throughout its life.
213 * @return a @link{java.lang.String} instance representing
214 * the instance in textual form.
216 public String toString()
221 string = string.substring(0, string.length() - 1)
222 + ",signature=" + Arrays.toString(signature)