org.jdesktop.dataset.io.schema
Class XMLDataSetSchemaReader

java.lang.Object
  extended by org.jdesktop.dataset.io.schema.XMLDataSetSchemaReader
All Implemented Interfaces:
DataSetSchemaReader

public class XMLDataSetSchemaReader
extends java.lang.Object
implements DataSetSchemaReader

An XMLDataSetSchemaReader instantiates a DataSet from an XML Schema. Each instance of XMLDataSetSchemaReader works against a single XML datasource, e.g. an InputStream; once instantiated against that InputStream, the reader methods (e.g. readDataSet()) may be used to load the DataSet. DataSetSchemaReader classes do not load data, only the DataSet schema. Typical usage: InputStream xmlIS = getClass().getResourceAsStream("resources/products.xsd"); XMLDataSetSchemaReader reader = new XMLDataSetSchemaReader(xmlIS); DataSet dataSet = reader.readDataSet(); xmlIS.close(); You can also use the single-line utility method DataSetUtility.readDataSetFromXml(InputStream, String[]).

Author:
Richard Bair, Patrick Wright

Constructor Summary
XMLDataSetSchemaReader(java.io.InputStream xmlInputStream)
          Instantiates a new XMLDataSetSchemaReader for an input stream holding a DataSet schema in XML format.
XMLDataSetSchemaReader(java.io.Reader xmlReader)
          Instantiates a new XMLDataSetSchemaReader for an input stream holding a DataSet schema in XML format.
 
Method Summary
 java.util.List<java.lang.String> addRelations(DataSet dataSet, java.lang.String... tableNames)
          Adds all DataRelation for the named DataTable to the specified DataSet, as read from the schema which this reader is reading from.
 java.util.List<java.lang.String> addTables(DataSet dataSet, java.lang.String... tableNames)
          Appends one or more DataTable to a DataSet from the schema represented by this reader.
 DataSet readDataSet()
          Instantiates a new DataSet from the InputStream specified in the constructor.
 DataSet readDataSet(java.lang.String... tableNames)
          Instantiates a new DataSet from the InputStream specified in the implementing class, with the DataSet schema loaded but without data, for the tables and columns given in the tableNames parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLDataSetSchemaReader

public XMLDataSetSchemaReader(java.io.InputStream xmlInputStream)
                       throws SchemaReaderException
Instantiates a new XMLDataSetSchemaReader for an input stream holding a DataSet schema in XML format. The input stream cannot be changed once the reader in instantiated, and the caller is responsible for closing the stream once the schema is loaded. See class documentation for more details.

Parameters:
xmlInputStream - A InputStream holding DataSet schema contents in XML format. The stream must be readable, and the caller is responsible for closing the stream once done.
Throws:
SchemaReaderException

XMLDataSetSchemaReader

public XMLDataSetSchemaReader(java.io.Reader xmlReader)
                       throws SchemaReaderException
Instantiates a new XMLDataSetSchemaReader for an input stream holding a DataSet schema in XML format. The input stream cannot be changed once the reader in instantiated, and the caller is responsible for closing the stream once the schema is loaded. See class documentation for more details.

Parameters:
xmlReader - A InputStream holding DataSet schema contents in XML format. The stream must be readable, and the caller is responsible for closing the stream once done.
Throws:
SchemaReaderException
Method Detail

readDataSet

public DataSet readDataSet()
                    throws SchemaReaderException
Instantiates a new DataSet from the InputStream specified in the constructor. If the schema contains multiple DataTables or DataRelations, all of them are loaded from the schema into the new DataSet.

Specified by:
readDataSet in interface DataSetSchemaReader
Returns:
A new DataSet instantiated from the InputStream specified for the implementing class, including all tables and relations in the schema.
Throws:
ashktheman.dataset.io.SchemaReaderException - If an error occurred while loading the schema.
SchemaReaderException

readDataSet

public DataSet readDataSet(java.lang.String... tableNames)
                    throws SchemaReaderException
Instantiates a new DataSet from the InputStream specified in the implementing class, with the DataSet schema loaded but without data, for the tables and columns given in the tableNames parameter.

Specified by:
readDataSet in interface DataSetSchemaReader
Parameters:
tableNames - One or more table names to load from the schema. Each name can be either a table, or a table and column, dot-separated. If no columns are specified, all columns in the table are read from the schema; if columns are listed, only those columns are loaded. DataRelations for those tables and columns loaded from the schema are also instantiated automatically through addRelations(org.jdesktop.dataset.DataSet, String[]).
Returns:
A new DataSet instantiated from the InputStream specified for the implementing class, including only the tables and columns listed in the tableNames parameter.
Throws:
ashktheman.dataset.io.SchemaReaderException - If an error occurred while loading the schema.
SchemaReaderException

addRelations

public java.util.List<java.lang.String> addRelations(DataSet dataSet,
                                                     java.lang.String... tableNames)
                                              throws SchemaReaderException
Adds all DataRelation for the named DataTable to the specified DataSet, as read from the schema which this reader is reading from. All DataRelations for the table are dropped from the DataSet and re-added.

Specified by:
addRelations in interface DataSetSchemaReader
Parameters:
dataSet - The DataSet to which to add the relations.
tableNames - One or more table names for which to read relations from the schema. Only those relations for columns in the DataTable (as currently loaded) are added.
Returns:
A List of the DataRelation names loaded from the schema.
Throws:
org.jdesktop.dataset.io.SchemaReaderException - If an error occurred while reading the schema.
SchemaReaderException

addTables

public java.util.List<java.lang.String> addTables(DataSet dataSet,
                                                  java.lang.String... tableNames)
                                           throws SchemaReaderException
Appends one or more DataTable to a DataSet from the schema represented by this reader. If the table, by name, is found in the DataSet, the table is skipped; if you want to re-add a table (for example, to pick up changes in table structure), drop the table from the DataSet before calling this method.

Specified by:
addTables in interface DataSetSchemaReader
Parameters:
dataSet - The DataSet to which to add the tables.
tableNames - One or more table names to load from the schema and add to the DataSet. Each name can be either a table, or a table and column, dot-separated. If no columns are specified, all columns in the table are read from the schema; if columns are listed, only those columns are loaded. DataRelations for those tables and columns are not loaded from the schema; to that end, use addRelations(DataSet, String...).
Returns:
A List of the table names that were actually found. You can check this to verify that all tables requested were loaded.
Throws:
org.jdesktop.dataset.io.SchemaReaderException - If an error occurred while reading the schema.
SchemaReaderException


Copyright © 2005 Sun Microsystems All Rights Reserved.