List of usage examples for javax.xml.bind JAXBContext createMarshaller
public abstract Marshaller createMarshaller() throws JAXBException;
From source file:org.castor.jaxb.allannotations.XmlValueTest.java
@Test public void testFullCycle() throws JAXBException { JAXBContext context = JAXBContext.newInstance(ForXmlValue.class); Marshaller m = context.createMarshaller(); StringWriter sw = new StringWriter(); ForXmlValue fxv = new ForXmlValue(); fxv.content = new BigDecimal(4711); m.marshal(fxv, sw);// w ww .j a v a 2s . c om System.out.println(sw.toString()); }
From source file:au.id.hazelwood.xmltvguidebuilder.binding.BindingService.java
public BindingService(String contextPath) throws JAXBException { StopWatch stopWatch = new StopWatch(); stopWatch.start();//from w w w .j av a 2 s .c o m JAXBContext jaxbContext = JAXBContext.newInstance(contextPath); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); stopWatch.stop(); LOGGER.debug("BindingService created for {} in {}", contextPath, formatDurationWords(stopWatch.getTime())); }
From source file:org.mule.modules.rest.model.LeagueTransformers.java
@Transformer(resultMimeType = "text/xml") public String toXml(League league) throws IOException, JAXBException { JAXBContext context = JAXBContext.newInstance(League.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ByteArrayOutputStream boas = new ByteArrayOutputStream(); m.marshal(league, boas);/*w ww.j a v a 2 s .c o m*/ return new String(boas.toByteArray()); }
From source file:com.tremolosecurity.openunison.util.OpenUnisonUtils.java
private static void storeMethod(String unisonXMLFile, TremoloType tt, String ksPath, KeyStore ks) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, JAXBException, PropertyException { logger.info("Storing the keystore"); ks.store(new FileOutputStream(ksPath), tt.getKeyStorePassword().toCharArray()); logger.info("Saving the unison xml file"); JAXBContext jc = JAXBContext.newInstance("com.tremolosecurity.config.xml"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); OutputStream os = new FileOutputStream(unisonXMLFile); JAXBElement<TremoloType> root = new JAXBElement<TremoloType>( new QName("http://www.tremolosecurity.com/tremoloConfig", "tremoloConfig", "tns"), TremoloType.class, tt); marshaller.marshal(root, os);/* w ww.j a va 2 s . c o m*/ os.flush(); os.close(); }
From source file:org.mule.module.apikit.leagues.Teams.java
@Transformer(resultMimeType = "text/xml") public String toXml(Teams teams) throws IOException, JAXBException { JAXBContext context = JAXBContext.newInstance(getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ByteArrayOutputStream boas = new ByteArrayOutputStream(); m.marshal(teams, boas);/*from ww w . ja v a2 s . c om*/ return new String(boas.toByteArray()); }
From source file:org.mule.module.apikit.leagues.Leagues.java
@Transformer(resultMimeType = "text/xml") public String toXml(Leagues leagues) throws IOException, JAXBException { JAXBContext context = JAXBContext.newInstance(getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ByteArrayOutputStream boas = new ByteArrayOutputStream(); m.marshal(leagues, boas);// w w w. j a va 2 s . co m return new String(boas.toByteArray()); }
From source file:Product.java
public String toXML() throws JAXBException { ByteArrayOutputStream out = new ByteArrayOutputStream(); JAXBContext context = JAXBContext.newInstance(Product.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(this, out); return out.toString(); }
From source file:jails.http.converter.xml.AbstractJaxb2HttpMessageConverter.java
/** * Creates a new {@link Marshaller} for the given class. * * @param clazz the class to create the marshaller for * @return the {@code Marshaller}/*from w w w. j a va2 s .c om*/ * @throws HttpMessageConversionException in case of JAXB errors */ protected final Marshaller createMarshaller(Class clazz) { try { JAXBContext jaxbContext = getJaxbContext(clazz); return jaxbContext.createMarshaller(); } catch (JAXBException ex) { throw new HttpMessageConversionException( "Could not create Marshaller for class [" + clazz + "]: " + ex.getMessage(), ex); } }
From source file:se.inera.intyg.intygstjanst.web.integration.converter.SendMessageToCareConverter.java
public String convertToXmlString(SendMessageToCareType sendMessageToCareType) throws JAXBException { ObjectFactory objectFactory = new ObjectFactory(); JAXBContext jaxbContext = JAXBContext.newInstance(SendMessageToCareType.class); Marshaller marshaller = jaxbContext.createMarshaller(); StringWriter stringWriter = new StringWriter(); marshaller.marshal(objectFactory.createSendMessageToCare(sendMessageToCareType), stringWriter); return stringWriter.toString().replaceAll("[\\n\\t ]", ""); }
From source file:org.hisp.dhis.dxf2.importsummary.ImportSummaryTest.java
@Test public void marshallImportSummary() throws Exception { ImportSummary summary = new ImportSummary(); summary.setDescription("Testing"); summary.setStatus(ImportStatus.SUCCESS); summary.setDataValueCount(new ImportCount(2, 1, 4)); JAXBContext jaxbContext = JAXBContext.newInstance(ImportSummary.class); Marshaller jaxbmarshaller = jaxbContext.createMarshaller(); jaxbmarshaller.marshal(summary, System.out); }