1 16 package org.jboss.axis.message; 17 18 import org.jboss.axis.AxisFault; 19 import org.jboss.axis.Constants; 20 import org.jboss.axis.MessageContext; 21 import org.jboss.axis.description.FaultDesc; 22 import org.jboss.axis.description.OperationDesc; 23 import org.jboss.axis.encoding.Callback; 24 import org.jboss.axis.encoding.CallbackTarget; 25 import org.jboss.axis.encoding.DeserializationContext; 26 import org.jboss.axis.encoding.Deserializer; 27 import org.jboss.axis.encoding.DeserializerImpl; 28 import org.jboss.axis.soap.SOAPConstants; 29 import org.jboss.axis.utils.ClassUtils; 30 import org.jboss.axis.utils.Messages; 31 import org.xml.sax.Attributes ; 32 import org.xml.sax.SAXException ; 33 34 import javax.xml.namespace.QName ; 35 36 42 public class SOAPFaultDetailsBuilder extends SOAPHandler implements Callback 43 { 44 protected SOAPFaultBuilder builder; 45 46 public SOAPFaultDetailsBuilder(SOAPFaultBuilder builder) 47 { 48 this.builder = builder; 49 } 50 51 public void startElement(String namespace, String localName, 52 String prefix, Attributes attributes, 53 DeserializationContext context) 54 throws SAXException 55 { 56 SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; 57 if (context.getMessageContext() != null) 58 soapConstants = context.getMessageContext().getSOAPConstants(); 59 60 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && 61 attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) 62 { 63 64 AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, 65 null, Messages.getMessage("noEncodingStyleAttrAppear", "Detail"), null, null, null); 66 67 throw new SAXException (fault); 68 } 69 70 super.startElement(namespace, localName, prefix, attributes, context); 71 } 72 73 public SOAPHandler onStartChild(String namespace, 74 String name, 75 String prefix, 76 Attributes attributes, 77 DeserializationContext context) 78 throws SAXException 79 { 80 QName qn = new QName (namespace, name); 82 83 if (name.equals("exceptionName")) 87 { 88 Deserializer dser = context.getDeserializerForType(Constants.XSD_STRING); 90 dser.registerValueTarget(new CallbackTarget(this, "exceptionName")); 91 return (SOAPHandler)dser; 92 } 93 94 MessageContext msgContext = context.getMessageContext(); 97 SOAPConstants soapConstants = msgContext.getSOAPConstants(); 98 OperationDesc op = msgContext.getOperation(); 99 Class faultClass = null; 100 QName faultXmlType = null; 101 if (op != null) 102 { 103 FaultDesc faultDesc = null; 104 faultXmlType = context.getTypeFromAttributes(namespace, 106 name, 107 attributes); 108 if (faultXmlType != null) 109 { 110 faultDesc = op.getFaultByXmlType(faultXmlType); 111 } 112 113 if (faultDesc == null) 115 { 116 faultDesc = op.getFaultByQName(qn); 117 if ((faultXmlType == null) && (faultDesc != null)) 118 { 119 faultXmlType = faultDesc.getXmlType(); 120 } 121 } 122 123 if (faultDesc != null) 125 { 126 try 127 { 128 faultClass = ClassUtils.forName(faultDesc.getClassName()); 129 } 130 catch (ClassNotFoundException e) 131 { 132 } 134 } 135 } 136 else 137 { 138 faultXmlType = context.getTypeFromAttributes(namespace, 139 name, 140 attributes); 141 } 142 143 if (faultClass == null) 144 { 145 faultClass = 146 context.getTypeMapping().getClassForQName(faultXmlType); 147 } 148 149 if (faultClass != null && faultXmlType != null) 150 { 151 builder.setFaultClass(faultClass); 152 builder.setWaiting(true); 153 Deserializer dser = null; 155 if (attributes.getValue(soapConstants.getAttrHref()) == null) 156 { 157 dser = context.getDeserializerForType(faultXmlType); 158 } 159 else 160 { 161 dser = new DeserializerImpl(); 162 dser.setDefaultType(faultXmlType); 163 } 164 if (dser != null) 165 { 166 dser.registerValueTarget(new CallbackTarget(this, "faultData")); 167 } 168 return (SOAPHandler)dser; 169 } 170 return null; 171 } 172 173 179 public void setValue(Object value, Object hint) 180 { 181 if ("faultData".equals(hint)) 182 { 183 builder.setFaultData(value); 184 } 185 else if ("exceptionName".equals(hint)) 186 { 187 String faultClassName = (String )value; 188 try 189 { 190 Class faultClass = ClassUtils.forName(faultClassName); 191 builder.setFaultClass(faultClass); 192 } 193 catch (ClassNotFoundException e) 194 { 195 } 197 } 198 199 } 200 } 201 | Popular Tags |