001/* OpenMBeanConstructorInfoSupport.java -- Open typed info about an constructor. 002 Copyright (C) 2006 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038package javax.management.openmbean; 039 040import java.util.Arrays; 041 042import javax.management.MBeanConstructorInfo; 043import javax.management.MBeanParameterInfo; 044 045/** 046 * Describes a constructor for an open management bean. 047 * 048 * @author Andrew John Hughes (gnu_andrew@member.fsf.org) 049 * @since 1.5 050 */ 051public class OpenMBeanConstructorInfoSupport 052 extends MBeanConstructorInfo 053 implements OpenMBeanConstructorInfo 054{ 055 056 /** 057 * Compatible with JDK 1.5 058 */ 059 private static final long serialVersionUID = -4400441579007477003L; 060 061 /** 062 * The hash code of this instance. 063 */ 064 private transient Integer hashCode; 065 066 /** 067 * The <code>toString()</code> result of this instance. 068 */ 069 private transient String string; 070 071 /** 072 * Constructs a @link{OpenMBeanConstructorInfo} with the specified 073 * name, description and parameter information. A <code>null</code> 074 * value for the parameter information is the same as passing in 075 * an empty array. Neither the name nor the description may be 076 * null or equal to the empty string. A copy of the parameter array 077 * is taken, so later changes have no effect. 078 * 079 * @param name the name of the constructor. 080 * @param desc a description of the constructor. 081 * @param sig the signature of the constructor, as a series 082 * of {@link MBeanParameterInfo} objects, one for 083 * each parameter. 084 * @throws IllegalArgumentException if the name or description is 085 * either <code>null</code> 086 * or the empty string. 087 * @throws ArrayStoreException if the members of the signature array 088 * are not assignable to 089 * {@link javax.management.MBeanParameterInfo} 090 */ 091 public OpenMBeanConstructorInfoSupport(String name, String desc, 092 OpenMBeanParameterInfo[] sig) 093 { 094 super(name, desc, (MBeanParameterInfo[]) sig); 095 if (name == null) 096 throw new IllegalArgumentException("The name may not be null."); 097 if (desc == null) 098 throw new IllegalArgumentException("The description may not be null."); 099 if (name.length() == 0) 100 throw new IllegalArgumentException("The name may not be the empty string."); 101 if (desc.length() == 0) 102 throw new IllegalArgumentException("The description may not be the " + 103 "empty string."); 104 } 105 106 /** 107 * Compares this attribute with the supplied object. This returns 108 * true iff the object is an instance of {@link OpenMBeanConstructorInfo} 109 * with an equal name and signature. 110 * 111 * @param obj the object to compare. 112 * @return true if the object is a {@link OpenMBeanParameterInfo} 113 * instance, 114 * <code>name.equals(object.getName())</code>, 115 * and <code>signature.equals(object.getSignature())</code>. 116 */ 117 public boolean equals(Object obj) 118 { 119 if (!(obj instanceof OpenMBeanConstructorInfo)) 120 return false; 121 OpenMBeanConstructorInfo o = (OpenMBeanConstructorInfo) obj; 122 return getName().equals(o.getName()) && 123 getSignature().equals(o.getSignature()); 124 } 125 126 /** 127 * <p> 128 * Returns the hashcode of the constructor information as the sum of 129 * the hashcodes of the name and signature (calculated by 130 * <code>java.util.Arrays.asList(signature).hashCode()</code>). 131 * </p> 132 * <p> 133 * As instances of this class are immutable, the return value 134 * is computed just once for each instance and reused 135 * throughout its life. 136 * </p> 137 * 138 * @return the hashcode of the constructor information. 139 */ 140 public int hashCode() 141 { 142 if (hashCode == null) 143 hashCode = Integer.valueOf(getName().hashCode() + 144 Arrays.asList(getSignature()).hashCode()); 145 return hashCode.intValue(); 146 } 147 148 /** 149 * <p> 150 * Returns a textual representation of this instance. This 151 * is constructed using the class name 152 * (<code>javax.management.openmbean.OpenMBeanConstructorInfo</code>) 153 * along with the name and signature. 154 * </p> 155 * <p> 156 * As instances of this class are immutable, the return value 157 * is computed just once for each instance and reused 158 * throughout its life. 159 * </p> 160 * 161 * @return a @link{java.lang.String} instance representing 162 * the instance in textual form. 163 */ 164 public String toString() 165 { 166 if (string == null) 167 string = getClass().getName() 168 + "[name=" + getName() 169 + ",signature=" + Arrays.toString(getSignature()) 170 + "]"; 171 return string; 172 } 173 174}