package com.thoughtworks.xstream.converters.extended; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.core.JVM; 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.awt.Font; import java.awt.font.TextAttribute; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import javax.swing.plaf.FontUIResource; /* loaded from: classes.dex */ public class FontConverter implements Converter { static /* synthetic */ Class class$com$thoughtworks$xstream$mapper$Mapper$Null; static /* synthetic */ Class class$java$util$Map; static /* synthetic */ Class class$javax$swing$plaf$FontUIResource; private final Mapper mapper; private final SingleValueConverter textAttributeConverter; public FontConverter() { this(null); } 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 != null && (cls.getName().equals("java.awt.Font") || cls.getName().equals("javax.swing.plaf.FontUIResource")); } @Override // com.thoughtworks.xstream.converters.Converter public void marshal(Object obj, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) { Class cls; Map attributes = ((Font) obj).getAttributes(); Mapper mapper = this.mapper; if (mapper == null) { hierarchicalStreamWriter.startNode("attributes"); marshallingContext.convertAnother(attributes); hierarchicalStreamWriter.endNode(); return; } String aliasForSystemAttribute = mapper.aliasForSystemAttribute("class"); for (Map.Entry entry : attributes.entrySet()) { String singleValueConverter = this.textAttributeConverter.toString(entry.getKey()); Object value = entry.getValue(); if (value != null) { cls = value.getClass(); } else { 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; } } ExtendedHierarchicalStreamWriterHelper.startNode(hierarchicalStreamWriter, singleValueConverter, cls); hierarchicalStreamWriter.addAttribute(aliasForSystemAttribute, this.mapper.serializedClass(cls)); if (value != null) { marshallingContext.convertAnother(value); } hierarchicalStreamWriter.endNode(); } } @Override // com.thoughtworks.xstream.converters.Converter public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) { Map map; if (hierarchicalStreamReader.hasMoreChildren()) { hierarchicalStreamReader.moveDown(); if (hierarchicalStreamReader.getNodeName().equals("attributes")) { Class cls = class$java$util$Map; if (cls == null) { cls = class$("java.util.Map"); class$java$util$Map = cls; } map = (Map) unmarshallingContext.convertAnother(null, cls); hierarchicalStreamReader.moveUp(); } else { String aliasForSystemAttribute = this.mapper.aliasForSystemAttribute("class"); map = new HashMap(); do { if (!map.isEmpty()) { hierarchicalStreamReader.moveDown(); } Class realClass = this.mapper.realClass(hierarchicalStreamReader.getAttribute(aliasForSystemAttribute)); TextAttribute textAttribute = (TextAttribute) this.textAttributeConverter.fromString(hierarchicalStreamReader.getNodeName()); Class cls2 = class$com$thoughtworks$xstream$mapper$Mapper$Null; if (cls2 == null) { cls2 = class$("com.thoughtworks.xstream.mapper.Mapper$Null"); class$com$thoughtworks$xstream$mapper$Mapper$Null = cls2; } map.put(textAttribute, realClass == cls2 ? null : unmarshallingContext.convertAnother(null, realClass)); hierarchicalStreamReader.moveUp(); } while (hierarchicalStreamReader.hasMoreChildren()); } } else { map = Collections.EMPTY_MAP; } if (!JVM.isVersion(6)) { Iterator it = map.values().iterator(); while (it.hasNext()) { if (it.next() == null) { it.remove(); } } } Font font = Font.getFont(map); Class requiredType = unmarshallingContext.getRequiredType(); Class cls3 = class$javax$swing$plaf$FontUIResource; if (cls3 == null) { cls3 = class$("javax.swing.plaf.FontUIResource"); class$javax$swing$plaf$FontUIResource = cls3; } return requiredType == cls3 ? new FontUIResource(font) : font; } public FontConverter(Mapper mapper) { this.mapper = mapper; if (mapper == null) { this.textAttributeConverter = null; } else { this.textAttributeConverter = new TextAttributeConverter(); } } }