Source Code Cross Referenced for FrameworkStatisticsDataReader.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:         * @(#)FrameworkStatisticsDataReader.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.util.HashMap;
042:        import java.util.Map;
043:        import java.util.Stack;
044:
045:        import javax.xml.parsers.ParserConfigurationException;
046:        import javax.xml.parsers.SAXParser;
047:        import javax.xml.parsers.SAXParserFactory;
048:
049:        import org.xml.sax.Attributes;
050:        import org.xml.sax.InputSource;
051:        import org.xml.sax.SAXException;
052:        import org.xml.sax.helpers.DefaultHandler;
053:
054:        import com.sun.esb.management.common.data.FrameworkStatisticsData;
055:
056:        /**
057:         * @author graj
058:         *
059:         */
060:        public class FrameworkStatisticsDataReader extends DefaultHandler
061:                implements  FrameworkStatisticsDataXMLConstants, Serializable {
062:
063:            static final long serialVersionUID = -1L;
064:
065:            // Private members needed to parse the XML document
066:
067:            // keep track of parsing
068:            private boolean parsingInProgress;
069:
070:            // keep track of QName
071:            private Stack<String> qNameStack = new Stack<String>();
072:
073:            private String frameworkStatisticsDataListVersion;
074:
075:            private FrameworkStatisticsData data;
076:
077:            private Map<String /* instanceName */, FrameworkStatisticsData> dataMap;
078:
079:            /**
080:             * Constructor - creates a new instance of
081:             * FrameworkStatisticsDataReader
082:             */
083:            public FrameworkStatisticsDataReader() {
084:            }
085:
086:            /**
087:             * @return the dataMap
088:             */
089:            public Map<String /* instanceName */, FrameworkStatisticsData> getFrameworkStatisticsDataMap() {
090:                return this .dataMap;
091:            }
092:
093:            /**
094:             * Start of document processing.
095:             * 
096:             * @throws org.xml.sax.SAXException
097:             *             is any SAX exception, possibly wrapping another exception.
098:             */
099:            public void startDocument() throws SAXException {
100:                parsingInProgress = true;
101:                qNameStack.removeAllElements();
102:            }
103:
104:            /**
105:             * End of document processing.
106:             * 
107:             * @throws org.xml.sax.SAXException
108:             *             is any SAX exception, possibly wrapping another exception.
109:             */
110:            public void endDocument() throws SAXException {
111:                parsingInProgress = false;
112:                // We have encountered the end of the document. Do any processing that
113:                // is desired, for example dump all collected element2 values.
114:
115:            }
116:
117:            /**
118:             * Process the new element.
119:             * 
120:             * @param uri
121:             *            is the Namespace URI, or the empty string if the element has
122:             *            no Namespace URI or if Namespace processing is not being
123:             *            performed.
124:             * @param localName
125:             *            is the The local name (without prefix), or the empty string if
126:             *            Namespace processing is not being performed.
127:             * @param qName
128:             *            is the qualified name (with prefix), or the empty string if
129:             *            qualified names are not available.
130:             * @param attributes
131:             *            is the attributes attached to the element. If there are no
132:             *            attributes, it shall be an empty Attributes object.
133:             * @throws org.xml.sax.SAXException
134:             *             is any SAX exception, possibly wrapping another exception.
135:             */
136:            public void startElement(String uri, String localName,
137:                    String qName, Attributes attributes) throws SAXException {
138:                if (qName != null) {
139:                    if (qName.endsWith(FRAMEWORK_STATISTICS_DATA_LIST_KEY)) {
140:                        // ELEMENT1 has an attribute, get it by name
141:                        // Do something with the attribute
142:                        if ((attributes != null)
143:                                && (attributes.getLength() > 0)) {
144:                            String namespace = attributes
145:                                    .getValue(NAMESPACE_KEY);
146:                            // //////////////////////////////////////////////////////
147:                            // Read performanceDataListVersion attribute and ensure you
148:                            // store the right
149:                            // performanceDataListVersion of the report map list
150:                            // //////////////////////////////////////////////////////
151:                            this .frameworkStatisticsDataListVersion = attributes
152:                                    .getValue(VERSION_KEY);
153:                            if ((frameworkStatisticsDataListVersion != null)
154:                                    && (VERSION_VALUE
155:                                            .equals(frameworkStatisticsDataListVersion))) {
156:                                this .dataMap = new HashMap<String /* instanceName */, FrameworkStatisticsData>();
157:                            } else {
158:                                // Invalid frameworkStatisticsDataListVersion.
159:                                // Not storing it
160:                            }
161:                        }
162:                    } else if (qName.endsWith(FRAMEWORK_STATISTICS_DATA_KEY)) {
163:                        // ELEMENT1 has an attribute, get it by name
164:                        // Do something with the attribute
165:                        if (this .dataMap != null) {
166:                            this .data = new FrameworkStatisticsData();
167:                        }
168:                    }
169:                    // Keep track of QNames
170:                    qNameStack.push(qName);
171:                }
172:            }
173:
174:            /**
175:             * Process the character report for current tag.
176:             * 
177:             * @param ch
178:             *            are the element's characters.
179:             * @param start
180:             *            is the start position in the character array.
181:             * @param length
182:             *            is the number of characters to use from the character array.
183:             * @throws org.xml.sax.SAXException
184:             *             is any SAX exception, possibly wrapping another exception.
185:             */
186:            public void characters(char[] ch, int start, int length)
187:                    throws SAXException {
188:                String qName;
189:                String chars = new String(ch, start, length);
190:                // Get current QName
191:                qName = (String) qNameStack.peek();
192:                if (qName.endsWith(INSTANCE_NAME_KEY)) {
193:                    if (this .data != null) {
194:                        this .data.setInstanceName(chars);
195:                    }
196:                } else if (qName.endsWith(STARTUP_TIME_KEY)) {
197:                    if (this .data != null) {
198:                        long startupTime = Long.valueOf(chars).longValue();
199:                        this .data.setStartupTime(startupTime);
200:                    }
201:                } else if (qName.endsWith(UP_TIME_KEY)) {
202:                    if (this .data != null) {
203:                        long upTime = Long.valueOf(chars).longValue();
204:                        this .data.setUpTime(upTime);
205:                    }
206:                }
207:            }
208:
209:            /**
210:             * Process the end element tag.
211:             * 
212:             * @param uri
213:             *            is the Namespace URI, or the empty string if the element has
214:             *            no Namespace URI or if Namespace processing is not being
215:             *            performed.
216:             * @param localName
217:             *            is the The local name (without prefix), or the empty string if
218:             *            Namespace processing is not being performed.
219:             * @param qName
220:             *            is the qualified name (with prefix), or the empty string if
221:             *            qualified names are not available.
222:             * @throws org.xml.sax.SAXException
223:             *             is any SAX exception, possibly wrapping another exception.
224:             */
225:            public void endElement(String uri, String localName, String qName)
226:                    throws SAXException {
227:                // Pop QName, since we are done with it
228:                qNameStack.pop();
229:                if (qName != null) {
230:                    if (qName.endsWith(FRAMEWORK_STATISTICS_DATA_KEY)) {
231:                        // We have encountered the end of ELEMENT1
232:                        // ...
233:                        if ((this .dataMap != null) && (this .data != null)) {
234:                            this .dataMap.put(this .data.getInstanceName(),
235:                                    this .data);
236:                            this .data = null;
237:                        }
238:                    }
239:                }
240:            }
241:
242:            /**
243:             * 
244:             * @param rawXMLData
245:             * @return
246:             * @throws MalformedURLException
247:             * @throws ParserConfigurationException
248:             * @throws SAXException
249:             * @throws URISyntaxException
250:             * @throws IOException
251:             */
252:            public static Map<String /* instanceName */, FrameworkStatisticsData> parseFromXMLData(
253:                    String rawXMLData) throws MalformedURLException,
254:                    ParserConfigurationException, SAXException,
255:                    URISyntaxException, IOException {
256:                // System.out.println("Parsing file: "+uriString);
257:                // Get an instance of the SAX parser factory
258:                SAXParserFactory factory = SAXParserFactory.newInstance();
259:
260:                // Get an instance of the SAX parser
261:                SAXParser saxParser = factory.newSAXParser();
262:
263:                // Initialize the XML Document InputStream
264:                Reader reader = new StringReader(rawXMLData);
265:
266:                // Create an InputSource from the InputStream
267:                InputSource inputSource = new InputSource(reader);
268:
269:                // Parse the aspectInput XML document stream, using my event handler
270:                FrameworkStatisticsDataReader parser = new FrameworkStatisticsDataReader();
271:                saxParser.parse(inputSource, parser);
272:
273:                return parser.getFrameworkStatisticsDataMap();
274:
275:            }
276:
277:            /**
278:             * 
279:             * @param fileName
280:             * @return
281:             * @throws MalformedURLException
282:             * @throws ParserConfigurationException
283:             * @throws SAXException
284:             * @throws URISyntaxException
285:             * @throws IOException
286:             */
287:            public static Map<String /* instanceName */, FrameworkStatisticsData> parseFromFile(
288:                    String fileName) throws MalformedURLException,
289:                    ParserConfigurationException, SAXException,
290:                    URISyntaxException, IOException {
291:                File file = new File(fileName);
292:                return parseFromFile(file);
293:            }
294:
295:            /**
296:             * 
297:             * @param fileName
298:             * @return
299:             * @throws MalformedURLException
300:             * @throws ParserConfigurationException
301:             * @throws SAXException
302:             * @throws URISyntaxException
303:             * @throws IOException
304:             */
305:            public static Map<String /* instanceName */, FrameworkStatisticsData> parseFromFile(
306:                    File file) throws MalformedURLException,
307:                    ParserConfigurationException, SAXException,
308:                    URISyntaxException, IOException {
309:
310:                // Get an instance of the SAX parser factory
311:                SAXParserFactory factory = SAXParserFactory.newInstance();
312:
313:                // Get an instance of the SAX parser
314:                SAXParser saxParser = factory.newSAXParser();
315:
316:                // Initialize the URI and XML Document InputStream
317:                InputStream inputStream = new FileInputStream(file);
318:
319:                // Create an InputSource from the InputStream
320:                InputSource inputSource = new InputSource(inputStream);
321:
322:                // Parse the aspectInput XML document stream, using my event handler
323:                FrameworkStatisticsDataReader parser = new FrameworkStatisticsDataReader();
324:                saxParser.parse(inputSource, parser);
325:
326:                return parser.getFrameworkStatisticsDataMap();
327:            }
328:
329:            /**
330:             * 
331:             * @param uriString
332:             * @return
333:             * @throws MalformedURLException
334:             * @throws ParserConfigurationException
335:             * @throws SAXException
336:             * @throws URISyntaxException
337:             * @throws IOException
338:             */
339:            public static Map<String /* instanceName */, FrameworkStatisticsData> parseFromURI(
340:                    String uriString) throws MalformedURLException,
341:                    ParserConfigurationException, SAXException,
342:                    URISyntaxException, IOException {
343:                URI uri = new URI(uriString);
344:                return parseFromURI(uri);
345:            }
346:
347:            /**
348:             * 
349:             * @param uri
350:             * @return
351:             * @throws MalformedURLException
352:             * @throws ParserConfigurationException
353:             * @throws SAXException
354:             * @throws URISyntaxException
355:             * @throws IOException
356:             */
357:            public static Map<String /* instanceName */, FrameworkStatisticsData> parseFromURI(
358:                    URI uri) throws MalformedURLException,
359:                    ParserConfigurationException, SAXException,
360:                    URISyntaxException, IOException {
361:
362:                // Get an instance of the SAX parser factory
363:                SAXParserFactory factory = SAXParserFactory.newInstance();
364:
365:                // Get an instance of the SAX parser
366:                SAXParser saxParser = factory.newSAXParser();
367:
368:                // Initialize the URI and XML Document InputStream
369:                InputStream inputStream = uri.toURL().openStream();
370:
371:                // Create an InputSource from the InputStream
372:                InputSource inputSource = new InputSource(inputStream);
373:
374:                // Parse the aspectInput XML document stream, using my event handler
375:                FrameworkStatisticsDataReader parser = new FrameworkStatisticsDataReader();
376:                saxParser.parse(inputSource, parser);
377:
378:                return parser.getFrameworkStatisticsDataMap();
379:            }
380:
381:            /**
382:             * @param args
383:             */
384:            public static void main(String[] args) {
385:                String uri = "C:/test/schema/frameworkstatistics/FrameworkStatisticsData.xml";
386:                try {
387:                    Map<String /* instanceName */, FrameworkStatisticsData> map = null;
388:                    map = FrameworkStatisticsDataReader.parseFromFile(uri);
389:                    for (String instanceName : map.keySet()) {
390:                        System.out.println(map.get(instanceName)
391:                                .getDisplayString());
392:                    }
393:                } catch (MalformedURLException e) {
394:                    e.printStackTrace();
395:                } catch (ParserConfigurationException e) {
396:                    e.printStackTrace();
397:                } catch (SAXException e) {
398:                    e.printStackTrace();
399:                } catch (URISyntaxException e) {
400:                    e.printStackTrace();
401:                } catch (IOException e) {
402:                    e.printStackTrace();
403:                }
404:            }
405:
406:        }
w_w__w_.j___a___v__a__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.