Package javax.xml.bind

Examples of javax.xml.bind.JAXBContext.createUnmarshaller()


            StringReader reader = new StringReader(xml);
            Source source = new StreamSource(reader);

            if (!validate) {
                Unmarshaller unmarshaller = context.createUnmarshaller();
                JAXBElement<T> element = unmarshaller.unmarshal(source, type);
                return element.getValue();
            } else {
                // If an adapter fails, we don't get an unmarshal exception.
                // Instead, we have to register and interrogate a handler.
View Full Code Here


            } else {
                // If an adapter fails, we don't get an unmarshal exception.
                // Instead, we have to register and interrogate a handler.
                // See also: http://java.net/jira/browse/JAXB-537

                Unmarshaller unmarshaller = context.createUnmarshaller();

                String xsd = this.generateSchema(type);
                SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                Schema schema = sf.newSchema(new StreamSource(new StringReader(xsd)));
View Full Code Here

        factory.setNamespaceAware(true);
        factory.setValidating(false);
        SAXParser parser = factory.newSAXParser();

        JAXBContext ctx = getContext(type);
        Unmarshaller unmarshaller = ctx.createUnmarshaller();
        unmarshaller.setEventHandler(new ValidationEventHandler() {
            public boolean handleEvent(ValidationEvent validationEvent) {
                System.out.println(validationEvent);
                return false;
            }
View Full Code Here

                arg = new JAXBElement(ROOT_ELEMENT, Object.class, arg);
            }
            JAXBContext context = JAXBContext.newInstance(cls);
            Document doc = DOMHelper.newDocument();
            context.createMarshaller().marshal(arg, doc);
            JAXBElement<?> element = context.createUnmarshaller().unmarshal(doc, cls);
            return isElement ? element : element.getValue();
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }
View Full Code Here

    /**
     * Lets try parse via JAXB
     */
    protected <T> T unmarshall(Class<T> type, Object value) throws JAXBException {
        JAXBContext context = createContext(type);
        Unmarshaller unmarshaller = context.createUnmarshaller();

        if (parentTypeConverter != null) {
            InputStream inputStream = parentTypeConverter.convertTo(InputStream.class, value);
            if (inputStream != null) {
                Object unmarshalled = unmarshaller.unmarshal(inputStream);
View Full Code Here

            Object obj = cls.newInstance();
            StringWriter sw = new StringWriter();
            context.createMarshaller().marshal(obj, sw);
            // System.out.println(sw.toString());
            StringReader sr = new StringReader(sw.toString());
            context.createUnmarshaller().unmarshal(new StreamSource(sr), cls);
        }
    }

    @Test
    public void testGenerateSchema() throws Exception {
View Full Code Here

            exception = new ManifoldCFException("FetchTokensThread error - interface returned incorrect return code for: " + url + " - " + response.getStatusLine().toString());
            return;
          }
          JAXBContext context;
          context = JAXBContext.newInstance(Auth.class);
          Unmarshaller m = context.createUnmarshaller();
          auth = (Auth) m.unmarshal(response.getEntity().getContent());
        } catch (JAXBException ex) {
          exception = ex;
        } finally {
          EntityUtils.consume(response.getEntity());
View Full Code Here

          try {
            ClassLoader cl = URLClassLoader.newInstance(new URL[]{fileEntry.toURI().toURL()});

            InputStream    configStream     = cl.getResourceAsStream(VIEW_XML);
            JAXBContext    jaxbContext      = JAXBContext.newInstance(ViewConfig.class);
            Unmarshaller   jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            ViewConfig     viewConfig       = (ViewConfig) jaxbUnmarshaller.unmarshal(configStream);
            ViewEntity viewDefinition       = installView(viewConfig, configuration, cl, fileEntry.getAbsolutePath());

            for (InstanceConfig instanceConfig : viewConfig.getInstances()) {
              ViewInstanceEntity viewInstanceDefinition = new ViewInstanceEntity(viewDefinition, instanceConfig);
View Full Code Here

        factory.setNamespaceAware(true);
        factory.setValidating(false);
        SAXParser parser = factory.newSAXParser();

        JAXBContext ctx = getContext(type);
        Unmarshaller unmarshaller = ctx.createUnmarshaller();
        unmarshaller.setEventHandler(new ValidationEventHandler() {
            public boolean handleEvent(ValidationEvent validationEvent) {
                System.out.println(validationEvent);
                return false;
            }
View Full Code Here

   
    protected Unmarshaller createUnmarshaller(Class<?> cls, Type genericType, boolean isCollection)
        throws JAXBException {
        JAXBContext context = isCollection ? getCollectionContext(cls)
                                           : getJAXBContext(cls, genericType);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        if (schema != null) {
            unmarshaller.setSchema(schema);
        }
        if (eventHandler != null) {
            unmarshaller.setEventHandler(eventHandler);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.