001 /* MBeanFeatureInfo.java -- Information about a bean feature. 002 Copyright (C) 2006 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 package javax.management; 039 040 import java.io.IOException; 041 import java.io.ObjectOutputStream; 042 import 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 */ 054 public 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 }