1 55 56 package org.jboss.axis.encoding.ser; 57 58 import org.jboss.axis.encoding.SerializationContext; 59 import org.jboss.axis.utils.Messages; 60 import org.jboss.axis.wsdl.fromJava.Types; 61 import org.jboss.logging.Logger; 62 import org.w3c.dom.Element ; 63 import org.xml.sax.Attributes ; 64 65 import javax.xml.namespace.QName ; 66 import java.io.IOException ; 67 68 74 public class EnumSerializer extends SimpleSerializer 75 { 76 private static Logger log = Logger.getLogger(EnumSerializer.class.getName()); 77 78 private java.lang.reflect.Method toStringMethod = null; 79 80 public EnumSerializer(Class javaType, QName xmlType) 81 { 82 super(javaType, xmlType); 83 } 84 85 88 public void serialize(QName name, Attributes attributes, 89 Object value, SerializationContext context) 90 throws IOException 91 { 92 context.startElement(name, attributes); 93 context.writeString(getValueAsString(value, context)); 94 context.endElement(); 95 } 96 97 public String getValueAsString(Object value, SerializationContext context) 98 { 99 try 102 { 103 if (toStringMethod == null) 104 { 105 toStringMethod = javaType.getMethod("toString", null); 106 } 107 return (String )toStringMethod.invoke(value, null); 108 } 109 catch (Exception e) 110 { 111 log.error(Messages.getMessage("exception00"), e); 112 } 113 return null; 114 } 115 116 127 public Element writeSchema(Class javaType, Types types) throws Exception 128 { 129 return types.writeEnumType(xmlType, javaType); 131 } 132 } 133 | Popular Tags |