Search in sources :

Example 1 with UnmarshallerHandler

use of javax.xml.bind.UnmarshallerHandler in project OpenAM by OpenRock.

the class UnmarshallerImpl method unmarshal.

public final Object unmarshal(Node node) throws JAXBException {
    try {
        DOMScanner scanner = new DOMScanner();
        UnmarshallerHandler handler = new InterningUnmarshallerHandler(createUnmarshallerHandler(new DOMLocator(scanner)));
        if (node instanceof Element)
            scanner.parse((Element) node, handler);
        else if (node instanceof Document)
            scanner.parse(((Document) node).getDocumentElement(), handler);
        else
            // no other type of input is supported
            throw new IllegalArgumentException();
        return handler.getResult();
    } catch (SAXException e) {
        throw createUnmarshalException(e);
    }
}
Also used : DOMScanner(com.sun.xml.bind.unmarshaller.DOMScanner) Element(org.w3c.dom.Element) UnmarshallerHandler(javax.xml.bind.UnmarshallerHandler) DOMLocator(com.sun.xml.bind.validator.DOMLocator) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 2 with UnmarshallerHandler

use of javax.xml.bind.UnmarshallerHandler in project OpenAM by OpenRock.

the class UnmarshallerImpl method unmarshal.

public final Object unmarshal(Node node) throws JAXBException {
    try {
        DOMScanner scanner = new DOMScanner();
        UnmarshallerHandler handler = new InterningUnmarshallerHandler(createUnmarshallerHandler(new DOMLocator(scanner)));
        if (node instanceof Element)
            scanner.parse((Element) node, handler);
        else if (node instanceof Document)
            scanner.parse(((Document) node).getDocumentElement(), handler);
        else
            // no other type of input is supported
            throw new IllegalArgumentException();
        return handler.getResult();
    } catch (SAXException e) {
        throw createUnmarshalException(e);
    }
}
Also used : DOMScanner(com.sun.xml.bind.unmarshaller.DOMScanner) Element(org.w3c.dom.Element) UnmarshallerHandler(javax.xml.bind.UnmarshallerHandler) DOMLocator(com.sun.xml.bind.validator.DOMLocator) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 3 with UnmarshallerHandler

use of javax.xml.bind.UnmarshallerHandler in project tomee by apache.

the class JaxbPersistenceFactory method getPersistence.

public static <T> T getPersistence(final Class<T> clazz, final InputStream persistenceDescriptor) throws Exception {
    final JAXBContext jc = clazz.getClassLoader() == JaxbPersistenceFactory.class.getClassLoader() ? JaxbJavaee.getContext(clazz) : JAXBContextFactory.newInstance(clazz);
    final Unmarshaller u = jc.createUnmarshaller();
    final UnmarshallerHandler uh = u.getUnmarshallerHandler();
    // create a new XML parser
    final SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    final SAXParser parser = factory.newSAXParser();
    final XMLReader xmlReader = parser.getXMLReader();
    // Create a filter to intercept events
    final PersistenceFilter xmlFilter = new PersistenceFilter(xmlReader);
    // Be sure the filter has the JAXB content handler set (or it wont work)
    xmlFilter.setContentHandler(uh);
    final SAXSource source = new SAXSource(xmlFilter, new InputSource(persistenceDescriptor));
    return (T) u.unmarshal(source);
}
Also used : InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) SAXParser(javax.xml.parsers.SAXParser) JAXBContext(javax.xml.bind.JAXBContext) UnmarshallerHandler(javax.xml.bind.UnmarshallerHandler) Unmarshaller(javax.xml.bind.Unmarshaller) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 4 with UnmarshallerHandler

use of javax.xml.bind.UnmarshallerHandler in project OpenAM by OpenRock.

the class UnmarshallerImpl method unmarshal.

public final Object unmarshal(Node node) throws JAXBException {
    try {
        DOMScanner scanner = new DOMScanner();
        UnmarshallerHandler handler = new InterningUnmarshallerHandler(createUnmarshallerHandler(new DOMLocator(scanner)));
        if (node instanceof Element)
            scanner.parse((Element) node, handler);
        else if (node instanceof Document)
            scanner.parse(((Document) node).getDocumentElement(), handler);
        else
            // no other type of input is supported
            throw new IllegalArgumentException();
        return handler.getResult();
    } catch (SAXException e) {
        throw createUnmarshalException(e);
    }
}
Also used : DOMScanner(com.sun.xml.bind.unmarshaller.DOMScanner) Element(org.w3c.dom.Element) UnmarshallerHandler(javax.xml.bind.UnmarshallerHandler) DOMLocator(com.sun.xml.bind.validator.DOMLocator) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 5 with UnmarshallerHandler

use of javax.xml.bind.UnmarshallerHandler in project OpenAM by OpenRock.

the class UnmarshallerImpl method unmarshal.

public final Object unmarshal(Node node) throws JAXBException {
    try {
        DOMScanner scanner = new DOMScanner();
        UnmarshallerHandler handler = new InterningUnmarshallerHandler(createUnmarshallerHandler(new DOMLocator(scanner)));
        if (node instanceof Element)
            scanner.parse((Element) node, handler);
        else if (node instanceof Document)
            scanner.parse(((Document) node).getDocumentElement(), handler);
        else
            // no other type of input is supported
            throw new IllegalArgumentException();
        return handler.getResult();
    } catch (SAXException e) {
        throw createUnmarshalException(e);
    }
}
Also used : DOMScanner(com.sun.xml.bind.unmarshaller.DOMScanner) Element(org.w3c.dom.Element) UnmarshallerHandler(javax.xml.bind.UnmarshallerHandler) DOMLocator(com.sun.xml.bind.validator.DOMLocator) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

UnmarshallerHandler (javax.xml.bind.UnmarshallerHandler)5 DOMScanner (com.sun.xml.bind.unmarshaller.DOMScanner)4 DOMLocator (com.sun.xml.bind.validator.DOMLocator)4 Document (org.w3c.dom.Document)4 Element (org.w3c.dom.Element)4 SAXException (org.xml.sax.SAXException)4 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 SAXSource (javax.xml.transform.sax.SAXSource)1 InputSource (org.xml.sax.InputSource)1 XMLReader (org.xml.sax.XMLReader)1