Source Code Cross Referenced for EndpointStatisticsDataReader.java in  » ESB » open-esb » com » sun » esb » management » common » data » helper » 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 » ESB » open esb » com.sun.esb.management.common.data.helper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)EndpointStatisticsDataReader.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.esb.management.common.data.helper;
030:
031:        import java.io.File;
032:        import java.io.FileInputStream;
033:        import java.io.IOException;
034:        import java.io.InputStream;
035:        import java.io.Reader;
036:        import java.io.Serializable;
037:        import java.io.StringReader;
038:        import java.net.MalformedURLException;
039:        import java.net.URI;
040:        import java.net.URISyntaxException;
041:        import java.text.ParseException;
042:        import java.text.SimpleDateFormat;
043:        import java.util.Date;
044:        import java.util.HashMap;
045:        import java.util.Map;
046:        import java.util.Stack;
047:
048:        import javax.xml.parsers.ParserConfigurationException;
049:        import javax.xml.parsers.SAXParser;
050:        import javax.xml.parsers.SAXParserFactory;
051:
052:        import org.xml.sax.Attributes;
053:        import org.xml.sax.InputSource;
054:        import org.xml.sax.SAXException;
055:        import org.xml.sax.helpers.DefaultHandler;
056:
057:        import com.sun.esb.management.common.data.ConsumingEndpointStatisticsData;
058:        import com.sun.esb.management.common.data.IEndpointStatisticsData;
059:        import com.sun.esb.management.common.data.PerformanceData;
060:        import com.sun.esb.management.common.data.ProvisioningEndpointStatisticsData;
061:
062:        /**
063:         * @author graj
064:         *
065:         */
066:        public class EndpointStatisticsDataReader extends DefaultHandler
067:                implements  EndpointStatisticsDataXMLConstants, Serializable {
068:
069:            static final long serialVersionUID = -1L;
070:
071:            // Private members needed to parse the XML document
072:
073:            // keep track of parsing
074:            private boolean parsingInProgress;
075:
076:            // keep track of QName
077:            private Stack<String> qNameStack = new Stack<String>();
078:
079:            private String endpointStatisticsDataListVersion;
080:
081:            private IEndpointStatisticsData data;
082:
083:            private ProvisioningEndpointStatisticsData provisioningData;
084:
085:            private ConsumingEndpointStatisticsData consumingData;
086:
087:            private Map<String /* instanceName */, IEndpointStatisticsData> dataMap;
088:
089:            private PerformanceData performanceData;
090:
091:            private Map<String /* category */, PerformanceData> performanceDataMap;
092:
093:            private String performanceDataListVersion;
094:
095:            /**
096:             * Constructor - creates a new instance of
097:             * EndpointStatisticsDataReader
098:             */
099:            public EndpointStatisticsDataReader() {
100:            }
101:
102:            /**
103:             * @return the dataMap
104:             */
105:            public Map<String /* instanceName */, IEndpointStatisticsData> getEndpointStatisticsDataMap() {
106:                return this .dataMap;
107:            }
108:
109:            /**
110:             * Start of document processing.
111:             * 
112:             * @throws org.xml.sax.SAXException
113:             *             is any SAX exception, possibly wrapping another exception.
114:             */
115:            public void startDocument() throws SAXException {
116:                parsingInProgress = true;
117:                qNameStack.removeAllElements();
118:            }
119:
120:            /**
121:             * End of document processing.
122:             * 
123:             * @throws org.xml.sax.SAXException
124:             *             is any SAX exception, possibly wrapping another exception.
125:             */
126:            public void endDocument() throws SAXException {
127:                parsingInProgress = false;
128:                // We have encountered the end of the document. Do any processing that
129:                // is desired, for example dump all collected element2 values.
130:
131:            }
132:
133:            /**
134:             * Process the new element.
135:             * 
136:             * @param uri
137:             *            is the Namespace URI, or the empty string if the element has
138:             *            no Namespace URI or if Namespace processing is not being
139:             *            performed.
140:             * @param localName
141:             *            is the The local name (without prefix), or the empty string if
142:             *            Namespace processing is not being performed.
143:             * @param qName
144:             *            is the qualified name (with prefix), or the empty string if
145:             *            qualified names are not available.
146:             * @param attributes
147:             *            is the attributes attached to the element. If there are no
148:             *            attributes, it shall be an empty Attributes object.
149:             * @throws org.xml.sax.SAXException
150:             *             is any SAX exception, possibly wrapping another exception.
151:             */
152:            public void startElement(String uri, String localName,
153:                    String qName, Attributes attributes) throws SAXException {
154:                if (qName != null) {
155:                    if (qName.endsWith(ENDPOINT_STATISTICS_DATA_LIST_KEY)) {
156:                        // ELEMENT1 has an attribute, get it by name
157:                        // Do something with the attribute
158:                        if ((attributes != null)
159:                                && (attributes.getLength() > 0)) {
160:                            String namespace = attributes
161:                                    .getValue(ENDPOINT_NAMESPACE_KEY);
162:                            // //////////////////////////////////////////////////////
163:                            // Read performanceDataListVersion attribute and ensure you
164:                            // store the right
165:                            // performanceDataListVersion of the report map list
166:                            // //////////////////////////////////////////////////////
167:                            this .endpointStatisticsDataListVersion = attributes
168:                                    .getValue(ENDPOINT_VERSION_KEY);
169:                            if ((endpointStatisticsDataListVersion != null)
170:                                    && (ENDPOINT_VERSION_VALUE
171:                                            .equals(endpointStatisticsDataListVersion))) {
172:                                this .dataMap = new HashMap<String /* instanceName */, IEndpointStatisticsData>();
173:                            } else {
174:                                // Invalid endpointStatisticsDataListVersion.
175:                                // Not storing it
176:                            }
177:                        }
178:                    } else if (qName
179:                            .endsWith(PROVISIONING_ENDPOINT_STATISTICS_DATA_KEY)) {
180:                        // ELEMENT1 has an attribute, get it by name
181:                        // Do something with the attribute
182:                        if (this .dataMap != null) {
183:                            this .data = new ProvisioningEndpointStatisticsData();
184:                            this .provisioningData = (ProvisioningEndpointStatisticsData) this .data;
185:                        }
186:                    } else if (qName
187:                            .endsWith(CONSUMING_ENDPOINT_STATISTICS_DATA_KEY)) {
188:                        // ELEMENT1 has an attribute, get it by name
189:                        // Do something with the attribute
190:                        if (this .dataMap != null) {
191:                            this .data = new ConsumingEndpointStatisticsData();
192:                            this .consumingData = (ConsumingEndpointStatisticsData) this .data;
193:                        }
194:                    } else if (qName
195:                            .endsWith(PerformanceDataXMLConstants.PERFORMANCE_MEASUREMENT_DATA_LIST_KEY)) {
196:                        // ELEMENT1 has an attribute, get it by name
197:                        // Do something with the attribute
198:                        if ((attributes != null)
199:                                && (attributes.getLength() > 0)) {
200:                            String namespace = attributes
201:                                    .getValue(PerformanceDataXMLConstants.NAMESPACE_KEY);
202:                            ////////////////////////////////////////////////////////
203:                            // Read performanceDataListVersion attribute and ensure you store the right
204:                            // performanceDataListVersion of the data map list
205:                            ////////////////////////////////////////////////////////
206:                            this .performanceDataListVersion = attributes
207:                                    .getValue(PerformanceDataXMLConstants.VERSION_KEY);
208:                            if ((performanceDataListVersion != null)
209:                                    && (PerformanceDataXMLConstants.VERSION_VALUE
210:                                            .equals(performanceDataListVersion))) {
211:                                this .performanceDataMap = new HashMap<String /* category */, PerformanceData>();
212:                            } else {
213:                                // Invalid performanceDataListVersion. Not storing it
214:                            }
215:                        }
216:
217:                    } else if (qName
218:                            .endsWith(PerformanceDataXMLConstants.PERFORMANCE_MEASUREMENT_DATA_KEY)) {
219:                        // ELEMENT1 has an attribute, get it by name
220:                        // Do something with the attribute
221:                        if (this .performanceDataMap != null) {
222:                            this .performanceData = new PerformanceData();
223:                        }
224:                    }
225:
226:                    // Keep track of QNames
227:                    qNameStack.push(qName);
228:                }
229:            }
230:
231:            /**
232:             * Process the character report for current tag.
233:             * 
234:             * @param ch
235:             *            are the element's characters.
236:             * @param start
237:             *            is the start position in the character array.
238:             * @param length
239:             *            is the number of characters to use from the character array.
240:             * @throws org.xml.sax.SAXException
241:             *             is any SAX exception, possibly wrapping another exception.
242:             */
243:            public void characters(char[] ch, int start, int length)
244:                    throws SAXException {
245:                String qName;
246:                String chars = new String(ch, start, length);
247:                // Get current QName
248:                qName = (String) qNameStack.peek();
249:                ///////
250:                // 1. Read all the Provisioning Endpoints first
251:                if (true == qName
252:                        .endsWith(EndpointStatisticsDataXMLConstants.ACTIVATION_TIME_KEY)) {
253:                    if (data == null) {
254:                        data = new ProvisioningEndpointStatisticsData();
255:                        provisioningData = (ProvisioningEndpointStatisticsData) data;
256:                    }
257:                    Date value = null;
258:                    // Mon Dec 03 02:19:09 PST 2007
259:                    // Make a SimpleDateFormat for toString()'s output. This
260:                    // has short (text) date, a space, short (text) month, a space,
261:                    // 2-digit date, a space, hour (0-23), minute, second, a space,
262:                    // short timezone, a final space, and a long year.
263:                    SimpleDateFormat format = new SimpleDateFormat(
264:                            "EEE MMM dd HH:mm:ss zzz yyyy");
265:                    try {
266:                        value = format.parse(chars);
267:                    } catch (ParseException e) {
268:                    }
269:                    provisioningData.setActivationTime(value);
270:                }
271:                if (true == qName
272:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_ACTIVE_EXCHANGES_KEY)) {
273:                    if (data == null) {
274:                        data = new ProvisioningEndpointStatisticsData();
275:                        provisioningData = (ProvisioningEndpointStatisticsData) data;
276:                    }
277:                    Long value = new Long(chars);
278:                    provisioningData.setNumberOfActiveExchanges(value
279:                            .longValue());
280:                }
281:                if (true == qName
282:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_RECEIVED_REQUESTS_KEY)) {
283:                    if (data == null) {
284:                        data = new ProvisioningEndpointStatisticsData();
285:                        provisioningData = (ProvisioningEndpointStatisticsData) data;
286:                    }
287:                    Long value = new Long(chars);
288:                    provisioningData.setNumberOfReceivedRequests(value
289:                            .longValue());
290:                }
291:                if (true == qName
292:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_SENT_REPLIES_KEY)) {
293:                    if (data == null) {
294:                        data = new ProvisioningEndpointStatisticsData();
295:                        provisioningData = (ProvisioningEndpointStatisticsData) data;
296:                    }
297:                    Long value = new Long(chars);
298:                    provisioningData.setNumberOfSentReplies(value.longValue());
299:                }
300:                if (true == qName
301:                        .endsWith(EndpointStatisticsDataXMLConstants.UPTIME_KEY)) {
302:                    if (data == null) {
303:                        data = new ProvisioningEndpointStatisticsData();
304:                        provisioningData = (ProvisioningEndpointStatisticsData) data;
305:                    }
306:                    Long value = new Long(chars);
307:                    provisioningData.setUptime(value.longValue());
308:                }
309:                if (true == qName
310:                        .endsWith(EndpointStatisticsDataXMLConstants.MESSAGE_EXCHANGE_RESPONSE_TIME_AVERAGE_KEY)) {
311:                    if (data == null) {
312:                        data = new ProvisioningEndpointStatisticsData();
313:                        provisioningData = (ProvisioningEndpointStatisticsData) data;
314:                    }
315:                    Long value = new Long(chars);
316:                    provisioningData
317:                            .setMessageExchangeResponseTimeAverage(value
318:                                    .longValue());
319:                }
320:                // 2. Read all the Consuming Endpoints.
321:                if (true == qName
322:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_RECEIVED_REPLIES_KEY)) {
323:                    if (data == null) {
324:                        data = new ConsumingEndpointStatisticsData();
325:                        consumingData = (ConsumingEndpointStatisticsData) data;
326:                    }
327:                    Long value = new Long(chars);
328:                    consumingData.setNumberOfReceivedReplies(value.longValue());
329:                }
330:                if (true == qName
331:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_SENT_REQUESTS_KEY)) {
332:                    if (data == null) {
333:                        data = new ConsumingEndpointStatisticsData();
334:                        consumingData = (ConsumingEndpointStatisticsData) data;
335:                    }
336:                    Long value = new Long(chars);
337:                    consumingData.setNumberOfSentRequests(value.longValue());
338:                }
339:                if (true == qName
340:                        .endsWith(EndpointStatisticsDataXMLConstants.MESSAGE_EXCHANGE_STATUS_TIME_AVERAGE_KEY)) {
341:                    if (data == null) {
342:                        data = new ConsumingEndpointStatisticsData();
343:                        consumingData = (ConsumingEndpointStatisticsData) data;
344:                    }
345:                    Long value = new Long(chars);
346:                    consumingData.setMessageExchangeStatusTimeAverage(value
347:                            .longValue());
348:                }
349:                // 3. Read all the base Endpoint Statistics Data.
350:                if (true == qName
351:                        .endsWith(EndpointStatisticsDataXMLConstants.INSTANCE_NAME_KEY)) {
352:                    if (data != null) {
353:                        this .data.setInstanceName(chars);
354:                    }
355:                }
356:                if (true == qName
357:                        .endsWith(EndpointStatisticsDataXMLConstants.COMPONENT_NAME_KEY)) {
358:                    if (data != null) {
359:                        this .data.setComponentName(chars);
360:                    }
361:                }
362:                if (true == qName
363:                        .endsWith(EndpointStatisticsDataXMLConstants.MESSAGE_EXCHANGE_COMPONENT_TIME_AVERAGE_KEY)) {
364:                    Long value = new Long(chars);
365:                    if (data != null) {
366:                        this .data.setMessageExchangeComponentTimeAverage(value
367:                                .longValue());
368:                    }
369:                }
370:                if (true == qName
371:                        .endsWith(EndpointStatisticsDataXMLConstants.MESSAGE_EXCHANGE_DELIVERY_CHANNEL_TIME_AVERAGE_KEY)) {
372:                    Long value = new Long(chars);
373:                    if (data != null) {
374:                        this .data
375:                                .setMessageExchangeDeliveryChannelTimeAverage(value
376:                                        .longValue());
377:                    }
378:                }
379:                if (true == qName
380:                        .endsWith(EndpointStatisticsDataXMLConstants.MESSAGE_EXCHANGE_SERVICE_TIME_AVERAGE_KEY)) {
381:                    Long value = new Long(chars);
382:                    if (data != null) {
383:                        this .data.setMessageExchangeServiceTimeAverage(value
384:                                .longValue());
385:                    }
386:                }
387:                if (true == qName
388:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_RECEIVED_DONES_KEY)) {
389:                    Long value = new Long(chars);
390:                    if (data != null) {
391:                        this .data.setNumberOfReceivedDones(value.longValue());
392:                    }
393:                }
394:                if (true == qName
395:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_RECEIVED_ERRORS_KEY)) {
396:                    Long value = new Long(chars);
397:                    if (data != null) {
398:                        this .data.setNumberOfReceivedErrors(value.longValue());
399:                    }
400:                }
401:                if (true == qName
402:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_RECEIVED_FAULTS_KEY)) {
403:                    Long value = new Long(chars);
404:                    if (data != null) {
405:                        this .data.setNumberOfReceivedFaults(value.longValue());
406:                    }
407:                }
408:                if (true == qName
409:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_SENT_DONES_KEY)) {
410:                    Long value = new Long(chars);
411:                    if (data != null) {
412:                        this .data.setNumberOfSentDones(value.longValue());
413:                    }
414:                }
415:                if (true == qName
416:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_SENT_ERRORS_KEY)) {
417:                    Long value = new Long(chars);
418:                    if (data != null) {
419:                        this .data.setNumberOfSentErrors(value.longValue());
420:                    }
421:                }
422:                if (true == qName
423:                        .endsWith(EndpointStatisticsDataXMLConstants.NUMBER_OF_SENT_FAULTS_KEY)) {
424:                    Long value = new Long(chars);
425:                    if (data != null) {
426:                        this .data.setNumberOfSentFaults(value.longValue());
427:                    }
428:                }
429:                ////////
430:                if (qName.endsWith(PerformanceDataXMLConstants.CATEGORY_KEY)) {
431:                    if (this .performanceData != null) {
432:                        this .performanceData.setCategory(chars);
433:                    }
434:                } else if (qName
435:                        .endsWith(PerformanceDataXMLConstants.ENDPOINT_KEY)) {
436:                    if (this .performanceData != null) {
437:                        this .performanceData.setEndpoint(chars);
438:                    }
439:                } else if (qName
440:                        .endsWith(PerformanceDataXMLConstants.SOURCE_CLASS_NAME_KEY)) {
441:                    if (this .performanceData != null) {
442:                        this .performanceData.setSourceClassName(chars);
443:                    }
444:                } else if (qName
445:                        .endsWith(PerformanceDataXMLConstants.NUMBER_OF_MEASUREMENT_OBJECTS_KEY)) {
446:                    if (this .performanceData != null) {
447:                        int numberOfMeasurementObjects = Integer.valueOf(chars)
448:                                .intValue();
449:                        this .performanceData
450:                                .setNumberOfMeasurementObjects(numberOfMeasurementObjects);
451:                    }
452:                } else if (qName
453:                        .endsWith(PerformanceDataXMLConstants.NUMBER_OF_MEASUREMENTS_KEY)) {
454:                    if (this .performanceData != null) {
455:                        int numberOfMeasurements = Integer.valueOf(chars)
456:                                .intValue();
457:                        this .performanceData
458:                                .setNumberOfMeasurements(numberOfMeasurements);
459:                    }
460:                } else if (qName
461:                        .endsWith(PerformanceDataXMLConstants.AVERAGE_KEY)) {
462:                    if (this .performanceData != null) {
463:                        double average = Double.valueOf(chars).doubleValue();
464:                        this .performanceData.setAverage(average);
465:                    }
466:                } else if (qName
467:                        .endsWith(PerformanceDataXMLConstants.AVERAGE_WITHOUT_FIRST_MEASUREMENT_KEY)) {
468:                    if (this .performanceData != null) {
469:                        double averageWithoutFirstMeasurement = Double.valueOf(
470:                                chars).doubleValue();
471:                        this .performanceData
472:                                .setAverageWithoutFirstMeasurement(averageWithoutFirstMeasurement);
473:                    }
474:                } else if (qName
475:                        .endsWith(PerformanceDataXMLConstants.FIRST_MEASUREMENT_TIME_KEY)) {
476:                    if (this .performanceData != null) {
477:                        double firstMeasurementTime = Double.valueOf(chars)
478:                                .doubleValue();
479:                        this .performanceData
480:                                .setFirstMeasurementTime(firstMeasurementTime);
481:                    }
482:                } else if (qName.endsWith(PerformanceDataXMLConstants.LOAD_KEY)) {
483:                    if (this .performanceData != null) {
484:                        double load = Double.valueOf(chars).doubleValue();
485:                        this .performanceData.setLoad(load);
486:                    }
487:                } else if (qName
488:                        .endsWith(PerformanceDataXMLConstants.MEDIAN_KEY)) {
489:                    if (this .performanceData != null) {
490:                        double median = Double.valueOf(chars).doubleValue();
491:                        this .performanceData.setMedian(median);
492:                    }
493:                } else if (qName
494:                        .endsWith(PerformanceDataXMLConstants.THROUGHPUT_KEY)) {
495:                    if (this .performanceData != null) {
496:                        double throughput = Double.valueOf(chars).doubleValue();
497:                        this .performanceData.setThroughput(throughput);
498:                    }
499:                } else if (qName
500:                        .endsWith(PerformanceDataXMLConstants.TIME_TAKEN_KEY)) {
501:                    if (this .performanceData != null) {
502:                        double timeTaken = Double.valueOf(chars).doubleValue();
503:                        this .performanceData.setTimeTaken(timeTaken);
504:                    }
505:                } else if (qName
506:                        .endsWith(PerformanceDataXMLConstants.TOTAL_TIME_KEY)) {
507:                    if (this .performanceData != null) {
508:                        double totalTime = Double.valueOf(chars).doubleValue();
509:                        this .performanceData.setTotalTime(totalTime);
510:                    }
511:                }
512:            }
513:
514:            /**
515:             * Process the end element tag.
516:             * 
517:             * @param uri
518:             *            is the Namespace URI, or the empty string if the element has
519:             *            no Namespace URI or if Namespace processing is not being
520:             *            performed.
521:             * @param localName
522:             *            is the The local name (without prefix), or the empty string if
523:             *            Namespace processing is not being performed.
524:             * @param qName
525:             *            is the qualified name (with prefix), or the empty string if
526:             *            qualified names are not available.
527:             * @throws org.xml.sax.SAXException
528:             *             is any SAX exception, possibly wrapping another exception.
529:             */
530:            public void endElement(String uri, String localName, String qName)
531:                    throws SAXException {
532:                // Pop QName, since we are done with it
533:                qNameStack.pop();
534:                if (qName != null) {
535:                    if (qName
536:                            .endsWith(PROVISIONING_ENDPOINT_STATISTICS_DATA_KEY)) {
537:                        // We have encountered the end of ELEMENT1
538:                        // ...
539:                        if ((this .dataMap != null) && (this .data != null)) {
540:                            this .dataMap.put(this .data.getInstanceName(),
541:                                    this .provisioningData);
542:                            this .data = null;
543:                            this .provisioningData = null;
544:                        }
545:                    }
546:                    if (qName.endsWith(CONSUMING_ENDPOINT_STATISTICS_DATA_KEY)) {
547:                        // We have encountered the end of ELEMENT1
548:                        // ...
549:                        if ((this .dataMap != null) && (this .data != null)) {
550:                            this .dataMap.put(this .data.getInstanceName(),
551:                                    this .consumingData);
552:                            this .data = null;
553:                            this .consumingData = null;
554:                        }
555:                    }
556:                    if (qName
557:                            .endsWith(PerformanceDataXMLConstants.PERFORMANCE_MEASUREMENT_DATA_KEY)) {
558:                        // We have encountered the end of ELEMENT1
559:                        // ...
560:                        if ((this .dataMap != null) && (this .data != null)
561:                                && (this .performanceDataMap != null)
562:                                && (this .performanceData != null)) {
563:                            this .performanceDataMap.put(this .performanceData
564:                                    .getCategory(), this .performanceData);
565:                            this .performanceData = null;
566:                        }
567:                    }
568:                    if (qName
569:                            .endsWith(PerformanceDataXMLConstants.PERFORMANCE_MEASUREMENT_DATA_LIST_KEY)) {
570:                        // We have encountered the end of ELEMENT1
571:                        // ...
572:                        if ((this .dataMap != null) && (this .data != null)
573:                                && (this .performanceDataMap != null)) {
574:                            this .data
575:                                    .setCategoryToPerformanceDataMap(this .performanceDataMap);
576:                            this .performanceDataMap = null;
577:                            this .performanceData = null;
578:
579:                        }
580:                    }
581:                }
582:            }
583:
584:            /**
585:             * 
586:             * @param rawXMLData
587:             * @return
588:             * @throws MalformedURLException
589:             * @throws ParserConfigurationException
590:             * @throws SAXException
591:             * @throws URISyntaxException
592:             * @throws IOException
593:             */
594:            public static Map<String /* instanceName */, IEndpointStatisticsData> parseFromXMLData(
595:                    String rawXMLData) throws MalformedURLException,
596:                    ParserConfigurationException, SAXException,
597:                    URISyntaxException, IOException {
598:                // System.out.println("Parsing file: "+uriString);
599:                // Get an instance of the SAX parser factory
600:                SAXParserFactory factory = SAXParserFactory.newInstance();
601:
602:                // Get an instance of the SAX parser
603:                SAXParser saxParser = factory.newSAXParser();
604:
605:                // Initialize the XML Document InputStream
606:                Reader reader = new StringReader(rawXMLData);
607:
608:                // Create an InputSource from the InputStream
609:                InputSource inputSource = new InputSource(reader);
610:
611:                // Parse the aspectInput XML document stream, using my event handler
612:                EndpointStatisticsDataReader parser = new EndpointStatisticsDataReader();
613:                saxParser.parse(inputSource, parser);
614:
615:                return parser.getEndpointStatisticsDataMap();
616:
617:            }
618:
619:            /**
620:             * 
621:             * @param fileName
622:             * @return
623:             * @throws MalformedURLException
624:             * @throws ParserConfigurationException
625:             * @throws SAXException
626:             * @throws URISyntaxException
627:             * @throws IOException
628:             */
629:            public static Map<String /* instanceName */, IEndpointStatisticsData> parseFromFile(
630:                    String fileName) throws MalformedURLException,
631:                    ParserConfigurationException, SAXException,
632:                    URISyntaxException, IOException {
633:                File file = new File(fileName);
634:                return parseFromFile(file);
635:            }
636:
637:            /**
638:             * 
639:             * @param fileName
640:             * @return
641:             * @throws MalformedURLException
642:             * @throws ParserConfigurationException
643:             * @throws SAXException
644:             * @throws URISyntaxException
645:             * @throws IOException
646:             */
647:            public static Map<String /* instanceName */, IEndpointStatisticsData> parseFromFile(
648:                    File file) throws MalformedURLException,
649:                    ParserConfigurationException, SAXException,
650:                    URISyntaxException, IOException {
651:
652:                // Get an instance of the SAX parser factory
653:                SAXParserFactory factory = SAXParserFactory.newInstance();
654:
655:                // Get an instance of the SAX parser
656:                SAXParser saxParser = factory.newSAXParser();
657:
658:                // Initialize the URI and XML Document InputStream
659:                InputStream inputStream = new FileInputStream(file);
660:
661:                // Create an InputSource from the InputStream
662:                InputSource inputSource = new InputSource(inputStream);
663:
664:                // Parse the aspectInput XML document stream, using my event handler
665:                EndpointStatisticsDataReader parser = new EndpointStatisticsDataReader();
666:                saxParser.parse(inputSource, parser);
667:
668:                return parser.getEndpointStatisticsDataMap();
669:            }
670:
671:            /**
672:             * 
673:             * @param uriString
674:             * @return
675:             * @throws MalformedURLException
676:             * @throws ParserConfigurationException
677:             * @throws SAXException
678:             * @throws URISyntaxException
679:             * @throws IOException
680:             */
681:            public static Map<String /* instanceName */, IEndpointStatisticsData> parseFromURI(
682:                    String uriString) throws MalformedURLException,
683:                    ParserConfigurationException, SAXException,
684:                    URISyntaxException, IOException {
685:                URI uri = new URI(uriString);
686:                return parseFromURI(uri);
687:            }
688:
689:            /**
690:             * 
691:             * @param uri
692:             * @return
693:             * @throws MalformedURLException
694:             * @throws ParserConfigurationException
695:             * @throws SAXException
696:             * @throws URISyntaxException
697:             * @throws IOException
698:             */
699:            public static Map<String /* instanceName */, IEndpointStatisticsData> parseFromURI(
700:                    URI uri) throws MalformedURLException,
701:                    ParserConfigurationException, SAXException,
702:                    URISyntaxException, IOException {
703:
704:                // Get an instance of the SAX parser factory
705:                SAXParserFactory factory = SAXParserFactory.newInstance();
706:
707:                // Get an instance of the SAX parser
708:                SAXParser saxParser = factory.newSAXParser();
709:
710:                // Initialize the URI and XML Document InputStream
711:                InputStream inputStream = uri.toURL().openStream();
712:
713:                // Create an InputSource from the InputStream
714:                InputSource inputSource = new InputSource(inputStream);
715:
716:                // Parse the aspectInput XML document stream, using my event handler
717:                EndpointStatisticsDataReader parser = new EndpointStatisticsDataReader();
718:                saxParser.parse(inputSource, parser);
719:
720:                return parser.getEndpointStatisticsDataMap();
721:            }
722:
723:            /**
724:             * @param args
725:             */
726:            public static void main(String[] args) {
727:                String uri = "C:/test/schema/endpointstatistics/EndpointStatisticsData.xml";
728:                try {
729:                    Map<String /* instanceName */, IEndpointStatisticsData> map = null;
730:                    map = EndpointStatisticsDataReader.parseFromFile(uri);
731:                    for (String instanceName : map.keySet()) {
732:                        System.out.println("////////////////////////");
733:                        System.out.println("//" + instanceName);
734:                        System.out.println("////////////////////////");
735:                        System.out.println(map.get(instanceName)
736:                                .getDisplayString());
737:                    }
738:                } catch (MalformedURLException e) {
739:                    e.printStackTrace();
740:                } catch (ParserConfigurationException e) {
741:                    e.printStackTrace();
742:                } catch (SAXException e) {
743:                    e.printStackTrace();
744:                } catch (URISyntaxException e) {
745:                    e.printStackTrace();
746:                } catch (IOException e) {
747:                    e.printStackTrace();
748:                }
749:            }
750:
751:        }
w___ww.___ja_v___a2s_.__co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.