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


001:        /*
002:         * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.monitoring.statistics;
006:
007:        import com.sun.portal.log.common.PortalLogger;
008:
009:        import javax.management.*;
010:        import javax.management.openmbean.CompositeData;
011:        import javax.management.openmbean.CompositeDataSupport;
012:        import javax.management.openmbean.OpenDataException;
013:        import java.util.Iterator;
014:        import java.util.Map;
015:        import java.util.TreeMap;
016:        import java.util.logging.Logger;
017:        import java.util.logging.LogRecord;
018:        import java.util.logging.Level;
019:
020:        public class OpenStatistic implements  DynamicMBean {
021:            private static final Logger logger = PortalLogger
022:                    .getLogger(OpenStatistic.class);
023:
024:            private static LogRecord getLogRecord(Level level, String message,
025:                    Object[] parameters, Throwable t) {
026:                LogRecord result = new LogRecord(level, message);
027:                result.setLoggerName(logger.getName());
028:                result.setParameters(parameters);
029:                result.setThrown(t);
030:                return result;
031:            }
032:
033:            private StatisticWrapper statisticWrapper;
034:
035:            public OpenStatistic(StatisticWrapper statisticWrapper) {
036:                this .statisticWrapper = statisticWrapper;
037:            }
038:
039:            public StatisticWrapper getStatisticWrapper() {
040:                return statisticWrapper;
041:            }
042:
043:            public Object getAttribute(String name)
044:                    throws AttributeNotFoundException, MBeanException,
045:                    ReflectionException {
046:                if (name == null) {
047:                    throw new AttributeNotFoundException("null");
048:                }
049:
050:                if (name.length() == 0) {
051:                    throw new AttributeNotFoundException("");
052:                }
053:
054:                CompositeData compositeData;
055:                try {
056:                    compositeData = statisticWrapper.toCompositeData();
057:                } catch (OpenDataException e) {
058:                    if (logger.isLoggable(Level.SEVERE)) {
059:                        logger.log(getLogRecord(Level.SEVERE, "PSMN_CSPM0001",
060:                                new Object[] { e.getLocalizedMessage() }, e));
061:                    }
062:                    throw new MBeanException(e);
063:                }
064:
065:                Object result;
066:                if (compositeData.containsKey(name)) {
067:                    result = compositeData.get(name);
068:                } else {
069:                    throw new AttributeNotFoundException(name);
070:                }
071:
072:                return result;
073:            }
074:
075:            private Map getItemNamesValues(CompositeData compositeData) {
076:                String[] itemNames = statisticWrapper.getItemNames();
077:                Object[] itemValues = compositeData.getAll(itemNames);
078:                Map map = new TreeMap();
079:                for (int i = 0; i < itemNames.length; i++) {
080:                    map.put(itemNames[i], itemValues[i]);
081:                }
082:
083:                return map;
084:            }
085:
086:            public void setAttribute(Attribute attribute)
087:                    throws AttributeNotFoundException,
088:                    InvalidAttributeValueException, MBeanException,
089:                    ReflectionException {
090:                if (attribute == null) {
091:                    throw new AttributeNotFoundException("null");
092:                } else if (attribute.getName() == null) {
093:                    throw new AttributeNotFoundException("null");
094:                }
095:
096:                CompositeData compositeData;
097:                try {
098:                    compositeData = statisticWrapper.toCompositeData();
099:                } catch (OpenDataException e) {
100:                    if (logger.isLoggable(Level.SEVERE)) {
101:                        logger.log(getLogRecord(Level.SEVERE, "PSMN_CSPM0001",
102:                                new Object[] { e.getLocalizedMessage() }, e));
103:                    }
104:                    throw new MBeanException(e);
105:                }
106:
107:                if (compositeData.containsKey(attribute.getName())) {
108:                    Map itemNamesValues = getItemNamesValues(compositeData);
109:                    itemNamesValues.put(attribute.getName(), attribute
110:                            .getValue());
111:                    try {
112:                        compositeData = new CompositeDataSupport(compositeData
113:                                .getCompositeType(), itemNamesValues);
114:                    } catch (OpenDataException e) {
115:                        if (logger.isLoggable(Level.SEVERE)) {
116:                            logger.log(getLogRecord(Level.SEVERE,
117:                                    "PSMN_CSPM0001", new Object[] { e
118:                                            .getLocalizedMessage() }, e));
119:                        }
120:                        throw new MBeanException(e);
121:                    }
122:
123:                    try {
124:                        statisticWrapper.fromCompositeData(compositeData);
125:                    } catch (OpenDataException e) {
126:                        if (logger.isLoggable(Level.SEVERE)) {
127:                            logger.log(getLogRecord(Level.SEVERE,
128:                                    "PSMN_CSPM0001", new Object[] { e
129:                                            .getLocalizedMessage() }, e));
130:                        }
131:                        throw new MBeanException(e);
132:                    }
133:                } else {
134:                    throw new AttributeNotFoundException(attribute.getName());
135:                }
136:            }
137:
138:            public AttributeList getAttributes(String[] names) {
139:                AttributeList result = null;
140:
141:                if (names != null) {
142:                    if (names.length != 0) {
143:                        result = new AttributeList();
144:                        for (int i = 0; i < names.length; i++) {
145:                            try {
146:                                result.add(new Attribute(names[i],
147:                                        getAttribute(names[i])));
148:                            } catch (AttributeNotFoundException e) {
149:                                if (logger.isLoggable(Level.INFO)) {
150:                                    logger
151:                                            .log(getLogRecord(
152:                                                    Level.INFO,
153:                                                    "PSMN_CSPM0001",
154:                                                    new Object[] { e
155:                                                            .getLocalizedMessage() },
156:                                                    e));
157:                                }
158:                            } catch (MBeanException e) {
159:                                if (logger.isLoggable(Level.SEVERE)) {
160:                                    logger
161:                                            .log(getLogRecord(
162:                                                    Level.SEVERE,
163:                                                    "PSMN_CSPM0001",
164:                                                    new Object[] { e
165:                                                            .getLocalizedMessage() },
166:                                                    e));
167:                                }
168:                            } catch (ReflectionException e) {
169:                                if (logger.isLoggable(Level.SEVERE)) {
170:                                    logger
171:                                            .log(getLogRecord(
172:                                                    Level.SEVERE,
173:                                                    "PSMN_CSPM0001",
174:                                                    new Object[] { e
175:                                                            .getLocalizedMessage() },
176:                                                    e));
177:                                }
178:                            }
179:                        }
180:                    }
181:                }
182:
183:                return result;
184:            }
185:
186:            public AttributeList setAttributes(AttributeList attributeList) {
187:                AttributeList result = null;
188:
189:                CompositeData compositeData;
190:                try {
191:                    compositeData = statisticWrapper.toCompositeData();
192:                } catch (OpenDataException e) {
193:                    if (logger.isLoggable(Level.SEVERE)) {
194:                        logger.log(getLogRecord(Level.SEVERE, "PSMN_CSPM0001",
195:                                new Object[] { e.getLocalizedMessage() }, e));
196:                    }
197:                    throw new RuntimeException(e);
198:                }
199:
200:                Map itemNamesValues = getItemNamesValues(compositeData);
201:                for (Iterator iterator = attributeList.iterator(); iterator
202:                        .hasNext();) {
203:                    Attribute attribute = (Attribute) iterator.next();
204:                    if (compositeData.containsKey(attribute.getName())) {
205:                        itemNamesValues.put(attribute.getName(), attribute
206:                                .getValue());
207:                    } else {
208:                        throw new RuntimeException(
209:                                new AttributeNotFoundException(attribute
210:                                        .getName()));
211:                    }
212:                }
213:
214:                try {
215:                    compositeData = new CompositeDataSupport(compositeData
216:                            .getCompositeType(), itemNamesValues);
217:                } catch (OpenDataException e) {
218:                    if (logger.isLoggable(Level.SEVERE)) {
219:                        logger.log(getLogRecord(Level.SEVERE, "PSMN_CSPM0001",
220:                                new Object[] { e.getLocalizedMessage() }, e));
221:                    }
222:                    throw new RuntimeException(e);
223:                }
224:
225:                try {
226:                    statisticWrapper.fromCompositeData(compositeData);
227:                } catch (OpenDataException e) {
228:                    if (logger.isLoggable(Level.SEVERE)) {
229:                        logger.log(getLogRecord(Level.SEVERE, "PSMN_CSPM0001",
230:                                new Object[] { e.getLocalizedMessage() }, e));
231:                    }
232:                    throw new RuntimeException(e);
233:                }
234:
235:                return result;
236:            }
237:
238:            public Object invoke(String name, Object[] params,
239:                    String[] paramTypes) throws MBeanException,
240:                    ReflectionException {
241:                if (name.equals("reset")) {
242:                    statisticWrapper.getStatisticImpl().reset();
243:                    return null;
244:                }
245:
246:                throw new ReflectionException(new NoSuchMethodException(name));
247:            }
248:
249:            public MBeanInfo getMBeanInfo() {
250:                try {
251:                    return statisticWrapper.getMBeanInfo();
252:                } catch (OpenDataException e) {
253:                    if (logger.isLoggable(Level.SEVERE)) {
254:                        logger.log(getLogRecord(Level.SEVERE, "PSMN_CSPM0001",
255:                                new Object[] { e.getLocalizedMessage() }, e));
256:                    }
257:                    throw new RuntimeException(e);
258:                }
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.