Example usage for javax.xml.bind Unmarshaller getUnmarshallerHandler

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

Introduction

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

Prototype

public UnmarshallerHandler getUnmarshallerHandler();

Source Link

Document

Get an unmarshaller handler object that can be used as a component in an XML pipeline.

Usage

From source file:gov.nih.nci.ncicb.tcga.dcc.common.jaxb.JAXBUtil.java

private static SAXSource applyMetaDataNamespaceFilter(final Unmarshaller unmarshaller,
        final Reader xmlFileReader) throws SAXException, ParserConfigurationException, FileNotFoundException {

    final SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true); // this should not be changed!
    final XMLReader reader = factory.newSAXParser().getXMLReader();
    final XMLFilterImpl xmlFilter = new MetaDataXMLNamespaceFilter(reader);
    reader.setContentHandler(unmarshaller.getUnmarshallerHandler());

    return new SAXSource(xmlFilter, new InputSource(xmlFileReader));
}

From source file:org.apache.hadoop.hbase.rest.TestTableScan.java

/**
 * An example to scan using listener in unmarshaller for XML.
 * @throws Exception the exception//  w  w  w .  j av  a 2 s.  c  om
 */
@Test
public void testScanUsingListenerUnmarshallerXML() throws Exception {
    StringBuilder builder = new StringBuilder();
    builder.append("/*");
    builder.append("?");
    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
    builder.append("&");
    builder.append(Constants.SCAN_LIMIT + "=10");
    Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    JAXBContext context = JAXBContext.newInstance(ClientSideCellSetModel.class, RowModel.class,
            CellModel.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();

    final ClientSideCellSetModel.Listener listener = new ClientSideCellSetModel.Listener() {
        @Override
        public void handleRowModel(ClientSideCellSetModel helper, RowModel row) {
            assertTrue(row.getKey() != null);
            assertTrue(row.getCells().size() > 0);
        }
    };

    // install the callback on all ClientSideCellSetModel instances
    unmarshaller.setListener(new Unmarshaller.Listener() {
        public void beforeUnmarshal(Object target, Object parent) {
            if (target instanceof ClientSideCellSetModel) {
                ((ClientSideCellSetModel) target).setCellSetModelListener(listener);
            }
        }

        public void afterUnmarshal(Object target, Object parent) {
            if (target instanceof ClientSideCellSetModel) {
                ((ClientSideCellSetModel) target).setCellSetModelListener(null);
            }
        }
    });

    // create a new XML parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XMLReader reader = factory.newSAXParser().getXMLReader();
    reader.setContentHandler(unmarshaller.getUnmarshallerHandler());
    assertFalse(ClientSideCellSetModel.listenerInvoked);
    reader.parse(new InputSource(response.getStream()));
    assertTrue(ClientSideCellSetModel.listenerInvoked);

}

From source file:org.kalypso.mapserver.utils.MapFileUtilities.java

/**
 * This function loads a map file from XML.
 *
 * @param inputStream/*  w ww . j  av a 2 s.  c o  m*/
 *          The input stream.
 * @return The contents of the map file.
 */
public static Map loadFromXML(final InputStream inputStream)
        throws JAXBException, SAXException, ParserConfigurationException, IOException {
    /* Create the unmarshaller. */
    final Unmarshaller unmarshaller = JC.createUnmarshaller();

    /* Get the sax parser factory. */
    final SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setXIncludeAware(true);

    /* Get the xml reader. */
    final XMLReader xr = spf.newSAXParser().getXMLReader();
    xr.setContentHandler(unmarshaller.getUnmarshallerHandler());
    xr.parse(new InputSource(inputStream));

    return (Map) unmarshaller.getUnmarshallerHandler().getResult();
}

From source file:org.kalypso.ogc.gml.GisTemplateHelper.java

public static final Gismapview loadGisMapView(final InputSource is)
        throws JAXBException, SAXException, ParserConfigurationException, IOException {
    final Unmarshaller unmarshaller = TemplateUtilities.createGismapviewUnmarshaller();

    // XInclude awareness
    final SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);/*from  w w  w .  j  a  v  a  2 s.  c  om*/
    spf.setXIncludeAware(true);
    final XMLReader xr = spf.newSAXParser().getXMLReader();
    xr.setContentHandler(unmarshaller.getUnmarshallerHandler());
    xr.parse(is);
    return (Gismapview) unmarshaller.getUnmarshallerHandler().getResult();
}

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);// w  ww  .  j  a  v  a2  s  .c om

    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();
}