FileDocCategorySizeDatePackage
CastorEnumTypeSerializer.javaAPI DocApache Axis 1.44462Sat Apr 22 18:57:28 BST 2006org.apache.axis.encoding.ser.castor

CastorEnumTypeSerializer

public class CastorEnumTypeSerializer extends Object implements org.apache.axis.encoding.Serializer
Castor serializer
author
Ozzie Gurkan
version
1.0

Fields Summary
protected static Log
log
Constructors Summary
Methods Summary
public java.lang.StringgetMechanismType()

        return Constants.AXIS_SAX;
    
public voidserialize(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.

param
name
param
attributes
param
value this must be a castor object for marshalling
param
context
throws
IOException for XML schema noncompliance, bad object type, and any IO trouble.


                                                                                  
      
             
             
             
             
              
        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.ElementwriteSchema(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.

param
javaType the Java Class we're writing out schema for
param
types the Java2WSDL Types object which holds the context for the WSDL being generated.
return
a type element containing a schema simpleType/complexType
see
org.apache.axis.wsdl.fromJava.Types

        /*
        <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;