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 AckRequested extends MessageElement implements IRmElement { 38 39 42 private MessageElement ackRequested; 43 44 47 private Identifier identifier; 48 49 52 private MessageNumber messageNumber; 53 54 57 public AckRequested() { 58 ackRequested = new MessageElement(); 59 ackRequested.setName(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.ACK_REQUESTED); 60 } 61 62 63 69 public MessageElement getSoapElement() throws SOAPException { 70 71 ackRequested.addChildElement(identifier.getSoapElement()); 72 ackRequested.addChildElement(messageNumber.getSoapElement()); 73 74 return ackRequested; 75 } 76 77 84 public SOAPEnvelope toSoapEnvelop(SOAPEnvelope envelope) throws Exception { 85 86 SOAPEnvelope env = envelope; 87 removeHeaders(env); 88 89 if (env.getHeader() == null) { 90 env.addHeader(); 91 } 92 93 Name name = env.createName("", Constants.WSRM.NS_PREFIX_RM, Constants.WSRM.NS_URI_RM); 94 SOAPHeaderElement headerElement = (SOAPHeaderElement) env.getHeader().addHeaderElement(name); 95 96 headerElement.setActor(null); 98 headerElement.setName(Constants.WSRM.ACK_REQUESTED); 99 headerElement.setMustUnderstand(true); 100 101 if (identifier != null) { 102 identifier.toSOAPEnvelope(headerElement); 103 } 104 105 if (messageNumber != null) { 106 messageNumber.toSOAPEnvelope(headerElement); 107 } 108 109 return env; 110 } 111 112 118 public AckRequested fromSOAPEnveploe(SOAPHeaderElement headerElement) throws AxisFault { 119 120 Iterator iterator = headerElement.getChildElements(); 121 MessageElement childElement; 122 123 while (iterator.hasNext()) { 124 childElement = (MessageElement) iterator.next(); 125 126 if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.IDENTIFIER)) { 127 identifier = new Identifier(); 128 identifier.fromSOAPEnvelope(childElement); 129 } 130 131 if (childElement.getName().equals(Constants.WSRM.IDENTIFIER)) { 132 identifier = new Identifier(); 133 identifier.fromSOAPEnvelope(childElement); 134 } 135 136 if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.MSG_NUMBER)) { 137 messageNumber = new MessageNumber(); 138 messageNumber.fromSOAPEnvelope(childElement); 139 } 140 141 if (childElement.getName().equals(Constants.WSRM.MSG_NUMBER)) { 142 messageNumber = new MessageNumber(); 143 messageNumber.fromSOAPEnvelope(childElement); 144 } 145 } 146 147 return this; 148 } 149 150 156 public void addChildElement(MessageElement element) throws SOAPException { 157 ackRequested.addChildElement(element); 158 } 159 160 165 public Identifier getIdentifier() { 166 return identifier; 167 } 168 169 174 public MessageNumber getMessageNumber() { 175 return messageNumber; 176 } 177 178 183 public void setIdentifier(Identifier identifier) { 184 this.identifier = identifier; 185 } 186 187 192 public void setMessageNumber(MessageNumber number) { 193 messageNumber = number; 194 } 195 196 public void removeHeaders(SOAPEnvelope soapEnvelope) throws Exception { 197 198 Iterator iterator = soapEnvelope.getHeader().getChildElements(); 199 MessageElement childElement; 200 201 while (iterator.hasNext()) { 202 childElement = (MessageElement) iterator.next(); 203 204 if (Constants.WSRM.ACK_REQUESTED.equals(childElement.getName()) && 205 (Constants.WSRM.NS_URI_RM.equals(childElement.getNamespaceURI()))) { 206 childElement.detachNode(); 207 break; 208 } 209 } 210 } 211 } | Popular Tags |