1 16 17 package org.apache.axis.encoding.ser; 18 19 import java.io.IOException ; 20 21 import javax.activation.DataHandler ; 22 import javax.xml.namespace.QName ; 23 24 import org.apache.axis.Constants; 25 import org.apache.axis.Part; 26 import org.apache.axis.attachments.Attachments; 27 import org.apache.axis.components.logger.LogFactory; 28 import org.apache.axis.encoding.SerializationContext; 29 import org.apache.axis.encoding.Serializer; 30 import org.apache.axis.soap.SOAPConstants; 31 import org.apache.axis.utils.Messages; 32 import org.apache.axis.wsdl.fromJava.Types; 33 import org.apache.commons.logging.Log; 34 import org.w3c.dom.Element ; 35 import org.xml.sax.Attributes ; 36 import org.xml.sax.helpers.AttributesImpl ; 37 38 43 public class JAFDataHandlerSerializer implements Serializer { 44 45 protected static Log log = 46 LogFactory.getLog(JAFDataHandlerSerializer.class.getName()); 47 48 51 public void serialize(QName name, Attributes attributes, 52 Object value, SerializationContext context) 53 throws IOException 54 { 55 DataHandler dh= (DataHandler )value; 56 Attachments attachments= context.getCurrentMessage().getAttachmentsImpl(); 58 59 if (attachments == null) { 60 throw new IOException (Messages.getMessage("noAttachments")); 64 } 65 SOAPConstants soapConstants = context.getMessageContext().getSOAPConstants(); 66 Part attachmentPart= attachments.createAttachmentPart(dh); 67 68 AttributesImpl attrs = new AttributesImpl (); 69 if (attributes != null && 0 < attributes.getLength()) 70 attrs.setAttributes(attributes); 72 int typeIndex=-1; 73 if((typeIndex = attrs.getIndex(Constants.URI_DEFAULT_SCHEMA_XSI, 74 "type")) != -1){ 75 76 attrs.removeAttribute(typeIndex); 78 } 79 80 boolean doTheDIME = false; 81 if(attachments.getSendType() == Attachments.SEND_TYPE_DIME) 82 doTheDIME = true; 83 84 attrs.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(), 85 "CDATA", doTheDIME ? attachmentPart.getContentId() : attachmentPart.getContentIdRef() ); 86 87 context.startElement(name, attrs); 88 context.endElement(); } 90 91 public String getMechanismType() { return Constants.AXIS_SAX; } 92 93 104 public Element writeSchema(Class javaType, Types types) throws Exception { 105 return null; 106 } 107 } 108 | Popular Tags |