KickJava   Java API By Example, From Geeks To Geeks.

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


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.Constants;
19 import org.apache.axis2.addressing.AddressingConstants;
20 import org.apache.axis2.addressing.EndpointReference;
21 import org.apache.axis2.clientapi.Call;
22 import org.apache.axis2.clientapi.Callback;
23 import org.apache.axis2.engine.AxisFault;
24 import org.apache.axis2.om.OMElement;
25 import sample.amazon.amazonSimpleQueueService.OMElementCreator;
26
27 import javax.swing.*;
28
29 /**
30  * This will create the Excutable code which runs seperately of GUI interations
31  *
32  * @author Saminda Abeyruwan <saminda@opensource.lk>
33  */

34 public class RunnableCreateQueue extends QueueManager implements Runnable JavaDoc {
35     JTextField createQueue;
36     JTextArea result;
37     JTextField queueCode;
38     JTextField enqueue;
39
40     public RunnableCreateQueue(JTextField createQueue, JTextField queueCode, JTextField enqueue,
41                                JTextArea result) {
42         this.createQueue = createQueue;
43         this.queueCode = queueCode;
44         this.enqueue = enqueue;
45         this.result = result;
46     }
47
48     public void run() {
49         if (this.createQueue.isEditable()) {
50             OMElement createQueueElement = OMElementCreator.creatQueueElement(
51                     this.createQueue.getText(),getKey());
52             this.axis2EngineRuns("CreateQueue", createQueueElement,
53                     new SimpleQueueCreateQueueCallbackHandler(this.createQueue, this.queueCode,
54                             this.enqueue, this.result));
55         }
56         if (this.enqueue.isEditable()) {
57             OMElement enqueueElement = OMElementCreator.enqueueElement(this.enqueue.getText(),
58                     this.queueCode.getText(),getKey());
59             this.axis2EngineRuns("Enqueue", enqueueElement, new SimpleQueueEnqueueCallbackHandler(
60                     this.createQueue, this.queueCode, this.enqueue, this.result));
61         }
62     }
63
64     private void axis2EngineRuns(String JavaDoc operation, OMElement element,
65                                  Callback specificCallbackObject) {
66         //endpoint uri is hard coded....
67
String JavaDoc url = "http://webservices.amazon.com/onca/soap?Service=AWSSimpleQueueService";
68         try {
69             Call call = new Call();
70             call.setTo(new EndpointReference(AddressingConstants.WSA_TO, url));
71             call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
72             call.invokeNonBlocking(operation, element, specificCallbackObject);
73         } catch (AxisFault axisFault) {
74             axisFault.printStackTrace();
75         } catch (Exception JavaDoc e) {
76             e.printStackTrace();
77         }
78     }
79
80 }
81
Popular Tags