Search in sources :

Example 1 with DefaultFmuLocator

use of com.opensimulationplatform.systemstructure.util.DefaultFmuLocator in project osp-validator by open-simulation-platform.

the class Validator method getModelDescriptionErrorMessages.

private List<String> getModelDescriptionErrorMessages(File ospSystemStructureFile, OspSystemStructure ospSystemStructureElement) {
    List<String> errorMessages = new ArrayList<>();
    for (Simulators.Simulator simulator : ospSystemStructureElement.getSimulators().getSimulator()) {
        FmuLocator fmuLocator = new DefaultFmuLocator(ospSystemStructureFile);
        URI fmu = fmuLocator.get(simulator);
        OspModelDescriptionLocator ospModelDescriptionLocator = new DefaultOspModelDescriptionLocator(ospSystemStructureFile, fmuLocator);
        Optional<File> ospModelDescriptionXml = ospModelDescriptionLocator.get(simulator);
        if (ospModelDescriptionXml.isPresent()) {
            OspModelDescriptionParser parser = new OspModelDescriptionParser();
            OspModelDescriptionType ospModelDescriptionElement = parser.parse(ospModelDescriptionXml.get());
            Map<Object, Location> locations = parser.getLocations();
            ModelDescriptionFactory factory = new ModelDescriptionFactory();
            ModelDescription modelDescription = factory.create(ospModelDescriptionXml.get(), fmu);
            Simulator s = new Simulator();
            s.setName(simulator.getName());
            s.setModelDescription(modelDescription);
            SystemStructure systemStructure = new SystemStructure();
            systemStructure.getSimulators().add(s);
            ModelDescriptionValidator validator = new ModelDescriptionValidator();
            List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
            Map<Object, Object> coreToJaxb = createModelDescriptionMap(ospModelDescriptionElement, modelDescription);
            errorMessages.addAll(getErrorMessages(ospModelDescriptionXml.get(), locations, diagnostics, coreToJaxb));
        }
    }
    return errorMessages;
}
Also used : ModelDescriptionFactory(com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory) OspSystemStructure(com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) URI(java.net.URI) OspModelDescriptionParser(com.opensimulationplatform.modeldescription.xml.parser.OspModelDescriptionParser) DefaultFmuLocator(com.opensimulationplatform.systemstructure.util.DefaultFmuLocator) FmuLocator(com.opensimulationplatform.systemstructure.util.FmuLocator) ModelDescriptionValidator(com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Simulators(com.opensimulationplatform.systemstructure.xml.model.Simulators) DefaultOspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator) OspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.OspModelDescriptionLocator) DefaultOspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator) DefaultFmuLocator(com.opensimulationplatform.systemstructure.util.DefaultFmuLocator) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) File(java.io.File) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Location(javax.xml.stream.Location)

Example 2 with DefaultFmuLocator

use of com.opensimulationplatform.systemstructure.util.DefaultFmuLocator 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

DefaultFmuLocator (com.opensimulationplatform.systemstructure.util.DefaultFmuLocator)2 DefaultOspModelDescriptionLocator (com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator)2 OspSystemStructure (com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure)2 ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)1 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)1 SystemStructure (com.opensimulationplatform.core.model.systemstructure.SystemStructure)1 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)1 ModelDescriptionValidator (com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator)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 ConverterContext (com.opensimulationplatform.systemstructure.xml.converter.ConverterContext)1 OspSystemStructureConverter (com.opensimulationplatform.systemstructure.xml.converter.OspSystemStructureConverter)1 Simulators (com.opensimulationplatform.systemstructure.xml.model.Simulators)1 OspSystemStructureParser (com.opensimulationplatform.systemstructure.xml.parser.OspSystemStructureParser)1 File (java.io.File)1 URI (java.net.URI)1 Location (javax.xml.stream.Location)1