Nux 1.6

nux.xom.pool
Class XSLTransformPool

java.lang.Object
  extended by nux.xom.pool.XSLTransformPool

public class XSLTransformPool
extends Object

Efficient thread-safe pool/cache of XOM XSLTransform objects, creating and holding at most maxEntries XSLTransform objects (each representing a compiled stylesheet). On cache miss, a new XSLTransform is created via a factory, cached for future reuse, and then returned. On cache hit an XSLTransform is returned instantly. Pool eviction is based on a LRU (least recently used) policy, or if the JVM runs low on free memory.

This class helps to avoid the large overhead involved in constructing (i.e. compiling) an XSLTransform instance, in particul for complex transforms over small input XML documents. Most useful in high throughput server container environments (e.g. large-scale Peer-to-Peer messaging network infrastructures over high-bandwidth networks, scalable MOMs, etc).

Example usage (in any arbitrary thread and any arbitrary object):

     XSLTransform trans = XSLTransformPool.GLOBAL_POOL.getTransform(new File("/tmp/test.xsl"));
     Document doc = BuilderPool.GLOBAL_POOL.getBuilder(false).build(new File("/tmp/test.xml"));
     Nodes nodes = trans.transform(doc);
     for (int i=0; i < nodes.size(); i++) {
         System.out.println("node "+i+": "+nodes.get(i).toXML());
     }
 

Note: Internally uses extremely short-lived locks; the resulting potential lock contention is completely negligible.

Author:
whoschek.AT.lbl.DOT.gov, $Author: hoschek3 $

Field Summary
static XSLTransformPool GLOBAL_POOL
          A default pool (can be shared freely across threads without harm); global per class loader.
 
Constructor Summary
XSLTransformPool()
          Creates a new pool with default parameters.
XSLTransformPool(PoolConfig config, XSLTransformFactory factory)
          Creates a new pool with the given configuration that uses the given factory on cache misses.
 
Method Summary
 XSLTransform getTransform(Document stylesheet)
          Returns an XSLTransform for the given stylesheet.
 XSLTransform getTransform(File stylesheet)
          Returns an XSLTransform for the given stylesheet.
 XSLTransform getTransform(ResourceResolver resolver, String resourceName, URI baseURI)
          Returns an XSLTransform for the input stream obtained from resolving the given resourceName against the given resolver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GLOBAL_POOL

public static final XSLTransformPool GLOBAL_POOL
A default pool (can be shared freely across threads without harm); global per class loader.

Constructor Detail

XSLTransformPool

public XSLTransformPool()
Creates a new pool with default parameters.


XSLTransformPool

public XSLTransformPool(PoolConfig config,
                        XSLTransformFactory factory)
Creates a new pool with the given configuration that uses the given factory on cache misses.

Parameters:
config - the configuration to use
factory - the factory creating new XSLTransform instances on cache misses
Method Detail

getTransform

public XSLTransform getTransform(Document stylesheet)
                          throws XSLException
Returns an XSLTransform for the given stylesheet.

Parameters:
stylesheet - the stylesheet to compile
Returns:
an XSL transform
Throws:
XSLException - if the XSLTransform can't be created, e.g. because of an XSL syntax error.

getTransform

public XSLTransform getTransform(File stylesheet)
                          throws XSLException,
                                 ParsingException,
                                 IOException
Returns an XSLTransform for the given stylesheet.

Parameters:
stylesheet - the stylesheet to compile
Returns:
an XSL transform
Throws:
IOException - if an I/O error occurs while reading from the stream
ParsingException - if the stylesheet is not well-formed XML
XSLException - if the XSLTransform can't be created, e.g. because of an XSL syntax error.

getTransform

public XSLTransform getTransform(ResourceResolver resolver,
                                 String resourceName,
                                 URI baseURI)
                          throws XSLException,
                                 ParsingException,
                                 IOException,
                                 MissingResourceException
Returns an XSLTransform for the input stream obtained from resolving the given resourceName against the given resolver.

Parameters:
resolver - an object that can produce an input stream for a given resource name.
resourceName - the resource name (e.g. a path or URL)
baseURI - the (absolute) base URI of the transform (may be null) Need not be the actual URI of the resolver's stream.
Returns:
an XSL transform
Throws:
MissingResourceException - if the resolver could not find the resource (unchecked exception)
IOException - if an I/O error occurs while reading from the stream
ParsingException - if the stylesheet is not well-formed XML
XSLException - if the XSLTransform can't be created, e.g. because of an XSL syntax error.

Nux 1.6