KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > amazon > amazonSimpleQueueService > OMElementCreator


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;
17
18 import org.apache.axis2.om.OMAbstractFactory;
19 import org.apache.axis2.om.OMElement;
20 import org.apache.axis2.om.OMNamespace;
21 import org.apache.axis2.soap.SOAPFactory;
22
23 /**
24  * This will create the OMElement needed to be used in invokeNonBlocking() method
25  * OMElements are created for CreateQueueu, ListMyQueues, Read, and Enqueue operations
26  *
27  * @author Saminda Abeyruwan <saminda@opensource.lk>
28  */

29 public class OMElementCreator {
30     public static OMElement creatQueueElement(String JavaDoc createQueueElement, String JavaDoc key) {
31         SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
32         OMNamespace opN = factory.createOMNamespace(
33                 "http://webservices.amazon.com/AWSSimpleQueueService/2005-01-01", "nsQ");
34         OMElement createQueue = factory.createOMElement("CreateQueue", opN);
35         OMElement subID = factory.createOMElement("SubscriptionId", opN);
36         OMElement request = factory.createOMElement("Request", opN);
37         OMElement queueName = factory.createOMElement("QueueName", opN);
38         OMElement readLockTimeOutSeconds = factory.createOMElement("ReadLockTimeoutSeconds", opN);
39         request.addChild(queueName);
40         request.addChild(readLockTimeOutSeconds);
41         subID.addChild(factory.createText(key));
42         queueName.addChild(factory.createText(createQueueElement));
43         readLockTimeOutSeconds.addChild(factory.createText("10"));
44         createQueue.addChild(subID);
45         createQueue.addChild(request);
46         return createQueue;
47     }
48     public static OMElement deleteQueueElement(String JavaDoc deleteQueueName, String JavaDoc key) {
49         SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
50         OMNamespace opN = factory.createOMNamespace(
51                 "http://webservices.amazon.com/AWSSimpleQueueService/2005-01-01", "nsQ");
52         OMElement enque = factory.createOMElement("DeleteQueue", opN);
53         OMElement subID = factory.createOMElement("SubscriptionId", opN);
54         OMElement request = factory.createOMElement("Request", opN);
55         OMElement queueName = factory.createOMElement("QueueName", opN);
56         //OMElement queueID = factory.createOMElement("QueueId",opN);
57
request.addChild(queueName);
58         //request.addChild(queueID);
59
subID.addChild(factory.createText(key));
60         queueName.addChild(factory.createText(deleteQueueName));
61         //queueID.addChild(factory.createText(queueIden));
62
enque.addChild(subID);
63         enque.addChild(request);
64         return enque;
65     }
66     public static OMElement enqueueElement(String JavaDoc queueEntyBody, String JavaDoc queueIden, String JavaDoc key) {
67         SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
68         OMNamespace opN = factory.createOMNamespace(
69                 "http://webservices.amazon.com/AWSSimpleQueueService/2005-01-01", "nsQ");
70         OMElement enque = factory.createOMElement("Enqueue", opN);
71         OMElement subID = factory.createOMElement("SubscriptionId", opN);
72         OMElement request = factory.createOMElement("Request", opN);
73         //OMElement queueName = factory.createOMElement("QueueName",opN);
74
OMElement queueID = factory.createOMElement("QueueId", opN);
75         OMElement queueEntryBodies = factory.createOMElement("QueueEntryBodies", opN);
76         OMElement queueEntryBody1 = factory.createOMElement("QueueEntryBody", opN);
77         queueEntryBodies.addChild(queueEntryBody1);
78         //request.addChild(queueName);
79
request.addChild(queueID);
80         request.addChild(queueEntryBodies);
81         subID.addChild(factory.createText(key));
82         //queueName.addChild(factory.createText("Test Queue LSF "));
83
queueID.addChild(factory.createText(queueIden));
84         queueEntryBody1.addChild(factory.createText(queueEntyBody));
85         enque.addChild(subID);
86         enque.addChild(request);
87         return enque;
88     }
89     public static OMElement queueListElement(String JavaDoc key) {
90         SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
91         OMNamespace opN = factory.createOMNamespace(
92                 "http://webservices.amazon.com/AWSSimpleQueueService/2005-01-01",
93                 "nsQ");
94         OMElement listMyQueues = factory.createOMElement("ListMyQueues", opN);
95         OMElement subID = factory.createOMElement("SubscriptionId", opN);
96         OMElement request = factory.createOMElement("Request", opN);
97         subID.addChild(factory.createText(key));
98         listMyQueues.addChild(subID);
99         listMyQueues.addChild(request);
100         return listMyQueues;
101     }
102     public static OMElement read(String JavaDoc requiredQueueName,String JavaDoc key) {
103         SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
104         OMNamespace opN = factory.createOMNamespace(
105                 "http://webservices.amazon.com/AWSSimpleQueueService/2005-01-01", "nsQ");
106         OMElement read = factory.createOMElement("Read", opN);
107         OMElement subID = factory.createOMElement("SubscriptionId", opN);
108         OMElement request = factory.createOMElement("Request", opN);
109         OMElement queueName = factory.createOMElement("QueueName", opN);
110         //OMElement queueID = factory.createOMElement("QueueId",opN);
111
OMElement readCount = factory.createOMElement("ReadCount", opN);
112         request.addChild(queueName);
113         //request.addChild(queueID);
114
request.addChild(readCount);
115         subID.addChild(factory.createText(key));
116         queueName.addChild(factory.createText(requiredQueueName));
117         //queueID.addChild(factory.createText(queueIden));
118
readCount.addChild(factory.createText("25"));
119         read.addChild(subID);
120         read.addChild(request);
121         return read;
122     }
123 }
124
Popular Tags