Package javax.xml.bind

Examples of javax.xml.bind.Marshaller


    public void marshall(@SuppressWarnings("rawtypes") Class parent, QName qname,
                         ExtensibilityElement obj, PrintWriter pw,
                         final Definition wsdl, ExtensionRegistry registry) throws WSDLException {
        // TODO Auto-generated method stub
        try {
            Marshaller u = getContext().createMarshaller();
            u.setProperty("jaxb.encoding", "UTF-8");
            u.setProperty("jaxb.fragment", Boolean.TRUE);
            u.setProperty("jaxb.formatted.output", Boolean.TRUE);
           
            Object mObj = obj;
           
            Class<?> objectFactory = Class.forName(PackageUtils.getPackageName(typeClass) + ".ObjectFactory",
                                                   true,
                                                   obj.getClass().getClassLoader());
            Method methods[] = objectFactory.getDeclaredMethods();
            for (Method method : methods) {
                if (method.getParameterTypes().length == 1
                    && method.getParameterTypes()[0].equals(typeClass)) {
                   
                    mObj = method.invoke(objectFactory.newInstance(), new Object[] {obj});
                }
            }

            javax.xml.stream.XMLOutputFactory fact = javax.xml.stream.XMLOutputFactory.newInstance();
            XMLStreamWriter writer =
                new PrettyPrintXMLStreamWriter(fact.createXMLStreamWriter(pw), parent);
            writer.setNamespaceContext(new javax.xml.namespace.NamespaceContext() {
               
                public String getNamespaceURI(String arg) {
                    return wsdl.getNamespace(arg);
                }
                               
                public String getPrefix(String arg) {
                    if (arg.equals(jaxbNamespace)) {
                        arg = namespace;
                    }
                   
                    for (Object ent : wsdl.getNamespaces().entrySet()) {
                        Map.Entry<?, ?> entry = (Map.Entry<?, ?>)ent;
                        if (arg.equals(entry.getValue())) {
                            return (String)entry.getKey();
                        }
                    }
                    return null;
                }
               
                public Iterator<String> getPrefixes(String arg) {
                    if (arg.equals(jaxbNamespace)) {
                        arg = namespace;
                    }
                    Iterator<String> ret = CastUtils.cast(wsdl.getNamespaces().keySet().iterator());
                    return ret;
                }
            });
           
            u.marshal(mObj, writer);
            writer.flush();           
        } catch (Exception ex) {
            throw new WSDLException(WSDLException.PARSER_ERROR,
                                    "",
                                    ex);
View Full Code Here


    }
   
    private Marshaller getMarshaller() throws JAXBException {
        JAXBContext jaxbContext =
            VersionTransformer.getExposedJAXBContext(currentNamespaceURI);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        return marshaller;
    }
View Full Code Here

        throws JAXBException {
       
        Class<?> objClazz = JAXBElement.class.isAssignableFrom(cls)
                            ? ((JAXBElement)obj).getDeclaredType() : cls;
        JAXBContext context = getJAXBContext(objClazz, genericType);
        Marshaller marshaller = context.createMarshaller();
        String enc = m.getParameters().get(CHARSET_PARAMETER);
        if (enc != null) {
            marshaller.setProperty(Marshaller.JAXB_ENCODING, enc);
        }
        return marshaller;
    }
View Full Code Here

            Object actualObject = checkAdapter(obj, anns);
            Class<?> actualClass = actualObject.getClass();
            if (cls == genericType) {
                genericType = actualClass;
            }
            Marshaller ms = createMarshaller(actualObject, actualClass, genericType, m);

            XMLOutputFactory factory = new MappedXMLOutputFactory(namespaceMap);
            XMLStreamWriter xsw = factory.createXMLStreamWriter(os);           
            ms.marshal(actualObject, xsw);
            xsw.close();
           
        } catch (JAXBException e) {
            throw new WebApplicationException(e);
        } catch (XMLStreamException e) {
View Full Code Here

            Object actualObject = checkAdapter(obj, anns);
            Class<?> actualClass = actualObject.getClass();
            if (cls == genericType) {
                genericType = actualClass;
            }
            Marshaller ms = createMarshaller(actualObject, actualClass, genericType, m);
            for (Map.Entry<String, Object> entry : mProperties.entrySet()) {
                ms.setProperty(entry.getKey(), entry.getValue());
            }
            ms.marshal(actualObject, os);
           
        } catch (JAXBException e) {
            throw new WebApplicationException(e);
        }
    }
View Full Code Here

   * @param element
   * @return
   * @throws Exception
   */
  private Element marshallerPart(JIDContext context, OutputStream output, Element element) throws Exception {
    Marshaller marshaller = this.generateMarshaller(false, true);
    if (this.log.isInfoEnabled()) {
      StringBufferWriter buffer = new StringBufferWriter(new StringWriter());
      marshaller.marshal(element, buffer);
      buffer.flush();
      String content = buffer.toString();
      this.log.info("Write on " + context.jid().asString() + " " + content);
      output.write(content.getBytes("UTF-8"));
    } else {
      marshaller.marshal(element, output);
    }
    return element;
  }
View Full Code Here

   * @param element
   * @return
   * @throws Exception
   */
  private Element marshallerPart(JIDContext context, WriterPart part, OutputStream output, Element element) throws Exception {
    Marshaller marshaller = this.generateMarshaller(true, part == WriterPart.WITHOUT_FIRST ? true : false);
    String content = this.getPart(this.prepareToLines(marshaller, element), part);
    this.log.info("Write on " + context.jid().asString() + " " + content);
    output.write(content.getBytes("UTF-8"));
    return element;
  }
View Full Code Here

    }
    return this;
  }

  private Marshaller generateMarshaller(boolean format, boolean fragment) throws JAXBException, PropertyException {
    Marshaller marshaller = this.context.createMarshaller();
    marshaller.setProperty(this.mapperProperty, this.mapper);
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, fragment);
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format);
    return marshaller;
  }
View Full Code Here

            xrd.getService().add(service);

            xrds.getOtherelement().add(xrd);

            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            marshaller.marshal(xrds, writer);
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

            xrd.getService().add(service);

            xrds.getOtherelement().add(xrd);

            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            marshaller.marshal(xrds, writer);
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

TOP

Related Classes of javax.xml.bind.Marshaller

Copyright © 2018 www.massapicom. 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.