KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
28  * Callback class which deals with the outcome of the operation
29  *
30  * @author Saminda Abeyruwan <saminda@opensource.lk>
31  */

32 public class SimpleQueueListMyQueuesCallbackHandler extends Callback {
33     private String JavaDoc returnString = "Listing Available Queues......\n";
34     private JTextField createQueue;
35     private JTextArea result;
36     private JTextField queueCode;
37     private JTextField read;
38     private JButton button;
39
40     public SimpleQueueListMyQueuesCallbackHandler() {
41     }//defaultConstructor
42

43     public SimpleQueueListMyQueuesCallbackHandler(JTextField createQueue, JTextField queueCode,
44                                                   JTextField read, JTextArea result,
45                                                   JButton button) {
46         super();
47         this.createQueue = createQueue;
48         this.queueCode = queueCode;
49         this.read = read;
50         this.result = result;
51         this.button = button;
52     }
53
54     public void onComplete(AsyncResult result) {
55         SOAPBody body = result.getResponseEnvelope().getBody();
56         getResults(body);
57         this.button.setText("Load Queue");
58     }
59
60     public void reportError(Exception JavaDoc e) {
61
62     }
63
64     private boolean getResults(OMElement element) {
65         Iterator JavaDoc iterator = element.getChildren();
66         while (iterator.hasNext()) {
67             OMNode omNode = (OMNode) iterator.next();
68             if (omNode.getType() == OMNode.ELEMENT_NODE) {
69                 OMElement omElement = (OMElement) omNode;
70                 if ((omElement.getLocalName().equals("QueueId"))
71                         || (omElement.getLocalName().equals("QueueName"))) {
72
73                     if (omElement.getLocalName().equals("QueueId")) {
74                         this.getText(omElement);
75                     }
76                     if (omElement.getLocalName().equals("QueueName")) {
77                         this.getText(omElement);
78                     }
79
80                 } else {
81                     getResults(omElement);
82                 }
83             }
84         }
85         return false;
86     }
87
88     public String JavaDoc getReturnString() {
89         return this.returnString;
90     }
91
92     private void getText(OMElement element) {
93         returnString = returnString + element.getText() + "\n";
94         this.result.setText(returnString);
95     }
96 }
97
Popular Tags