110 lines
4.2 KiB
Java
110 lines
4.2 KiB
Java
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;
|
|
}
|
|
}
|