Search in sources :

Example 1 with ObjectFactory

use of org.switchyard.quickstarts.demos.library.types.ObjectFactory in project quickstarts by jboss-switchyard.

the class Library method toString.

public String toString(boolean detailed) {
    StringWriter sw = new StringWriter();
    synchronized (librarian) {
        try {
            if (detailed) {
                JAXBContext ctx = JAXBContext.newInstance("org.switchyard.quickstarts.demos.library.types");
                Marshaller m = ctx.createMarshaller();
                m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
                ObjectFactory of = new ObjectFactory();
                for (Book book : isbns_to_books.values()) {
                    int quantity = isbns_to_quantities.get(book.getIsbn());
                    sw.write("\nBook (quantity=" + quantity + ")\n");
                    m.marshal(of.createBook(book), sw);
                    sw.write('\n');
                }
            } else {
                for (Book book : isbns_to_books.values()) {
                    int quantity = isbns_to_quantities.get(book.getIsbn());
                    sw.write(book.getTitle() + " (" + quantity + ")\n");
                }
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    return sw.toString().trim();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) ObjectFactory(org.switchyard.quickstarts.demos.library.types.ObjectFactory) Book(org.switchyard.quickstarts.demos.library.types.Book) JAXBContext(javax.xml.bind.JAXBContext)

Aggregations

StringWriter (java.io.StringWriter)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Book (org.switchyard.quickstarts.demos.library.types.Book)1 ObjectFactory (org.switchyard.quickstarts.demos.library.types.ObjectFactory)1