Glassfish ESB: The only viable Enterprise Service Bus Life, The Universe and some other things

Tuesday Mar 17, 2009

The BPEL 2.0 implementation within GlassFishESB offers a useful functoid that will generate a dateTime string that conforms to section 3.2.7 of the W3C Standard for the dateTime datatype. Unfortunately, there are no supporting functoids that facilitate arithmetic adjustment or alternative formatting of these strings.

A Java class is now available to help with this limitation. This may be invoked using the Sun BPEL to Java calling extension (See here for more information).

The class is com.sun.fast.util.DateAdjust

The methods are adjust(String,String,String) and format(String,String).

Adjusting the dateTime
Here's an example of how you can adjust a dateTime arithmetically in BPEL.

<assign name="AssignDateTime">
 <copy>
  <from>sxxf:current-dateTime()</from>
  <to variable="bpelDate"/>
 </copy>
</assign>
<assign name="AssignDoAdjustment">
 <copy xmlns:dateAdjust="java://com.sun.fast.util.DateAdjust">
  <from>dateAdjust:adjust($bpelDate,'M','11')</from>
  <to variable="bpelDate"/>
 </copy>
 </assign>

In the first assignment, we copy the dateTime string to a previously defined variable.

In the second assignment we invoke the adjust method and specify that we want 11 months added. The result is copied back to the same variable.

If the input dateTime to this method is 2009-03-17T09:17:03.01+00:00 then the output for this example would be 2010-02-17T09:17:03.01+00:00

[ Note:- This class does not offer any facility to adjust the fractional seconds part. This will always be returned as is ]

USAGE:

The first parameter must be a well-formed dateTime string.

The second parameter must be one of the following:-

Y - Year

M - Month

D - Day

H - hour

m - minute

S - second

The third parameter must be a string representation of an integer (may be negative)

Re-formatting the dateTime
This utility method uses java.text.SimpleDateFormat to perform the formatting. Therefore, the user needs to be aware of the format string syntax for this class.
Usage is very simple in the style shown earlier. In this assign extract, we want to return the date in yyMMdd style:-

  <from>dateAdjust:format($bpelDate,'yyMMdd')</from>

Using the same input as above, the output would be "090317"
The utility implementation is available here
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed