Source Code Cross Referenced for XMLDefaultMutableTreeNode.java in  » Testing » jakarta-jmeter » org » apache » jmeter » visualizers » 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 » Testing » jakarta jmeter » org.apache.jmeter.visualizers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.visualizers;
020:
021:        import javax.swing.tree.DefaultMutableTreeNode;
022:
023:        import org.apache.jorphan.logging.LoggingManager;
024:        import org.apache.log.Logger;
025:        import org.w3c.dom.Attr;
026:        import org.w3c.dom.CDATASection;
027:        import org.w3c.dom.Comment;
028:        import org.w3c.dom.NamedNodeMap;
029:        import org.w3c.dom.Node;
030:        import org.w3c.dom.NodeList;
031:        import org.w3c.dom.Text;
032:        import org.xml.sax.SAXException;
033:
034:        /**
035:         * A extended class of DefaultMutableTreeNode except that it also attached XML
036:         * node and convert XML document into DefaultMutableTreeNode.
037:         * 
038:         */
039:        public class XMLDefaultMutableTreeNode extends DefaultMutableTreeNode {
040:            private static final Logger log = LoggingManager
041:                    .getLoggerForClass();
042:            // private static final int LIMIT_STR_SIZE = 100;
043:            // private boolean isRoot;
044:            private transient Node xmlNode;
045:
046:            public XMLDefaultMutableTreeNode() {
047:                log.warn("Constructor only intended for use in testing"); // $NON-NLS-1$
048:            }
049:
050:            public XMLDefaultMutableTreeNode(Node root) throws SAXException {
051:                super (root.getNodeName());
052:                initAttributeNode(root, this );
053:                initRoot(root);
054:
055:            }
056:
057:            public XMLDefaultMutableTreeNode(String name, Node xmlNode) {
058:                super (name);
059:                this .xmlNode = xmlNode;
060:
061:            }
062:
063:            /**
064:             * init root
065:             * 
066:             * @param root
067:             * @throws SAXException
068:             */
069:            private void initRoot(Node xmlRoot) throws SAXException {
070:
071:                NodeList childNodes = xmlRoot.getChildNodes();
072:                for (int i = 0; i < childNodes.getLength(); i++) {
073:                    Node childNode = childNodes.item(i);
074:                    initNode(childNode, this );
075:                }
076:
077:            }
078:
079:            /**
080:             * init node
081:             * 
082:             * @param node
083:             * @param mTreeNode
084:             * @throws SAXException
085:             */
086:            private void initNode(Node node, XMLDefaultMutableTreeNode mTreeNode)
087:                    throws SAXException {
088:
089:                switch (node.getNodeType()) {
090:                case Node.ELEMENT_NODE:
091:                    initElementNode(node, mTreeNode);
092:                    break;
093:
094:                case Node.TEXT_NODE:
095:                    initTextNode((Text) node, mTreeNode);
096:                    break;
097:
098:                case Node.CDATA_SECTION_NODE:
099:                    initCDATASectionNode((CDATASection) node, mTreeNode);
100:                    break;
101:                case Node.COMMENT_NODE:
102:                    initCommentNode((Comment) node, mTreeNode);
103:                    break;
104:
105:                default:
106:                    // if other node type, we will just skip it
107:                    break;
108:
109:                }
110:
111:            }
112:
113:            /**
114:             * init element node
115:             * 
116:             * @param node
117:             * @param mTreeNode
118:             * @throws SAXException
119:             */
120:            private void initElementNode(Node node,
121:                    DefaultMutableTreeNode mTreeNode) throws SAXException {
122:                String nodeName = node.getNodeName();
123:
124:                NodeList childNodes = node.getChildNodes();
125:                XMLDefaultMutableTreeNode childTreeNode = new XMLDefaultMutableTreeNode(
126:                        nodeName, node);
127:
128:                mTreeNode.add(childTreeNode);
129:                initAttributeNode(node, childTreeNode);
130:                for (int i = 0; i < childNodes.getLength(); i++) {
131:                    Node childNode = childNodes.item(i);
132:                    initNode(childNode, childTreeNode);
133:                }
134:
135:            }
136:
137:            /**
138:             * init attribute node
139:             * 
140:             * @param node
141:             * @param mTreeNode
142:             * @throws SAXException
143:             */
144:            private void initAttributeNode(Node node,
145:                    DefaultMutableTreeNode mTreeNode) throws SAXException {
146:                NamedNodeMap nm = node.getAttributes();
147:                for (int i = 0; i < nm.getLength(); i++) {
148:                    Attr nmNode = (Attr) nm.item(i);
149:                    String value = nmNode.getName() + " = \""
150:                            + nmNode.getValue() + "\""; // $NON-NLS-1$ $NON-NLS-2$
151:                    XMLDefaultMutableTreeNode attributeNode = new XMLDefaultMutableTreeNode(
152:                            value, nmNode);
153:                    mTreeNode.add(attributeNode);
154:
155:                }
156:            }
157:
158:            /**
159:             * init comment Node
160:             * 
161:             * @param node
162:             * @param mTreeNode
163:             * @throws SAXException
164:             */
165:            private void initCommentNode(Comment node,
166:                    DefaultMutableTreeNode mTreeNode) throws SAXException {
167:                String data = node.getData();
168:                if (data != null && data.length() > 0) {
169:                    String value = "<!--" + node.getData() + "-->"; // $NON-NLS-1$ $NON-NLS-2$
170:                    XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(
171:                            value, node);
172:                    mTreeNode.add(commentNode);
173:                }
174:            }
175:
176:            /**
177:             * init CDATASection Node
178:             * 
179:             * @param node
180:             * @param mTreeNode
181:             * @throws SAXException
182:             */
183:            private void initCDATASectionNode(CDATASection node,
184:                    DefaultMutableTreeNode mTreeNode) throws SAXException {
185:                String data = node.getData();
186:                if (data != null && data.length() > 0) {
187:                    String value = "<!-[CDATA" + node.getData() + "]]>"; // $NON-NLS-1$ $NON-NLS-2$
188:                    XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(
189:                            value, node);
190:                    mTreeNode.add(commentNode);
191:                }
192:            }
193:
194:            /**
195:             * init the TextNode
196:             * 
197:             * @param node
198:             * @param mTreeNode
199:             * @throws SAXException
200:             */
201:            private void initTextNode(Text node,
202:                    DefaultMutableTreeNode mTreeNode) throws SAXException {
203:                String text = node.getNodeValue().trim();
204:                if (text != null && text.length() > 0) {
205:                    XMLDefaultMutableTreeNode textNode = new XMLDefaultMutableTreeNode(
206:                            text, node);
207:                    mTreeNode.add(textNode);
208:                }
209:            }
210:
211:            /**
212:             * get the xml node
213:             * 
214:             * @return the XML node
215:             */
216:            public Node getXMLNode() {
217:                return xmlNode;
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.