SK.gnome.dwarf.config
Class XMLConfiguration

java.lang.Object
  extended bySK.gnome.dwarf.config.XMLConfiguration

public class XMLConfiguration
extends java.lang.Object

Provides a XML-based tool for constructing and configuring server applications.

A Dwarf-based application consisting of group of servers and services can be described using the XML language. This class then loads and parses the given XML configuration data and instantiates and configures the whole server application via the getService() method.

A sample code using the XMLConfiguration class:

 public static void main(String[] args) throws Exception
 { 
   // load the XML configuration data 
   XMLConfiguration config = new XMLConfiguration("file:conf/tutorial.xml");

   // instantiate the server application 
   MainServer s = (MainServer)config.getService();
  
   // initialize and start the application 
   s.init(null);
   s.start();
 }
 

See Also:
XML Configuration Guide

Constructor Summary
XMLConfiguration(org.w3c.dom.Document document)
          Creates a new XMLConfiguration instance.
XMLConfiguration(java.lang.String url)
          Creates a new XMLConfiguration instance.
 
Method Summary
 org.w3c.dom.Document getDocument()
          Returns the XML configuration data as a DOM object.
 int getObjectCount()
          Returns the total number of services created by the getService() method.
 Service getService()
          Creates a service instance from the XML configuration data.
static void setAttribute(java.lang.Object obj, java.lang.String name, java.lang.String value)
          Sets the object's attribute.
static void setValidation(boolean value)
          Enables or disables validation of the XML data.
static void setVerbosity(boolean value)
          Enables or disables verbose operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLConfiguration

public XMLConfiguration(java.lang.String url)
                 throws XMLConfigurationException
Creates a new XMLConfiguration instance.

It loads and parses the given XML document. If the validation is enabled, the XML document will be validated against its DTD. Validation is enabled by default and can be turned on or off via the static setValidation(boolean) method.

Parameters:
url - the URL of the XML configuration data
Throws:
XMLConfigurationException - if an error occured during the loading of the XML data

XMLConfiguration

public XMLConfiguration(org.w3c.dom.Document document)
                 throws XMLConfigurationException
Creates a new XMLConfiguration instance.

The document argument must reference a valid XML configuration data as described by its DTD.

Parameters:
document - the XML configuration data
Throws:
XMLConfigurationException - if an error occured
Method Detail

getService

public Service getService()
                   throws XMLConfigurationException
Creates a service instance from the XML configuration data.

It returns a service instance referenced by the top-level <service> tag in the XML configuration document.

Returns:
the service instance
Throws:
XMLConfigurationException - if an error occured

setAttribute

public static void setAttribute(java.lang.Object obj,
                                java.lang.String name,
                                java.lang.String value)
                         throws java.lang.Exception
Sets the object's attribute.

This method sets the object's attribute through the traditional setter method. A call to setAttribute(service, "attribute", "value") is valid if the object referenced by the service argument declares a public setAttribute method with an argument of one of the following types:

Attributes of java.lang.String[] type may utilize a special feature, which is a check against the predefined possible values. If an attribute is named myExtensions, for example, the corresponding setter method would have signature setMyExtensions(String[]). In addition, if the given class declares another public method getAllMyExtensions() with the return type of String[], this string array will be regarded as a set of all possible string values, and the setAttribute method won't allow to set a value, which is not present in this array. The checking is always case insensitive.

Parameters:
obj - the object
name - the attribute name
value - the attribute value
Throws:
java.lang.Exception - if the setting fails

setVerbosity

public static void setVerbosity(boolean value)
Enables or disables verbose operation.

If enabled, a detailed information about every XML element processed by the getService() method is printed to the standard output stream.

The verbose operation is disabled by default.

Parameters:
value - true to enable verbose operation
See Also:
getService()

setValidation

public static void setValidation(boolean value)
Enables or disables validation of the XML data.

If enabled, the XML document will be validated against its DTD.

The validation is enabled by default.

Parameters:
value - true to enable validation

getDocument

public org.w3c.dom.Document getDocument()
Returns the XML configuration data as a DOM object.

Returns:
the XML document

getObjectCount

public int getObjectCount()
Returns the total number of services created by the getService() method.

Returns:
the number of objects
See Also:
getService()


Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.