com.skaringa.javaxml
Interface ObjectTransformer

All Known Implementing Classes:
ObjectTransformerImpl

public interface ObjectTransformer

Interface that describes the Skaringa transformer.


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 in)
          Transform one object into another using pre-parsed transformation instructions.
 java.lang.Object transform(java.lang.Object in, javax.xml.transform.Source instructionSrc)
          Deprecated. Use setPostprocessorInstruction(Source) and transform(Object).
 void transform(java.lang.Object obj, javax.xml.transform.Source transformationInstruction, javax.xml.transform.Result result)
          Deprecated. Use setPostprocessorInstruction(Source) and serialize(Object, Result).
 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.
 

Method Detail

serialize

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

Parameters:
obj - The object to serialize.
result - The result to serialize the Object to.
Throws:
SerializerException - If the serialization failed.

serializeToString

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

Parameters:
obj - The object to serialize.
Returns:
The object serialized into a String.
Throws:
SerializerException - If the serialization failed.

deserialize

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

Parameters:
src - Source of the object's XML representation.
Returns:
The deserialized object.
Throws:
DeserializerException - If the deserialization failed.

deserializeFromString

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

Parameters:
s - The string containing the object's XML representation.
Returns:
The deserialized object.
Throws:
DeserializerException - If the deserialization failed.

writeXMLSchema

void writeXMLSchema(java.lang.Class type,
                    javax.xml.transform.Result result)
                    throws SerializerException
Write the XML schema definition of a type.

Parameters:
type - The type of the object.
result - The result to write the schema to.
Throws:
SerializerException - If an error occured.

writeXMLSchema

void writeXMLSchema(java.lang.Class type,
                    java.util.Collection componentTypes,
                    javax.xml.transform.Result result)
                    throws SerializerException
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.

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.

transform

java.lang.Object transform(java.lang.Object in,
                           javax.xml.transform.Source instructionSrc)
                           throws SerializerException,
                                  DeserializerException
Deprecated. Use setPostprocessorInstruction(Source) and transform(Object).

Transform one object into another using explicite transformation instructions.

Parameters:
in - The object to transform.
instructionSrc - 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.

transform

java.lang.Object transform(java.lang.Object in)
                           throws SerializerException,
                                  DeserializerException
Transform one object into another using pre-parsed transformation instructions. These instructions have to be set by setPostprocessorInstruction(Source).

Parameters:
in - 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.

transform

void transform(java.lang.Object obj,
               javax.xml.transform.Source transformationInstruction,
               javax.xml.transform.Result result)
               throws SerializerException
Deprecated. Use setPostprocessorInstruction(Source) and serialize(Object, Result).

Transform a Java object into a XML Result using explicite transformation instructions.

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.

setProperty

void setProperty(java.lang.String name,
                 java.lang.Object value)
                 throws NoImplementationException
Set a transformer property.

Parameters:
name - The name of the property to set.
value - The value of the property.
Throws:
NoImplementationException - If the name of the property is not valid.
See Also:
PropertyKeys

setClassLoader

void setClassLoader(java.lang.ClassLoader classLoader)
Set the class loader used to load classes during deserialization.

Parameters:
classLoader - The class loader to use.

setPreprocessorInstruction

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

Parameters:
transformationInstruction - A source of XSLT instructions.
Throws:
NoImplementationException - If the transformer doesn't support this feature.

setPostprocessorInstruction

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

Parameters:
transformationInstruction - A source of XSLT instructions.
Throws:
NoImplementationException - If the transformer doesn't support this feature.

serializeToJson

void serializeToJson(java.lang.Object obj,
                     java.io.OutputStream stream)
                     throws SerializerException
Serializes an object into a stream using JSON format.

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.

serializeToJsonString

java.lang.String serializeToJsonString(java.lang.Object obj)
                                       throws SerializerException
Serializes an object into a String using JSON format.

Parameters:
obj - The object to serialize.
Returns:
The object serialized into a String.
Throws:
SerializerException - If the serialization failed.

deserializeFromJson

java.lang.Object deserializeFromJson(java.io.InputStream stream,
                                     java.lang.Class rootType)
                                     throws DeserializerException
Deserializes an Object from a stream using JSON format.

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.

deserializeFromJson

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

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.

deserializeFromJsonString

java.lang.Object deserializeFromJsonString(java.lang.String s,
                                           java.lang.Class rootType)
                                           throws DeserializerException
Deserializes an Object from a String using JSON format.

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.

deserializeFromJsonString

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

Parameters:
s - The String in JSON format.
Returns:
Map or List depending on the JSON stream.
Throws:
DeserializerException - If the deserialization failed.