KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jmx > export > TestDynamicMBean


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16
17 package org.springframework.jmx.export;
18
19 import javax.management.Attribute JavaDoc;
20 import javax.management.AttributeList JavaDoc;
21 import javax.management.AttributeNotFoundException JavaDoc;
22 import javax.management.DynamicMBean JavaDoc;
23 import javax.management.InvalidAttributeValueException JavaDoc;
24 import javax.management.MBeanAttributeInfo JavaDoc;
25 import javax.management.MBeanConstructorInfo JavaDoc;
26 import javax.management.MBeanException JavaDoc;
27 import javax.management.MBeanInfo JavaDoc;
28 import javax.management.MBeanNotificationInfo JavaDoc;
29 import javax.management.MBeanOperationInfo JavaDoc;
30 import javax.management.ReflectionException JavaDoc;
31
32 /**
33  * @author Rob Harrop
34  */

35 public class TestDynamicMBean implements DynamicMBean JavaDoc {
36
37     public void setFailOnInit(boolean failOnInit) {
38         if (failOnInit) {
39             throw new IllegalArgumentException JavaDoc("Failing on initialization");
40         }
41     }
42
43     public Object JavaDoc getAttribute(String JavaDoc attribute)
44             throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
45
46         if ("name".equals(attribute)) {
47             return "Rob Harrop";
48         }
49         else {
50             return null;
51         }
52     }
53
54     public void setAttribute(Attribute JavaDoc arg0) throws AttributeNotFoundException JavaDoc,
55             InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
56     }
57
58     public AttributeList JavaDoc getAttributes(String JavaDoc[] arg0) {
59         return null;
60     }
61
62     public AttributeList JavaDoc setAttributes(AttributeList JavaDoc arg0) {
63         return null;
64     }
65
66     public Object JavaDoc invoke(String JavaDoc arg0, Object JavaDoc[] arg1, String JavaDoc[] arg2)
67             throws MBeanException JavaDoc, ReflectionException JavaDoc {
68         return null;
69     }
70
71     public MBeanInfo JavaDoc getMBeanInfo() {
72         MBeanAttributeInfo JavaDoc attr =
73                 new MBeanAttributeInfo JavaDoc("name", "java.lang.String", "", true, false, false);
74
75         MBeanInfo JavaDoc inf = new MBeanInfo JavaDoc(
76                 TestDynamicMBean.class.getName(), "",
77                 new MBeanAttributeInfo JavaDoc[]{attr},
78                 new MBeanConstructorInfo JavaDoc[0],
79                 new MBeanOperationInfo JavaDoc[0],
80                 new MBeanNotificationInfo JavaDoc[0]);
81
82         return inf;
83     }
84
85 }
86
Popular Tags