com.skaringa.javaxml.impl
Class ObjectTransformerImpl

java.lang.Object
  extended by com.skaringa.javaxml.impl.ObjectTransformerImpl
All Implemented Interfaces:
ObjectTransformer

public final class ObjectTransformerImpl
extends java.lang.Object
implements ObjectTransformer

Implementation of ObjectTransformer. This implementation uses SAX events to parse and generate the XML documents.


Constructor Summary
ObjectTransformerImpl()
          Construct a new Implementation of an ObjectTransformer
 
Method Summary
 java.lang.Object deserialize(javax.xml.transform.Source src)
          Deserializes an Object from a Source using XML format.
 java.lang.Object deserializeFromJson(java.io.InputStream stream)
          Deserializes a List or Map from a stream using JSON format.
 java.lang.Object deserializeFromJson(java.io.InputStream stream, java.lang.Class rootType)
          Deserializes an Object from a stream using JSON format.
 java.lang.Object deserializeFromJsonString(java.lang.String s)
          Deserializes a List or Map from a String using JSON format.
 java.lang.Object deserializeFromJsonString(java.lang.String s, java.lang.Class rootType)
          Deserializes an Object from a String using JSON format.
 java.lang.Object deserializeFromString(java.lang.String s)
          Deserializes an Object from a string using XML format.
 void serialize(java.lang.Object obj, javax.xml.transform.Result result)
          Serializes an Object into a result using XML format.
 void serializeToJson(java.lang.Object obj, java.io.OutputStream stream)
          Serializes an object into a stream using JSON format.
 java.lang.String serializeToJsonString(java.lang.Object obj)
          Serializes an object into a String using JSON format.
 java.lang.String serializeToString(java.lang.Object obj)
          Serializes an Object into a String using XML format.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Set the class loader used to load classes during deserialization.
 void setPostprocessorInstruction(javax.xml.transform.Source transformationInstruction)
          Set the stylesheet to be used for postprocessing.
 void setPreprocessorInstruction(javax.xml.transform.Source transformationInstruction)
          Set the instructions to be used for preprocessing.
 void setProperty(java.lang.String name, java.lang.Object value)
          Set a transformer property.
 java.lang.Object transform(java.lang.Object obj)
          Transform one object into another using pre-parsed transformation instructions.
 java.lang.Object transform(java.lang.Object obj, javax.xml.transform.Source transformationInstruction)
          Deprecated.  
 void transform(java.lang.Object obj, javax.xml.transform.Source transformationInstruction, javax.xml.transform.Result result)
          Deprecated.  
 void writeXMLSchema(java.lang.Class type, java.util.Collection componentTypes, javax.xml.transform.Result result)
          Write the XML schema definition of a type.
 void writeXMLSchema(java.lang.Class type, javax.xml.transform.Result result)
          Write the XML schema definition of a type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectTransformerImpl

public ObjectTransformerImpl()
                      throws NoImplementationException
Construct a new Implementation of an ObjectTransformer

Throws:
NoImplementationException - If the underlying XML Transformer doesn't support SAXTransformer.
Method Detail

serialize

public void serialize(java.lang.Object obj,
                      javax.xml.transform.Result result)
               throws SerializerException
Description copied from interface: ObjectTransformer
Serializes an Object into a result using XML format. If postprocessing instructions have been set by ObjectTransformer.setPostprocessorInstruction(Source) these are applied to the result of the serialization.

Specified by:
serialize in interface ObjectTransformer
Parameters:
obj - The object to serialize.
result - The result to serialize the Object to.
Throws:
SerializerException - If the serialization failed.
See Also:
ObjectTransformer.serialize(Object, Result)

serializeToString

public java.lang.String serializeToString(java.lang.Object obj)
                                   throws SerializerException
Description copied from interface: ObjectTransformer
Serializes an Object into a String using XML format. If postprocessing instructions have been set by ObjectTransformer.setPostprocessorInstruction(Source) these are applied to the result of the serialization.

Specified by:
serializeToString in interface ObjectTransformer
Parameters:
obj - The object to serialize.
Returns:
The object serialized into a String.
Throws:
SerializerException - If the serialization failed.
See Also:
ObjectTransformer.serializeToString(Object)

deserialize

public java.lang.Object deserialize(javax.xml.transform.Source src)
                             throws DeserializerException
Description copied from interface: ObjectTransformer
Deserializes an Object from a Source using XML format. If preproccessing instructions have been set by ObjectTransformer.setPreprocessorInstruction(Source) these are applied first to the Source before piping it into the deserializer.

Specified by:
deserialize in interface ObjectTransformer
Parameters:
src - Source of the object's XML representation.
Returns:
The deserialized object.
Throws:
DeserializerException - If the deserialization failed.
See Also:
ObjectTransformer.deserialize(Source)

deserializeFromString

public java.lang.Object deserializeFromString(java.lang.String s)
                                       throws DeserializerException
Description copied from interface: ObjectTransformer
Deserializes an Object from a string using XML format. If preproccessing instructions have been set by ObjectTransformer.setPreprocessorInstruction(Source) these are applied first to the source before piping it into the deserializer.

Specified by:
deserializeFromString in interface ObjectTransformer
Parameters:
s - The string containing the object's XML representation.
Returns:
The deserialized object.
Throws:
DeserializerException - If the deserialization failed.
See Also:
ObjectTransformer.deserializeFromString(String)

writeXMLSchema

public void writeXMLSchema(java.lang.Class type,
                           javax.xml.transform.Result result)
                    throws SerializerException
Description copied from interface: ObjectTransformer
Write the XML schema definition of a type.

Specified by:
writeXMLSchema in interface ObjectTransformer
Parameters:
type - The type of the object.
result - The result to write the schema to.
Throws:
SerializerException - If an error occured.
See Also:
ObjectTransformer.writeXMLSchema(Class, Result)

writeXMLSchema

public void writeXMLSchema(java.lang.Class type,
                           java.util.Collection componentTypes,
                           javax.xml.transform.Result result)
                    throws SerializerException
Description copied from interface: ObjectTransformer
Write the XML schema definition of a type. Additional types to be included into the schema can be specified. This is useful for generating schemas for collections, because their component types are not documented in the class definition.

Specified by:
writeXMLSchema in interface ObjectTransformer
Parameters:
type - The type of the object.
componentTypes - A collection of Class objects which contain the component types.
result - The result to write the schema to.
Throws:
SerializerException - If an error occured.
See Also:
ObjectTransformer.writeXMLSchema(Class, Collection, Result)

transform

public java.lang.Object transform(java.lang.Object obj,
                                  javax.xml.transform.Source transformationInstruction)
                           throws SerializerException,
                                  DeserializerException
Deprecated. 

Description copied from interface: ObjectTransformer
Transform one object into another using explicite transformation instructions.

Specified by:
transform in interface ObjectTransformer
Parameters:
obj - The object to transform.
transformationInstruction - The source where to get the XSLT instructions from.
Returns:
The transformed object.
Throws:
SerializerException - If an error occured in the serializer.
DeserializerException - If an error occured in the deserializer.
See Also:
ObjectTransformer.transform(Object, Source)

transform

public java.lang.Object transform(java.lang.Object obj)
                           throws SerializerException,
                                  DeserializerException
Description copied from interface: ObjectTransformer
Transform one object into another using pre-parsed transformation instructions. These instructions have to be set by ObjectTransformer.setPostprocessorInstruction(Source).

Specified by:
transform in interface ObjectTransformer
Parameters:
obj - The object to transform.
Returns:
The transformed object.
Throws:
SerializerException - If an error occured in the serializer.
DeserializerException - If an error occured in the deserializer.
See Also:
ObjectTransformer.transform(Object)

transform

public void transform(java.lang.Object obj,
                      javax.xml.transform.Source transformationInstruction,
                      javax.xml.transform.Result result)
               throws SerializerException
Deprecated. 

Description copied from interface: ObjectTransformer
Transform a Java object into a XML Result using explicite transformation instructions.

Specified by:
transform in interface ObjectTransformer
Parameters:
obj - The object to transform.
transformationInstruction - A source of XSLT instructions or null if a simple copy transformation has to be performed.
result - The result of the transformation.
Throws:
SerializerException - If an error occured.
See Also:
ObjectTransformer.transform(Object, Source, Result)

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
Description copied from interface: ObjectTransformer
Set a transformer property.

Specified by:
setProperty in interface ObjectTransformer
Parameters:
name - The name of the property to set.
value - The value of the property.
See Also:
ObjectTransformer.setProperty(String, Object)

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Description copied from interface: ObjectTransformer
Set the class loader used to load classes during deserialization.

Specified by:
setClassLoader in interface ObjectTransformer
Parameters:
classLoader - The class loader to use.
See Also:
ObjectTransformer.setClassLoader(java.lang.ClassLoader)

setPreprocessorInstruction

public void setPreprocessorInstruction(javax.xml.transform.Source transformationInstruction)
                                throws NoImplementationException
Description copied from interface: ObjectTransformer
Set the instructions to be used for preprocessing. These instruction are applied to the XML that is passed to ObjectTransformer.deserialize(Source) or ObjectTransformer.deserializeFromString(String) before deserializing the object.

Specified by:
setPreprocessorInstruction in interface ObjectTransformer
Parameters:
transformationInstruction - A source of XSLT instructions.
Throws:
NoImplementationException - If the transformer doesn't support this feature.
See Also:
ObjectTransformer.setPreprocessorInstruction(Source)

setPostprocessorInstruction

public void setPostprocessorInstruction(javax.xml.transform.Source transformationInstruction)
                                 throws NoImplementationException
Description copied from interface: ObjectTransformer
Set the stylesheet to be used for postprocessing. These instruction are applied to the XML that is the result of ObjectTransformer.serialize(Object, Result) or ObjectTransformer.serializeToString(Object) after serializing the object. Additionally, these instructions are used by ObjectTransformer.transform(Object).

Specified by:
setPostprocessorInstruction in interface ObjectTransformer
Parameters:
transformationInstruction - A source of XSLT instructions.
Throws:
NoImplementationException - If the transformer doesn't support this feature.
See Also:
ObjectTransformer.setPostprocessorInstruction(Source)

serializeToJson

public void serializeToJson(java.lang.Object obj,
                            java.io.OutputStream stream)
                     throws SerializerException
Description copied from interface: ObjectTransformer
Serializes an object into a stream using JSON format.

Specified by:
serializeToJson in interface ObjectTransformer
Parameters:
obj - The object to serialize.
stream - The stream to write the JSON to. Note that JSON is always UTF-8 encoded.
Throws:
SerializerException - If the serialization failed.
See Also:
ObjectTransformer.serializeToJson(Object, OutputStream)

serializeToJsonString

public java.lang.String serializeToJsonString(java.lang.Object obj)
                                       throws SerializerException
Description copied from interface: ObjectTransformer
Serializes an object into a String using JSON format.

Specified by:
serializeToJsonString in interface ObjectTransformer
Parameters:
obj - The object to serialize.
Returns:
The object serialized into a String.
Throws:
SerializerException - If the serialization failed.
See Also:
ObjectTransformer.serializeToJsonString(Object)

deserializeFromJson

public java.lang.Object deserializeFromJson(java.io.InputStream stream,
                                            java.lang.Class rootType)
                                     throws DeserializerException
Description copied from interface: ObjectTransformer
Deserializes an Object from a stream using JSON format.

Specified by:
deserializeFromJson in interface ObjectTransformer
Parameters:
stream - The stream containing the JSON. Note that JSON is always UTF-8 encoded.
rootType - The type of the root object to instantiate. If null, then LinkedList or HashMap is used depending on the JSON stream.
Returns:
The deserialized object. It has the class rootType.
Throws:
DeserializerException - If the deserialization failed.
See Also:
ObjectTransformer.deserializeFromJson(InputStream, Class)

deserializeFromJsonString

public java.lang.Object deserializeFromJsonString(java.lang.String s,
                                                  java.lang.Class rootType)
                                           throws DeserializerException
Description copied from interface: ObjectTransformer
Deserializes an Object from a String using JSON format.

Specified by:
deserializeFromJsonString in interface ObjectTransformer
Parameters:
s - The String in JSON format.
rootType - The type of the root object to instantiate. If null, then LinkedList or HashMap is used depending on the JSON string.
Returns:
The deserialized object. It has the class rootType.
Throws:
DeserializerException - If the deserialization failed.
See Also:
ObjectTransformer.deserializeFromJsonString(java.lang.String, java.lang.Class)

deserializeFromJson

public java.lang.Object deserializeFromJson(java.io.InputStream stream)
                                     throws DeserializerException
Description copied from interface: ObjectTransformer
Deserializes a List or Map from a stream using JSON format. It is the same as calling deserializeFromJson(stream, null)

Specified by:
deserializeFromJson in interface ObjectTransformer
Parameters:
stream - The stream containing the JSON. Note that JSON is always UTF-8 encoded.
Returns:
Map or List depending on the JSON stream.
Throws:
DeserializerException - If the deserialization failed.
See Also:
ObjectTransformer.deserializeFromJson(java.io.InputStream)

deserializeFromJsonString

public java.lang.Object deserializeFromJsonString(java.lang.String s)
                                           throws DeserializerException
Description copied from interface: ObjectTransformer
Deserializes a List or Map from a String using JSON format. It is the same as calling deserializeFromJsonString(s, null)

Specified by:
deserializeFromJsonString in interface ObjectTransformer
Parameters:
s - The String in JSON format.
Returns:
Map or List depending on the JSON stream.
Throws:
DeserializerException - If the deserialization failed.
See Also:
ObjectTransformer.deserializeFromJsonString(java.lang.String)