001/* MBeanFeatureInfo.java -- Information about a bean feature.
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
040import java.io.IOException;
041import java.io.ObjectOutputStream;
042import java.io.Serializable;
043
044/**
045 * A general superclass for the description of features
046 * of management beans.  This allows the user to access
047 * the feature dynamically, without knowing the details
048 * beforehand.  The information is immutable as standard.
049 * Of course, subclasses may change this, but this
050 * behaviour is not recommended.
051 * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
052 * @since 1.5
053 */
054public class MBeanFeatureInfo
055  implements Serializable
056{
057
058  /**
059   * Compatible with JDK 1.5
060   */
061  private static final long serialVersionUID = 3952882688968447265L;
062
063  /**
064   * A description of the feature in human-readable form.
065   * Subclasses should access this via the {@link #getDescription()}
066   * function rather than using the value directly.
067   *
068   * @serial a description of the feature.
069   */
070  protected String description;
071
072  /**
073   * The name of the feature.  Subclasses should access this
074   * via the {@link #getName()} function rather than using the
075   * value directly.
076   *
077   * @serial the name of the feature.
078   */
079  protected String name;
080
081  /**
082   * The <code>toString()</code> result of this instance.
083   */
084  transient String string;
085
086  /**
087   * Constructs a new {@link MBeanFeatureInfo} with the specified
088   * name and description.
089   *
090   * @param name the name of the management bean feature.
091   * @param description the description of the feature.
092   */
093  public MBeanFeatureInfo(String name, String description)
094  {
095    this.name = name;
096    this.description = description;
097  }
098
099  /**
100   * Compares this feature with the supplied object.  This
101   * returns true iff the object is an instance of
102   * {@link MBeanFeatureInfo} and {@link Object#equals()}
103   * returns true for a comparison of both the name and
104   * description of this feature with that of the specified
105   * object.
106   *
107   * @param obj the object to compare.
108   * @return true if the object is a {@link MBeanFeatureInfo}
109   *         instance, 
110   *         <code>name.equals(object.getName())</code> and
111   *         <code>description.equals(object.getDescription</code>.
112   */
113  public boolean equals(Object obj)
114  {
115    if (obj instanceof MBeanFeatureInfo)
116      {
117        MBeanFeatureInfo o = (MBeanFeatureInfo) obj;
118        return ((name == null ? 
119                 o.getName() == null : 
120                 name.equals(o.getName())) &&
121                (description == null ?
122                 o.getDescription() == null :
123                 description.equals(o.getDescription())));
124      }
125    else
126      return false;
127  }
128
129  /**
130   * Returns a description of this feature.
131   *
132   * @return a human-readable description.
133   */
134  public String getDescription()
135  {
136    return description;
137  }
138
139  /**
140   * Returns the name of this feature.
141   *
142   * @return the name of the feature.
143   */
144  public String getName()
145  {
146    return name;
147  }
148
149  /**
150   * Returns the hashcode of the feature as
151   * the sum of the hashcodes of its name
152   * and description.
153   *
154   * @return the hashcode of this feature.
155   */
156  public int hashCode()
157  {
158    return (name == null ? -1 : name.hashCode())
159      + (description == null ? -1 : description.hashCode());
160  }
161
162  /**
163   * <p>
164   * Returns a textual representation of this instance.  This
165   * is constructed using the class name
166   * (<code>javax.management.MBeanFeatureInfo</code>) and
167   * the name and description of the feature.
168   * </p>
169   * <p>
170   * As instances of this class are immutable, the return value
171   * is computed just once for each instance and reused
172   * throughout its life.
173   * </p>
174   *
175   * @return a @link{java.lang.String} instance representing
176   *         the instance in textual form.
177   */
178  public String toString()
179  {
180    if (string == null)
181      string = getClass().getName()
182        + "[name=" + name 
183        + ",desc=" + description 
184        + "]";
185    return string;
186  }
187
188  /**
189   * Serialize the {@link MBeanFeatureInfo}.
190   *
191   * @param out the output stream to write to.
192   * @throws IOException if an I/O error occurs.
193   */
194  private void writeObject(ObjectOutputStream out)
195    throws IOException
196  {
197    out.defaultWriteObject();
198    /* FIXME: Handle extra 1.6 descriptor stuff */
199  }
200
201}