0N/A/*
2362N/A * Copyright (c) 1999, 2008, 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 com.sun.jmx.mbeanserver.Introspector;
0N/Aimport java.lang.annotation.Annotation;
0N/Aimport java.lang.reflect.Constructor;
0N/Aimport java.util.Arrays;
0N/A
0N/A/**
0N/A * Describes a constructor exposed by an MBean. Instances of this
0N/A * class are immutable. Subclasses may be mutable but this is not
0N/A * recommended.
0N/A *
0N/A * @since 1.5
0N/A */
0N/Apublic class MBeanConstructorInfo extends MBeanFeatureInfo implements Cloneable {
0N/A
0N/A /* Serial version */
0N/A static final long serialVersionUID = 4433990064191844427L;
0N/A
0N/A static final MBeanConstructorInfo[] NO_CONSTRUCTORS =
0N/A new MBeanConstructorInfo[0];
0N/A
0N/A /** @see MBeanInfo#arrayGettersSafe */
0N/A private final transient boolean arrayGettersSafe;
0N/A
0N/A /**
0N/A * @serial The signature of the method, that is, the class names of the arguments.
0N/A */
0N/A private final MBeanParameterInfo[] signature;
0N/A
0N/A /**
0N/A * Constructs an <CODE>MBeanConstructorInfo</CODE> object. The
0N/A * {@link Descriptor} of the constructed object will include
0N/A * fields contributed by any annotations on the {@code
0N/A * Constructor} object that contain the {@link DescriptorKey}
0N/A * meta-annotation.
0N/A *
0N/A * @param description A human readable description of the operation.
0N/A * @param constructor The <CODE>java.lang.reflect.Constructor</CODE>
0N/A * object describing the MBean constructor.
0N/A */
686N/A public MBeanConstructorInfo(String description, Constructor<?> constructor) {
0N/A this(constructor.getName(), description,
0N/A constructorSignature(constructor),
1790N/A Introspector.descriptorForElement(constructor));
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <CODE>MBeanConstructorInfo</CODE> object.
0N/A *
0N/A * @param name The name of the constructor.
0N/A * @param signature <CODE>MBeanParameterInfo</CODE> objects
0N/A * describing the parameters(arguments) of the constructor. This
0N/A * may be null with the same effect as a zero-length array.
0N/A * @param description A human readable description of the constructor.
0N/A */
0N/A public MBeanConstructorInfo(String name,
0N/A String description,
0N/A MBeanParameterInfo[] signature) {
0N/A this(name, description, signature, null);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <CODE>MBeanConstructorInfo</CODE> object.
0N/A *
0N/A * @param name The name of the constructor.
0N/A * @param signature <CODE>MBeanParameterInfo</CODE> objects
0N/A * describing the parameters(arguments) of the constructor. This
0N/A * may be null with the same effect as a zero-length array.
0N/A * @param description A human readable description of the constructor.
0N/A * @param descriptor The descriptor for the constructor. 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 MBeanConstructorInfo(String name,
0N/A String description,
0N/A MBeanParameterInfo[] signature,
0N/A Descriptor descriptor) {
0N/A super(name, description, descriptor);
0N/A
0N/A if (signature == null || signature.length == 0)
0N/A signature = MBeanParameterInfo.NO_PARAMS;
0N/A else
0N/A signature = signature.clone();
0N/A this.signature = signature;
0N/A this.arrayGettersSafe =
0N/A MBeanInfo.arrayGettersSafe(this.getClass(),
0N/A MBeanConstructorInfo.class);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * <p>Returns a shallow clone of this instance. The clone is
0N/A * obtained by simply calling <tt>super.clone()</tt>, thus calling
0N/A * the default native shallow cloning mechanism implemented by
0N/A * <tt>Object.clone()</tt>. No deeper cloning of any internal
0N/A * field is made.</p>
0N/A *
0N/A * <p>Since this class is immutable, cloning is chiefly of
0N/A * interest to subclasses.</p>
0N/A */
0N/A public Object clone () {
0N/A try {
0N/A return super.clone() ;
0N/A } catch (CloneNotSupportedException e) {
0N/A // should not happen as this class is cloneable
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * <p>Returns the list of parameters for this constructor. Each
0N/A * parameter is described by an <CODE>MBeanParameterInfo</CODE>
0N/A * object.</p>
0N/A *
0N/A * <p>The returned array is a shallow copy of the internal array,
0N/A * which means that it is a copy of the internal array of
0N/A * references to the <CODE>MBeanParameterInfo</CODE> objects but
0N/A * that each referenced <CODE>MBeanParameterInfo</CODE> object is
0N/A * not copied.</p>
0N/A *
0N/A * @return An array of <CODE>MBeanParameterInfo</CODE> objects.
0N/A */
0N/A public MBeanParameterInfo[] getSignature() {
0N/A if (signature.length == 0)
0N/A return signature;
0N/A else
0N/A return signature.clone();
0N/A }
0N/A
0N/A private MBeanParameterInfo[] fastGetSignature() {
0N/A if (arrayGettersSafe)
0N/A return signature;
0N/A else
0N/A return getSignature();
0N/A }
0N/A
0N/A public String toString() {
0N/A return
0N/A getClass().getName() + "[" +
0N/A "description=" + getDescription() + ", " +
0N/A "name=" + getName() + ", " +
0N/A "signature=" + Arrays.asList(fastGetSignature()) + ", " +
0N/A "descriptor=" + getDescriptor() +
0N/A "]";
0N/A }
0N/A
0N/A /**
0N/A * Compare this MBeanConstructorInfo 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 MBeanConstructorInfo such
0N/A * that its {@link #getName()}, {@link #getDescription()},
0N/A * {@link #getSignature()}, and {@link #getDescriptor()}
0N/A * values are equal (not necessarily
0N/A * identical) to those of this MBeanConstructorInfo. Two
0N/A * signature arrays are equal if their elements are pairwise
0N/A * equal.
0N/A */
0N/A public boolean equals(Object o) {
0N/A if (o == this)
0N/A return true;
0N/A if (!(o instanceof MBeanConstructorInfo))
0N/A return false;
0N/A MBeanConstructorInfo p = (MBeanConstructorInfo) o;
0N/A return (p.getName().equals(getName()) &&
0N/A p.getDescription().equals(getDescription()) &&
0N/A Arrays.equals(p.fastGetSignature(), fastGetSignature()) &&
0N/A p.getDescriptor().equals(getDescriptor()));
0N/A }
0N/A
0N/A /* Unlike attributes and operations, it's quite likely we'll have
0N/A more than one constructor with the same name and even
0N/A description, so we include the parameter array in the hashcode.
0N/A We don't include the description, though, because it could be
0N/A quite long and yet the same between constructors. Likewise for
0N/A the descriptor. */
0N/A public int hashCode() {
0N/A int hash = getName().hashCode();
0N/A MBeanParameterInfo[] sig = fastGetSignature();
0N/A for (int i = 0; i < sig.length; i++)
0N/A hash ^= sig[i].hashCode();
0N/A return hash;
0N/A }
0N/A
686N/A private static MBeanParameterInfo[] constructorSignature(Constructor<?> cn) {
686N/A final Class<?>[] classes = cn.getParameterTypes();
0N/A final Annotation[][] annots = cn.getParameterAnnotations();
0N/A return MBeanOperationInfo.parameters(classes, annots);
0N/A }
0N/A}