This section provides the following examples that illustrate how the adapter processes a business object:
The following sample code illustrates connector code that writes a simple message ("Hello World") to WebSphere MQ.
/********************************************** *Create the MQSession object and access the MQQueueManager and (local) MQQueue **********************************************/ MQSession MQSess = new MQSession(); iDispatch = MQSess.AccessQueueManager("COMTest"); MQQueueManager QMgr = new MQQueueManager(iDispatch); QMgr.Connect(); MQQueue MyQueue=new MQQueue(QMgr.AccessQueue_4("SYSTEM.DEFAULT.LOCAL.QUEUE",17)); MyQueue.Open(); MQMessage PutMsg = new MQMessage(MQSess.AccessMessage()); //write a string to the message PutMsg.WriteString("Hello World";); //put the message on the queue MyQueue.Put(PutMsg); MyQueue.Close(); QMgr.Disconnect();
The following sample screens illustrate the business object structure and application specific information required for the code in the Connector call sequence sample to function properly. The business object illustrated in these sample screens uses the Create verb.
Figure 5. Business object level ASI and supported verbs
Figure 5 illustrates the top-level business object, MQ_MQSession, which corresponds to the first object created in the method sequence. The Create verb ASI contains AccessQueueManager, which is the function that will allow access to an MQQueueManager object.
AccessQueueManager returns an object of type Integer. This object can be passed into the constructor of MQQueueManager to create an instance of the MQQueueManager proxy.
Note that the business object level ASI contains the string proxy_class=mqtest.MQSession, which is the proxy object that represents the COM component for this business object. For a description of the proxy_class ASI, see Table 4.
Figure 6. Business object hierarchy for the MQSession object
Figure 6 illustrates the business object hierarchy, from the parent (MQSession) all the way down to the lowest-level child.
AccessQueueManager is a method that returns an iDispatch pointer, which is mapped to MQQueueManager (designated as the Return_Value attribute in the business object). MQQueueManager is a proxy object, represented by the child object MQ_MQQueueManager in the business object structure shown in Figure 6.
Figure 7. Method call sequence for MQ_MQQueueManager
Figure 7 illustrates the method sequence on the verb Create of the business object MQ_MQQueueManager.
The sequence is made up of the following three methods:
Note that in the BO structure illustrated in Figure 6, AccessQueue_4 returns a proxy object, called MQ_MQQueue. Therefore, the connector will process this returned proxy object (which is the child of AccessQueue_4) after executing AccessQueue4 and before executing Disconnect, the third and last method in the call sequence of MQ_MQQueueManager.
Figure 8. Method call sequence for MQ_MQQueue
Figure 8 illustrates the method sequence for MQ_MQQueue, the child of AccessQueue_4 (Figure 6). The call sequence is made up of the following three methods:
The Put method takes MQMessage as an argument, so the connector must create the MQMessage object (and execute methods on it) before executing the Put method.
Note that the recursive nature of the connector's processing behavior means that Put is executed before the Disconnect method of MQ_MQQueueManager (Figure 7), the parent of AccessQueue_4 (Figure 6).
Figure 9. Method call sequence for MQMessage
Figure 9 illustrates the method sequence for MQMessage. This sequence calls only the WriteString method, which takes a simple string as an argument. In this example, the argument is the "Hello World" message. The message is written to WebSphere MQ and then the connector continues processing methods in the recursive sequence described in this section: after calling WriteString, the connector "backtracks" up the hierarchy and executes the Close method of MQ_MQQueue (Figure 8), followed by the Disconnect method of MQ_MQQueueManager (Figure 7).