101 lines
4.5 KiB
Java
101 lines
4.5 KiB
Java
package com.thoughtworks.xstream.converters.extended;
|
|
|
|
import com.thoughtworks.xstream.converters.Converter;
|
|
import com.thoughtworks.xstream.converters.MarshallingContext;
|
|
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
|
import com.thoughtworks.xstream.core.util.HierarchicalStreams;
|
|
import com.thoughtworks.xstream.core.util.Primitives;
|
|
import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
|
|
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
|
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
|
import com.thoughtworks.xstream.mapper.Mapper;
|
|
import java.lang.reflect.Array;
|
|
import java.util.ArrayList;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class NamedArrayConverter implements Converter {
|
|
static /* synthetic */ Class class$com$thoughtworks$xstream$mapper$Mapper$Null;
|
|
private final Class arrayType;
|
|
private final String itemName;
|
|
private final Mapper mapper;
|
|
|
|
public NamedArrayConverter(Class cls, Mapper mapper, String str) {
|
|
if (cls.isArray()) {
|
|
this.arrayType = cls;
|
|
this.mapper = mapper;
|
|
this.itemName = str;
|
|
} else {
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
stringBuffer.append(cls.getName());
|
|
stringBuffer.append(" is not an array");
|
|
throw new IllegalArgumentException(stringBuffer.toString());
|
|
}
|
|
}
|
|
|
|
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 boolean canConvert(Class cls) {
|
|
return cls == this.arrayType;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.Converter
|
|
public void marshal(Object obj, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) {
|
|
Class<?> unbox;
|
|
String aliasForSystemAttribute;
|
|
int length = Array.getLength(obj);
|
|
for (int i = 0; i < length; i++) {
|
|
Object obj2 = Array.get(obj, i);
|
|
if (obj2 == null) {
|
|
unbox = class$com$thoughtworks$xstream$mapper$Mapper$Null;
|
|
if (unbox == null) {
|
|
unbox = class$("com.thoughtworks.xstream.mapper.Mapper$Null");
|
|
class$com$thoughtworks$xstream$mapper$Mapper$Null = unbox;
|
|
}
|
|
} else {
|
|
unbox = this.arrayType.getComponentType().isPrimitive() ? Primitives.unbox(obj2.getClass()) : obj2.getClass();
|
|
}
|
|
ExtendedHierarchicalStreamWriterHelper.startNode(hierarchicalStreamWriter, this.itemName, unbox);
|
|
if (!unbox.equals(this.arrayType.getComponentType()) && (aliasForSystemAttribute = this.mapper.aliasForSystemAttribute("class")) != null) {
|
|
hierarchicalStreamWriter.addAttribute(aliasForSystemAttribute, this.mapper.serializedClass(unbox));
|
|
}
|
|
if (obj2 != null) {
|
|
marshallingContext.convertAnother(obj2);
|
|
}
|
|
hierarchicalStreamWriter.endNode();
|
|
}
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.Converter
|
|
public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) {
|
|
ArrayList arrayList = new ArrayList();
|
|
while (hierarchicalStreamReader.hasMoreChildren()) {
|
|
hierarchicalStreamReader.moveDown();
|
|
String readClassAttribute = HierarchicalStreams.readClassAttribute(hierarchicalStreamReader, this.mapper);
|
|
Class<?> componentType = readClassAttribute == null ? this.arrayType.getComponentType() : this.mapper.realClass(readClassAttribute);
|
|
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;
|
|
}
|
|
Object obj = null;
|
|
if (!cls.equals(componentType)) {
|
|
obj = unmarshallingContext.convertAnother(null, componentType);
|
|
}
|
|
arrayList.add(obj);
|
|
hierarchicalStreamReader.moveUp();
|
|
}
|
|
Object newInstance = Array.newInstance(this.arrayType.getComponentType(), arrayList.size());
|
|
for (int i = 0; i < arrayList.size(); i++) {
|
|
Array.set(newInstance, i, arrayList.get(i));
|
|
}
|
|
return newInstance;
|
|
}
|
|
}
|