texsoft.java.object
Class XsObjectWithKey

java.lang.Object
  extended bytexsoft.java.object.XsObjectWithReflection
      extended bytexsoft.java.object.XsObjectSerializable
          extended bytexsoft.java.object.XsObjectWithKey
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
XsObject

public abstract class XsObjectWithKey
extends XsObjectSerializable
implements java.lang.Comparable

This class adds key support to XsObjectSerializable.

The queryKeyClass() function must be everriden into derived classes to return the Class object for the XsKeyObject's derived class that is key for this class.

The readKey() method returns a new key whose properties are set from this object. The writeKey(XsKeyObject) methods, given a key object, set this object properties from the key. The createKey() method return a new key empty.

Moreover, this class implements the Comparable interface, that allow ordering and searching of instances of this class based on object key. The object can be compared to another object of the same type or to a key of the object. In both case ordering is based on the key. The key object of the class must have set in its constructor the ordering of the properties (if there are multiple properties in the key and their order is significative for comparison). If the key has only one property it is not needed.

If an ordering other than that imposed by the key is needed a XsObjectComparator can be created listing the properties on which sorting has to be done, and used in sorting/searching Collections funcions.


Constructor Summary
XsObjectWithKey()
          Creates a new XsObjectWithKey instance.
XsObjectWithKey(java.lang.Class iface)
          Creates new XsObjectWithKey with given interface filter.
XsObjectWithKey(java.lang.String ser)
          Creates a new XsObjectWithKey object and initializes it with the serialized string passed as argument.
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compares to an object of the same type or a to key object for this class.
 XsKeyObject createKey()
          Returns a new instance of the key class for this class.
abstract  java.lang.Class queryKeyClass()
          Returns a Class object of the key class for this class.
 XsKeyObject readKey()
          Returns a key object with key properties set from this object.
 XsObjectWithKey writeKey(XsKeyObject key)
          Valorizes key properties of this object from the key object passed.
 
Methods inherited from class texsoft.java.object.XsObjectSerializable
deserialize, serialize
 
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

XsObjectWithKey

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

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

XsObjectWithKey

public XsObjectWithKey(java.lang.Class iface)
                throws XsObjectException
Creates new XsObjectWithKey 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)

XsObjectWithKey

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

The passed String is supposed to be created by a XsObjectSerializable.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.
See Also:
XsObjectSerializable.XsObjectSerializable(String)
Method Detail

queryKeyClass

public abstract java.lang.Class queryKeyClass()
Returns a Class object of the key class for this class.

Must be implemented in derived classes to define the key type for the class.

Returns:
a Class object for the key class for this class.

createKey

public final XsKeyObject createKey()
                            throws XsObjectException
Returns a new instance of the key class for this class.

Returns:
a new key object for this object.
Throws:
XsObjectException - thrown if a error occurs creating the key object.

readKey

public final XsKeyObject readKey()
                          throws XsObjectException
Returns a key object with key properties set from this object.

Returns:
a new key object with properties valorized from this object instance.
Throws:
XsObjectException - thrown if a error occurs creating the key object.

writeKey

public final XsObjectWithKey writeKey(XsKeyObject key)
                               throws XsObjectException
Valorizes key properties of this object from the key object passed. Returns itself, to allow compact construct.

Parameters:
key - key object for this class.
Returns:
the object itself.
Throws:
XsObjectException - thrown if a error occurs setting the object's properties.

compareTo

public int compareTo(java.lang.Object obj)
Compares to an object of the same type or a to key object for this class. See Comparable and Collections sorting/search services.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - object to be compared to this instance. This argument can be either another instance of this class or an instance of the key class of this class. So the object can be compared to another object or to a key.
Returns:
-1, 0, 1 as the argument is lower, equal or higher than this object.