Example usage for javax.xml.bind Unmarshaller unmarshal

List of usage examples for javax.xml.bind Unmarshaller unmarshal

Introduction

In this page you can find the example usage for javax.xml.bind Unmarshaller unmarshal.

Prototype

public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException;

Source Link

Document

Unmarshal XML data from the specified pull parser and return the resulting content tree.

Usage

From source file:org.openmrs.module.dhisreport.api.DHIS2ReportingServiceDXFTest.java

@Ignore
@Test/*from   w  ww.  j a  v a 2s. c  o m*/
public void postDhisReportTest() throws Exception {
    HttpDhis2Server server = new HttpDhis2Server();
    server.setUsername("admin");
    server.setPassword("district");
    server.setUrl(new URL("http://apps.dhis2.org/dev"));

    service.setDhis2Server(server);
    ClassPathResource resource = new ClassPathResource("dvset.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(DataValueSet.class);

    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    DataValueSet dvset = (DataValueSet) jaxbUnmarshaller.unmarshal(resource.getInputStream());
    ImportSummary summary = service.postDataValueSet(dvset);
    JAXBContext importSummaryContext = JAXBContext.newInstance(ImportSummary.class);

    Marshaller jaxbmarshaller = importSummaryContext.createMarshaller();
    jaxbmarshaller.marshal(summary, System.out);
}

From source file:org.apache.falcon.regression.core.response.ServiceResponse.java

/**
 * Retrieves EntitySummaryResult from a message if possible.
 * @return EntitiesResult//from   w  w  w  .  ja  va2 s .c  o m
 */
public EntitySummaryResult getEntitySummaryResult() {
    try {
        JAXBContext jc = JAXBContext.newInstance(EntitySummaryResult.class);
        Unmarshaller u = jc.createUnmarshaller();
        return (EntitySummaryResult) u.unmarshal(new StringReader(message));
    } catch (JAXBException e) {
        LOGGER.info("getEntitySummaryResult() failed:\n" + ExceptionUtils.getStackTrace(e));
        return null;
    }
}

From source file:fr.fastconnect.factory.tibco.bw.codereview.CodeReviewInitialize.java

private ReviewResult loadReviewResult(File f) {
    try {/*  w  ww.j  a v  a  2s.  com*/
        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        Object o = jaxbUnmarshaller.unmarshal(f);
        return (ReviewResult) o;
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:de.extra.client.plugins.configplugin.controller.ConfigPluginController.java

/**
 * Unmarshalling der Profildatei./*from   w w  w . j  a v  a2  s . co  m*/
 * 
 * @param dateiName
 *            Vollstaendiger Pfad der Profildatei
 * @return JaxB-Element
 */
private ProfilkonfigurationType unmarshalConfig(final File profileFile) {
    ProfilkonfigurationType pkt = null;
    JAXBContext jc;
    try {
        // Initialisieren des JaxB-Contextes
        jc = JAXBContext.newInstance(ConfigConstants.UNMARSHAL_CONFIG);

        // Aufruf des Unmarshallers
        Unmarshaller u = jc.createUnmarshaller();
        pkt = (ProfilkonfigurationType) u.unmarshal(profileFile);
    } catch (JAXBException e) {
        LOG.error("Fehler beim Verarbeiten des XML", e);
    } catch (Exception e) {
        LOG.error("Fehler beim Verarbeiten des XML", e);
    }
    return pkt;
}

From source file:fr.mael.microrss.xml.AtomFeedParser.java

@Override
public Feed parseFeedInfo(Feed feed) throws Exception {
    JAXBContext jc = JAXBContext.newInstance("fr.mael.microrss.xml.atom");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    Object o = unmarshaller.unmarshal(new URL(feed.getUrl()).openStream());
    if (o instanceof JAXBElement) {
        JAXBElement element = (JAXBElement) o;
        FeedType feedType = (FeedType) element.getValue();
        String link = XMLUtil.readLinkType("link", feedType.getAuthorOrCategoryOrContributor());
        feed.setIcon(Tools.getImage(Tools.getBaseUrl(link) + "/favicon.ico"));
        feed.setTitle(XMLUtil.readTextType("title", feedType.getAuthorOrCategoryOrContributor()));
    }/*from  www . ja  v a  2 s .co  m*/
    return feed;
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.ProfileMarshaller.java

public Profile unmarshal(Source source) throws JAXBException, IOException {
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    unmarshaller.setSchema(profileSchema);
    return (Profile) unmarshaller.unmarshal(source);
}

From source file:gov.nih.nci.cacis.sa.mirthconnect.SemanticAdapterChannelIntegrationTest.java

/**
 * This test calls out acceptSource(..) operation on SematicAdapter WS.
 * The SemanticAdapter WS is the source connector to SemanticAdapterChannel in Mirth.
 * @throws Exception exception//from   w w  w  .ja v  a2s. com
 */
@Test
public void invokeSemanticAdapterWS() throws Exception { //NOPMD
    final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(AcceptSourcePortType.class);
    factory.setAddress(ADDRESS);
    final AcceptSourcePortType client = (AcceptSourcePortType) factory.create();

    final InputStream sampleMessageIS = FileUtils
            .openInputStream(new File(getClass().getClassLoader().getResource("SARequestSample.xml").toURI()));

    final JAXBContext jc = JAXBContext.newInstance(CaCISRequest.class);
    final Unmarshaller unm = jc.createUnmarshaller();

    final CaCISRequest request = (CaCISRequest) unm.unmarshal(sampleMessageIS);

    final Marshaller m = jc.createMarshaller();
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    m.marshal(request, pw);
    final String reqStr = sw.toString();

    final CaCISResponse response = client.acceptSource(request);
    assertTrue(response.getStatus() == ResponseStatusType.SUCCESS);

}

From source file:actions.AddStudent.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ActionForward findForward = mapping.findForward("main");

    StudentForm formStudent = (StudentForm) request.getAttribute("studentForm");

    Student newStudent = new Student();
    BeanUtils.copyProperties(newStudent, formStudent);

    System.out.println("newStudent.firstName=" + newStudent.getFirstName());
    System.out.println("newStudent.lastName=" + newStudent.getLastName());
    System.out.println("newStudent.studentId=" + newStudent.getStudentId());
    System.out.println("newStudent.dob=" + newStudent.getDob());

    //Student.fileWrite(null, newStudent.fileOutputString());
    boolean successAdd = newStudent.saveStudent();
    Student.getStudents().put(newStudent.getStudentId(), newStudent);

    ActionMessages messages = new ActionMessages();
    if (successAdd) {
        messages.add("message1", (new ActionMessage("label.student.added.successfully")));
    } else {//from www. j a v a  2s.  c  o  m
        messages.add("error", (new ActionMessage("label.student.added.error")));
    }
    saveMessages(request, messages);

    //**********************************************************************
    //**********************************************************************
    //**********************************************************************
    //http://www.vogella.com/tutorials/JAXB/article.html
    // create JAXB context and instantiate marshaller
    JAXBContext context = JAXBContext.newInstance(Student.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    // Write to System.out
    StringWriter sw = new StringWriter();
    m.marshal(newStudent, sw);
    String xmlStudent = sw.toString();
    System.out.println("xmlEncodedStudent=" + xmlStudent);
    //**********************************************************************
    //**********************************************************************

    //Unmarshall back for testing
    Unmarshaller um = context.createUnmarshaller();
    Student backStudent = (Student) um.unmarshal(new StringReader(xmlStudent));
    System.out.println("Student back from xml:" + backStudent.toString());

    //**********************************************************************
    //**********************************************************************
    //**********************************************************************
    return findForward;

}

From source file:org.openmrs.module.dhisreport.api.model.ReportTemplatesTest.java

@Test
public void marshallReportTemplates() throws Exception {
    ClassPathResource resource = new ClassPathResource("templates_ethiopia.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(ReportTemplates.class);

    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    ReportTemplates reportTemplates = (ReportTemplates) jaxbUnmarshaller.unmarshal(resource.getInputStream());
    Collection<DataValueTemplate> dvts = reportTemplates.getReportDefinitions().get(1).getDataValueTemplates();
    for (DataValueTemplate dvt : dvts) {
        dvt.setQuery("select count(*) from something & something_else");
    }// w ww . j  a  va 2  s .  co m
    Marshaller jaxbmarshaller = jaxbContext.createMarshaller();
    jaxbmarshaller.marshal(reportTemplates, System.out);
}

From source file:com.discogs.api.webservice.impl.HttpClientWebService.java

private Resp createResp(InputStream inputStream) {
    Resp resp = null;//w w w  .  jav a 2s  . c  o m
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance("com.discogs.api.model");
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        resp = (Resp) unmarshaller.unmarshal(inputStream);
    } catch (JAXBException e) {
        logger.error(e.getMessage());
    }
    return resp;
}