1 17 18 package org.apache.sandesha.ws.rm; 19 20 import org.apache.axis.AxisFault; 21 import org.apache.axis.message.MessageElement; 22 import org.apache.axis.message.SOAPEnvelope; 23 import org.apache.axis.message.SOAPHeaderElement; 24 import org.apache.sandesha.Constants; 25 26 import javax.xml.soap.Name ; 27 import javax.xml.soap.SOAPException ; 28 import java.util.Iterator ; 29 30 37 public class Sequence extends MessageElement implements IRmElement { 38 39 42 private MessageElement seqElement; 43 44 47 private Identifier identifier; 48 49 52 private MessageNumber messageNumber; 53 54 57 private LastMessage lastMessage; 58 59 62 public Sequence() { 63 seqElement = new MessageElement(); 64 seqElement.setName(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.SEQUENCE); 65 } 66 67 73 public MessageElement getSoapElement() throws SOAPException { 74 75 seqElement.addChildElement(identifier.getSoapElement()); 76 seqElement.addChildElement(messageNumber.getSoapElement()); 77 seqElement.addChildElement(lastMessage.getSoapElement()); 78 79 return seqElement; 80 } 81 82 89 public SOAPEnvelope toSoapEnvelop(SOAPEnvelope envelope) throws Exception { 90 91 SOAPEnvelope env = envelope; 92 93 if (env.getHeader() == null) { 94 env.addHeader(); 95 } 96 removeHeaders(envelope); 97 98 Name name = env.createName("", Constants.WSRM.NS_PREFIX_RM, Constants.WSRM.NS_URI_RM); 99 SOAPHeaderElement headerElement = (SOAPHeaderElement) env.getHeader().addHeaderElement(name); 100 101 headerElement.setActor(null); 102 headerElement.setName(Constants.WSRM.SEQUENCE); 103 headerElement.setMustUnderstand(true); 104 105 106 if (identifier != null) { 107 identifier.toSOAPEnvelope(headerElement); 108 } 109 110 if (messageNumber != null) { 111 messageNumber.toSOAPEnvelope(headerElement); 112 } 113 114 if (lastMessage != null) { 115 lastMessage.toSOAPEnvelope(headerElement); 116 } 117 118 return env; 119 } 120 121 127 public Sequence fromSOAPEnveploe(SOAPHeaderElement headerElement) throws AxisFault { 128 129 Iterator iterator = headerElement.getChildElements(); 130 MessageElement childElement; 131 132 while (iterator.hasNext()) { 133 childElement = (MessageElement) iterator.next(); 134 135 if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.IDENTIFIER)) { 136 identifier = new Identifier(); 137 identifier.fromSOAPEnvelope(childElement); 138 } 139 140 if (childElement.getName().equals(Constants.WSRM.IDENTIFIER)) { 141 identifier = new Identifier(); 142 identifier.fromSOAPEnvelope(childElement); 143 } 144 145 if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.MSG_NUMBER)) { 146 messageNumber = new MessageNumber(); 147 messageNumber.fromSOAPEnvelope(childElement); 148 } 149 150 if (childElement.getName().equals(Constants.WSRM.MSG_NUMBER)) { 151 messageNumber = new MessageNumber(); 152 messageNumber.fromSOAPEnvelope(childElement); 153 } 154 155 if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.LAST_MSG)) { 156 lastMessage = new LastMessage(); 157 lastMessage.fromSOAPEnvelope(childElement); 158 } 159 160 if (childElement.getName().equals(Constants.WSRM.LAST_MSG)) { 161 lastMessage = new LastMessage(); 162 lastMessage.fromSOAPEnvelope(childElement); 163 } 164 } 165 166 return this; 167 } 168 169 public void removeHeaders(SOAPEnvelope soapEnvelope) throws Exception { 170 171 Iterator iterator = soapEnvelope.getHeader().getChildElements(); 172 MessageElement childElement; 173 174 while (iterator.hasNext()) { 175 childElement = (MessageElement) iterator.next(); 176 177 if (Constants.WSRM.SEQUENCE.equals(childElement.getName()) && 178 (Constants.WSRM.NS_URI_RM.equals(childElement.getNamespaceURI()))) { 179 childElement.detachNode(); 180 break; 181 } 182 } 183 } 184 185 191 public void addChildElement(MessageElement element) throws SOAPException { 192 seqElement.addChildElement(element); 193 } 194 195 200 public Identifier getIdentifier() { 201 return identifier; 202 } 203 204 209 public LastMessage getLastMessage() { 210 return lastMessage; 211 } 212 213 218 public MessageNumber getMessageNumber() { 219 return messageNumber; 220 } 221 222 227 public void setIdentifier(Identifier identifer) { 228 identifier = identifer; 229 } 230 231 236 public void setLastMessage(LastMessage message) { 237 lastMessage = message; 238 } 239 240 245 public void setMessageNumber(MessageNumber number) { 246 messageNumber = number; 247 } 248 } | Popular Tags |