Java Code Examples for org.jpmml.model.JAXBUtil#createMarshaller()

The following examples show how to use org.jpmml.model.JAXBUtil#createMarshaller() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelProvider.java    From openscoring with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void writeTo(Model model, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException {
	Evaluator evaluator = model.getEvaluator();

	HasPMML hasPMML = (HasPMML)evaluator;

	httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_TYPE.withCharset("UTF-8"));
	httpHeaders.putSingle(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=model.pmml.xml"); // XXX

	PMML pmml = hasPMML.getPMML();

	try {
		Result result = new StreamResult(entityStream);

		Marshaller marshaller = JAXBUtil.createMarshaller();

		marshaller.marshal(pmml, result);
	} catch(JAXBException je){
		throw new InternalServerErrorException(je);
	}
}
 
Example 2
Source File: PMMLUtils.java    From oryx with Apache License 2.0 5 votes vote down vote up
/**
 * @param pmml model
 * @return model serialized as an XML document as a string
 */
public static String toString(PMML pmml) {
  try (StringWriter out = new StringWriter()) {
    // v JAXBUtil.marshalPMML but need to set compact, non-pretty output
    Marshaller marshaller = JAXBUtil.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
    marshaller.marshal(pmml, new StreamResult(out));
    return out.toString();
  } catch (JAXBException | IOException e) {
    // IOException should not be possible; JAXBException would only happen with XML
    // config problems.
    throw new IllegalStateException(e);
  }
}
 
Example 3
Source File: Example.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Marshaller createMarshaller() throws JAXBException {
	return JAXBUtil.createMarshaller();
}