/** * @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); } }
public Marshaller createMarshaller() throws JAXBException { return JAXBUtil.createMarshaller(); }
/** * <p> * Marshals any class model object. * </p> */ static public void marshal(Object object, Result result) throws JAXBException { Marshaller marshaller = createMarshaller(); marshaller.marshal(object, result); }
/** * <p> * Marshals any class model object. * </p> */ static public void marshal(Object object, Result result) throws JAXBException { Marshaller marshaller = createMarshaller(); marshaller.marshal(object, result); }
/** * @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); } }
@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); } }