WOX2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
package wox.serial;
import java.lang.reflect.*;
import org.litesoft.core.typeutils.Objects;
import java.util.*;
/**
* This is a simple object to XML serializer. The SimpleWriter class
* extends WoxWriter. It takes a C# object and a XMLwriter object.
* It writes (converts) an object to XML, and writes it using the XMLwriter.
*
* Version: 1.0
* Author: Carlos R. Jaimez Gonzalez
* Author: Simon M. Lucas
* Site: http://woxserializer.sourceforge.net/
*
* Version: 1.5
* Author: Steven M Lewis
*
* Version: 2.0
* Author: George Smith
* SVN: http://svn.xp-dev.com/svn/WOX2/
* Note: XML form for vs 2 is more compact and therefor incompatible with vs 1
*/
public class SimpleWriter extends Serial implements WoxWriter
{
private final Hashtable<Object, String> mInstanceToIDs = new Hashtable<Object, String>();
private final WoxHandlers mWoxHandlers;
private int mNextID = 1;
// not much point writing out final values - at least not yet -
// the reader is not able to set them (though there's probably
// a hidden way of doing this)
public SimpleWriter( WoxHandlers pWoxHandlers )
{
mWoxHandlers = pWoxHandlers;
}
public String createIDfor( Object pObject )
{
String zID = Integer.toString( mNextID++ );
mInstanceToIDs.put( pObject, zID );
return zID;
}
/**
* This method is the entry point to write an object in XML.
*/
public void write( Object pObject, Field pField, XMLwriter pWriter, boolean pJustType )
{
if ( pObject == null )
{
pWriter.writeStartElement( OBJECT );
pWriter.writeEndElement();
return;
}
if ( mInstanceToIDs.containsKey( pObject ) )
{
pWriter.writeStartElement( OBJECT );
pWriter.writeAttributeString( IDREF, mInstanceToIDs.get( pObject ) );
pWriter.writeEndElement();
return;
}
Class zNativeType = pObject.getClass();
WoxHandler zWoxHandler = mWoxHandlers.getNativeHandler( zNativeType );
if ( pJustType && !zWoxHandler.supportsJustTypeWriting() )
{
throw new ApplicationException( "No significant Type infomation for: " + zNativeType.getName() );
}
zWoxHandler.writeObject( mWoxHandlers, this, pObject, pField, pWriter, pJustType );
}
}
|