|
Nux 1.6 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object nux.xom.pool.XSLTransformPool
public class XSLTransformPool
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.
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 |
---|
public static final XSLTransformPool GLOBAL_POOL
Constructor Detail |
---|
public XSLTransformPool()
public XSLTransformPool(PoolConfig config, XSLTransformFactory factory)
config
- the configuration to usefactory
- the factory creating new XSLTransform instances on cache missesMethod Detail |
---|
public XSLTransform getTransform(Document stylesheet) throws XSLException
XSLTransform
for the given stylesheet.
stylesheet
- the stylesheet to compile
XSLException
- if the XSLTransform can't be created, e.g. because of an XSL
syntax error.public XSLTransform getTransform(File stylesheet) throws XSLException, ParsingException, IOException
XSLTransform
for the given stylesheet.
stylesheet
- the stylesheet to compile
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.public XSLTransform getTransform(ResourceResolver resolver, String resourceName, URI baseURI) throws XSLException, ParsingException, IOException, MissingResourceException
XSLTransform
for the input stream obtained from
resolving the given resourceName against the given resolver.
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.
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 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |