org.opentcs.util.persistence.ProbePlantModelTO Maven / Gradle / Ivy
/**
* Copyright (c) The openTCS Authors.
*
* This program is free software and subject to the MIT license. (For details,
* see the licensing information (LICENSE.txt) you should have received with
* this copy of the software.)
*/
package org.opentcs.util.persistence;
import java.io.IOException;
import java.io.Reader;
import static java.util.Objects.requireNonNull;
import javax.annotation.Nonnull;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.xml.sax.SAXException;
/**
* Allows reading a model file to access basic information (such as the model version) for
* validation purposes.
*
* @author Martin Grzenia (Fraunhofer IML)
*/
@XmlRootElement(name = "model")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class ProbePlantModelTO
extends BasePlantModelTO {
/**
* Unmarshals an instance of this class from the given XML representation.
*
* @param reader Provides the XML representation to parse to an instance.
* @return The instance unmarshalled from the given reader.
* @throws IOException If there was a problem unmarshalling the given string.
*/
public static ProbePlantModelTO fromXml(@Nonnull Reader reader)
throws IOException {
requireNonNull(reader, "reader");
try {
return (ProbePlantModelTO) createUnmarshaller().unmarshal(reader);
}
catch (JAXBException | SAXException exc) {
throw new IOException("Exception unmarshalling data", exc);
}
}
private static Unmarshaller createUnmarshaller()
throws JAXBException, SAXException {
Unmarshaller unmarshaller = createContext().createUnmarshaller();
return unmarshaller;
}
private static JAXBContext createContext()
throws JAXBException {
return JAXBContext.newInstance(ProbePlantModelTO.class);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy