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 Nebojša Miletić <ne...@accordia.co.yu> on 2006/10/27 19:39:09 UTC

Serialization with FileStreams

Hello

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. 

In some other (non-SVG) parts of my application, I use this kind of
serialization (and it works):

<code>
	import java.beans.XMLEncoder;

	FileOutputStream os = null;
	try{
		os = new FileOutputStream("c:\\serialization.xml");
	}
	catch(Exception ex){
	}
	
	if(os != null){
		XMLEncoder encoder = new XMLEncoder(os);
		encoder.writeObject(serializedObject);
		encoder.close();
	}
</code>

The object I try to serialize is:
<code>
	SVGOMRectElement serializedObject = new SVGOMRectElement("customNS",
jsvgCanvas.getDocument());
</code>

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"
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement
XMLEncoder.writeObject(SVGOMRectElement);
Continuing ...

So...
Is there some other way to serialize this (and deserialize it afterwards)?
Or I am doing something wrong?
Or I have to dive into the Batik source code and deal with the unaccessible
members?
Or any other suggestion?


Thanks,
Nebojsa

-- 
View this message in context: http://www.nabble.com/Serialization-with-FileStreams-tf2522028.html#a7034898
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: Serialization with FileStreams

Posted by th...@kodak.com.
Hi Nebojša,

Nebojša Miletić <ne...@accordia.co.yu> wrote on 10/28/2006 01:05:59 PM:

> Let's say that I create SVG elements using the SVGDocument as a factory. 

>   Element myRect = document.createElementNS(svgNS, "rect");

> After that I attach event listener to the rect:
>   ((EventTarget)myRect).addEventListener("click", new CEventListener(), 
false);
> 
> I use batik.dom.util.DOMUtilities methods to serialize myRect. But this
> ignores all information about the event handlers attached to myRect.
> 
> My event handling is written in Java and cannot be transferred to
> JavaScript.
> 
> How should I deal with this?

   Well you could always use your XML Serializer to serialize just
your event listener instance (into a separate namespace) and attach 
it as a child of the rect element in the XML file.

   Then when you read in the XML you can use getElementsByTagNameNS
to find your listeners and attach them to their parent elements.

> thomas.deweese wrote:
> > 
> > Hi Nebojša,
> > 
> > Nebojša Miletić <ne...@accordia.co.yu> 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: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> > 
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/Serialization-with-
> FileStreams-tf2522028.html#a7051942
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


Re: Serialization with FileStreams

Posted by Nebojša Miletić <ne...@accordia.co.yu>.
Hi, Thomas

Ok, I have found certain things in your reply that could initiate
interesting discussion, but I will focus on my "burning" issue at this
moment.

Let's say that I create SVG elements using the SVGDocument as a factory. 

<code>
Element myRect = document.createElementNS(svgNS, "rect");
</code>

After that I attach event listener to the rect:

<code>
((EventTarget)myRect).addEventListener("click", new CEventListener(),
false);
</code>

I use batik.dom.util.DOMUtilities methods to serialize myRect. But this
ignores all information about the event handlers attached to myRect.

My event handling is written in Java and cannot be transferred to
JavaScript.

How should I deal with this?


Thanks,
Nebojsa




thomas.deweese wrote:
> 
> Hi Nebojša,
> 
> Nebojša Miletić <ne...@accordia.co.yu> 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: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Serialization-with-FileStreams-tf2522028.html#a7051942
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: Serialization with FileStreams

Posted by th...@kodak.com.
Hi Nebojša,

Nebojša Miletić <ne...@accordia.co.yu> 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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org