Skip navigation links

@XmlSchema(prefix="cognos", namespace="")

Package org.apache.juneau.dto.cognos

Cognos Data Transfer Objects

See: Description

Package org.apache.juneau.dto.cognos Description

Cognos Data Transfer Objects

Table of Contents
  1. Cognos serialization support

  2. Cognos parsing support

1 - Cognos serialization support

The DataSet class is a DTO used to convert POJO models directly to Cognos-XML.

Because of the nature of the Cognos XML syntax, only 2-dimensional POJO data structures can be serialized to Cognos-XML.

For example...

  • Collection<Bean>
  • Collection<Map>
  • MyBean[]
  • HashMap[]

The following example shows how to generate Cognos-XML from a POJO. The example uses the AddressBook sample POJO. It should be noted that since the AddressBook class is a subclass of LinkedList, it fulfills the requirement of being a tabular data structure.

// Create our POJO with some entries. AddressBook addressBook = new AddressBook(); addressBook.add( new Person("Barack Obama", "Aug 4, 1961", new Address("1600 Pennsylvania Ave", "Washington", "DC", 20500, true), new Address("5046 S Greenwood Ave", "Chicago", "IL", 60615, false) ) ); addressBook.add( new Person("George Walker Bush", "Jul 6, 1946", new Address("43 Prairie Chapel Rd", "Crawford", "TX", 76638, true), new Address("1600 Pennsylvania Ave", "Washington", "DC", 20500, false) ) ); // Define the Cognos metadata Column[] items = { new Column("name", "xs:String", 255), new Column("age", "xs:int"), new Column("numAddresses", "xs:int") .addPojoSwap( new PojoSwap<Person,Integer>() { @Override public Integer swap(BeanSession session, Person p) { return p.addresses.size(); } } ) }; // Create the Cognos DataSet object DataSet ds = new DataSet(items, addressBook, BeanContext.DEFAULT); // Serialize it to XML String xml = XmlSerializer.DEFAULT_SQ.serialize(ds);

When run, this code produces the following XML...

<?xml version='1.0' encoding='UTF-8'?> <c:dataset xmlns:c=''> <c:metadata> <c:item name='name' type='xs:String' length='255'/> <c:item name='age' type='xs:int'/> <c:item name='numAddresses' type='xs:int'/> </c:metadata> <c:data> <c:row> <c:value>Barack Obama</c:value> <c:value>52</c:value> <c:value>2</c:value> </c:row> <c:row> <c:value>George Walker Bush</c:value> <c:value>67</c:value> <c:value>2</c:value> </c:row> </c:data> </c:dataset>

Other data formats

The following shows examples of what this data structure looks like when serialized to other formats:


2 - Cognos parsing support

The DataSet class can be reconstructed from Cognos/XML using one of the standard XML parsers.


// Parse XML back into original DataSet DataSet ds = XmlParser.DEFAULT.parse(xml, DataSet.class);

Skip navigation links

Copyright © 2018 Apache. All rights reserved.