TopoWeb Commons API

org.topoweb.xml
Class Factory

java.lang.Object
  |
  +--org.topoweb.xml.Factory

public class Factory
extends java.lang.Object

Intended an efficient, thread-safe factory for XML-related objects.

Author:
Babak Farhang

Nested Class Summary
protected static class Factory.Components
          Encapsulates the XML component factories shipped with the runtime.
 
Field Summary
protected  java.lang.ThreadLocal threadLocal
          The instance's thread-local.
 
Constructor Summary
Factory()
          Creates a new instance.
 
Method Summary
 javax.xml.parsers.DocumentBuilder getDocumentBuilder()
          Always returns the same DocumentBuilder instance in any given thread.
 javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()
          Always returns the same DocumentBuilderFactory instance in any given thread.
static Factory getGlobalInstance()
          Returns the global instance.
 javax.xml.transform.TransformerFactory getTransformerFactory()
          Always returns the same TransformerFactory instance in any given thread.
protected  Factory.Components newComponents()
          Returns a container for the thread-specific components that will be accessed.
static void setGlobalInstance(Factory global)
          Sets the global instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadLocal

protected final java.lang.ThreadLocal threadLocal
The instance's thread-local. Note that invoking threadLocal.set(Object) has no effect on this instance. Invoking threadLocal.get(), always returns a Factory.Components instance.

See Also:
newComponents()
Constructor Detail

Factory

public Factory()
Creates a new instance. Subclasses may add accessors by overriding the newComponents method.

Method Detail

setGlobalInstance

public static void setGlobalInstance(Factory global)
Sets the global instance. The value null is taken to mean an instance of this class.

Implementation Note:

Not protected against concurrent access with the getGlobalInstance method.

Parameters:
global - the new global instance
See Also:
getGlobalInstance()

getGlobalInstance

public static Factory getGlobalInstance()
Returns the global instance.

Returns:
the global instance
See Also:
setGlobalInstance(Factory)

newComponents

protected Factory.Components newComponents()
Returns a container for the thread-specific components that will be accessed. The value returned by threadLocal.initialValue() is the return value of this method. Thus overriding this method, effectively overrides the initialValue() method of the internal ThreadLocal instance.

Returns:
a container for the thread-specific components

getTransformerFactory

public javax.xml.transform.TransformerFactory getTransformerFactory()
Always returns the same TransformerFactory instance in any given thread.

Returns:
a thread-specific TransformerFactory

getDocumentBuilderFactory

public javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()
                                                                   throws javax.xml.parsers.ParserConfigurationException
Always returns the same DocumentBuilderFactory instance in any given thread.

Returns:
a thread-specific DocumentBuilderFactory
javax.xml.parsers.ParserConfigurationException

getDocumentBuilder

public javax.xml.parsers.DocumentBuilder getDocumentBuilder()
                                                     throws javax.xml.parsers.ParserConfigurationException
Always returns the same DocumentBuilder instance in any given thread.

Returns:
a thread-specific DocumentBuilder
javax.xml.parsers.ParserConfigurationException

TopoWeb Commons API

Copyright (C) 2002 Babak Farhang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.