List of usage examples for javax.xml.bind Marshaller marshal
public void marshal(Object jaxbElement, javax.xml.stream.XMLEventWriter writer) throws JAXBException;
From source file:edu.duke.cabig.c3pr.webservice.integration.SubjectRegistryWebServicePerformanceTest.java
private void importStudySubjects(int sbegin, int send, int pbegin, int pend, String batch) throws Exception { SubjectRegistry service = getService(); // successful creation final ImportStudySubjectRegistryRequest request = new ImportStudySubjectRegistryRequest(); request.setStudySubjects(new DSETStudySubject()); //String batch = ""; for (int start = sbegin; start < send; start++) { int study = start; //batch += "-"+(400-20*(study-500)); for (int subject = pbegin; subject < pend; subject++) { StudySubject studySubject = createStudySubjectForImport(); //Override some values ((Person) studySubject.getEntity()).setRaceCode(iso.DSETCD(iso.CD(RACE_WHITE))); ((Person) studySubject.getEntity()).setTelecomAddress(iso.BAGTEL(iso.TEL(TEST_EMAIL_ADDR_ISO))); ((Person) studySubject.getEntity()).getBiologicEntityIdentifier().get(0).getIdentifier() .setExtension(subject + ""); studySubject.getSubjectIdentifier().get(0).getIdentifier() .setExtension(RandomStringUtils.randomAlphanumeric(6) + "--" + batch); studySubject.getSubjectIdentifier().get(0).setPrimaryIndicator(iso.BL(true)); studySubject.getStudySubjectProtocolVersion().getStudySiteProtocolVersion() .getStudyProtocolVersion().getStudyProtocolDocument().getDocument().getDocumentIdentifier() .get(0).getIdentifier().setExtension(study + ""); //add 1st consent studySubject.getStudySubjectProtocolVersion().getStudySubjectConsentVersion().clear(); StudySubjectConsentVersion studySubjectConsentVersion = new StudySubjectConsentVersion(); studySubjectConsentVersion.setConsentDeliveryDate(iso.TSDateTime(TEST_CONSENT_DELIVERY_DATE1)); studySubjectConsentVersion.setInformedConsentDate(iso.TSDateTime(TEST_CONSENT_SIGNED_DATE1)); studySubjectConsentVersion.setConsentingMethod(iso.CD(TEST_CONSENTING_METHOD1)); studySubjectConsentVersion.setConsentPresenter(iso.ST(TEST_CONSENT_PRESENTER1)); studySubjectConsentVersion.setConsent(new DocumentVersion()); studySubjectConsentVersion.getConsent().setOfficialTitle(iso.ST(TEST_CONSENT_NAME1)); studySubjectConsentVersion.getConsent().setVersionNumberText(iso.ST(TEST_CONSENT_VERSION1)); PerformedStudySubjectMilestone subjectAnswer = new PerformedStudySubjectMilestone(); subjectAnswer.setMissedIndicator(iso.BL(TEST_CONSENT_ANS11)); subjectAnswer.setConsentQuestion(new DocumentVersion()); subjectAnswer.getConsentQuestion().setOfficialTitle(iso.ST(TEST_CONSENT_QUES11)); studySubjectConsentVersion.getSubjectConsentAnswer().add(subjectAnswer); studySubject.getStudySubjectProtocolVersion().getStudySubjectConsentVersion() .add(studySubjectConsentVersion); request.getStudySubjects().getItem().add(studySubject); }/* w w w.j a v a2 s . c o m*/ } JAXBContext context = JAXBContext.newInstance("edu.duke.cabig.c3pr.webservice.subjectregistry"); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(request, System.out); System.out.flush(); DSETStudySubject createdStudySubjects = service.importSubjectRegistry(request).getStudySubjects(); assertNotNull(createdStudySubjects); // assertEquals(scount*pcount, createdStudySubjects.getItem().size()); }
From source file:com.hp.octane.integrations.uft.items.UftTestDiscoveryResult.java
public void writeToFile(File fileToWriteTo) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(UftTestDiscoveryResult.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(this, fileToWriteTo); }
From source file:it.geosolutions.geobatch.unredd.script.util.GeoStoreUtil.java
/** * Delete a resource./* w w w . j a v a2s.c om*/ * Delete the resource identified by id. * * @param id */ @Override public void delete(long id) throws GeoStoreException { try { RESTResource resource = new RESTResource(); resource.setId(id); // this part creates the file to feed the GeoStoreAction File inputFile = File.createTempFile("Delete", ".xml", tempDir); Marshaller m = JAXBMarshallerBuilder.getJAXBMarshaller(resource.getClass()); m.marshal(resource, inputFile); GeostoreActionConfiguration geoStoreCfg = createConfiguration(); geoStoreCfg.setShortResource(true); geoStoreCfg.setOperation(GeostoreOperation.Operation.DELETE); GeostoreAction action = new GeostoreAction(geoStoreCfg); action.setTempDir(tempDir); SingleFileActionExecutor.execute(action, inputFile); } catch (Exception ex) { throw new GeoStoreException("Error while deleting resource " + id, ex); } }
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 {/*from w w w.j a v a 2s .c o 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:it.geosolutions.geobatch.unredd.script.util.GeoStoreUtil.java
/** * Generic search in GeoStoreUtil.//from ww w . j ava 2 s . c om * * @param filter the filter to apply for searching * @param getShortResource true if a list of resource is required, false if a RESTResource list is sufficient * * @return always a not null list */ // @Override protected List search(SearchFilter filter, boolean getShortResource, String fileNameHint) throws GeoStoreException { File tmpFile = null; try { tmpFile = File.createTempFile(fileNameHint, ".xml", tempDir); Marshaller m = JAXBMarshallerBuilder.getJAXBMarshaller(filter.getClass()); m.marshal(filter, tmpFile); GeostoreActionConfiguration geoStoreCfg = createConfiguration(); geoStoreCfg.setShortResource(getShortResource); geoStoreCfg.setOperation(GeostoreOperation.Operation.SEARCH); GeostoreAction action = new GeostoreAction(geoStoreCfg); action.setTempDir(tempDir); SingleFileActionExecutor.execute(action, tmpFile); List ret = getShortResource ? action.getShortResourceList() : action.getResourceList(); return ret == null ? Collections.EMPTY_LIST : ret; } catch (Exception e) { throw new GeoStoreException("Error while searching in GeoStore", e); } finally { FileUtils.deleteQuietly(tmpFile); // we're putting the temp file in a working dir, so this delete is probably useless } }
From source file:it.geosolutions.geobatch.unredd.script.util.GeoStoreUtil.java
@Override public void updateData(long id, String data) throws GeoStoreException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Updating data for resource " + id); }/* www . j av a 2s . c o m*/ // this part creates the file to feed the GeoStoreAction File tmpFile = null; try { RESTResource resource = new RESTResource(); // this is just a packaging for id+data resource.setId(id); resource.setData(data); tmpFile = File.createTempFile("UpdateData", ".xml", tempDir); Marshaller m = JAXBMarshallerBuilder.getJAXBMarshaller(resource.getClass()); m.marshal(resource, tmpFile); GeostoreActionConfiguration geoStoreCfg = createConfiguration(); geoStoreCfg.setShortResource(true); geoStoreCfg.setOperation(GeostoreOperation.Operation.UPDATEDATA); GeostoreAction action = new GeostoreAction(geoStoreCfg); action.setTempDir(tempDir); SingleFileActionExecutor.execute(action, tmpFile); } catch (Exception ex) { throw new GeoStoreException("Exception while updating data", ex); } finally { FileUtils.deleteQuietly(tmpFile); // we're putting the temp file in a working dir, so this delete is probably useless } }
From source file:it.geosolutions.geobatch.unredd.script.util.GeoStoreUtil.java
/** * generic insert into geostore/* ww w . ja v a2 s . c om*/ * * @param resource the resource to insert * @throws GeoStoreException */ @Override public Long insert(RESTResource resource) throws GeoStoreException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Creating " + resource.getCategory().getName() + " --> " + resource.getName()); } String hintName = resource.getCategory().getName() + "_" + resource.getName(); // this part creates the file to feed the GeoStoreAction File tmpFile = null; try { tmpFile = File.createTempFile("Insert_" + hintName, ".xml", tempDir); Marshaller m = JAXBMarshallerBuilder.getJAXBMarshaller(resource.getClass()); m.marshal(resource, tmpFile); GeostoreActionConfiguration geoStoreCfg = createConfiguration(); geoStoreCfg.setShortResource(true); geoStoreCfg.setOperation(GeostoreOperation.Operation.INSERT); GeostoreAction action = new GeostoreAction(geoStoreCfg); action.setTempDir(tempDir); SingleFileActionExecutor.execute(action, tmpFile); return null; // no id here } catch (Exception e) { LOGGER.error("Error while inserting in GeoStore: " + resource); throw new GeoStoreException("Error while inserting in GeoStore", e); } finally { FileUtils.deleteQuietly(tmpFile); // we're putting the temp file in a working dir, so this delete is probably useless } }
From source file:org.geosdi.geoplatform.connector.CatalogContextTest.java
@Test public void testJAXBContext() throws JAXBException { Assert.assertNotNull(cswContext);/* www . ja v a 2s . com*/ Unmarshaller m = cswContext.acquireUnmarshaller(); try { if (entity != null) { InputStream content = entity.getContent(); CapabilitiesType cap = ((JAXBElement<CapabilitiesType>) m.unmarshal(content)).getValue(); logger.info("CSW GET_CAPABILITIES VERSION @@@@@@@@@@@@@@@@@@@@@@@ " + cap.getVersion()); logger.info("CSW SERVICE IDENTIFICATION @@@@@@@@@@ " + cap.getServiceIdentification()); String cswFile = "target/csw.xml"; Marshaller ma = cswContext.acquireMarshaller(); FileOutputStream fos = null; try { fos = new FileOutputStream(cswFile); ma.marshal(cap, fos); } finally { if (fos != null) { fos.close(); } } } } catch (IOException ex) { logger.error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " + ex.getMessage()); } }
From source file:org.axiom_tools.codecs.ModelCodec.java
/** * Converts a model to XML./*from w ww . jav a 2 s . co m*/ * @return model XML, or empty */ public String toXML() { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Marshaller m = buildJAXBContext().createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); m.marshal(this.entity, stream); return stream.toString(XML_ENCODING).trim(); } catch (Exception e) { Log.error(e.getMessage(), e); return Empty; } }
From source file:org.usd.edu.btl.cli.ConvertBets.java
public void toGalaxy(String input, String output) { InputStream infile = null;//from www. j a v a 2 s .c o m Tool myTool = null; try { JAXBContext jaxbContext = JAXBContext.newInstance(Tool.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); //Unmarshalling Convert XML content into a Java Object. infile = new FileInputStream("./test_inputs/test_galaxy.xml"); Tool test_tool = (Tool) unmarshaller.unmarshal(infile); myTool = test_tool; //System.out.println(test_tool.toString()); //print the test_tool } catch (FileNotFoundException e) { System.err.println(e.getMessage()); } catch (JAXBException e) { System.err.println(e.getMessage()); } finally { try { if (infile != null) { infile.close(); } } catch (IOException e) { System.err.println("You're rubbish, you can't even close a file"); System.err.println(e.getMessage()); } } //JAXB-Marshall Java back to XML try { JAXBContext jaxbContext = JAXBContext.newInstance(Tool.class); Marshaller marshaller = jaxbContext.createMarshaller(); //Marshalling Convert a Java object into a XML file. marshaller.marshal(myTool, System.out); //print XML out } catch (JAXBException e) { System.err.println("JAXB dun goofed"); System.err.println(e.getMessage()); } // RUN GALAXY TO BETS CONVERSION BETSV1 betsOutput = GalaxyConverter.toBETS(myTool); try { System.err.println("************************************************\n" + "*********PRINTING OUT CONVERSION************\n" + "----------Galaxy --> Bets--------------\n" + "************************************************\n"); //print objects as Json using jackson System.err.println("=== BLD TO BETS JSON === \n"); System.out.println(betsOutput); } catch (Exception e) { System.err.println(e.getMessage()); } }