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
| import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Collection;
import flex.messaging.io.PropertyProxy;
import flex.messaging.io.PropertyProxyRegistry;
import flex.messaging.io.SerializationDescriptor;
/**
* Used to map to client mx.collections.ArrayCollection to java.util.Lists in Java.
*/
public class ArrayCollection extends ArrayList implements Externalizable
{
private static final long serialVersionUID = 8037277879661457358L;
private SerializationDescriptor descriptor = null;
public ArrayCollection()
{
super();
}
public ArrayCollection(Collection c)
{
super(c);
}
public ArrayCollection(int initialCapacity)
{
super(initialCapacity);
}
public Object[] getSource()
{
return toArray();
}
public void setDescriptor(SerializationDescriptor desc)
{
this.descriptor = desc;
}
public void setSource(Object[] s)
{
if (s != null)
{
if (size() > 0)
clear();
for (int i = 0; i < s.length; i++)
{
add(s[i]);
}
}
else
{
clear();
}
}
public void setSource(Collection s)
{
addAll(s);
}
public void readExternal(ObjectInput input) throws IOException, ClassNotFoundException
{
Object s = input.readObject();
if (s instanceof Collection)
s = ((Collection)s).toArray();
Object[] source = (Object[])s;
setSource(source);
}
public void writeExternal(ObjectOutput output) throws IOException
{
if (descriptor == null)
output.writeObject(getSource());
else
{
Object[] source = getSource();
if (source == null)
output.writeObject(null);
else
{
for (int i = 0; i < source.length; i++)
{
Object item = source[i];
if (item == null)
source[i] = null;
else
{
PropertyProxy proxy = PropertyProxyRegistry.getProxy(item);
proxy = (PropertyProxy)proxy.clone();
proxy.setDescriptor(descriptor);
proxy.setDefaultInstance(item);
source[i] = proxy;
}
}
output.writeObject(source);
}
}
}
} |