Search in sources :

Example 1 with ModelDescriptionFactory

use of com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory 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 ModelDescriptionFactory

use of com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory in project osp-validator by open-simulation-platform.

the class ValidateOspModelDescriptionFile method main.

public static void main(String[] args) throws URISyntaxException {
    File ospModelDescriptionFile = new File("/path/to/OspModelDescription.xml");
    URI fmu = new URI("file:///path/to/model.fmu");
    ModelDescriptionFactory factory = new ModelDescriptionFactory();
    ModelDescription modelDescription = factory.create(ospModelDescriptionFile, fmu);
    ModelDescriptionValidator validator = new ModelDescriptionValidator();
    List<ValidationDiagnostic<Object>> diagnostics = validator.validate(modelDescription);
    for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
        System.out.println("Message: " + diagnostic.getErrorMessage());
        System.out.println("Object: " + diagnostic.getValidatedObject());
    }
}
Also used : ModelDescriptionFactory(com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory) ModelDescriptionValidator(com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) File(java.io.File) URI(java.net.URI)

Example 3 with ModelDescriptionFactory

use of com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory in project osp-validator by open-simulation-platform.

the class SimulatorConverter method getModelDescription.

private ModelDescription getModelDescription(Simulators.Simulator simulatorElement) {
    Optional<File> ospModelDescriptionFile = context.ospModelDescriptionLocator.get(simulatorElement);
    URI fmu = context.fmuLocator.get(simulatorElement);
    ModelDescriptionFactory factory = new ModelDescriptionFactory();
    if (ospModelDescriptionFile.isPresent()) {
        return factory.create(ospModelDescriptionFile.get(), fmu);
    } else {
        return factory.create(fmu);
    }
}
Also used : ModelDescriptionFactory(com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory) File(java.io.File) URI(java.net.URI)

Aggregations

ModelDescriptionFactory (com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory)3 File (java.io.File)3 URI (java.net.URI)3 ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)2 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)2 ModelDescriptionValidator (com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator)2 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)1 SystemStructure (com.opensimulationplatform.core.model.systemstructure.SystemStructure)1 OspModelDescriptionParser (com.opensimulationplatform.modeldescription.xml.parser.OspModelDescriptionParser)1 DefaultFmuLocator (com.opensimulationplatform.systemstructure.util.DefaultFmuLocator)1 DefaultOspModelDescriptionLocator (com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator)1 FmuLocator (com.opensimulationplatform.systemstructure.util.FmuLocator)1 OspModelDescriptionLocator (com.opensimulationplatform.systemstructure.util.OspModelDescriptionLocator)1 OspSystemStructure (com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure)1 Simulators (com.opensimulationplatform.systemstructure.xml.model.Simulators)1 Location (javax.xml.stream.Location)1