Source for javax.management.MBeanFeatureInfo

   1: /* MBeanFeatureInfo.java -- Information about a bean feature.
   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;
  39: 
  40: import java.io.Serializable;
  41: 
  42: /**
  43:  * A general superclass for the description of features
  44:  * of management beans.  This allows the user to access
  45:  * the feature dynamically, without knowing the details
  46:  * beforehand.  The information is immutable as standard.
  47:  * Of course, subclasses may change this, but this
  48:  * behaviour is not recommended.
  49:  * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  50:  * @since 1.5
  51:  */
  52: public class MBeanFeatureInfo
  53:   implements Serializable
  54: {
  55: 
  56:   /**
  57:    * Compatible with JDK 1.5
  58:    */
  59:   private static final long serialVersionUID = 3952882688968447265L;
  60: 
  61:   /**
  62:    * A description of the feature in human-readable form.
  63:    * Subclasses should access this via the {@link #getDescription()}
  64:    * function rather than using the value directly.
  65:    *
  66:    * @serial a description of the feature.
  67:    */
  68:   protected String description;
  69: 
  70:   /**
  71:    * The name of the feature.  Subclasses should access this
  72:    * via the {@link #getName()} function rather than using the
  73:    * value directly.
  74:    *
  75:    * @serial the name of the feature.
  76:    */
  77:   protected String name;
  78: 
  79:   /**
  80:    * The <code>toString()</code> result of this instance.
  81:    */
  82:   protected transient String string;
  83: 
  84:   /**
  85:    * Constructs a new {@link MBeanFeatureInfo} with the specified
  86:    * name and description.
  87:    *
  88:    * @param name the name of the management bean feature.
  89:    * @param description the description of the feature.
  90:    */
  91:   public MBeanFeatureInfo(String name, String description)
  92:   {
  93:     this.name = name;
  94:     this.description = description;
  95:   }
  96: 
  97:   /**
  98:    * Compares this feature with the supplied object.  This
  99:    * returns true iff the object is an instance of
 100:    * {@link MBeanFeatureInfo} and {@link Object#equals()}
 101:    * returns true for a comparison of both the name and
 102:    * description of this feature with that of the specified
 103:    * object.
 104:    *
 105:    * @param obj the object to compare.
 106:    * @return true if the object is a {@link MBeanFeatureInfo}
 107:    *         instance, 
 108:    *         <code>name.equals(object.getName())</code> and
 109:    *         <code>description.equals(object.getDescription</code>.
 110:    */
 111:   public boolean equals(Object obj)
 112:   {
 113:     if (obj instanceof MBeanFeatureInfo)
 114:       {
 115:     MBeanFeatureInfo o = (MBeanFeatureInfo) obj;
 116:     return ((name == null ? 
 117:          o.getName() == null : 
 118:          name.equals(o.getName())) &&
 119:         (description == null ?
 120:          o.getDescription() == null :
 121:          description.equals(o.getDescription())));
 122:       }
 123:     else
 124:       return false;
 125:   }
 126: 
 127:   /**
 128:    * Returns a description of this feature.
 129:    *
 130:    * @return a human-readable description.
 131:    */
 132:   public String getDescription()
 133:   {
 134:     return description;
 135:   }
 136: 
 137:   /**
 138:    * Returns the name of this feature.
 139:    *
 140:    * @return the name of the feature.
 141:    */
 142:   public String getName()
 143:   {
 144:     return name;
 145:   }
 146: 
 147:   /**
 148:    * Returns the hashcode of the feature as
 149:    * the sum of the hashcodes of its name
 150:    * and description.
 151:    *
 152:    * @return the hashcode of this feature.
 153:    */
 154:   public int hashCode()
 155:   {
 156:     return (name == null ? -1 : name.hashCode())
 157:       + (description == null ? -1 : description.hashCode());
 158:   }
 159: 
 160:   /**
 161:    * <p>
 162:    * Returns a textual representation of this instance.  This
 163:    * is constructed using the class name
 164:    * (<code>javax.management.MBeanFeatureInfo</code>) and
 165:    * the name and description of the feature.
 166:    * </p>
 167:    * <p>
 168:    * As instances of this class are immutable, the return value
 169:    * is computed just once for each instance and reused
 170:    * throughout its life.
 171:    * </p>
 172:    *
 173:    * @return a @link{java.lang.String} instance representing
 174:    *         the instance in textual form.
 175:    */
 176:   public String toString()
 177:   {
 178:     if (string == null)
 179:       string = getClass().getName()
 180:     + "[name=" + name 
 181:     + ",desc=" + description 
 182:     + "]";
 183:     return string;
 184:   }
 185: 
 186: }