349 lines
16 KiB
Java
349 lines
16 KiB
Java
package com.thoughtworks.xstream.mapper;
|
|
|
|
import com.thoughtworks.xstream.InitializationException;
|
|
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
|
|
import com.thoughtworks.xstream.core.util.Primitives;
|
|
import com.thoughtworks.xstream.mapper.Mapper;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Modifier;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ImplicitCollectionMapper extends MapperWrapper {
|
|
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;
|
|
private final Map classNameToMapper;
|
|
private ReflectionProvider reflectionProvider;
|
|
|
|
private class ImplicitCollectionMapperForClass {
|
|
private Class definedIn;
|
|
private Map namedItemTypeToDef = new HashMap();
|
|
private Map itemFieldNameToDef = new HashMap();
|
|
private Map fieldNameToDef = new HashMap();
|
|
|
|
ImplicitCollectionMapperForClass(Class cls) {
|
|
this.definedIn = cls;
|
|
}
|
|
|
|
private ImplicitCollectionMappingImpl getImplicitCollectionDefByItemFieldName(String str) {
|
|
if (str == null) {
|
|
return null;
|
|
}
|
|
ImplicitCollectionMappingImpl implicitCollectionMappingImpl = (ImplicitCollectionMappingImpl) this.itemFieldNameToDef.get(str);
|
|
if (implicitCollectionMappingImpl != null) {
|
|
return implicitCollectionMappingImpl;
|
|
}
|
|
ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(this.definedIn.getSuperclass(), null);
|
|
if (mapper != null) {
|
|
return mapper.getImplicitCollectionDefByItemFieldName(str);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void add(ImplicitCollectionMappingImpl implicitCollectionMappingImpl) {
|
|
this.fieldNameToDef.put(implicitCollectionMappingImpl.getFieldName(), implicitCollectionMappingImpl);
|
|
this.namedItemTypeToDef.put(implicitCollectionMappingImpl.createNamedItemType(), implicitCollectionMappingImpl);
|
|
if (implicitCollectionMappingImpl.getItemFieldName() != null) {
|
|
this.itemFieldNameToDef.put(implicitCollectionMappingImpl.getItemFieldName(), implicitCollectionMappingImpl);
|
|
}
|
|
}
|
|
|
|
public String getFieldNameForItemTypeAndName(Class cls, String str) {
|
|
Iterator it = this.namedItemTypeToDef.keySet().iterator();
|
|
ImplicitCollectionMappingImpl implicitCollectionMappingImpl = null;
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
break;
|
|
}
|
|
NamedItemType namedItemType = (NamedItemType) it.next();
|
|
ImplicitCollectionMappingImpl implicitCollectionMappingImpl2 = (ImplicitCollectionMappingImpl) this.namedItemTypeToDef.get(namedItemType);
|
|
Class cls2 = ImplicitCollectionMapper.class$com$thoughtworks$xstream$mapper$Mapper$Null;
|
|
if (cls2 == null) {
|
|
cls2 = ImplicitCollectionMapper.class$("com.thoughtworks.xstream.mapper.Mapper$Null");
|
|
ImplicitCollectionMapper.class$com$thoughtworks$xstream$mapper$Mapper$Null = cls2;
|
|
}
|
|
if (cls == cls2) {
|
|
implicitCollectionMappingImpl = implicitCollectionMappingImpl2;
|
|
break;
|
|
}
|
|
if (namedItemType.itemType.isAssignableFrom(cls)) {
|
|
if (implicitCollectionMappingImpl2.getItemFieldName() != null) {
|
|
if (implicitCollectionMappingImpl2.getItemFieldName().equals(str)) {
|
|
return implicitCollectionMappingImpl2.getFieldName();
|
|
}
|
|
} else if (implicitCollectionMappingImpl == null || implicitCollectionMappingImpl.getItemType() == null || (implicitCollectionMappingImpl2.getItemType() != null && implicitCollectionMappingImpl.getItemType().isAssignableFrom(implicitCollectionMappingImpl2.getItemType()))) {
|
|
implicitCollectionMappingImpl = implicitCollectionMappingImpl2;
|
|
}
|
|
}
|
|
}
|
|
if (implicitCollectionMappingImpl != null) {
|
|
return implicitCollectionMappingImpl.getFieldName();
|
|
}
|
|
ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(this.definedIn.getSuperclass(), null);
|
|
if (mapper != null) {
|
|
return mapper.getFieldNameForItemTypeAndName(cls, str);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Mapper.ImplicitCollectionMapping getImplicitCollectionDefForFieldName(String str) {
|
|
Mapper.ImplicitCollectionMapping implicitCollectionMapping = (Mapper.ImplicitCollectionMapping) this.fieldNameToDef.get(str);
|
|
if (implicitCollectionMapping != null) {
|
|
return implicitCollectionMapping;
|
|
}
|
|
ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(this.definedIn.getSuperclass(), null);
|
|
if (mapper != null) {
|
|
return mapper.getImplicitCollectionDefForFieldName(str);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Class getItemTypeForItemFieldName(String str) {
|
|
ImplicitCollectionMappingImpl implicitCollectionDefByItemFieldName = getImplicitCollectionDefByItemFieldName(str);
|
|
if (implicitCollectionDefByItemFieldName != null) {
|
|
return implicitCollectionDefByItemFieldName.getItemType();
|
|
}
|
|
ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(this.definedIn.getSuperclass(), null);
|
|
if (mapper != null) {
|
|
return mapper.getItemTypeForItemFieldName(str);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static class ImplicitCollectionMappingImpl implements Mapper.ImplicitCollectionMapping {
|
|
private final String fieldName;
|
|
private final String itemFieldName;
|
|
private final Class itemType;
|
|
private final String keyFieldName;
|
|
|
|
ImplicitCollectionMappingImpl(String str, Class cls, String str2, String str3) {
|
|
this.fieldName = str;
|
|
this.itemFieldName = str2;
|
|
this.itemType = cls;
|
|
this.keyFieldName = str3;
|
|
}
|
|
|
|
public NamedItemType createNamedItemType() {
|
|
return new NamedItemType(this.itemType, this.itemFieldName);
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.mapper.Mapper.ImplicitCollectionMapping
|
|
public String getFieldName() {
|
|
return this.fieldName;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.mapper.Mapper.ImplicitCollectionMapping
|
|
public String getItemFieldName() {
|
|
return this.itemFieldName;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.mapper.Mapper.ImplicitCollectionMapping
|
|
public Class getItemType() {
|
|
return this.itemType;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.mapper.Mapper.ImplicitCollectionMapping
|
|
public String getKeyFieldName() {
|
|
return this.keyFieldName;
|
|
}
|
|
}
|
|
|
|
private static class NamedItemType {
|
|
String itemFieldName;
|
|
Class itemType;
|
|
|
|
NamedItemType(Class cls, String str) {
|
|
if (cls == null && (cls = ImplicitCollectionMapper.class$java$lang$Object) == null) {
|
|
cls = ImplicitCollectionMapper.class$("java.lang.Object");
|
|
ImplicitCollectionMapper.class$java$lang$Object = cls;
|
|
}
|
|
this.itemType = cls;
|
|
this.itemFieldName = str;
|
|
}
|
|
|
|
private static boolean isEquals(Object obj, Object obj2) {
|
|
return obj == null ? obj2 == null : obj.equals(obj2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (!(obj instanceof NamedItemType)) {
|
|
return false;
|
|
}
|
|
NamedItemType namedItemType = (NamedItemType) obj;
|
|
return this.itemType.equals(namedItemType.itemType) && isEquals(this.itemFieldName, namedItemType.itemFieldName);
|
|
}
|
|
|
|
public int hashCode() {
|
|
int hashCode = this.itemType.hashCode() << 7;
|
|
String str = this.itemFieldName;
|
|
return str != null ? hashCode + str.hashCode() : hashCode;
|
|
}
|
|
}
|
|
|
|
public ImplicitCollectionMapper(Mapper mapper, ReflectionProvider reflectionProvider) {
|
|
super(mapper);
|
|
this.classNameToMapper = new HashMap();
|
|
this.reflectionProvider = reflectionProvider;
|
|
}
|
|
|
|
static /* synthetic */ Class class$(String str) {
|
|
try {
|
|
return Class.forName(str);
|
|
} catch (ClassNotFoundException e) {
|
|
throw new NoClassDefFoundError().initCause(e);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public ImplicitCollectionMapperForClass getMapper(Class cls, String str) {
|
|
Field fieldOrNull = str != null ? this.reflectionProvider.getFieldOrNull(cls, str) : null;
|
|
Class<?> declaringClass = fieldOrNull != null ? fieldOrNull.getDeclaringClass() : null;
|
|
while (cls != null) {
|
|
ImplicitCollectionMapperForClass implicitCollectionMapperForClass = (ImplicitCollectionMapperForClass) this.classNameToMapper.get(cls);
|
|
if (implicitCollectionMapperForClass != null) {
|
|
return implicitCollectionMapperForClass;
|
|
}
|
|
if (cls == declaringClass) {
|
|
break;
|
|
}
|
|
cls = cls.getSuperclass();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private ImplicitCollectionMapperForClass getOrCreateMapper(Class cls) {
|
|
ImplicitCollectionMapperForClass implicitCollectionMapperForClass = (ImplicitCollectionMapperForClass) this.classNameToMapper.get(cls);
|
|
if (implicitCollectionMapperForClass != null) {
|
|
return implicitCollectionMapperForClass;
|
|
}
|
|
ImplicitCollectionMapperForClass implicitCollectionMapperForClass2 = new ImplicitCollectionMapperForClass(cls);
|
|
this.classNameToMapper.put(cls, implicitCollectionMapperForClass2);
|
|
return implicitCollectionMapperForClass2;
|
|
}
|
|
|
|
public void add(Class cls, String str, Class cls2) {
|
|
add(cls, str, null, cls2);
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.mapper.MapperWrapper, com.thoughtworks.xstream.mapper.Mapper
|
|
public String getFieldNameForItemTypeAndName(Class cls, Class cls2, String str) {
|
|
ImplicitCollectionMapperForClass mapper = getMapper(cls, null);
|
|
if (mapper != null) {
|
|
return mapper.getFieldNameForItemTypeAndName(cls2, str);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.mapper.MapperWrapper, com.thoughtworks.xstream.mapper.Mapper
|
|
public Mapper.ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class cls, String str) {
|
|
ImplicitCollectionMapperForClass mapper = getMapper(cls, str);
|
|
if (mapper != null) {
|
|
return mapper.getImplicitCollectionDefForFieldName(str);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.mapper.MapperWrapper, com.thoughtworks.xstream.mapper.Mapper
|
|
public Class getItemTypeForItemFieldName(Class cls, String str) {
|
|
ImplicitCollectionMapperForClass mapper = getMapper(cls, null);
|
|
if (mapper != null) {
|
|
return mapper.getItemTypeForItemFieldName(str);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void add(Class cls, String str, String str2, Class cls2) {
|
|
add(cls, str, str2, cls2, null);
|
|
}
|
|
|
|
public void add(Class cls, String str, String str2, Class cls2, String str3) {
|
|
Field field;
|
|
if (cls != null) {
|
|
Class cls3 = cls;
|
|
loop0: do {
|
|
field = null;
|
|
while (true) {
|
|
Class cls4 = class$java$lang$Object;
|
|
if (cls4 == null) {
|
|
cls4 = class$("java.lang.Object");
|
|
class$java$lang$Object = cls4;
|
|
}
|
|
if (cls3 == cls4) {
|
|
break loop0;
|
|
}
|
|
try {
|
|
field = cls3.getDeclaredField(str);
|
|
break;
|
|
} catch (NoSuchFieldException unused) {
|
|
cls3 = cls3.getSuperclass();
|
|
} catch (SecurityException e) {
|
|
throw new InitializationException("Access denied for field with implicit collection", e);
|
|
}
|
|
}
|
|
} while (Modifier.isStatic(field.getModifiers()));
|
|
} else {
|
|
field = null;
|
|
}
|
|
if (field != null) {
|
|
Class cls5 = class$java$util$Map;
|
|
if (cls5 == null) {
|
|
cls5 = class$("java.util.Map");
|
|
class$java$util$Map = cls5;
|
|
}
|
|
if (!cls5.isAssignableFrom(field.getType())) {
|
|
Class cls6 = class$java$util$Collection;
|
|
if (cls6 == null) {
|
|
cls6 = class$("java.util.Collection");
|
|
class$java$util$Collection = cls6;
|
|
}
|
|
if (!cls6.isAssignableFrom(field.getType())) {
|
|
Class<?> type = field.getType();
|
|
if (type.isArray()) {
|
|
Class componentType = type.getComponentType();
|
|
if (componentType.isPrimitive()) {
|
|
componentType = Primitives.box(componentType);
|
|
}
|
|
if (cls2 == null) {
|
|
cls2 = componentType;
|
|
} else {
|
|
if (cls2.isPrimitive()) {
|
|
cls2 = Primitives.box(cls2);
|
|
}
|
|
if (!componentType.isAssignableFrom(cls2)) {
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
stringBuffer.append("Field \"");
|
|
stringBuffer.append(str);
|
|
stringBuffer.append("\" declares an array, but the array type is not compatible with ");
|
|
stringBuffer.append(cls2.getName());
|
|
throw new InitializationException(stringBuffer.toString());
|
|
}
|
|
}
|
|
} else {
|
|
StringBuffer stringBuffer2 = new StringBuffer();
|
|
stringBuffer2.append("Field \"");
|
|
stringBuffer2.append(str);
|
|
stringBuffer2.append("\" declares no collection or array");
|
|
throw new InitializationException(stringBuffer2.toString());
|
|
}
|
|
}
|
|
} else if (str2 == null && str3 == null && (cls2 = class$java$util$Map$Entry) == null) {
|
|
cls2 = class$("java.util.Map$Entry");
|
|
class$java$util$Map$Entry = cls2;
|
|
}
|
|
getOrCreateMapper(cls).add(new ImplicitCollectionMappingImpl(str, cls2, str2, str3));
|
|
return;
|
|
}
|
|
StringBuffer stringBuffer3 = new StringBuffer();
|
|
stringBuffer3.append("No field \"");
|
|
stringBuffer3.append(str);
|
|
stringBuffer3.append("\" for implicit collection");
|
|
throw new InitializationException(stringBuffer3.toString());
|
|
}
|
|
}
|