1 55 package org.jboss.axis.message; 56 57 import org.jboss.axis.AxisFault; 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.MessageContext; 60 import org.jboss.axis.encoding.DeserializationContext; 61 import org.jboss.axis.soap.SOAPConstants; 62 import org.jboss.axis.utils.Messages; 63 import org.xml.sax.Attributes ; 64 import org.xml.sax.SAXException ; 65 66 import javax.xml.namespace.QName ; 67 68 76 public class EnvelopeBuilder extends SOAPHandler 77 { 78 private SOAPEnvelopeAxisImpl envelope; 79 private SOAPConstants soapConstants = SOAPConstants.SOAP11_CONSTANTS; 80 81 private boolean gotHeader = false; 82 private boolean gotBody = false; 83 84 public EnvelopeBuilder(String messageType, SOAPConstants soapConstants) 85 { 86 envelope = new SOAPEnvelopeAxisImpl(false, soapConstants); 87 envelope.setMessageType(messageType); 88 myElement = envelope; 89 } 90 91 public EnvelopeBuilder(SOAPEnvelopeAxisImpl env, String messageType) 92 { 93 envelope = env; 94 envelope.setMessageType(messageType); 95 myElement = envelope; 96 } 97 98 public SOAPEnvelopeAxisImpl getEnvelope() 99 { 100 return envelope; 101 } 102 103 public void startElement(String namespace, String localName, 104 String prefix, Attributes attributes, 105 DeserializationContext context) 106 throws SAXException 107 { 108 if (!localName.equals(Constants.ELEM_ENVELOPE)) 109 throw new SAXException (Messages.getMessage("badTag00", localName)); 110 111 MessageContext msgContext = context.getMessageContext(); 113 SOAPConstants singleVersion = null; 114 if (msgContext != null) 115 { 116 singleVersion = (SOAPConstants)msgContext.getProperty(Constants.MC_SINGLE_SOAP_VERSION); 117 } 118 119 if (namespace.equals(Constants.URI_SOAP11_ENV)) 120 { 121 soapConstants = SOAPConstants.SOAP11_CONSTANTS; 123 } 124 else if (namespace.equals(Constants.URI_SOAP12_ENV)) 125 { 126 soapConstants = SOAPConstants.SOAP12_CONSTANTS; 128 } 129 else 130 { 131 soapConstants = null; 132 } 133 134 if ((soapConstants == null) || 135 (singleVersion != null && soapConstants != singleVersion)) 136 { 137 140 soapConstants = SOAPConstants.SOAP11_CONSTANTS; 143 if (singleVersion == null) singleVersion = soapConstants; 144 145 try 146 { 147 AxisFault fault = new AxisFault(soapConstants.getVerMismatchFaultCodeQName(), 148 null, Messages.getMessage("versionMissmatch00"), null, null, null); 149 150 SOAPHeaderElementAxisImpl newHeader = new 151 SOAPHeaderElementAxisImpl(soapConstants.getEnvelopeURI(), 152 Constants.ELEM_UPGRADE); 153 154 SOAPElementAxisImpl innerHeader = new 157 SOAPElementAxisImpl(soapConstants.getEnvelopeURI(), 158 Constants.ELEM_SUPPORTEDENVELOPE); 159 innerHeader.addAttribute(null, Constants.ATTR_QNAME, 160 new QName (singleVersion.getEnvelopeURI(), Constants.ELEM_ENVELOPE)); 161 162 newHeader.addChildElement(innerHeader); 163 fault.addHeader(newHeader); 164 165 throw new SAXException (fault); 166 167 } 168 catch (javax.xml.soap.SOAPException e) 169 { 170 throw new SAXException (e); 171 } 172 } 173 174 if (context.getMessageContext() != null) 177 context.getMessageContext().setSOAPConstants(soapConstants); 178 179 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && 180 attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) 181 { 182 183 AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, 184 null, Messages.getMessage("noEncodingStyleAttrAppear", "Envelope"), null, null, null); 185 186 throw new SAXException (fault); 187 } 188 189 envelope.setPrefix(prefix); 190 envelope.setNamespaceURI(namespace); 191 envelope.setNSMappings(context.getCurrentNSMappings()); 192 envelope.setSoapConstants(soapConstants); 193 context.pushNewElement(envelope); 194 } 195 196 public SOAPHandler onStartChild(String namespace, 197 String localName, 198 String prefix, 199 Attributes attributes, 200 DeserializationContext context) 201 throws SAXException 202 { 203 QName thisQName = new QName (namespace, localName); 204 if (thisQName.equals(soapConstants.getHeaderQName())) 205 { 206 if (gotHeader) 207 throw new SAXException (Messages.getMessage("only1Header00")); 208 209 gotHeader = true; 210 return new HeaderBuilder(envelope); 211 } 212 213 if (thisQName.equals(soapConstants.getBodyQName())) 214 { 215 if (gotBody) 216 throw new SAXException (Messages.getMessage("only1Body00")); 217 218 gotBody = true; 219 return new BodyBuilder(envelope); 220 } 221 222 if (!gotBody) 223 throw new SAXException (Messages.getMessage("noCustomElems00")); 224 225 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) 226 { 227 throw new SAXException (Messages.getMessage("noElemAfterBody12")); 228 } 229 230 try 231 { 232 SOAPElementAxisImpl element = new SOAPElementAxisImpl(namespace, localName, prefix, 233 attributes, context); 234 235 if (element.getFixupDeserializer() != null) 236 return (SOAPHandler)element.getFixupDeserializer(); 237 } 238 catch (AxisFault axisFault) 239 { 240 throw new SAXException (axisFault); 241 } 242 243 return null; 244 } 245 246 public void onEndChild(String namespace, String localName, 247 DeserializationContext context) 248 { 249 } 250 251 public void endElement(String namespace, String localName, 252 DeserializationContext context) 253 throws SAXException 254 { 255 envelope.setDirty(false); 257 } 258 } 259 | Popular Tags |