use of com.opensimulationplatform.modeldescription.xml.model.OspModelDescriptionType in project osp-validator by open-simulation-platform.
the class OspModelDescriptionParser method parse.
public OspModelDescriptionType parse(File ospModelDescriptionFile) {
XMLInputFactory inputFactory = XMLInputFactory.newFactory();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try (FileInputStream fileInputStream = new FileInputStream(ospModelDescriptionFile)) {
XMLStreamReader reader = inputFactory.createXMLStreamReader(fileInputStream);
listener = new LocationListener(reader);
Schema schema = schemaFactory.newSchema(OspModelDescriptionParser.class.getResource("/OspModelDescription-1.0.0.xsd"));
JAXBContext context = JAXBContext.newInstance(OspModelDescriptionType.class.getPackage().getName());
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(schema);
unmarshaller.setListener(listener);
return (OspModelDescriptionType) JAXBIntrospector.getValue(unmarshaller.unmarshal(reader));
} catch (Exception e) {
String message = "Unable to parse '" + ospModelDescriptionFile.getAbsolutePath() + "'";
throw new RuntimeException(message, e);
}
}
use of com.opensimulationplatform.modeldescription.xml.model.OspModelDescriptionType in project osp-validator by open-simulation-platform.
the class OspModelDescriptionTypeFactoryTest method canCreate.
@Test
public void canCreate() throws Exception {
ModelDescriptionFactory factory = new ModelDescriptionFactory();
ModelDescription modelDescription = factory.create(TestResources.CRANE_CONTROLLER_XML, TestResources.CRANE_CONTROLLER_FMU.toURI());
OspModelDescriptionTypeFactory typeFactory = new OspModelDescriptionTypeFactory();
OspModelDescriptionType ospModelDescriptionType = typeFactory.create(modelDescription);
ObjectFactory objectFactory = new ObjectFactory();
JAXBContext jc = JAXBContext.newInstance(ospModelDescriptionType.getClass());
JAXBSource source = new JAXBSource(jc, objectFactory.createOspModelDescription(ospModelDescriptionType));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(OspModelDescriptionParser.class.getResource("/OspModelDescription-1.0.0.xsd"));
Validator validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) {
fail(exception.toString());
}
@Override
public void error(SAXParseException exception) {
fail(exception.toString());
}
@Override
public void fatalError(SAXParseException exception) {
fail(exception.toString());
}
});
validator.validate(source);
}
use of com.opensimulationplatform.modeldescription.xml.model.OspModelDescriptionType in project osp-validator by open-simulation-platform.
the class ModelDescriptionFactory method create.
public ModelDescription create(File ospModelDescription, URI fmu) {
OspModelDescriptionParser parser = new OspModelDescriptionParser();
OspModelDescriptionType ospModelDescriptionType = parser.parse(ospModelDescription);
OspModelDescriptionTypeConverter converter = new OspModelDescriptionTypeConverter(fmu);
return converter.convert(ospModelDescriptionType);
}
use of com.opensimulationplatform.modeldescription.xml.model.OspModelDescriptionType in project osp-validator by open-simulation-platform.
the class ModelDescriptionFactory method create.
public ModelDescription create(URI fmu) {
OspModelDescriptionType ospModelDescriptionType = new OspModelDescriptionType();
OspModelDescriptionTypeConverter converter = new OspModelDescriptionTypeConverter(fmu);
return converter.convert(ospModelDescriptionType);
}
Aggregations