KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > management > mbeans > ConcreteMBean


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

15 package org.apache.hivemind.management.mbeans;
16
17 import javax.management.Attribute JavaDoc;
18 import javax.management.AttributeNotFoundException JavaDoc;
19 import javax.management.InvalidAttributeValueException JavaDoc;
20 import javax.management.MBeanAttributeInfo JavaDoc;
21 import javax.management.MBeanConstructorInfo JavaDoc;
22 import javax.management.MBeanException JavaDoc;
23 import javax.management.MBeanNotificationInfo JavaDoc;
24 import javax.management.MBeanOperationInfo JavaDoc;
25 import javax.management.MBeanParameterInfo JavaDoc;
26 import javax.management.ReflectionException JavaDoc;
27
28 /**
29  * Test MBean
30  *
31  * @author Achim Huegen
32  */

33 public class ConcreteMBean extends AbstractDynamicMBean
34 {
35     private String JavaDoc attribute1 = "value1";
36
37     private String JavaDoc attribute2 = "value2";
38
39     public boolean isSetAttribute1Called;
40
41     public boolean isSetAttribute2Called;
42
43     public ConcreteMBean()
44     {
45     }
46
47     protected MBeanAttributeInfo JavaDoc[] createMBeanAttributeInfo()
48     {
49         MBeanAttributeInfo JavaDoc att1 = new MBeanAttributeInfo JavaDoc("attribute1", "String", "", true,
50                 true, false);
51         MBeanAttributeInfo JavaDoc att2 = new MBeanAttributeInfo JavaDoc("attribute2", "String", "", true,
52                 true, false);
53         return new MBeanAttributeInfo JavaDoc[]
54         { att1, att2 };
55     }
56
57     protected MBeanConstructorInfo JavaDoc[] createMBeanConstructorInfo()
58     {
59         MBeanConstructorInfo JavaDoc constructor = new MBeanConstructorInfo JavaDoc("constructor", "",
60                 new MBeanParameterInfo JavaDoc[] {});
61         return new MBeanConstructorInfo JavaDoc[]
62         { constructor };
63     }
64
65     protected MBeanNotificationInfo JavaDoc[] createMBeanNotificationInfo()
66     {
67         MBeanNotificationInfo JavaDoc notification = new MBeanNotificationInfo JavaDoc(new String JavaDoc[0],
68                 "notification", "");
69         return new MBeanNotificationInfo JavaDoc[]
70         { notification };
71     }
72
73     protected MBeanOperationInfo JavaDoc[] createMBeanOperationInfo()
74     {
75         MBeanOperationInfo JavaDoc operation = new MBeanOperationInfo JavaDoc("operation", "",
76                 new MBeanParameterInfo JavaDoc[0], "String", 0);
77         return new MBeanOperationInfo JavaDoc[]
78         { operation };
79     }
80
81     public Object JavaDoc getAttribute(String JavaDoc name) throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc,
82             ReflectionException JavaDoc
83     {
84         if (name.equals("attribute1"))
85             return attribute1;
86         if (name.equals("attribute2"))
87             return attribute2;
88         throw new AttributeNotFoundException JavaDoc();
89     }
90
91     public void setAttribute(Attribute JavaDoc attribute) throws AttributeNotFoundException JavaDoc,
92             InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
93     {
94         if (attribute.getName().equals("attribute1"))
95             attribute1 = (String JavaDoc) attribute.getValue();
96         if (attribute.getName().equals("attribute2"))
97             attribute2 = (String JavaDoc) attribute.getValue();
98         throw new AttributeNotFoundException JavaDoc();
99     }
100 }
101
Popular Tags