KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > ws > rm > CreateSequence


1 /*
2  * Copyright 1999-2004 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  */

17
18 package org.apache.sandesha.ws.rm;
19
20 import org.apache.axis.message.MessageElement;
21 import org.apache.axis.message.SOAPBodyElement;
22 import org.apache.axis.message.SOAPEnvelope;
23 import org.apache.sandesha.Constants;
24
25 import javax.xml.soap.Name JavaDoc;
26 import javax.xml.soap.SOAPException JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 /**
30  * class CreateSequence
31  *
32  * @author Amila Navarathna
33  * @author Jaliya Ekanayaka
34  * @author Sudar Nimalan
35  */

36 public class CreateSequence implements IRmElement {
37
38     /**
39      * Field createSequence
40      */

41     private MessageElement createSequence;
42
43     private SequenceOffer offer;
44
45     private AcksTo acksTo;
46
47     /**
48      * Constructor CreateSequence
49      */

50     public CreateSequence() {
51         createSequence = new MessageElement();
52         createSequence.setName(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.CREATE_SEQUENCE);
53     }
54
55
56     /**
57      * Method getSoapElement
58      *
59      * @return MessageElement
60      */

61     public MessageElement getSoapElement() throws SOAPException JavaDoc {
62         createSequence.addChildElement(acksTo.getSoapElement());
63         createSequence.addChildElement(offer.getSoapElement());
64         return createSequence;
65     }
66
67     /**
68      * Method toSoapEnvelop
69      *
70      * @param envelope
71      * @return SOAPEnvelope
72      * @throws SOAPException
73      */

74     public SOAPEnvelope toSoapEnvelop(SOAPEnvelope envelope) throws SOAPException JavaDoc {
75
76         SOAPEnvelope env = envelope;
77         if (env.getBody() == null) {
78             env.addBody();
79         }
80
81         Name JavaDoc name = env.createName("", Constants.WSRM.NS_PREFIX_RM, Constants.WSRM.NS_URI_RM);
82         SOAPBodyElement bodyElement = (SOAPBodyElement) env.getBody().addBodyElement(name);
83
84         bodyElement.setName(Constants.WSRM.CREATE_SEQUENCE);
85
86         if (acksTo != null)
87             acksTo.toSOAPEnvelope(bodyElement);
88         if (offer != null)
89             offer.toSOAPEnvelope(bodyElement);
90
91         return env;
92     }
93
94     /**
95      * Method fromSOAPEnveploe
96      *
97      * @param bodyElement
98      * @return CreateSequence
99      */

100     public CreateSequence fromSOAPEnveploe(SOAPBodyElement bodyElement) throws Exception JavaDoc {
101
102         Iterator JavaDoc iterator = bodyElement.getChildElements();
103         MessageElement childElement;
104         while (iterator.hasNext()) {
105
106             //TODO add offer processing code here
107
//TEST OFFER
108
childElement = (MessageElement) iterator.next();
109
110             if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.ACKS_TO)) {
111                 acksTo = new AcksTo();
112                 acksTo.fromSOAPEnvelope(childElement);
113             } else if (childElement.getName().equals(Constants.WSRM.ACKS_TO)) {
114                 acksTo = new AcksTo();
115                 acksTo.fromSOAPEnvelope(childElement);
116             } else if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.SEQUENCE_OFFER)) {
117                 offer = new SequenceOffer();
118                 offer.fromSOAPEnvelope(childElement);
119             } else if (childElement.getName().equals(Constants.WSRM.SEQUENCE_OFFER)) {
120                 offer = new SequenceOffer();
121                 offer.fromSOAPEnvelope(childElement);
122             }
123
124         }
125         return this;
126     }
127
128     /**
129      * Method addChildElement
130      *
131      * @param element
132      */

133     public void addChildElement(MessageElement element) {
134     }
135
136
137     public SequenceOffer getOffer() {
138         return offer;
139     }
140
141
142     public void setOffer(SequenceOffer offer) {
143         this.offer = offer;
144     }
145
146     public AcksTo getAcksTo() {
147         return acksTo;
148     }
149
150     public void setAcksTo(AcksTo acksTo) {
151         this.acksTo = acksTo;
152     }
153 }
Popular Tags