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

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

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

import java.io.InputStream;

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

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class XmlRulesDeploySerializer implements IRulesDeploySerializer {
    public final static String RULES_DEPLOY_DESCRIPTOR_TAG = "rules-deploy";
    public final static String MODULE_NAME = "module";
    public final static String LAZY_MODULES_FOR_COMPILATION = "lazy-modules-for-compilation";

    private XStream xstream;

    public XmlRulesDeploySerializer() {
        xstream = new XStream(new DomDriver());
        xstream.ignoreUnknownElements();
        xstream.omitField(RulesDeploy.class, "log");

        xstream.setMode(XStream.NO_REFERENCES);
        
        xstream.aliasType("publisher", RulesDeploy.PublisherType.class);
        xstream.aliasType(RULES_DEPLOY_DESCRIPTOR_TAG, RulesDeploy.class);
        xstream.aliasType(MODULE_NAME, RulesDeploy.WildcardPattern.class);
        
        xstream.aliasField(LAZY_MODULES_FOR_COMPILATION, RulesDeploy.class, "lazyModulesForCompilationPatterns");
        
        xstream.aliasField("name", RulesDeploy.WildcardPattern.class, "value");
        xstream.useAttributeFor(RulesDeploy.WildcardPattern.class, "value");
    }

    public XStream getXstream() {
        return xstream;
    }

    public String serialize(RulesDeploy source) {
        return xstream.toXML(source);
    }

    public RulesDeploy deserialize(InputStream source) {
        return (RulesDeploy) xstream.fromXML(source);
    }

    public RulesDeploy deserialize(String source) {
        return (RulesDeploy) xstream.fromXML(source);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy