Hi Nebojša,

Nebojša Miletić <[EMAIL PROTECTED]> wrote on 10/27/2006 01:39:09 PM:

> I am working on complex relationship management desktop application. The
> user can load or create some graph on the JSVGCanvas. He is able to edit
> that graph (move nodes, edit relations etc). 
> 
> The user should be able to save the state of the edited graph and load 
that
> state whenever he wants. 

   Sure this is a pretty standard thing to do with SVG as well.

> In some other (non-SVG) parts of my application, I use this kind of
> serialization (and it works):
> 
> <code>
>    import java.beans.XMLEncoder;
> </code>
> 
> The object I try to serialize is:
> <code>
>    SVGOMRectElement serializedObject = new SVGOMRectElement("customNS",
> jsvgCanvas.getDocument());
> </code>

    This is not the correct way to create an SVG Rect element.
You should use the document as a factory to create your elements:

        Element rect = jsvgCanvas.getDocument().createElement
          ("http://www.w3.org/2000/svg";, "rect");

> This is the reported exception:
> java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline can 
not
> access a member of class org.apache.batik.dom.svg.SVGOMRectElement with
> modifiers "protected"

> Is there some other way to serialize this (and deserialize it 
afterwards)?
> Or I am doing something wrong?

    So I don't know much about XMLEncoder but I presume it
uses reflection to try and turn the given Java object into XML.
However, this would be a really round about way to serialize
a DOM object into XML (A DOM object is essentially an in-memory
version of an XML element).  You can use the methods in 
batik.dom.util.DOMUtilities to serialize individual elements 
or whole documents.

> Or I have to dive into the Batik source code and deal with the 
unaccessible
> members?
> Or any other suggestion?

    For this sort of stuff I would normally 'annotate'
a standard SVG file with extra elements/attributes in 
a custom namespace.  Often with this approach you can
have a static SVG picture that any SVG client can 
display, but still enable editing within your application.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to