use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.
the class OrcidMessage method marshall.
private static String marshall(Object obj) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(obj.getClass());
StringWriter writer = new StringWriter();
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(obj, writer);
return writer.toString();
}
use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.
the class ValidateV2_1SamplesTest method unmarshall.
private Object unmarshall(Reader reader, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
try {
JAXBContext context = JAXBContext.newInstance(type);
Unmarshaller unmarshaller = context.createUnmarshaller();
if (schemaPath != null) {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(getClass().getResource(schemaPath).toURI()));
unmarshaller.setSchema(schema);
}
return unmarshaller.unmarshal(reader);
} catch (JAXBException e) {
throw new RuntimeException("Unable to unmarshall orcid message" + e);
}
}
use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.
the class ValidateV2SamplesTest method marshall.
private void marshall(Object object, String path) throws JAXBException, SAXException, URISyntaxException {
JAXBContext context = JAXBContext.newInstance(object.getClass());
Marshaller marshaller = context.createMarshaller();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(getClass().getResource(path).toURI()));
marshaller.setSchema(schema);
marshaller.marshal(object, System.out);
}
use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.
the class ValidateV2SamplesTest method unmarshall.
private Object unmarshall(Reader reader, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
try {
JAXBContext context = JAXBContext.newInstance(type);
Unmarshaller unmarshaller = context.createUnmarshaller();
if (schemaPath != null) {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(getClass().getResource(schemaPath).toURI()));
unmarshaller.setSchema(schema);
}
return unmarshaller.unmarshal(reader);
} catch (JAXBException e) {
throw new RuntimeException("Unable to unmarshall orcid message" + e);
}
}
use of javax.xml.bind.JAXBContext in project opennms by OpenNMS.
the class JdbcDataCollectionConfigTest method generateSchema.
@Test
public void generateSchema() throws Exception {
File schemaFile = fa.expecting("jdbc-datacollection-config.xsd");
JAXBContext c = JAXBContext.newInstance(JdbcDataCollectionConfig.class);
c.generateSchema(new TestOutputResolver(schemaFile));
if (fa.isInitialized()) {
fa.deleteExpected();
}
}
Aggregations