A SAX filter and "The TransformerHandler is not serially reusable.The startDocument() method must be called once only." exception

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

A SAX filter and "The TransformerHandler is not serially reusable.The startDocument() method must be called once only." exception

Maciej Arciuch
Hi,

I've been trying recently to put a SAX filter on my custom DB-generator.
The goal is to read the data from the database in the generator, pass it
though a filter and pour it into the XPL pipeline (the filter prunes
certain nodes, so Orbeon consumes less memory while parsing it later).
Unfortunately, I'm getting java.lang.UnsupportedOperationException: "The
TransformerHandler is not serially reusable. The startDocument() method
must be called once only." exception from TransformerHandlerImpl class.

I'm not a SAX guru, perhaps I'm doing something wrong. Could you take a
look at this pseudo-code?


public void generateDocument(PipelineContext context,
    ContentHandler outputContentHandler) throws SAXException {
    InputStream is = null; // from somewhere          
    InputSource source = new InputSource(is);
           
    XMLReader reader = new SAXParser();
           
    ContentHandler ch = new MyContentHandler(outputContentHandler);
    reader.setContentHandler(ch);
         
    reader.parse(source);
}

where MyContentHandler is a simple pass-through-identity-do-nothing
ContentHandler:

public class MyContentHandler implements ContentHandler {
    private ContentHandler outputContentHandler; // set in constructor

    // each method "m(params)" in ContentHandler implemented as
outputContentHandler.m(params)
}


Am I doing something wrong? Perhaps I misunderstand some SAX concepts?
Any help would be appreciated. Best regards,
--
Maciej Arciuch
programista
tel. +48 22 564 2482


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: A SAX filter and "The TransformerHandler is not serially reusable.The startDocument() method must be called once only." exception

Alessandro  Vernet
Administrator
Maciej,

I am wondering what code is trying to serialize a TransformerHandler.
Could you quote the full exception?

Otherwise your code looks good. You can maybe save yourself a few
keystrokes by extending ForwardingContentHandler, which does something
similar to what you are doing there. Then in your inherited class, you
will maybe override some methods like startElement().

Alex

2010/2/19 Maciej Arciuch <[hidden email]>:

> Hi,
>
> I've been trying recently to put a SAX filter on my custom DB-generator. The
> goal is to read the data from the database in the generator, pass it though
> a filter and pour it into the XPL pipeline (the filter prunes certain nodes,
> so Orbeon consumes less memory while parsing it later). Unfortunately, I'm
> getting java.lang.UnsupportedOperationException: "The TransformerHandler is
> not serially reusable. The startDocument() method must be called once only."
> exception from TransformerHandlerImpl class.
>
> I'm not a SAX guru, perhaps I'm doing something wrong. Could you take a look
> at this pseudo-code?
>
>
> public void generateDocument(PipelineContext context,
>   ContentHandler outputContentHandler) throws SAXException {
>   InputStream is = null; // from somewhere             InputSource source =
> new InputSource(is);
>             XMLReader reader = new SAXParser();
>             ContentHandler ch = new MyContentHandler(outputContentHandler);
>   reader.setContentHandler(ch);
>           reader.parse(source);
> }
>
> where MyContentHandler is a simple pass-through-identity-do-nothing
> ContentHandler:
>
> public class MyContentHandler implements ContentHandler {
>   private ContentHandler outputContentHandler; // set in constructor
>
>   // each method "m(params)" in ContentHandler implemented as
> outputContentHandler.m(params)
> }
>
>
> Am I doing something wrong? Perhaps I misunderstand some SAX concepts? Any
> help would be appreciated. Best regards,
> --
> Maciej Arciuch
> programista
> tel. +48 22 564 2482
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing
> list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>


--
Orbeon Forms - Web forms, open-source, for the Enterprise -
http://www.orbeon.com/
My Twitter: http://twitter.com/avernet


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: A SAX filter and "The TransformerHandler is not serially reusable.The startDocument() method must be called once only." exception

Maciej Arciuch
Hi Alex,

I've looked at the source code of ForwardingContentHandler and if I instantiate with the default "forwarding" constructor it will behave exactly as my content handler. So I guess I won't be helpful.

From what I've seen it seems that the error occurs later, when an ordinary oxf:xslt processor attempts to modify the output of the generator in which I use my ContentHandler. I'll provide the full stack trace and relevant parts of pipeline definion on Monday.

The only posts I've found about the mentioned exception suggested to try the Saxon >=8.9. Is it possible with Orbeon? What would it take to switch to another version of Saxon? Just replace the saxon.jar? I'm using Orbeon 3.7.1.

Thanks for replying, Maciek
Reply | Threaded
Open this post in threaded view
|

Re: Re: A SAX filter and "The TransformerHandler is not seriallyreusable.The startDocument() method must be called once only." exception

Alessandro  Vernet
Administrator
Maciek,

I wasn't trying to say that using the ForwardingContentHandler would
solve your problem, just that extending that class might make your
code shorter. And yes, it would be great if you could copy here the
full stack trace of the exception you get, so we can figure out what
code is trying to serialize a TransformerHandler.

Upgrading Saxon is not a simple task: we have some changes to Saxon
that may needed to be ported forward, and Orbeon Forms uses a lot of
APIs in Saxon which can change from one version to the next. In
essence, I wouldn't try upgrading Saxon just because it might solve
your problem; it seems wiser to first determine what the source of the
problem is. You can find a bit more about this on:

http://wiki.orbeon.com/forms/doc/contributor-guide/third-party-java-libraries

Alex

On Sat, Feb 20, 2010 at 2:54 AM, Maciej Arciuch
<[hidden email]> wrote:

>
> Hi Alex,
>
> I've looked at the source code of ForwardingContentHandler and if I
> instantiate with the default "forwarding" constructor it will behave exactly
> as my content handler. So I guess I won't be helpful.
>
> From what I've seen it seems that the error occurs later, when an ordinary
> oxf:xslt processor attempts to modify the output of the generator in which I
> use my ContentHandler. I'll provide the full stack trace and relevant parts
> of pipeline definion on Monday.
>
> The only posts I've found about the mentioned exception suggested to try the
> Saxon >=8.9. Is it possible with Orbeon? What would it take to switch to
> another version of Saxon? Just replace the saxon.jar? I'm using Orbeon
> 3.7.1.
>
> Thanks for replying, Maciek
> --
> View this message in context: http://n4.nabble.com/A-SAX-filter-and-The-TransformerHandler-is-not-serially-reusable-The-startDocument-method-must-be-can-tp1561599p1562742.html
> Sent from the ObjectWeb OPS - Users mailing list archive at Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>


--
Orbeon Forms - Web forms, open-source, for the Enterprise -
http://www.orbeon.com/
My Twitter: http://twitter.com/avernet


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet