CastorEnumTypeSerializerpublic class CastorEnumTypeSerializer extends Object implements org.apache.axis.encoding.Serializer
Fields Summary |
---|
protected static Log | log |
Methods Summary |
---|
public java.lang.String | getMechanismType()
return Constants.AXIS_SAX;
| public void | serialize(javax.xml.namespace.QName name, org.xml.sax.Attributes attributes, java.lang.Object value, org.apache.axis.encoding.SerializationContext context)Serialize a Castor Enum Type object.
context.startElement(name, attributes);
try {
//get the value of the object
Method method = value.getClass().getMethod("toString", new Class[]{});
//call the method to return the string
String string = (String) method.invoke(value, new Object[]{});
//write the string
context.writeString(string);
} catch (Exception me) {
log.error(Messages.getMessage("exception00"), me);
throw new IOException("Castor object error: " + me.getLocalizedMessage());
} finally {
context.endElement();
}
| public org.w3c.dom.Element | writeSchema(java.lang.Class javaType, org.apache.axis.wsdl.fromJava.Types types)Return XML schema for the specified type, suitable for insertion into
the <types> element of a WSDL document, or underneath an
<element> or <attribute> declaration.
/*
<simpleType>
<restriction base="xsd:string">
<enumeration value="OK"/>
<enumeration value="ERROR"/>
<enumeration value="WARNING"/>
</restriction>
</simpleType>
*/
Element simpleType = types.createElement("simpleType");
Element restriction = types.createElement("restriction");
simpleType.appendChild(restriction);
restriction.setAttribute("base", Constants.NS_PREFIX_SCHEMA_XSD + ":string");
Method enumerateMethod = javaType.getMethod("enumerate", new Class[0]);
Enumeration en = (Enumeration) enumerateMethod.invoke(null, new Object[0]);
while (en.hasMoreElements()) {
Object obj = (Object) en.nextElement();
Method toStringMethod = obj.getClass().getMethod("toString", new Class[0]);
String value = (String) toStringMethod.invoke(obj, new Object[0]);
Element enumeration = types.createElement("enumeration");
restriction.appendChild(enumeration);
enumeration.setAttribute("value", value);
}
return simpleType;
|
|