Container & Global Container in Message Mapping

Posted on Apr. 5, 2010 at 06.01 PM - Kuala Lumpur, Malaysia

When we create a user defined function parameters, a Container object is also automatically added. Sometime, we wonder how to use this standard parameter. One of the usage is to temporarily save objects or values that you want to reuse the next time you call the same user defined function. We can also use a GlobalContainer to exchange values between different user defined functions.

The Container object supports the following methods:

    • - void setParameter(String, Object): saves parameters
    • - Object getParameter(String): reads saved parameters
    • - GlobalContainer getGlobalContainer(): creates GlobalContainer
    • - AbstractTrace getTrace(): creates an AbstractTrace object
    • - Map getTransformationParameters(): reads runtime constants

The GlobalContainer object supports the following methods:

    • - void setParameter(String, Object): saves parameters
    • - Object getParameter(String): reads parameters

The AbstractTrace object supports the following methods:

    • - void addWarning (String)
    • - void addInfo(String)
    • - void addDebugMessage(String)

To illustrate on how to use these GlobalContainer parameters, consider the following example.

GlobalContainer gc = container.getGlobalContainer();

Integer counter = (Integer) gc.getParameter( "counter" );

if ( counter == null ) {

counter = new Integer( 0 );

gc.setParameter ("counter", counter );

}

counter = (Integer) gc.getParameter( "counter" );

counter = new Integer ( counter.intValue() + 1 );

gc.setParameter( "counter", counter );

When the method is called the first time, a local counter is set to 1. This value then stored in the GlobalContainer under the name of counter. Each subsequent time the method is called, the value is retrieved again to the local variable called counter and increased by 1. The new value then again is stored in the GlobalContainer under the name of counter.

Life is beautiful! Let's make it meaningful and colorful!