Example usage for javax.xml.bind UnmarshallerHandler getResult

List of usage examples for javax.xml.bind UnmarshallerHandler getResult

Introduction

In this page you can find the example usage for javax.xml.bind UnmarshallerHandler getResult.

Prototype

Object getResult() throws JAXBException, IllegalStateException;

Source Link

Document

Obtains the unmarshalled result.

Usage

From source file:org.castor.jaxb.CastorUnmarshallerTest.java

/**
 * Tests the {@link CastorUnmarshaller#getUnmarshallerHandler()} method.
 *
 * @throws Exception if any error occurs during test
 *//*from  w w w  .  j  a  va2  s . c  o  m*/
@Test
public void testGetUnmarshallHandler() throws Exception {
    UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);

    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    xmlReader.setContentHandler(unmarshallerHandler);
    xmlReader.parse(new InputSource(new StringReader(INPUT_XML)));

    Entity entity = (Entity) unmarshallerHandler.getResult();
    testEntity(entity);
}

From source file:org.kuali.rice.core.impl.config.property.JAXBConfigImpl.java

protected org.kuali.rice.core.impl.config.property.Config unmarshal(Unmarshaller unmarshaller, InputStream in)
        throws SAXException, ParserConfigurationException, IOException, IllegalStateException, JAXBException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);//from w  w w .  j av a 2  s. c o m

    XMLFilter filter = new ConfigNamespaceURIFilter();
    filter.setParent(spf.newSAXParser().getXMLReader());

    UnmarshallerHandler handler = unmarshaller.getUnmarshallerHandler();
    filter.setContentHandler(handler);

    filter.parse(new InputSource(in));

    return (org.kuali.rice.core.impl.config.property.Config) handler.getResult();
}