Package com.javaeye.jert.service.impl

Source Code of com.javaeye.jert.service.impl.ExportImportServiceXStreamImpl

package com.javaeye.jert.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.javaeye.jert.domain.Database;
import com.javaeye.jert.domain.ParameterDefinition;
import com.javaeye.jert.domain.ReportDefinition;
import com.javaeye.jert.service.ExportImportService;
import com.thoughtworks.xstream.XStream;

/**
* @author Quake Wang
* @since 2005-1-12
* @version $Revision: 1.2 $
*/
public class ExportImportServiceXStreamImpl implements ExportImportService {
    private XStream xstream;

    public ExportImportServiceXStreamImpl() {
        xstream = new XStream();
        xstream.alias("reportdefinition", ReportDefinition.class);
        xstream.alias("parameterdefinition", ParameterDefinition.class);
    }

    public String exportToXml(ReportDefinition rd) {
        return xstream.toXML(new ReportDefinition(rd));
    }

    public String exportAllToXml(Database database) {
        List rds = new ArrayList(database.getReportDefinitions().size());
        for (Iterator iter = database.getReportDefinitions().iterator(); iter.hasNext();) {
            ReportDefinition rd = (ReportDefinition) iter.next();
            rds.add(new ReportDefinition(rd));
        }
        return xstream.toXML(rds);
    }

    public ReportDefinition[] importFromXml(String xml) {
        Object imported = xstream.fromXML(xml);
        if (imported instanceof List) {
            List result = (List) imported;
            return (ReportDefinition[]) result.toArray(new ReportDefinition[result.size()]);
        } else {
            return new ReportDefinition[] { (ReportDefinition) imported };
        }

    }
}
TOP

Related Classes of com.javaeye.jert.service.impl.ExportImportServiceXStreamImpl

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.