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;
}
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());
}
}
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);
}
}
Aggregations