com.languagecomputer.api.query
Class QueryXML

java.lang.Object
  extended by com.languagecomputer.api.query.QueryXML

public class QueryXML
extends Object

Handles XML conversion for Querys, QueryResults, Keywords, and Answers. Designed to be capable of handling different Query versions much like the DocumentXML. The XML version number does not depend on the API version number.

Since:
1.0
Author:
Kirk Roberts

Field Summary
static String CURRENT_VERSION
           
 
Constructor Summary
QueryXML()
          Creates a new QueryXML that writes using the current Query XML version.
QueryXML(String version)
          Creates a new QueryXML that writes using the given version.
 
Method Summary
 List<Answer> readAnswers(Reader reader)
          Reads the XML into a new List of Answers.
 Query readQuery(Reader reader)
          Reads the XML into a new Query.
 List<QueryResult> readQueryResults(Reader reader, DocumentXML xmlReader)
          Reads the XML into a new List of QueryResults.
 void writeAnswers(List<Answer> answers, Writer writer)
          Writes the given Answers to XML in the given Writer.
 void writeQuery(Query query, Writer writer)
          Writes the given Query to XML in the given Writer.
 void writeQueryResults(List<QueryResult> queryResults, DocumentXML xmlWriter, Writer writer)
          Writes the given QueryResults to XML in the given Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CURRENT_VERSION

public static final String CURRENT_VERSION
See Also:
Constant Field Values
Constructor Detail

QueryXML

public QueryXML()
Creates a new QueryXML that writes using the current Query XML version. Is capable of reading all known versions.

See Also:
CURRENT_VERSION

QueryXML

public QueryXML(String version)
Creates a new QueryXML that writes using the given version. Is capable of reading all known versions.

Parameters:
version - The version number to use for writing/reading. Using old versions for writing is not guaranteed.
Method Detail

writeQuery

public void writeQuery(Query query,
                       Writer writer)
                throws IOException
Writes the given Query to XML in the given Writer. Does not close the Writer.

Parameters:
query - Query to serialize to XML.
writer - Writer to write the XML to.
Throws:
IllegalStateException - If the version number is unknown.
IOException - If there is a problem writing to XML.

writeQueryResults

public void writeQueryResults(List<QueryResult> queryResults,
                              DocumentXML xmlWriter,
                              Writer writer)
                       throws IOException
Writes the given QueryResults to XML in the given Writer. Does not close the Writer.

Parameters:
queryResults - QueryResults to serialize to XML.
xmlWriter - DocumentXML to convert the Document to a specific XML version.
writer - Writer to write the XML to.
Throws:
IllegalStateException - If the version number is unknown.
IOException - If there is a problem writing to XML.

writeAnswers

public void writeAnswers(List<Answer> answers,
                         Writer writer)
                  throws IOException
Writes the given Answers to XML in the given Writer. Does not close the Writer.

Parameters:
answers - Answers to serialize to XML.
writer - Writer to write the XML to.
Throws:
IllegalStateException - If the version number is unknown.
IOException - If there is a problem writing to XML.

readQuery

public Query readQuery(Reader reader)
                throws IOException
Reads the XML into a new Query.

Parameters:
reader - Reader to read the XML from.
Returns:
New Query from the XML.
Throws:
IllegalArgumentException - If the Query is an unknown version or is un-readable.
IOException - If there is a problem reading the XML.

readQueryResults

public List<QueryResult> readQueryResults(Reader reader,
                                          DocumentXML xmlReader)
                                   throws IOException
Reads the XML into a new List of QueryResults.

Parameters:
reader - Reader to read the XML from.
Returns:
New QueryResults from the XML.
Throws:
IllegalArgumentException - If the QueryResults are an unknown version or is un-readable.
IOException - If there is a problem reading the XML.

readAnswers

public List<Answer> readAnswers(Reader reader)
                         throws IOException
Reads the XML into a new List of Answers.

Parameters:
reader - Reader to read the XML from.
Returns:
New Answers from the XML.
Throws:
IllegalArgumentException - If the Answers are an unknown version or is un-readable.
IOException - If there is a problem reading the XML.


Copyright © 2009. All Rights Reserved.