WebSphere Enterprise Service Bus, Version 6.2.0 Operating Systems: AIX, HP-UX, i5/OS, Linux, Solaris, Windows


Arrays in business objects

You can define arrays for an element in a business object so that the element can contain more than one instance of data.

You can use a List type to create an array for a single named element in a business object. This will allow you to use that element to contain multiple instances of data. For example, you can use an array to store several telephone numbers within an element named telephone that is defined as a string in its business object wrapper. You can also define the size of the array by specifying the number of data instances using the maxOccurs value. The following example code shows how you would create such an array that will hold three instances of data for that element:
<xsd:element name="telephone" type="xsd:string" maxOccurs="3"/>
This will create a list index for the element telephone that can hold up to three data instances. You may also use the value minOccurs if you are only planning to have one item in the array.
The resulting array consists of two items:
In order to create this array, however, you need perform an intermediate step by defining a wrapper. This wrapper, in effect, replaces the property of the element with an array object. In the example above, you can create an ArrayOfTelephone object to define the element telephone as an array. The following code example shows how you accomplish this task:
<?xml version="1.0" encoding="UTF-8"?>
 	<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 	 	  <xsd:element name="Customer">
 	    <xsd:complexType>
 	      <xsd:sequence>
 	        <xsd:element name="name" type="xsd:string"/>
 	        <xsd:element name="ArrayOfTelephone" type="ArrayOfTelephone"/>
 	      </xsd:sequence>
 	    </xsd:complexType>
 	  </xsd:element>

 	  <xsd:complexType name="ArrayOfTelephone">
 	    <xsd:sequence maxOccurs="3">
 	      <xsd:element name="telephone" type="xsd:string" nillable="true"/>
 	    </xsd:sequence>
 	  </xsd:complexType> 
	</xsd:schema>

The telephone element now appears as a child of the ArrayOfTelephone wrapper object.

Note that in the example above, the telephone element contains a property named nillable. You can set this property to true if you want to certain items in the array index to contain no data. The following example code shows how the data in an array may be represented:
<Customer>
	  <name>Bob</name>
	  <ArrayOfTelephone>
	    <telephone>111-1111</telephone>
	    <telephone xsi:nil="true"/>
	    <telephone>333-3333</telephone>
	  </ArrayOfTelephone>
	</Customer>
In this case, the first and third items in the array index for the telephone element contain data, while the second item does not contain any data. If you had not used the nillable property for the telephone element, then you would have had to have the first two elements contain data.
You can use the Service Data Object (SDO) Sequence APIs in WebSphere® Process Server as an alternative method to handle sequences in business object arrays. The following example code will create an array for the telephone element with data identical to that shown above:
DataObject customer = ...
	customer.setString("name", "Bob");
	 
	DataObject tele_array = customer.createDataObject("ArrayOfTelephone");
	Sequence seq = tele_array.getSequence();  // The array is sequenced
	seq.add("telephone", "111-1111");
	seq.add("telephone", null);
	seq.add("telephone", "333-3333");
You can return the data for a given element array index by using code similar to the example below:
String tele3 = tele_array.get("telephone[3]");  // tele3 = "333-3333"
In this example, a string named tele3 will return the data "333-3333".

You can fill the data items for the array in the list index by using fixed width or delimited data placed in a JMS or MQ message queue. You can also accomplish this task by using a flat text file that contains the properly formatted data


concept Concept topic

Terms of use | Feedback


Timestamp icon Last updated: 21 June 2010


http://publib.boulder.ibm.com/infocenter/dmndhelp/v6r2mx/topic//com.ibm.websphere.wesb620.doc/doc/cpro_array_define.html
Copyright IBM Corporation 2005, 2010. All Rights Reserved.
This information center is powered by Eclipse technology (http://www.eclipse.org).