WebSphere WebSphere Business Integration Message Service Clients for C/C++ Version 1.2.7 and .NET Version 1.2.6 Operating Systems: AIX, Linux, Solaris, Windows

Iterators

An iterator encapsulates a list of objects and a cursor that maintains the current position in the list. A C or C++ application uses an iterator to retrieve each object in the list in turn.

When an iterator is created, the position of the cursor is before the first object. An application uses an iterator to retrieve each object in turn. To retrieve the objects, the application uses the following three methods of the Iterator class:

The Iterator class is equivalent to the Enumerator class in Java. XMS .NET is similar to Java and uses an IEnumerator interface.

An application can use an iterator to perform the following tasks:
The following code fragment shows how a C application can use an iterator to print out all properties of a message:
/********************************************************/
/* XMS Sample using an iterator to browse properties    */
/********************************************************/
rc = xmsMsgGetProperties(hMsg, &it, xmsError);
if (rc == XMS_OK)
{
  rc = xmsIteratorHasNext(it, &more, xmsError);
  while (more)
  {
    rc = xmsIteratorGetNext(it, (xmsHObj)&p, xmsError);
    if (rc == XMS_OK)
    {
      xmsPropertyGetName(p, name, 100, &len, xmsError);
      printf("Property name=\"%s\"\n", name);
      xmsPropertyGetTypeId(p, &type, xmsError);
      switch (type)
      {
        case XMS_PROPERTY_TYPE_INT:
        {
          xmsINT value=0;
          xmsPropertyGetInt(p, &value, xmsError);
          printf("Property value=%d\n", value);
          break;
        }
        case XMS_PROPERTY_TYPE_STRING:
        {
          xmsINT len=0;
          char value[100];
          xmsPropertyGetString(p, value, 100, &len, xmsError);
          printf("Property value=\"%s\"\n", value);
          break;
        }
        default:
        {
          printf("Unhandled property type (%d)\n", (int)type);
        }
      }
      xmsPropertyDispose(&p, xmsError);
    }
    rc = xmsIteratorHasNext(it, &more, xmsError);
  }
  printf("Finished iterator....\n");
  xmsIteratorDispose(&it, xmsError);
}
/********************************************************/

Concept topic

Terms of Use | Rate this page

Last updated: 18 Jun 2008

© Copyright IBM Corporation 2005, 2008. All Rights Reserved.