Package org.jboss.xb.binding

Examples of org.jboss.xb.binding.AbstractMarshaller


      // get the output writter to write the XML content
      StringWriter xmlOutput = new StringWriter();

      // create an instance of XML Schema marshaller
      AbstractMarshaller marshaller = (AbstractMarshaller)Marshaller.FACTORY.getInstance();

      // we need to specify what elements are top most (roots) providing namespace URI, prefix and local name
      marshaller.addRootElement("http://example.org/ns/books/", "", "book");

      // declare default namespace
      marshaller.declareNamespace(null, "http://example.org/ns/books/");

      // add schema location by declaring xsi namespace and adding xsi:schemaReader attribute
      marshaller.declareNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
      marshaller.addAttribute("xsi",
         "schemaReader",
         "string",
         "http://example.org/ns/books/ resources/book/books.xsd"
      );

      // create an instance of Object Model Provider with no book
      ObjectModelProvider provider = new BookObjectProvider();

      // marshall Book instance passing it as an argument instead of using the one that is returned by the BookObjectProvider
      marshaller.marshal(getResourceUrl("xml/book/books.xsd").toString(), provider, book, xmlOutput);

      String xml = xmlOutput.getBuffer().toString();
      if(log.isTraceEnabled())
      {
         log.debug("marshalled with " + marshaller.getClass().getName() + ": " + xml);
      }
      checkMarshalledBook(xml, book);
   }
View Full Code Here


   private void marshallingTest()
      throws Exception
   {
      StringWriter strWriter = new StringWriter();

      AbstractMarshaller marshaller = (AbstractMarshaller)Marshaller.FACTORY.getInstance();
      marshaller.addRootElement("http://jboss.org/xmbean", "xmbean", "mbean");
      marshaller.declareNamespace("xmbean", "http://jboss.org/xmbean");
      marshaller.declareNamespace("jdbcpm", "http://jboss.org/xmbean/persistence/jdbc");

      XMBeanMetaData xmbean = createXMBeanMetaData();
      ObjectModelProvider provider = XMBeanMetaDataProvider.INSTANCE;

      ObjectModelProvider jdbcPmProvider = new JDBCPmMetaDataProvider((JDBCPm)xmbean.getPersistenceManager());
      marshaller.mapClassToGlobalElement(JDBCPm.class,
         "persistence-manager",
         "http://jboss.org/xmbean/persistence/jdbc",
         getResourceUrl("xml/multispaced/jdbcpm.xsd").toString(),
         jdbcPmProvider
      );

      marshaller.marshal(getResourceUrl("xml/multispaced/xmbean.xsd").toString(), provider, xmbean, strWriter);

      final String xml = strWriter.getBuffer().toString();
      log.debug("marshalled with " + marshaller.getClass().getName() + ": " + xml);

      StringReader xmlReader = new StringReader(xml);
      XMBeanMetaData unmarshalled = unmarshalXMBean(xmlReader);

      assertEquals(xmbean, unmarshalled);
View Full Code Here

   private void marshallingTest()
      throws Exception
   {
      StringWriter strWriter = new StringWriter();

      AbstractMarshaller marshaller = (AbstractMarshaller)Marshaller.FACTORY.getInstance();
      marshaller.addRootElement("http://jboss.org/xmbean", "xmbean", "mbean");
      marshaller.declareNamespace("xmbean", "http://jboss.org/xmbean");
      marshaller.declareNamespace("jdbcpm", "http://jboss.org/xmbean/persistence/jdbc");

      XMBeanMetaData xmbean = createXMBeanMetaData();
      ObjectModelProvider provider = XMBeanMetaDataProvider.INSTANCE;

      ObjectModelProvider jdbcPmProvider = new JDBCPmMetaDataProvider((JDBCPm)xmbean.getPersistenceManager());
      marshaller.mapClassToGlobalElement(JDBCPm.class,
         "persistence-manager",
         "http://jboss.org/xmbean/persistence/jdbc",
         getResourceUrl("xml/multispaced/jdbcpm.xsd").toString(),
         jdbcPmProvider
      );

      marshaller.marshal(getResourceUrl("xml/multispaced/xmbean.xsd").toString(), provider, xmbean, strWriter);

      final String xml = strWriter.getBuffer().toString();
      log.debug("marshalled with " + marshaller.getClass().getName() + ": " + xml);

      StringReader xmlReader = new StringReader(xml);
      XMBeanMetaData unmarshalled = unmarshalXMBean(xmlReader);

      assertEquals(xmbean, unmarshalled);
View Full Code Here

      // get the output writter to write the XML content
      StringWriter xmlOutput = new StringWriter();

      // create an instance of XML Schema marshaller
      AbstractMarshaller marshaller = (AbstractMarshaller)Marshaller.FACTORY.getInstance();

      // we need to specify what elements are top most (roots) providing namespace URI, prefix and local name
      marshaller.addRootElement("http://example.org/ns/books/", "", "book");

      // declare default namespace
      marshaller.declareNamespace(null, "http://example.org/ns/books/");

      // add schema location by declaring xsi namespace and adding xsi:schemaReader attribute
      marshaller.declareNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
      marshaller.addAttribute("xsi",
         "schemaReader",
         "string",
         "http://example.org/ns/books/ resources/book/books.xsd"
      );

      // create an instance of Object Model Provider with no book
      ObjectModelProvider provider = new BookObjectProvider();

      // marshall Book instance passing it as an argument instead of using the one that is returned by the BookObjectProvider
      marshaller.marshal(getResource("/xml/book/books.xsd").toString(), provider, book, xmlOutput);

      String xml = xmlOutput.getBuffer().toString();
      if(log.isTraceEnabled())
      {
         log.debug("marshalled with " + marshaller.getClass().getName() + ": " + xml);
      }
      checkMarshalledBook(xml, book);
   }
View Full Code Here

TOP

Related Classes of org.jboss.xb.binding.AbstractMarshaller

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.