texsoft.java.object
Class XsObjectSerializable

java.lang.Object
  extended bytexsoft.java.object.XsObjectWithReflection
      extended bytexsoft.java.object.XsObjectSerializable
Direct Known Subclasses:
XsKeyObject, XsObjectWithKey

public class XsObjectSerializable
extends XsObjectWithReflection

Defines an object able to serialize it state, using XsObjectWithReflection services, into a String and to init itself from a previously serialized string.

Only read/write properties are processed by the serialization process.

The serialize() method return a String rappresentation of object's properties. Only those object's properties that are publicly readable are serialized.

The deserialize(String) method set the object properties reading them from the serialized string passed as argument.

If a property is a serializable object itself it is correctly managed during serialization and deserialization (deserialization is managed by the special case of String setter of XsClassInspector).

Special characters are converted in both ways using a java unicode like rappresentatio.

See Also:
XsObjectWithReflection

Constructor Summary
XsObjectSerializable()
          Creates a new XsObjectSerializable instance.
XsObjectSerializable(java.lang.Class iface)
          Creates new XsObjectSerializable with given interface filter.
XsObjectSerializable(java.lang.String ser)
          Creates a new XsObjectSerializable object and initializes it with the serialized string passed as argument.
 
Method Summary
 XsObjectSerializable deserialize(java.lang.String s)
          Given an input string in the format used by serialize(), sets the object's properties.
 java.lang.String serialize()
          Serialize the object's properties in a format that can be used by the string constructor and deserialize(String) to recreate the object contents.
 
Methods inherited from class texsoft.java.object.XsObjectWithReflection
applyInterfaceFilter, applyInterfaceFilter, doGet, doNew, doSet, doSet, doSet, doSet, doSet, doSet, doSet, doSet, doSet, inspect, removeInterfaceFilter, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XsObjectSerializable

public XsObjectSerializable()
                     throws XsObjectException
Creates a new XsObjectSerializable instance.

Throws:
XsObjectException - thrown if a problem occurs while obtaining the inspector for the class.
See Also:
XsObjectWithReflection.XsObjectWithReflection()

XsObjectSerializable

public XsObjectSerializable(java.lang.Class iface)
                     throws XsObjectException
Creates new XsObjectSerializable with given interface filter.

Parameters:
iface - class corresponding to an interface implemented by this class used as a filter for properties accessible with inspection methods.
Throws:
XsObjectException - thrown if a problem occurs while obtaining the inspector for the class.
See Also:
XsObjectWithReflection.XsObjectWithReflection(Class)

XsObjectSerializable

public XsObjectSerializable(java.lang.String ser)
                     throws XsObjectException
Creates a new XsObjectSerializable object and initializes it with the serialized string passed as argument.

The passed String is supposed to be created by a serialize() method called on a object of the same type of the this.

Parameters:
ser - serialized rapresentation of an object of this class.
Throws:
XsObjectException - thrown if an error occurs during deserialization of the string.
Method Detail

serialize

public final java.lang.String serialize()
                                 throws XsObjectException
Serialize the object's properties in a format that can be used by the string constructor and deserialize(String) to recreate the object contents.

Only read/write properties are serialized.

The format is defined in BNF as:

 key ::= property {property}
 property ::= name = delimiter text delimiter separator | name = separator
 name ::= simplechar {simplechar}
 text ::= complexchar {complexchar}
 escape ::= '\\'
 delimiter ::= '|'
 separator ::= ';'
 simplechar ::= all_ascii_except_escape_delimiter_separator_eos
 complexchar ::= simplechar | escape delimiter | escape escape | escape u hex hex hex hex
 hex ::= hexadecimal_digit
 
Escape, delimiter, separator and EOS characters are defined as constants into XsObjectUtil.

Returns:
the serialized rapresentation of the object.
Throws:
XsObjectException - thrown if an error occurs during serialization of the string.

deserialize

public final XsObjectSerializable deserialize(java.lang.String s)
                                       throws XsObjectException
Given an input string in the format used by serialize(), sets the object's properties. Returns itself.

Parameters:
s - serialized rapresentation of an object of this class.
Returns:
the object itself.
Throws:
XsObjectException - thrown if an error occurs during deserialization of the string.