1 16 package org.apache.axis.encoding.ser; 17 18 import java.io.IOException ; 19 import java.text.SimpleDateFormat ; 20 import java.util.Calendar ; 21 import java.util.TimeZone ; 22 23 import javax.xml.namespace.QName ; 24 25 import org.w3c.dom.Element ; 26 import org.xml.sax.Attributes ; 27 28 import org.apache.axis.Constants; 29 import org.apache.axis.encoding.SerializationContext; 30 import org.apache.axis.encoding.SimpleValueSerializer; 31 import org.apache.axis.wsdl.fromJava.Types; 32 33 37 public class TimeSerializer implements SimpleValueSerializer { 38 39 42 private static SimpleDateFormat zulu = new SimpleDateFormat ("HH:mm:ss.SSS'Z'"); 43 44 static { 46 zulu.setTimeZone(TimeZone.getTimeZone("GMT")); 47 } 48 49 50 53 public void serialize(QName name, Attributes attributes, 54 Object value, SerializationContext context) 55 throws IOException 56 { 57 context.startElement(name, attributes); 58 context.writeString(getValueAsString(value, context)); 59 context.endElement(); 60 } 61 62 public String getValueAsString(Object value, SerializationContext context) { 63 StringBuffer buf = new StringBuffer (); 64 ((Calendar ) value).set(0,0,0); 66 buf.append(zulu.format(((Calendar )value).getTime())); 67 return buf.toString(); 68 } 69 70 public String getMechanismType() { return Constants.AXIS_SAX; } 71 72 83 public Element writeSchema(Class javaType, Types types) throws Exception { 84 return null; 85 } 86 } 87 | Popular Tags |