Source Code Cross Referenced for MBeanDynamic.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:         * Copyright (C) The MX4J Contributors.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the MX4J License version 1.0.
006:         * See the terms of the MX4J License in the documentation provided with this software.
007:         */
008:
009:        package test.javax.management.support;
010:
011:        import javax.management.Attribute;
012:        import javax.management.AttributeList;
013:        import javax.management.AttributeNotFoundException;
014:        import javax.management.DynamicMBean;
015:        import javax.management.InvalidAttributeValueException;
016:        import javax.management.MBeanAttributeInfo;
017:        import javax.management.MBeanConstructorInfo;
018:        import javax.management.MBeanException;
019:        import javax.management.MBeanInfo;
020:        import javax.management.MBeanNotificationInfo;
021:        import javax.management.MBeanOperationInfo;
022:        import javax.management.MBeanParameterInfo;
023:        import javax.management.ReflectionException;
024:
025:        /**
026:         * @version $Revision: 1.4 $
027:         */
028:        public class MBeanDynamic implements  DynamicMBean {
029:            private String m_value1 = "";
030:            private String m_value2 = "";
031:
032:            public MBeanInfo getMBeanInfo() {
033:                MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[2];
034:                attrs[0] = new MBeanAttributeInfo("DynamicAttribute1",
035:                        "java.lang.String", "A first dynamic attribute", true,
036:                        true, false);
037:                attrs[1] = new MBeanAttributeInfo("DynamicAttribute2",
038:                        "java.lang.String", "A second dynamic attribute", true,
039:                        true, false);
040:
041:                MBeanConstructorInfo[] ctors = new MBeanConstructorInfo[1];
042:                ctors[0] = new MBeanConstructorInfo("ParameterlessConstructor",
043:                        "A dynamic constructor", new MBeanParameterInfo[0]);
044:
045:                MBeanOperationInfo[] opers = new MBeanOperationInfo[1];
046:                MBeanParameterInfo[] params = new MBeanParameterInfo[1];
047:                params[0] = new MBeanParameterInfo("supposedAttributeValue",
048:                        "java.lang.String",
049:                        "Checks if the value of the argument is equal to the value of the attribute");
050:                opers[0] = new MBeanOperationInfo("dynamicOperation",
051:                        "A dynamic operation", params, "boolean",
052:                        MBeanOperationInfo.INFO);
053:
054:                MBeanNotificationInfo[] notifs = new MBeanNotificationInfo[0];
055:
056:                return new MBeanInfo(getClass().getName(),
057:                        "A MBeanDynamic MBean", attrs, ctors, opers, notifs);
058:            }
059:
060:            private String getDynamicAttribute1() {
061:                return m_value1;
062:            }
063:
064:            private void setDynamicAttribute1(String value) {
065:                m_value1 = value;
066:            }
067:
068:            private String getDynamicAttribute2() {
069:                return m_value2;
070:            }
071:
072:            private void setDynamicAttribute2(String value) {
073:                m_value2 = value;
074:            }
075:
076:            private boolean dynamicOperation(String value) {
077:                return m_value1.equals(value);
078:            }
079:
080:            public Object getAttribute(String attribute)
081:                    throws AttributeNotFoundException, MBeanException,
082:                    ReflectionException {
083:                if (attribute.equals("DynamicAttribute1")) {
084:                    return getDynamicAttribute1();
085:                } else if (attribute.equals("DynamicAttribute2")) {
086:                    return getDynamicAttribute2();
087:                } else
088:                    throw new AttributeNotFoundException(attribute);
089:            }
090:
091:            public void setAttribute(Attribute attribute)
092:                    throws AttributeNotFoundException,
093:                    InvalidAttributeValueException, MBeanException,
094:                    ReflectionException {
095:                if (attribute.getName().equals("DynamicAttribute1")) {
096:                    Object val = attribute.getValue();
097:                    if (val instanceof  String) {
098:                        setDynamicAttribute1((String) val);
099:                    } else {
100:                        throw new InvalidAttributeValueException(
101:                                val == null ? "null" : val.toString());
102:                    }
103:                } else if (attribute.getName().equals("DynamicAttribute2")) {
104:                    Object val = attribute.getValue();
105:                    if (val instanceof  String) {
106:                        setDynamicAttribute2((String) val);
107:                    } else {
108:                        throw new InvalidAttributeValueException(
109:                                val == null ? "null" : val.toString());
110:                    }
111:                } else {
112:                    throw new AttributeNotFoundException(attribute.getName());
113:                }
114:            }
115:
116:            public AttributeList getAttributes(String[] attributes) {
117:                AttributeList list = new AttributeList();
118:                for (int i = 0; i < attributes.length; ++i) {
119:                    if (attributes[i].equals("DynamicAttribute1")) {
120:                        list.add(new Attribute(attributes[i],
121:                                getDynamicAttribute1()));
122:                    } else if (attributes[i].equals("DynamicAttribute2")) {
123:                        list.add(new Attribute(attributes[i],
124:                                getDynamicAttribute2()));
125:                    }
126:                }
127:                return list;
128:            }
129:
130:            public AttributeList setAttributes(AttributeList attributes) {
131:                AttributeList list = new AttributeList();
132:                for (int i = 0; i < attributes.size(); ++i) {
133:                    Attribute attr = (Attribute) attributes.get(i);
134:                    if (attr.getName().equals("DynamicAttribute1")
135:                            || attr.getName().equals("DynamicAttribute2")) {
136:                        try {
137:                            setAttribute(attr);
138:                            list.add(attr);
139:                        } catch (AttributeNotFoundException ignored) {
140:                        } catch (InvalidAttributeValueException ignored) {
141:                        } catch (MBeanException ignored) {
142:                        } catch (ReflectionException ignored) {
143:                        }
144:                    }
145:                }
146:                return list;
147:            }
148:
149:            public Object invoke(String method, Object[] arguments,
150:                    String[] params) throws MBeanException, ReflectionException {
151:                if (method.equals("dynamicOperation") && params.length == 1
152:                        && params[0].equals("java.lang.String")
153:                        && arguments.length == 1
154:                        && arguments[0] instanceof  String) {
155:                    boolean match = dynamicOperation((String) arguments[0]);
156:                    return new Boolean(match);
157:                } else {
158:                    throw new MBeanException(new IllegalArgumentException(
159:                            "Invalid method or arguments for invoke"));
160:                }
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.