Search in sources :

Example 1 with ObjectFactory

use of com.opensimulationplatform.modeldescription.xml.model.ObjectFactory 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);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) ErrorHandler(org.xml.sax.ErrorHandler) OspModelDescriptionType(com.opensimulationplatform.modeldescription.xml.model.OspModelDescriptionType) Schema(javax.xml.validation.Schema) JAXBContext(javax.xml.bind.JAXBContext) OspModelDescriptionParser(com.opensimulationplatform.modeldescription.xml.parser.OspModelDescriptionParser) JAXBSource(javax.xml.bind.util.JAXBSource) ObjectFactory(com.opensimulationplatform.modeldescription.xml.model.ObjectFactory) SAXParseException(org.xml.sax.SAXParseException) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Validator(javax.xml.validation.Validator) Test(org.junit.Test)

Aggregations

ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)1 ObjectFactory (com.opensimulationplatform.modeldescription.xml.model.ObjectFactory)1 OspModelDescriptionType (com.opensimulationplatform.modeldescription.xml.model.OspModelDescriptionType)1 OspModelDescriptionParser (com.opensimulationplatform.modeldescription.xml.parser.OspModelDescriptionParser)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBSource (javax.xml.bind.util.JAXBSource)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 Validator (javax.xml.validation.Validator)1 Test (org.junit.Test)1 ErrorHandler (org.xml.sax.ErrorHandler)1 SAXParseException (org.xml.sax.SAXParseException)1