Search in sources :

Example 6 with OspSystemStructure

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);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) Schema(javax.xml.validation.Schema) JAXBContext(javax.xml.bind.JAXBContext) FileInputStream(java.io.FileInputStream) Unmarshaller(javax.xml.bind.Unmarshaller) XMLInputFactory(javax.xml.stream.XMLInputFactory) OspSystemStructure(com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure)

Example 7 with OspSystemStructure

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);
}
Also used : OspSystemStructureParser(com.opensimulationplatform.systemstructure.xml.parser.OspSystemStructureParser) ConverterContext(com.opensimulationplatform.systemstructure.xml.converter.ConverterContext) DefaultFmuLocator(com.opensimulationplatform.systemstructure.util.DefaultFmuLocator) OspSystemStructureConverter(com.opensimulationplatform.systemstructure.xml.converter.OspSystemStructureConverter) OspSystemStructure(com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure) DefaultOspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator)

Aggregations

OspSystemStructure (com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure)7 SystemStructure (com.opensimulationplatform.core.model.systemstructure.SystemStructure)3 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)2 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)2 DefaultFmuLocator (com.opensimulationplatform.systemstructure.util.DefaultFmuLocator)2 DefaultOspModelDescriptionLocator (com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator)2 Connections (com.opensimulationplatform.systemstructure.xml.model.Connections)2 Simulators (com.opensimulationplatform.systemstructure.xml.model.Simulators)2 OspSystemStructureParser (com.opensimulationplatform.systemstructure.xml.parser.OspSystemStructureParser)2 ArrayList (java.util.ArrayList)2 Location (javax.xml.stream.Location)2 ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)1 VariableConnection (com.opensimulationplatform.core.model.systemstructure.VariableConnection)1 VariableGroupConnection (com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection)1 ModelDescriptionValidator (com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator)1 SystemStructureValidator (com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator)1 ModelDescriptionFactory (com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory)1 OspModelDescriptionParser (com.opensimulationplatform.modeldescription.xml.parser.OspModelDescriptionParser)1 FmuLocator (com.opensimulationplatform.systemstructure.util.FmuLocator)1 OspModelDescriptionLocator (com.opensimulationplatform.systemstructure.util.OspModelDescriptionLocator)1