FileDocCategorySizeDatePackage
XmlRpcConfiguration.javaAPI DocExample6483Sat Jun 03 14:54:06 BST 2000com.oreilly.xml

XmlRpcConfiguration

public class XmlRpcConfiguration extends Object
XmlRpcConfiguration is a utility class that will load configuration information for XML-RPC servers and clients to use.
author
Brett McLaughlin
version
1.0

Fields Summary
private InputStream
in
The stream to read the XML configuration from
private int
portNumber
Port number server runs on
private String
hostname
Hostname server runs on
private String
driverClass
SAX Driver Class to load
private Hashtable
handlers
Handlers to register in XML-RPC server
Constructors Summary
public XmlRpcConfiguration(String filename)

This will set a filename to read configuration information from.

param
filename String name of XML configuration file.


        this(new FileInputStream(filename));
    
public XmlRpcConfiguration(InputStream in)

This will set a filename to read configuration information from.

param
in InputStream to read configuration information from.


        this.in = in;
        portNumber = 0;
        hostname = "";
        handlers = new Hashtable();

        // Parse the XML configuration information
        parseConfiguration();
    
Methods Summary
public java.lang.StringgetDriverClass()

This returns the SAX driver class to load.

return
String - name of SAX driver class.

        return driverClass;
    
public java.util.HashtablegetHandlers()

This returns the handlers the server should register.

return
Hashtable of handlers.

        return handlers;
    
public java.lang.StringgetHostname()

This returns the hostname the server listens on.

return
String - hostname of server.

        return hostname;
    
public intgetPortNumber()

This returns the port number the server listens on.

return
int - number of server port.

        return portNumber;
    
private voidparseConfiguration()

Parse the XML configuration information and make it available to clients.

throws
IOException when errors occur.


        try {
            // Request DOM Implementation and Xerces Parser
            Builder builder =
                new DOMBuilder("org.jdom.adapters.XercesDOMAdapter");

            // Get the Configuration Document, with validation
            Document doc = builder.build(in);

            // Get the root element
            Element root = doc.getRootElement();

            // Get the JavaXML namespace
            Namespace ns = Namespace.getNamespace("JavaXML",
                           "http://www.oreilly.com/catalog/javaxml/");

            // Load the hostname, port, and handler class
            hostname = root.getChild("hostname", ns).getContent();
            driverClass = root.getChild("parserClass", ns).getContent();
            portNumber =
                Integer.parseInt(root.getChild("port", ns).getContent());

            // Get the handlers
            List handlerElements =
                root.getChild("xmlrpc-server", ns)
                    .getChild("handlers", ns)
                    .getChildren("handler", ns);

            Iterator i = handlerElements.iterator();
            while (i.hasNext()) {
                Element current = (Element)i.next();
                handlers.put(current.getChild("identifier", ns).getContent(),
                             current.getChild("class", ns).getContent());
            }
        } catch (JDOMException e) {
            throw new IOException(e.getMessage());
        }