Source Code Cross Referenced for MBeanDisplayBean.java in  » Portal » Open-Portal » com » sun » portal » admin » console » sra » monitoring » 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 » Portal » Open Portal » com.sun.portal.admin.console.sra.monitoring 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.admin.console.sra.monitoring;
002:
003:        import com.sun.data.provider.DataProvider;
004:        import com.sun.data.provider.impl.ObjectListDataProvider;
005:        import com.sun.portal.admin.console.sra.SraBaseBean;
006:        import com.sun.portal.admin.console.sra.utils.Util;
007:        import com.sun.web.ui.model.Option;
008:
009:        import com.sun.portal.admin.common.util.AdminClientUtil;
010:
011:        import javax.faces.event.ValueChangeEvent;
012:        import javax.management.MBeanAttributeInfo;
013:        import javax.management.MBeanInfo;
014:        import javax.management.ObjectName;
015:        import javax.management.QueryExp;
016:        import java.util.*;
017:        import java.util.logging.Level;
018:
019:        /**
020:         * author: Noble Paul Date: Jun 28, 2005, 1:01:21 PM
021:         */
022:        public class MBeanDisplayBean extends SraBaseBean {
023:            List instanceList = new ArrayList();
024:
025:            private int selectedBean = -1;
026:
027:            private String selectedProfile = "";
028:
029:            private String selectedHost = "";
030:
031:            private String selectedProxyType = "";
032:
033:            public static final String FOUR_SPACES = "    ";
034:
035:            private SRAMBean selectedBeanObj;
036:
037:            Map attributesMap;
038:
039:            private SRAProxiesBean.SRAInstance selectedInstance;
040:
041:            private int selected = -1;
042:
043:            List beans = new ArrayList() {
044:                public boolean add(Object o) {
045:                    SRAMBean sramBean = (SRAMBean) o;
046:                    if (sramBean.getName().hashCode() == selectedBean)
047:                        selectedBeanObj = sramBean;
048:                    return super .add(o);
049:                }
050:
051:                public boolean addAll(Collection c) {
052:                    for (Iterator iterator = c.iterator(); iterator.hasNext();) {
053:                        add(new SRAMBean((ObjectName) iterator.next()));
054:                    }
055:                    return true;
056:                }
057:            };
058:
059:            public MBeanDisplayBean() {
060:                super (GATEWAY_SVC, new String[0]);
061:                try {
062:                    init();
063:                } catch (Exception e) {
064:                    log(
065:                            Level.SEVERE,
066:                            "MBeanDisplayBean.MBeanDisplayBean() : Init failed ",
067:                            e);
068:                }
069:            }
070:
071:            public void initData() {
072:
073:            }
074:
075:            public void init() {
076:                String s = (String) Util.getRequestParameter("bean");
077:                selectedProfile = (String) Util.getRequestParameter("profile");
078:                selectedHost = (String) Util.getRequestParameter("host");
079:                selectedProxyType = (String) Util.getRequestParameter("proxy");
080:
081:                if (Util
082:                        .getSessionParameter("MONITORING_SELECTED_INSTANCE_OPTION") != null) {
083:                    Option opt = (Option) Util
084:                            .getSessionParameter("MONITORING_SELECTED_INSTANCE_OPTION");
085:                    setSelected(opt.getValue().toString());
086:                }
087:
088:                if (s != null) {
089:                    try {
090:                        selectedBean = Integer.parseInt(s);
091:                    } catch (NumberFormatException e) {
092:                        selectedBean = s.hashCode();
093:                    }
094:                }
095:
096:                List profiles = new SRAProxiesBean().getProfiles();
097:                String on = " "
098:                        + Util.evaluateCachedValueBinding(
099:                                "#{monitoring['string.on']}").toString() + " ";
100:                for (int i = 0; i < profiles.size(); i++) {
101:                    SRAProxiesBean.Profile profile = (SRAProxiesBean.Profile) profiles
102:                            .get(i);
103:                    String profName = profile.getName();
104:                    instanceList
105:                            .add(new Option(
106:                                    profName,
107:                                    Util
108:                                            .evaluateCachedValueBinding("#{monitoring['rowgroup.header']}")
109:                                            + profName, profName, true));
110:
111:                    List instances = profile.getInstancesList();
112:                    for (int j = 0; j < instances.size(); j++) {
113:                        SRAProxiesBean.SRAInstance sraInstance = (SRAProxiesBean.SRAInstance) instances
114:                                .get(j);
115:
116:                        if (sraInstance.getMonitoringStatus() != SRAProxiesBean.STARTED)
117:                            continue;
118:
119:                        String value = profName + ":"
120:                                + sraInstance.getTypeShort() + ":"
121:                                + sraInstance.getHostName();
122:                        String label = sraInstance.getType() + on
123:                                + sraInstance.getHostName();
124:                        instanceList.add(new Option(value, FOUR_SPACES + label,
125:                                "", false));
126:                        if (selectedHost == null)
127:                            selectedHost = sraInstance.getHostName();
128:                        if (selectedProxyType == null)
129:                            selectedProxyType = sraInstance.getTypeShort();
130:                        if (selectedProfile == null)
131:                            selectedProfile = profName;
132:
133:                        if (profName.equals(selectedProfile)
134:                                && sraInstance.getHostName().equals(
135:                                        selectedHost)
136:                                && sraInstance.getTypeShort().equals(
137:                                        selectedProxyType)) {
138:                            selected = instanceList.size() - 1;
139:                            selectedInstance = sraInstance;
140:                            beans.addAll(queryNames(sraInstance));
141:                        }
142:                    }
143:                }
144:            }
145:
146:            public Option[] getListItems() {
147:                return (Option[]) instanceList.toArray(new Option[0]);
148:            }
149:
150:            public void setListItems(Option[] listItems) {
151:            }
152:
153:            public String getSelected() {
154:                if (selected < 1)
155:                    return null;
156:                Option opt = (Option) instanceList.get(selected);
157:                return opt.getValue().toString();
158:            }
159:
160:            public void setSelected(String selected) {
161:            }
162:
163:            private List getMBeansList() {
164:                return beans;
165:            }
166:
167:            public ObjectListDataProvider getMbeans() {
168:                return new ObjectListDataProvider(getMBeansList());
169:            }
170:
171:            public void setMbeans(DataProvider mbeans) {
172:            }
173:
174:            public class NameValueBean implements  java.io.Serializable {
175:                String name;
176:
177:                String value;
178:
179:                public NameValueBean() {
180:                }
181:
182:                public NameValueBean(Map.Entry entry) {
183:                    name = (String) entry.getKey();
184:                    value = (String) entry.getValue();
185:                }
186:
187:                public NameValueBean(String name, String value) {
188:                    this .name = name;
189:                    this .value = value;
190:                }
191:
192:                public String getName() {
193:                    return name;
194:                }
195:
196:                public void setName(String name) {
197:                    this .name = name;
198:                }
199:
200:                public String getValue() {
201:                    return value;
202:                }
203:
204:                public void setValue(String value) {
205:                    this .value = value;
206:                }
207:
208:            }
209:
210:            public class SRAMBean {
211:                ObjectName objectName;
212:
213:                String name;
214:
215:                public SRAMBean(ObjectName o) {
216:                    this .objectName = o;
217:                    name = o.getKeyProperty("type");
218:                }
219:
220:                public String getName() {
221:                    return name;
222:                }
223:
224:                public ObjectName getObjectName() {
225:                    return objectName;
226:                }
227:
228:                public void setName(String name) {
229:                }
230:
231:                public boolean getShowAttributes() {
232:                    return name.hashCode() == selectedBean;
233:                }
234:
235:                public String getUrl() {
236:                    return "profile=" + selectedProfile + "&host="
237:                            + selectedHost + "&proxy=" + selectedProxyType
238:                            + "&bean=" + name.hashCode();
239:                }
240:            }
241:
242:            public String switchInstance(ValueChangeEvent event) {
243:                String value = event.getNewValue().toString();
244:                setSelectedValues(value);
245:
246:                Iterator iterator = instanceList.iterator();
247:                int i = 0;
248:                while (iterator.hasNext()) {
249:                    Option opt = (Option) iterator.next();
250:                    String optValue = opt.getValue().toString();
251:                    if (optValue.equals(value)) {
252:                        Util.setSessionParameter(
253:                                "MONITORING_SELECTED_INSTANCE_OPTION", opt);
254:                        break;
255:                    }
256:                    i++;
257:                }
258:                selected = i;
259:                return "";
260:
261:            }
262:
263:            private void setSelectedValues(String value) {
264:                String[] info = value.split(":");
265:                selectedProfile = info[0];
266:                selectedProxyType = info[1];
267:                selectedHost = info[2];
268:            }
269:
270:            // For the second table
271:
272:            public DataProvider getBeanAttributes() {
273:                if (selectedBean != -1) {
274:                    if (attributesMap == null) {
275:                        attributesMap = getAttributeNameValues();
276:                    }
277:                    // attributes = new StringWrapper []{new StringWrapper("Count =
278:                    // 52"),new StringWrapper("Start Time=35767645")};
279:                } else {
280:                    attributesMap = Collections.EMPTY_MAP;
281:                }
282:                ArrayList list = new ArrayList();
283:                Iterator iter = attributesMap.entrySet().iterator();
284:                while (iter.hasNext()) {
285:                    Map.Entry entry = (Map.Entry) iter.next();
286:                    list.add(new NameValueBean(entry));
287:                }
288:                return new ObjectListDataProvider(list);
289:            }
290:
291:            public String getSelectedAttribute() {
292:                if (selectedBeanObj == null)
293:                    return Util.evaluateCachedValueBinding(
294:                            "#{monitoring['string.none']}").toString();
295:                return selectedBeanObj.getName();
296:            }
297:
298:            public boolean getShowAttributeTable() {
299:                return !(selectedBean == -1);
300:
301:            }
302:
303:            private Set queryNames(SRAProxiesBean.SRAInstance instance) {
304:                Object result;
305:                Object[] params = new Object[5];
306:                String[] signatures = new String[5];
307:                params[0] = "queryNames";
308:                params[1] = instance.getTypeShort();
309:                params[2] = instance.getProfile().getName();
310:                try {
311:                    params[3] = new ObjectName("com.sun.portal:*");
312:                } catch (Exception e) {
313:                    log(Level.SEVERE,
314:                            "MBeanDisplayBean.queryNames() : Exception ", e);
315:                }
316:                params[4] = null;
317:                signatures[0] = signatures[1] = signatures[2] = STRING;
318:                signatures[3] = ObjectName.class.getName();
319:                signatures[4] = QueryExp.class.getName();
320:                result = invokeMonitoringMBean(params, signatures, instance);
321:                return (Set) result;
322:            }
323:
324:            protected Map getAttributeNameValues() {
325:                Map result = new TreeMap();
326:                MBeanInfo mBeanInfo = null;
327:                mBeanInfo = getMonitoringMBeanInfo();
328:
329:                MBeanAttributeInfo[] mBeanAttributeInfos = mBeanInfo
330:                        .getAttributes();
331:                for (int i = 0; i < mBeanAttributeInfos.length; i++) {
332:                    MBeanAttributeInfo mBeanAttributeInfo = mBeanAttributeInfos[i];
333:
334:                    if (mBeanAttributeInfo.isReadable()) {
335:                        String attributeName = mBeanAttributeInfo.getName();
336:                        result
337:                                .put(
338:                                        attributeName,
339:                                        String
340:                                                .valueOf(getMonitoringMBeanAttribute(attributeName)));
341:                        // String attributeType = mBeanAttributeInfo.getType();
342:
343:                        /*
344:                         * try { if (attributeType.startsWith("[")) { int dimension =
345:                         * attributeType.lastIndexOf("[") + 1; Object itemValue =
346:                         * getAttribute1(objectName, attributeName);
347:                         * 
348:                         * String elementType = attributeType.substring(dimension,
349:                         * dimension + 1); if (elementType.equals("B")) {
350:                         * result.putAll(getAttributeNameValues(attributeName,
351:                         * dimension, itemValue, byte.class)); } else if
352:                         * (elementType.equals("C")) {
353:                         * result.putAll(getAttributeNameValues(attributeName,
354:                         * dimension, itemValue, char.class)); } else if
355:                         * (elementType.equals("D")) {
356:                         * result.putAll(getAttributeNameValues(attributeName,
357:                         * dimension, itemValue, double.class)); } else if
358:                         * (elementType.equals("F")) {
359:                         * result.putAll(getAttributeNameValues(attributeName,
360:                         * dimension, itemValue, float.class)); } else if
361:                         * (elementType.equals("I")) {
362:                         * result.putAll(getAttributeNameValues(attributeName,
363:                         * dimension, itemValue, int.class)); } else if
364:                         * (elementType.equals("J")) {
365:                         * result.putAll(getAttributeNameValues(attributeName,
366:                         * dimension, itemValue, long.class)); } else if
367:                         * (elementType.equals("L")) { String arrayElementType =
368:                         * attributeType.substring(dimension + 1, attributeType.length() -
369:                         * ";".length()); try { Class arrayElementClass =
370:                         * Class.forName(arrayElementType);
371:                         * result.putAll(getAttributeNameValues(attributeName,
372:                         * dimension, itemValue, arrayElementClass)); } catch
373:                         * (ClassNotFoundException cnfe) {
374:                         * result.putAll(getAttributeNameValues(attributeName,
375:                         * dimension, itemValue, Object.class)); } } else if
376:                         * (elementType.equals("S")) {
377:                         * result.putAll(getAttributeNameValues(attributeName,
378:                         * dimension, itemValue, short.class)); } else if
379:                         * (elementType.equals("Z")) {
380:                         * result.putAll(getAttributeNameValues(attributeName,
381:                         * dimension, itemValue, boolean.class)); } else { } } else if
382:                         * (attributeType.equals("javax.management.openmbean.CompositeData")) {
383:                         * CompositeData compositeData = (CompositeData)
384:                         * getCommandClient().getAttribute(objectName, attributeName);
385:                         * result.putAll(getAttributeNameValues(attributeName,
386:                         * compositeData)); } else if
387:                         * (attributeType.equals("javax.management.openmbean.TabularData")) {
388:                         * TabularData tabularData = (TabularData)
389:                         * getCommandClient().getAttribute(objectName, attributeName);
390:                         * result.putAll(getAttributeNameValues(attributeName,
391:                         * tabularData)); } else { Object value =
392:                         * getCommandClient().getAttribute(objectName, attributeName);
393:                         * result.put(attributeName, value); } } catch (Throwable t) {
394:                         * System.err.println(objectName);
395:                         * System.err.println(getLocalizedString(MONITORING_PREFIX +
396:                         * WARNING + COULD_NOT_GET_ATTRIBUTE, new
397:                         * Object[]{attributeName})); }
398:                         */
399:                    }
400:                }
401:
402:                return result;
403:            }
404:
405:            public MBeanInfo getMonitoringMBeanInfo() {
406:                Object[] params = new Object[4];
407:                String[] types = new String[4];
408:                params[0] = "getMBeanInfo";
409:                params[1] = selectedInstance.getTypeShort();
410:                params[2] = selectedInstance.getProfile().getName();
411:                params[3] = selectedBeanObj.getObjectName();
412:                types[0] = types[1] = types[2] = STRING;
413:                types[3] = ObjectName.class.getName();
414:                return (MBeanInfo) invokeMonitoringMBean(params, types,
415:                        selectedInstance);
416:            }
417:
418:            private Object invokeMonitoringMBean(Object[] params,
419:                    String[] types, SRAProxiesBean.SRAInstance instance) {
420:                return invokeRemoteMBean(instance.host,
421:                        AdminClientUtil.SRA_MONITORING_MBEAN, "invoke",
422:                        new Object[] { null, null, params, types },
423:                        new String[] { ObjectName.class.getName(), STRING,
424:                                Object[].class.getName(),
425:                                String[].class.getName() });
426:            }
427:
428:            public Object getMonitoringMBeanAttribute(String attrName) {
429:                Object[] params = new Object[5];
430:                String[] types = new String[5];
431:                params[0] = "getAttribute";
432:                params[1] = selectedInstance.getTypeShort();
433:                params[2] = selectedInstance.getProfile().getName();
434:                params[3] = selectedBeanObj.getObjectName();
435:                params[4] = attrName;
436:
437:                types[0] = types[1] = types[2] = STRING;
438:                types[3] = ObjectName.class.getName();
439:                types[3] = STRING;
440:                return invokeMonitoringMBean(params, types, selectedInstance);
441:            }
442:        }
w___w__w._j_ava__2___s___._c__o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.