WS-AppServer BusObject Mapping (3)

In last post, we had a look at mapping a database query result to a BusObject. This post lists you the WS-AppServer facilities which you can use for mapping data into a target BusObject, taken from a source XML or source BusObject/BusObjects.
Suppose you are getting data from an Enterprise Information System. The data structure has been fully prepared already as per the definition of the WS-AppServer class. In that case, you can directly set the object data. Taking forward the bankaccount example, but assume it’s coming from EIS now, your XML might look like this:

<AccountFull xmlns="http://schemas.cordys.com/TestDB">
  <AccountID>1</AccountID>
  <CustomerID>2</CustomerID>
  <BondType>1</BondType>
  <Dividend>2456</Dividend>
  <Customer>
    <CustomerID>2</CustomerID>
    <Name>Howard Ldt</Name>
    <Address>Hovard road 2412, AD</Address>
  </Customer>
  <RiskProfile>
    <RiskLevel>2</RiskLevel>
    <DateAccessed>2012-12-03</DateAccessed>
  </RiskProfile>
</AccountFull>

Take care of the namespace!

Setting the object data of a fresh object can now be done like this:

No event handlers will be fired, which is most likely also not needed.  Memory cleanup responsibility for eisXmlHandle is still with the caller (see API documentation).

In most cases, the XML as comes from the EIS won’t fit as per the WS-AppServer class definition. In that case, first an XSLT transformation can be applied with help from an XSLT in XML Store:

Now suppose you have an AccountSummary class. You want to map the data from an existing AccountFull busObject, for the bold elements:

<AccountFull xmlns="http://schemas.cordys.com/TestDB">
  <AccountID>1</AccountID>
  <CustomerID>2</CustomerID>
  <BondType>1</BondType>
  <Dividend>2456</Dividend>
  <Customer>
    <CustomerID>2</CustomerID>
    <Name>Howard Ldt</Name>
    <Address>Hovard road 2412, AD</Address>
  </Customer>
  <RiskProfile>
    <RiskLevel>2</RiskLevel>
    <DateAccessed>2012-12-03</DateAccessed>
  </RiskProfile>
</AccountFull>

This can be done in 2 steps. First we map the needed attributes from the top level using sys_mapAttributes. Subsequently, we map the inner Customer structure using sys_mapAttributesEx:

In the second step, effectively an inner object gets established.

In case you want to map the data the other way back, use sys_mapAttributesReverse, using same mapping array:

Now suppose, you want to map an XML to an inner busobject using setObjectData(). Or you want to map a subset of attributes from a source object to the inner object. In that case, we will first need to create the inner object (upon creating a new busobject, initially no attributes and no inner objects will be there).

Subsequently you can map into the customer target object.

Last option I want to show you is applicable for a situation in which you can map a whole structure into the target, but maybe just one substructure is not applicable. In that case, you can use the ‘sys_dropPropertyXML’ method. Suppose we want to eliminate the RiskProfile from an AccountFull object:

By supplying ‘true’, the NOM memory gets garbage collected for this substructure.

And that concludes the 3-part series on BusObject Mapping. By this you should have a good toolbox of facilities to manage your WS-AppServer UI, business and data objects. I’m leaving you with a link to the CROM Framework as found on Cordys wiki, which also touches on the topic of ORM mapping, and gives support for Order-OrderLine-Item type of patterns.

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>