|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.ricebridge.xmlman.XmlManager
This is the main class for loading XML files.
Quick Start:
To load an XML file from disk as a List of String[] arrays:
XmlManager xmlman = new XmlManager();
List records = xmlman.load( "/path/to/file.xml",
new RecordSpec( "/xpath/to/record/element",
new String[] { "xpath/for/field-one",
"xpath/for/field-two",
"xpath/for/field-three" } ) );
for( int rI = 0; rI < records.size(); rI++ ) {
String[] record = (String[]) records.get( rI );
// do stuff with record
}
The best way to learn how to use XML Manager is to start with the
Getting Started guide, which shows you
the most important details, and has lots of example code.
Loading XML Data
The XmlManager class provides the following ways to load XML data:
List of String[] arrays - load(File,RecordSpec)List of Lists of Strings
- loadAsLists(File,RecordSpec)TableModel - loadTableModel(File,RecordSpec)ResultSet - loadResultSet(File,RecordSpec)loadBeans(File,RecordSpec,BeanSpec)RecordListenerSaving XML Data
The XmlManager class also provides the following ways to save XML data:
List of String[] arrays - save(File,RecordSpec,List)List of Lists of Strings
- saveAsLists(File,RecordSpec,List)TableModel - saveTableModel(File,RecordSpec,javax.swing.table.TableModel)ResultSet - saveResultSet(File,RecordSpec,ResultSet)saveBeans(File,RecordSpec,BeanSpec,List)RecordProviderInput
XML Data can be read from the following types of input:
File - load(File,RecordSpec)String - load(String,RecordSpec)InputStream - load(InputStream,RecordSpec)InputSource - load(InputSource,RecordSpec)loadFromURI(String,RecordSpec)loadFromString(String,RecordSpec)String parameter is normally considered to be
a file path (for example, load(String,RecordSpec). Use the loadFromString
methods to load XML content contained in String variables.
Output
XML Data can be written to the following types of output:
File - save(File,RecordSpec,List)String - save(String,RecordSpec,List)OutputStream - save(OutputStream,RecordSpec,List)saveToString(RecordSpec,List)String parameter is normally considered to be
a file path (for example, save(String,RecordSpec,List). Use the saveToString
methods to save data into a String variable as XML content.
How to Find the Method You Need
XmlManager provides many loading and saving shortcut methods, but it's still easy to find the method you need.
Just think of two things: where does the XML data come from, and what form do you want it in?
For example, if the data comes from a File and you want it as a List, use
load(File,RecordSpec). Or if it comes from an InputStream and you want it as a TableModel
then use loadTableModel(InputStream,RecordSpec).
To save XML data, apply the same questions; where does the data go and what form is it in now?
For example, if you have the data as a ResultSet and you want to save it to a File use
saveResultSet(File,RecordSpec,ResultSet).
More formally, the loading methods are organised according to the following pattern:
[type] load[type]( [source], RecordSpec )
Where [type] is one of
List of String[]AsLists: returns a List of Lists of StringsResultSet: returns ResultSetTableModel: returns javax.swing.table.TableModelBeans: returns a List of Java Bean objects[source] is one of
File String (file path)InputStream InputSource When [source] is a String containing XML data as text,
append FromString to the method name, like so: loadResultSetFromString(String,RecordSpec).
This prevents the String data from being interpreted as a file path.
When [source] is a URI indicating the location of the XML content
append FromURI to the method name, like so: loadAsListsFromURI(String,RecordSpec).
When loading Java Beans, you will also need to include a BeanSpec parameter,
see loadBeans(File,RecordSpec,BeanSpec) for an example.
The saving methods are organised according to the following pattern:
When you want to save XML data to a When saving Java Beans, you will also need to include a Using A Throughout this API documentation, we use a standard reference block of XML for most of the examples.
This block of XML looks like so: If we apply the XPath expression The This declaration creates a new XML Manager uses Prepared It is often the case that you need to apply the same Once you have prepared a You can call the load and save methods repeatedly, and the prepared Saving Data with The XPath expressions in a RecordSpec are used for both loading and saving XML data. When loading, the
XPath expressions specify the element paths to follow when extracting data. XPath predicates
( Callback Interfaces If the predefined methods of input and output are not suitable, you can implement your own
access to your XML data. The If you want to provide data to save in a XML format, you can use the Please note: to use the Options for XML format For a full description of all the available options,
refer to the Frequently used options: Background Processing It is possible to perform the loading and saving operations in a background Statistics XML Manager provides a number of statistics on the loading and saving process. To
access these statistics, call the For a quick summary of these statistics, use the Error Messages and Exception Handling Normally an When an error occurs this class throws a
This is the main class of the XML Manager API.
To use this class, all you need to do is create a new instance and call one of the
You can use the same The To specify your own default settings, use the
The Unlike this constructor, the If an
This constructor parses and stores the save[type]( [destination], [data] )
Where [type] is one of
and [data] is a List of String[], or a LineProviderAsLists: [data] is a
List of Lists of StringsResultSet: [data] is a ResultSetTableModel: [data] is a javax.swing.table.TableModelBeans: [data] is a List of Java Bean objects[destination] is one of
and File String (file path)OutputStream [data] is an object of type
List of String[] arraysList of Lists of StringsResultSetjavax.swing.table.TableModelList of Java Bean objectsString variable
append ToString to the method name, like so: saveToString(RecordSpec,List).BeanSpec parameter,
see saveBeans(File,RecordSpec,BeanSpec,List) for an example.RecordSpecsRecordSpec is a record specification class. This is an immutable class that specifies the
XPath expression for the data record, and the XPath expressions for each data field.
<?xml version='1.0' encoding='UTF-8'?>
<root>
<record name="r1">
<foo>f1</foo>
<bar>b1</bar>
</record>
<record name="r2">
<foo>f2</foo>
<bar>b2</bar>
</record>
<record name="r3">
<foo>f3</foo>
<bar>b3</bar>
</record>
</root>
/root/record to this XML, we select all the
record elements. For each of these elements, if we further apply the XPath expressions
@name and foo (with each record element as the context node),
we get the values r1 and f1 for the first
record, the values values r2 and f2 for the second record, and finally
r3 and f3 for the last record.RecordSpec class allows us to specify this set of XPath expressions, like so:
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name", "foo"} );
RecordSpec, with the first parameter, a String
specifying the record XPath expression,
and the second parameter, a String[] array, specifying the list of field XPath expressions.RecordSpecs both for reading and writing XML, and thus all
save and load methods require access to a RecordSpec object. You can either supply this
directly as a method parameter, as with the method load(File,RecordSpec), or you can use a prepared
RecordSpec, as with the method load(File)
RecordSpecsRecordSpec many times to multiple
input files. It's wasteful of computing resources to constantly reparse the XPath expressions, so
XML Manager allows you to prepare a RecordSpec for subsequent repeated use.
You can prepare a RecordSpec as follows:
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name", "foo"} );
// prepared via the XmlManager constructor
XmlManager xmlman = new XmlManager( rs );
// OR prepared via the setRecordSpec method
xmlman.setRecordSpec( rs );
RecordSpec, you can then use the load and save methods
that do not have a RecordSpec parameter, such as load(File) and save(File,List).
For all the load and save methods that take a RecordSpec parameter, there are equivalent methods that do not
require a RecordSpec. See the setRecordSpec(RecordSpec) method for more details. RecordSpec is always used.
XML Manager has been carefully designed to be thread-safe, so you can use prepared RecordSpecs
in multi-threaded applications very easily. You can call the load and save methods on the same XmlManager
instance in more than one thread, and everything will still work just fine.RecordSpecsrecord[@name='r1']) can also be used. When saving, the XPath expressions define the
exact format of the output XML. Predicates are ignored and so is the // syntax. What you get
is direct translation of the XPath element steps into XML elements. Thus /root/record will create
a root element containing record elements. RecordListener interface can be used via the
load(*,RecordSpec,RecordListener) methods to get direct access to the XML
data as it is loaded. Using an implementation of this interface means that you can load XML data and
place it in any data structure that you require.RecordProvider interface to provide the
data by calling the save(*,RecordSpec,RecordProvider) methods.RecordListener interface, you should extend the support class
RecordListenerSupport, as this will provide you with future-compatibility and error-handling support.
The RecordProviderSupport support class is also provided for this purpose.XmlSpec class. The options used by XmlManager are stored in
a XmlSpec object and you can access
the current XmlSpec with getXmlSpec().XmlSpec.setEncoding(java.lang.String)XmlSpec.setNamespaceAware(boolean)XmlSpec.setIndent(boolean)Thread.
To do this, set XmlSpec.setBackground(boolean) to true. This creates a daemon Thread (which
halts automatically if the main Thread halts) where the loading or saving operation is performed.
You can call the isLoadFinished() and isSaveFinished() methods to monitor the process.getStats() method to get the current Stats object.
This object provides the following information:Stats.getTotalRecords() - final record count (current if running in background)Stats.getTotalBadRecords() - final bad record count (current if running in background)Stats.getAverageTimePerRecordInSeconds() - as double valueStats.getTimeTaken() - as long valueStats.getTimeTakenInSeconds() - as double valueStats.getStartDate() - as Date objectStats.getEndDate() - as Date objectStats.getSummary() method.XmlManagerException is thrown as soon as an error occurs, and processing halts.
If you set XmlSpec.setIgnoreBadRecords(boolean) to true then errors are collected and processing continues until
all data records are processed. This allows you to load as much valid data as possible.
Note that an XML syntax error always causes processing to halt, as per the
XML Specification.
You can get the collected error messages (as BadRecord objects) from the getBadRecords() method.XmlManagerException
which is a subclass of RuntimeException
Since RuntimeExceptions need not be declared, none of the methods in this class
declare that that they throw any Exceptions.
You can choose to catch these XmlManagerExceptions directly or let them pass up to other
exception handling within your code. Each XmlManagerException contains an explanation of the
error and a set of error values which give more information about the cause of the error.
Calling XmlManagerException.toString() or XmlManagerException.getUserMessage() on a XmlManagerException
will return a user-friendly description of the problem.
Calling XmlManagerException.getMessage() will return
a technical description of the problem, suitable for debugging purposes.
See XmlManagerException for a more detailed
description of how to work with XmlManagerExceptions.
RecordSpec,
XmlSpec,
Stats,
XmlManagerException
Constructor Summary
XmlManager()
Create a new instance of XmlManager, with default settings.
XmlManager(RecordSpec pRecordSpec)
Create a new instance of XmlManager using the specified RecordSpec data record specification.
XmlManager(XmlSpec pXmlSpec)
Create a new instance of XmlManager using the specified XmlSpec XML format specification.
XmlManager(XmlSpec pXmlSpec,
RecordSpec pRecordSpec)
Create a new instance of XmlManager using the specified XmlSpec XML format
and RecordSpec data record specification.
Method Summary
voidfinishSave()
Special method to complete final XML elements of streamed documents.
ListgetBadRecords()
Get a list of descriptions of any semantically incorrect data records encountered.
StatsgetStats()
Get statistics on the number of records processed and processing time.
XmlManagerStoregetXmlManagerStore()
XmlManagerStore is a utility class for creating
RecordListener and RecordProvider instances.
XmlSpecgetXmlSpec()
Get the current XmlSpec, which specifies the settings for the interpretation and generation of XML.
booleanisLoadFinished()
Returns true when the loading process is finished.
booleanisSaveFinished()
Returns true when the saving process is finished.
Listload(File pXmlFile)
Load XML data from a file as a List of String[] arrays, using the default RecordSpec.
voidload(File pXmlFile,
RecordListener pRecordListener)
Load XML data from a file as a stream using your own RecordListener, using the default RecordSpec.
Listload(File pXmlFile,
RecordSpec pRecordSpec)
Load XML data from a file as a List of String[] arrays.
voidload(File pXmlFile,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
Load XML data from a file as a stream using your own RecordListener.
Listload(InputSource pInputSource)
Load XML data from an InputSource as a List of String[] arrays,
using the default RecordSpec.
voidload(InputSource pInputSource,
RecordListener pRecordListener)
Load XML data from an InputSource as a stream using your own RecordListener,
using the default RecordSpec.
Listload(InputSource pInputSource,
RecordSpec pRecordSpec)
Load XML data from an InputSource as a List of String[] arrays.
voidload(InputSource pInputSource,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
Load XML data from an InputSource as a stream using your own RecordListener.
Listload(InputStream pInputStream)
Load XML data from an InputStream as a List of String[] arrays,
using the default RecordSpec.
voidload(InputStream pInputStream,
RecordListener pRecordListener)
Load XML data from an InputStream as a stream using your own RecordListener,
using the default RecordSpec.
Listload(InputStream pInputStream,
RecordSpec pRecordSpec)
Load XML data from an InputStream as a List of String[] arrays.
voidload(InputStream pInputStream,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
Load XML data from an InputStream as a stream using your own RecordListener.
Listload(String pXmlFilePath)
Load XML data from a specified file path as a List of String[] arrays, using the default RecordSpec.
voidload(String pXmlFilePath,
RecordListener pRecordListener)
Load XML data from a specified file path as a stream using your own RecordListener, using the default RecordSpec.
Listload(String pXmlFilePath,
RecordSpec pRecordSpec)
Load XML data from a specified file path as a List of String[] arrays.
voidload(String pXmlFilePath,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
Load XML data from a specified file path as a stream using your own RecordListener.
ListloadAsLists(File pXmlFile)
Load XML data from a file as a List of Lists of Strings,
using the default RecordSpec.
ListloadAsLists(File pXmlFile,
RecordSpec pRecordSpec)
Load XML data from a file as a List of Lists of Strings.
ListloadAsLists(InputSource pInputSource)
Load XML data from an InputSource as a List of Lists of Strings,
using the default RecordSpec.
ListloadAsLists(InputSource pInputSource,
RecordSpec pRecordSpec)
Load XML data from an InputSource as a List of Lists of Strings.
ListloadAsLists(InputStream pInputStream)
Load XML data from an InputStream as a List of Lists of Strings,
using the default RecordSpec.
ListloadAsLists(InputStream pInputStream,
RecordSpec pRecordSpec)
Load XML data from an InputStream as a List of Lists of Strings.
ListloadAsLists(String pXmlFilePath)
Load XML data from a specified file path as a List of Lists of Strings,
using the default RecordSpec.
ListloadAsLists(String pXmlFilePath,
RecordSpec pRecordSpec)
Load XML data from a specified file path as a List of Lists of Strings.
ListloadAsListsFromString(String pXmlString)
Load XML data from a String variable as a List of Lists of Strings,
using the default RecordSpec.
ListloadAsListsFromString(String pXmlString,
RecordSpec pRecordSpec)
Load XML data from a String variable as a List of Lists of Strings.
ListloadAsListsFromURI(String pURI)
Load XML data specified by a Uniform Resource Identifier (URI) as a List of Lists of Strings,
using the default RecordSpec.
ListloadAsListsFromURI(String pURI,
RecordSpec pRecordSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a List of Lists of Strings.
ListloadBeans(File pXmlFile,
BeanSpec pBeanSpec)
Load XML data from a file as a List
of Java Beans, using the default RecordSpec.
ListloadBeans(File pXmlFile,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
Load XML data from a file as a List of Java Beans.
ListloadBeans(InputSource pInputSource,
BeanSpec pBeanSpec)
Load XML data from an InputSource as a List
of Java Beans, using the default RecordSpec.
ListloadBeans(InputSource pInputSource,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
Load XML data from an InputSource as a
List of Java Beans.
ListloadBeans(InputStream pInputStream,
BeanSpec pBeanSpec)
Load XML data from an InputStream as a List
of Java Beans, using the default RecordSpec.
ListloadBeans(InputStream pInputStream,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
Load XML data from an InputStream as a
List of Java Beans.
ListloadBeans(String pXmlFilePath,
BeanSpec pBeanSpec)
Load XML data from a specified file path as a List
of Java Beans, using the default RecordSpec.
ListloadBeans(String pXmlFilePath,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
Load XML data from a specified file path as a List of Java Beans.
ListloadBeansFromString(String pXmlString,
BeanSpec pBeanSpec)
Load XML data from a String variable as a List
of Java Beans, using the default RecordSpec.
ListloadBeansFromString(String pXmlString,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
Load XML data from a String variable as a
List of Java Beans.
ListloadBeansFromURI(String pURI,
BeanSpec pBeanSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a List
of Java Beans, using the default RecordSpec.
ListloadBeansFromURI(String pURI,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a
List of Java Beans.
ListloadFromString(String pXmlString)
Load XML data from a String variable as a List of String[] arrays,
using the default RecordSpec.
voidloadFromString(String pXmlString,
RecordListener pRecordListener)
Load XML data from a String variable as a stream using your own RecordListener,
using the default RecordSpec.
ListloadFromString(String pXmlString,
RecordSpec pRecordSpec)
Load XML data from a String variable as a List of String[] arrays.
voidloadFromString(String pXmlString,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
Load XML data from a String variable as a stream using your own RecordListener.
ListloadFromURI(String pURI)
Load XML data specified by a Uniform Resource Identifier (URI) as a List of String[] arrays,
using the default RecordSpec.
voidloadFromURI(String pURI,
RecordListener pRecordListener)
Load XML data specified by a Uniform Resource Identifier (URI) as a stream using your own RecordListener,
using the default RecordSpec.
ListloadFromURI(String pURI,
RecordSpec pRecordSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a List of String[] arrays.
voidloadFromURI(String pURI,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
Load XML data specified by a Uniform Resource Identifier (URI) as a stream using your own RecordListener.
ResultSetloadResultSet(File pXmlFile)
Load XML data from a file as a ResultSet,
using the default RecordSpec.
ResultSetloadResultSet(File pXmlFile,
RecordSpec pRecordSpec)
Load XML data from a file as a ResultSet.
ResultSetloadResultSet(InputSource pInputSource)
Load XML data from an InputSource as a ResultSet,
using the default RecordSpec.
ResultSetloadResultSet(InputSource pInputSource,
RecordSpec pRecordSpec)
Load XML data from an InputSource as a ResultSet.
ResultSetloadResultSet(InputStream pInputStream)
Load XML data from an InputStream as a ResultSet,
using the default RecordSpec.
ResultSetloadResultSet(InputStream pInputStream,
RecordSpec pRecordSpec)
Load XML data from an InputStream as a ResultSet.
ResultSetloadResultSet(String pXmlFilePath)
Load XML data from a specified file path as a ResultSet,
using the default RecordSpec.
ResultSetloadResultSet(String pXmlFilePath,
RecordSpec pRecordSpec)
Load XML data from a specified file path as a ResultSet.
ResultSetloadResultSetFromString(String pXmlString)
Load XML data from a String variable as a ResultSet,
using the default RecordSpec.
ResultSetloadResultSetFromString(String pXmlString,
RecordSpec pRecordSpec)
Load XML data from a String variable as a ResultSet.
ResultSetloadResultSetFromURI(String pURI)
Load XML data specified by a Uniform Resource Identifier (URI) as a ResultSet,
using the default RecordSpec.
ResultSetloadResultSetFromURI(String pURI,
RecordSpec pRecordSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a ResultSet.
TableModelloadTableModel(File pXmlFile)
Load XML data from a file as a TableModel,
using the default RecordSpec.
TableModelloadTableModel(File pXmlFile,
RecordSpec pRecordSpec)
Load XML data from a file as a TableModel.
TableModelloadTableModel(InputSource pInputSource)
Load XML data from an InputSource as a TableModel,
using the default RecordSpec.
TableModelloadTableModel(InputSource pInputSource,
RecordSpec pRecordSpec)
Load XML data from an InputSource as a TableModel.
TableModelloadTableModel(InputStream pInputStream)
Load XML data from an InputStream as a TableModel,
using the default RecordSpec.
TableModelloadTableModel(InputStream pInputStream,
RecordSpec pRecordSpec)
Load XML data from an InputStream as a TableModel.
TableModelloadTableModel(String pXmlFilePath)
Load XML data from a specified file path as a TableModel,
using the default RecordSpec.
TableModelloadTableModel(String pXmlFilePath,
RecordSpec pRecordSpec)
Load XML data from a specified file path as a TableModel.
TableModelloadTableModelFromString(String pXmlString)
Load XML data from a String variable as a TableModel,
using the default RecordSpec.
TableModelloadTableModelFromString(String pXmlString,
RecordSpec pRecordSpec)
Load XML data from a String variable as a TableModel.
TableModelloadTableModelFromURI(String pURI)
Load XML data specified by a Uniform Resource Identifier (URI) as a TableModel,
using the default RecordSpec.
TableModelloadTableModelFromURI(String pURI,
RecordSpec pRecordSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a TableModel.
RecordSpecnullcheck(RecordSpec pRecordSpec)
Check that RecordSpec is not null.
voidsave(File pXmlFile,
List pData)
Save XML data to a file from a List of String[] arrays,
using the default RecordSpec.
voidsave(File pXmlFile,
RecordProvider pRecordProvider)
Save XML data to a file using your own RecordProvider,
using the default RecordSpec.
voidsave(File pXmlFile,
RecordSpec pRecordSpec,
List pData)
Save XML data to a file from a List of String[] arrays.
voidsave(File pXmlFile,
RecordSpec pRecordSpec,
RecordProvider pRecordProvider)
Save XML data to a file using your own RecordProvider.
voidsave(OutputStream pOutputStream,
List pData)
Save XML data to an OutputStream from a List of String[] arrays,
using the default RecordSpec.
voidsave(OutputStream pOutputStream,
RecordProvider pRecordProvider)
Save XML data to an OutputStream using your own RecordProvider,
using the default RecordSpec.
voidsave(OutputStream pOutputStream,
RecordSpec pRecordSpec,
List pData)
Save XML data to an OutputStream from a List of String[] arrays.
voidsave(OutputStream pOutputStream,
RecordSpec pRecordSpec,
RecordProvider pRecordProvider)
Save XML data to an OutputStream using your own RecordProvider.
voidsave(String pXmlFilePath,
List pData)
Save XML data to a specified file path from a List of String[] arrays,
using the default RecordSpec.
voidsave(String pXmlFilePath,
RecordProvider pRecordProvider)
Save XML data to a specified file path using your own RecordProvider,
using the default RecordSpec.
voidsave(String pXmlFilePath,
RecordSpec pRecordSpec,
List pData)
Save XML data to a specified file path from a List of String[] arrays.
voidsave(String pXmlFilePath,
RecordSpec pRecordSpec,
RecordProvider pRecordProvider)
Save XML data to a specified file path using your own RecordProvider.
voidsaveAsLists(File pXmlFile,
List pData)
Save XML data to a file from a List of Lists of Strings,
using the default RecordSpec.
voidsaveAsLists(File pXmlFile,
RecordSpec pRecordSpec,
List pData)
Save XML data to a file from a List of Lists of Strings.
voidsaveAsLists(OutputStream pOutputStream,
List pData)
Save XML data to an OutputStream from a List of Lists of Strings
using the default RecordSpec.
voidsaveAsLists(OutputStream pOutputStream,
RecordSpec pRecordSpec,
List pData)
Save XML data to an OutputStream from a List of Lists of Strings.
voidsaveAsLists(String pXmlFilePath,
List pData)
Save XML data to a specified file path from a List of Lists of Strings,
using the default RecordSpec.
voidsaveAsLists(String pXmlFilePath,
RecordSpec pRecordSpec,
List pData)
Save XML data to a specified file path from a List of Lists of Strings.
StringsaveAsListsToString(List pData)
Save XML data to a String variable from a List of Lists of Strings
using the default RecordSpec.
StringsaveAsListsToString(RecordSpec pRecordSpec,
List pData)
Save XML data to a String variable from a List of Lists of Strings.
voidsaveBeans(File pXmlFile,
BeanSpec pBeanSpec,
List pBeans)
Save Java Beans as XML data to a file,
using the default RecordSpec.
voidsaveBeans(File pXmlFile,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec,
List pBeans)
Save Java Beans as XML data to a file.
voidsaveBeans(OutputStream pOutputStream,
BeanSpec pBeanSpec,
List pBeans)
Save Java Beans as XML data to an OutputStream,
using the default RecordSpec.
voidsaveBeans(OutputStream pOutputStream,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec,
List pBeans)
Save Java Beans as XML data to a file.
voidsaveBeans(String pXmlFilePath,
BeanSpec pBeanSpec,
List pBeans)
Save Java Beans as XML data to a specified file path,
using the default RecordSpec.
voidsaveBeans(String pXmlFilePath,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec,
List pBeans)
Save Java Beans as XML data to a specified file path.
StringsaveBeansToString(BeanSpec pBeanSpec,
List pBeans)
Save Java Beans as XML data to a String variable,
using the default RecordSpec.
StringsaveBeansToString(RecordSpec pRecordSpec,
BeanSpec pBeanSpec,
List pBeans)
Save Java Beans as XML data to a file.
voidsaveResultSet(File pXmlFile,
RecordSpec pRecordSpec,
ResultSet pResultSet)
Save XML data to a file from a ResultSet.
voidsaveResultSet(File pXmlFile,
ResultSet pResultSet)
Save XML data to a file from a ResultSet,
using the default RecordSpec.
voidsaveResultSet(OutputStream pOutputStream,
RecordSpec pRecordSpec,
ResultSet pResultSet)
Save XML data to an OutputStream from a ResultSet.
voidsaveResultSet(OutputStream pOutputStream,
ResultSet pResultSet)
Save XML data to an OutputStream from a ResultSet,
using the default RecordSpec.
voidsaveResultSet(String pXmlFilePath,
RecordSpec pRecordSpec,
ResultSet pResultSet)
Save XML data to a specified file path from a ResultSet.
voidsaveResultSet(String pXmlFilePath,
ResultSet pResultSet)
Save XML data to a specified file path from a ResultSet,
using the default RecordSpec.
StringsaveResultSetToString(RecordSpec pRecordSpec,
ResultSet pResultSet)
Save XML data to a String variable from a ResultSet.
StringsaveResultSetToString(ResultSet pResultSet)
Save XML data to a String variable from a ResultSet,
using the default RecordSpec.
voidsaveTableModel(File pXmlFile,
RecordSpec pRecordSpec,
TableModel pTableModel)
Save XML data to a file from a TableModel.
voidsaveTableModel(File pXmlFile,
TableModel pTableModel)
Save XML data to a file from a TableModel,
using the default RecordSpec.
voidsaveTableModel(OutputStream pOutputStream,
RecordSpec pRecordSpec,
TableModel pTableModel)
Save XML data to an OutputStream from a TableModel.
voidsaveTableModel(OutputStream pOutputStream,
TableModel pTableModel)
Save XML data to an OutputStream from a TableModel.
voidsaveTableModel(String pXmlFilePath,
RecordSpec pRecordSpec,
TableModel pTableModel)
Save XML data to a specified file path from a TableModel.
voidsaveTableModel(String pXmlFilePath,
TableModel pTableModel)
Save XML data to a specified file path from a TableModel.
StringsaveTableModelToString(RecordSpec pRecordSpec,
TableModel pTableModel)
Save XML data to a String variable from a TableModel.
StringsaveTableModelToString(TableModel pTableModel)
Save XML data to a String variable from a TableModel.
StringsaveToString(List pData)
Save XML data to a String variable from a List of String[] arrays,
using the default RecordSpec.
StringsaveToString(RecordProvider pRecordProvider)
Save XML data to a String variable using your own RecordProvider,
using the default RecordSpec.
StringsaveToString(RecordSpec pRecordSpec,
List pData)
Save XML data to a String variable from a List of String[] arrays.
StringsaveToString(RecordSpec pRecordSpec,
RecordProvider pRecordProvider)
Save XML data to a String variable using your own RecordProvider.
voidsetBadRecordListener(BadRecordListener pBadRecordListener)
Set a BadRecordListener object to receive notification of semantically incorrect records
as they are encountered.
voidsetRecordSpec(RecordSpec pRecordSpec)
Set the default RecordSpec for this XmlManager instance.
voidsetXmlSpec(XmlSpec pXmlSpec)
XmlManager uses XmlSpec to control the interpretation and generation of XML.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
XmlManager
public XmlManager()
XmlManager, with default settings.
load or save
methods with a RecordSpec defining your data records.XmlManager instance more than once by
calling the setRecordSpec(RecordSpec) method first, and then calling one the
load or save methods with no
RecordSpec parameter.XmlManager class is designed to be thread safe, so you
can use the same XmlManager instance in more than one thread.XmlManager(XmlSpec) constructor.
To specify a default RecordSpec use the XmlManager(RecordSpec) constructor.XmlManager(XmlSpec),
XmlManager(XmlSpec,RecordSpec),
XmlManager(RecordSpec)
XmlManager
public XmlManager(XmlSpec pXmlSpec)
XmlManager using the specified XmlSpec XML format specification.
XmlSpec specified here is used to create a local XmlSpec copy for
each thread that uses this XmlManager instance. This allows you to set a default XmlSpec
for each new thread. If the XmlSpec specified in this constructor is changed, then all subsequent new copies will
reflect those changes, but existing copies will not.setXmlSpec(XmlSpec) method only sets the XmlSpec for the current thread.
This means that you can alter the XmlSpec in a fully thread-safe manner without disrupting other threads
using this XmlManager instanceXmlSpec is not specified in a constructor, then a new default XmlSpec is created as needed.XmlManager(),
XmlManager(XmlSpec,RecordSpec),
XmlSpec
XmlManager
public XmlManager(RecordSpec pRecordSpec)
XmlManager using the specified RecordSpec data record specification.
RecordSpec XPath expressions ahead of time. This gives a
performance boost when loading data with the same XML format multiple times. Normally you would use it
in the following manner:
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name","foo","bar"} );
XmlManager xmlman = new XmlManager( rs );
while( theresAnotherFile() ) {
List data = xmlman.load( getNextFile() );
// do something with data
}
Note that the load(File) method is used rather than the load(File,RecordSpec) method.
Methods that take a RecordSpec parameter use the RecordSpec they are given and
not the default RecordSpec specified in this constructor.
You can also call the setRecordSpec(RecordSpec) method to achieve the same purpose as using this constructor.
The XmlManager class is designed to be thread safe, so you
can use the same XmlManager instance with the same RecordSpec object in more than one thread.
No copies are created of the RecordSpec object as it is immutable (unlike XmlSpec).
XmlManager,
RecordSpec,
XmlManager(XmlSpec,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public XmlManager(XmlSpec pXmlSpec,
RecordSpec pRecordSpec)
XmlManager using the specified XmlSpec XML format
and RecordSpec data record specification.
See the documentation for the XmlManager(XmlSpec) and XmlManager(RecordSpec)
constructors for more details.
XmlManager(com.ricebridge.xmlman.XmlSpec, com.ricebridge.xmlman.RecordSpec),
XmlManager(XmlSpec),
XmlManager(RecordSpec)| Method Detail |
public void setRecordSpec(RecordSpec pRecordSpec)
RecordSpec for this XmlManager instance.
This method parses and stores the XPath expressions in the RecordSpec
so that higher performance can be achieved when reading data with the same XML format many times.
See the documentation for the XmlManager(RecordSpec) constructor for more details.
Methods that take a RecordSpec parameter use the RecordSpec they are given and
not the default RecordSpec specified in this method.
You can call this method as many times as you like, but note that other threads using
the same XmlManager instance will use the new RecordSpec specified here, rather than
keeping their old RecordSpec.
To use different RecordSpecs in different threads, either create new
XmlManager instances, or use the load and save methods that take a RecordSpec parameter.
XmlManager(RecordSpec),
RecordSpecpublic List load(File pXmlFile)
List of String[] arrays, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(File,RecordSpec), which has the same functionality.
List of String[] arraysload(File,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List load(String pXmlFilePath)
List of String[] arrays, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(String,RecordSpec), which has the same functionality.
List of String[] arraysload(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List load(InputStream pInputStream)
InputStream as a List of String[] arrays,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(InputStream,RecordSpec), which has the same functionality.
List of String[] arraysload(InputStream,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List load(InputSource pInputSource)
InputSource as a List of String[] arrays,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(InputSource,RecordSpec), which has the same functionality.
List of String[] arraysload(InputSource,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List loadFromURI(String pURI)
List of String[] arrays,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadFromURI(String,RecordSpec), which has the same functionality.
List of String[] arraysloadFromURI(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List loadFromString(String pXmlString)
String variable as a List of String[] arrays,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadFromString(String,RecordSpec), which has the same functionality.
List of String[] arraysloadFromString(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public List load(File pXmlFile,
RecordSpec pRecordSpec)
List of String[] arrays.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name","foo","bar"} );
List data = xmlManager.load( xmlFile, rs );
StringBuffer sb = new StringBuffer();
for( int record = 0; record < data.size(); record++ ) {
sb.append( "record: "+record+"\n" );
String[] fields = (String[]) data.get(record);
for( int field = 0; field < fields.length; field++ ) {
sb.append( "field "+field+" has value: "+fields[field]+"\n" );
}
}
System.out.println( sb.toString() );
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
pXmlFile - XML file to loadpRecordSpec - XML Record Specification
List of String[] arraysload(String,RecordSpec),
load(InputStream,RecordSpec),
load(InputSource,RecordSpec),
loadFromURI(String,RecordSpec),
loadFromString(String,RecordSpec)
public List load(String pXmlFilePath,
RecordSpec pRecordSpec)
List of String[] arrays.
This method allows you to specify the path to the XML file using a String instead of
creating a File object.
For a code example, see load(File,RecordSpec).
List of String[] arraysload(File,RecordSpec)
public List load(InputStream pInputStream,
RecordSpec pRecordSpec)
InputStream as a List of String[] arrays.
This method allows you to use an InputStream instead of a file as the source of your XML data.
For a code example, see load(File,RecordSpec).
List of String[] arraysload(File,RecordSpec)
public List load(InputSource pInputSource,
RecordSpec pRecordSpec)
InputSource as a List of String[] arrays.
This method allows you to use an InputSource instead of a file as the source of your XML data.
For a code example, see load(File,RecordSpec).
List of String[] arraysload(File,RecordSpec)
public List loadFromURI(String pURI,
RecordSpec pRecordSpec)
List of String[] arrays.
This method allows you to use XML data available over a network or remote file system
by providing a URI specifying the location of the data. See
http://www.w3.org/Addressing for more information about URIs.
For a code example, see load(File,RecordSpec).
List of String[] arraysload(File,RecordSpec)
public List loadFromString(String pXmlString,
RecordSpec pRecordSpec)
String variable as a List of String[] arrays.
This method allows you to use XML data from an internal String variable
instead of loading it from an external file.
For a code example, see load(File,RecordSpec).
List of String[] arraysload(File,RecordSpec)public List loadAsLists(File pXmlFile)
List of Lists of Strings,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadAsLists(File,RecordSpec), which has the same functionality.
List of Lists of StringsloadAsLists(File,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List loadAsLists(String pXmlFilePath)
List of Lists of Strings,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadAsLists(String,RecordSpec), which has the same functionality.
List of Lists of StringsloadAsLists(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List loadAsLists(InputStream pInputStream)
InputStream as a List of Lists of Strings,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadAsLists(InputStream,RecordSpec), which has the same functionality.
List of Lists of StringsloadAsLists(InputStream,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List loadAsLists(InputSource pInputSource)
InputSource as a List of Lists of Strings,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadAsLists(InputSource,RecordSpec), which has the same functionality.
List of Lists of StringsloadAsLists(InputSource,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List loadAsListsFromURI(String pURI)
List of Lists of Strings,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadAsListsFromURI(String,RecordSpec), which has the same functionality.
List of Lists of StringsloadAsListsFromURI(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public List loadAsListsFromString(String pXmlString)
String variable as a List of Lists of Strings,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadAsListsFromString(String,RecordSpec), which has the same functionality.
List of Lists of StringsloadAsListsFromString(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public List loadAsLists(File pXmlFile,
RecordSpec pRecordSpec)
List of Lists of Strings.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name","foo","bar"} );
List data = xmlManager.loadAsLists( xmlFile, rs );
StringBuffer sb = new StringBuffer();
for( int record = 0; record < data.size(); record++ ) {
sb.append( "record: "+record+"\n" );
List fields = (List) data.get(record);
for( int field = 0; field < fields.size(); field++ ) {
sb.append( "field "+field+" has value: "+fields.get(field)+"\n" );
}
}
System.out.println( sb.toString() );
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
pXmlFile - XML file to loadpRecordSpec - XML Record Specification
List of Lists of StringsloadAsLists(String,RecordSpec),
loadAsLists(InputStream,RecordSpec),
loadAsLists(InputSource,RecordSpec),
loadAsListsFromURI(String,RecordSpec),
loadAsListsFromString(String,RecordSpec)
public List loadAsLists(String pXmlFilePath,
RecordSpec pRecordSpec)
List of Lists of Strings.
This method allows you to specify the path to the XML file using a String instead of
creating a File object.
For a code example, see loadAsLists(File,RecordSpec).
List of Lists of StringsloadAsLists(File,RecordSpec)
public List loadAsLists(InputStream pInputStream,
RecordSpec pRecordSpec)
InputStream as a List of Lists of Strings.
This method allows you to use an InputStream instead of a file as the source of your XML data.
For a code example, see loadAsLists(File,RecordSpec).
List of Lists of StringsloadAsLists(File,RecordSpec)
public List loadAsLists(InputSource pInputSource,
RecordSpec pRecordSpec)
InputSource as a List of Lists of Strings.
This method allows you to use an InputSource instead of a file as the source of your XML data.
For a code example, see loadAsLists(File,RecordSpec).
List of Lists of StringsloadAsLists(File,RecordSpec)
public List loadAsListsFromURI(String pURI,
RecordSpec pRecordSpec)
List of Lists of Strings.
This method allows you to use XML data available over a network or remote file system
by providing a URI specifying the location of the data. See
http://www.w3.org/Addressing for more information about URIs.
For a code example, see loadAsLists(File,RecordSpec).
List of Lists of StringsloadAsLists(File,RecordSpec)
public List loadAsListsFromString(String pXmlString,
RecordSpec pRecordSpec)
String variable as a List of Lists of Strings.
This method allows you to use XML data from an internal String variable
instead of loading it from an external file.
For a code example, see loadAsLists(File,RecordSpec).
List of Lists of StringsloadAsLists(File,RecordSpec)public TableModel loadTableModel(File pXmlFile)
TableModel,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadTableModel(File,RecordSpec), which has the same functionality.
TableModelloadTableModel(File,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public TableModel loadTableModel(String pXmlFilePath)
TableModel,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadTableModel(String,RecordSpec), which has the same functionality.
TableModelloadTableModel(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public TableModel loadTableModel(InputStream pInputStream)
InputStream as a TableModel,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadTableModel(InputStream,RecordSpec), which has the same functionality.
TableModelloadTableModel(InputStream,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public TableModel loadTableModel(InputSource pInputSource)
InputSource as a TableModel,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadTableModel(InputSource,RecordSpec), which has the same functionality.
TableModelloadTableModel(InputSource,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public TableModel loadTableModelFromURI(String pURI)
TableModel,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadTableModelFromURI(String,RecordSpec), which has the same functionality.
TableModelloadTableModelFromURI(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public TableModel loadTableModelFromString(String pXmlString)
String variable as a TableModel,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadTableModelFromString(String,RecordSpec), which has the same functionality.
TableModelloadTableModelFromString(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public TableModel loadTableModel(File pXmlFile,
RecordSpec pRecordSpec)
TableModel.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
RecordSpec rs = new RecordSpec( "/root/record",
new String[] {"@name","foo","bar"},
new String[] {"Name","Foo","Bar"} );
TableModel tm = xmlManager.loadTableModel( xmlFile, rs );
JTable table = new JTable();
table.setModel( tm );
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
This method allows you to directly display your data in a Swing application.
You can specify the column headers using the third String[] argument to the
RecordSpec constructor.
Alternatively, if the first record of your XML data defines column headers,
set the TableModel.dataHasHeaders setting to true, like so:
XmlSpec xs = xmlManager.getXmlSpec();
xs.setProperty("TableModel.dataHasHeaders",true);
The first record of your XML data will then become the column headers of your table, and the data displayed in the table starts
with the second record of the XML file.
You can also use the TableModel.editable setting to make the JTable cells editable.
pXmlFile - XML file to loadpRecordSpec - XML Record Specification
TableModelloadTableModel(String,RecordSpec),
loadTableModel(InputStream,RecordSpec),
loadTableModel(InputSource,RecordSpec),
loadTableModelFromURI(String,RecordSpec),
loadTableModelFromString(String,RecordSpec)
public TableModel loadTableModel(String pXmlFilePath,
RecordSpec pRecordSpec)
TableModel.
This method allows you to specify the path to the XML file using a String instead of
creating a File object. For a code example,
see loadTableModel(File,RecordSpec)
pXmlFilePath - path of XML file to loadpRecordSpec - XML Record Specification
TableModelloadTableModel(File,RecordSpec)
public TableModel loadTableModel(InputStream pInputStream,
RecordSpec pRecordSpec)
InputStream as a TableModel.
This method allows you to use an InputStream instead of a file as the source of your XML data.
For a code example, see loadTableModel(File,RecordSpec)
pInputStream - InputStream providing XML datapRecordSpec - XML Record Specification
TableModelloadTableModel(File,RecordSpec)
public TableModel loadTableModel(InputSource pInputSource,
RecordSpec pRecordSpec)
InputSource as a TableModel.
This method allows you to use an InputSource instead of a file as the source of your XML data.
For a code example, see loadTableModel(File,RecordSpec)
pInputSource - InputSource providing XML datapRecordSpec - XML Record Specification
TableModelloadTableModel(File,RecordSpec)
public TableModel loadTableModelFromURI(String pURI,
RecordSpec pRecordSpec)
TableModel.
This method allows you to use XML data available over a network or remote file system
by providing a URI specifying the location of the data. See
http://www.w3.org/Addressing for more information about URIs.
For a code example, see loadTableModel(File,RecordSpec)
pURI - Uniform Resource Identifier stringpRecordSpec - XML Record Specification
TableModelloadTableModel(File,RecordSpec)
public TableModel loadTableModelFromString(String pXmlString,
RecordSpec pRecordSpec)
String variable as a TableModel.
This method allows you to use XML data from an internal String variable
instead of loading it from an external file.
For a code example, see loadTableModel(File,RecordSpec)
pXmlString - String containing XML datapRecordSpec - XML Record Specification
TableModelloadTableModel(File,RecordSpec)public ResultSet loadResultSet(File pXmlFile)
ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadResultSet(File,RecordSpec), which has the same functionality.
ResultSetloadResultSet(File,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public ResultSet loadResultSet(String pXmlFilePath)
ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadResultSet(String,RecordSpec), which has the same functionality.
ResultSetloadResultSet(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public ResultSet loadResultSet(InputStream pInputStream)
InputStream as a ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadResultSet(InputStream,RecordSpec), which has the same functionality.
ResultSetloadResultSet(InputStream,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public ResultSet loadResultSet(InputSource pInputSource)
InputSource as a ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadResultSet(InputSource,RecordSpec), which has the same functionality.
ResultSetloadResultSet(InputSource,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public ResultSet loadResultSetFromURI(String pURI)
ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadResultSetFromURI(String,RecordSpec), which has the same functionality.
ResultSetloadResultSetFromURI(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public ResultSet loadResultSetFromString(String pXmlString)
String variable as a ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadResultSetFromString(String,RecordSpec), which has the same functionality.
ResultSetloadResultSetFromString(String,RecordSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public ResultSet loadResultSet(File pXmlFile,
RecordSpec pRecordSpec)
ResultSet.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
RecordSpec rs = new RecordSpec( "/root/record",
new String[] {"@name","foo","bar"},
new String[] {"Name","Foo","Bar"} );
ResultSet resultset = xmlManager.loadResultSet( xmlFile, rs );
ResultSetMetaData rsmd = resultset.getMetaData();
int numCols = rsmd.getColumnCount();
StringBuffer sb = new StringBuffer();
for( int col = 1; col <= numCols; col++ ) {
sb.append( rsmd.getColumnName(col) + (col<numCols?", ":"\n") );
}
while( resultset.next() ) {
for( int col = 1; col <= numCols; col++ ) {
sb.append( resultset.getString(col) + (col<numCols?", ":"\n") );
}
}
System.out.println( sb.toString() );
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
This method allows you to access your data as if it came from a database.
You can specify the column headers using the third String[] argument to the
RecordSpec constructor.
Alternatively, if the first record of your XML data defines column headers,
set the ResultSet.dataHasHeaders property to true, like so:
XmlSpec xs = xmlManager.getXmlSpec();
xs.setProperty("ResultSet.dataHasHeaders",true);
The first record of your XML data will then become the column headers in your ResultSet,
and the data returned by the ResultSet starts with the second record of the XML file.
pXmlFile - XML file to loadpRecordSpec - XML Record Specification
ResultSetloadResultSet(String,RecordSpec),
loadResultSet(InputStream,RecordSpec),
loadResultSet(InputSource,RecordSpec),
loadResultSetFromString(String,RecordSpec),
loadResultSetFromURI(String,RecordSpec)
public ResultSet loadResultSet(String pXmlFilePath,
RecordSpec pRecordSpec)
ResultSet.
This method allows you to specify the path to the XML file using a String instead of
creating a File object. For a code example,
see loadResultSet(File,RecordSpec)
pXmlFilePath - path of XML file to loadpRecordSpec - XML Record Specification
ResultSetloadResultSet(File,RecordSpec)
public ResultSet loadResultSet(InputStream pInputStream,
RecordSpec pRecordSpec)
InputStream as a ResultSet.
This method allows you to use an InputStream instead of a file as the source of your XML data.
For a code example, see loadResultSet(File,RecordSpec)
pInputStream - InputStream providing XML datapRecordSpec - XML Record Specification
ResultSetloadResultSet(File,RecordSpec)
public ResultSet loadResultSet(InputSource pInputSource,
RecordSpec pRecordSpec)
InputSource as a ResultSet.
This method allows you to use an InputSource instead of a file as the source of your XML data.
For a code example, see loadResultSet(File,RecordSpec)
pInputSource - InputSource providing XML datapRecordSpec - XML Record Specification
ResultSetloadResultSet(File,RecordSpec)
public ResultSet loadResultSetFromURI(String pURI,
RecordSpec pRecordSpec)
ResultSet.
This method allows you to use XML data available over a network or remote file system
by providing a URI specifying the location of the data. See
http://www.w3.org/Addressing for more information about URIs.
For a code example, see loadResultSet(File,RecordSpec)
pURI - Uniform Resource Identifier stringpRecordSpec - XML Record Specification
ResultSetloadResultSet(File,RecordSpec)
public ResultSet loadResultSetFromString(String pXmlString,
RecordSpec pRecordSpec)
String variable as a ResultSet.
This method allows you to use XML data from an internal String variable
instead of loading it from an external file.
For a code example, see loadResultSet(File,RecordSpec)
pXmlString - String containing XML datapRecordSpec - XML Record Specification
ResultSetloadResultSet(File,RecordSpec)
public List loadBeans(File pXmlFile,
BeanSpec pBeanSpec)
List
of Java Beans, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadBeans(File,RecordSpec,BeanSpec), which has the same functionality.
pXmlFile - XML file to loadpBeanSpec - Java Bean specification
List of Java BeansloadBeans(File,RecordSpec,BeanSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public List loadBeans(String pXmlFilePath,
BeanSpec pBeanSpec)
List
of Java Beans, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadBeans(String,RecordSpec,BeanSpec), which has the same functionality.
pXmlFilePath - path of XML file to loadpBeanSpec - Java Bean specification
List of Java BeansloadBeans(String,RecordSpec,BeanSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public List loadBeans(InputStream pInputStream,
BeanSpec pBeanSpec)
InputStream as a List
of Java Beans, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadBeans(InputStream,RecordSpec,BeanSpec), which has the same functionality.
pInputStream - InputStream providing XML datapBeanSpec - Java Bean specification
List of Java BeansloadBeans(InputStream,RecordSpec,BeanSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public List loadBeans(InputSource pInputSource,
BeanSpec pBeanSpec)
InputSource as a List
of Java Beans, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadBeans(InputSource,RecordSpec,BeanSpec), which has the same functionality.
pInputSource - InputSource providing XML datapBeanSpec - Java Bean specification
List of Java BeansloadBeans(InputSource,RecordSpec,BeanSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public List loadBeansFromURI(String pURI,
BeanSpec pBeanSpec)
List
of Java Beans, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadBeansFromURI(String,RecordSpec,BeanSpec), which has the same functionality.
pURI - Uniform Resource Identifier stringpBeanSpec - Java Bean specification
List of Java BeansloadBeansFromURI(String,RecordSpec,BeanSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public List loadBeansFromString(String pXmlString,
BeanSpec pBeanSpec)
String variable as a List
of Java Beans, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see loadBeansFromString(String,RecordSpec,BeanSpec), which has the same functionality.
pXmlString - String containing XML datapBeanSpec - Java Bean specification
List of Java BeansloadBeansFromString(String,RecordSpec,BeanSpec),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public List loadBeans(File pXmlFile,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
List of Java Beans.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File( "mydata.xml" );
XmlManager xmlManager = new XmlManager();
RecordSpec rs = new RecordSpec( "/root/record",
new String[] {"@name","foo","bar"},
new String[] {"Name","Foo","Bar"} );
BeanSpec bs = new BeanSpec( BeanRecord.class );
List beans = xmlManager.loadBeans( xmlFile, rs, bs );
System.out.println( beans.toString() );
// You'll also need this class definition
public static class BeanRecord {
private String iName, iFoo, iBar;
public BeanRecord( String pName, String pFoo, String pBar ) {
iName = pName; iFoo = pFoo; iBar = pBar;
}
public void setName( String pName ) { iName = pName; }
public String getName() { return iName; }
public void setFoo( String pFoo ) { iFoo = pFoo; }
public String getFoo() { return iFoo; }
public void setBar( String pBar ) { iBar = pBar; }
public String getBar() { return iBar; }
public String toString() {
return iName+":"+iFoo+":"+iBar;
}
}
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
This method allows you to access your data as a set of Java Bean objects.
You must specify the property method names using the third String[] argument to the
RecordSpec constructor. The property method names are the root names of the property methods, that is, with the
get/set/is prefix removed.
For more details on specifying the bean properties, see BeanSpec.
You can control the response to invalid data by using the Bean.useDefault property.
When true, invalid data is replaced with the default value for that data type. When false, an
Exception is thrown. Set this property like so:
XmlSpec xs = xmlManager.getXmlSpec();
xs.setProperty("Bean.useDefault",true);
Limitations
Java Beans support in XML Manager is intended only for bean properties. Object graphs are not saved, and
thus event listeners and so on are not saved. XML Manager does support normal get/set properties, boolean properties
and indexed properties. For standard Java types, such as int and double and so on,
XML Manager performs automatic conversion between the textual representation of the data type, and the internal Java variable.
For more complex objects, you can define your own conversions,
using a StringConverter.
pXmlFile - XML file to loadpRecordSpec - XML Record SpecificationpBeanSpec - Java Bean specification
List of Java BeansloadBeans(String,RecordSpec,BeanSpec),
loadBeans(InputStream,RecordSpec,BeanSpec),
loadBeans(InputSource,RecordSpec,BeanSpec),
loadBeansFromString(String,RecordSpec,BeanSpec),
loadBeansFromURI(String,RecordSpec,BeanSpec)
public List loadBeans(String pXmlFilePath,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
List of Java Beans.
This method allows you to specify the path to the XML file using a String instead of
creating a File object. For a code example,
see loadBeans(File,RecordSpec,BeanSpec)
pXmlFilePath - path of XML file to loadpRecordSpec - XML Record SpecificationpBeanSpec - Java Bean specification
List of Java BeansloadBeans(File,RecordSpec,BeanSpec)
public List loadBeans(InputStream pInputStream,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
InputStream as a
List of Java Beans.
This method allows you to use an InputStream instead of a file as the source of your XML data.
For a code example, see loadBeans(File,RecordSpec,BeanSpec)
pInputStream - InputStream providing XML datapRecordSpec - XML Record SpecificationpBeanSpec - Java Bean specification
List of Java BeansloadBeans(File,RecordSpec,BeanSpec)
public List loadBeans(InputSource pInputSource,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
InputSource as a
List of Java Beans.
This method allows you to use an InputSource instead of a file as the source of your XML data.
For a code example, see loadBeans(File,RecordSpec,BeanSpec)
pInputSource - InputSource providing XML datapRecordSpec - XML Record SpecificationpBeanSpec - Java Bean specification
List of Java BeansloadBeans(File,RecordSpec,BeanSpec)
public List loadBeansFromURI(String pURI,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
List of Java Beans.
This method allows you to use XML data available over a network or remote file system
by providing a URI specifying the location of the data. See
http://www.w3.org/Addressing for more information about URIs.
For a code example, see loadBeans(File,RecordSpec,BeanSpec)
pURI - Uniform Resource Identifier stringpRecordSpec - XML Record SpecificationpBeanSpec - Java Bean specification
List of Java BeansloadBeans(File,RecordSpec,BeanSpec)
public List loadBeansFromString(String pXmlString,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec)
String variable as a
List of Java Beans.
This method allows you to use XML data from an internal String variable
instead of loading it from an external file.
For a code example, see loadBeans(File,RecordSpec,BeanSpec)
pXmlString - String containing XML datapRecordSpec - XML Record SpecificationpBeanSpec - Java Bean pecification
List of Java BeansloadBeans(File,RecordSpec,BeanSpec)
public void load(File pXmlFile,
RecordListener pRecordListener)
RecordListener, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(File,RecordSpec,RecordListener), which has the same functionality.
load(File,RecordSpec,RecordListener)
public void load(String pXmlFilePath,
RecordListener pRecordListener)
RecordListener, using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(File,RecordSpec,RecordListener), which has the same functionality.
load(File,RecordSpec,RecordListener)
public void load(InputStream pInputStream,
RecordListener pRecordListener)
InputStream as a stream using your own RecordListener,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(File,RecordSpec,RecordListener), which has the same functionality.
load(File,RecordSpec,RecordListener)
public void load(InputSource pInputSource,
RecordListener pRecordListener)
InputSource as a stream using your own RecordListener,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(File,RecordSpec,RecordListener), which has the same functionality.
load(File,RecordSpec,RecordListener)
public void loadFromURI(String pURI,
RecordListener pRecordListener)
RecordListener,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(File,RecordSpec,RecordListener), which has the same functionality.
load(File,RecordSpec,RecordListener)
public void loadFromString(String pXmlString,
RecordListener pRecordListener)
String variable as a stream using your own RecordListener,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see load(File,RecordSpec,RecordListener), which has the same functionality.
load(File,RecordSpec,RecordListener)
public void load(File pXmlFile,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
RecordListener.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File( "mydata.xml" );
XmlManager xmlManager = new XmlManager();
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name","foo","bar"} );
SimpleRecordListener srl = new SimpleRecordListener();
xmlManager.load( xmlFile, rs, srl );
System.out.println( srl.getData() );
// you'll also need this class definition
public static class SimpleRecordListener extends RecordListenerSupport {
StringBuffer sb = new StringBuffer();
protected BadRecord handleRecordImpl( String[] pRecord, long pRecordNumber ) {
sb.append( pRecordNumber+":"+Arrays.asList( pRecord )+" " );
return null;
}
public String getData() {
return sb.toString();
}
}
This method allows you to access your XML data in a flexible and customised manner by providing your own handling and
storage of the XML data as it is loaded. See RecordListener for a more detailed discussion of this approach.
Note: you can use XmlSpec.setBackground(boolean) to load the XML data in a separate Thread.
pXmlFile - XML file to loadpRecordSpec - XML Record SpecificationpRecordListener - RecordListener to receive dataRecordListener,
load(String,RecordSpec,RecordListener),
load(InputStream,RecordSpec,RecordListener),
load(InputSource,RecordSpec,RecordListener),
loadFromURI(String,RecordSpec,RecordListener),
loadFromString(String,RecordSpec,RecordListener)
public void load(String pXmlFilePath,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
RecordListener.
This method allows you to specify the path to the XML file using a String instead of
creating a File object.
For a code example, see load(File,RecordSpec,RecordListener).
load(File,RecordSpec,RecordListener)
public void load(InputStream pInputStream,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
InputStream as a stream using your own RecordListener.
This method allows you to use an InputStream instead of a file as the source of your XML data.
For a code example, see load(File,RecordSpec,RecordListener).
load(File,RecordSpec,RecordListener)
public void load(InputSource pInputSource,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
InputSource as a stream using your own RecordListener.
This method allows you to use an InputSource instead of a file as the source of your XML data.
For a code example, see load(File,RecordSpec,RecordListener).
load(File,RecordSpec,RecordListener)
public void loadFromURI(String pURI,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
RecordListener.
This method allows you to use XML data available over a network or remote file system
by providing a URI specifying the location of the data. See
http://www.w3.org/Addressing for more information about URIs.
For a code example, see load(File,RecordSpec,RecordListener).
load(File,RecordSpec,RecordListener)
public void loadFromString(String pXmlString,
RecordSpec pRecordSpec,
RecordListener pRecordListener)
String variable as a stream using your own RecordListener.
This method allows you to use XML data from an internal String variable
instead of loading it from an external file.
For a code example, see load(File,RecordSpec,RecordListener).
load(File,RecordSpec,RecordListener)
public void save(File pXmlFile,
List pData)
List of String[] arrays,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see save(File,RecordSpec,List), which has the same functionality.
save(File,RecordSpec,List),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public void save(String pXmlFilePath,
List pData)
List of String[] arrays,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see save(String,RecordSpec,List), which has the same functionality.
save(String,RecordSpec,List),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public void save(OutputStream pOutputStream,
List pData)
OutputStream from a List of String[] arrays,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see save(OutputStream,RecordSpec,List), which has the same functionality.
save(OutputStream,RecordSpec,List),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public String saveToString(List pData)
String variable from a List of String[] arrays,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveToString(RecordSpec,List), which has the same functionality.
saveToString(RecordSpec,List),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public void save(File pXmlFile,
RecordSpec pRecordSpec,
List pData)
List of String[] arrays.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name","foo","bar"} );
ArrayList data = new ArrayList();
data.add( new String[] {"r1","f1","b1"} );
data.add( new String[] {"r2","f2","b2"} );
data.add( new String[] {"r3","f3","b3"} );
xmlManager.save( xmlFile, rs, data );
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
pXmlFile - XML file to savepRecordSpec - XML Record Specification defining output XMLpData - XML data (List of String[] arrays) to savesave(String,RecordSpec,List),
save(OutputStream,RecordSpec,List),
saveToString(RecordSpec,List)
public void save(String pXmlFilePath,
RecordSpec pRecordSpec,
List pData)
List of String[] arrays.
This method allows you to specify the path to the XML file using a String instead of
creating a File object. For a code example, see save(File,RecordSpec,List)
pXmlFilePath - path of file to save XML data topRecordSpec - XML Record Specification defining output XMLpData - XML data (List of String[] arrays) to savesave(File,RecordSpec,List)
public void save(OutputStream pOutputStream,
RecordSpec pRecordSpec,
List pData)
OutputStream from a List of String[] arrays.
This method allows you to save XML data to an OutputStream instead of to a file.
For a code example, see save(File,RecordSpec,List)
pOutputStream - OutputStream to save XML data topRecordSpec - XML Record Specification defining output XMLpData - XML data (List of String[] arrays) to savesave(File,RecordSpec,List)
public String saveToString(RecordSpec pRecordSpec,
List pData)
String variable from a List of String[] arrays.
This method allows you to save XML data directly to an internal String variable instead of to a file.
For a code example, see save(File,RecordSpec,List)
pData - XML data (List of String[] arrays) to savepRecordSpec - XML Record Specification defining output XML
String containing text in XML formatsave(File,RecordSpec,List)
public void saveAsLists(File pXmlFile,
List pData)
List of Lists of Strings,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveAsLists(File,RecordSpec,List), which has the same functionality.
pXmlFile - XML file to savepData - XML data (List of Lists of Strings) to savesaveAsLists(File,RecordSpec,List),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public void saveAsLists(String pXmlFilePath,
List pData)
List of Lists of Strings,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveAsLists(String,RecordSpec,List), which has the same functionality.
pXmlFilePath - path of file to save XML data topData - XML data (List of Lists of Strings) to savesaveAsLists(String,RecordSpec,List),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public void saveAsLists(OutputStream pOutputStream,
List pData)
OutputStream from a List of Lists of Strings
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveAsLists(OutputStream,RecordSpec,List), which has the same functionality.
pOutputStream - OutputStream to save XML data topData - XML data (List of Lists of Strings) to savesaveAsLists(OutputStream,RecordSpec,List),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)public String saveAsListsToString(List pData)
String variable from a List of Lists of Strings
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveAsListsToString(RecordSpec,List), which has the same functionality.
pData - XML data (List of Lists of Strings) to savesaveAsListsToString(RecordSpec,List),
setRecordSpec(com.ricebridge.xmlman.RecordSpec)
public void saveAsLists(File pXmlFile,
RecordSpec pRecordSpec,
List pData)
List of Lists of Strings.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name","foo","bar"} );
ArrayList data = new ArrayList();
ArrayList rec1 = new ArrayList(); rec1.add("r1"); rec1.add("f1"); rec1.add("b1");
ArrayList rec2 = new ArrayList(); rec2.add("r2"); rec2.add("f2"); rec2.add("b2");
ArrayList rec3 = new ArrayList(); rec3.add("r3"); rec3.add("f3"); rec3.add("b3");
data.add(rec1); data.add(rec2); data.add(rec3);
xmlManager.saveAsLists( xmlFile, rs, data );
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
pXmlFile - XML file to savepRecordSpec - XML Record Specification defining output XMLpData - XML data (List of Lists of Strings) to savesaveAsLists(String,RecordSpec,List),
saveAsLists(OutputStream,RecordSpec,List),
saveAsListsToString(RecordSpec,List)
public void saveAsLists(String pXmlFilePath,
RecordSpec pRecordSpec,
List pData)
List of Lists of Strings.
This method allows you to specify the path to the XML file using a String instead of
creating a File object. For a code example, see saveAsLists(File,RecordSpec,List)
pXmlFilePath - path of file to save XML data topRecordSpec - XML Record Specification defining output XMLpData - XML data (List of Lists of Strings) to savesaveAsLists(File,RecordSpec,List)
public void saveAsLists(OutputStream pOutputStream,
RecordSpec pRecordSpec,
List pData)
OutputStream from a List of Lists of Strings.
This method allows you to save XML data to an OutputStream instead of to a file.
For a code example, see saveAsLists(File,RecordSpec,List)
pOutputStream - OutputStream to save XML data topRecordSpec - XML Record Specification defining output XMLpData - XML data (List of Lists of Strings) to savesaveAsLists(File,RecordSpec,List)
public String saveAsListsToString(RecordSpec pRecordSpec,
List pData)
String variable from a List of Lists of Strings.
This method allows you to save XML data directly to an internal String variable instead of to a file.
For a code example, see saveAsLists(File,RecordSpec,List)
pData - XML data (List of Lists of Strings) to savepRecordSpec - XML Record Specification defining output XML
String containing text in XML formatsaveAsLists(File,RecordSpec,List)
public void saveTableModel(File pXmlFile,
TableModel pTableModel)
TableModel,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveTableModel(File,RecordSpec,TableModel), which has the same functionality.
pXmlFile - XML file to savepTableModel - XML data (as TableModel) to savesaveTableModel(String,TableModel),
saveTableModel(OutputStream,TableModel),
saveTableModelToString(TableModel)
public void saveTableModel(String pXmlFilePath,
TableModel pTableModel)
TableModel.
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveTableModel(String,RecordSpec,TableModel), which has the same functionality.
pXmlFilePath - path of file to save XML data topTableModel - XML data (as TableModel) to savesaveTableModel(File,RecordSpec,TableModel)
public void saveTableModel(OutputStream pOutputStream,
TableModel pTableModel)
OutputStream from a TableModel.
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveTableModel(OutputStream,RecordSpec,TableModel), which has the same functionality.
pOutputStream - OutputStream to save XML data topTableModel - XML data (as TableModel) to savesaveTableModel(File,RecordSpec,TableModel)public String saveTableModelToString(TableModel pTableModel)
String variable from a TableModel.
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveTableModelToString(RecordSpec,TableModel), which has the same functionality.
pTableModel - XML data (as TableModel) to save
String containing text in XML formatsaveTableModel(File,RecordSpec,TableModel)
public void saveTableModel(File pXmlFile,
RecordSpec pRecordSpec,
TableModel pTableModel)
TableModel.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
TableModel tm = myJTable.getModel();
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name","foo","bar"} );
xmlManager.saveTableModel( xmlFile, rs, tm );
Note: you will need to provide the myJTable variable before this code snippet will compile.
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
This method allows you to save your data directly from a Swing application.
If you want the first record of your XML data to contain the column headers,
set the TableModel.saveHeaders property to true, using XmlSpec.
The fields of the first record of your XML data will then come from the
TableModel.getColumnName(int) method,
and the second and subsequent records come from the data displayed in the table.
pXmlFile - XML file to savepRecordSpec - XML Record Specification defining output XMLpTableModel - XML data (as TableModel) to savesaveTableModel(String,TableModel),
saveTableModel(OutputStream,TableModel),
saveTableModelToString(TableModel)
public void saveTableModel(String pXmlFilePath,
RecordSpec pRecordSpec,
TableModel pTableModel)
TableModel.
This method allows you to specify the path to the XML file using a String instead of
creating a File object.
For a code example, see saveTableModel(File,RecordSpec,javax.swing.table.TableModel)
pXmlFilePath - path of file to save XML data topRecordSpec - XML Record Specification defining output XMLpTableModel - XML data (as TableModel) to savesaveTableModel(File,RecordSpec,TableModel)
public void saveTableModel(OutputStream pOutputStream,
RecordSpec pRecordSpec,
TableModel pTableModel)
OutputStream from a TableModel.
This method allows you to save XML data to an OutputStream instead of to a file.
For a code example, see saveTableModel(File,RecordSpec,javax.swing.table.TableModel)
pOutputStream - OutputStream to save XML data topRecordSpec - XML Record Specification defining output XMLpTableModel - XML data (as TableModel) to savesaveTableModel(File,RecordSpec,TableModel)
public String saveTableModelToString(RecordSpec pRecordSpec,
TableModel pTableModel)
String variable from a TableModel.
This method allows you to save XML data directly to an internal String variable instead of to a file.
For a code example, see saveTableModel(File,RecordSpec,TableModel)
pTableModel - XML data (as TableModel) to savepRecordSpec - XML Record Specification defining output XML
String containing text in XML formatsaveTableModel(File,RecordSpec,TableModel)
public void saveResultSet(File pXmlFile,
ResultSet pResultSet)
ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveResultSet(File,RecordSpec,ResultSet), which has the same functionality.
pXmlFile - XML file to savepResultSet - XML data (as ResultSet) to savesaveResultSet(String,ResultSet),
saveResultSet(OutputStream,ResultSet),
saveResultSetToString(ResultSet)
public void saveResultSet(String pXmlFilePath,
ResultSet pResultSet)
ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveResultSet(String,RecordSpec,ResultSet), which has the same functionality.
pXmlFilePath - path of file to save XML data topResultSet - XML data (as ResultSet) to savesaveResultSet(File,RecordSpec,ResultSet)
public void saveResultSet(OutputStream pOutputStream,
ResultSet pResultSet)
OutputStream from a ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveResultSet(OutputStream,RecordSpec,ResultSet), which has the same functionality.
pOutputStream - OutputStream to save XML data topResultSet - XML data (as ResultSet) to savesaveResultSet(File,RecordSpec,ResultSet)public String saveResultSetToString(ResultSet pResultSet)
String variable from a ResultSet,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveResultSetToString(RecordSpec,ResultSet), which has the same functionality.
pResultSet - XML data (as ResultSet) to save
String containing text in XML formatsaveResultSet(File,RecordSpec,ResultSet)
public void saveResultSet(File pXmlFile,
RecordSpec pRecordSpec,
ResultSet pResultSet)
ResultSet.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
Connection con = getDatabaseConnection(); // return a java.sql.Connection
// assume a Product table in database
PreparedStatement ps
= con.prepareStatement( "SELECT * FROM Product" );
ResultSet resultset = ps.executeQuery();
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name","foo","bar"} );
xmlManager.saveResultSet( xmlFile, rs, resultset );
Note: you will need to provide the getDatabaseConnection method before this code snippet will compile.
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
This method allows you to save your data directly from a database using the JDBC API.
If you want the first record of your XML data to be the column names, set ResultSet.saveHeaders
property to true, using XmlSpec.
The fields of the first record of your XML data will then come from the ResultSetMetaData object returned
from the ResultSet.getMetaData method,
and the second and subsequent records will come from the data presented by the ResultSet.
pXmlFile - XML file to savepRecordSpec - XML Record Specification defining output XMLpResultSet - XML data (as ResultSet) to savesaveResultSet(String,RecordSpec,ResultSet),
saveResultSet(OutputStream,RecordSpec,ResultSet),
saveResultSetToString(RecordSpec,ResultSet)
public void saveResultSet(String pXmlFilePath,
RecordSpec pRecordSpec,
ResultSet pResultSet)
ResultSet.
This method allows you to specify the path to the XML file using a String instead of
creating a File object.
For a code example, see saveResultSet(File,RecordSpec,ResultSet).
pXmlFilePath - path of file to save XML data topRecordSpec - XML Record Specification defining output XMLpResultSet - XML data (as ResultSet) to savesaveResultSet(File,RecordSpec,ResultSet)
public void saveResultSet(OutputStream pOutputStream,
RecordSpec pRecordSpec,
ResultSet pResultSet)
OutputStream from a ResultSet.
This method allows you to save XML data to an OutputStream instead of to a file.
For a code example, see saveResultSet(File,RecordSpec,ResultSet).
pOutputStream - OutputStream to save XML data topRecordSpec - XML Record Specification defining output XMLpResultSet - XML data (as ResultSet) to savesaveResultSet(File,RecordSpec,ResultSet)
public String saveResultSetToString(RecordSpec pRecordSpec,
ResultSet pResultSet)
String variable from a ResultSet.
This method allows you to save XML data directly to an internal String variable instead of to a file.
For a code example, see saveResultSet(File,RecordSpec,ResultSet).
pRecordSpec - XML Record Specification defining output XMLpResultSet - XML data (as ResultSet) to save
String containing text in XML formatsaveResultSet(File,RecordSpec,ResultSet)
public void saveBeans(File pXmlFile,
BeanSpec pBeanSpec,
List pBeans)
RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveBeans(File,RecordSpec,BeanSpec,List), which has the same functionality.
pXmlFile - XML file to savepBeanSpec - Java Bean specificationpBeans - List of Java Bean objectssaveBeans(String,BeanSpec,List),
saveBeans(OutputStream,BeanSpec,List),
saveBeansToString(BeanSpec,List)
public void saveBeans(String pXmlFilePath,
BeanSpec pBeanSpec,
List pBeans)
RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveBeans(String,RecordSpec,BeanSpec,List), which has the same functionality.
pXmlFilePath - path of file to save XML data topBeanSpec - Java Bean specificationpBeans - List of Java Bean objectssaveBeans(File,BeanSpec,List)
public void saveBeans(OutputStream pOutputStream,
BeanSpec pBeanSpec,
List pBeans)
OutputStream,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveBeans(OutputStream,RecordSpec,BeanSpec,List), which has the same functionality.
pOutputStream - OutputStream to save XML data topBeanSpec - Java Bean specificationpBeans - List of Java Bean objectssaveBeans(File,BeanSpec,List)
public String saveBeansToString(BeanSpec pBeanSpec,
List pBeans)
String variable,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveBeansToString(RecordSpec,BeanSpec,List), which has the same functionality.
pBeanSpec - Java Bean specificationpBeans - List of Java Bean objects
String containing text in XML formatsaveBeans(File,BeanSpec,List)
public void saveBeans(File pXmlFile,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec,
List pBeans)
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
// For Beans, we need to specify field names.
// These field names map directly to the bean property methods
RecordSpec rs = new RecordSpec( "/root/record",
new String[] {"@name","foo","bar"},
new String[] {"Name","Foo","Bar"} );
BeanSpec bs = new BeanSpec( BeanRecord.class );
ArrayList beans = new ArrayList();
beans.add( new BeanRecord("r1","f1","b1") );
beans.add( new BeanRecord("r2","f2","b2") );
beans.add( new BeanRecord("r3","f3","b3") );
xmlManager.saveBeans( xmlFile, rs, bs, beans );
// You'll also need this class definition
public static class BeanRecord {
private String iName, iFoo, iBar;
public BeanRecord( String pName, String pFoo, String pBar ) {
iName = pName; iFoo = pFoo; iBar = pBar;
}
public void setName( String pName ) { iName = pName; }
public String getName() { return iName; }
public void setFoo( String pFoo ) { iFoo = pFoo; }
public String getFoo() { return iFoo; }
public void setBar( String pBar ) { iBar = pBar; }
public String getBar() { return iBar; }
public String toString() {
return iName+":"+iFoo+":"+iBar;
}
}
The XML file mydata.xml is assumed to be the standard example XML file,
used throughout this API documentation. Follow the link to see the data in the file.
This method allows you to save your Java Beans directly as XML data.
You must specify the property method names using the third String[] argument to the
RecordSpec constructor. The property method names are the root names of the property methods, that is, with the
get/set/is prefix removed.
For more details on specifying the bean properties, see BeanSpec.
See the documentation for the loadBeans(File,RecordSpec,BeanSpec) method for more information about Java Beans support
in XML Manager.
pXmlFile - XML file to savepRecordSpec - XML Record Specification defining output XMLpBeanSpec - Java Bean specificationpBeans - List of Java Bean objectssaveBeans(String,RecordSpec,BeanSpec,List),
saveBeans(OutputStream,RecordSpec,BeanSpec,List),
saveBeansToString(RecordSpec,BeanSpec,List)
public void saveBeans(String pXmlFilePath,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec,
List pBeans)
This method allows you to specify the path to the XML file using a String instead of
creating a File object.
For a code example, see saveBeans(File,RecordSpec,BeanSpec,List).
pXmlFilePath - path of file to save XML data topRecordSpec - XML Record Specification defining output XMLpBeanSpec - Java Bean specificationpBeans - List of Java Bean objectssaveBeans(File,RecordSpec,BeanSpec,List)
public void saveBeans(OutputStream pOutputStream,
RecordSpec pRecordSpec,
BeanSpec pBeanSpec,
List pBeans)
This method allows you to save XML data to an OutputStream instead of to a file.
For a code example, see saveBeans(File,RecordSpec,BeanSpec,List).
pOutputStream - OutputStream to save XML data topRecordSpec - XML Record Specification defining output XMLpBeanSpec - Java Bean specificationpBeans - List of Java Bean objectssaveBeans(File,RecordSpec,BeanSpec,List)
public String saveBeansToString(RecordSpec pRecordSpec,
BeanSpec pBeanSpec,
List pBeans)
This method allows you to save XML data directly to an internal String variable instead of to a file.
For a code example, see saveBeans(File,RecordSpec,BeanSpec,List).
pRecordSpec - XML Record Specification defining output XMLpBeanSpec - Java Bean specificationpBeans - List of Java Bean objectssaveBeans(File,RecordSpec,BeanSpec,List)
public void save(File pXmlFile,
RecordProvider pRecordProvider)
RecordProvider,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see save(File,RecordSpec,RecordProvider), which has the same functionality.
pXmlFile - XML file to savepRecordProvider - RecordProvider providing data recordsRecordProvider,
save(File,RecordSpec,RecordProvider)
public void save(String pXmlFilePath,
RecordProvider pRecordProvider)
RecordProvider,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see save(String,RecordSpec,RecordProvider), which has the same functionality.
pXmlFilePath - path of XML file to loadpRecordProvider - RecordProvider to provide datasave(String,RecordSpec,RecordProvider)
public void save(OutputStream pOutputStream,
RecordProvider pRecordProvider)
OutputStream using your own RecordProvider,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see save(OutputStream,RecordSpec,RecordProvider), which has the same functionality.
pOutputStream - OutputStream receiving XML datapRecordProvider - RecordProvider to provide datasave(File,RecordSpec,RecordProvider)public String saveToString(RecordProvider pRecordProvider)
String variable using your own RecordProvider,
using the default RecordSpec.
To use this method, call setRecordSpec(RecordSpec) first to set the default RecordSpec.
For more details, see saveToString(RecordSpec,RecordProvider), which has the same functionality.
pRecordProvider - RecordProvider to provide data
String contained text in XML formatsave(File,RecordSpec,RecordProvider)
public void save(File pXmlFile,
RecordSpec pRecordSpec,
RecordProvider pRecordProvider)
RecordProvider.
Here is a code example to demonstrate the use of this method:
File xmlFile = new File("mydata.xml");
XmlManager xmlManager = new XmlManager();
RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name","foo","bar"} );
ArrayList data = new ArrayList();
data.add( new String[] {"r1","f1","b1"} );
data.add( new String[] {"r2","f2","b2"} );
data.add( new String[] {"r3","f3","b3"} );
SimpleRecordProvider srp = new SimpleRecordProvider( data );
xmlManager.save( xmlFile, rs, srp );
// you'll also need this class definition
public static class SimpleRecordProvider extends RecordProviderSupport {
private List iData;
private int iRecordIndex = 0;
public SimpleRecordProvider( List pData ) {
iData = pData;
}
public boolean hasNextRecordImpl() {
return iRecordIndex < iData.size();
}
public String[] nextRecordImpl() {
return (String[]) iData.get(iRecordIndex++);
}
}
This method allows you to provide your data in a flexible and customised manner for saving.
See RecordProvider for a more detailed discussion of this approach.
Note: you can use XmlSpec.setBackground(boolean) to save the XML data in a separate Thread.
pXmlFile - XML file to savepRecordSpec - XML Record Specification defining output XMLpRecordProvider - RecordProvider to provide dataRecordProvider,
save(File,RecordSpec,List)
public void save(String pXmlFilePath,
RecordSpec pRecordSpec,
RecordProvider pRecordProvider)
RecordProvider.
This method allows you to specify the path to the XML file using a String instead of
creating a File object. For a code example of how to use a RecordProvider,
see save(File,RecordSpec,RecordProvider)
pXmlFilePath - path of XML file to loadpRecordSpec - XML Record Specification defining output XMLpRecordProvider - RecordProvider to provide datasave(File,RecordSpec,RecordProvider)
public void save(OutputStream pOutputStream,
RecordSpec pRecordSpec,
RecordProvider pRecordProvider)
OutputStream using your own RecordProvider.
This method allows you to use an OutputStream instead of a file as the destination for your XML data.
For a code example of how to use a RecordProvider, see save(File,RecordSpec,RecordProvider)
pOutputStream - OutputStream receiving XML datapRecordSpec - XML Record Specification defining output XMLpRecordProvider - RecordProvider to provide datasave(File,RecordSpec,RecordProvider)
public String saveToString(RecordSpec pRecordSpec,
RecordProvider pRecordProvider)
String variable using your own RecordProvider.
This method allows you to save XML data to an internal String variable
instead of saving it to an external file.
For a code example of how to use a RecordProvider, see save(File,RecordSpec,RecordProvider)
pRecordProvider - RecordProvider to provide datapRecordSpec - XML Record Specification defining output XML
String contained text in XML formatsave(File,RecordSpec,RecordProvider)public boolean isLoadFinished()
true when the loading process is finished.
Normally this is only useful when loading as a background process.
getStats()public boolean isSaveFinished()
true when the saving process is finished.
Normally this is only useful when saving as a background process.
getStats()public void setXmlSpec(XmlSpec pXmlSpec)
XmlManager uses XmlSpec to control the interpretation and generation of XML.
Use this method to set your own XmlSpec instance with your own settings.
pXmlSpec - XmlSpec instancegetXmlSpec(),
XmlSpecpublic XmlSpec getXmlSpec()
XmlSpec, which specifies the settings for the interpretation and generation of XML.
This method returns the current instance of XmlSpec, so that you can change the
XML settings directly.
setXmlSpec(com.ricebridge.xmlman.XmlSpec),
XmlSpecpublic Stats getStats()
This method returns a convenience object that reports of the
number of data records loaded or saved, and how long the operation took.
It also provides an average processing time per record.
Full details are available on the Stats object API page.
Statspublic void setBadRecordListener(BadRecordListener pBadRecordListener)
BadRecordListener object to receive notification of semantically incorrect records
as they are encountered.
This is a callback interface similar to RecordListener and RecordProvider that provides
access to bad data so that you can handle it directly.
pBadRecordListener - BadRecordListener implementationBadRecordListener,
getBadRecords()public List getBadRecords()
XML Manager uses the BadRecord class to describe semantically incorrect data records.
This method returns a list of all bad records encountered. If the ignore bad records
setting is true, then all bad records will be in the list, if false then only the first such
record, as processing has been halted in this case.
What do we mean by semantically incorrect? Syntax errors are not allowed in XML, so XML Manager has to fail
immediately on those. Therefore, the only errors that can be collected as BadRecords are those where the actual
data in the record is bad, or where attempts to use the data fail. Normally this will not happen in the standard
RecordListeners such as StringArrayRecordListener simply because there is nothing to go wrong.
However, in custom RecordListeners that you might write yourself, such as ones that save data records to a database,
errors can occur. In such cases, you can return a BadRecord with your own application specific data
from the RecordListener.handleRecord(java.lang.String[], long)
method, and it will be stored for later examination via the getBadRecords method.
Of course, you can also just throw an Exception from the handleRecord method
instead, and XML Manager will automatically create a BadRecord for you.
BadRecord,
RecordListener,
getStats()public XmlManagerStore getXmlManagerStore()
XmlManagerStore is a utility class for creating
RecordListener and RecordProvider instances.
You can use XmlManagerStore to access the
default listeners and providers, or set your own defaults.
These listeners and providers are used with the four
data models: List of String[], List of Lists of String,
TableModel, ResultSet and Java Beans.
NOTE: the XmlManagerStore instance is shared by all threads using this XmlManager.
XmlManagerStorepublic void finishSave()
If the XmlSpec.setStreamOutput(boolean) setting is false, then this
method has no effect. Otherwise it attempts to output the closing XML elements
to the OutputStream previously supplied to a save method.
XmlSpec.setStreamOutput(boolean)public RecordSpec nullcheck(RecordSpec pRecordSpec)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||