Source Code Cross Referenced for ViewMBeanCommand.java in  » JMX » jfoxmx » org » huihoo » jfox » jmx » adaptor » http » 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 » jfoxmx » org.huihoo.jfox.jmx.adaptor.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JFox, the OpenSource J2EE Application Server
002:         *
003:         * Copyright (C) 2002 huihoo.com
004:         * Distributable under GNU LGPL license
005:         * See the GNU Lesser General Public License for more details.
006:         */
007:
008:        package org.huihoo.jfox.jmx.adaptor.http;
009:
010:        import java.util.HashMap;
011:        import java.util.Map;
012:        import java.util.List;
013:        import java.util.ArrayList;
014:        import javax.management.ObjectName;
015:        import javax.management.MBeanServer; //import javax.management.ObjectInstance;
016:        import javax.management.MBeanInfo;
017:        import javax.management.MBeanAttributeInfo;
018:        import javax.management.AttributeList;
019:        import javax.management.Attribute;
020:        import javax.management.MBeanOperationInfo;
021:        import javax.management.MBeanParameterInfo;
022:        import org.huihoo.jfox.jmx.loading.PrimitiveClassLoader;
023:        import org.huihoo.jfox.jmx.ExtendedObjectInstance;
024:
025:        /**
026:         *
027:         * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
028:         */
029:
030:        public class ViewMBeanCommand extends AbstractCommand {
031:
032:            public void doGet(HttpRequest request, HttpResponse response)
033:                    throws Exception {
034:                String _objectName = request.getParameter("objectname");
035:                ObjectName objectName = new ObjectName(_objectName);
036:                MBeanServer server = request.getThread().getServer()
037:                        .getServer();
038:                ExtendedObjectInstance instance = (ExtendedObjectInstance) server
039:                        .getObjectInstance(objectName);
040:
041:                MBeanInfo info = server.getMBeanInfo(objectName);
042:                MBeanAttributeInfo[] attributes = info.getAttributes();
043:                //    for(int i=0; i<attributes.length; i++){
044:                //      System.out.println("Attribute: " + attributes[i].getNameSpace());
045:                //    }
046:
047:                AttributeList attributeList = server.getAttributes(objectName,
048:                        getAtrributeNames(attributes));
049:                //    for(int i=0; i<attributeList.size(); i++){
050:                //      System.out.println("AttributeList: " + attributeList.get(i));
051:                //    }
052:
053:                Map attributeMap = getAttributeMap(attributeList);
054:
055:                MBeanOperationInfo[] operations = info.getOperations();
056:
057:                ctx.put("instance", instance);
058:                ctx.put("attributes", attributes);
059:                ctx.put("attributeMap", attributeMap);
060:                ctx.put("operations", operations);
061:            }
062:
063:            public void doPost(HttpRequest request, HttpResponse response)
064:                    throws Exception {
065:                String operation = request.getParameter("operation");
066:                if (operation == null || operation.trim().length() == 0)
067:                    return;
068:                if (operation.equalsIgnoreCase("invoke")) {
069:                    doInvoke(request, response);
070:                } else if (operation.equalsIgnoreCase("setAttribute")) {
071:                    doSetAttribute(request, response);
072:                }
073:
074:                doGet(request, response);
075:
076:            }
077:
078:            private String[] getAtrributeNames(MBeanAttributeInfo[] attributes) {
079:                if (attributes == null || attributes.length == 0)
080:                    return new String[0];
081:
082:                List attributeNames = new ArrayList();
083:                for (int i = 0; i < attributes.length; i++) {
084:                    if (attributes[i].isReadable())
085:                        attributeNames.add(attributes[i].getName());
086:                }
087:                return (String[]) attributeNames.toArray(new String[0]);
088:            }
089:
090:            private Map getAttributeMap(AttributeList attributeList) {
091:                Map attributeMap = new HashMap();
092:                for (int i = 0; i < attributeList.size(); i++) {
093:                    Attribute attribute = (Attribute) attributeList.get(i);
094:                    //      System.out.println("Put Attribute: " + attribute.getNameSpace());
095:                    attributeMap.put(attribute.getName(), attribute.getValue());
096:                }
097:                return attributeMap;
098:            }
099:
100:            // Note: can't support the same operation name with different signature
101:            private void doInvoke(HttpRequest request, HttpResponse response)
102:                    throws Exception {
103:                String _objectName = request.getParameter("objectname");
104:                ObjectName objectName = new ObjectName(_objectName);
105:                String operationName = request.getParameter("operationName");
106:
107:                MBeanServer server = request.getThread().getServer()
108:                        .getServer();
109:                MBeanInfo info = server.getMBeanInfo(objectName);
110:                MBeanOperationInfo operationInfo = getOperationInfo(info,
111:                        operationName);
112:
113:                String[] signatures = getSignature(operationInfo);
114:                String[] _values = new String[signatures.length];
115:                for (int i = 0; i < signatures.length; i++) {
116:                    String _value = request.getParameter(operationInfo
117:                            .getName()
118:                            + "_" + i);
119:                    if (_value == null)
120:                        _value = "";
121:                    _values[i] = _value;
122:                }
123:                Object[] values = createObjects(_values, signatures);
124:
125:                server.invoke(objectName, operationName, values, signatures);
126:            }
127:
128:            private void doSetAttribute(HttpRequest request,
129:                    HttpResponse response) throws Exception {
130:                String _objectName = request.getParameter("objectname");
131:                String attributeName = request.getParameter("attributeName");
132:                String attributeValue = request.getParameter("attributeValue");
133:
134:                ObjectName objectName = new ObjectName(_objectName);
135:                MBeanServer server = request.getThread().getServer()
136:                        .getServer();
137:
138:                MBeanInfo info = server.getMBeanInfo(objectName);
139:                MBeanAttributeInfo[] attributeInfos = info.getAttributes();
140:                MBeanAttributeInfo attrInfo = null;
141:                for (int i = 0; i < attributeInfos.length; i++) {
142:                    if (attributeInfos[i].getName().equals(attributeName)) {
143:                        attrInfo = attributeInfos[i];
144:                        break;
145:                    }
146:                }
147:
148:                Class attrClass = null;
149:
150:                if (attrInfo.isReadable()) {
151:                    Object obj = null;
152:                    try {
153:                        obj = server.getAttribute(objectName, attributeName);
154:                    } catch (Exception e) {
155:                    }
156:                    attrClass = obj.getClass();
157:                } else {
158:                    try {
159:                        attrClass = Class.forName(attrInfo.getType());
160:                    } catch (Exception e) {
161:                        e.printStackTrace();
162:                    }
163:                }
164:                Object value = attrClass.getConstructor(
165:                        new Class[] { java.lang.String.class }).newInstance(
166:                        new Object[] { attributeValue });
167:                Attribute attribute = new Attribute(attributeName, value);
168:                server.setAttribute(objectName, attribute);
169:            }
170:
171:            private MBeanOperationInfo getOperationInfo(MBeanInfo info,
172:                    String operation) {
173:                MBeanOperationInfo[] operInfos = info.getOperations();
174:                for (int i = 0; i < operInfos.length; i++) {
175:                    if (operInfos[i].getName().equals(operation))
176:                        return operInfos[i];
177:                }
178:                return null;
179:            }
180:
181:            private String[] getSignature(MBeanOperationInfo operationInfo) {
182:                MBeanParameterInfo[] paramInfos = operationInfo.getSignature();
183:                String[] sigatures = new String[paramInfos.length];
184:                for (int i = 0; i < sigatures.length; i++) {
185:                    sigatures[i] = paramInfos[i].getType();
186:                }
187:                return sigatures;
188:            }
189:
190:            private Object[] createObjects(String[] values, String[] signatures) {
191:                PrimitiveClassLoader pcloader = PrimitiveClassLoader
192:                        .getInstance();
193:                Object[] objects = new Object[values.length];
194:                for (int i = 0; i < objects.length; i++) {
195:                    Object obj = pcloader
196:                            .createObject(values[i], signatures[i]);
197:                    if (obj == null)
198:                        obj = values[i];
199:                    objects[i] = obj;
200:                }
201:                return objects;
202:            }
203:
204:            public static void main(String[] args) {
205:
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.