001/* MBeanParameterInfo.java -- Information about an operation's parameters.
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;
039
040/**
041 * Describes the parameters of a constructor or operation associated
042 * with a management bean.  The information in this class is immutable
043 * as standard.  Of course, subclasses may change this, but this
044 * behaviour is not recommended.
045 *
046 * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
047 * @since 1.5
048 */
049public class MBeanParameterInfo
050  extends MBeanFeatureInfo
051  implements Cloneable
052{
053
054  /**
055   * Compatible with JDK 1.5
056   */
057  private static final long serialVersionUID = 7432616882776782338L;
058
059  /**
060   * The type of the parameter, represented by the class name.
061   */
062  private String type;
063
064  /**
065   * Constructs a new {@link MBeanParameterInfo} using the specified
066   * name, description and type.  
067   *
068   * @param name the name of the attribute.
069   * @param type the type of the attribute, in the form of its class name.
070   * @param desc a description of the attribute.
071   */
072  public MBeanParameterInfo(String name, String type, String desc)
073  {
074    super(name, desc);
075    this.type = type;
076  }
077
078  /**
079   * Returns a clone of this instance.  The clone is created
080   * using just the method provided by {@link java.lang.Object}.
081   * Thus, the clone is just a shallow clone as returned by
082   * that method, and does not contain any deeper cloning based
083   * on the subject of this class.
084   *
085   * @return a clone of this instance.
086   * @see java.lang.Cloneable
087   */
088  public Object clone()
089  {
090    try
091      {
092        return super.clone();
093      }
094    catch (CloneNotSupportedException e)
095      {
096        /* This shouldn't happen; we implement Cloneable */
097        throw new IllegalStateException("clone() called on " +
098                                        "non-cloneable object.");
099      }
100  }
101
102  /**
103   * Compares this feature with the supplied object.  This returns
104   * true iff the object is an instance of {@link MBeanParameterInfo},
105   * {@link Object#equals()} returns true for a comparison of both the
106   * name and description of this parameter with that of the specified
107   * object (performed by the superclass), and the type of the two
108   * instances is equal.
109   *
110   * @param obj the object to compare.
111   * @return true if the object is a {@link MBeanParameterInfo}
112   *         instance, 
113   *         <code>name.equals(object.getName())</code>,
114   *         <code>description.equals(object.getDescription())</code>,
115   *         and <code>type.equals(object.getType())</code>.
116   */
117  public boolean equals(Object obj)
118  {
119    if (!(obj instanceof MBeanParameterInfo))
120      return false;
121    if (!(super.equals(obj)))
122      return false;
123    MBeanParameterInfo o = (MBeanParameterInfo) obj;
124    return type.equals(o.getType());
125  }
126
127  /**
128   * Returns the type of this attribute, in the form of its class name.
129   *
130   * @return the type of this attribute.
131   */
132  public String getType()
133  {
134    return type;
135  }
136
137  /**
138   * Returns the hashcode of the parameter information as the sum of
139   * the hashcode of the superclass and the hashcode of the type.
140   *
141   * @return the hashcode of the parameter information.
142   */
143  public int hashCode()
144  {
145    return super.hashCode() + type.hashCode();
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.MBeanParameterInfo</code>) along
153   * with the name, description and type of the parameter.
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      {
168        super.toString();
169        string = string.substring(0, string.length() - 1) 
170          + ",type=" + type
171          + "]";
172      }
173    return string;
174  }
175
176}