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

org.openl.rules.project.xml.BaseRulesDeploySerializer Maven / Gradle / Ivy

There is a newer version: 5.27.9
Show newest version
package org.openl.rules.project.xml;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import javax.xml.bind.JAXBException;

import org.openl.rules.project.IRulesDeploySerializer;
import org.openl.rules.project.model.ObjectVersionConverter;
import org.openl.rules.project.model.RulesDeploy;

public class BaseRulesDeploySerializer implements IRulesDeploySerializer {
    private final ObjectVersionConverter rulesDeployVersionConverter;

    private final JAXBSerializer jaxbSerializer;

    public BaseRulesDeploySerializer(ObjectVersionConverter rulesDeployVersionConverter,
                                     Class clazz) {
        jaxbSerializer = new JAXBSerializer(clazz);
        this.rulesDeployVersionConverter = rulesDeployVersionConverter;
    }

    @Override
    public String serialize(RulesDeploy source) throws IOException, JAXBException {
        try (StringWriter stringWriter = new StringWriter()) {
            jaxbSerializer.marshal(rulesDeployVersionConverter.toOldVersion(source), stringWriter);
            return stringWriter.toString();
        }
    }

    @Override
    public RulesDeploy deserialize(InputStream source) throws JAXBException {
        @SuppressWarnings("unchecked")
        T oldVersion = (T) jaxbSerializer.unmarshal(source);
        return rulesDeployVersionConverter.fromOldVersion(oldVersion);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy