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
80
81
82
83
84
85
86
87
88
89
90
91
92
|
package wox.serial;
import org.litesoft.core.typeutils.Objects;
import java.util.*;
/**
* This is a simple XML to object de-serializer. The SimpleReader class
* extends WoxReader. It reads an object from a XMLreader object
* and puts it back to a live Java object.
*
* 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 SimpleReader extends Serial implements WoxReader
{
private final Hashtable<String,Object> mIDtoInstances = new Hashtable<String,Object>();
private final WoxHandlers mWoxHandlers;
public SimpleReader( WoxHandlers pWoxHandlers )
{
mWoxHandlers = pWoxHandlers;
}
public Object read( XMLreader pReader )
{
if ( !pReader.hasAttributesOrElementText() )
{
return null;
}
String zID = pReader.getAttribute( IDREF ); // Is ID Ref?
if ( zID != null )
{
return mIDtoInstances.get(zID);
}
// at this point we must be reading an actual Object
// so we will need to store it by its ID so that later we
// can retrieve the object by IDREFs
String zForWoxTypeName = pReader.getAttribute( TYPE );
if ( zForWoxTypeName == null )
{
return null;// No Type == null Object
}
zID = pReader.getAttribute( ID );
WoxHandler zWoxHandler = mWoxHandlers.getWoxHandler( zForWoxTypeName );
return map( zID, zWoxHandler.readObject( mWoxHandlers, this, pReader ) );
}
private Object map( String pID, Object pInstance )
{
if ( pID != null )
{
mIDtoInstances.put( pID, pInstance );
}
return pInstance;
}
//-----------------------------------------------------------------------------
/**
* Purpose: To constuct the byte array based on the a and pReader
* Befor constructs back the byte array, it has to be decoded
* Carlos Jaimez (29 april 2005)
* @param a
* @param pReader
* @return : int Array
*/
/*protected Object readByteArray(Element pReader) {
//get the encoded base64 text from the XML
String strByte = pReader.getText();
//get the bytes from the String
byte[] encodedArray = strByte.getBytes();
System.out.println("encoded.length: " + encodedArray.length);
//decode the source byte[] array
byte[] decodedArray = EncodeBase64.decode(encodedArray);
System.out.println("decoded.length: " + decodedArray.length);
//return the real decoded array of byte
return decodedArray;
}*/
}
|