KickJava   Java API By Example, From Geeks To Geeks.

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


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 SimpleQueueDeleteQueueCallbackHandler extends Callback {
32     private String JavaDoc returnString = "";
33     JTextArea results;
34     JButton button;
35     public SimpleQueueDeleteQueueCallbackHandler(){}//defalut handler
36
public SimpleQueueDeleteQueueCallbackHandler(JTextArea results,JButton button){
37         super();
38         this.results = results;
39         this.button = button;
40     }
41     public void onComplete(AsyncResult result) {
42         SOAPBody body = result.getResponseEnvelope().getBody();
43         this.getQueueDeleteStatus(body);
44         this.button.setText("Delete Queue");
45     }
46     public void reportError(Exception JavaDoc e) {
47
48     }
49     private void getQueueDeleteStatus(OMElement element) {
50         Iterator JavaDoc iterator = element.getChildren();
51         while (iterator.hasNext()) {
52             OMNode omNode = (OMNode) iterator.next();
53             if (omNode.getType() == OMNode.ELEMENT_NODE) {
54                 OMElement omElement = (OMElement) omNode;
55                 if (omElement.getLocalName().equals("Status")) {
56                     this.readTheQueue(omElement);
57                 }else{
58                     getQueueDeleteStatus(omElement);
59                 }
60             }
61         }
62     }
63     private void readTheQueue(OMElement element) {
64         if (element.getText().equals("Errors")) {
65             returnString += "Queue can't be deleted, it has to be dequeued first" + "\n";
66         }
67         else{
68            returnString += "Queue is deleted" + "\n";
69         }
70         this.results.setText(returnString + "\n");
71     }
72 }
73
Popular Tags