Class BeanSerializer

  • All Implemented Interfaces:
    java.io.Serializable, Serializer, Serializer

    public class BeanSerializer
    extends java.lang.Object
    implements Serializer, java.io.Serializable
    General purpose serializer/deserializerFactory for an arbitrary java bean.
    Author:
    Sam Ruby , Rich Scheuerle , Tom Jordahl
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getMechanismType()
      Gets the type of the XML processing mechanism and representation used by this Serializer.
      protected org.xml.sax.Attributes getObjectAttributes​(java.lang.Object value, org.xml.sax.Attributes attributes, SerializationContext context)
      Check for meta-data in the bean that will tell us if any of the properties are actually attributes, add those to the element attribute list
      void serialize​(QName name, org.xml.sax.Attributes attributes, java.lang.Object value, SerializationContext context)
      Serialize a bean.
      protected void writeAttribute​(Types types, java.lang.String fieldName, java.lang.Class fieldType, QName fieldXmlType, org.w3c.dom.Element where)
      write aa attribute element and append it to the 'where' Node
      protected void writeField​(Types types, java.lang.String fieldName, QName xmlType, java.lang.Class fieldType, boolean isUnbounded, boolean isOmittable, org.w3c.dom.Element where, boolean isAnonymous, QName itemQName)
      write a schema representation of the given Class field and append it to the where Node, recurse on complex types
      org.w3c.dom.Element writeSchema​(java.lang.Class javaType, 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        protected static org.apache.commons.logging.Log log
    • Constructor Detail

      • BeanSerializer

        public BeanSerializer​(java.lang.Class javaType,
                              QName xmlType)
      • BeanSerializer

        public BeanSerializer​(java.lang.Class javaType,
                              QName xmlType,
                              TypeDesc typeDesc)
    • Method Detail

      • serialize

        public void serialize​(QName name,
                              org.xml.sax.Attributes attributes,
                              java.lang.Object value,
                              SerializationContext context)
                       throws java.io.IOException
        Serialize a bean. Done simply by serializing each bean property.
        Specified by:
        serialize in interface Serializer
        Parameters:
        name - is the element name
        attributes - are the attributes...serialize is free to add more.
        value - is the value
        context - is the SerializationContext
        Throws:
        java.io.IOException
      • getMechanismType

        public java.lang.String getMechanismType()
        Description copied from interface: Serializer
        Gets the type of the XML processing mechanism and representation used by this Serializer.
        Specified by:
        getMechanismType in interface Serializer
        Returns:
        XML processing mechanism type
      • writeSchema

        public org.w3c.dom.Element writeSchema​(java.lang.Class javaType,
                                               Types types)
                                        throws java.lang.Exception
        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.
        Specified by:
        writeSchema in interface Serializer
        Parameters:
        javaType - the Java Class we're writing out schema for
        types - the Java2WSDL Types object which holds the context for the WSDL being generated.
        Returns:
        a type element containing a schema simpleType/complexType
        Throws:
        java.lang.Exception
        See Also:
        Types
      • writeField

        protected void writeField​(Types types,
                                  java.lang.String fieldName,
                                  QName xmlType,
                                  java.lang.Class fieldType,
                                  boolean isUnbounded,
                                  boolean isOmittable,
                                  org.w3c.dom.Element where,
                                  boolean isAnonymous,
                                  QName itemQName)
                           throws java.lang.Exception
        write a schema representation of the given Class field and append it to the where Node, recurse on complex types
        Parameters:
        fieldName - name of the field
        xmlType - the schema type of the field
        fieldType - type of the field
        isUnbounded - causes maxOccurs="unbounded" if set
        where - location for the generated schema node
        itemQName -
        Throws:
        java.lang.Exception
      • writeAttribute

        protected void writeAttribute​(Types types,
                                      java.lang.String fieldName,
                                      java.lang.Class fieldType,
                                      QName fieldXmlType,
                                      org.w3c.dom.Element where)
                               throws java.lang.Exception
        write aa attribute element and append it to the 'where' Node
        Parameters:
        fieldName - name of the field
        fieldType - type of the field
        where - location for the generated schema node
        Throws:
        java.lang.Exception
      • getObjectAttributes

        protected org.xml.sax.Attributes getObjectAttributes​(java.lang.Object value,
                                                             org.xml.sax.Attributes attributes,
                                                             SerializationContext context)
        Check for meta-data in the bean that will tell us if any of the properties are actually attributes, add those to the element attribute list
        Parameters:
        value - the object we are serializing
        Returns:
        attributes for this element, null if none