biz.hammurapi.configx
Class XmlConfigFactory

java.lang.Object
  extended by biz.hammurapi.configx.XmlConfigFactory

public class XmlConfigFactory
extends java.lang.Object

This class instantiates Java objects from XML configuration parsed by XML Beans. This class is a counterpart and replacement for biz.hammurapi.config.DomConfigFactory

Author:
Pavel

Field Summary
static java.lang.String CONFIG_RESOURCE_PREFIX
           
static java.lang.String XML_EXTENSION
           
 
Constructor Summary
XmlConfigFactory()
           
 
Method Summary
static java.lang.Object create(biz.hammurapi.configx.xmltypes.ComponentDocument cd, java.lang.ClassLoader classLoader, java.net.URL baseURL)
           
static java.lang.Object create(java.io.Reader reader, java.lang.ClassLoader classLoader)
          Parses component document (as defined in configx.xsd) at URL and creates object from it.
static
<T> T
create(biz.hammurapi.configx.xmltypes.Typed spec, java.lang.ClassLoader classLoader, java.net.URL context)
          Instantiates object from Typed XML definition or its subclass.
static java.lang.Object create(java.net.URL configURL, java.lang.ClassLoader classLoader)
          Parses component document (as defined in configx.xsd) at URL and creates object from it.
static java.lang.ClassLoader getClassLoader(biz.hammurapi.configx.xmltypes.Path spec, java.lang.ClassLoader parent, java.net.URL context)
          Creates class loader from specification
static
<T> T
getService(java.lang.Class<T> service, java.lang.ClassLoader classLoader)
          Returns composite service.
static java.util.Hashtable<java.lang.String,java.lang.Object> instantiate(biz.hammurapi.configx.xmltypes.NamedObjectSpecification[] attributes, java.lang.ClassLoader classLoader, java.net.URL context)
          Instantiates properties from XML defintion
static java.util.Hashtable<java.lang.String,java.lang.Object> instantiate(biz.hammurapi.configx.xmltypes.Property[] properties)
          Instantiates properties from XML defintion
static
<T> java.util.Iterator<T>
loadProviders(java.lang.Class<T> service, java.lang.ClassLoader classLoader)
          Loads providers for a given service.
static void main(java.lang.String[] args)
           
static
<T> java.lang.Iterable<T>
providers(java.lang.Class<T> service, java.lang.ClassLoader classLoader)
          Loads and caches providers.
static java.lang.Object validateAndCreate(biz.hammurapi.configx.xmltypes.Typed spec, java.lang.ClassLoader classLoader, java.net.URL context)
          Validates specification and then creates object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_EXTENSION

public static final java.lang.String XML_EXTENSION
See Also:
Constant Field Values

CONFIG_RESOURCE_PREFIX

public static final java.lang.String CONFIG_RESOURCE_PREFIX
See Also:
Constant Field Values
Constructor Detail

XmlConfigFactory

public XmlConfigFactory()
Method Detail

getClassLoader

public static java.lang.ClassLoader getClassLoader(biz.hammurapi.configx.xmltypes.Path spec,
                                                   java.lang.ClassLoader parent,
                                                   java.net.URL context)
                                            throws java.net.MalformedURLException
Creates class loader from specification

Parameters:
spec - Specification. Can be null.
parent - Parent classloader. Can be null.
context - Context URL. Can be null.
Returns:
New class loader if spec is not null, or parent if it is not null or classloader used to load XmlConfigFactory class.
Throws:
java.net.MalformedURLException

validateAndCreate

public static java.lang.Object validateAndCreate(biz.hammurapi.configx.xmltypes.Typed spec,
                                                 java.lang.ClassLoader classLoader,
                                                 java.net.URL context)
                                          throws biz.hammurapi.config.ConfigurationException
Validates specification and then creates object. Use this method on top-level elements.

Parameters:
spec -
classLoader -
context -
Returns:
Throws:
biz.hammurapi.config.ConfigurationException

create

public static <T> T create(biz.hammurapi.configx.xmltypes.Typed spec,
                           java.lang.ClassLoader classLoader,
                           java.net.URL context)
                throws biz.hammurapi.config.ConfigurationException
Instantiates object from Typed XML definition or its subclass.

Parameters:
spec - Specification
classLoader - Class loader. If it is null, then factory's classloader is used.
Returns:
Throws:
biz.hammurapi.config.ConfigurationException

instantiate

public static java.util.Hashtable<java.lang.String,java.lang.Object> instantiate(biz.hammurapi.configx.xmltypes.Property[] properties)
                                                                          throws biz.hammurapi.config.ConfigurationException
Instantiates properties from XML defintion

Parameters:
property -
Returns:
Throws:
biz.hammurapi.config.ConfigurationException

instantiate

public static java.util.Hashtable<java.lang.String,java.lang.Object> instantiate(biz.hammurapi.configx.xmltypes.NamedObjectSpecification[] attributes,
                                                                                 java.lang.ClassLoader classLoader,
                                                                                 java.net.URL context)
                                                                          throws biz.hammurapi.config.ConfigurationException
Instantiates properties from XML defintion

Parameters:
property -
Returns:
Throws:
biz.hammurapi.config.ConfigurationException

main

public static void main(java.lang.String[] args)
Parameters:
args -

create

public static java.lang.Object create(java.net.URL configURL,
                                      java.lang.ClassLoader classLoader)
                               throws biz.hammurapi.config.ConfigurationException
Parses component document (as defined in configx.xsd) at URL and creates object from it.

Type Parameters:
T -
Parameters:
url -
classLoader -
Returns:
Throws:
biz.hammurapi.config.ConfigurationException

create

public static java.lang.Object create(java.io.Reader reader,
                                      java.lang.ClassLoader classLoader)
                               throws biz.hammurapi.config.ConfigurationException
Parses component document (as defined in configx.xsd) at URL and creates object from it.

Type Parameters:
T -
Parameters:
Configuration - document reader.
classLoader -
Returns:
Configured object.
Throws:
biz.hammurapi.config.ConfigurationException

create

public static java.lang.Object create(biz.hammurapi.configx.xmltypes.ComponentDocument cd,
                                      java.lang.ClassLoader classLoader,
                                      java.net.URL baseURL)
                               throws biz.hammurapi.config.ConfigurationException
Throws:
biz.hammurapi.config.ConfigurationException

loadProviders

public static <T> java.util.Iterator<T> loadProviders(java.lang.Class<T> service,
                                                      java.lang.ClassLoader classLoader)
Loads providers for a given service. Providers are loaded anew at every invocation of this method.

Type Parameters:
T -
Parameters:
service - Service class.
classLoader - Class loader
Returns:
Iterator of providers of given class.
Throws:
biz.hammurapi.config.ConfigurationException

providers

public static <T> java.lang.Iterable<T> providers(java.lang.Class<T> service,
                                                  java.lang.ClassLoader classLoader)
                                       throws biz.hammurapi.config.ConfigurationException
Loads and caches providers. If provider implements Component, then its start method is invoked after creation, and stop() method is invoked in shutdown hook.

Type Parameters:
T -
Parameters:
service -
classLoader -
Returns:
Throws:
biz.hammurapi.config.ConfigurationException

getService

public static <T> T getService(java.lang.Class<T> service,
                               java.lang.ClassLoader classLoader)
                    throws biz.hammurapi.config.ConfigurationException
Returns composite service. In order to use this method providers shall implement CompositeProvider interface.

Type Parameters:
T -
Parameters:
service -
Returns:
Throws:
biz.hammurapi.config.ConfigurationException


Copyright © 2006 Hammurapi Group. All Rights Reserved.