com.gridsystems
Class GridXMLSerializer

java.lang.Object
  extended by com.gridsystems.GridXMLSerializer

public class GridXMLSerializer
extends java.lang.Object

XML Serializer.

The main use of this class is to obtain a human-readable representation of a set of objects, for debugging, tests, etc.

Usage

   java.io.Writer writer = ...;
   GridXMLSerializer ser = new GridXMLSerializer(writer);
   try {
     ser.begin();
     ser.write(obj1);
     ser.write(obj2);
     ...
     ser.end();
   } finally {
     writer.close();
   }
 
For each object, the serialization works as follows:
  1. If a static field is found with the following structure:
             private static final ObjectStreamField[] xmlPersistentFields = {
               new ObjectStreamField("myField", myClass.class)
             };
           
    Only the specified fields in this array will be serialized.
  2. Otherwise, all non-static fields will be serialized, including those from ancestor classes.

Version:
2.0
Author:
Gaston Freire Amoedo, Rodrigo Ruiz

Constructor Summary
GridXMLSerializer(java.io.Writer output)
          Creates a new instance.
 
Method Summary
 void begin()
          Starts serialization, generating the appropriate XML headers.
static java.lang.String encodeXML(java.lang.String in)
          Codifica los caracteres susceptibles de confundir el codigo xml.
 void end()
          Termina la serializacion, generando el cierre de las cabeceras XML correspondientes Despues de esta operacion se recomienda hacer flush() y close() del writer.
 void write(java.lang.Object obj)
          Serializa en XML el objeto pasado por parametro.
 void write(java.lang.Object obj, java.lang.String excluded)
          Serializa en XML el objeto pasado por parametro.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridXMLSerializer

public GridXMLSerializer(java.io.Writer output)
Creates a new instance.

Parameters:
output - Writer to write to
Method Detail

begin

public void begin()
           throws java.io.IOException
Starts serialization, generating the appropriate XML headers.

Throws:
java.io.IOException - If an I/O error occurs writing to the writer

end

public void end()
         throws java.io.IOException
Termina la serializacion, generando el cierre de las cabeceras XML correspondientes Despues de esta operacion se recomienda hacer flush() y close() del writer.

Throws:
java.io.IOException - If an I/O error occurs writing to the writer

write

public void write(java.lang.Object obj,
                  java.lang.String excluded)
           throws java.io.IOException
Serializa en XML el objeto pasado por parametro.

Parameters:
obj - objeto a serializar en XML
excluded - para excluir arboles xml que contengan esta palabra, ya sea en el nodo raiz como en alguno de sus nodos hijos (con un nivel de profundidad como maximo)
Throws:
java.io.IOException - If an I/O error occurs writing to the writer

write

public void write(java.lang.Object obj)
           throws java.io.IOException
Serializa en XML el objeto pasado por parametro.

Parameters:
obj - objeto a serializar en XML
Throws:
java.io.IOException - If an I/O error occurs writing to the writer

encodeXML

public static java.lang.String encodeXML(java.lang.String in)
Codifica los caracteres susceptibles de confundir el codigo xml.

Parameters:
in - Cadena con los caracteres a sustituir
Returns:
a String containing the encoded data


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.