1 16 17 package org.apache.axis.encoding.ser; 18 19 import org.apache.axis.Constants; 20 import org.apache.axis.encoding.SerializationContext; 21 import org.apache.axis.encoding.SimpleValueSerializer; 22 import org.apache.axis.wsdl.fromJava.Types; 23 import org.w3c.dom.Element ; 24 import org.xml.sax.Attributes ; 25 26 import javax.xml.namespace.QName ; 27 import java.io.IOException ; 28 import java.text.SimpleDateFormat ; 29 import java.util.Calendar ; 30 import java.util.Date ; 31 import java.util.TimeZone ; 32 33 40 public class CalendarSerializer implements SimpleValueSerializer { 41 42 private static SimpleDateFormat zulu = 43 new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 44 46 static { 47 zulu.setTimeZone(TimeZone.getTimeZone("GMT")); 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 Date date = value instanceof Date ? (Date ) value : 64 ((Calendar ) value).getTime(); 65 66 synchronized (zulu) { 68 return zulu.format(date); 70 } 71 } 72 73 public String getMechanismType() { return Constants.AXIS_SAX; } 74 75 86 public Element writeSchema(Class javaType, Types types) throws Exception { 87 return null; 88 } 89 } 90 | Popular Tags |