com.ricebridge.xmlman
Class XmlManager

java.lang.Object
  extended bycom.ricebridge.xmlman.XmlManager

public class XmlManager
extends Object

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:

Saving XML Data

The XmlManager class also provides the following ways to save XML data:

Input

XML Data can be read from the following types of input:

All the load methods accept these input types as their first parameter. Note that for ease-of-use, a 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:

All the save methods accept these output types as their first parameter. Note that for ease-of-use, a 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

and [source] is one of

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:
save[type]( [destination], [data] )
Where [type] is one of

and [destination] is one of and [data] is an object of type

When you want to save XML data to a String variable append ToString to the method name, like so: saveToString(RecordSpec,List).

When saving Java Beans, you will also need to include a BeanSpec parameter, see saveBeans(File,RecordSpec,BeanSpec,List) for an example.

Using RecordSpecs

A RecordSpec 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.

Throughout this API documentation, we use a standard reference block of XML for most of the examples. This block of XML looks like so:

  <?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>
  

If we apply the XPath expression /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.

The RecordSpec class allows us to specify this set of XPath expressions, like so:

  RecordSpec rs = new RecordSpec( "/root/record", new String[] {"@name", "foo"} );
  

This declaration creates a new 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.

XML Manager uses 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)

Prepared RecordSpecs

It is often the case that you need to apply the same RecordSpec 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 );
  

Once you have prepared a 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.

You can call the load and save methods repeatedly, and the prepared 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.

Saving Data with RecordSpecs

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 (record[@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.

Callback Interfaces

If the predefined methods of input and output are not suitable, you can implement your own access to your XML data. The 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.

If you want to provide data to save in a XML format, you can use the RecordProvider interface to provide the data by calling the save(*,RecordSpec,RecordProvider) methods.

Please note: to use the 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.

Options for XML format

For a full description of all the available options, refer to the XmlSpec class. The options used by XmlManager are stored in a XmlSpec object and you can access the current XmlSpec with getXmlSpec().

Frequently used options:

Background Processing

It is possible to perform the loading and saving operations in a background 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.

Statistics

XML Manager provides a number of statistics on the loading and saving process. To access these statistics, call the getStats() method to get the current Stats object. This object provides the following information:

For a quick summary of these statistics, use the Stats.getSummary() method.

Error Messages and Exception Handling

Normally an 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.

When an error occurs this class throws a 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.

See Also:
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
 void finishSave()
          Special method to complete final XML elements of streamed documents.
 List getBadRecords()
          Get a list of descriptions of any semantically incorrect data records encountered.
 Stats getStats()
          Get statistics on the number of records processed and processing time.
 XmlManagerStore getXmlManagerStore()
          XmlManagerStore is a utility class for creating RecordListener and RecordProvider instances.
 XmlSpec getXmlSpec()
          Get the current XmlSpec, which specifies the settings for the interpretation and generation of XML.
 boolean isLoadFinished()
          Returns true when the loading process is finished.
 boolean isSaveFinished()
          Returns true when the saving process is finished.
 List load(File pXmlFile)
          Load XML data from a file as a List of String[] arrays, using the default RecordSpec.
 void load(File pXmlFile, RecordListener pRecordListener)
          Load XML data from a file as a stream using your own RecordListener, using the default RecordSpec.
 List load(File pXmlFile, RecordSpec pRecordSpec)
          Load XML data from a file as a List of String[] arrays.
 void load(File pXmlFile, RecordSpec pRecordSpec, RecordListener pRecordListener)
          Load XML data from a file as a stream using your own RecordListener.
 List load(InputSource pInputSource)
          Load XML data from an InputSource as a List of String[] arrays, using the default RecordSpec.
 void load(InputSource pInputSource, RecordListener pRecordListener)
          Load XML data from an InputSource as a stream using your own RecordListener, using the default RecordSpec.
 List load(InputSource pInputSource, RecordSpec pRecordSpec)
          Load XML data from an InputSource as a List of String[] arrays.
 void load(InputSource pInputSource, RecordSpec pRecordSpec, RecordListener pRecordListener)
          Load XML data from an InputSource as a stream using your own RecordListener.
 List load(InputStream pInputStream)
          Load XML data from an InputStream as a List of String[] arrays, using the default RecordSpec.
 void load(InputStream pInputStream, RecordListener pRecordListener)
          Load XML data from an InputStream as a stream using your own RecordListener, using the default RecordSpec.
 List load(InputStream pInputStream, RecordSpec pRecordSpec)
          Load XML data from an InputStream as a List of String[] arrays.
 void load(InputStream pInputStream, RecordSpec pRecordSpec, RecordListener pRecordListener)
          Load XML data from an InputStream as a stream using your own RecordListener.
 List load(String pXmlFilePath)
          Load XML data from a specified file path as a List of String[] arrays, using the default RecordSpec.
 void load(String pXmlFilePath, RecordListener pRecordListener)
          Load XML data from a specified file path as a stream using your own RecordListener, using the default RecordSpec.
 List load(String pXmlFilePath, RecordSpec pRecordSpec)
          Load XML data from a specified file path as a List of String[] arrays.
 void load(String pXmlFilePath, RecordSpec pRecordSpec, RecordListener pRecordListener)
          Load XML data from a specified file path as a stream using your own RecordListener.
 List loadAsLists(File pXmlFile)
          Load XML data from a file as a List of Lists of Strings, using the default RecordSpec.
 List loadAsLists(File pXmlFile, RecordSpec pRecordSpec)
          Load XML data from a file as a List of Lists of Strings.
 List loadAsLists(InputSource pInputSource)
          Load XML data from an InputSource as a List of Lists of Strings, using the default RecordSpec.
 List loadAsLists(InputSource pInputSource, RecordSpec pRecordSpec)
          Load XML data from an InputSource as a List of Lists of Strings.
 List loadAsLists(InputStream pInputStream)
          Load XML data from an InputStream as a List of Lists of Strings, using the default RecordSpec.
 List loadAsLists(InputStream pInputStream, RecordSpec pRecordSpec)
          Load XML data from an InputStream as a List of Lists of Strings.
 List loadAsLists(String pXmlFilePath)
          Load XML data from a specified file path as a List of Lists of Strings, using the default RecordSpec.
 List loadAsLists(String pXmlFilePath, RecordSpec pRecordSpec)
          Load XML data from a specified file path as a List of Lists of Strings.
 List loadAsListsFromString(String pXmlString)
          Load XML data from a String variable as a List of Lists of Strings, using the default RecordSpec.
 List loadAsListsFromString(String pXmlString, RecordSpec pRecordSpec)
          Load XML data from a String variable as a List of Lists of Strings.
 List loadAsListsFromURI(String pURI)
          Load XML data specified by a Uniform Resource Identifier (URI) as a List of Lists of Strings, using the default RecordSpec.
 List loadAsListsFromURI(String pURI, RecordSpec pRecordSpec)
          Load XML data specified by a Uniform Resource Identifier (URI) as a List of Lists of Strings.
 List loadBeans(File pXmlFile, BeanSpec pBeanSpec)
          Load XML data from a file as a List of Java Beans, using the default RecordSpec.
 List loadBeans(File pXmlFile, RecordSpec pRecordSpec, BeanSpec pBeanSpec)
          Load XML data from a file as a List of Java Beans.
 List loadBeans(InputSource pInputSource, BeanSpec pBeanSpec)
          Load XML data from an InputSource as a List of Java Beans, using the default RecordSpec.
 List loadBeans(InputSource pInputSource, RecordSpec pRecordSpec, BeanSpec pBeanSpec)
          Load XML data from an InputSource as a List of Java Beans.
 List loadBeans(InputStream pInputStream, BeanSpec pBeanSpec)
          Load XML data from an InputStream as a List of Java Beans, using the default RecordSpec.
 List loadBeans(InputStream pInputStream, RecordSpec pRecordSpec, BeanSpec pBeanSpec)
          Load XML data from an InputStream as a List of Java Beans.
 List loadBeans(String pXmlFilePath, BeanSpec pBeanSpec)
          Load XML data from a specified file path as a List of Java Beans, using the default RecordSpec.
 List loadBeans(String pXmlFilePath, RecordSpec pRecordSpec, BeanSpec pBeanSpec)
          Load XML data from a specified file path as a List of Java Beans.
 List loadBeansFromString(String pXmlString, BeanSpec pBeanSpec)
          Load XML data from a String variable as a List of Java Beans, using the default RecordSpec.
 List loadBeansFromString(String pXmlString, RecordSpec pRecordSpec, BeanSpec pBeanSpec)
          Load XML data from a String variable as a List of Java Beans.
 List loadBeansFromURI(String pURI, BeanSpec pBeanSpec)
          Load XML data specified by a Uniform Resource Identifier (URI) as a List of Java Beans, using the default RecordSpec.
 List loadBeansFromURI(String pURI, RecordSpec pRecordSpec, BeanSpec pBeanSpec)
          Load XML data specified by a Uniform Resource Identifier (URI) as a List of Java Beans.
 List loadFromString(String pXmlString)
          Load XML data from a String variable as a List of String[] arrays, using the default RecordSpec.
 void loadFromString(String pXmlString, RecordListener pRecordListener)
          Load XML data from a String variable as a stream using your own RecordListener, using the default RecordSpec.
 List loadFromString(String pXmlString, RecordSpec pRecordSpec)
          Load XML data from a String variable as a List of String[] arrays.
 void loadFromString(String pXmlString, RecordSpec pRecordSpec, RecordListener pRecordListener)
          Load XML data from a String variable as a stream using your own RecordListener.
 List loadFromURI(String pURI)
          Load XML data specified by a Uniform Resource Identifier (URI) as a List of String[] arrays, using the default RecordSpec.
 void loadFromURI(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.
 List loadFromURI(String pURI, RecordSpec pRecordSpec)
          Load XML data specified by a Uniform Resource Identifier (URI) as a List of String[] arrays.
 void loadFromURI(String pURI, RecordSpec pRecordSpec, RecordListener pRecordListener)
          Load XML data specified by a Uniform Resource Identifier (URI) as a stream using your own RecordListener.
 ResultSet loadResultSet(File pXmlFile)
          Load XML data from a file as a ResultSet, using the default RecordSpec.
 ResultSet loadResultSet(File pXmlFile, RecordSpec pRecordSpec)
          Load XML data from a file as a ResultSet.
 ResultSet loadResultSet(InputSource pInputSource)
          Load XML data from an InputSource as a ResultSet, using the default RecordSpec.
 ResultSet loadResultSet(InputSource pInputSource, RecordSpec pRecordSpec)
          Load XML data from an InputSource as a ResultSet.
 ResultSet loadResultSet(InputStream pInputStream)
          Load XML data from an InputStream as a ResultSet, using the default RecordSpec.
 ResultSet loadResultSet(InputStream pInputStream, RecordSpec pRecordSpec)
          Load XML data from an InputStream as a ResultSet.
 ResultSet loadResultSet(String pXmlFilePath)
          Load XML data from a specified file path as a ResultSet, using the default RecordSpec.
 ResultSet loadResultSet(String pXmlFilePath, RecordSpec pRecordSpec)
          Load XML data from a specified file path as a ResultSet.
 ResultSet loadResultSetFromString(String pXmlString)
          Load XML data from a String variable as a ResultSet, using the default RecordSpec.
 ResultSet loadResultSetFromString(String pXmlString, RecordSpec pRecordSpec)
          Load XML data from a String variable as a ResultSet.
 ResultSet loadResultSetFromURI(String pURI)
          Load XML data specified by a Uniform Resource Identifier (URI) as a ResultSet, using the default RecordSpec.
 ResultSet loadResultSetFromURI(String pURI, RecordSpec pRecordSpec)
          Load XML data specified by a Uniform Resource Identifier (URI) as a ResultSet.
 TableModel loadTableModel(File pXmlFile)
          Load XML data from a file as a TableModel, using the default RecordSpec.
 TableModel loadTableModel(File pXmlFile, RecordSpec pRecordSpec)
          Load XML data from a file as a TableModel.
 TableModel loadTableModel(InputSource pInputSource)
          Load XML data from an InputSource as a TableModel, using the default RecordSpec.
 TableModel loadTableModel(InputSource pInputSource, RecordSpec pRecordSpec)
          Load XML data from an InputSource as a TableModel.
 TableModel loadTableModel(InputStream pInputStream)
          Load XML data from an InputStream as a TableModel, using the default RecordSpec.
 TableModel loadTableModel(InputStream pInputStream, RecordSpec pRecordSpec)
          Load XML data from an InputStream as a TableModel.
 TableModel loadTableModel(String pXmlFilePath)
          Load XML data from a specified file path as a TableModel, using the default RecordSpec.
 TableModel loadTableModel(String pXmlFilePath, RecordSpec pRecordSpec)
          Load XML data from a specified file path as a TableModel.
 TableModel loadTableModelFromString(String pXmlString)
          Load XML data from a String variable as a TableModel, using the default RecordSpec.
 TableModel loadTableModelFromString(String pXmlString, RecordSpec pRecordSpec)
          Load XML data from a String variable as a TableModel.
 TableModel loadTableModelFromURI(String pURI)
          Load XML data specified by a Uniform Resource Identifier (URI) as a TableModel, using the default RecordSpec.
 TableModel loadTableModelFromURI(String pURI, RecordSpec pRecordSpec)
          Load XML data specified by a Uniform Resource Identifier (URI) as a TableModel.
 RecordSpec nullcheck(RecordSpec pRecordSpec)
          Check that RecordSpec is not null.
 void save(File pXmlFile, List pData)
          Save XML data to a file from a List of String[] arrays, using the default RecordSpec.
 void save(File pXmlFile, RecordProvider pRecordProvider)
          Save XML data to a file using your own RecordProvider, using the default RecordSpec.
 void save(File pXmlFile, RecordSpec pRecordSpec, List pData)
          Save XML data to a file from a List of String[] arrays.
 void save(File pXmlFile, RecordSpec pRecordSpec, RecordProvider pRecordProvider)
          Save XML data to a file using your own RecordProvider.
 void save(OutputStream pOutputStream, List pData)
          Save XML data to an OutputStream from a List of String[] arrays, using the default RecordSpec.
 void save(OutputStream pOutputStream, RecordProvider pRecordProvider)
          Save XML data to an OutputStream using your own RecordProvider, using the default RecordSpec.
 void save(OutputStream pOutputStream, RecordSpec pRecordSpec, List pData)
          Save XML data to an OutputStream from a List of String[] arrays.
 void save(OutputStream pOutputStream, RecordSpec pRecordSpec, RecordProvider pRecordProvider)
          Save XML data to an OutputStream using your own RecordProvider.
 void save(String pXmlFilePath, List pData)
          Save XML data to a specified file path from a List of String[] arrays, using the default RecordSpec.
 void save(String pXmlFilePath, RecordProvider pRecordProvider)
          Save XML data to a specified file path using your own RecordProvider, using the default RecordSpec.
 void save(String pXmlFilePath, RecordSpec pRecordSpec, List pData)
          Save XML data to a specified file path from a List of String[] arrays.
 void save(String pXmlFilePath, RecordSpec pRecordSpec, RecordProvider pRecordProvider)
          Save XML data to a specified file path using your own RecordProvider.
 void saveAsLists(File pXmlFile, List pData)
          Save XML data to a file from a List of Lists of Strings, using the default RecordSpec.
 void saveAsLists(File pXmlFile, RecordSpec pRecordSpec, List pData)
          Save XML data to a file from a List of Lists of Strings.
 void saveAsLists(OutputStream pOutputStream, List pData)
          Save XML data to an OutputStream from a List of Lists of Strings using the default RecordSpec.
 void saveAsLists(OutputStream pOutputStream, RecordSpec pRecordSpec, List pData)
          Save XML data to an OutputStream from a List of Lists of Strings.
 void saveAsLists(String pXmlFilePath, List pData)
          Save XML data to a specified file path from a List of Lists of Strings, using the default RecordSpec.
 void saveAsLists(String pXmlFilePath, RecordSpec pRecordSpec, List pData)
          Save XML data to a specified file path from a List of Lists of Strings.
 String saveAsListsToString(List pData)
          Save XML data to a String variable from a List of Lists of Strings using the default RecordSpec.
 String saveAsListsToString(RecordSpec pRecordSpec, List pData)
          Save XML data to a String variable from a List of Lists of Strings.
 void saveBeans(File pXmlFile, BeanSpec pBeanSpec, List pBeans)
          Save Java Beans as XML data to a file, using the default RecordSpec.
 void saveBeans(File pXmlFile, RecordSpec pRecordSpec, BeanSpec pBeanSpec, List pBeans)
          Save Java Beans as XML data to a file.
 void saveBeans(OutputStream pOutputStream, BeanSpec pBeanSpec, List pBeans)
          Save Java Beans as XML data to an OutputStream, using the default RecordSpec.
 void saveBeans(OutputStream pOutputStream, RecordSpec pRecordSpec, BeanSpec pBeanSpec, List pBeans)
          Save Java Beans as XML data to a file.
 void saveBeans(String pXmlFilePath, BeanSpec pBeanSpec, List pBeans)
          Save Java Beans as XML data to a specified file path, using the default RecordSpec.
 void saveBeans(String pXmlFilePath, RecordSpec pRecordSpec, BeanSpec pBeanSpec, List pBeans)
          Save Java Beans as XML data to a specified file path.
 String saveBeansToString(BeanSpec pBeanSpec, List pBeans)
          Save Java Beans as XML data to a String variable, using the default RecordSpec.
 String saveBeansToString(RecordSpec pRecordSpec, BeanSpec pBeanSpec, List pBeans)
          Save Java Beans as XML data to a file.
 void saveResultSet(File pXmlFile, RecordSpec pRecordSpec, ResultSet pResultSet)
          Save XML data to a file from a ResultSet.
 void saveResultSet(File pXmlFile, ResultSet pResultSet)
          Save XML data to a file from a ResultSet, using the default RecordSpec.
 void saveResultSet(OutputStream pOutputStream, RecordSpec pRecordSpec, ResultSet pResultSet)
          Save XML data to an OutputStream from a ResultSet.
 void saveResultSet(OutputStream pOutputStream, ResultSet pResultSet)
          Save XML data to an OutputStream from a ResultSet, using the default RecordSpec.
 void saveResultSet(String pXmlFilePath, RecordSpec pRecordSpec, ResultSet pResultSet)
          Save XML data to a specified file path from a ResultSet.
 void saveResultSet(String pXmlFilePath, ResultSet pResultSet)
          Save XML data to a specified file path from a ResultSet, using the default RecordSpec.
 String saveResultSetToString(RecordSpec pRecordSpec, ResultSet pResultSet)
          Save XML data to a String variable from a ResultSet.
 String saveResultSetToString(ResultSet pResultSet)
          Save XML data to a String variable from a ResultSet, using the default RecordSpec.
 void saveTableModel(File pXmlFile, RecordSpec pRecordSpec, TableModel pTableModel)
          Save XML data to a file from a TableModel.
 void saveTableModel(File pXmlFile, TableModel pTableModel)
          Save XML data to a file from a TableModel, using the default RecordSpec.
 void saveTableModel(OutputStream pOutputStream, RecordSpec pRecordSpec, TableModel pTableModel)
          Save XML data to an OutputStream from a TableModel.
 void saveTableModel(OutputStream pOutputStream, TableModel pTableModel)
          Save XML data to an OutputStream from a TableModel.
 void saveTableModel(String pXmlFilePath, RecordSpec pRecordSpec, TableModel pTableModel)
          Save XML data to a specified file path from a TableModel.
 void saveTableModel(String pXmlFilePath, TableModel pTableModel)
          Save XML data to a specified file path from a TableModel.
 String saveTableModelToString(RecordSpec pRecordSpec, TableModel pTableModel)
          Save XML data to a String variable from a TableModel.
 String saveTableModelToString(TableModel pTableModel)
          Save XML data to a String variable from a TableModel.
 String saveToString(List pData)
          Save XML data to a String variable from a List of String[] arrays, using the default RecordSpec.
 String saveToString(RecordProvider pRecordProvider)
          Save XML data to a String variable using your own RecordProvider, using the default RecordSpec.
 String saveToString(RecordSpec pRecordSpec, List pData)
          Save XML data to a String variable from a List of String[] arrays.
 String saveToString(RecordSpec pRecordSpec, RecordProvider pRecordProvider)
          Save XML data to a String variable using your own RecordProvider.
 void setBadRecordListener(BadRecordListener pBadRecordListener)
          Set a BadRecordListener object to receive notification of semantically incorrect records as they are encountered.
 void setRecordSpec(RecordSpec pRecordSpec)
          Set the default RecordSpec for this XmlManager instance.
 void setXmlSpec(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()
Create a new instance of XmlManager, with default settings.

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 load or save methods with a RecordSpec defining your data records.

You can use the same 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.

The XmlManager class is designed to be thread safe, so you can use the same XmlManager instance in more than one thread.

To specify your own default settings, use the XmlManager(XmlSpec) constructor. To specify a default RecordSpec use the XmlManager(RecordSpec) constructor.

See Also:
XmlManager(XmlSpec), XmlManager(XmlSpec,RecordSpec), XmlManager(RecordSpec)

XmlManager

public XmlManager(XmlSpec pXmlSpec)
Create a new instance of XmlManager using the specified XmlSpec XML format specification.

The 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.

Unlike this constructor, the 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 instance

If an XmlSpec is not specified in a constructor, then a new default XmlSpec is created as needed.

See Also:
XmlManager(), XmlManager(XmlSpec,RecordSpec), XmlSpec

XmlManager

public XmlManager(RecordSpec pRecordSpec)
Create a new instance of XmlManager using the specified RecordSpec data record specification.

This constructor parses and stores the 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).

See Also:
XmlManager, RecordSpec, XmlManager(XmlSpec,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

XmlManager

public XmlManager(XmlSpec pXmlSpec,
                  RecordSpec pRecordSpec)
Create a new instance of 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.

See Also:
XmlManager(com.ricebridge.xmlman.XmlSpec, com.ricebridge.xmlman.RecordSpec), XmlManager(XmlSpec), XmlManager(RecordSpec)
Method Detail

setRecordSpec

public void setRecordSpec(RecordSpec pRecordSpec)
Set the default 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.

See Also:
XmlManager(RecordSpec), RecordSpec

load

public List load(File pXmlFile)
Load XML data from a file 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(File,RecordSpec), which has the same functionality.

Returns:
List of String[] arrays
See Also:
load(File,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

load

public List load(String pXmlFilePath)
Load XML data from a specified file path 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(String,RecordSpec), which has the same functionality.

Returns:
List of String[] arrays
See Also:
load(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

load

public List load(InputStream pInputStream)
Load XML data from an 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.

Returns:
List of String[] arrays
See Also:
load(InputStream,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

load

public List load(InputSource pInputSource)
Load XML data from an 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.

Returns:
List of String[] arrays
See Also:
load(InputSource,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadFromURI

public List loadFromURI(String pURI)
Load XML data specified by a Uniform Resource Identifier (URI) 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 loadFromURI(String,RecordSpec), which has the same functionality.

Returns:
List of String[] arrays
See Also:
loadFromURI(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadFromString

public List loadFromString(String pXmlString)
Load XML data from a 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.

Returns:
List of String[] arrays
See Also:
loadFromString(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

load

public List load(File pXmlFile,
                 RecordSpec pRecordSpec)
Load XML data from a file as a 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.

Parameters:
pXmlFile - XML file to load
pRecordSpec - XML Record Specification
Returns:
List of String[] arrays
See Also:
load(String,RecordSpec), load(InputStream,RecordSpec), load(InputSource,RecordSpec), loadFromURI(String,RecordSpec), loadFromString(String,RecordSpec)

load

public List load(String pXmlFilePath,
                 RecordSpec pRecordSpec)
Load XML data from a specified file path as a 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).

Returns:
List of String[] arrays
See Also:
load(File,RecordSpec)

load

public List load(InputStream pInputStream,
                 RecordSpec pRecordSpec)
Load XML data from an 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).

Returns:
List of String[] arrays
See Also:
load(File,RecordSpec)

load

public List load(InputSource pInputSource,
                 RecordSpec pRecordSpec)
Load XML data from an 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).

Returns:
List of String[] arrays
See Also:
load(File,RecordSpec)

loadFromURI

public List loadFromURI(String pURI,
                        RecordSpec pRecordSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a 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).

Returns:
List of String[] arrays
See Also:
load(File,RecordSpec)

loadFromString

public List loadFromString(String pXmlString,
                           RecordSpec pRecordSpec)
Load XML data from a 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).

Returns:
List of String[] arrays
See Also:
load(File,RecordSpec)

loadAsLists

public List loadAsLists(File pXmlFile)
Load XML data from a file 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(File,RecordSpec), which has the same functionality.

Returns:
List of Lists of Strings
See Also:
loadAsLists(File,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadAsLists

public List loadAsLists(String pXmlFilePath)
Load XML data from a specified file path 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(String,RecordSpec), which has the same functionality.

Returns:
List of Lists of Strings
See Also:
loadAsLists(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadAsLists

public List loadAsLists(InputStream pInputStream)
Load XML data from an 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.

Returns:
List of Lists of Strings
See Also:
loadAsLists(InputStream,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadAsLists

public List loadAsLists(InputSource pInputSource)
Load XML data from an 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.

Returns:
List of Lists of Strings
See Also:
loadAsLists(InputSource,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadAsListsFromURI

public List loadAsListsFromURI(String pURI)
Load XML data specified by a Uniform Resource Identifier (URI) 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 loadAsListsFromURI(String,RecordSpec), which has the same functionality.

Returns:
List of Lists of Strings
See Also:
loadAsListsFromURI(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadAsListsFromString

public List loadAsListsFromString(String pXmlString)
Load XML data from a 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.

Returns:
List of Lists of Strings
See Also:
loadAsListsFromString(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadAsLists

public List loadAsLists(File pXmlFile,
                        RecordSpec pRecordSpec)
Load XML data from a file as a 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.

Parameters:
pXmlFile - XML file to load
pRecordSpec - XML Record Specification
Returns:
List of Lists of Strings
See Also:
loadAsLists(String,RecordSpec), loadAsLists(InputStream,RecordSpec), loadAsLists(InputSource,RecordSpec), loadAsListsFromURI(String,RecordSpec), loadAsListsFromString(String,RecordSpec)

loadAsLists

public List loadAsLists(String pXmlFilePath,
                        RecordSpec pRecordSpec)
Load XML data from a specified file path as a 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).

Returns:
List of Lists of Strings
See Also:
loadAsLists(File,RecordSpec)

loadAsLists

public List loadAsLists(InputStream pInputStream,
                        RecordSpec pRecordSpec)
Load XML data from an 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).

Returns:
List of Lists of Strings
See Also:
loadAsLists(File,RecordSpec)

loadAsLists

public List loadAsLists(InputSource pInputSource,
                        RecordSpec pRecordSpec)
Load XML data from an 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).

Returns:
List of Lists of Strings
See Also:
loadAsLists(File,RecordSpec)

loadAsListsFromURI

public List loadAsListsFromURI(String pURI,
                               RecordSpec pRecordSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a 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).

Returns:
List of Lists of Strings
See Also:
loadAsLists(File,RecordSpec)

loadAsListsFromString

public List loadAsListsFromString(String pXmlString,
                                  RecordSpec pRecordSpec)
Load XML data from a 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).

Returns:
List of Lists of Strings
See Also:
loadAsLists(File,RecordSpec)

loadTableModel

public TableModel loadTableModel(File pXmlFile)
Load XML data from a file 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(File,RecordSpec), which has the same functionality.

Returns:
TableModel
See Also:
loadTableModel(File,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadTableModel

public TableModel loadTableModel(String pXmlFilePath)
Load XML data from a specified file path 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(String,RecordSpec), which has the same functionality.

Returns:
TableModel
See Also:
loadTableModel(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadTableModel

public TableModel loadTableModel(InputStream pInputStream)
Load XML data from an 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.

Returns:
TableModel
See Also:
loadTableModel(InputStream,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadTableModel

public TableModel loadTableModel(InputSource pInputSource)
Load XML data from an 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.

Returns:
TableModel
See Also:
loadTableModel(InputSource,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadTableModelFromURI

public TableModel loadTableModelFromURI(String pURI)
Load XML data specified by a Uniform Resource Identifier (URI) as a 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.

Returns:
TableModel
See Also:
loadTableModelFromURI(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadTableModelFromString

public TableModel loadTableModelFromString(String pXmlString)
Load XML data from a 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.

Returns:
TableModel
See Also:
loadTableModelFromString(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadTableModel

public TableModel loadTableModel(File pXmlFile,
                                 RecordSpec pRecordSpec)
Load XML data from a file as a 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.

Parameters:
pXmlFile - XML file to load
pRecordSpec - XML Record Specification
Returns:
TableModel
See Also:
loadTableModel(String,RecordSpec), loadTableModel(InputStream,RecordSpec), loadTableModel(InputSource,RecordSpec), loadTableModelFromURI(String,RecordSpec), loadTableModelFromString(String,RecordSpec)

loadTableModel

public TableModel loadTableModel(String pXmlFilePath,
                                 RecordSpec pRecordSpec)
Load XML data from a specified file path as a 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)

Parameters:
pXmlFilePath - path of XML file to load
pRecordSpec - XML Record Specification
Returns:
TableModel
See Also:
loadTableModel(File,RecordSpec)

loadTableModel

public TableModel loadTableModel(InputStream pInputStream,
                                 RecordSpec pRecordSpec)
Load XML data from an 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)

Parameters:
pInputStream - InputStream providing XML data
pRecordSpec - XML Record Specification
Returns:
TableModel
See Also:
loadTableModel(File,RecordSpec)

loadTableModel

public TableModel loadTableModel(InputSource pInputSource,
                                 RecordSpec pRecordSpec)
Load XML data from an 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)

Parameters:
pInputSource - InputSource providing XML data
pRecordSpec - XML Record Specification
Returns:
TableModel
See Also:
loadTableModel(File,RecordSpec)

loadTableModelFromURI

public TableModel loadTableModelFromURI(String pURI,
                                        RecordSpec pRecordSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a 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)

Parameters:
pURI - Uniform Resource Identifier string
pRecordSpec - XML Record Specification
Returns:
TableModel
See Also:
loadTableModel(File,RecordSpec)

loadTableModelFromString

public TableModel loadTableModelFromString(String pXmlString,
                                           RecordSpec pRecordSpec)
Load XML data from a 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)

Parameters:
pXmlString - String containing XML data
pRecordSpec - XML Record Specification
Returns:
TableModel
See Also:
loadTableModel(File,RecordSpec)

loadResultSet

public ResultSet loadResultSet(File pXmlFile)
Load XML data from a file 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(File,RecordSpec), which has the same functionality.

Returns:
ResultSet
See Also:
loadResultSet(File,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadResultSet

public ResultSet loadResultSet(String pXmlFilePath)
Load XML data from a specified file path 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(String,RecordSpec), which has the same functionality.

Returns:
ResultSet
See Also:
loadResultSet(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadResultSet

public ResultSet loadResultSet(InputStream pInputStream)
Load XML data from an 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.

Returns:
ResultSet
See Also:
loadResultSet(InputStream,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadResultSet

public ResultSet loadResultSet(InputSource pInputSource)
Load XML data from an 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.

Returns:
ResultSet
See Also:
loadResultSet(InputSource,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadResultSetFromURI

public ResultSet loadResultSetFromURI(String pURI)
Load XML data specified by a Uniform Resource Identifier (URI) as a 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.

Returns:
ResultSet
See Also:
loadResultSetFromURI(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadResultSetFromString

public ResultSet loadResultSetFromString(String pXmlString)
Load XML data from a 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.

Returns:
ResultSet
See Also:
loadResultSetFromString(String,RecordSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadResultSet

public ResultSet loadResultSet(File pXmlFile,
                               RecordSpec pRecordSpec)
Load XML data from a file as a 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.

Parameters:
pXmlFile - XML file to load
pRecordSpec - XML Record Specification
Returns:
ResultSet
See Also:
loadResultSet(String,RecordSpec), loadResultSet(InputStream,RecordSpec), loadResultSet(InputSource,RecordSpec), loadResultSetFromString(String,RecordSpec), loadResultSetFromURI(String,RecordSpec)

loadResultSet

public ResultSet loadResultSet(String pXmlFilePath,
                               RecordSpec pRecordSpec)
Load XML data from a specified file path as a 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)

Parameters:
pXmlFilePath - path of XML file to load
pRecordSpec - XML Record Specification
Returns:
ResultSet
See Also:
loadResultSet(File,RecordSpec)

loadResultSet

public ResultSet loadResultSet(InputStream pInputStream,
                               RecordSpec pRecordSpec)
Load XML data from an 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)

Parameters:
pInputStream - InputStream providing XML data
pRecordSpec - XML Record Specification
Returns:
ResultSet
See Also:
loadResultSet(File,RecordSpec)

loadResultSet

public ResultSet loadResultSet(InputSource pInputSource,
                               RecordSpec pRecordSpec)
Load XML data from an 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)

Parameters:
pInputSource - InputSource providing XML data
pRecordSpec - XML Record Specification
Returns:
ResultSet
See Also:
loadResultSet(File,RecordSpec)

loadResultSetFromURI

public ResultSet loadResultSetFromURI(String pURI,
                                      RecordSpec pRecordSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a 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)

Parameters:
pURI - Uniform Resource Identifier string
pRecordSpec - XML Record Specification
Returns:
ResultSet
See Also:
loadResultSet(File,RecordSpec)

loadResultSetFromString

public ResultSet loadResultSetFromString(String pXmlString,
                                         RecordSpec pRecordSpec)
Load XML data from a 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)

Parameters:
pXmlString - String containing XML data
pRecordSpec - XML Record Specification
Returns:
ResultSet
See Also:
loadResultSet(File,RecordSpec)

loadBeans

public List loadBeans(File pXmlFile,
                      BeanSpec pBeanSpec)
Load XML data from a file 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(File,RecordSpec,BeanSpec), which has the same functionality.

Parameters:
pXmlFile - XML file to load
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeans(File,RecordSpec,BeanSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadBeans

public List loadBeans(String pXmlFilePath,
                      BeanSpec pBeanSpec)
Load XML data from a specified file path 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(String,RecordSpec,BeanSpec), which has the same functionality.

Parameters:
pXmlFilePath - path of XML file to load
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeans(String,RecordSpec,BeanSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadBeans

public List loadBeans(InputStream pInputStream,
                      BeanSpec pBeanSpec)
Load XML data from an 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.

Parameters:
pInputStream - InputStream providing XML data
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeans(InputStream,RecordSpec,BeanSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadBeans

public List loadBeans(InputSource pInputSource,
                      BeanSpec pBeanSpec)
Load XML data from an 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.

Parameters:
pInputSource - InputSource providing XML data
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeans(InputSource,RecordSpec,BeanSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadBeansFromURI

public List loadBeansFromURI(String pURI,
                             BeanSpec pBeanSpec)
Load XML data specified by a Uniform Resource Identifier (URI) 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 loadBeansFromURI(String,RecordSpec,BeanSpec), which has the same functionality.

Parameters:
pURI - Uniform Resource Identifier string
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeansFromURI(String,RecordSpec,BeanSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadBeansFromString

public List loadBeansFromString(String pXmlString,
                                BeanSpec pBeanSpec)
Load XML data from a 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.

Parameters:
pXmlString - String containing XML data
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeansFromString(String,RecordSpec,BeanSpec), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

loadBeans

public List loadBeans(File pXmlFile,
                      RecordSpec pRecordSpec,
                      BeanSpec pBeanSpec)
Load XML data from a file as a 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.

Parameters:
pXmlFile - XML file to load
pRecordSpec - XML Record Specification
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeans(String,RecordSpec,BeanSpec), loadBeans(InputStream,RecordSpec,BeanSpec), loadBeans(InputSource,RecordSpec,BeanSpec), loadBeansFromString(String,RecordSpec,BeanSpec), loadBeansFromURI(String,RecordSpec,BeanSpec)

loadBeans

public List loadBeans(String pXmlFilePath,
                      RecordSpec pRecordSpec,
                      BeanSpec pBeanSpec)
Load XML data from a specified file path as a 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)

Parameters:
pXmlFilePath - path of XML file to load
pRecordSpec - XML Record Specification
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeans(File,RecordSpec,BeanSpec)

loadBeans

public List loadBeans(InputStream pInputStream,
                      RecordSpec pRecordSpec,
                      BeanSpec pBeanSpec)
Load XML data from an 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)

Parameters:
pInputStream - InputStream providing XML data
pRecordSpec - XML Record Specification
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeans(File,RecordSpec,BeanSpec)

loadBeans

public List loadBeans(InputSource pInputSource,
                      RecordSpec pRecordSpec,
                      BeanSpec pBeanSpec)
Load XML data from an 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)

Parameters:
pInputSource - InputSource providing XML data
pRecordSpec - XML Record Specification
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeans(File,RecordSpec,BeanSpec)

loadBeansFromURI

public List loadBeansFromURI(String pURI,
                             RecordSpec pRecordSpec,
                             BeanSpec pBeanSpec)
Load XML data specified by a Uniform Resource Identifier (URI) as a 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)

Parameters:
pURI - Uniform Resource Identifier string
pRecordSpec - XML Record Specification
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
See Also:
loadBeans(File,RecordSpec,BeanSpec)

loadBeansFromString

public List loadBeansFromString(String pXmlString,
                                RecordSpec pRecordSpec,
                                BeanSpec pBeanSpec)
Load XML data from a 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)

Parameters:
pXmlString - String containing XML data
pRecordSpec - XML Record Specification
pBeanSpec - Java Bean pecification
Returns:
List of Java Beans
See Also:
loadBeans(File,RecordSpec,BeanSpec)

load

public void load(File pXmlFile,
                 RecordListener pRecordListener)
Load XML data from a file 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.

See Also:
load(File,RecordSpec,RecordListener)

load

public void load(String pXmlFilePath,
                 RecordListener pRecordListener)
Load XML data from a specified file path 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.

See Also:
load(File,RecordSpec,RecordListener)

load

public void load(InputStream pInputStream,
                 RecordListener pRecordListener)
Load XML data from an 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.

See Also:
load(File,RecordSpec,RecordListener)

load

public void load(InputSource pInputSource,
                 RecordListener pRecordListener)
Load XML data from an 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.

See Also:
load(File,RecordSpec,RecordListener)

loadFromURI

public void loadFromURI(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.

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.

See Also:
load(File,RecordSpec,RecordListener)

loadFromString

public void loadFromString(String pXmlString,
                           RecordListener pRecordListener)
Load XML data from a 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.

See Also:
load(File,RecordSpec,RecordListener)

load

public void load(File pXmlFile,
                 RecordSpec pRecordSpec,
                 RecordListener pRecordListener)
Load XML data from a file as a stream using your own 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.

Parameters:
pXmlFile - XML file to load
pRecordSpec - XML Record Specification
pRecordListener - RecordListener to receive data
See Also:
RecordListener, load(String,RecordSpec,RecordListener), load(InputStream,RecordSpec,RecordListener), load(InputSource,RecordSpec,RecordListener), loadFromURI(String,RecordSpec,RecordListener), loadFromString(String,RecordSpec,RecordListener)

load

public void load(String pXmlFilePath,
                 RecordSpec pRecordSpec,
                 RecordListener pRecordListener)
Load XML data from a specified file path as a stream using your own 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).

See Also:
load(File,RecordSpec,RecordListener)

load

public void load(InputStream pInputStream,
                 RecordSpec pRecordSpec,
                 RecordListener pRecordListener)
Load XML data from an 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).

See Also:
load(File,RecordSpec,RecordListener)

load

public void load(InputSource pInputSource,
                 RecordSpec pRecordSpec,
                 RecordListener pRecordListener)
Load XML data from an 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).

See Also:
load(File,RecordSpec,RecordListener)

loadFromURI

public void loadFromURI(String pURI,
                        RecordSpec pRecordSpec,
                        RecordListener pRecordListener)
Load XML data specified by a Uniform Resource Identifier (URI) as a stream using your own 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).

See Also:
load(File,RecordSpec,RecordListener)

loadFromString

public void loadFromString(String pXmlString,
                           RecordSpec pRecordSpec,
                           RecordListener pRecordListener)
Load XML data from a 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).

See Also:
load(File,RecordSpec,RecordListener)

save

public void save(File pXmlFile,
                 List pData)
Save XML data to a file 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(File,RecordSpec,List), which has the same functionality.

See Also:
save(File,RecordSpec,List), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

save

public void save(String pXmlFilePath,
                 List pData)
Save XML data to a specified file path 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(String,RecordSpec,List), which has the same functionality.

See Also:
save(String,RecordSpec,List), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

save

public void save(OutputStream pOutputStream,
                 List pData)
Save XML data to an 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.

See Also:
save(OutputStream,RecordSpec,List), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

saveToString

public String saveToString(List pData)
Save XML data to a 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.

See Also:
saveToString(RecordSpec,List), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

save

public void save(File pXmlFile,
                 RecordSpec pRecordSpec,
                 List pData)
Save XML data to a file from a 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.

Parameters:
pXmlFile - XML file to save
pRecordSpec - XML Record Specification defining output XML
pData - XML data (List of String[] arrays) to save
See Also:
save(String,RecordSpec,List), save(OutputStream,RecordSpec,List), saveToString(RecordSpec,List)

save

public void save(String pXmlFilePath,
                 RecordSpec pRecordSpec,
                 List pData)
Save XML data to a specified file path from a 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)

Parameters:
pXmlFilePath - path of file to save XML data to
pRecordSpec - XML Record Specification defining output XML
pData - XML data (List of String[] arrays) to save
See Also:
save(File,RecordSpec,List)

save

public void save(OutputStream pOutputStream,
                 RecordSpec pRecordSpec,
                 List pData)
Save XML data to an 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)

Parameters:
pOutputStream - OutputStream to save XML data to
pRecordSpec - XML Record Specification defining output XML
pData - XML data (List of String[] arrays) to save
See Also:
save(File,RecordSpec,List)

saveToString

public String saveToString(RecordSpec pRecordSpec,
                           List pData)
Save XML data to a 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)

Parameters:
pData - XML data (List of String[] arrays) to save
pRecordSpec - XML Record Specification defining output XML
Returns:
String containing text in XML format
See Also:
save(File,RecordSpec,List)

saveAsLists

public void saveAsLists(File pXmlFile,
                        List pData)
Save XML data to a file 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(File,RecordSpec,List), which has the same functionality.

Parameters:
pXmlFile - XML file to save
pData - XML data (List of Lists of Strings) to save
See Also:
saveAsLists(File,RecordSpec,List), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

saveAsLists

public void saveAsLists(String pXmlFilePath,
                        List pData)
Save XML data to a specified file path 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(String,RecordSpec,List), which has the same functionality.

Parameters:
pXmlFilePath - path of file to save XML data to
pData - XML data (List of Lists of Strings) to save
See Also:
saveAsLists(String,RecordSpec,List), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

saveAsLists

public void saveAsLists(OutputStream pOutputStream,
                        List pData)
Save XML data to an 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.

Parameters:
pOutputStream - OutputStream to save XML data to
pData - XML data (List of Lists of Strings) to save
See Also:
saveAsLists(OutputStream,RecordSpec,List), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

saveAsListsToString

public String saveAsListsToString(List pData)
Save XML data to a 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.

Parameters:
pData - XML data (List of Lists of Strings) to save
See Also:
saveAsListsToString(RecordSpec,List), setRecordSpec(com.ricebridge.xmlman.RecordSpec)

saveAsLists

public void saveAsLists(File pXmlFile,
                        RecordSpec pRecordSpec,
                        List pData)
Save XML data to a file from a 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.

Parameters:
pXmlFile - XML file to save
pRecordSpec - XML Record Specification defining output XML
pData - XML data (List of Lists of Strings) to save
See Also:
saveAsLists(String,RecordSpec,List), saveAsLists(OutputStream,RecordSpec,List), saveAsListsToString(RecordSpec,List)

saveAsLists

public void saveAsLists(String pXmlFilePath,
                        RecordSpec pRecordSpec,
                        List pData)
Save XML data to a specified file path from a 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)

Parameters:
pXmlFilePath - path of file to save XML data to
pRecordSpec - XML Record Specification defining output XML
pData - XML data (List of Lists of Strings) to save
See Also:
saveAsLists(File,RecordSpec,List)

saveAsLists

public void saveAsLists(OutputStream pOutputStream,
                        RecordSpec pRecordSpec,
                        List pData)
Save XML data to an 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)

Parameters:
pOutputStream - OutputStream to save XML data to
pRecordSpec - XML Record Specification defining output XML
pData - XML data (List of Lists of Strings) to save
See Also:
saveAsLists(File,RecordSpec,List)

saveAsListsToString

public String saveAsListsToString(RecordSpec pRecordSpec,
                                  List pData)
Save XML data to a 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)

Parameters:
pData - XML data (List of Lists of Strings) to save
pRecordSpec - XML Record Specification defining output XML
Returns:
String containing text in XML format
See Also:
saveAsLists(File,RecordSpec,List)

saveTableModel

public void saveTableModel(File pXmlFile,
                           TableModel pTableModel)
Save XML data to a file 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(File,RecordSpec,TableModel), which has the same functionality.

Parameters:
pXmlFile - XML file to save
pTableModel - XML data (as TableModel) to save
See Also:
saveTableModel(String,TableModel), saveTableModel(OutputStream,TableModel), saveTableModelToString(TableModel)

saveTableModel

public void saveTableModel(String pXmlFilePath,
                           TableModel pTableModel)
Save XML data to a specified file path 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(String,RecordSpec,TableModel), which has the same functionality.

Parameters:
pXmlFilePath - path of file to save XML data to
pTableModel - XML data (as TableModel) to save
See Also:
saveTableModel(File,RecordSpec,TableModel)

saveTableModel

public void saveTableModel(OutputStream pOutputStream,
                           TableModel pTableModel)
Save XML data to an 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.

Parameters:
pOutputStream - OutputStream to save XML data to
pTableModel - XML data (as TableModel) to save
See Also:
saveTableModel(File,RecordSpec,TableModel)

saveTableModelToString

public String saveTableModelToString(TableModel pTableModel)
Save XML data to a 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.

Parameters:
pTableModel - XML data (as TableModel) to save
Returns:
String containing text in XML format
See Also:
saveTableModel(File,RecordSpec,TableModel)

saveTableModel

public void saveTableModel(File pXmlFile,
                           RecordSpec pRecordSpec,
                           TableModel pTableModel)
Save XML data to a file from a 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.

Parameters:
pXmlFile - XML file to save
pRecordSpec - XML Record Specification defining output XML
pTableModel - XML data (as TableModel) to save
See Also:
saveTableModel(String,TableModel), saveTableModel(OutputStream,TableModel), saveTableModelToString(TableModel)

saveTableModel

public void saveTableModel(String pXmlFilePath,
                           RecordSpec pRecordSpec,
                           TableModel pTableModel)
Save XML data to a specified file path from a 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)

Parameters:
pXmlFilePath - path of file to save XML data to
pRecordSpec - XML Record Specification defining output XML
pTableModel - XML data (as TableModel) to save
See Also:
saveTableModel(File,RecordSpec,TableModel)

saveTableModel

public void saveTableModel(OutputStream pOutputStream,
                           RecordSpec pRecordSpec,
                           TableModel pTableModel)
Save XML data to an 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)

Parameters:
pOutputStream - OutputStream to save XML data to
pRecordSpec - XML Record Specification defining output XML
pTableModel - XML data (as TableModel) to save
See Also:
saveTableModel(File,RecordSpec,TableModel)

saveTableModelToString

public String saveTableModelToString(RecordSpec pRecordSpec,
                                     TableModel pTableModel)
Save XML data to a 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)

Parameters:
pTableModel - XML data (as TableModel) to save
pRecordSpec - XML Record Specification defining output XML
Returns:
String containing text in XML format
See Also:
saveTableModel(File,RecordSpec,TableModel)

saveResultSet

public void saveResultSet(File pXmlFile,
                          ResultSet pResultSet)
Save XML data to a file 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(File,RecordSpec,ResultSet), which has the same functionality.

Parameters:
pXmlFile - XML file to save
pResultSet - XML data (as ResultSet) to save
See Also:
saveResultSet(String,ResultSet), saveResultSet(OutputStream,ResultSet), saveResultSetToString(ResultSet)

saveResultSet

public void saveResultSet(String pXmlFilePath,
                          ResultSet pResultSet)
Save XML data to a specified file path 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(String,RecordSpec,ResultSet), which has the same functionality.

Parameters:
pXmlFilePath - path of file to save XML data to
pResultSet - XML data (as ResultSet) to save
See Also:
saveResultSet(File,RecordSpec,ResultSet)

saveResultSet

public void saveResultSet(OutputStream pOutputStream,
                          ResultSet pResultSet)
Save XML data to an 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.

Parameters:
pOutputStream - OutputStream to save XML data to
pResultSet - XML data (as ResultSet) to save
See Also:
saveResultSet(File,RecordSpec,ResultSet)

saveResultSetToString

public String saveResultSetToString(ResultSet pResultSet)
Save XML data to a 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.

Parameters:
pResultSet - XML data (as ResultSet) to save
Returns:
String containing text in XML format
See Also:
saveResultSet(File,RecordSpec,ResultSet)

saveResultSet

public void saveResultSet(File pXmlFile,
                          RecordSpec pRecordSpec,
                          ResultSet pResultSet)
Save XML data to a file from a 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.

Parameters:
pXmlFile - XML file to save
pRecordSpec - XML Record Specification defining output XML
pResultSet - XML data (as ResultSet) to save
See Also:
saveResultSet(String,RecordSpec,ResultSet), saveResultSet(OutputStream,RecordSpec,ResultSet), saveResultSetToString(RecordSpec,ResultSet)

saveResultSet

public void saveResultSet(String pXmlFilePath,
                          RecordSpec pRecordSpec,
                          ResultSet pResultSet)
Save XML data to a specified file path from a 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).

Parameters:
pXmlFilePath - path of file to save XML data to
pRecordSpec - XML Record Specification defining output XML
pResultSet - XML data (as ResultSet) to save
See Also:
saveResultSet(File,RecordSpec,ResultSet)

saveResultSet

public void saveResultSet(OutputStream pOutputStream,
                          RecordSpec pRecordSpec,
                          ResultSet pResultSet)
Save XML data to an 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).

Parameters:
pOutputStream - OutputStream to save XML data to
pRecordSpec - XML Record Specification defining output XML
pResultSet - XML data (as ResultSet) to save
See Also:
saveResultSet(File,RecordSpec,ResultSet)

saveResultSetToString

public String saveResultSetToString(RecordSpec pRecordSpec,
                                    ResultSet pResultSet)
Save XML data to a 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).

Parameters:
pRecordSpec - XML Record Specification defining output XML
pResultSet - XML data (as ResultSet) to save
Returns:
String containing text in XML format
See Also:
saveResultSet(File,RecordSpec,ResultSet)

saveBeans

public void saveBeans(File pXmlFile,
                      BeanSpec pBeanSpec,
                      List pBeans)
Save Java Beans as XML data to a file, using the default 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.

Parameters:
pXmlFile - XML file to save
pBeanSpec - Java Bean specification
pBeans - List of Java Bean objects
See Also:
saveBeans(String,BeanSpec,List), saveBeans(OutputStream,BeanSpec,List), saveBeansToString(BeanSpec,List)

saveBeans

public void saveBeans(String pXmlFilePath,
                      BeanSpec pBeanSpec,
                      List pBeans)
Save Java Beans as XML data to a specified file path, using the default 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.

Parameters:
pXmlFilePath - path of file to save XML data to
pBeanSpec - Java Bean specification
pBeans - List of Java Bean objects
See Also:
saveBeans(File,BeanSpec,List)

saveBeans

public void saveBeans(OutputStream pOutputStream,
                      BeanSpec pBeanSpec,
                      List pBeans)
Save Java Beans as XML data to an 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.

Parameters:
pOutputStream - OutputStream to save XML data to
pBeanSpec - Java Bean specification
pBeans - List of Java Bean objects
See Also:
saveBeans(File,BeanSpec,List)

saveBeansToString

public String saveBeansToString(BeanSpec pBeanSpec,
                                List pBeans)
Save Java Beans as XML data to a 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.

Parameters:
pBeanSpec - Java Bean specification
pBeans - List of Java Bean objects
Returns:
String containing text in XML format
See Also:
saveBeans(File,BeanSpec,List)

saveBeans

public void saveBeans(File pXmlFile,
                      RecordSpec pRecordSpec,
                      BeanSpec pBeanSpec,
                      List pBeans)
Save Java Beans as XML data to a file.

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.

Parameters:
pXmlFile - XML file to save
pRecordSpec - XML Record Specification defining output XML
pBeanSpec - Java Bean specification
pBeans - List of Java Bean objects
See Also:
saveBeans(String,RecordSpec,BeanSpec,List), saveBeans(OutputStream,RecordSpec,BeanSpec,List), saveBeansToString(RecordSpec,BeanSpec,List)

saveBeans

public void saveBeans(String pXmlFilePath,
                      RecordSpec pRecordSpec,
                      BeanSpec pBeanSpec,
                      List pBeans)
Save Java Beans as XML data to a specified file path.

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).

Parameters:
pXmlFilePath - path of file to save XML data to
pRecordSpec - XML Record Specification defining output XML
pBeanSpec - Java Bean specification
pBeans - List of Java Bean objects
See Also:
saveBeans(File,RecordSpec,BeanSpec,List)

saveBeans

public void saveBeans(OutputStream pOutputStream,
                      RecordSpec pRecordSpec,
                      BeanSpec pBeanSpec,
                      List pBeans)
Save Java Beans as XML data to a file.

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).

Parameters:
pOutputStream - OutputStream to save XML data to
pRecordSpec - XML Record Specification defining output XML
pBeanSpec - Java Bean specification
pBeans - List of Java Bean objects
See Also:
saveBeans(File,RecordSpec,BeanSpec,List)

saveBeansToString

public String saveBeansToString(RecordSpec pRecordSpec,
                                BeanSpec pBeanSpec,
                                List pBeans)
Save Java Beans as XML data to a file.

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).

Parameters:
pRecordSpec - XML Record Specification defining output XML
pBeanSpec - Java Bean specification
pBeans - List of Java Bean objects
See Also:
saveBeans(File,RecordSpec,BeanSpec,List)

save

public void save(File pXmlFile,
                 RecordProvider pRecordProvider)
Save XML data to a file 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(File,RecordSpec,RecordProvider), which has the same functionality.

Parameters:
pXmlFile - XML file to save
pRecordProvider - RecordProvider providing data records
See Also:
RecordProvider, save(File,RecordSpec,RecordProvider)

save

public void save(String pXmlFilePath,
                 RecordProvider pRecordProvider)
Save XML data to a specified file path 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(String,RecordSpec,RecordProvider), which has the same functionality.

Parameters:
pXmlFilePath - path of XML file to load
pRecordProvider - RecordProvider to provide data
See Also:
save(String,RecordSpec,RecordProvider)

save

public void save(OutputStream pOutputStream,
                 RecordProvider pRecordProvider)
Save XML data to an 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.

Parameters:
pOutputStream - OutputStream receiving XML data
pRecordProvider - RecordProvider to provide data
See Also:
save(File,RecordSpec,RecordProvider)

saveToString

public String saveToString(RecordProvider pRecordProvider)
Save XML data to a 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.

Parameters:
pRecordProvider - RecordProvider to provide data
Returns:
String contained text in XML format
See Also:
save(File,RecordSpec,RecordProvider)

save

public void save(File pXmlFile,
                 RecordSpec pRecordSpec,
                 RecordProvider pRecordProvider)
Save XML data to a file using your own 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.

Parameters:
pXmlFile - XML file to save
pRecordSpec - XML Record Specification defining output XML
pRecordProvider - RecordProvider to provide data
See Also:
RecordProvider, save(File,RecordSpec,List)

save

public void save(String pXmlFilePath,
                 RecordSpec pRecordSpec,
                 RecordProvider pRecordProvider)
Save XML data to a specified file path using your own 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)

Parameters:
pXmlFilePath - path of XML file to load
pRecordSpec - XML Record Specification defining output XML
pRecordProvider - RecordProvider to provide data
See Also:
save(File,RecordSpec,RecordProvider)

save

public void save(OutputStream pOutputStream,
                 RecordSpec pRecordSpec,
                 RecordProvider pRecordProvider)
Save XML data to an 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)

Parameters:
pOutputStream - OutputStream receiving XML data
pRecordSpec - XML Record Specification defining output XML
pRecordProvider - RecordProvider to provide data
See Also:
save(File,RecordSpec,RecordProvider)

saveToString

public String saveToString(RecordSpec pRecordSpec,
                           RecordProvider pRecordProvider)
Save XML data to a 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)

Parameters:
pRecordProvider - RecordProvider to provide data
pRecordSpec - XML Record Specification defining output XML
Returns:
String contained text in XML format
See Also:
save(File,RecordSpec,RecordProvider)

isLoadFinished

public boolean isLoadFinished()
Returns true when the loading process is finished.

Normally this is only useful when loading as a background process.

See Also:
getStats()

isSaveFinished

public boolean isSaveFinished()
Returns true when the saving process is finished.

Normally this is only useful when saving as a background process.

See Also:
getStats()

setXmlSpec

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.

Parameters:
pXmlSpec - XmlSpec instance
See Also:
getXmlSpec(), XmlSpec

getXmlSpec

public XmlSpec getXmlSpec()
Get the current 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.

See Also:
setXmlSpec(com.ricebridge.xmlman.XmlSpec), XmlSpec

getStats

public Stats getStats()
Get statistics on the number of records processed and processing time.

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.

See Also:
Stats

setBadRecordListener

public void setBadRecordListener(BadRecordListener pBadRecordListener)
Set a 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.

Parameters:
pBadRecordListener - BadRecordListener implementation
See Also:
BadRecordListener, getBadRecords()

getBadRecords

public List getBadRecords()
Get a list of descriptions of any semantically incorrect data records encountered.

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.

See Also:
BadRecord, RecordListener, getStats()

getXmlManagerStore

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.

See Also:
XmlManagerStore

finishSave

public void finishSave()
Special method to complete final XML elements of streamed documents.

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.

See Also:
XmlSpec.setStreamOutput(boolean)

nullcheck

public RecordSpec nullcheck(RecordSpec pRecordSpec)
Check that RecordSpec is not null.



Copyright © 2004-2005 Ricebridge