Source Code Cross Referenced for FlatXmlDataSet.java in  » Testing » DbUnit » org » dbunit » dataset » 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 » Testing » DbUnit » org.dbunit.dataset.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * The DbUnit Database Testing Framework
004:         * Copyright (C)2002-2004, DbUnit.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         */
021:
022:        package org.dbunit.dataset.xml;
023:
024:        import org.slf4j.Logger;
025:        import org.slf4j.LoggerFactory;
026:
027:        import org.dbunit.dataset.CachedDataSet;
028:        import org.dbunit.dataset.DataSetException;
029:        import org.dbunit.dataset.IDataSet;
030:
031:        import org.xml.sax.InputSource;
032:
033:        import java.io.File;
034:        import java.io.IOException;
035:        import java.io.InputStream;
036:        import java.io.OutputStream;
037:        import java.io.Reader;
038:        import java.io.Writer;
039:        import java.net.URL;
040:
041:        /**
042:         * Reads and writes flat XML dataset document. Each XML element corresponds to a table row.
043:         *       Each XML element name corresponds to a table name. The XML attributes
044:         *       correspond to table columns.
045:         * <p>
046:         * Flat XML dataset document sample:
047:         * <p>
048:         * <pre>
049:         * &lt;!DOCTYPE dataset SYSTEM "my-dataset.dtd"&gt;
050:         * &lt;dataset&gt;
051:         *     &lt;TEST_TABLE COL0="row 0 col 0"
052:         *         COL1="row 0 col 1"
053:         *         COL2="row 0 col 2"/&gt;
054:         *     &lt;TEST_TABLE COL1="row 1 col 1"/&gt;
055:         *     &lt;SECOND_TABLE COL0="row 0 col 0"
056:         *           COL1="row 0 col 1" /&gt;
057:         *     &lt;EMPTY_TABLE/&gt;
058:         * &lt;/dataset&gt;</pre>
059:         * <p>
060:         * To specify null values, omit corresponding attribute.
061:         * In the above example, missing COL0 and COL2 attributes of TEST_TABLE second row represents null values.
062:         * <p>
063:         * Table metadata is deduced from the first row of each table. <b>Beware that DbUnit may think
064:         * a table miss some columns if the first row of that table has one or more null values.</b>
065:         * Because of that, this is highly recommended to use DTD. DbUnit will use the
066:         * columns declared in the DTD as table metadata. DbUnit only support external system URI.
067:         * The URI can be absolute or relative.
068:         *
069:         * @author Manuel Laflamme
070:         * @version $Revision: 554 $
071:         * @since Mar 12, 2002
072:         */
073:        public class FlatXmlDataSet extends CachedDataSet {
074:
075:            /**
076:             * Logger for this class
077:             */
078:            private static final Logger logger = LoggerFactory
079:                    .getLogger(FlatXmlDataSet.class);
080:
081:            /**
082:             * Creates an FlatXmlDataSet object with the specifed InputSource.
083:             */
084:            public FlatXmlDataSet(InputSource source) throws IOException,
085:                    DataSetException {
086:                super (new FlatXmlProducer(source));
087:            }
088:
089:            /**
090:             * Creates an FlatXmlDataSet object with the specifed xml file.
091:             * Relative DOCTYPE uri are resolved from the xml file path.
092:             *
093:             * @param xmlFile the xml file
094:             */
095:            public FlatXmlDataSet(File xmlFile) throws IOException,
096:                    DataSetException {
097:                this (xmlFile, true);
098:            }
099:
100:            /**
101:             * Creates an FlatXmlDataSet object with the specifed xml file.
102:             * Relative DOCTYPE uri are resolved from the xml file path.
103:             *
104:             * @param xmlFile the xml file
105:             * @param dtdMetadata if <code>false</code> do not use DTD as metadata
106:             */
107:            public FlatXmlDataSet(File xmlFile, boolean dtdMetadata)
108:                    throws IOException, DataSetException {
109:                this (xmlFile.toURL(), dtdMetadata);
110:            }
111:
112:            /**
113:             * Creates an FlatXmlDataSet object with the specifed xml URL.
114:             * Relative DOCTYPE uri are resolved from the xml file path.
115:             *
116:             * @param xmlUrl the xml URL
117:             */
118:            public FlatXmlDataSet(URL xmlUrl) throws IOException,
119:                    DataSetException {
120:                this (xmlUrl, true);
121:            }
122:
123:            /**
124:             * Creates an FlatXmlDataSet object with the specifed xml URL.
125:             * Relative DOCTYPE uri are resolved from the xml file path.
126:             *
127:             * @param xmlUrl the xml URL
128:             * @param dtdMetadata if <code>false</code> do not use DTD as metadata
129:             */
130:            public FlatXmlDataSet(URL xmlUrl, boolean dtdMetadata)
131:                    throws IOException, DataSetException {
132:                super (new FlatXmlProducer(new InputSource(xmlUrl.toString()),
133:                        dtdMetadata));
134:            }
135:
136:            /**
137:             * Creates an FlatXmlDataSet object with the specifed xml reader.
138:             * Relative DOCTYPE uri are resolved from the current working dicrectory.
139:             *
140:             * @param xmlReader the xml reader
141:             */
142:            public FlatXmlDataSet(Reader xmlReader) throws IOException,
143:                    DataSetException {
144:                this (xmlReader, true);
145:            }
146:
147:            /**
148:             * Creates an FlatXmlDataSet object with the specifed xml reader.
149:             * Relative DOCTYPE uri are resolved from the current working dicrectory.
150:             *
151:             * @param xmlReader the xml reader
152:             * @param dtdMetadata if <code>false</code> do not use DTD as metadata
153:             */
154:            public FlatXmlDataSet(Reader xmlReader, boolean dtdMetadata)
155:                    throws IOException, DataSetException {
156:                super (new FlatXmlProducer(new InputSource(xmlReader),
157:                        dtdMetadata));
158:            }
159:
160:            /**
161:             * Creates an FlatXmlDataSet object with the specifed xml and dtd readers.
162:             *
163:             * @param xmlReader the xml reader
164:             * @param dtdReader the dtd reader
165:             */
166:            public FlatXmlDataSet(Reader xmlReader, Reader dtdReader)
167:                    throws IOException, DataSetException {
168:                this (xmlReader, new FlatDtdDataSet(dtdReader));
169:            }
170:
171:            /**
172:             * Creates an FlatXmlDataSet object with the specifed xml reader.
173:             *
174:             * @param xmlReader the xml reader
175:             * @param metaDataSet the dataset used as metadata source.
176:             */
177:            public FlatXmlDataSet(Reader xmlReader, IDataSet metaDataSet)
178:                    throws IOException, DataSetException {
179:                super (new FlatXmlProducer(new InputSource(xmlReader),
180:                        metaDataSet));
181:            }
182:
183:            /**
184:             * Creates an FlatXmlDataSet object with the specifed xml input stream.
185:             * Relative DOCTYPE uri are resolved from the current working dicrectory.
186:             *
187:             * @param xmlStream the xml input stream
188:             */
189:            public FlatXmlDataSet(InputStream xmlStream) throws IOException,
190:                    DataSetException {
191:                this (xmlStream, true);
192:            }
193:
194:            /**
195:             * Creates an FlatXmlDataSet object with the specifed xml input stream.
196:             * Relative DOCTYPE uri are resolved from the current working dicrectory.
197:             *
198:             * @param xmlStream the xml input stream
199:             * @param dtdMetadata if <code>false</code> do not use DTD as metadata
200:             */
201:            public FlatXmlDataSet(InputStream xmlStream, boolean dtdMetadata)
202:                    throws IOException, DataSetException {
203:                super (new FlatXmlProducer(new InputSource(xmlStream),
204:                        dtdMetadata));
205:            }
206:
207:            /**
208:             * Creates an FlatXmlDataSet object with the specifed xml and dtd input
209:             * stream.
210:             *
211:             * @param xmlStream the xml input stream
212:             * @param dtdStream the dtd input stream
213:             */
214:            public FlatXmlDataSet(InputStream xmlStream, InputStream dtdStream)
215:                    throws IOException, DataSetException {
216:                this (xmlStream, new FlatDtdDataSet(dtdStream));
217:            }
218:
219:            /**
220:             * Creates an FlatXmlDataSet object with the specifed xml input stream.
221:             *
222:             * @param xmlStream the xml input stream
223:             * @param metaDataSet the dataset used as metadata source.
224:             */
225:            public FlatXmlDataSet(InputStream xmlStream, IDataSet metaDataSet)
226:                    throws IOException, DataSetException {
227:                super (new FlatXmlProducer(new InputSource(xmlStream),
228:                        metaDataSet));
229:            }
230:
231:            /**
232:             * Write the specified dataset to the specified output stream as xml.
233:             */
234:            public static void write(IDataSet dataSet, OutputStream out)
235:                    throws IOException, DataSetException {
236:                logger.debug("write(dataSet=" + dataSet + ", out=" + out
237:                        + ") - start");
238:
239:                FlatXmlWriter datasetWriter = new FlatXmlWriter(out);
240:                datasetWriter.setIncludeEmptyTable(true);
241:                datasetWriter.write(dataSet);
242:            }
243:
244:            /**
245:             * Write the specified dataset to the specified writer as xml.
246:             */
247:            public static void write(IDataSet dataSet, Writer writer)
248:                    throws IOException, DataSetException {
249:                logger.debug("write(dataSet=" + dataSet + ", writer=" + writer
250:                        + ") - start");
251:
252:                write(dataSet, writer, null);
253:            }
254:
255:            /**
256:             * Write the specified dataset to the specified writer as xml.
257:             */
258:            public static void write(IDataSet dataSet, Writer writer,
259:                    String encoding) throws IOException, DataSetException {
260:                logger.debug("write(dataSet=" + dataSet + ", writer=" + writer
261:                        + ", encoding=" + encoding + ") - start");
262:
263:                FlatXmlWriter datasetWriter = new FlatXmlWriter(writer,
264:                        encoding);
265:                datasetWriter.setIncludeEmptyTable(true);
266:                datasetWriter.write(dataSet);
267:            }
268:
269:            /**
270:             * Write a DTD for the specified dataset to the specified output.
271:             * @deprecated use {@link FlatDtdDataSet#write}
272:             */
273:            public static void writeDtd(IDataSet dataSet, OutputStream out)
274:                    throws IOException, DataSetException {
275:                logger.debug("writeDtd(dataSet=" + dataSet + ", out=" + out
276:                        + ") - start");
277:
278:                FlatDtdDataSet.write(dataSet, out);
279:            }
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.