107 lines
5.1 KiB
Java
107 lines
5.1 KiB
Java
package com.thoughtworks.xstream.converters.collections;
|
|
|
|
import com.thoughtworks.xstream.converters.ConversionException;
|
|
import com.thoughtworks.xstream.converters.Converter;
|
|
import com.thoughtworks.xstream.converters.ErrorWritingException;
|
|
import com.thoughtworks.xstream.converters.MarshallingContext;
|
|
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
|
import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
|
|
import com.thoughtworks.xstream.core.util.HierarchicalStreams;
|
|
import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
|
|
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
|
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
|
import com.thoughtworks.xstream.mapper.Mapper;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class AbstractCollectionConverter implements Converter {
|
|
static /* synthetic */ Class class$com$thoughtworks$xstream$mapper$Mapper$Null;
|
|
private final Mapper mapper;
|
|
|
|
public AbstractCollectionConverter(Mapper mapper) {
|
|
this.mapper = mapper;
|
|
}
|
|
|
|
static /* synthetic */ Class class$(String str) {
|
|
try {
|
|
return Class.forName(str);
|
|
} catch (ClassNotFoundException e) {
|
|
throw new NoClassDefFoundError().initCause(e);
|
|
}
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.ConverterMatcher
|
|
public abstract boolean canConvert(Class cls);
|
|
|
|
protected Object createCollection(Class cls) {
|
|
ErrorWritingException conversionException;
|
|
Class defaultImplementationOf = mapper().defaultImplementationOf(cls);
|
|
try {
|
|
return defaultImplementationOf.newInstance();
|
|
} catch (IllegalAccessException e) {
|
|
conversionException = new ObjectAccessException("Cannot instantiate default collection", e);
|
|
conversionException.add("collection-type", cls.getName());
|
|
conversionException.add("default-type", defaultImplementationOf.getName());
|
|
throw conversionException;
|
|
} catch (InstantiationException e2) {
|
|
conversionException = new ConversionException("Cannot instantiate default collection", e2);
|
|
conversionException.add("collection-type", cls.getName());
|
|
conversionException.add("default-type", defaultImplementationOf.getName());
|
|
throw conversionException;
|
|
}
|
|
}
|
|
|
|
protected Mapper mapper() {
|
|
return this.mapper;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.Converter
|
|
public abstract void marshal(Object obj, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext);
|
|
|
|
protected Object readBareItem(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext, Object obj) {
|
|
return unmarshallingContext.convertAnother(obj, HierarchicalStreams.readClassType(hierarchicalStreamReader, mapper()));
|
|
}
|
|
|
|
protected Object readCompleteItem(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext, Object obj) {
|
|
hierarchicalStreamReader.moveDown();
|
|
Object readItem = readItem(hierarchicalStreamReader, unmarshallingContext, obj);
|
|
hierarchicalStreamReader.moveUp();
|
|
return readItem;
|
|
}
|
|
|
|
protected Object readItem(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext, Object obj) {
|
|
return readBareItem(hierarchicalStreamReader, unmarshallingContext, obj);
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.Converter
|
|
public abstract Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext);
|
|
|
|
protected void writeBareItem(Object obj, MarshallingContext marshallingContext, HierarchicalStreamWriter hierarchicalStreamWriter) {
|
|
marshallingContext.convertAnother(obj);
|
|
}
|
|
|
|
protected void writeCompleteItem(Object obj, MarshallingContext marshallingContext, HierarchicalStreamWriter hierarchicalStreamWriter) {
|
|
writeItem(obj, marshallingContext, hierarchicalStreamWriter);
|
|
}
|
|
|
|
protected void writeItem(Object obj, MarshallingContext marshallingContext, HierarchicalStreamWriter hierarchicalStreamWriter) {
|
|
if (obj == null) {
|
|
writeNullItem(marshallingContext, hierarchicalStreamWriter);
|
|
return;
|
|
}
|
|
ExtendedHierarchicalStreamWriterHelper.startNode(hierarchicalStreamWriter, mapper().serializedClass(obj.getClass()), obj.getClass());
|
|
writeBareItem(obj, marshallingContext, hierarchicalStreamWriter);
|
|
hierarchicalStreamWriter.endNode();
|
|
}
|
|
|
|
protected void writeNullItem(MarshallingContext marshallingContext, HierarchicalStreamWriter hierarchicalStreamWriter) {
|
|
String serializedClass = mapper().serializedClass(null);
|
|
Class cls = class$com$thoughtworks$xstream$mapper$Mapper$Null;
|
|
if (cls == null) {
|
|
cls = class$("com.thoughtworks.xstream.mapper.Mapper$Null");
|
|
class$com$thoughtworks$xstream$mapper$Mapper$Null = cls;
|
|
}
|
|
ExtendedHierarchicalStreamWriterHelper.startNode(hierarchicalStreamWriter, serializedClass, cls);
|
|
hierarchicalStreamWriter.endNode();
|
|
}
|
|
}
|