use of com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure in project osp-validator by open-simulation-platform.
the class OspSystemStructureParser method parse.
public OspSystemStructure parse(File ospSystemStructureFile) {
XMLInputFactory inputFactory = XMLInputFactory.newFactory();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try (FileInputStream fileInputStream = new FileInputStream(ospSystemStructureFile)) {
XMLStreamReader reader = inputFactory.createXMLStreamReader(fileInputStream);
listener = new LocationListener(reader);
Schema schema = schemaFactory.newSchema(OspSystemStructureParser.class.getResource("/OspSystemStructure.xsd"));
JAXBContext context = JAXBContext.newInstance(OspSystemStructure.class.getPackage().getName());
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(schema);
unmarshaller.setListener(listener);
return (OspSystemStructure) JAXBIntrospector.getValue(unmarshaller.unmarshal(reader));
} catch (Exception e) {
String message = "Unable to parse '" + ospSystemStructureFile.getAbsolutePath() + "'";
throw new RuntimeException(message, e);
}
}
use of com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure in project osp-validator by open-simulation-platform.
the class SystemStructureFactory method create.
public SystemStructure create(File ospSystemStructureFile) {
OspSystemStructureParser parser = new OspSystemStructureParser();
OspSystemStructure ospSystemStructure = parser.parse(ospSystemStructureFile);
if (fmuLocator == null) {
fmuLocator = new DefaultFmuLocator(ospSystemStructureFile);
}
if (ospModelDescriptionLocator == null) {
ospModelDescriptionLocator = new DefaultOspModelDescriptionLocator(ospSystemStructureFile, fmuLocator);
}
ConverterContext context = new ConverterContext();
context.ospModelDescriptionLocator = ospModelDescriptionLocator;
context.fmuLocator = fmuLocator;
OspSystemStructureConverter converter = new OspSystemStructureConverter(context);
return converter.convert(ospSystemStructure);
}
Aggregations