1 17 18 package org.apache.sandesha.ws.rm; 19 20 import org.apache.axis.message.MessageElement; 21 import org.apache.axis.message.SOAPEnvelope; 22 import org.apache.axis.message.SOAPHeaderElement; 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 import java.util.LinkedList ; 29 import java.util.List ; 30 31 38 public class SequenceAcknowledgement extends MessageElement implements IRmElement { 39 40 43 private MessageElement seqAck; 45 48 private List ackRanges; 49 50 53 private List nackList; 54 55 58 private Identifier identifier; 59 60 63 public SequenceAcknowledgement() { 64 65 ackRanges = new LinkedList (); 66 nackList = new LinkedList (); 67 seqAck = new MessageElement(); 68 69 seqAck.setName(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.SEQUENCE_ACK); 70 } 71 72 78 public MessageElement getSoapElement() throws SOAPException { 79 80 Iterator ite = ackRanges.iterator(); 81 82 while (ite.hasNext()) { 83 MessageElement element = (MessageElement) ite.next(); 84 85 seqAck.addChildElement(element); 86 } 87 88 ite = nackList.iterator(); 89 90 while (ite.hasNext()) { 91 MessageElement element = (MessageElement) ite.next(); 92 93 seqAck.addChildElement(element); 94 } 95 96 seqAck.addChildElement(identifier.getSoapElement()); 97 98 return seqAck; 99 } 100 101 108 public SOAPEnvelope toSoapEnvelop(SOAPEnvelope envelope) throws SOAPException { 109 110 SOAPEnvelope env = envelope; 111 112 if (env.getHeader() == null) { 113 env.addHeader(); 114 } 115 116 Name name = env.createName("", Constants.WSRM.NS_PREFIX_RM, Constants.WSRM.NS_URI_RM); 117 SOAPHeaderElement headerElement = (SOAPHeaderElement) env.getHeader().addHeaderElement(name); 118 119 headerElement.setActor(null); 120 headerElement.setName(Constants.WSRM.SEQUENCE_ACK); 121 headerElement.setMustUnderstand(true); 122 123 Iterator iterator = ackRanges.iterator(); 124 125 while (iterator.hasNext()) { 126 127 AcknowledgementRange ackRange = (AcknowledgementRange) iterator.next(); 128 ackRange.toSOAPEnvelope(headerElement); 129 } 130 131 iterator = nackList.iterator(); 132 133 while (iterator.hasNext()) { 134 Nack nack = (Nack) iterator.next(); 135 136 nack.toSOAPEnvelope(headerElement); 137 } 138 139 if (identifier != null) { 140 identifier.toSOAPEnvelope(headerElement); 141 } 142 143 return env; 144 } 145 146 152 public SequenceAcknowledgement fromSOAPEnveploe(SOAPHeaderElement headerElement) { 153 154 Iterator iterator = headerElement.getChildElements(); 155 MessageElement childElement; 156 157 while (iterator.hasNext()) { 158 159 childElement = (MessageElement) iterator.next(); 160 161 if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.IDENTIFIER)) { 162 identifier = new Identifier(); 163 identifier.fromSOAPEnvelope(childElement); 164 } 165 166 if (childElement.getName().equals(Constants.WSRM.IDENTIFIER)) { 167 identifier = new Identifier(); 168 identifier.fromSOAPEnvelope(childElement); 169 } 170 171 if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.ACK_RANGE)) { 172 AcknowledgementRange ackRange = new AcknowledgementRange(); 173 174 ackRange.fromSOAPEnvelope(childElement); 175 ackRanges.add(ackRange); 176 } 177 178 if (childElement.getName().equals(Constants.WSRM.ACK_RANGE)) { 179 AcknowledgementRange ackRange = new AcknowledgementRange(); 180 ackRange.fromSOAPEnvelope(childElement); 181 ackRanges.add(ackRange); 182 } 183 184 if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.NACK)) { 185 Nack nack = new Nack(); 186 nack.fromSOAPEnvelope(childElement); 187 } 188 189 if (childElement.getName().equals(Constants.WSRM.NACK)) { 190 Nack nack = new Nack(); 191 nack.fromSOAPEnvelope(childElement); 192 } 193 } 194 195 return this; 196 } 197 198 204 public void addChildElement(MessageElement element) throws SOAPException { 205 seqAck.addChildElement(element); 206 } 207 208 213 public List getAckRanges() { 214 return ackRanges; 215 } 216 217 222 public Identifier getIdentifier() { 223 return identifier; 224 } 225 226 231 public List getNackList() { 232 return nackList; 233 } 234 235 241 public AcknowledgementRange addAckRanges(AcknowledgementRange ackRange) { 242 243 ackRanges.add(ackRange); 244 245 return ackRange; 246 } 247 248 254 public Nack addNackRanges(Nack nack) { 255 256 nackList.add(nack); 257 258 return nack; 259 } 260 261 266 public void setIdentifier(Identifier identifier) { 267 this.identifier = identifier; 268 } 269 270 275 public void setAckRanges(List list) { 276 ackRanges = list; 277 } 278 } | Popular Tags |