384 lines
18 KiB
Java
384 lines
18 KiB
Java
package com.thoughtworks.xstream.converters.reflection;
|
|
|
|
import com.thoughtworks.xstream.converters.ConversionException;
|
|
import com.thoughtworks.xstream.converters.Converter;
|
|
import com.thoughtworks.xstream.converters.MarshallingContext;
|
|
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
|
import com.thoughtworks.xstream.core.Caching;
|
|
import com.thoughtworks.xstream.core.ReferencingMarshallingContext;
|
|
import com.thoughtworks.xstream.core.util.Fields;
|
|
import com.thoughtworks.xstream.core.util.SerializationMembers;
|
|
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.lang.reflect.Field;
|
|
import java.lang.reflect.Modifier;
|
|
import java.util.AbstractList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class AbstractReflectionConverter implements Converter, Caching {
|
|
static /* synthetic */ Class class$com$thoughtworks$xstream$mapper$Mapper$Null;
|
|
static /* synthetic */ Class class$java$lang$Object;
|
|
static /* synthetic */ Class class$java$util$Collection;
|
|
static /* synthetic */ Class class$java$util$Map;
|
|
static /* synthetic */ Class class$java$util$Map$Entry;
|
|
protected final Mapper mapper;
|
|
private transient ReflectionProvider pureJavaReflectionProvider;
|
|
protected final ReflectionProvider reflectionProvider;
|
|
protected transient SerializationMethodInvoker serializationMethodInvoker = new SerializationMethodInvoker();
|
|
protected transient SerializationMembers serializationMembers = this.serializationMethodInvoker.serializationMembers;
|
|
|
|
private static class ArraysList extends ArrayList {
|
|
final Class physicalFieldType;
|
|
|
|
ArraysList(Class cls) {
|
|
this.physicalFieldType = cls;
|
|
}
|
|
|
|
Object toPhysicalArray() {
|
|
Object[] array = toArray();
|
|
Object newInstance = Array.newInstance(this.physicalFieldType.getComponentType(), array.length);
|
|
if (this.physicalFieldType.getComponentType().isPrimitive()) {
|
|
for (int i = 0; i < array.length; i++) {
|
|
Array.set(newInstance, i, Array.get(array, i));
|
|
}
|
|
} else {
|
|
System.arraycopy(array, 0, newInstance, 0, array.length);
|
|
}
|
|
return newInstance;
|
|
}
|
|
}
|
|
|
|
public static class DuplicateFieldException extends ConversionException {
|
|
/* JADX WARN: Illegal instructions before constructor call */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
public DuplicateFieldException(java.lang.String r3) {
|
|
/*
|
|
r2 = this;
|
|
java.lang.StringBuffer r0 = new java.lang.StringBuffer
|
|
r0.<init>()
|
|
java.lang.String r1 = "Duplicate field "
|
|
r0.append(r1)
|
|
r0.append(r3)
|
|
java.lang.String r0 = r0.toString()
|
|
r2.<init>(r0)
|
|
java.lang.String r0 = "field"
|
|
r2.add(r0, r3)
|
|
return
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.DuplicateFieldException.<init>(java.lang.String):void");
|
|
}
|
|
}
|
|
|
|
private static class FieldInfo extends FieldLocation {
|
|
final Class type;
|
|
final Object value;
|
|
|
|
FieldInfo(String str, Class cls, Class cls2, Object obj) {
|
|
super(str, cls2);
|
|
this.type = cls;
|
|
this.value = obj;
|
|
}
|
|
}
|
|
|
|
private static class FieldLocation {
|
|
final Class definedIn;
|
|
final String fieldName;
|
|
|
|
FieldLocation(String str, Class cls) {
|
|
this.fieldName = str;
|
|
this.definedIn = cls;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (obj == null || getClass() != obj.getClass()) {
|
|
return false;
|
|
}
|
|
FieldLocation fieldLocation = (FieldLocation) obj;
|
|
if (this.definedIn != fieldLocation.definedIn) {
|
|
return false;
|
|
}
|
|
String str = this.fieldName;
|
|
if (str == null) {
|
|
if (fieldLocation.fieldName != null) {
|
|
return false;
|
|
}
|
|
} else if (!str.equals(fieldLocation.fieldName)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Class cls = this.definedIn;
|
|
int hashCode = ((cls == null ? 0 : cls.getName().hashCode()) + 7) * 7;
|
|
String str = this.fieldName;
|
|
return hashCode + (str != null ? str.hashCode() : 0);
|
|
}
|
|
}
|
|
|
|
private interface FieldMarshaller {
|
|
void writeField(String str, String str2, Class cls, Class cls2, Object obj);
|
|
|
|
void writeItem(Object obj);
|
|
}
|
|
|
|
private class MappingList extends AbstractList {
|
|
private final Map fieldCache = new HashMap();
|
|
private final String keyFieldName;
|
|
private final Map map;
|
|
|
|
public MappingList(Map map, String str) {
|
|
this.map = map;
|
|
this.keyFieldName = str;
|
|
}
|
|
|
|
@Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List
|
|
public boolean add(Object obj) {
|
|
if (obj == null) {
|
|
boolean z = !this.map.containsKey(null);
|
|
this.map.put(null, null);
|
|
return z;
|
|
}
|
|
Class<?> cls = obj.getClass();
|
|
if (this.keyFieldName != null) {
|
|
Field field = (Field) this.fieldCache.get(cls);
|
|
if (field == null) {
|
|
field = AbstractReflectionConverter.this.reflectionProvider.getField(cls, this.keyFieldName);
|
|
this.fieldCache.put(cls, field);
|
|
}
|
|
if (field != null) {
|
|
return this.map.put(Fields.read(field, obj), obj) == null;
|
|
}
|
|
} else if (obj instanceof Map.Entry) {
|
|
Map.Entry entry = (Map.Entry) obj;
|
|
return this.map.put(entry.getKey(), entry.getValue()) == null;
|
|
}
|
|
ConversionException conversionException = new ConversionException("Element is not defined as entry for implicit map");
|
|
conversionException.add("map-type", this.map.getClass().getName());
|
|
conversionException.add("element-type", obj.getClass().getName());
|
|
throw conversionException;
|
|
}
|
|
|
|
@Override // java.util.AbstractList, java.util.List
|
|
public Object get(int i) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
|
public int size() {
|
|
return this.map.size();
|
|
}
|
|
}
|
|
|
|
public static class UnknownFieldException extends ConversionException {
|
|
/* JADX WARN: Illegal instructions before constructor call */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
public UnknownFieldException(java.lang.String r3, java.lang.String r4) {
|
|
/*
|
|
r2 = this;
|
|
java.lang.StringBuffer r0 = new java.lang.StringBuffer
|
|
r0.<init>()
|
|
java.lang.String r1 = "No such field "
|
|
r0.append(r1)
|
|
r0.append(r3)
|
|
java.lang.String r3 = "."
|
|
r0.append(r3)
|
|
r0.append(r4)
|
|
java.lang.String r3 = r0.toString()
|
|
r2.<init>(r3)
|
|
java.lang.String r3 = "field"
|
|
r2.add(r3, r4)
|
|
return
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.UnknownFieldException.<init>(java.lang.String, java.lang.String):void");
|
|
}
|
|
}
|
|
|
|
public AbstractReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
|
|
this.mapper = mapper;
|
|
this.reflectionProvider = reflectionProvider;
|
|
}
|
|
|
|
static /* synthetic */ Class class$(String str) {
|
|
try {
|
|
return Class.forName(str);
|
|
} catch (ClassNotFoundException e) {
|
|
throw new NoClassDefFoundError().initCause(e);
|
|
}
|
|
}
|
|
|
|
private void handleUnknownField(Class cls, String str, Class cls2, String str2) {
|
|
if (cls == null) {
|
|
for (Class cls3 = cls2; cls3 != null; cls3 = cls3.getSuperclass()) {
|
|
if (!this.mapper.shouldSerializeMember(cls3, str2)) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
throw new UnknownFieldException(cls2.getName(), str);
|
|
}
|
|
|
|
private Class readDeclaringClass(HierarchicalStreamReader hierarchicalStreamReader) {
|
|
String aliasForSystemAttribute = this.mapper.aliasForSystemAttribute("defined-in");
|
|
String attribute = aliasForSystemAttribute == null ? null : hierarchicalStreamReader.getAttribute(aliasForSystemAttribute);
|
|
if (attribute == null) {
|
|
return null;
|
|
}
|
|
return this.mapper.realClass(attribute);
|
|
}
|
|
|
|
private void writeValueToImplicitCollection(Object obj, Map map, Object obj2, FieldLocation fieldLocation) {
|
|
Collection collection = (Collection) map.get(fieldLocation);
|
|
if (collection == null) {
|
|
Field fieldOrNull = this.reflectionProvider.getFieldOrNull(fieldLocation.definedIn, fieldLocation.fieldName);
|
|
Class type = fieldOrNull != null ? fieldOrNull.getType() : this.reflectionProvider.getFieldType(obj2, fieldLocation.fieldName, null);
|
|
if (type.isArray()) {
|
|
collection = new ArraysList(type);
|
|
} else {
|
|
Class<?> defaultImplementationOf = this.mapper.defaultImplementationOf(type);
|
|
Class cls = class$java$util$Collection;
|
|
if (cls == null) {
|
|
cls = class$("java.util.Collection");
|
|
class$java$util$Collection = cls;
|
|
}
|
|
if (!cls.isAssignableFrom(defaultImplementationOf)) {
|
|
Class cls2 = class$java$util$Map;
|
|
if (cls2 == null) {
|
|
cls2 = class$("java.util.Map");
|
|
class$java$util$Map = cls2;
|
|
}
|
|
if (!cls2.isAssignableFrom(defaultImplementationOf)) {
|
|
ObjectAccessException objectAccessException = new ObjectAccessException("Field is configured for an implicit Collection or Map, but is of an incompatible type");
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
stringBuffer.append(obj2.getClass().getName());
|
|
stringBuffer.append(".");
|
|
stringBuffer.append(fieldLocation.fieldName);
|
|
objectAccessException.add("field", stringBuffer.toString());
|
|
objectAccessException.add("field-type", defaultImplementationOf.getName());
|
|
throw objectAccessException;
|
|
}
|
|
}
|
|
if (this.pureJavaReflectionProvider == null) {
|
|
this.pureJavaReflectionProvider = new PureJavaReflectionProvider();
|
|
}
|
|
Object newInstance = this.pureJavaReflectionProvider.newInstance(defaultImplementationOf);
|
|
Collection mappingList = newInstance instanceof Collection ? (Collection) newInstance : new MappingList((Map) newInstance, this.mapper.getImplicitCollectionDefForFieldName(fieldLocation.definedIn, fieldLocation.fieldName).getKeyFieldName());
|
|
this.reflectionProvider.writeField(obj2, fieldLocation.fieldName, newInstance, fieldOrNull != null ? fieldOrNull.getDeclaringClass() : null);
|
|
collection = mappingList;
|
|
}
|
|
map.put(fieldLocation, collection);
|
|
}
|
|
collection.add(obj);
|
|
}
|
|
|
|
protected boolean canAccess(Class cls) {
|
|
try {
|
|
this.reflectionProvider.getFieldOrNull(cls, "%");
|
|
return true;
|
|
} catch (NoClassDefFoundError unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:19:0x017f A[SYNTHETIC] */
|
|
/* JADX WARN: Removed duplicated region for block: B:23:0x008d A[SYNTHETIC] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
protected void doMarshal(final java.lang.Object r20, final com.thoughtworks.xstream.io.HierarchicalStreamWriter r21, final com.thoughtworks.xstream.converters.MarshallingContext r22) {
|
|
/*
|
|
Method dump skipped, instructions count: 399
|
|
To view this dump change 'Code comments level' option to 'DEBUG'
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(java.lang.Object, com.thoughtworks.xstream.io.HierarchicalStreamWriter, com.thoughtworks.xstream.converters.MarshallingContext):void");
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:51:0x0100 */
|
|
/* JADX WARN: Removed duplicated region for block: B:59:0x0218 */
|
|
/* JADX WARN: Removed duplicated region for block: B:62:0x022e */
|
|
/* JADX WARN: Removed duplicated region for block: B:76:0x0103 */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
public java.lang.Object doUnmarshal(java.lang.Object r13, com.thoughtworks.xstream.io.HierarchicalStreamReader r14, com.thoughtworks.xstream.converters.UnmarshallingContext r15) {
|
|
/*
|
|
Method dump skipped, instructions count: 676
|
|
To view this dump change 'Code comments level' option to 'DEBUG'
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(java.lang.Object, com.thoughtworks.xstream.io.HierarchicalStreamReader, com.thoughtworks.xstream.converters.UnmarshallingContext):java.lang.Object");
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.core.Caching
|
|
public void flushCache() {
|
|
this.serializationMethodInvoker.flushCache();
|
|
}
|
|
|
|
protected Object instantiateNewInstance(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) {
|
|
String aliasForSystemAttribute = this.mapper.aliasForSystemAttribute("resolves-to");
|
|
String attribute = aliasForSystemAttribute == null ? null : hierarchicalStreamReader.getAttribute(aliasForSystemAttribute);
|
|
Object currentObject = unmarshallingContext.currentObject();
|
|
return currentObject != null ? currentObject : attribute != null ? this.reflectionProvider.newInstance(this.mapper.realClass(attribute)) : this.reflectionProvider.newInstance(unmarshallingContext.getRequiredType());
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.Converter
|
|
public void marshal(Object obj, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) {
|
|
Object callWriteReplace = this.serializationMembers.callWriteReplace(obj);
|
|
if (callWriteReplace != obj && (marshallingContext instanceof ReferencingMarshallingContext)) {
|
|
((ReferencingMarshallingContext) marshallingContext).replace(obj, callWriteReplace);
|
|
}
|
|
if (callWriteReplace.getClass() == obj.getClass()) {
|
|
doMarshal(callWriteReplace, hierarchicalStreamWriter, marshallingContext);
|
|
return;
|
|
}
|
|
String aliasForSystemAttribute = this.mapper.aliasForSystemAttribute("resolves-to");
|
|
if (aliasForSystemAttribute != null) {
|
|
hierarchicalStreamWriter.addAttribute(aliasForSystemAttribute, this.mapper.serializedClass(callWriteReplace.getClass()));
|
|
}
|
|
marshallingContext.convertAnother(callWriteReplace);
|
|
}
|
|
|
|
protected void marshallField(MarshallingContext marshallingContext, Object obj, Field field) {
|
|
marshallingContext.convertAnother(obj, this.mapper.getLocalConverter(field.getDeclaringClass(), field.getName()));
|
|
}
|
|
|
|
protected Object readResolve() {
|
|
this.serializationMethodInvoker = new SerializationMethodInvoker();
|
|
this.serializationMembers = this.serializationMethodInvoker.serializationMembers;
|
|
return this;
|
|
}
|
|
|
|
protected boolean shouldUnmarshalField(Field field) {
|
|
return !Modifier.isTransient(field.getModifiers()) || shouldUnmarshalTransientFields();
|
|
}
|
|
|
|
protected boolean shouldUnmarshalTransientFields() {
|
|
return false;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.Converter
|
|
public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) {
|
|
return this.serializationMembers.callReadResolve(doUnmarshal(instantiateNewInstance(hierarchicalStreamReader, unmarshallingContext), hierarchicalStreamReader, unmarshallingContext));
|
|
}
|
|
|
|
protected Object unmarshallField(UnmarshallingContext unmarshallingContext, Object obj, Class cls, Field field) {
|
|
return unmarshallingContext.convertAnother(obj, cls, this.mapper.getLocalConverter(field.getDeclaringClass(), field.getName()));
|
|
}
|
|
}
|