KickJava   Java API By Example, From Geeks To Geeks.

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


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  *
29  * @author Saminda Abeyruwan <saminda@opensource.lk>
30  */

31 public class SimpleQueueCreateQueueCallbackHandler extends Callback {
32     private static String JavaDoc returnString = "";
33     private JTextField createQueue;
34     private JTextArea result;
35     private JTextField queueCode;
36     private JTextField enqueue;
37
38     public SimpleQueueCreateQueueCallbackHandler() {
39     }//defaultConstructor
40

41     public SimpleQueueCreateQueueCallbackHandler(JTextField createQueue, JTextField queueCode,
42                                                  JTextField enqueue, JTextArea result) {
43         super();
44         this.createQueue = createQueue;
45         this.queueCode = queueCode;
46         this.enqueue = enqueue;
47         this.result = result;
48     }
49
50     public void onComplete(AsyncResult result) {
51         SOAPBody body = result.getResponseEnvelope().getBody();
52         getResults(body);
53     }
54
55     public void reportError(Exception JavaDoc e) {
56
57     }
58
59     private boolean getResults(OMElement element) {
60         Iterator JavaDoc iterator = element.getChildren();
61         while (iterator.hasNext()) {
62             OMNode omNode = (OMNode) iterator.next();
63             if (omNode.getType() == OMNode.ELEMENT_NODE) {
64                 OMElement omElement = (OMElement) omNode;
65                 if ((omElement.getLocalName().equals("Status"))
66                         || (omElement.getLocalName().equals("QueueId"))) {
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                 this.enqueue.setEditable(true);
85                 returnString = returnString + "Successfully Added the new Queue.." +
86                         "[" + this.createQueue.getText() + "]" + "\n";
87                 this.result.setText(returnString);
88             }
89             if (element.getText().equals("Warnings")) {
90                 this.enqueue.setEditable(true);
91                 this.createQueue.setEditable(false);
92                 returnString = returnString + "Enque the existing queue.." +
93                         "[" + this.createQueue.getText() + "]" + "..Allow Enquring data";
94                 this.result.setText(returnString);
95             }
96         }
97         if (element.getLocalName().equals("QueueId")) {
98             this.queueCode.setText(element.getText());
99         }
100     }
101 }
Popular Tags