Source Code Cross Referenced for PrivateMBeanDynamic.java in  » JMX » mx4j » test » javax » management » support » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » mx4j » test.javax.management.support 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:         * Copyright (C) The MX4J Contributors.
004:
005:         * All rights reserved.
006:
007:         *
008:
009:         * This software is distributed under the terms of the MX4J License version 1.0.
010:
011:         * See the terms of the MX4J License in the documentation provided with this software.
012:
013:         */
014:
015:        package test.javax.management.support;
016:
017:        import javax.management.Attribute;
018:        import javax.management.AttributeList;
019:        import javax.management.AttributeNotFoundException;
020:        import javax.management.DynamicMBean;
021:        import javax.management.InvalidAttributeValueException;
022:        import javax.management.MBeanAttributeInfo;
023:        import javax.management.MBeanConstructorInfo;
024:        import javax.management.MBeanException;
025:        import javax.management.MBeanInfo;
026:        import javax.management.MBeanNotificationInfo;
027:        import javax.management.MBeanOperationInfo;
028:        import javax.management.MBeanParameterInfo;
029:        import javax.management.ReflectionException;
030:
031:        /**
032:         * @version $Revision: 1.3 $
033:         */
034:
035:        class PrivateMBeanDynamic implements  DynamicMBean
036:
037:        {
038:
039:            private String m_value1 = "";
040:
041:            private String m_value2 = "";
042:
043:            public MBeanInfo getMBeanInfo()
044:
045:            {
046:
047:                MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[2];
048:
049:                attrs[0] = new MBeanAttributeInfo("DynamicAttribute1",
050:                        "java.lang.String", "A first dynamic attribute", true,
051:                        true, false);
052:
053:                attrs[1] = new MBeanAttributeInfo("DynamicAttribute2",
054:                        "java.lang.String", "A second dynamic attribute", true,
055:                        true, false);
056:
057:                MBeanConstructorInfo[] ctors = new MBeanConstructorInfo[1];
058:
059:                ctors[0] = new MBeanConstructorInfo(
060:                        "Parameterless Constructor", "A dynamic constructor",
061:                        new MBeanParameterInfo[0]);
062:
063:                MBeanOperationInfo[] opers = new MBeanOperationInfo[1];
064:
065:                MBeanParameterInfo[] params = new MBeanParameterInfo[1];
066:
067:                params[0] = new MBeanParameterInfo("supposedAttributeValue",
068:                        "java.lang.String",
069:                        "Checks if the value of the argument is equal to the value of the attribute");
070:
071:                opers[0] = new MBeanOperationInfo("dynamicOperation",
072:                        "A dynamic operation", params, "boolean",
073:                        MBeanOperationInfo.INFO);
074:
075:                MBeanNotificationInfo[] notifs = new MBeanNotificationInfo[0];
076:
077:                return new MBeanInfo(getClass().getName(),
078:                        "A MBeanDynamic MBean", attrs, ctors, opers, notifs);
079:
080:            }
081:
082:            private String getDynamicAttribute1() {
083:                return m_value1;
084:            }
085:
086:            private void setDynamicAttribute1(String value) {
087:                m_value1 = value;
088:            }
089:
090:            private String getDynamicAttribute2() {
091:                return m_value2;
092:            }
093:
094:            private void setDynamicAttribute2(String value) {
095:                m_value2 = value;
096:            }
097:
098:            private boolean dynamicOperation(String value) {
099:                return m_value1.equals(value);
100:            }
101:
102:            public Object getAttribute(String attribute)
103:                    throws AttributeNotFoundException, MBeanException,
104:                    ReflectionException
105:
106:            {
107:
108:                if (attribute.equals("DynamicAttribute1")) {
109:                    return getDynamicAttribute1();
110:                }
111:
112:                else if (attribute.equals("DynamicAttribute2")) {
113:                    return getDynamicAttribute2();
114:                }
115:
116:                else
117:                    throw new AttributeNotFoundException(attribute);
118:
119:            }
120:
121:            public void setAttribute(Attribute attribute)
122:                    throws AttributeNotFoundException,
123:                    InvalidAttributeValueException, MBeanException,
124:                    ReflectionException
125:
126:            {
127:
128:                if (attribute.getName().equals("DynamicAttribute1"))
129:
130:                {
131:
132:                    Object val = attribute.getValue();
133:
134:                    if (val instanceof  String) {
135:                        setDynamicAttribute1((String) val);
136:                    }
137:
138:                    else {
139:                        throw new InvalidAttributeValueException(
140:                                val == null ? "null" : val.toString());
141:                    }
142:
143:                }
144:
145:                else if (attribute.getName().equals("DynamicAttribute2"))
146:
147:                {
148:
149:                    Object val = attribute.getValue();
150:
151:                    if (val instanceof  String) {
152:                        setDynamicAttribute2((String) val);
153:                    }
154:
155:                    else {
156:                        throw new InvalidAttributeValueException(
157:                                val == null ? "null" : val.toString());
158:                    }
159:
160:                }
161:
162:                else {
163:                    throw new AttributeNotFoundException(attribute.getName());
164:                }
165:
166:            }
167:
168:            public AttributeList getAttributes(String[] attributes)
169:
170:            {
171:
172:                AttributeList list = new AttributeList();
173:
174:                for (int i = 0; i < attributes.length; ++i)
175:
176:                {
177:
178:                    if (attributes[i].equals("DynamicAttribute1"))
179:
180:                    {
181:
182:                        list.add(new Attribute(attributes[i],
183:                                getDynamicAttribute1()));
184:
185:                    }
186:
187:                    else if (attributes[i].equals("DynamicAttribute2"))
188:
189:                    {
190:
191:                        list.add(new Attribute(attributes[i],
192:                                getDynamicAttribute2()));
193:
194:                    }
195:
196:                }
197:
198:                return list;
199:
200:            }
201:
202:            public AttributeList setAttributes(AttributeList attributes)
203:
204:            {
205:
206:                AttributeList list = new AttributeList();
207:
208:                for (int i = 0; i < attributes.size(); ++i)
209:
210:                {
211:
212:                    Attribute attr = (Attribute) attributes.get(i);
213:
214:                    if (attr.getName().equals("DynamicAttribute1")
215:                            || attr.getName().equals("DynamicAttribute2"))
216:
217:                    {
218:
219:                        try
220:
221:                        {
222:
223:                            setAttribute(attr);
224:
225:                            list.add(attr);
226:
227:                        }
228:
229:                        catch (AttributeNotFoundException ignored) {
230:                        }
231:
232:                        catch (InvalidAttributeValueException ignored) {
233:                        }
234:
235:                        catch (MBeanException ignored) {
236:                        }
237:
238:                        catch (ReflectionException ignored) {
239:                        }
240:
241:                    }
242:
243:                }
244:
245:                return list;
246:
247:            }
248:
249:            public Object invoke(String method, Object[] arguments,
250:                    String[] params) throws MBeanException, ReflectionException
251:
252:            {
253:
254:                if (method.equals("dynamicOperation") &&
255:
256:                params.length == 1 &&
257:
258:                params[0].equals("java.lang.String") &&
259:
260:                arguments.length == 1 &&
261:
262:                arguments[0] instanceof  String)
263:
264:                {
265:
266:                    boolean match = dynamicOperation((String) arguments[0]);
267:
268:                    return new Boolean(match);
269:
270:                }
271:
272:                else
273:
274:                {
275:
276:                    throw new MBeanException(new IllegalArgumentException(
277:                            "Invalid method or arguments for invoke"));
278:
279:                }
280:
281:            }
282:
283:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.