JGAP

org.jgap.xml
Class XMLManager

java.lang.Object
  extended by org.jgap.xml.XMLManager

public class XMLManager
extends java.lang.Object

The XMLManager performs marshalling of genetic entity instances (such as Chromosomes and Genotypes) to XML representations of those entities, as well as unmarshalling. All of the methods in this class are static, so no construction is required (or allowed).

Since:
1.0

Method Summary
static Chromosome getChromosomeFromDocument(Configuration a_activeConfiguration, org.w3c.dom.Document a_xmlDocument)
          Unmarshall a Chromosome instance from a given XML Document representation.
static Chromosome getChromosomeFromElement(Configuration a_activeConfiguration, org.w3c.dom.Element a_xmlElement)
          Unmarshall a Chromosome instance from a given XML Element representation.
static Gene[] getGenesFromElement(Configuration a_activeConfiguration, org.w3c.dom.Element a_xmlElement)
          Unmarshall a Chromosome instance from a given XML Element representation.
static Genotype getGenotypeFromDocument(Configuration a_activeConfiguration, org.w3c.dom.Document a_xmlDocument)
          Unmarshall a Genotype instance from a given XML Document representation.
static Genotype getGenotypeFromElement(Configuration a_activeConfiguration, org.w3c.dom.Element a_xmlElement)
          Unmarshall a Genotype instance from a given XML Element representation.
static org.w3c.dom.Document readFile(java.io.File file)
          Reads in an XML file and returns a Document object
static org.w3c.dom.Document representChromosomeAsDocument(IChromosome a_subject)
          Deprecated. use XMLDocumentBuilder instead
static org.w3c.dom.Element representChromosomeAsElement(IChromosome a_subject, org.w3c.dom.Document a_xmlDocument)
          Deprecated. use XMLDocumentBuilder instead
static org.w3c.dom.Element representGenesAsElement(Gene[] a_geneValues, org.w3c.dom.Document a_xmlDocument)
          Deprecated. use XMLDocumentBuilder instead
static org.w3c.dom.Document representGenotypeAsDocument(Genotype a_subject)
          Deprecated. use XMLDocumentBuilder instead
static org.w3c.dom.Element representGenotypeAsElement(Genotype a_subject, org.w3c.dom.Document a_xmlDocument)
          Deprecated. use XMLDocumentBuilder instead
static void writeFile(org.w3c.dom.Document doc, java.io.File file)
          Writes an XML file from a Document object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

representChromosomeAsDocument

public static org.w3c.dom.Document representChromosomeAsDocument(IChromosome a_subject)
Deprecated. use XMLDocumentBuilder instead

Marshall a Chromosome instance to an XML Document representation, including its contained Gene instances.

Parameters:
a_subject - the chromosome to represent as an XML document
Returns:
a Document object representing the given Chromosome
Since:
1.0

representGenotypeAsDocument

public static org.w3c.dom.Document representGenotypeAsDocument(Genotype a_subject)
Deprecated. use XMLDocumentBuilder instead

Marshall a Genotype to an XML Document representation, including its population of Chromosome instances.

Parameters:
a_subject - the genotype to represent as an XML document
Returns:
a Document object representing the given Genotype
Since:
1.0

representGenesAsElement

public static org.w3c.dom.Element representGenesAsElement(Gene[] a_geneValues,
                                                          org.w3c.dom.Document a_xmlDocument)
Deprecated. use XMLDocumentBuilder instead

Marshall an array of Genes to an XML Element representation.

Parameters:
a_geneValues - the genes to represent as an XML element
a_xmlDocument - a Document instance that will be used to create the Element instance. Note that the element will NOT be added to the document by this method
Returns:
an Element object representing the given genes
Since:
1.0

representChromosomeAsElement

public static org.w3c.dom.Element representChromosomeAsElement(IChromosome a_subject,
                                                               org.w3c.dom.Document a_xmlDocument)
Deprecated. use XMLDocumentBuilder instead

Marshall a Chromosome instance to an XML Element representation, including its contained Genes as sub-elements. This may be useful in scenarios where representation as an entire Document is undesirable, such as when the representation of this Chromosome is to be combined with other elements in a single Document.

Parameters:
a_subject - the chromosome to represent as an XML element
a_xmlDocument - a Document instance that will be used to create the Element instance. Note that the element will NOT be added to the document by this method
Returns:
an Element object representing the given Chromosome
Since:
1.0

representGenotypeAsElement

public static org.w3c.dom.Element representGenotypeAsElement(Genotype a_subject,
                                                             org.w3c.dom.Document a_xmlDocument)
Deprecated. use XMLDocumentBuilder instead

Marshall a Genotype instance into an XML Element representation, including its population of Chromosome instances as sub-elements. This may be useful in scenarios where representation as an entire Document is undesirable, such as when the representation of this Genotype is to be combined with other elements in a single Document.

Parameters:
a_subject - the genotype to represent as an XML element
a_xmlDocument - a Document instance that will be used to create the Element instance. Note that the element will NOT be added to the document by this method
Returns:
an Element object representing the given Genotype
Since:
1.0

getGenesFromElement

public static Gene[] getGenesFromElement(Configuration a_activeConfiguration,
                                         org.w3c.dom.Element a_xmlElement)
                                  throws ImproperXMLException,
                                         UnsupportedRepresentationException,
                                         GeneCreationException
Unmarshall a Chromosome instance from a given XML Element representation.

Parameters:
a_activeConfiguration - current Configuration object
a_xmlElement - the XML Element representation of the Chromosome
Returns:
a new Chromosome instance setup with the data from the XML Element representation
Throws:
ImproperXMLException - if the given Element is improperly structured or missing data
UnsupportedRepresentationException - if the actively configured Gene implementation does not support the string representation of the alleles used in the given XML document
GeneCreationException - if there is a problem creating or populating an Gene instance
Since:
1.0

getChromosomeFromElement

public static Chromosome getChromosomeFromElement(Configuration a_activeConfiguration,
                                                  org.w3c.dom.Element a_xmlElement)
                                           throws ImproperXMLException,
                                                  InvalidConfigurationException,
                                                  UnsupportedRepresentationException,
                                                  GeneCreationException
Unmarshall a Chromosome instance from a given XML Element representation.

Parameters:
a_activeConfiguration - The current active Configuration object that is to be used during construction of the Chromosome.
a_xmlElement - The XML Element representation of the Chromosome.
Returns:
A new Chromosome instance setup with the data from the XML Element representation.
Throws:
ImproperXMLException - if the given Element is improperly structured or missing data.
InvalidConfigurationException - if the given Configuration is in an inconsistent state.
UnsupportedRepresentationException - if the actively configured Gene implementation does not support the string representation of the alleles used in the given XML document.
GeneCreationException - if there is a problem creating or populating an Gene instance.
Since:
1.0

getGenotypeFromElement

public static Genotype getGenotypeFromElement(Configuration a_activeConfiguration,
                                              org.w3c.dom.Element a_xmlElement)
                                       throws ImproperXMLException,
                                              InvalidConfigurationException,
                                              UnsupportedRepresentationException,
                                              GeneCreationException
Unmarshall a Genotype instance from a given XML Element representation. Its population of Chromosomes will be unmarshalled from the Chromosome sub-elements.

Parameters:
a_activeConfiguration - The current active Configuration object that is to be used during construction of the Genotype and Chromosome instances.
a_xmlElement - The XML Element representation of the Genotype
Returns:
A new Genotype instance, complete with a population of Chromosomes, setup with the data from the XML Element representation.
Throws:
ImproperXMLException - if the given Element is improperly structured or missing data.
InvalidConfigurationException - if the given Configuration is in an inconsistent state.
UnsupportedRepresentationException - if the actively configured Gene implementation does not support the string representation of the alleles used in the given XML document.
GeneCreationException - if there is a problem creating or populating an Gene instance.
Since:
1.0

getGenotypeFromDocument

public static Genotype getGenotypeFromDocument(Configuration a_activeConfiguration,
                                               org.w3c.dom.Document a_xmlDocument)
                                        throws ImproperXMLException,
                                               InvalidConfigurationException,
                                               UnsupportedRepresentationException,
                                               GeneCreationException
Unmarshall a Genotype instance from a given XML Document representation. Its population of Chromosomes will be unmarshalled from the Chromosome sub-elements.

Parameters:
a_activeConfiguration - The current active Configuration object that is to be used during construction of the Genotype and Chromosome instances.
a_xmlDocument - The XML Document representation of the Genotype.
Returns:
A new Genotype instance, complete with a population of Chromosomes, setup with the data from the XML Document representation.
Throws:
ImproperXMLException - if the given Document is improperly structured or missing data.
InvalidConfigurationException - if the given Configuration is in an inconsistent state.
UnsupportedRepresentationException - if the actively configured Gene implementation does not support the string representation of the alleles used in the given XML document.
GeneCreationException - if there is a problem creating or populating an Gene instance.
Since:
1.0

getChromosomeFromDocument

public static Chromosome getChromosomeFromDocument(Configuration a_activeConfiguration,
                                                   org.w3c.dom.Document a_xmlDocument)
                                            throws ImproperXMLException,
                                                   InvalidConfigurationException,
                                                   UnsupportedRepresentationException,
                                                   GeneCreationException
Unmarshall a Chromosome instance from a given XML Document representation. Its genes will be unmarshalled from the gene sub-elements.

Parameters:
a_activeConfiguration - The current active Configuration object that is to be used during construction of the Chromosome instances.
a_xmlDocument - The XML Document representation of the Chromosome.
Returns:
A new Chromosome instance setup with the data from the XML Document representation.
Throws:
ImproperXMLException - if the given Document is improperly structured or missing data.
InvalidConfigurationException - if the given Configuration is in an inconsistent state.
UnsupportedRepresentationException - if the actively configured Gene implementation does not support the string representation of the alleles used in the given XML document.
GeneCreationException - if there is a problem creating or populating an Gene instance.
Since:
1.0

readFile

public static org.w3c.dom.Document readFile(java.io.File file)
                                     throws java.io.IOException,
                                            org.xml.sax.SAXException
Reads in an XML file and returns a Document object

Parameters:
file - the file to be read in
Returns:
Document
Throws:
java.io.IOException
SAXException
Since:
2.0

writeFile

public static void writeFile(org.w3c.dom.Document doc,
                             java.io.File file)
                      throws java.io.IOException
Writes an XML file from a Document object

Parameters:
doc - the Document object to be written to file
file - the file to be written
Throws:
java.io.IOException
Since:
2.0

JGAP