KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > javax > management > support > ComplianceSupport


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package test.javax.management.support;
10
11 import javax.management.Attribute JavaDoc;
12 import javax.management.AttributeList JavaDoc;
13 import javax.management.AttributeNotFoundException JavaDoc;
14 import javax.management.DynamicMBean JavaDoc;
15 import javax.management.InvalidAttributeValueException JavaDoc;
16 import javax.management.MBeanException JavaDoc;
17 import javax.management.MBeanInfo JavaDoc;
18 import javax.management.ReflectionException JavaDoc;
19
20 /**
21  * @version $Revision: 1.6 $
22  */

23 public class ComplianceSupport
24 {
25    // Not a manageable class: missing management interface
26
public static class NoManagement
27    {
28    }
29
30
31    // Not a manageable class: implements an interface with different name
32
public interface LexicalPatternNotRespectedMBean
33    {
34       public void fake();
35    }
36
37    public static class DoesntRespectLexicalPattern implements LexicalPatternNotRespectedMBean
38    {
39       public void fake()
40       {
41       }
42    }
43
44
45    // MBeans with overloaded attributes are not compliant
46
public interface OverloadedAttributeSetSetMBean
47    {
48       public void setAttribute(String JavaDoc s);
49
50       public void setAttribute(Integer JavaDoc i);
51    }
52
53    public static class OverloadedAttributeSetSet implements OverloadedAttributeSetSetMBean
54    {
55       public void setAttribute(String JavaDoc s)
56       {
57       }
58
59       public void setAttribute(Integer JavaDoc i)
60       {
61       }
62    }
63
64    public interface OverloadedAttributeGetSetMBean
65    {
66       public String JavaDoc getAttribute();
67
68       public void setAttribute(Integer JavaDoc i);
69    }
70
71    public static class OverloadedAttributeGetSet implements OverloadedAttributeGetSetMBean
72    {
73       public String JavaDoc getAttribute()
74       {
75          return null;
76       }
77
78       public void setAttribute(Integer JavaDoc i)
79       {
80       }
81    }
82
83    public interface OverloadedAttributeIsGetMBean
84    {
85       public boolean isBoolean();
86
87       public boolean getBoolean();
88    }
89
90    public static class OverloadedAttributeIsGet implements OverloadedAttributeIsGetMBean
91    {
92       public boolean isBoolean()
93       {
94          return false;
95       }
96
97       public boolean getBoolean()
98       {
99          return false;
100       }
101    }
102
103
104    // In JMX 1.0 this is not a manageable class: it's abstract
105
// In JMX 1.1 the requirement for the MBean class to be concrete has been removed
106
// public interface AbstractMBean {}
107
// public static abstract class Abstract implements AbstractMBean {}
108

109
110    // Valid MBean
111
public static interface BasicStandardMBean
112    {
113       public void test();
114    }
115
116    public static class BasicStandard implements BasicStandardMBean
117    {
118       private int m_count;
119
120       // This method should not be part of the management interface
121
public void noManage()
122       {
123       }
124
125       public void test()
126       {
127          ++m_count;
128       }
129    }
130
131
132    // Valid MBean that inherits from parent its manageability
133
public static class Derived extends BasicStandard
134    {
135       public void derivedNoManage()
136       {
137       }
138    }
139
140
141    // Valid MBean with inherited management interface
142
public interface BaseMBean
143    {
144       public void base();
145    }
146
147    public interface InheritedMBean extends BaseMBean
148    {
149       public void derived();
150
151       public void test2();
152
153       public void retest();
154    }
155
156    public static class Inherited implements InheritedMBean
157    {
158       public void base()
159       {
160       }
161
162       public void derived()
163       {
164       }
165
166       public void test2()
167       {
168       }
169
170       public void retest()
171       {
172       }
173    }
174
175
176    // Valid MBean with a trap: the management interface should be only the one inherited from Basic
177
public static class NotInherited extends BasicStandard implements InheritedMBean
178    {
179       public void base()
180       {
181       }
182
183       public void derived()
184       {
185       }
186
187       public void retest()
188       {
189       }
190
191       public void test2()
192       {
193       }
194
195       public void unManage()
196       {
197       }
198    }
199
200
201    // Valid MBean with multiple inheritance
202
public interface MultiMBean extends BasicStandardMBean, InheritedMBean
203    {
204    }
205
206    public static class Multi extends Inherited implements MultiMBean
207    {
208       public void test()
209       {
210       }
211    }
212
213
214    // Valid MBean even if the class is package private
215
public interface PackagePrivateMBean
216    {
217    }
218
219    static class PackagePrivate implements PackagePrivateMBean
220    {
221    }
222
223
224    // In JMX 1.0 this is not a valid MBean: it is standard and dynamic
225
// In JMX 1.1 it is dynamic, since the spec says that every class that implements DynamicMBean is a dynamic mbean
226
// However, I assume that if someone writes such a class, or it did not understand JMX or is trying to fool the MBeanServer
227
public interface StandardDynamicMBean
228    {
229    }
230
231    public static class StandardDynamic implements DynamicMBean JavaDoc, StandardDynamicMBean
232    {
233       public MBeanInfo JavaDoc getMBeanInfo()
234       {
235          return new MBeanInfo JavaDoc(getClass().getName(), null, null, null, null, null);
236       }
237
238       public Object JavaDoc getAttribute(String JavaDoc attribute) throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
239       {
240          return null;
241       }
242
243       public void setAttribute(Attribute JavaDoc attribute) throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
244       {
245       }
246
247       public AttributeList JavaDoc getAttributes(String JavaDoc[] attributes)
248       {
249          return new AttributeList JavaDoc();
250       }
251
252       public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributes)
253       {
254          return new AttributeList JavaDoc();
255       }
256
257       public Object JavaDoc invoke(String JavaDoc method, Object JavaDoc[] arguments, String JavaDoc[] params) throws MBeanException JavaDoc, ReflectionException JavaDoc
258       {
259          return null;
260       }
261    }
262
263
264    // JMX 1.0: Invalid MBean: the standard MBean interface is a dynamic MBean
265
// JMX 1.1: This is a dynamic MBean
266
public interface StandardAndDynamicMBean extends DynamicMBean JavaDoc
267    {
268       public void mix();
269    }
270
271    public static class StandardAndDynamic implements StandardAndDynamicMBean
272    {
273       public void mix()
274       {
275       }
276
277       public MBeanInfo JavaDoc getMBeanInfo()
278       {
279          return new MBeanInfo JavaDoc(getClass().getName(), null, null, null, null, null);
280       }
281
282       public Object JavaDoc getAttribute(String JavaDoc attribute) throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
283       {
284          return null;
285       }
286
287       public void setAttribute(Attribute JavaDoc attribute) throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
288       {
289       }
290
291       public AttributeList JavaDoc getAttributes(String JavaDoc[] attributes)
292       {
293          return null;
294       }
295
296       public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributes)
297       {
298          return null;
299       }
300
301       public Object JavaDoc invoke(String JavaDoc method, Object JavaDoc[] arguments, String JavaDoc[] params) throws MBeanException JavaDoc, ReflectionException JavaDoc
302       {
303          return null;
304       }
305    }
306
307
308    // A valid dynamic MBean
309
public static class BasicDynamic implements DynamicMBean JavaDoc
310    {
311       public MBeanInfo JavaDoc getMBeanInfo()
312       {
313          return new MBeanInfo JavaDoc(getClass().getName(), null, null, null, null, null);
314       }
315
316       public Object JavaDoc getAttribute(String JavaDoc attribute) throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
317       {
318          return null;
319       }
320
321       public void setAttribute(Attribute JavaDoc attribute) throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
322       {
323       }
324
325       public AttributeList JavaDoc getAttributes(String JavaDoc[] attributes)
326       {
327          return null;
328       }
329
330       public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributes)
331       {
332          return null;
333       }
334
335       public Object JavaDoc invoke(String JavaDoc method, Object JavaDoc[] arguments, String JavaDoc[] params) throws MBeanException JavaDoc, ReflectionException JavaDoc
336       {
337          return null;
338       }
339    }
340
341
342    // Invalid dynamic MBean because getClassName() returns null
343
public static class NoClassNameDynamicMBean extends BasicDynamic
344    {
345       public MBeanInfo JavaDoc getMBeanInfo()
346       {
347          MBeanInfo JavaDoc info = super.getMBeanInfo();
348          return new MBeanInfo JavaDoc(null, info.getDescription(), info.getAttributes(), info.getConstructors(), info.getOperations(), info.getNotifications());
349       }
350    }
351
352
353    // Valid dynamic MBean, even if its parent is standard
354
public static class DynamicFromStandard extends BasicStandard implements DynamicMBean JavaDoc
355    {
356       public MBeanInfo JavaDoc getMBeanInfo()
357       {
358          return new MBeanInfo JavaDoc(getClass().getName(), null, null, null, null, null);
359       }
360
361       public Object JavaDoc getAttribute(String JavaDoc attribute) throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
362       {
363          return null;
364       }
365
366       public void setAttribute(Attribute JavaDoc attribute) throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
367       {
368       }
369
370       public AttributeList JavaDoc getAttributes(String JavaDoc[] attributes)
371       {
372          return new AttributeList JavaDoc();
373       }
374
375       public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributes)
376       {
377          return new AttributeList JavaDoc();
378       }
379
380       public Object JavaDoc invoke(String JavaDoc method, Object JavaDoc[] arguments, String JavaDoc[] params) throws MBeanException JavaDoc, ReflectionException JavaDoc
381       {
382          return null;
383       }
384    }
385
386
387    // In JMX 1.0, this is a valid standard MBean even if its parent is dynamic
388
// In JMX 1.1, this is a dynamic MBean
389
public interface StandardFromDynamicMBean
390    {
391    }
392
393    public static class StandardFromDynamic extends DynamicFromStandard implements StandardFromDynamicMBean
394    {
395    }
396
397 }
398
Popular Tags