org.apache.naming.config
Class XmlConfigurator

java.lang.Object
  extended byorg.apache.naming.config.XmlConfigurator

public class XmlConfigurator
extends java.lang.Object

Configure an in-memory JNDI implementation using an XML configuration file.

Multiple named contexts can be configured, and names configured in the file can be made relative to a base name. Use the "base" attribute of the context element in the xml config to specify a base name and use the "name" attribute to specify an external name for the context, which will be its key in ContextBindings. Configurations added using loadConfiguration(java.io.InputStream) add / update data for contexts already defined. To destroy contexts already defined, use either destroyInitialContext(), which destroys the "anonymous" context (what new InitialContext() returns); or destroyAll(), which destroys all defined contexts (named or "anonymous").

Version:
$Id: XmlConfigurator.java,v 1.2 2003/12/01 02:02:45 brett Exp $
Author:
Brett Porter

Constructor Summary
XmlConfigurator()
           
 
Method Summary
static void destroyAll()
          Destroys all named contexts as well as "anonymous" context.
static void destroyInitialContext()
          Destroys "anonymous" initial context, destoying subcontexts recursively.
static void loadConfiguration(java.io.InputStream inputFile)
          Loads xml configuration data from inputFile.
protected static void makeContexts(Config.Naming naming)
          Creates naming contexts based on the configuration data in the input Config.Naming structure.
protected static Config.Naming parseFile(java.io.InputStream inputFile)
          Parses input file, returning a Config.Naming structure.
protected static void setSystemProperties()
          Sets System JNDI properties.
static void setupInitialContext()
          Sets up initial context using org.apache.naming.NamingContextFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlConfigurator

public XmlConfigurator()
Method Detail

setupInitialContext

public static void setupInitialContext()
                                throws javax.naming.NamingException
Sets up initial context using org.apache.naming.NamingContextFactory.

Also creates "env" subcontext in "java:comp" namespace.

Throws:
javax.naming.NamingException - if a NamingException occurs.

destroyInitialContext

public static void destroyInitialContext()
                                  throws javax.naming.NamingException
Destroys "anonymous" initial context, destoying subcontexts recursively.

Throws:
javax.naming.NamingException - if a NamingException occurs

destroyAll

public static void destroyAll()
                       throws javax.naming.NamingException
Destroys all named contexts as well as "anonymous" context.

Throws:
javax.naming.NamingException - if a naming exception occurs

setSystemProperties

protected static void setSystemProperties()
Sets System JNDI properties.


parseFile

protected static Config.Naming parseFile(java.io.InputStream inputFile)
                                  throws ParseException
Parses input file, returning a Config.Naming structure.

Parameters:
inputFile - file to be parsed
Returns:
Config.Naming representing the config data in the file
Throws:
ParseException - if an error occurs parsing the file

makeContexts

protected static void makeContexts(Config.Naming naming)
                            throws javax.naming.NamingException
Creates naming contexts based on the configuration data in the input Config.Naming structure.

Uses update semantics -- i.e., contexts / entries that already exist are updated with the data in the input configuration.

Parameters:
naming - Config.Naming structure containing the context configuration data
Throws:
javax.naming.NamingException - if a NamingException occurs

loadConfiguration

public static void loadConfiguration(java.io.InputStream inputFile)
                              throws javax.naming.NamingException,
                                     ParseException
Loads xml configuration data from inputFile. Uses update semantics -- i.e., does not clear and create new context(s) and bindings, but adds to current definitions, overwriting previous configuration when contexts or bindings already exist. To clear existing configuration, use destroyInitialContext() or destroyAll().

Parameters:
inputFile - input xml configuration file
Throws:
javax.naming.NamingException - if a NamingException occurs.
ParseException - if an error occurs parsing the configuration file.


Copyright © 2003-2005 Apache Software Foundation. All Rights Reserved.