Source for javax.management.openmbean.OpenMBeanConstructorInfoSupport

   1: /* OpenMBeanConstructorInfoSupport.java -- Open typed info about an 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.openmbean;
  39: 
  40: import java.util.Arrays;
  41: 
  42: import javax.management.MBeanConstructorInfo;
  43: import javax.management.MBeanParameterInfo;
  44: 
  45: /**
  46:  * Describes a constructor for an open management bean.
  47:  *
  48:  * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  49:  * @since 1.5
  50:  */
  51: public class OpenMBeanConstructorInfoSupport
  52:   extends MBeanConstructorInfo
  53:   implements OpenMBeanConstructorInfo
  54: {
  55: 
  56:   /**
  57:    * Compatible with JDK 1.5
  58:    */
  59:   private static final long serialVersionUID = -4400441579007477003L;
  60: 
  61:   /**
  62:    * The hash code of this instance.
  63:    */
  64:   private transient Integer hashCode;
  65: 
  66:   /**
  67:    * The <code>toString()</code> result of this instance.
  68:    */
  69:   private transient String string;
  70: 
  71:   /**
  72:    * Constructs a @link{OpenMBeanConstructorInfo} with the specified
  73:    * name, description and parameter information. A <code>null</code>
  74:    * value for the parameter information is the same as passing in
  75:    * an empty array.  Neither the name nor the description may be
  76:    * null or equal to the empty string.  A copy of the parameter array
  77:    * is taken, so later changes have no effect.
  78:    *
  79:    * @param name the name of the constructor.
  80:    * @param desc a description of the constructor.
  81:    * @param sig the signature of the constructor, as a series
  82:    *            of {@link MBeanParameterInfo} objects, one for
  83:    *            each parameter.
  84:    * @throws IllegalArgumentException if the name or description is
  85:    *                                  either <code>null</code>
  86:    *                                  or the empty string.
  87:    * @throws ArrayStoreException if the members of the signature array
  88:    *                             are not assignable to
  89:    *                             {@link javax.management.MBeanParameterInfo}
  90:    */
  91:   public OpenMBeanConstructorInfoSupport(String name, String desc,
  92:                                          OpenMBeanParameterInfo[] sig)
  93:   {
  94:     super(name, desc, (MBeanParameterInfo[]) sig);
  95:     if (name == null)
  96:       throw new IllegalArgumentException("The name may not be null.");
  97:     if (desc == null)
  98:       throw new IllegalArgumentException("The description may not be null.");
  99:     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: }