Thanks, I accept that the Templates object should be immutable and I've made
changes to fix this.
I don't think I've completely replicated all the details of the JAXP spec in
terms of base properties and overlay properties - it gets more like a
detailed description of the Xalan implementation each time it's issued - but
this point was fairly fundamental and the only suprising thing is that the
product behaved this way for so long before anyone noticed.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: saxon-help-admin@...
> [mailto:saxon-help-admin@...] On Behalf Of
> Phill Wolf
> Sent: 13 February 2006 18:27
> To: saxon-help@...
> Subject: Re: [saxon] Templates output properties modified by
> Transformer.setOutputProperties?
>
> Here is a stronger JAXP spec reference regarding Templates and
> Transformer. The JAXP 1.2 spec says, "Templates must be
> threadsafe for
> a given instance over multiple threads running concurrently,
> and may be
> used multiple times in a given session" [jaxp-1_2-fr-spec.pdf
> page 79].
> The consistency of a Templates' properties with respect to
> each other --
> which matters because you snapshot the whole lot of them when
> you make a
> Transformer -- isn't usefully thread-safe if concurrent tweaks to
> Transformer instances derived from the Templates, tweak the
> Templates as
> well.
>
> Michael Kay wrote:
>
> >It's certainly a reasonable expectation that
> setOutputProperties() on the
> >Transformer shouldn't affect the output properties
> associated with the
> >Templates object - though the JDK spec isn't exactly crystal
> clear on the
> >point. I'll see what I can do.
> >
> >Michael Kay
> >Saxonica Limited
> >
> >
> >
> >>-----Original Message-----
> >>From: saxon-help-admin@...
> >>[mailto:saxon-help-admin@...] On Behalf Of
> >>Phill Wolf
> >>Sent: 04 February 2006 00:27
> >>To: saxon-help@...
> >>Subject: [saxon] Templates output properties modified by
> >>Transformer.setOutputProperties?
> >>
> >>Javadoc for Templates.getOutputProperties()* says "Get the static
> >>properties for xsl:output. The object returned will be a
> clone of the
> >>internal values. Accordingly, it can be mutated without mutating the
> >>Templates object..."
> >>
> >>So I was surprised to see Saxon-B 8.6.1's
> >>Transformer.setOutputProperties modify the output properties of the
> >>Templates from which the Transformer was derived.
> >>
> >>The attached program demonstrates.
> >>
> >>import java.io.*;
> >>import java.util.*;
> >>import javax.xml.transform.*;
> >>import javax.xml.transform.stream.*;
> >>import org.xml.sax.*;
> >>
> >>public class j
> >>{
> >> public static void main(String[] args)
> >> throws Exception
> >> {
> >> Templates templates =
> >>TransformerFactory.newInstance().newTemplates
> >> (new StreamSource
> >> (new StringReader
> >> ("<xsl:stylesheet
> >>xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
> >>version='2.0'></xsl:stylesheet>")));
> >> Transformer transformer = templates.newTransformer();
> >> Properties transformerProperties =
> >>transformer.getOutputProperties();
> >> transformerProperties.setProperty("method", "html");
> >> checkOutputMethodIsXml(templates); // does not throw
> >> transformer.setOutputProperties(transformerProperties);
> >> checkOutputMethodIsXml(templates); // throws
> >> }
> >>
> >> private static void checkOutputMethodIsXml(Templates templates)
> >> {
> >> if (!("xml".equals(templates.getOutputProperties()
> >> .getProperty("method", "xml"))))
> >> throw new RuntimeException("Templates output
> >>method changed");
> >> }
> >>}
> >>
> >>*
> >>http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/
> Templates.html
> >>
> >>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep
> through log files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web.
> DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&
> dat=121642
> _______________________________________________
> saxon-help mailing list
> saxon-help@...
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
|