public Object unmarshal()

in xstream/src/java/com/thoughtworks/xstream/converters/extended/FontConverter.java [98:138]


    public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
        final Map<TextAttribute, Object> attributes;
        if (reader.hasMoreChildren()) {
            reader.moveDown();
            if (!reader.getNodeName().equals("attributes")) {
                final String classAlias = mapper.aliasForSystemAttribute("class");
                attributes = new HashMap<>();
                do {
                    if (!attributes.isEmpty()) {
                        reader.moveDown();
                    }
                    final Class<?> type = mapper.realClass(reader.getAttribute(classAlias));
                    final TextAttribute attribute = (TextAttribute)textAttributeConverter.fromString(reader
                        .getNodeName());
                    final Object value = type == Mapper.Null.class ? null : context.convertAnother(null, type);
                    attributes.put(attribute, value);
                    reader.moveUp();
                } while (reader.hasMoreChildren());
            } else {
                // in <attributes>
                @SuppressWarnings("unchecked")
                final Map<TextAttribute, Object> typedAttributes = (Map<TextAttribute, Object>)context.convertAnother(
                    null, Map.class);
                attributes = typedAttributes;
                reader.moveUp(); // out of </attributes>
            }
        } else {
            attributes = Collections.emptyMap();
        }
        for (final Iterator<?> iter = attributes.values().iterator(); iter.hasNext();) {
            if (iter.next() == null) {
                iter.remove();
            }
        }
        final Font font = Font.getFont(attributes);
        if (context.getRequiredType() == FontUIResource.class) {
            return new FontUIResource(font);
        } else {
            return font;
        }
    }