1 |
772 |
jeremybenn |
/* OpenMBeanOperationInfoSupport.java -- Open typed info about an operation.
|
2 |
|
|
Copyright (C) 2006, 2007 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.openmbean;
|
39 |
|
|
|
40 |
|
|
import java.util.Arrays;
|
41 |
|
|
|
42 |
|
|
import javax.management.MBeanOperationInfo;
|
43 |
|
|
import javax.management.MBeanParameterInfo;
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* Describes a operation for an open management bean.
|
47 |
|
|
*
|
48 |
|
|
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
49 |
|
|
* @since 1.5
|
50 |
|
|
*/
|
51 |
|
|
public class OpenMBeanOperationInfoSupport
|
52 |
|
|
extends MBeanOperationInfo
|
53 |
|
|
implements OpenMBeanOperationInfo
|
54 |
|
|
{
|
55 |
|
|
|
56 |
|
|
/**
|
57 |
|
|
* Compatible with JDK 1.5
|
58 |
|
|
*/
|
59 |
|
|
private static final long serialVersionUID = 4996859732565369366L;
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* The open type representing the return value.
|
63 |
|
|
*/
|
64 |
|
|
private OpenType<?> returnOpenType;
|
65 |
|
|
|
66 |
|
|
/**
|
67 |
|
|
* The hash code of this instance.
|
68 |
|
|
*/
|
69 |
|
|
private transient Integer hashCode;
|
70 |
|
|
|
71 |
|
|
/**
|
72 |
|
|
* The <code>toString()</code> result of this instance.
|
73 |
|
|
*/
|
74 |
|
|
private transient String string;
|
75 |
|
|
|
76 |
|
|
/**
|
77 |
|
|
* Constructs a @link{OpenMBeanOperationInfo} with the specified name,
|
78 |
|
|
* description, parameter information, open return type and impact. A
|
79 |
|
|
* <code>null</code> value for the parameter information is the same
|
80 |
|
|
* as passing in an empty array. A copy of the parameter array is
|
81 |
|
|
* taken, so later changes have no effect. The name and the
|
82 |
|
|
* description may not be equal to the empty string, and neither
|
83 |
|
|
* the name, description nor the open return type may be
|
84 |
|
|
* <code>null</code>. The value of <code>impact</code> must be
|
85 |
|
|
* one of the four valid values
|
86 |
|
|
* ({@link javax.management.MBeanOperationInfo#INFO},
|
87 |
|
|
* {@link javax.management.MBeanOperationInfo#ACTION},
|
88 |
|
|
* {@link javax.management.MBeanOperationInfo#ACTION_INFO} and
|
89 |
|
|
* {@link javax.management.MBeanOperationInfo#UNKNOWN}).
|
90 |
|
|
*
|
91 |
|
|
*
|
92 |
|
|
* @param name the name of the constructor.
|
93 |
|
|
* @param desc a description of the attribute.
|
94 |
|
|
* @param sig the signature of the method, as a series
|
95 |
|
|
* of {@link MBeanParameterInfo} objects, one for
|
96 |
|
|
* each parameter.
|
97 |
|
|
* @param type the open return type of the method.
|
98 |
|
|
* @param impact the impact of performing the operation.
|
99 |
|
|
* @throws IllegalArgumentException if the name, description or
|
100 |
|
|
* open return type is <code>null</code>,
|
101 |
|
|
* the name or description are equal to
|
102 |
|
|
* the empty string, or the impact factor
|
103 |
|
|
* is not one of the values enumerated
|
104 |
|
|
* above.
|
105 |
|
|
* @throws ArrayStoreException if the members of the signature array
|
106 |
|
|
* are not assignable to
|
107 |
|
|
* {@link javax.management.MBeanParameterInfo}
|
108 |
|
|
*/
|
109 |
|
|
public OpenMBeanOperationInfoSupport(String name, String desc,
|
110 |
|
|
OpenMBeanParameterInfo[] sig,
|
111 |
|
|
OpenType<?> type, int impact)
|
112 |
|
|
{
|
113 |
|
|
super(name, desc, (MBeanParameterInfo[]) sig,
|
114 |
|
|
type == null ? null : type.getClassName(), impact);
|
115 |
|
|
if (name == null)
|
116 |
|
|
throw new IllegalArgumentException("The name may not be null.");
|
117 |
|
|
if (desc == null)
|
118 |
|
|
throw new IllegalArgumentException("The description may not be null.");
|
119 |
|
|
if (type == null)
|
120 |
|
|
throw new IllegalArgumentException("The type may not be null.");
|
121 |
|
|
if (name.length() == 0)
|
122 |
|
|
throw new IllegalArgumentException("The name may not be the empty string.");
|
123 |
|
|
if (desc.length() == 0)
|
124 |
|
|
throw new IllegalArgumentException("The description may not be the " +
|
125 |
|
|
"empty string.");
|
126 |
|
|
if (impact != ACTION && impact != INFO &&
|
127 |
|
|
impact != ACTION_INFO && impact != UNKNOWN)
|
128 |
|
|
throw new IllegalArgumentException("The impact factor is an invalid value.");
|
129 |
|
|
returnOpenType = type;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
/**
|
133 |
|
|
* Compares this attribute with the supplied object. This returns
|
134 |
|
|
* true iff the object is an instance of {@link OpenMBeanOperationInfo}
|
135 |
|
|
* with an equal name, signature, open return type and impact.
|
136 |
|
|
*
|
137 |
|
|
* @param obj the object to compare.
|
138 |
|
|
* @return true if the object is a {@link OpenMBeanParameterInfo}
|
139 |
|
|
* instance,
|
140 |
|
|
* <code>name.equals(object.getName())</code>,
|
141 |
|
|
* <code>signature.equals(object.getSignature())</code>,
|
142 |
|
|
* <code>returnOpenType.equals(object.getReturnOpenType())</code>,
|
143 |
|
|
* and <code>impact == object.getImpact()</code>.
|
144 |
|
|
*/
|
145 |
|
|
public boolean equals(Object obj)
|
146 |
|
|
{
|
147 |
|
|
if (!(obj instanceof OpenMBeanOperationInfo))
|
148 |
|
|
return false;
|
149 |
|
|
OpenMBeanOperationInfo o = (OpenMBeanOperationInfo) obj;
|
150 |
|
|
return getName().equals(o.getName()) &&
|
151 |
|
|
getSignature().equals(o.getSignature()) &&
|
152 |
|
|
returnOpenType.equals(o.getReturnOpenType()) &&
|
153 |
|
|
getImpact() == o.getImpact();
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
/**
|
157 |
|
|
* Returns the open type instance which represents the type of the
|
158 |
|
|
* return value.
|
159 |
|
|
*
|
160 |
|
|
* @return the open type of the return value.
|
161 |
|
|
*/
|
162 |
|
|
public OpenType<?> getReturnOpenType()
|
163 |
|
|
{
|
164 |
|
|
return returnOpenType;
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
/**
|
168 |
|
|
* <p>
|
169 |
|
|
* Returns the hashcode of the operation information as the sum of
|
170 |
|
|
* the hashcodes of the name, open return type, impact and signature
|
171 |
|
|
* (calculated by
|
172 |
|
|
* <code>java.util.Arrays.asList(signature).hashCode()</code>).
|
173 |
|
|
* </p>
|
174 |
|
|
* <p>
|
175 |
|
|
* As instances of this class are immutable, the return value
|
176 |
|
|
* is computed just once for each instance and reused
|
177 |
|
|
* throughout its life.
|
178 |
|
|
* </p>
|
179 |
|
|
*
|
180 |
|
|
* @return the hashcode of the operation information.
|
181 |
|
|
*/
|
182 |
|
|
public int hashCode()
|
183 |
|
|
{
|
184 |
|
|
if (hashCode == null)
|
185 |
|
|
hashCode = Integer.valueOf(getName().hashCode() +
|
186 |
|
|
returnOpenType.hashCode() +
|
187 |
|
|
Integer.valueOf(getImpact()).hashCode() +
|
188 |
|
|
Arrays.asList(getSignature()).hashCode());
|
189 |
|
|
return hashCode.intValue();
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
/**
|
193 |
|
|
* <p>
|
194 |
|
|
* Returns a textual representation of this instance. This
|
195 |
|
|
* is constructed using the class name
|
196 |
|
|
* (<code>javax.management.openmbean.OpenMBeanOperationInfo</code>)
|
197 |
|
|
* along with the name, signature, open return type and impact.
|
198 |
|
|
* </p>
|
199 |
|
|
* <p>
|
200 |
|
|
* As instances of this class are immutable, the return value
|
201 |
|
|
* is computed just once for each instance and reused
|
202 |
|
|
* throughout its life.
|
203 |
|
|
* </p>
|
204 |
|
|
*
|
205 |
|
|
* @return a @link{java.lang.String} instance representing
|
206 |
|
|
* the instance in textual form.
|
207 |
|
|
*/
|
208 |
|
|
public String toString()
|
209 |
|
|
{
|
210 |
|
|
if (string == null)
|
211 |
|
|
{
|
212 |
|
|
String impactString;
|
213 |
|
|
switch (getImpact())
|
214 |
|
|
{
|
215 |
|
|
case INFO:
|
216 |
|
|
impactString = "INFO";
|
217 |
|
|
break;
|
218 |
|
|
case ACTION:
|
219 |
|
|
impactString = "ACTION";
|
220 |
|
|
break;
|
221 |
|
|
case ACTION_INFO:
|
222 |
|
|
impactString = "ACTION_INFO";
|
223 |
|
|
break;
|
224 |
|
|
case UNKNOWN:
|
225 |
|
|
impactString = "UNKNOWN";
|
226 |
|
|
break;
|
227 |
|
|
default:
|
228 |
|
|
impactString = "ERRONEOUS VALUE";
|
229 |
|
|
}
|
230 |
|
|
string = getClass().getName()
|
231 |
|
|
+ "[name=" + getName()
|
232 |
|
|
+ ",signature=" + Arrays.toString(getSignature())
|
233 |
|
|
+ ",returnOpenType=" + returnOpenType
|
234 |
|
|
+ ",impact=" + impactString
|
235 |
|
|
+ "]";
|
236 |
|
|
}
|
237 |
|
|
return string;
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
}
|