List of usage examples for javax.xml.bind JAXBContext createMarshaller
public abstract Marshaller createMarshaller() throws JAXBException;
From source file:com.olp.jpa.domain.docu.ut.DepartmentServiceTest.java
public void test_marshalling() throws JAXBException { List<DepartmentBean> list = __service.findAll(); DepartmentBean bean = __service.findByDeptCode("OPRTN"); JAXBContext ctx = JAXBContext.newInstance(DepartmentBean.class); StringWriter writer = new StringWriter(); Marshaller m = ctx.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(bean, writer);// w ww . ja v a2 s .c om final String xml = writer.toString(); System.out.println(xml); }
From source file:org.javelin.sws.ext.bind.jaxb.JaxbTest.java
@Test(expected = IllegalAnnotationsException.class) public void marshalIllegalProperties() throws Exception { JAXBContext ctx = JAXBContext.newInstance(org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1.class); Marshaller m = ctx.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1 mc5 = new org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1(); mc5.setC(String.class); m.marshal(new JAXBElement<org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1>(new QName("a", "a"), org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1.class, mc5), System.out); }
From source file:hydrograph.ui.graph.debugconverter.DebugConverter.java
public void marshall(Debug debug, IFile outPutFile) throws JAXBException, IOException, CoreException { JAXBContext jaxbContext = JAXBContext.newInstance(Debug.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.marshal(debug, out);//from w w w .j a v a2s . com if (outPutFile.exists()) outPutFile.setContents(new ByteArrayInputStream(out.toByteArray()), true, false, null); else outPutFile.create(new ByteArrayInputStream(out.toByteArray()), true, null); out.close(); }
From source file:com.testdroid.api.APIEntity.java
@JsonIgnore public String toXML() { try {/*from w ww . j a v a 2s . com*/ JAXBContext context = getJAXBContext(this.getClass()); Marshaller marshaller = context.createMarshaller(); StringWriter writer = new StringWriter(); marshaller.marshal(this, writer); return writer.toString(); } catch (JAXBException ex) { Logger.getLogger(APIEntity.class.getName()).log(Level.SEVERE, null, ex); } return ""; }
From source file:esg.node.components.registry.LasSistersGleaner.java
public synchronized boolean saveLasServers(LasServers servers) { boolean success = false; if (servers == null) { log.error("LasServers is [" + servers + "]"); return success; }/*from w w w. j av a 2 s.co m*/ log.trace("Saving LAS LasServers information to " + sistersPath + sistersFile); try { JAXBContext jc = JAXBContext.newInstance(LasServers.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(servers, new FileOutputStream(sistersPath + sistersFile)); success = true; } catch (Exception e) { log.error(e); } return success; }
From source file:esg.node.components.registry.AzsWhitelistGleaner.java
public synchronized boolean saveAzsWhitelist(AzsWhitelist azss) { boolean success = false; if (azss == null) { log.error("azss (whitelist) is null ? [" + azss + "]"); return success; }//from w w w. j a v a 2 s. c om log.trace("Saving AZS Whitelist information to " + azsWhitelistPath + azsWhitelistFile); try { JAXBContext jc = JAXBContext.newInstance(AzsWhitelist.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(azss, new FileOutputStream(azsWhitelistPath + azsWhitelistFile)); success = true; } catch (Exception e) { log.error(e); } return success; }
From source file:esg.node.components.registry.IdpWhitelistGleaner.java
public synchronized boolean saveIdpWhitelist(IdpWhitelist idps) { boolean success = false; if (idps == null) { log.error("idps (whitelist) is null ? [" + idps + "]"); return success; }//from w w w . j a v a 2 s. com log.trace("Saving IDP Whitelist information to " + idpWhitelistPath + idpWhitelistFile); try { JAXBContext jc = JAXBContext.newInstance(IdpWhitelist.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(idps, new FileOutputStream(idpWhitelistPath + idpWhitelistFile)); success = true; } catch (Exception e) { log.error(e); } return success; }
From source file:com.floreantpos.model.PosPrinters.java
public void save() { try {/* w ww. j av a 2 s . c om*/ getDefaultKitchenPrinter(); populatePrinterMaps(); File file = new File("config", "printers.xml"); //$NON-NLS-1$ //$NON-NLS-2$ JAXBContext jaxbContext = JAXBContext.newInstance(PosPrinters.class); Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter writer = new StringWriter(); m.marshal(this, writer); FileUtils.write(file, writer.toString()); } catch (Exception e) { PosLog.error(getClass(), e); } }
From source file:com.retroduction.carma.eventlisteners.ReportEventListener.java
public void destroy() { this.log.info("Finishing XML report"); this.runProcessingEnd = System.currentTimeMillis(); new StatisticalReportAnalyzer().enhanceReport(this.run); try {/* w ww . jav a 2 s .co m*/ if (this.writeTimingInfo) { ProcessingInfo info = this.createTimingInformation(this.runProcessingStart, this.runProcessingEnd); this.run.setProcessingInfo(info); } } catch (DatatypeConfigurationException e) { e.printStackTrace(); } try { JAXBContext context = JAXBContext.newInstance(MutationRun.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(this.run, new FileOutputStream(new File(this.outputFile))); } catch (JAXBException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:eu.modaclouds.sla.service.rest.AbstractSLARest.java
protected String printError(int code, String text) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {/* ww w .java 2 s .c o m*/ ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setCode(code); errorResponse.setMessage(text); JAXBContext jaxbContext; jaxbContext = JAXBContext.newInstance(eu.atos.sla.parser.data.ErrorResponse.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(errorResponse, out); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } return out.toString(); }