Join wMUsers | Blog at wMUsers | User Control Panel | Site Map | webMethods Jobs |For Employers

Carl Ozkaynak -- webMethods Ezine Columnist

Complex Record Mapping using Java



By Carl Ozkaynak

 

Introduction

webMethods Records provide interoperability between different systems, companies, and supply chains and offer a common, horizontal message architecture across an enterprise or business line.The webMethods Integration Server offers great flexibility in creating Records. A developer may choose to manually build a Record field-by-field, or alternatively, to automically build a Record based upon imported XML documents, DTDs, or Schemas.

When mapping values between Records, a developer chooses one of three methods:

  1. Flow mapping, from left to right
  2. Built-in transformation services
  3. Mapping and/or transformation within a webMethods Integration Server Java service

This article will focus on the third option -- performing mapping and transformations from within a Java service.


Benefits to Mapping/Transforming in a Java Service

When mapping Records within a Java service, a developer can get/set values from the pipeline and transform/map using Java. For a developer accustomed to Flow mapping or Built-in transformation services, understanding when to apply this approach may yield performance and manageability gains. Some reasons include:

  • Performance bottlenecks: If a particular map step becomes a performance bottleneck, consider replacing the map flow service with Java code to optimize performance. This is especially for CPU-intensive logic involving looping or frequent invocations.
  • The need for speed: If there are very aggressive performance requirements, it might be worth considering performing mapping operations in Java.
  • Error handling: Business requirements may require complex error handling. Mapping within a Java service enables the developer to use try-catch blocks that catch and possibly throw the proper exceptions, properly handling all conditions.
  • Complex calculations: Developers can effectively invoke complex mathematical operations, logical operations, custom date formatting, complex concatenation, and appending values on data.


The Values of IData Objects

In Flow, a webMethods Record may resemble Figure 1 below. The remainder of this webMethods Ezine article will reference this Record as we discuss how to manipulate its values from within a Java service.

The root node of the Record is Order, as seen in Figure 1. Referencing the webMethods API, Order can be set to an IData object named orderList using the following Java code:

    IData orderList = (IData)ValuesEmulator.get(pipeline, "Order");

The IData object orderList contains several sub-nodes. To set the NewOrder node to an IData object, apply the following Java code:

    IData newOrderList = (IData)ValuesEmulator.get(orderList, "NewOrder");

The same logic can be applied to set any sub-nodes with children as an IData object.

    IData bulkOrderList = (IData)ValuesEmulator.get(newOrderList, "BulkOrder");
    IData orderInformationList = (IData)ValuesEmulator.get(bulkOrderList, "OrderInformation");

An easier way to remember this is that (IData in Java service) = (Record in Flow service).


Navigating an IData object in Java

The values inside of an IData object can be easily retrieved, but first a developer must implement methods to access that data.

Continuing the example above, orderInformationList is an IData object it is parent to the Record List OrderItems. To get and set elements within an IData object, it is necessary to create an IdataCursor object.

    IDataCursor idc = orderInformationList.getCursor();

The getCursor() method retrieves an IdataCursor for the IData object orderInformationList. An IdataCursor object contains the most basic methods required to traverse an IData object and to get and set elements within it.

After setting the cursor, it remains in its original, "unpositioned" state. That is, the cursor is not resting on an element of the IData object. To move the cursor to the first key/value pair whose key is equal to "OrganizationType", call the following static method:

    idc.first("OrganizationType");

The cursor is now positioned on the key OrganizationType and its value can be retrieved using the method getValue().

    String organizationType = (String)idc.getValue();

If OrganizationType is the only key to retrieve, be sure to explicitly discard the IdataCursor. Although the Java garbage collector will destroy the object eventually, its explicit destruction will provide more efficient performance.

Use the following method to discard the IdataCursor:

    idc.destroy();



[1]  2  Next>>

Go Deeper on the Subject: The wMUsers Discussion Forums


Carl Ozkaynak is a Senior Application Consultant with NerveWire Inc and has significant experience and expertise in multiple technologies. Carl specializes in system integration and has significant experience in Internet/Intranet, middleware, client/server, and distributed technologies. Carl has designed, delivered and lead Internet and Intranet projects for a variety of industries, including financial services, high-tech manufacturing, and telecommunications.

Carl can be reached via email at


Advertise at wMUsers






  Home | Join wMUsers | Discussion Forums | Knowledge Center | Jobs | Shareware | User Groups | Links |
Contact Us | Terms of Service | Privacy Policy

wMUsers is an independent organization and is not sponsored in any manner by Software AG.


© All Rights Reserved, 2001-2008.