Package javax.xml.bind

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


                   
            CachedContextAndSchemas cache =
                JAXBContextCache.getCachedContextAndSchemas(classes, null, null, null, false);
            JAXBContext jaxbContext = cache.getContext();
           
            Marshaller marshaller = jaxbContext.createMarshaller();
            Document doc = DOMUtils.createDocument();
            Element rootElement = doc.createElement("root-element");
            JAXBElement<UsernameTokenType> tokenType =
                new JAXBElement<UsernameTokenType>(
                    QNameConstants.USERNAME_TOKEN, UsernameTokenType.class, usernameTokenType
View Full Code Here


        String content = null;
       
        if (useJaxbForContent) {
            JAXBContext jc = jaxbProvider.getJAXBContext(cls, cls);
            StringWriter writer = new StringWriter();
            jc.createMarshaller().marshal(o, writer);
            content = writer.toString();
        } else {
            Method m = cls.getMethod(entryContentMethodName, new Class[]{});
            content = (String)m.invoke(o, new Object[]{});
        }
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;
    }

    private void marshallFrom(String from, Element header, Marshaller 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

  @Before
  public void setUp() throws Exception {

    JAXBContext context = JAXBContext.newInstance("org.springframework.data.domain.jaxb");

    marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    unmarshaller = context.createUnmarshaller();
  }
View Full Code Here

        private final QName name;

        private JaxbStreamingPayload(Class<?> clazz, Object jaxbElement) throws JAXBException {
            JAXBContext jaxbContext = getJaxbContext(clazz);
            this.marshaller = jaxbContext.createMarshaller();
            this.marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
            this.jaxbElement = jaxbElement;
            JAXBIntrospector introspector = jaxbContext.createJAXBIntrospector();
            this.name = introspector.getElementName(jaxbElement);
        }
View Full Code Here

      extendedMetadataIsBuilt = true;
    }

    try {
      final JAXBContext context = JAXBContext.newInstance(AbstractSqlResourceMetaData.class);
      final Marshaller marshaller = context.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
      final StringWriter writer = new StringWriter();
      marshaller.marshal(this, writer);
      return writer.toString();
    } catch (final JAXBException exception) {
View Full Code Here

  /**
   * Marshall a JAXB object and return the XML as a string
   */
  public static String marshallJAXBObject(String namespace, Object o, boolean addXMLDeclaration) throws JAXBException {
    JAXBContext jc = getJAXBContext(namespace);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", addXMLDeclaration);
    StringWriter sw = new StringWriter();
    marshaller.marshal(o, sw);
    return sw.toString();
  }
View Full Code Here

    JAXBContext jaxbContext = jaxbContextHelper.getJaxbContext(clazz);

    // TODO: Is this expensive? Pool marshallers?

    try {
      Marshaller m = jaxbContext.createMarshaller();
      // m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
      m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
      return m;
    } catch (JAXBException e) {
      throw new IllegalStateException("Error creating XML marshaller", e);
View Full Code Here

                                      MediaType mediaType)
   {
      try
      {
         JAXBContext jaxb = findJAXBContext(type, annotations, mediaType, false);
         Marshaller marshaller = jaxb.createMarshaller();
         setCharset(mediaType, marshaller);
         // Pretty Print the XML response.
         Object formatted = mediaType.getParameters().get("formatted");
         if (formatted != null)
         {
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.