All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.carrot2.util.simplexml.MapSimpleXmlWrapper Maven / Gradle / Ivy


/*
 * Carrot2 project.
 *
 * Copyright (C) 2002-2016, Dawid Weiss, Stanisław Osiński.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the repository checkout or at:
 * http://www.carrot2.org/carrot2.LICENSE
 */

package org.carrot2.util.simplexml;

import java.util.HashMap;
import java.util.Map;

import org.carrot2.util.MapUtils;
import org.simpleframework.xml.ElementMap;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.core.Commit;
import org.simpleframework.xml.core.Persist;

/**
 * A wrapper for serializing maps with {@link String}s as keys.
 */
@Root(name = "map")
@SuppressWarnings(
{
    "unchecked", "rawtypes"
})
class MapSimpleXmlWrapper implements ISimpleXmlWrapper
{
    private Map map;

    @ElementMap(name = "map", attribute = true)
    private HashMap forSerialization;

    public Map getValue()
    {
        return map;
    }

    public void setValue(Map value)
    {
        map = value;
    }

    @Persist
    private void beforeSerialization()
    {
        forSerialization = MapUtils.asHashMap(SimpleXmlWrappers.wrap(map));
    }

    @Commit
    private void afterSerialization()
    {
        map = SimpleXmlWrappers.unwrap(forSerialization);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy