ix.util.xml
Class XMLLoader

java.lang.Object
  extended by ix.util.xml.XMLLoader

public class XMLLoader
extends java.lang.Object

A utility for obtaining XML documents, or objects represented as XML, from files or URLs, conducting dialogs as required. Some non-XML syntaxes for objects can also be handled and the objects can be converted to XML documents if desired.

See Also:
XMLTreeEditFrame

Field Summary
protected  java.lang.Class desiredResultClass
           
protected  javax.swing.JFileChooser fileChooser
           
protected  java.awt.Component frame
           
protected  java.io.File libDir
           
protected  XMLTranslator xmlt
           
 
Constructor Summary
XMLLoader(java.awt.Component frame)
           
XMLLoader(java.awt.Component frame, java.lang.Class desiredResultClass)
           
 
Method Summary
protected  java.io.File chooseFileToRead()
          Asks the user to choose a file.
 XMLTranslator getXMLTranslator()
          Returns the XMLTranslator that is used by the loadObject method to convert a JDOM document to an object.
 org.jdom.Document loadDocument()
          Reads a JDOM Document from a file selected by the user, conducting all necessary dialogs along the way.
 java.lang.Object loadObject()
          Reads an object from a file selected by the user, conducting all necessary dialogs along the way.
 javax.swing.JFileChooser makeFileChooser()
          Constructs a suitable file-chooser for this XMLLoader's desired result class.
protected  org.jdom.Document readDocumentFrom(java.io.File file)
          Converts the contents of the specified file to a JDOM Document.
protected  java.lang.Object readObjectFrom(java.io.File file)
          Converts the contents of the specified file to an object.
 void setXMLTranslator(XMLTranslator xmlt)
          Sets the XMLTranslator that is used by the loadObject method to convert a JDOM document to an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

libDir

protected java.io.File libDir

xmlt

protected XMLTranslator xmlt

fileChooser

protected javax.swing.JFileChooser fileChooser

frame

protected java.awt.Component frame

desiredResultClass

protected java.lang.Class desiredResultClass
Constructor Detail

XMLLoader

public XMLLoader(java.awt.Component frame)

XMLLoader

public XMLLoader(java.awt.Component frame,
                 java.lang.Class desiredResultClass)
Method Detail

getXMLTranslator

public XMLTranslator getXMLTranslator()
Returns the XMLTranslator that is used by the loadObject method to convert a JDOM document to an object.


setXMLTranslator

public void setXMLTranslator(XMLTranslator xmlt)
Sets the XMLTranslator that is used by the loadObject method to convert a JDOM document to an object.


loadObject

public java.lang.Object loadObject()
Reads an object from a file selected by the user, conducting all necessary dialogs along the way. It repeatedly asks the user to select a file until either the Document has been successfully read or the user decides to cancel the operation. The user is informed of any exceptions thrown while attempting to read, and "success" means that no exceptions were thrown.

Returns:
an Object, or else null if the user cancels.
See Also:
readObjectFrom(File)

readObjectFrom

protected java.lang.Object readObjectFrom(java.io.File file)
                                   throws java.io.IOException
Converts the contents of the specified file to an object.

Throws:
java.io.IOException

loadDocument

public org.jdom.Document loadDocument()
Reads a JDOM Document from a file selected by the user, conducting all necessary dialogs along the way. It repeatedly asks the user to select a file until either the Document has been successfully read or the user decides to cancel the operation. The user is informed of any exceptions thrown while attempting to read, and "success" means that no exceptions were thrown.

Returns:
a JDOM Document, or else null if the user cancels.
See Also:
readDocumentFrom(File)

readDocumentFrom

protected org.jdom.Document readDocumentFrom(java.io.File file)
                                      throws java.io.IOException
Converts the contents of the specified file to a JDOM Document. In addition to XML files, it is possible to read other syntaxes. However, a non-XML file is first read as an object by readObjectFrom(File) and then converted to a Document.

Throws:
java.io.IOException

chooseFileToRead

protected java.io.File chooseFileToRead()
Asks the user to choose a file. Returns null if the user cancels.


makeFileChooser

public javax.swing.JFileChooser makeFileChooser()
Constructs a suitable file-chooser for this XMLLoader's desired result class.