KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > amazon > amazonSimpleQueueService > util > SimpleQueueReadCallbackHandler


1 /*
2 * Copyright 2004,2005 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */

16 package sample.amazon.amazonSimpleQueueService.util;
17
18 import org.apache.axis2.clientapi.AsyncResult;
19 import org.apache.axis2.clientapi.Callback;
20 import org.apache.axis2.om.OMElement;
21 import org.apache.axis2.om.OMNode;
22 import org.apache.axis2.soap.SOAPBody;
23
24 import javax.swing.*;
25 import java.util.Iterator JavaDoc;
26 /**
27  * Callback class which deals with the outcome of the operation
28  * @author Saminda Abeyruwan <saminda@opensource.lk>
29  *
30  */

31 public class SimpleQueueReadCallbackHandler extends Callback {
32     private String JavaDoc returnString = "";
33     JTextField queueCode;
34     JTextArea results;
35     public SimpleQueueReadCallbackHandler(){}//defalut handler
36
public SimpleQueueReadCallbackHandler(JTextField queueCode, JTextArea results){
37         super();
38         this.queueCode = queueCode;
39         this.results = results;
40     }
41     public void onComplete(AsyncResult result) {
42         SOAPBody body = result.getResponseEnvelope().getBody();
43         this.getQueueEntryBody(body);
44     }
45     public void reportError(Exception JavaDoc e) {
46
47     }
48     private void getQueueEntryBody(OMElement element) {
49         Iterator JavaDoc iterator = element.getChildren();
50         while (iterator.hasNext()) {
51             OMNode omNode = (OMNode) iterator.next();
52             if (omNode.getType() == OMNode.ELEMENT_NODE) {
53                 OMElement omElement = (OMElement) omNode;
54                 if (omElement.getLocalName().equals("QueueEntryBody")) {
55                     this.readTheQueue(omElement);
56                 }else{
57                     getQueueEntryBody(omElement);
58                 }
59             }
60         }
61     }
62     private void readTheQueue(OMElement element) {
63         returnString = returnString + element.getText() + "\n";
64         this.results.setText(returnString + "\n");
65     }
66 }
67
Popular Tags