1 55 56 package org.jboss.axis.encoding.ser; 57 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.Part; 60 import org.jboss.axis.attachments.Attachments; 61 import org.jboss.axis.encoding.SerializationContext; 62 import org.jboss.axis.encoding.Serializer; 63 import org.jboss.axis.soap.SOAPConstants; 64 import org.jboss.axis.utils.Messages; 65 import org.jboss.axis.wsdl.fromJava.Types; 66 import org.jboss.logging.Logger; 67 import org.w3c.dom.Element ; 68 import org.xml.sax.Attributes ; 69 import org.xml.sax.helpers.AttributesImpl ; 70 71 import javax.activation.DataHandler ; 72 import javax.xml.namespace.QName ; 73 import java.io.IOException ; 74 75 81 public class JAFDataHandlerSerializer implements Serializer 82 { 83 84 private static Logger log = Logger.getLogger(JAFDataHandlerSerializer.class.getName()); 85 86 89 public void serialize(QName name, Attributes attributes, 90 Object value, SerializationContext context) 91 throws IOException 92 { 93 DataHandler dh = (DataHandler )value; 94 Attachments attachments = context.getCurrentMessage().getAttachmentsImpl(); 96 97 if (attachments == null) 98 { 99 throw new IOException (Messages.getMessage("noAttachments")); 103 } 104 SOAPConstants soapConstants = context.getMessageContext().getSOAPConstants(); 105 Part attachmentPart = attachments.createAttachmentPart(dh); 106 107 AttributesImpl attrs = new AttributesImpl (); 108 if (attributes != null && 0 < attributes.getLength()) 109 attrs.setAttributes(attributes); 111 int typeIndex = -1; 112 if ((typeIndex = attrs.getIndex(Constants.URI_DEFAULT_SCHEMA_XSI, 113 "type")) != -1) 114 { 115 116 attrs.removeAttribute(typeIndex); 118 } 119 120 boolean doTheDIME = false; 121 if (attachments.getSendType() == Attachments.SEND_TYPE_DIME) 122 doTheDIME = true; 123 124 attrs.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(), 125 "CDATA", doTheDIME ? attachmentPart.getContentId() : attachmentPart.getContentIdRef()); 126 127 context.startElement(name, attrs); 128 context.endElement(); } 130 131 public String getMechanismType() 132 { 133 return Constants.AXIS_SAX; 134 } 135 136 147 public Element writeSchema(Class javaType, Types types) throws Exception 148 { 149 return null; 150 } 151 } 152 | Popular Tags |