OSDN Git Service

Add NIOS2 support. Code from SourceyG++.
[pf3gnuchains/gcc-fork.git] / libjava / classpath / javax / management / MBeanFeatureInfo.java
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.IOException;
41 import java.io.ObjectOutputStream;
42 import java.io.Serializable;
43
44 /**
45  * A general superclass for the description of features
46  * of management beans.  This allows the user to access
47  * the feature dynamically, without knowing the details
48  * beforehand.  The information is immutable as standard.
49  * Of course, subclasses may change this, but this
50  * behaviour is not recommended.
51  * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
52  * @since 1.5
53  */
54 public class MBeanFeatureInfo
55   implements Serializable
56 {
57
58   /**
59    * Compatible with JDK 1.5
60    */
61   private static final long serialVersionUID = 3952882688968447265L;
62
63   /**
64    * A description of the feature in human-readable form.
65    * Subclasses should access this via the {@link #getDescription()}
66    * function rather than using the value directly.
67    *
68    * @serial a description of the feature.
69    */
70   protected String description;
71
72   /**
73    * The name of the feature.  Subclasses should access this
74    * via the {@link #getName()} function rather than using the
75    * value directly.
76    *
77    * @serial the name of the feature.
78    */
79   protected String name;
80
81   /**
82    * The <code>toString()</code> result of this instance.
83    */
84   transient String string;
85
86   /**
87    * Constructs a new {@link MBeanFeatureInfo} with the specified
88    * name and description.
89    *
90    * @param name the name of the management bean feature.
91    * @param description the description of the feature.
92    */
93   public MBeanFeatureInfo(String name, String description)
94   {
95     this.name = name;
96     this.description = description;
97   }
98
99   /**
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 }