
jdplus.toolkit.desktop.plugin.ui.variables.actions.VariablesConfig Maven / Gradle / Ivy
/*
* Copyright 2017 National Bank of Belgium
*
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package jdplus.toolkit.desktop.plugin.ui.variables.actions;
import jdplus.toolkit.desktop.plugin.Config;
import jdplus.toolkit.desktop.plugin.Converter;
import jdplus.toolkit.base.api.timeseries.regression.ModellingContext;
import jdplus.toolkit.base.api.timeseries.regression.TsDataSuppliers;
import jdplus.toolkit.base.api.util.NameManager;
import internal.toolkit.base.workspace.file.xml.util.XmlTsVariables;
import nbbrd.io.text.Formatter;
import nbbrd.io.text.Parser;
import nbbrd.io.xml.bind.Jaxb;
/**
*
* @author Philippe Charles
*/
final class VariablesConfig implements Converter {
static final String DOMAIN = TsDataSuppliers.class.getName();
private final Formatter formatter = Jaxb.Formatter.of(XmlTsVariables.class).asFormatter();
private final Parser parser = Jaxb.Parser.of(XmlTsVariables.class).asParser();
@Override
public Config doForward(TsDataSuppliers a) {
NameManager manager = ModellingContext.getActiveContext().getTsVariableManagers();
Config.Builder result = Config.builder(DOMAIN, manager.get(a), "3.0");
XmlTsVariables xml = new XmlTsVariables();
xml.copy(a);
result.parameter("xml", formatter.formatAsString(xml));
return result.build();
}
@Override
public TsDataSuppliers doBackward(Config b) {
String tmp = b.getParameter("xml");
if (tmp != null) {
XmlTsVariables xml = parser.parse(tmp);
if (xml != null) {
TsDataSuppliers value = xml.create();
if (value != null) {
return value;
}
}
}
throw new RuntimeException("Cannot parse config");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy