KickJava   Java API By Example, From Geeks To Geeks.

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


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 SimpleQueueEnqueueCallbackHandler extends Callback {
33     private static String JavaDoc returnString = "";
34     private JTextField createQueue;
35     private JTextArea result;
36     private JTextField queueCode;
37     private JTextField enqueue;
38
39     public SimpleQueueEnqueueCallbackHandler() {
40     }//defaultConstructor
41

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