1 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 ; 26 27 32 public class SimpleQueueEnqueueCallbackHandler extends Callback { 33 private static String returnString = ""; 34 private JTextField createQueue; 35 private JTextArea result; 36 private JTextField queueCode; 37 private JTextField enqueue; 38 39 public SimpleQueueEnqueueCallbackHandler() { 40 } 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 e) { 57 58 } 59 60 private boolean getResults(OMElement element) { 61 Iterator 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 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 |