com.skaringa.javaxml.serializers
Interface ComponentSerializer

All Known Implementing Classes:
AbstractSerializer, ArraySerializer, CollectionSerializer, DateSerializer, LocaleSerializer, MapEntrySerializer, MapSerializer, ObjectSerializer, PrimitiveTypeSerializer, SetSerializer

public interface ComponentSerializer

Interface that describes the (de)serializer of a component. Classes derived from this interface must be stateless! This is to avoid the creation of a new serializer object for each XML element.


Method Summary
 void addUsedClasses(java.lang.Class base, java.util.Set usedClasses)
          Get all classes used by a given base class.
 java.lang.Object endDeserialize(java.lang.Object obj, java.lang.String text)
          This method is called during deserialization when the end of the element is found.
 java.lang.String getXMLTypeName()
          Get the XML type name for objects handled by the serializer.
 void serialize(java.lang.Object obj, java.lang.Class type, java.lang.String name, java.util.Map propertyMap, java.util.Map objectIdMap, DocumentOutputHandlerInterface output)
          Serialize an object.
 void setMember(java.lang.Object parent, java.lang.String name, java.lang.Object value)
          This method is called when a member field of an object was completely deserialized and needs to be set.
 java.lang.Object startDeserialize(java.lang.String name, org.xml.sax.Attributes attrs, java.lang.Object parent, java.util.Stack objHolderStack, java.lang.ClassLoader classLoader)
          This method is called during deserialization when the start of an element is found.
 void toJson(java.lang.Object obj, java.lang.Class type, java.util.Map propertyMap, java.io.PrintStream output)
          Serialize an object to JSON.
 void writeXMLTypeDefinition(java.lang.Class type, java.util.Map propertyMap, DocumentOutputHandlerInterface output)
          Write the definition the type in XML Schema format.
 

Method Detail

serialize

void serialize(java.lang.Object obj,
               java.lang.Class type,
               java.lang.String name,
               java.util.Map propertyMap,
               java.util.Map objectIdMap,
               DocumentOutputHandlerInterface output)
               throws SerializerException
Serialize an object.

Parameters:
obj - The object to serialize.
type - The type of the object.
name - The name of the object.
propertyMap - A map (string-to-object) of properties for serialization.
objectIdMap - The objects and their ids that were already serialized.
output - The destination of the serialization.
Throws:
SerializerException - If an error occured during serialization.

startDeserialize

java.lang.Object startDeserialize(java.lang.String name,
                                  org.xml.sax.Attributes attrs,
                                  java.lang.Object parent,
                                  java.util.Stack objHolderStack,
                                  java.lang.ClassLoader classLoader)
                                  throws DeserializerException
This method is called during deserialization when the start of an element is found.

Parameters:
name - The name of the element.
attrs - The attributes of the XML element.
parent - The parent object or null if unknown.
objHolderStack - The complete stack of all parent ObjectDeserializerHolder objects.
classLoader - The class loader used to load the class of the new object.
Returns:
A newly created object.
Throws:
DeserializerException - If the creation of the object failed.

endDeserialize

java.lang.Object endDeserialize(java.lang.Object obj,
                                java.lang.String text)
                                throws DeserializerException
This method is called during deserialization when the end of the element is found.

Parameters:
obj - The element created by startDeserialize.
text - The text child node of the XML element.
Returns:
The completely deserialized object.
Throws:
DeserializerException - If the deserialization failed.

setMember

void setMember(java.lang.Object parent,
               java.lang.String name,
               java.lang.Object value)
               throws DeserializerException,
                      java.lang.NoSuchFieldException
This method is called when a member field of an object was completely deserialized and needs to be set.

Parameters:
parent - The parent object.
name - The name of the member.
value - The value of the member.
Throws:
DeserializerException - If the setting of the member failed.
java.lang.NoSuchFieldException - If the object doesn't have a member with the specified name.

getXMLTypeName

java.lang.String getXMLTypeName()
Get the XML type name for objects handled by the serializer.

Returns:
The XML type name.

writeXMLTypeDefinition

void writeXMLTypeDefinition(java.lang.Class type,
                            java.util.Map propertyMap,
                            DocumentOutputHandlerInterface output)
                            throws SerializerException
Write the definition the type in XML Schema format.

Parameters:
type - The type of the object.
propertyMap - A map (string-to-object) of properties.
output - Where to write the schema definition to.
Throws:
SerializerException - If an error occured during write.

addUsedClasses

void addUsedClasses(java.lang.Class base,
                    java.util.Set usedClasses)
                    throws SerializerException
Get all classes used by a given base class. This includes the class itself, the classes of all fields, and all base classes.

Parameters:
base - The base class.
usedClasses - A Set with Class objects which represent all used classes. This set is filled up by this function.
Throws:
SerializerException - If an error occured.

toJson

void toJson(java.lang.Object obj,
            java.lang.Class type,
            java.util.Map propertyMap,
            java.io.PrintStream output)
            throws SerializerException
Serialize an object to JSON.

Parameters:
obj - The object to serialize.
type - The type of the object.
propertyMap - A map (string-to-object) of properties for serialization.
output - The destination of the serialization.
Throws:
SerializerException - If an error occurred during serialization.