Source Code Cross Referenced for XMLTestSuiteLoader.java in  » Graphic-Library » batik » org » apache » batik » test » xml » 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 » Graphic Library » batik » org.apache.batik.test.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Licensed to the Apache Software Foundation (ASF) under one or more
004:           contributor license agreements.  See the NOTICE file distributed with
005:           this work for additional information regarding copyright ownership.
006:           The ASF licenses this file to You under the Apache License, Version 2.0
007:           (the "License"); you may not use this file except in compliance with
008:           the License.  You may obtain a copy of the License at
009:
010:               http://www.apache.org/licenses/LICENSE-2.0
011:
012:           Unless required by applicable law or agreed to in writing, software
013:           distributed under the License is distributed on an "AS IS" BASIS,
014:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:           See the License for the specific language governing permissions and
016:           limitations under the License.
017:
018:         */
019:        package org.apache.batik.test.xml;
020:
021:        import java.io.StringWriter;
022:        import java.io.PrintWriter;
023:
024:        import javax.xml.parsers.DocumentBuilderFactory;
025:        import javax.xml.parsers.DocumentBuilder;
026:
027:        import org.apache.batik.test.DefaultTestSuite;
028:        import org.apache.batik.test.TestSuite;
029:        import org.apache.batik.test.Test;
030:        import org.apache.batik.test.TestException;
031:
032:        import org.w3c.dom.Element;
033:        import org.w3c.dom.Document;
034:        import org.w3c.dom.Node;
035:        import org.w3c.dom.NodeList;
036:
037:        /**
038:         * This class loads an XML document describing a test suite
039:         * into a <tt>TestSuite</tt> object.
040:         *
041:         * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
042:         * @version $Id: XMLTestSuiteLoader.java 475477 2006-11-15 22:44:28Z cam $
043:         */
044:        public class XMLTestSuiteLoader implements  XTSConstants {
045:
046:            /**
047:             * An error happened while loading a test suite document.
048:             * {0} : the &lt;testSuite&gt; href value.
049:             * {1} : the exception's class name
050:             * {2} : exception's message
051:             * {3} : exception's stack trace
052:             */
053:            public static final String TEST_SUITE_LOADING_EXCEPTION = "xml.XMLTestSuiteLoader.error.test.suite.loading.exception";
054:
055:            /**
056:             * An error happened while processing a <tt>Test</tt>
057:             * description.
058:             * {0} : the <test> "className" attribute value
059:             * {1} : exception's class name
060:             * {2} : exception's message
061:             * {3} : exception's stack trace
062:             */
063:            public static final String CANNOT_CREATE_TEST = "xml.XMLTestSuiteLoader.error.cannot.create.test";
064:
065:            /**
066:             * Load the test suite defined by the input URI
067:             */
068:            public static TestSuite loadTestSuite(String testSuiteURI,
069:                    TestSuite parent) throws TestException {
070:                // System.out.println("loading test suite: " + testSuiteURI);
071:                Document testSuiteDocument = loadTestSuiteDocument(testSuiteURI);
072:                return buildTestSuite(testSuiteDocument.getDocumentElement(),
073:                        parent);
074:            }
075:
076:            /**
077:             * Loads the URI as a <tt>Document</tt>
078:             */
079:            protected static Document loadTestSuiteDocument(String testSuiteURI)
080:                    throws TestException {
081:
082:                Document doc = null;
083:
084:                try {
085:                    DocumentBuilder docBuilder = DocumentBuilderFactory
086:                            .newInstance().newDocumentBuilder();
087:
088:                    doc = docBuilder.parse(testSuiteURI);
089:                } catch (Exception e) {
090:                    StringWriter sw = new StringWriter();
091:                    PrintWriter pw = new PrintWriter(sw);
092:                    e.printStackTrace(pw);
093:                    throw new TestException(TEST_SUITE_LOADING_EXCEPTION,
094:                            new Object[] { testSuiteURI,
095:                                    e.getClass().getName(), e.getMessage(),
096:                                    sw.toString() }, e);
097:
098:                }
099:
100:                return doc;
101:            }
102:
103:            /**
104:             * Builds a <tt>TestSuite</tt> from an input element.
105:             * This method assumes that element is a &lt;testSuite&gt;
106:             * instance, as the input document should have been
107:             * validated when loaded.
108:             */
109:            protected static TestSuite buildTestSuite(Element element,
110:                    TestSuite parent) throws TestException {
111:                DefaultTestSuite testSuite = new DefaultTestSuite();
112:
113:                /* FIXX: Not used -- should we call testSuite.setName(suiteName)??? */
114:                // String suiteName 
115:                //     = element.getAttribute(XTS_NAME_ATTRIBUTE);
116:                String suiteId = element.getAttribute(XTS_ID_ATTRIBUTE);
117:
118:                testSuite.setId(suiteId);
119:
120:                NodeList children = element.getChildNodes();
121:                if (children != null && children.getLength() > 0) {
122:                    int n = children.getLength();
123:                    for (int i = 0; i < n; i++) {
124:                        Node child = children.item(i);
125:                        if (child.getNodeType() == Node.ELEMENT_NODE) {
126:                            Element childElement = (Element) child;
127:                            String tagName = childElement.getTagName().intern();
128:                            // System.out.println("Processing child : " + tagName);
129:                            if (tagName == XTS_TEST_TAG) {
130:                                Test t = buildTest(childElement);
131:                                testSuite.addTest(t);
132:                            } else if (tagName == XTS_TEST_GROUP_TAG) {
133:                                Test t = buildTestSuite(childElement, testSuite);
134:                                testSuite.addTest(t);
135:                            }
136:                        }
137:                    }
138:                }
139:
140:                return testSuite;
141:            }
142:
143:            protected static Test buildTest(Element element)
144:                    throws TestException {
145:                try {
146:                    Test t = (Test) XMLReflect.buildObject(element);
147:
148:                    String id = element.getAttribute(XTS_ID_ATTRIBUTE);
149:                    t.setId(id);
150:                    return t;
151:                } catch (Exception e) {
152:                    StringWriter sw = new StringWriter();
153:                    PrintWriter pw = new PrintWriter(sw);
154:                    e.printStackTrace(pw);
155:                    throw new TestException(CANNOT_CREATE_TEST, new Object[] {
156:                            element.getAttribute(XR_CLASS_ATTRIBUTE),
157:                            e.getClass().getName(), e.getMessage(),
158:                            sw.toString() }, e);
159:                }
160:            }
161:
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.