Methods Summary |
---|
public java.lang.String | getDriverClass()
This returns the SAX driver class to load.
return driverClass;
|
public java.util.Hashtable | getHandlers()
This returns the handlers the server should register.
return handlers;
|
public java.lang.String | getHostname()
This returns the hostname the server listens on.
return hostname;
|
public int | getPortNumber()
This returns the port number the server listens on.
return portNumber;
|
private void | parseConfiguration()
Parse the XML configuration information and
make it available to clients.
try {
// Request DOM Implementation and Xerces Parser
Builder builder =
new DOMBuilder("org.jdom.adapters.XercesDOMAdapter");
// Get the Configuration Document, with validation
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());
}
|
public synchronized void | saveConfiguration(java.lang.String filename)
This will save the current state out to the XML-RPC configuration
file.
saveConfigurationFromScratch(new FileOutputStream(filename));
|
public synchronized void | saveConfiguration(java.io.OutputStream out)
This will save the current state out to the specified
OutputStream .
try {
Element root = doc.getRootElement();
// Get the JavaXML namespace
Namespace ns = Namespace.getNamespace("JavaXML",
"http://www.oreilly.com/catalog/javaxml/");
// Update the hostname
root.getChild("hostname", ns)
.setContent(hostname);
// Update the SAX driver class
root.getChild("parserClass", ns)
.setContent(driverClass);
// Update the port number
root.getChild("port", ns)
.setContent(portNumber + "");
// Easier to remove and re-add handlers
Element handlersElement =
root.getChild("xmlrpc-server", ns)
.getChild("handlers", ns);
handlersElement.removeChildren("handler", ns);
// Add new handlers
Enumeration handlerIDs = handlers.keys();
while (handlerIDs.hasMoreElements()) {
String handlerID =
(String)handlerIDs.nextElement();
// Ensure we don't register any blank string
if (handlerID.trim().equals("")) {
continue;
}
String handlerClass =
(String)handlers.get(handlerID);
handlersElement.addChild(
new Element("handler", ns)
.addChild(
new Element("identifier", ns)
.setContent(handlerID))
.addChild(
new Element("class", ns)
.setContent(handlerClass))
);
}
// Output the document, use standard formatter
XMLOutputter fmt = new XMLOutputter();
fmt.output(doc, out);
} catch (JDOMException e) {
// Log an error
throw new IOException(e.getMessage());
}
|
public synchronized void | saveConfigurationFromScratch(java.io.OutputStream out)
This will save the current state out to the specified
OutputStream .
// Get the JavaXML namespace
Namespace ns = Namespace.getNamespace("JavaXML",
"http://www.oreilly.com/catalog/javaxml/");
// Create the root element
Element root = new Element("xmlrpc-config", ns);
Document doc = new Document(root);
doc.setDocType(new DocType("JavaXML:xmlrpc-config",
"DTD/XmlRpc.dtd"));
root.addChild(new Element("hostname", ns)
.setContent(hostname))
.addChild(new Element("port", ns)
.addAttribute("type", "unprotected")
.setContent(portNumber + ""))
.addChild(new Element("parserClass", ns)
.setContent(driverClass));
Element handlersElement = new Element("handlers", ns);
Enumeration e = handlers.keys();
while (e.hasMoreElements()) {
String handlerID = (String)e.nextElement();
String handlerClass = (String)handlers.get(handlerID);
handlersElement.addChild(new Element("handler", ns)
.addChild(new Element("identifier", ns)
.setContent(handlerID))
.addChild(new Element("class", ns)
.setContent(handlerClass))
);
}
root.addChild(new Element("xmlrpc-server", ns)
.addChild(handlersElement));
// Output the document, use standard formatter
XMLOutputter fmt = new XMLOutputter();
fmt.output(doc, out);
|
public void | setDriverClass(java.lang.String driverClass)
This will set the driver class for parsing.
this.driverClass = driverClass;
|
public void | setHandlers(java.util.Hashtable handlers)
This will set the handlers to register.
this.handlers = handlers;
|
public void | setHostname(java.lang.String hostname)
This will set the hostname for the server to listen to.
this.hostname = hostname;
|
public void | setPortNumber(int portNumber)
This will set the port number to listen to.
this.portNumber = portNumber;
|