Subversion Repository Public Repository

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package wox.serial;

import java.lang.reflect.*;
import org.litesoft.core.typeutils.Objects;
import java.util.*;

/**
 * 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 ListHandler extends AbstractHandler implements WoxIsAHandler
{
    public static final ListHandler INSTANCE = new ListHandler();

    public static final String WOX_TYPE = "list";

    private static final String GENERIC_WOX_TYPE_NAME_STARTS_WITH = WOX_TYPE + "<";

    protected ListHandler()
    {
    }

    @Override
    public boolean isFor( Class pType )
    {
        return List.class.isAssignableFrom( pType );
    }

    @Override
    public String[] getForReadObjectWoxTypeNames()
    {
        return null; // Ask Us
    }

    @Override
    public Class getNativeTypeFor( WoxHandlers pWoxHandlers, String pWoxType )
    {
        if ( WOX_TYPE.equals( pWoxType ) )
        {
            return ArrayList.class;
        }
        if ( pWoxType.startsWith( GENERIC_WOX_TYPE_NAME_STARTS_WITH ) )
        {
            Class zType = commonNativeType( pWoxHandlers, pWoxType );
            if ( zType != null )
            {
                return zType;
            }
        }
        throw new ApplicationException( "No Native Type for Wox Type: " + pWoxType );
    }

    @Override
    public String getWoxTypeFor( WoxHandlers pWoxHandlers, Class pType, Field pField, boolean pJustType )
    {
        if ( null != getGenericTypes( pField ) )
        {
            return commonWoxType( pWoxHandlers, pType, pField, pJustType );
        }
        if ( List.class.isAssignableFrom( pType ) )
        {
            return WOX_TYPE;
        }
        throw new ApplicationException( "No Wox Type for Native Type: " + pType );
    }

    @Override
    public boolean willReadObjectForWoxType( String pWoxType )
    {
        return WOX_TYPE.equals( pWoxType ) || pWoxType.startsWith( GENERIC_WOX_TYPE_NAME_STARTS_WITH );
    }

    @Override
    public Object readObject( WoxHandlers pWoxHandlers, WoxReader pWoxReader, XMLreader pReader )
    {
        XMLreader zSubtree = pReader.createSubtreeReader();
        zSubtree.readStartElement(); //position the cursor to our element

        try
        {
            return readObjects( pWoxReader, zSubtree );
        }
        catch ( Exception e )
        {
            throw new ApplicationException( "List Handler Read Object Exception is: " + e.getMessage(), e );
        }
        finally
        {
            consume( zSubtree );
        }
    }

    @Override
    public void writeObject( WoxHandlers pWoxHandlers, WoxWriter pWoxWriter, Object pObject, Field pField, XMLwriter pWriter, boolean pJustType )
    {
        Class zType = pObject.getClass();
        String zWoxTypeName = commonWoxType( pWoxHandlers, zType, pField, pJustType );

        pWriter.writeStartElement( Serial.OBJECT );
        pWriter.writeAttributeString( Serial.TYPE, zWoxTypeName );

        List<?> zList = (List<?>) pObject;
        if ( !zList.isEmpty() )
        {
            pWriter.writeAttributeString( Serial.ID, pWoxWriter.createIDfor( pObject ) );

            for ( Object zEntry : zList )
            {
                pWoxWriter.write( zEntry, pField, pWriter, pJustType );
            }
        }
        pWriter.writeEndElement();
    }
}

Commits for WOX2/trunk/Java/src/wox/serial/ListHandler.java

Diff revisions: vs.
Revision Author Commited Message
17 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 23:44:02 +0000

Extracting commonfoundation

15 Diff Diff GeorgeS picture GeorgeS Fri 19 Feb, 2010 22:29:49 +0000
7 Diff Diff GeorgeS picture GeorgeS Fri 05 Feb, 2010 19:14:48 +0000
5 Diff Diff GeorgeS picture GeorgeS Fri 05 Feb, 2010 18:59:04 +0000
4 Diff Diff GeorgeS picture GeorgeS Fri 05 Feb, 2010 18:15:55 +0000
3 GeorgeS picture GeorgeS Thu 04 Feb, 2010 23:53:47 +0000