You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Al...@ubsw.com on 2001/11/15 18:13:00 UTC

Problem with serializing/deserializing SVGDomDocument objects

Hi, 
I've experienced some problems when trying to serialize Document 
objects created with SVGDOMImplementation on remote jvm's.

Basically the problem seems to present itself when the Document object 
is deserialized and used  on a different jvm to which it was created 
on, almost as if some of the documents structure is not being preserved 
correctly.

For example I have attached at the bottom of this mail a version of 
DOMRasterizer which exhibits this problem

The first run through creates the document object within the jvm as 
normal, but also serializes a copy to a local file called out.obj.
when it is invoked for the second time, instead of creating the 
document object in memory, it loads up the copy serialized to disk. 
so far so good. but when it attempts to use the JPEGTranscoder object 
to write the image, it consistently fails with a NullPointerException 
from  within org.apache.batik.bridge.CSSUtilities.getViewCSS


This  behaviour can be repeated with batik 1.1rc3 on both  win2k and 
solaris 8, both with the latest sun jdk v1.3.1_01 and with documents 
which have been parsed in from file, or created using the api.


thanks in advance

Alistair.


import java.io.*;
import org.apache.batik.transcoder.image.JPEGTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.DOMImplementation;

public class DOMRasterizer
{
    
    public Document createDocument ()
    {
        DOMImplementation impl = 
SVGDOMImplementation.getDOMImplementation ();
        String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        Document document =
        impl.createDocument (svgNS, "svg", null);
        Element root = document.getDocumentElement ();
        root.setAttributeNS (null, "width", "450");
        root.setAttributeNS (null, "height", "500");
        
        Element e;
        e = document.createElementNS (svgNS, "rect");
        e.setAttributeNS (null, "x", "10");
        e.setAttributeNS (null, "y", "10");
        e.setAttributeNS (null, "width", "200");
        e.setAttributeNS (null, "height", "300");
        e.setAttributeNS (null, "style", 
"fill:red;stroke:black;stroke-width:4");
        root.appendChild (e);
        
        e = document.createElementNS (svgNS, "circle");
        e.setAttributeNS (null, "cx", "225");
        e.setAttributeNS (null, "cy", "250");
        e.setAttributeNS (null, "r", "100");
        e.setAttributeNS (null, "style", "fill:green;fill-opacity:.5");
        root.appendChild (e);
        
        return document;
    }
    
    public void save (Document document) throws Exception
    {
        JPEGTranscoder t = new JPEGTranscoder ();
        t.addTranscodingHint (JPEGTranscoder.KEY_QUALITY,
        new Float (.8));
        TranscoderInput input = new TranscoderInput (document);
        OutputStream ostream = new FileOutputStream ("out.jpg");
        TranscoderOutput output = new TranscoderOutput (ostream);
        t.transcode (input, output);
        ostream.flush ();
        ostream.close ();
    }
    
    public static void main (String [] args) throws Exception
    {
        try
        {
            DOMRasterizer rasterizer = new DOMRasterizer ();
            Document document=null;
            File objFile=new File ("out.obj");
            if( objFile.exists ()) // object exists, so lets read in 
from disk
            {
                System.err.println (" reading Document from disk: 
"+objFile);
                
                FileInputStream fis=new FileInputStream (objFile);
                ObjectInputStream ois=new ObjectInputStream (fis);
                document=(Document)ois.readObject (); // read in the 
document object
                ois.close ();
            }
            else
            { // create the document in the usual way.
                document = rasterizer.createDocument ();
                
                System.err.println (" Serializing Document to disk: 
"+objFile);
                // write serialized document object to disk
                FileOutputStream fos=new FileOutputStream (objFile);
                ObjectOutputStream oos=new ObjectOutputStream (fos);
                oos.writeObject (document);
                oos.flush ();
                oos.close ();
            }
            rasterizer.save (document);
            System.exit (0);
            
        } catch (NullPointerException npe) // oops
        { // catch the exception
            System.err.println ("***Error: "+npe+"+\n");
            npe.printStackTrace (System.err);
            System.exit (1);
        }
    }
}


Visit our website at http://www.ubswarburg.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Problem with serializing/deserializing SVGDomDocument objects

Posted by Stephane Hillion <sh...@ilog.fr>.
On Thursday 15 November 2001 18:13, Alistair.Taylor@ubsw.com wrote:
> I've experienced some problems when trying to serialize Document
> objects created with SVGDOMImplementation on remote jvm's.
>

This is a bug related with this one: 
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4643
the java serialization of the DOM does not work for the moment. I need to 
investigate.
--
  Stephane.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org