cometa.translator
Class Translator

java.lang.Object
  extended by cometa.translator.Translator

public class Translator
extends java.lang.Object

This class translates the metadta in form of an XML file into the corresponding Java object. It uses the JAXB library (for more information, see the JAXB documentation).


Constructor Summary
Translator()
          It creates a new instance of Translator.
 
Method Summary
static java.io.ByteArrayInputStream getByteInputStream(org.xmldb.api.modules.XMLResource xmlResource)
          The same as
static org.jdom.Document getDocumentTree(java.io.File xmlFile)
          This method returns a JDOM document tree, given as input an XML file.
static org.jdom.Document getDocumentTree(org.xmldb.api.modules.XMLResource xmlResource)
          This method returns a JDOM document tree, given as input an XMLResource object (which is a format used by the JAXB architecture).
static java.io.InputStream getInputStream(org.xmldb.api.modules.XMLResource xmlResource)
          This methods returns an InputStream corresponding to a given XMLResource.
static java.io.InputStream getInputStreamFromFile(java.io.File xmlFile)
          This methods returns an InputStream corresponding to a given XML File.
static java.io.File writeToFile(java.lang.String filename, java.lang.String content)
          This method writes a String to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Translator

public Translator()
It creates a new instance of Translator.

Method Detail

writeToFile

public static java.io.File writeToFile(java.lang.String filename,
                                       java.lang.String content)
This method writes a String to a file.

Parameters:
filename - The filename (containing the absolute path!) to where the file has to be written.
content - The content to write into the file.
Returns:
The created File or null if something went wrong.

getDocumentTree

public static org.jdom.Document getDocumentTree(java.io.File xmlFile)
                                         throws org.jdom.JDOMException,
                                                java.io.IOException
This method returns a JDOM document tree, given as input an XML file.

Parameters:
xmlFile - The XML input File.
Returns:
It returns the document corresponding to the XML input file.
Throws:
org.jdom.JDOMException - Exception thrown in case of a JDOM error.
java.io.IOException - Exception thrown if the XML input file cannot be found.

getDocumentTree

public static org.jdom.Document getDocumentTree(org.xmldb.api.modules.XMLResource xmlResource)
                                         throws org.jdom.JDOMException,
                                                java.io.IOException
This method returns a JDOM document tree, given as input an XMLResource object (which is a format used by the JAXB architecture).

Parameters:
xmlResource - The XMLResource for which the you want to recieve the document tree.
Returns:
The document tree for the input resource.
Throws:
org.jdom.JDOMException - Exception thrown if a JDOM error occurs.
java.io.IOException - Exception thrown if an error occurs while converting the input resource to a ByteArray.

getInputStream

public static java.io.InputStream getInputStream(org.xmldb.api.modules.XMLResource xmlResource)
                                          throws org.jdom.JDOMException,
                                                 java.io.IOException
This methods returns an InputStream corresponding to a given XMLResource. Notice that it does not write the content of the XMLResource to a temporary file, hence it speeds up the operation.

Parameters:
xmlResource - The input resource for which you want to receive the input stream.
Returns:
The input stream for the XML resource.
Throws:
org.jdom.JDOMException - Exception thrown if a JDOM error occurs.
java.io.IOException - Exception thrown if an error occurs while converting the input resource to a ByteArray.

getInputStreamFromFile

public static java.io.InputStream getInputStreamFromFile(java.io.File xmlFile)
                                                  throws java.io.IOException
This methods returns an InputStream corresponding to a given XML File.

Parameters:
xmlFile - The input XML file for which you want to receive the input stream.
Returns:
The input stream corresponding to the given XML file.
Throws:
java.io.IOException - Exception thrown if the XML input file cannot be found.

getByteInputStream

public static java.io.ByteArrayInputStream getByteInputStream(org.xmldb.api.modules.XMLResource xmlResource)
                                                       throws org.jdom.JDOMException,
                                                              java.io.IOException
The same as
getInputStream
but it returns ByteInputStream.

Parameters:
xmlResource - The XML resource for which you want to receive the byte input stream.
Returns:
The byte input stream for the given XML resource.
Throws:
org.jdom.JDOMException - Exception thrown if a JDOM error occurs.
java.io.IOException - Exception thrown if an error occurs while converting the input resource to a ByteArray.