net.directj.jlogger
Class XmlConfigurator

java.lang.Object
  |
  +--net.directj.jlogger.XmlConfigurator
All Implemented Interfaces:
Configurator

public class XmlConfigurator
extends java.lang.Object
implements Configurator

This class is used to configure JLogger from an XML file, using DOM. The XML configuration file must follow the jlogger.dtd, that can be found in the source.

Version:
0.3.0
Author:
CARTAPANIS Alexandre <earendil@jprolog.net>

Field Summary
private static java.lang.String CLASS_ATTR
          The class attribute string.
private  java.util.Vector currentLoggers
          The list of currently parsed logger.
private  javax.xml.parsers.DocumentBuilder docBuilder
          The document builder.
private static java.lang.String FORMATTER_TAG
          The formatter tag string.
private static java.lang.String LEVEL_ATTR
          The level attribute string.
private static java.lang.String LOGGER_TAG
          The logger tag string.
private static java.lang.String MANAGER_TAG
          The manager tag string.
private static java.lang.String NAME_ATTR
          The name attribute string.
private static java.lang.String NAMESPACE
          The namespace attribute string.
private static java.lang.String OUTPUT_TAG
          The output tag string.
private static java.lang.String PARAM_ATTR
          The param attribute string.
private static java.lang.String ROOT_TAG
          The root tag string.
 
Constructor Summary
XmlConfigurator()
          Creates a new jlogger configurator.
 
Method Summary
private  void addLogManager(java.util.Vector _loggers, java.lang.String _level, java.lang.String _class, java.lang.String _param)
          Adds a LogManager to the specified logger, using the _class and _param to create it.
private  void addLogManager(java.util.Vector _loggers, java.lang.String _level, java.lang.String _formatterClass, java.lang.String _formatterParam, java.lang.String _outputClass, java.lang.String _outputParam)
          Adds a LogManager to the specified logger, using the specified formatter and output.
 void configure(java.io.InputStream _input)
          Configures the JLogger tools, using an input stream (can be XML or Property file, or anything else, depending of the Configurator implementation you use).
private  java.lang.Object createObject(java.lang.String _class, java.lang.Object[] _construcArgs)
          Creates an object using the specified class name and the specified parameter array.
private  java.lang.String[] parseFormatter(org.w3c.dom.Node _formatter)
          Parses a formatter node of a jlogger config file.
private  void parseLogger(org.w3c.dom.Node _logger)
          Parses a logger node of a jlogger config file.
private  void parseManager(org.w3c.dom.Node _manager)
          Parses a manager node of a jlogger config file.
private  java.lang.String[] parseOutput(org.w3c.dom.Node _output)
          Parses an output node of a jlogger config file.
private  java.lang.Object[] parseParam(java.lang.String _lvl, java.lang.String _args)
          Parses a list of parameter and return it, as a list of object.
private  void parseRoot(org.w3c.dom.Node _root)
          Parses a root node of a jlogger config file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_TAG

private static final java.lang.String ROOT_TAG
The root tag string.

See Also:
Constant Field Values

LOGGER_TAG

private static final java.lang.String LOGGER_TAG
The logger tag string.

See Also:
Constant Field Values

MANAGER_TAG

private static final java.lang.String MANAGER_TAG
The manager tag string.

See Also:
Constant Field Values

FORMATTER_TAG

private static final java.lang.String FORMATTER_TAG
The formatter tag string.

See Also:
Constant Field Values

OUTPUT_TAG

private static final java.lang.String OUTPUT_TAG
The output tag string.

See Also:
Constant Field Values

NAME_ATTR

private static final java.lang.String NAME_ATTR
The name attribute string.

See Also:
Constant Field Values

LEVEL_ATTR

private static final java.lang.String LEVEL_ATTR
The level attribute string.

See Also:
Constant Field Values

CLASS_ATTR

private static final java.lang.String CLASS_ATTR
The class attribute string.

See Also:
Constant Field Values

PARAM_ATTR

private static final java.lang.String PARAM_ATTR
The param attribute string.

See Also:
Constant Field Values

NAMESPACE

private static final java.lang.String NAMESPACE
The namespace attribute string.

See Also:
Constant Field Values

docBuilder

private javax.xml.parsers.DocumentBuilder docBuilder
The document builder.


currentLoggers

private java.util.Vector currentLoggers
The list of currently parsed logger.

Constructor Detail

XmlConfigurator

public XmlConfigurator()
Creates a new jlogger configurator.

Method Detail

configure

public void configure(java.io.InputStream _input)
Configures the JLogger tools, using an input stream (can be XML or Property file, or anything else, depending of the Configurator implementation you use). Using an InputStream allow to easely use a resource, a file or a network to configure the tool.

Specified by:
configure in interface Configurator
Parameters:
_input - The input stream to use for configuration.

parseRoot

private void parseRoot(org.w3c.dom.Node _root)
                throws org.w3c.dom.DOMException
Parses a root node of a jlogger config file.

Parameters:
_root - The root node.
Throws:
org.w3c.dom.DOMException - If an exception occurs while analysing (in most case, because the document is mal-formed).

parseLogger

private void parseLogger(org.w3c.dom.Node _logger)
                  throws org.w3c.dom.DOMException
Parses a logger node of a jlogger config file.

Parameters:
_logger - The logger node.
Throws:
org.w3c.dom.DOMException - If an exception occurs while analysing (in most case, because the document is mal-formed).

parseManager

private void parseManager(org.w3c.dom.Node _manager)
                   throws org.w3c.dom.DOMException
Parses a manager node of a jlogger config file.

Parameters:
_manager - The manager node.
Throws:
org.w3c.dom.DOMException - If an exception occurs while analysing (in most case, because the document is mal-formed).

parseOutput

private java.lang.String[] parseOutput(org.w3c.dom.Node _output)
                                throws org.w3c.dom.DOMException
Parses an output node of a jlogger config file.

Parameters:
_output - The output node.
Returns:
String[] - A string array where array[0] is the class name and array[i] is the constructor parameters.
Throws:
org.w3c.dom.DOMException - If an exception occurs while analysing (in most case, because the document is mal-formed).

parseFormatter

private java.lang.String[] parseFormatter(org.w3c.dom.Node _formatter)
                                   throws org.w3c.dom.DOMException
Parses a formatter node of a jlogger config file.

Parameters:
_formatter - The formatter node.
Returns:
String[] - A string array where array[0] is the class name and array[i] is the constructor parameters.
Throws:
org.w3c.dom.DOMException - If an exception occurs while analysing (in most case, because the document is mal-formed).

addLogManager

private void addLogManager(java.util.Vector _loggers,
                           java.lang.String _level,
                           java.lang.String _class,
                           java.lang.String _param)
Adds a LogManager to the specified logger, using the _class and _param to create it.

Parameters:
_loggers - The logger list to append the LogManager.
_level - The LogManager level, as a string.
_class - The LogManager class.
_param - The LogManager constructor param.

addLogManager

private void addLogManager(java.util.Vector _loggers,
                           java.lang.String _level,
                           java.lang.String _formatterClass,
                           java.lang.String _formatterParam,
                           java.lang.String _outputClass,
                           java.lang.String _outputParam)
Adds a LogManager to the specified logger, using the specified formatter and output.

Parameters:
_loggers - The logger list to append the LogManager.
_level - The LogManager level, as a string.
_formatterClass - The Formatter class.
_formatterParam - The Formatter constructor param.
_outputClass - The Output class.
_outputParam - The Output constructor param.

parseParam

private java.lang.Object[] parseParam(java.lang.String _lvl,
                                      java.lang.String _args)
Parses a list of parameter and return it, as a list of object. Only primitive type can be parsed (int, double, boolea, and string).

Parameters:
_lvl - Thelevel, as a string, that will be converted to an Integer and added to the list of object. Ignored if null.
_args - The list of parameter, delimited with the ',' char.
Returns:
Object[] - The list of Object.

createObject

private java.lang.Object createObject(java.lang.String _class,
                                      java.lang.Object[] _construcArgs)
Creates an object using the specified class name and the specified parameter array.

Parameters:
_class - The class name (will be used to create the class, so don't forget the package).
_construcArgs - The constructor's array of parameter.
Returns:
Object - The created object, an instance of the _class class instancied with the _construcArgs parameters.


Copyright © 2002 CARTAPANIS Alexandre
This page was last updated on May 10 2003