1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
26 import javax.xml.soap.SOAPException;
27 import java.util.Iterator;
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 {
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 {
75
76 SOAPEnvelope env = envelope;
77 if (env.getBody() == null) {
78 env.addBody();
79 }
80
81 Name 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 {
101
102 Iterator iterator = bodyElement.getChildElements();
103 MessageElement childElement;
104 while (iterator.hasNext()) {
105
106
107
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 }