DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12317>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12317 TemplatesImp.java serialization fails [EMAIL PROTECTED] changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |santiago.pericasgeertsen@sun | |.com Status|ASSIGNED |RESOLVED Resolution| |FIXED ------- Additional Comments From [EMAIL PROTECTED] 2002-10-15 20:01 ------- Santiago and I have removed the readExternal(), writeExternal() methods (from interface Externizable) and instead rely on readObject(), writeObject(). We still implement the Serializable interface. We marked the TransformerFactoryImpl field in the TemplatesImpl class as transient, to make sure it does not get serialized. We overrode readObject(ObjectInputStream) so that we could create a new TransformerFactory in the case of reading in a serialized translet. Here is a JAXP program that I wrote that shows how this fix was tested: import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.Transformer; import javax.xml.transform.Templates; import javax.xml.transform.TransformerFactory; import java.io.FileOutputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.FileInputStream; import java.io.ObjectInput; import java.io.ObjectInputStream; import org.apache.xalan.xsltc.trax.TemplatesImpl; public class ProtoTemplates { public static void main(String[] args){ ProtoTemplates app = new ProtoTemplates(); app.run(args); } public void run(String[] args){ if (args.length != 2) { usage(); } String inputFilename = args[0]; String stylesheet = args[1]; Transformer transformer; TransformerFactory factory = TransformerFactory.newInstance(); try { FileOutputStream fout = new FileOutputStream("MyTemplates.ser"); ObjectOutput out = new ObjectOutputStream(fout); Templates templates = factory.newTemplates( new StreamSource(stylesheet)); out.writeObject(templates); out.flush(); out.close(); // try to use the serialized templates object, this will // create a new Transformer Factory, see TemplatesImpl.java, // readObject(...) method. FileInputStream fin = new FileInputStream("MyTemplates.ser"); ObjectInput in = new ObjectInputStream(fin); Templates templates2 = (Templates)in.readObject(); in.close(); transformer = templates2.newTransformer(); transformer.transform(new StreamSource(inputFilename), new StreamResult(System.out)); } catch (ClassCastException e) { System.err.println("CAST EXC: " + e); e.printStackTrace(); } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(); } System.exit(0); } public void usage() { System.err.println( "Usage: run <xml_file> <xsl_file>"); System.exit(1); } }
