Thanks. This makes sense. It seems like the key part of the code is this:

            ObjectInputStream p = new ObjectInputStream(isTranslet);
            Templates templates = (Templates)p.readObject();

So this means that the compiled Translet Class implements the Templates
interface? It doesn't in the JavaDoc, so this is part of what I was missing
if it's true. 

Why read the stream, instead of just call newInstance on the Class Object,
as is done in a different example, then cast it to Templates?

On a note related to Transformer usage: I see from the docs that the
Templates object is a compiled representation of the style sheet.
Unfortunately, the compiler docs mention several XSL constructs which are
not handled (Conformance issues and Known Problems). Are these issues only
present with the Translet, or will they also manifest if I use the
TransformerFactory to obtain Templates directly from a Source?

I understand the warnings about not reusing Transformers, but if I can't
support all of the un-compiled style sheets we currently have without
reparsing them for each use (as I believe would happen if I obtained a new
Transformer from the TransformerFactory each time), I'm inclined to take the
risk. The code I am replacing already is reusing a transformer and we
haven't had any problems with it yet.

Hope this question make sense.

        easy,
        douglas d


-----Original Message-----
From: Hunter, Bryan [mailto:[EMAIL PROTECTED]
Sent: Friday, January 25, 2002 12:41 PM
To: Xalan-J-Users (E-mail)
Subject: RE: Getting a transformer from a translet. 


Douglas,

I recently had to do something very similar, except I'm using translets
wrapped in a Templates.

The approach I took was to write a factory class that holds a static HashMap
of translet name:template instance pairs. Whenever I need a transformer - I
call my method in the factory to get transformers, it checks its hashmap to
see if it already has a templates instance for the requested translet, if it
does it'll return it, otherwise it'll create one add it to the hashmap and
then return it.

I'm using this in a J2EE application and everything appears to be working
fine

Keep in mind that a Transformer is a lightweight object that tracks state
information during the transformation and that for each transformation, a
new Transformer should be created.  Because of this, I hold the Templates
instances in my static hashmap and not a Transformer.

I also have a class that build translets (Templates) that is an ANT task if
you need it.

Below is the code I wrote:  
---------

[snip]

Reply via email to