Package com.coherentlogic.usaspending.client.core.converters

Source Code of com.coherentlogic.usaspending.client.core.converters.AgencyConverter

package com.coherentlogic.usaspending.client.core.converters;

import java.math.BigDecimal;

import com.coherentlogic.coherent.data.model.core.converters.AbstractConverter;
import com.coherentlogic.usaspending.client.core.domain.Agency;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;

/**
* A converter for the Agency class.
*
* @author <a href="mailto:support@coherentlogic.com">Support</a>
*/
public class AgencyConverter extends AbstractConverter {

    public static final String ID = "id", NAME = "name", RANK = "rank";

    @Override
    public Object unmarshal(
        HierarchicalStreamReader reader,
        UnmarshallingContext context
    ) {
        String id = reader.getAttribute(ID);

        String name = reader.getAttribute(NAME);

        String rankText = reader.getAttribute(RANK);
        Long rank = Long.valueOf(rankText);

        String valueText = reader.getValue();
        BigDecimal value = new BigDecimal (valueText);

        Agency agency = new Agency ();

        agency.setId(id);
        agency.setName(name);
        agency.setRank(rank);
        agency.setValue(value);

        return agency;
    }

    @Override
    public boolean canConvert(Class type) {
        return Agency.class.equals(type);
    }
}
TOP

Related Classes of com.coherentlogic.usaspending.client.core.converters.AgencyConverter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.