Initial commit
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package com.thoughtworks.xstream.converters.javabean;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BeanProperty {
|
||||
private static final Object[] EMPTY_ARGS = new Object[0];
|
||||
protected Method getter;
|
||||
private Class memberClass;
|
||||
private String propertyName;
|
||||
private Method setter;
|
||||
private Class type;
|
||||
|
||||
public BeanProperty(Class cls, String str, Class cls2) {
|
||||
this.memberClass = cls;
|
||||
this.propertyName = str;
|
||||
this.type = cls2;
|
||||
}
|
||||
|
||||
public Object get(Object obj) throws IllegalArgumentException, IllegalAccessException {
|
||||
if (isReadable()) {
|
||||
try {
|
||||
return this.getter.invoke(obj, EMPTY_ARGS);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new UndeclaredThrowableException(e.getTargetException());
|
||||
}
|
||||
}
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("Property ");
|
||||
stringBuffer.append(this.propertyName);
|
||||
stringBuffer.append(" of ");
|
||||
stringBuffer.append(this.memberClass);
|
||||
stringBuffer.append(" not readable");
|
||||
throw new IllegalStateException(stringBuffer.toString());
|
||||
}
|
||||
|
||||
public Class getBeanClass() {
|
||||
return this.memberClass;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.propertyName;
|
||||
}
|
||||
|
||||
public Class getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean isReadable() {
|
||||
return this.getter != null;
|
||||
}
|
||||
|
||||
public boolean isWritable() {
|
||||
return this.setter != null;
|
||||
}
|
||||
|
||||
public Object set(Object obj, Object obj2) throws IllegalArgumentException, IllegalAccessException {
|
||||
if (isWritable()) {
|
||||
try {
|
||||
return this.setter.invoke(obj, obj2);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new UndeclaredThrowableException(e.getTargetException());
|
||||
}
|
||||
}
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("Property ");
|
||||
stringBuffer.append(this.propertyName);
|
||||
stringBuffer.append(" of ");
|
||||
stringBuffer.append(this.memberClass);
|
||||
stringBuffer.append(" not writable");
|
||||
throw new IllegalStateException(stringBuffer.toString());
|
||||
}
|
||||
|
||||
public void setGetterMethod(Method method) {
|
||||
this.getter = method;
|
||||
}
|
||||
|
||||
public void setSetterMethod(Method method) {
|
||||
this.setter = method;
|
||||
}
|
||||
}
|
@@ -0,0 +1,169 @@
|
||||
package com.thoughtworks.xstream.converters.javabean;
|
||||
|
||||
import com.thoughtworks.xstream.converters.ConversionException;
|
||||
import com.thoughtworks.xstream.converters.ErrorWritingException;
|
||||
import com.thoughtworks.xstream.converters.javabean.JavaBeanProvider;
|
||||
import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BeanProvider implements JavaBeanProvider {
|
||||
protected static final Object[] NO_PARAMS = new Object[0];
|
||||
protected PropertyDictionary propertyDictionary;
|
||||
|
||||
public interface Visitor extends JavaBeanProvider.Visitor {
|
||||
}
|
||||
|
||||
public BeanProvider() {
|
||||
this(new PropertyDictionary(new NativePropertySorter()));
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.JavaBeanProvider
|
||||
public boolean canInstantiate(Class cls) {
|
||||
if (cls == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return newInstance(cls) != null;
|
||||
} catch (ErrorWritingException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canStreamProperty(PropertyDescriptor propertyDescriptor) {
|
||||
return (propertyDescriptor.getReadMethod() == null || propertyDescriptor.getWriteMethod() == null) ? false : true;
|
||||
}
|
||||
|
||||
protected Constructor getDefaultConstrutor(Class cls) {
|
||||
for (Constructor<?> constructor : cls.getConstructors()) {
|
||||
if (constructor.getParameterTypes().length == 0 && Modifier.isPublic(constructor.getModifiers())) {
|
||||
return constructor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected PropertyDescriptor getProperty(String str, Class cls) {
|
||||
return this.propertyDictionary.propertyDescriptor(cls, str);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.JavaBeanProvider
|
||||
public Class getPropertyType(Object obj, String str) {
|
||||
return getProperty(str, obj.getClass()).getPropertyType();
|
||||
}
|
||||
|
||||
protected PropertyDescriptor[] getSerializableProperties(Object obj) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
Iterator propertiesFor = this.propertyDictionary.propertiesFor(obj.getClass());
|
||||
while (propertiesFor.hasNext()) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) propertiesFor.next();
|
||||
if (canStreamProperty(propertyDescriptor)) {
|
||||
arrayList.add(propertyDescriptor);
|
||||
}
|
||||
}
|
||||
return (PropertyDescriptor[]) arrayList.toArray(new PropertyDescriptor[arrayList.size()]);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.JavaBeanProvider
|
||||
public Object newInstance(Class cls) {
|
||||
ErrorWritingException objectAccessException;
|
||||
try {
|
||||
return cls.newInstance();
|
||||
} catch (ExceptionInInitializerError e) {
|
||||
objectAccessException = new ConversionException("Cannot construct type", e);
|
||||
objectAccessException.add("construction-type", cls.getName());
|
||||
throw objectAccessException;
|
||||
} catch (IllegalAccessException e2) {
|
||||
objectAccessException = new ObjectAccessException("Cannot construct type", e2);
|
||||
objectAccessException.add("construction-type", cls.getName());
|
||||
throw objectAccessException;
|
||||
} catch (InstantiationException e3) {
|
||||
objectAccessException = new ConversionException("Cannot construct type", e3);
|
||||
objectAccessException.add("construction-type", cls.getName());
|
||||
throw objectAccessException;
|
||||
} catch (SecurityException e4) {
|
||||
objectAccessException = new ObjectAccessException("Cannot construct type", e4);
|
||||
objectAccessException.add("construction-type", cls.getName());
|
||||
throw objectAccessException;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.JavaBeanProvider
|
||||
public boolean propertyDefinedInClass(String str, Class cls) {
|
||||
return this.propertyDictionary.propertyDescriptorOrNull(cls, str) != null;
|
||||
}
|
||||
|
||||
public boolean propertyWriteable(String str, Class cls) {
|
||||
return getProperty(str, cls).getWriteMethod() != null;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.JavaBeanProvider
|
||||
public void visitSerializableProperties(Object obj, JavaBeanProvider.Visitor visitor) {
|
||||
ErrorWritingException conversionException;
|
||||
for (PropertyDescriptor propertyDescriptor : getSerializableProperties(obj)) {
|
||||
try {
|
||||
Method readMethod = propertyDescriptor.getReadMethod();
|
||||
String name = propertyDescriptor.getName();
|
||||
Class<?> declaringClass = readMethod.getDeclaringClass();
|
||||
if (visitor.shouldVisit(name, declaringClass)) {
|
||||
visitor.visit(name, propertyDescriptor.getPropertyType(), declaringClass, readMethod.invoke(obj, new Object[0]));
|
||||
}
|
||||
conversionException = null;
|
||||
} catch (IllegalAccessException e) {
|
||||
conversionException = new ObjectAccessException("Cannot access property", e);
|
||||
} catch (IllegalArgumentException e2) {
|
||||
conversionException = new ConversionException("Cannot get property", e2);
|
||||
} catch (InvocationTargetException e3) {
|
||||
conversionException = new ConversionException("Cannot get property", e3.getTargetException());
|
||||
}
|
||||
if (conversionException != null) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(obj.getClass());
|
||||
stringBuffer.append(".");
|
||||
stringBuffer.append(propertyDescriptor.getName());
|
||||
conversionException.add("property", stringBuffer.toString());
|
||||
throw conversionException;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.JavaBeanProvider
|
||||
public void writeProperty(Object obj, String str, Object obj2) {
|
||||
ErrorWritingException conversionException;
|
||||
PropertyDescriptor property = getProperty(str, obj.getClass());
|
||||
try {
|
||||
property.getWriteMethod().invoke(obj, obj2);
|
||||
conversionException = null;
|
||||
} catch (IllegalAccessException e) {
|
||||
conversionException = new ObjectAccessException("Cannot access property", e);
|
||||
} catch (IllegalArgumentException e2) {
|
||||
conversionException = new ConversionException("Cannot set property", e2);
|
||||
} catch (InvocationTargetException e3) {
|
||||
conversionException = new ConversionException("Cannot set property", e3.getTargetException());
|
||||
}
|
||||
if (conversionException == null) {
|
||||
return;
|
||||
}
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(obj.getClass());
|
||||
stringBuffer.append(".");
|
||||
stringBuffer.append(property.getName());
|
||||
conversionException.add("property", stringBuffer.toString());
|
||||
throw conversionException;
|
||||
}
|
||||
|
||||
public BeanProvider(Comparator comparator) {
|
||||
this(new PropertyDictionary(new ComparingPropertySorter(comparator)));
|
||||
}
|
||||
|
||||
public BeanProvider(PropertyDictionary propertyDictionary) {
|
||||
this.propertyDictionary = propertyDictionary;
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.thoughtworks.xstream.converters.javabean;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ComparingPropertySorter implements PropertySorter {
|
||||
private final Comparator comparator;
|
||||
|
||||
public ComparingPropertySorter(Comparator comparator) {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.PropertySorter
|
||||
public Map sort(Class cls, Map map) {
|
||||
TreeMap treeMap = new TreeMap(this.comparator);
|
||||
treeMap.putAll(map);
|
||||
return treeMap;
|
||||
}
|
||||
}
|
@@ -0,0 +1,186 @@
|
||||
package com.thoughtworks.xstream.converters.javabean;
|
||||
|
||||
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.converters.javabean.JavaBeanProvider;
|
||||
import com.thoughtworks.xstream.converters.reflection.MissingFieldException;
|
||||
import com.thoughtworks.xstream.core.util.FastField;
|
||||
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.util.HashSet;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class JavaBeanConverter implements Converter {
|
||||
static /* synthetic */ Class class$com$thoughtworks$xstream$mapper$Mapper$Null;
|
||||
protected final JavaBeanProvider beanProvider;
|
||||
private String classAttributeIdentifier;
|
||||
protected final Mapper mapper;
|
||||
private final Class type;
|
||||
|
||||
public static class DuplicateFieldException extends ConversionException {
|
||||
public DuplicateFieldException(String str) {
|
||||
super(str);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DuplicatePropertyException 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 DuplicatePropertyException(java.lang.String r3) {
|
||||
/*
|
||||
r2 = this;
|
||||
java.lang.StringBuffer r0 = new java.lang.StringBuffer
|
||||
r0.<init>()
|
||||
java.lang.String r1 = "Duplicate property "
|
||||
r0.append(r1)
|
||||
r0.append(r3)
|
||||
java.lang.String r0 = r0.toString()
|
||||
r2.<init>(r0)
|
||||
java.lang.String r0 = "property"
|
||||
r2.add(r0, r3)
|
||||
return
|
||||
*/
|
||||
throw new UnsupportedOperationException("Method not decompiled: com.thoughtworks.xstream.converters.javabean.JavaBeanConverter.DuplicatePropertyException.<init>(java.lang.String):void");
|
||||
}
|
||||
}
|
||||
|
||||
public JavaBeanConverter(Mapper mapper) {
|
||||
this(mapper, (Class) null);
|
||||
}
|
||||
|
||||
static /* synthetic */ Class class$(String str) {
|
||||
try {
|
||||
return Class.forName(str);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new NoClassDefFoundError().initCause(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Class determineType(HierarchicalStreamReader hierarchicalStreamReader, Object obj, String str) {
|
||||
String str2 = this.classAttributeIdentifier;
|
||||
if (str2 == null) {
|
||||
str2 = this.mapper.aliasForSystemAttribute("class");
|
||||
}
|
||||
String attribute = str2 == null ? null : hierarchicalStreamReader.getAttribute(str2);
|
||||
return attribute != null ? this.mapper.realClass(attribute) : this.mapper.defaultImplementationOf(this.beanProvider.getPropertyType(obj, str));
|
||||
}
|
||||
|
||||
private Object instantiateNewInstance(UnmarshallingContext unmarshallingContext) {
|
||||
Object currentObject = unmarshallingContext.currentObject();
|
||||
return currentObject == null ? this.beanProvider.newInstance(unmarshallingContext.getRequiredType()) : currentObject;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.ConverterMatcher
|
||||
public boolean canConvert(Class cls) {
|
||||
Class cls2 = this.type;
|
||||
return (cls2 == null || cls2 == cls) && this.beanProvider.canInstantiate(cls);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.Converter
|
||||
public void marshal(final Object obj, final HierarchicalStreamWriter hierarchicalStreamWriter, final MarshallingContext marshallingContext) {
|
||||
final String aliasForSystemAttribute = this.mapper.aliasForSystemAttribute("class");
|
||||
this.beanProvider.visitSerializableProperties(obj, new JavaBeanProvider.Visitor() { // from class: com.thoughtworks.xstream.converters.javabean.JavaBeanConverter.1
|
||||
private void writeField(String str, Class cls, Object obj2) {
|
||||
String str2;
|
||||
Class<?> cls2 = obj2.getClass();
|
||||
Class defaultImplementationOf = JavaBeanConverter.this.mapper.defaultImplementationOf(cls);
|
||||
ExtendedHierarchicalStreamWriterHelper.startNode(hierarchicalStreamWriter, JavaBeanConverter.this.mapper.serializedMember(obj.getClass(), str), cls2);
|
||||
if (!cls2.equals(defaultImplementationOf) && (str2 = aliasForSystemAttribute) != null) {
|
||||
hierarchicalStreamWriter.addAttribute(str2, JavaBeanConverter.this.mapper.serializedClass(cls2));
|
||||
}
|
||||
marshallingContext.convertAnother(obj2);
|
||||
hierarchicalStreamWriter.endNode();
|
||||
}
|
||||
|
||||
private void writeNullField(String str) {
|
||||
String serializedMember = JavaBeanConverter.this.mapper.serializedMember(obj.getClass(), str);
|
||||
HierarchicalStreamWriter hierarchicalStreamWriter2 = hierarchicalStreamWriter;
|
||||
Class cls = JavaBeanConverter.class$com$thoughtworks$xstream$mapper$Mapper$Null;
|
||||
if (cls == null) {
|
||||
cls = JavaBeanConverter.class$("com.thoughtworks.xstream.mapper.Mapper$Null");
|
||||
JavaBeanConverter.class$com$thoughtworks$xstream$mapper$Mapper$Null = cls;
|
||||
}
|
||||
ExtendedHierarchicalStreamWriterHelper.startNode(hierarchicalStreamWriter2, serializedMember, cls);
|
||||
HierarchicalStreamWriter hierarchicalStreamWriter3 = hierarchicalStreamWriter;
|
||||
String str2 = aliasForSystemAttribute;
|
||||
Mapper mapper = JavaBeanConverter.this.mapper;
|
||||
Class cls2 = JavaBeanConverter.class$com$thoughtworks$xstream$mapper$Mapper$Null;
|
||||
if (cls2 == null) {
|
||||
cls2 = JavaBeanConverter.class$("com.thoughtworks.xstream.mapper.Mapper$Null");
|
||||
JavaBeanConverter.class$com$thoughtworks$xstream$mapper$Mapper$Null = cls2;
|
||||
}
|
||||
hierarchicalStreamWriter3.addAttribute(str2, mapper.serializedClass(cls2));
|
||||
hierarchicalStreamWriter.endNode();
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.JavaBeanProvider.Visitor
|
||||
public boolean shouldVisit(String str, Class cls) {
|
||||
return JavaBeanConverter.this.mapper.shouldSerializeMember(cls, str);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.JavaBeanProvider.Visitor
|
||||
public void visit(String str, Class cls, Class cls2, Object obj2) {
|
||||
if (obj2 != null) {
|
||||
writeField(str, cls, obj2);
|
||||
} else {
|
||||
writeNullField(str);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.Converter
|
||||
public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) {
|
||||
Object instantiateNewInstance = instantiateNewInstance(unmarshallingContext);
|
||||
HashSet hashSet = new HashSet() { // from class: com.thoughtworks.xstream.converters.javabean.JavaBeanConverter.2
|
||||
@Override // java.util.HashSet, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
||||
public boolean add(Object obj) {
|
||||
if (super.add(obj)) {
|
||||
return true;
|
||||
}
|
||||
throw new DuplicatePropertyException(((FastField) obj).getName());
|
||||
}
|
||||
};
|
||||
Class<?> cls = instantiateNewInstance.getClass();
|
||||
while (hierarchicalStreamReader.hasMoreChildren()) {
|
||||
hierarchicalStreamReader.moveDown();
|
||||
String realMember = this.mapper.realMember(cls, hierarchicalStreamReader.getNodeName());
|
||||
if (this.mapper.shouldSerializeMember(cls, realMember)) {
|
||||
if (this.beanProvider.propertyDefinedInClass(realMember, cls)) {
|
||||
this.beanProvider.writeProperty(instantiateNewInstance, realMember, unmarshallingContext.convertAnother(instantiateNewInstance, determineType(hierarchicalStreamReader, instantiateNewInstance, realMember)));
|
||||
hashSet.add(new FastField(cls, realMember));
|
||||
} else if (!this.mapper.isIgnoredElement(realMember)) {
|
||||
throw new MissingFieldException(cls.getName(), realMember);
|
||||
}
|
||||
}
|
||||
hierarchicalStreamReader.moveUp();
|
||||
}
|
||||
return instantiateNewInstance;
|
||||
}
|
||||
|
||||
public JavaBeanConverter(Mapper mapper, Class cls) {
|
||||
this(mapper, new BeanProvider(), cls);
|
||||
}
|
||||
|
||||
public JavaBeanConverter(Mapper mapper, JavaBeanProvider javaBeanProvider) {
|
||||
this(mapper, javaBeanProvider, null);
|
||||
}
|
||||
|
||||
public JavaBeanConverter(Mapper mapper, JavaBeanProvider javaBeanProvider, Class cls) {
|
||||
this.mapper = mapper;
|
||||
this.beanProvider = javaBeanProvider;
|
||||
this.type = cls;
|
||||
}
|
||||
|
||||
public JavaBeanConverter(Mapper mapper, String str) {
|
||||
this(mapper, new BeanProvider());
|
||||
this.classAttributeIdentifier = str;
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package com.thoughtworks.xstream.converters.javabean;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface JavaBeanProvider {
|
||||
|
||||
public interface Visitor {
|
||||
boolean shouldVisit(String str, Class cls);
|
||||
|
||||
void visit(String str, Class cls, Class cls2, Object obj);
|
||||
}
|
||||
|
||||
boolean canInstantiate(Class cls);
|
||||
|
||||
Class getPropertyType(Object obj, String str);
|
||||
|
||||
Object newInstance(Class cls);
|
||||
|
||||
boolean propertyDefinedInClass(String str, Class cls);
|
||||
|
||||
void visitSerializableProperties(Object obj, Visitor visitor);
|
||||
|
||||
void writeProperty(Object obj, String str, Object obj2);
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.thoughtworks.xstream.converters.javabean;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class NativePropertySorter implements PropertySorter {
|
||||
@Override // com.thoughtworks.xstream.converters.javabean.PropertySorter
|
||||
public Map sort(Class cls, Map map) {
|
||||
return map;
|
||||
}
|
||||
}
|
@@ -0,0 +1,109 @@
|
||||
package com.thoughtworks.xstream.converters.javabean;
|
||||
|
||||
import com.thoughtworks.xstream.converters.reflection.MissingFieldException;
|
||||
import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
|
||||
import com.thoughtworks.xstream.core.Caching;
|
||||
import com.thoughtworks.xstream.core.util.OrderRetainingMap;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class PropertyDictionary implements Caching {
|
||||
static /* synthetic */ Class class$java$lang$Object;
|
||||
private transient Map propertyNameCache;
|
||||
private final PropertySorter sorter;
|
||||
|
||||
public PropertyDictionary() {
|
||||
this(new NativePropertySorter());
|
||||
}
|
||||
|
||||
private Map buildMap(Class cls) {
|
||||
Class cls2;
|
||||
Map map = (Map) this.propertyNameCache.get(cls);
|
||||
if (map != null) {
|
||||
return map;
|
||||
}
|
||||
try {
|
||||
if (class$java$lang$Object == null) {
|
||||
cls2 = class$("java.lang.Object");
|
||||
class$java$lang$Object = cls2;
|
||||
} else {
|
||||
cls2 = class$java$lang$Object;
|
||||
}
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(cls, cls2);
|
||||
OrderRetainingMap orderRetainingMap = new OrderRetainingMap();
|
||||
for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
|
||||
orderRetainingMap.put(propertyDescriptor.getName(), propertyDescriptor);
|
||||
}
|
||||
Map sort = this.sorter.sort(cls, orderRetainingMap);
|
||||
this.propertyNameCache.put(cls, sort);
|
||||
return sort;
|
||||
} catch (IntrospectionException e) {
|
||||
ObjectAccessException objectAccessException = new ObjectAccessException("Cannot get BeanInfo of type", e);
|
||||
objectAccessException.add("bean-type", cls.getName());
|
||||
throw objectAccessException;
|
||||
}
|
||||
}
|
||||
|
||||
static /* synthetic */ Class class$(String str) {
|
||||
try {
|
||||
return Class.forName(str);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new NoClassDefFoundError().initCause(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.core.Caching
|
||||
public void flushCache() {
|
||||
this.propertyNameCache.clear();
|
||||
}
|
||||
|
||||
public Iterator propertiesFor(Class cls) {
|
||||
return buildMap(cls).values().iterator();
|
||||
}
|
||||
|
||||
public BeanProperty property(Class cls, String str) {
|
||||
PropertyDescriptor propertyDescriptorOrNull = propertyDescriptorOrNull(cls, str);
|
||||
if (propertyDescriptorOrNull == null) {
|
||||
throw new MissingFieldException(cls.getName(), str);
|
||||
}
|
||||
if (propertyDescriptorOrNull.getReadMethod() == null || propertyDescriptorOrNull.getWriteMethod() == null) {
|
||||
return null;
|
||||
}
|
||||
return new BeanProperty(cls, propertyDescriptorOrNull.getName(), propertyDescriptorOrNull.getPropertyType());
|
||||
}
|
||||
|
||||
public PropertyDescriptor propertyDescriptor(Class cls, String str) {
|
||||
PropertyDescriptor propertyDescriptorOrNull = propertyDescriptorOrNull(cls, str);
|
||||
if (propertyDescriptorOrNull != null) {
|
||||
return propertyDescriptorOrNull;
|
||||
}
|
||||
throw new MissingFieldException(cls.getName(), str);
|
||||
}
|
||||
|
||||
public PropertyDescriptor propertyDescriptorOrNull(Class cls, String str) {
|
||||
return (PropertyDescriptor) buildMap(cls).get(str);
|
||||
}
|
||||
|
||||
public Iterator serializablePropertiesFor(Class cls) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
for (PropertyDescriptor propertyDescriptor : buildMap(cls).values()) {
|
||||
if (propertyDescriptor.getReadMethod() != null && propertyDescriptor.getWriteMethod() != null) {
|
||||
arrayList.add(new BeanProperty(cls, propertyDescriptor.getName(), propertyDescriptor.getPropertyType()));
|
||||
}
|
||||
}
|
||||
return arrayList.iterator();
|
||||
}
|
||||
|
||||
public PropertyDictionary(PropertySorter propertySorter) {
|
||||
this.propertyNameCache = Collections.synchronizedMap(new HashMap());
|
||||
this.sorter = propertySorter;
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.thoughtworks.xstream.converters.javabean;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface PropertySorter {
|
||||
Map sort(Class cls, Map map);
|
||||
}
|
Reference in New Issue
Block a user