com.skaringa.javaxml.serializers
Class SerializerRegistry

java.lang.Object
  extended by com.skaringa.javaxml.serializers.SerializerRegistry

public final class SerializerRegistry
extends java.lang.Object

Registry that holds the serializers. It is implemented using the singleton pattern.


Method Summary
 void addSerializer(java.lang.String className, ComponentSerializer ser)
          Add a serializer to the registry.
 ComponentSerializer findDeserializer(java.lang.Object parent, java.lang.String elementName)
          Try to find a deserializer if no xsi:type attribute is available.
 ComponentSerializer getDeserializer(java.lang.String elementName, org.xml.sax.Attributes attrs, java.lang.ClassLoader classLoader)
          Get a deserializer for an xml element.
static SerializerRegistry getInstance()
          Get the one instance of the SerializerRegistry.
 ComponentSerializer getSerializer(java.lang.Class type)
          Get a serializer for a type.
 ComponentSerializer guessDeserializerForNumber(java.lang.String s)
          Guess the deserializer for a number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static SerializerRegistry getInstance()
Get the one instance of the SerializerRegistry.

Returns:
The SerializerRegistry.

addSerializer

public void addSerializer(java.lang.String className,
                          ComponentSerializer ser)
Add a serializer to the registry.

Parameters:
className - The name of the class which should be handled by the serializer.
ser - The serializer.

getSerializer

public ComponentSerializer getSerializer(java.lang.Class type)
Get a serializer for a type.

Parameters:
type - The type.
Returns:
The serializer.

getDeserializer

public ComponentSerializer getDeserializer(java.lang.String elementName,
                                           org.xml.sax.Attributes attrs,
                                           java.lang.ClassLoader classLoader)
                                    throws DeserializerException
Get a deserializer for an xml element. This is done by evaluating the xsi:type attribute.

Parameters:
elementName - The name of the element.
attrs - The attributes of the element.
classLoader - The class loader used to load new classes.
Returns:
The deserializer.
Throws:
DeserializerException - If the deserializer can't be found.

findDeserializer

public ComponentSerializer findDeserializer(java.lang.Object parent,
                                            java.lang.String elementName)
                                     throws DeserializerException
Try to find a deserializer if no xsi:type attribute is available. This is done by examining the class definition of the parent.

Parameters:
parent - The parent object.
elementName - The name of the element.
Returns:
The deserializer.
Throws:
DeserializerException - If the deserializer can't be found.

guessDeserializerForNumber

public ComponentSerializer guessDeserializerForNumber(java.lang.String s)
                                               throws DeserializerException
Guess the deserializer for a number.

Parameters:
s - The number as String.
Returns:
The deserializer.
Throws:
DeserializerException - If the argument is not a number.