1 16 17 package org.apache.axis.encoding.ser; 18 19 import org.apache.axis.components.logger.LogFactory; 20 import org.apache.axis.encoding.SerializationContext; 21 import org.apache.axis.utils.Messages; 22 import org.apache.axis.wsdl.fromJava.Types; 23 import org.apache.commons.logging.Log; 24 import org.w3c.dom.Element ; 25 import org.xml.sax.Attributes ; 26 27 import javax.xml.namespace.QName ; 28 import java.io.IOException ; 29 30 36 public class EnumSerializer extends SimpleSerializer 37 { 38 protected static Log log = 39 LogFactory.getLog(EnumSerializer.class.getName()); 40 41 private java.lang.reflect.Method toStringMethod = null; 42 43 public EnumSerializer(Class javaType, QName xmlType) { 44 super(javaType, xmlType); 45 } 46 47 50 public void serialize(QName name, Attributes attributes, 51 Object value, SerializationContext context) 52 throws IOException 53 { 54 context.startElement(name, attributes); 55 context.writeString(getValueAsString(value, context)); 56 context.endElement(); 57 } 58 59 public String getValueAsString(Object value, SerializationContext context) { 60 try { 63 if (toStringMethod == null) { 64 toStringMethod = javaType.getMethod("toString", null); 65 } 66 return (String ) toStringMethod.invoke(value, null); 67 } catch (Exception e) { 68 log.error(Messages.getMessage("exception00"), e); 69 } 70 return null; 71 } 72 73 84 public Element writeSchema(Class javaType, Types types) throws Exception { 85 return types.writeEnumType(xmlType, javaType); 87 } 88 } 89 | Popular Tags |