texsoft.java.object
Class XsKeyObject

java.lang.Object
  extended bytexsoft.java.object.XsObjectWithReflection
      extended bytexsoft.java.object.XsObjectSerializable
          extended bytexsoft.java.object.XsKeyObject
All Implemented Interfaces:
java.lang.Comparable

public class XsKeyObject
extends XsObjectSerializable
implements java.lang.Comparable

Defines an object able to act as a key for instances of XsObjectWithKey and derived classes, for seeking and sorting, and to serialize its properties using XsObjectSerializable services.

A key object should derive from this class and should have properties with public setter and getter for each property that is a key (for seeking or sorting) of the class for which the object has to act as a key.

By default all public properties of the object are used as key properties and no standard sequence is imposed on the properties for sorting. This can be overriden defining a custom sequence of public properties with defineOrder(String[]).

The ordering option constants from XsObjectComparator can be appened to property names into the String array that defines key properties to select ordering options for the properties. Say k is a XsKeyObject and obj is an object belonging to a class for which k is a key, then the matching properties of k can be valorized from obj, and vice versa the matching properties of obj can be valorized from k. This is achieved using readFrom(XsObjectWithKey) and writeTo(XsObjectWithKey). All the public properties of the key object are involved into this process.

Implements the Comparable interface to allow ordering for key objects. The sorting order is defined by the properties order sequence, that is managed by defineOrder(String[])). If the key has to be used for sorting of object and it has more than one property, the constructor in derived classes should set the order array explicitly.

Interface filtering is suppressed for this class and its descendents: application of interface for properties filtering is ignored.


Constructor Summary
XsKeyObject()
          Creates a new XsKeyObject instance.
XsKeyObject(java.lang.Class iface)
          Creates new XsKeyObject.
XsKeyObject(java.lang.String serialized)
          Creates a new XsKeyObject object and initializes it with the serialized string passed as argument.
 
Method Summary
 void applyInterfaceFilter(java.lang.Class iface)
          Overloaded to avoid applying of filtering on key object.
 void applyInterfaceFilter(java.lang.String ifaceName)
          Overloaded to avoid applying of filtering on key object.
 int compareTo(java.lang.Object obj)
          Compares this object with the one passed as argument.
 java.lang.String[] currentOrder()
          Gets the String array that defines the properties that compose the key and defines their order for sorting.
 void defineOrder(java.lang.String[] order)
          Sets the String array that defines the properties that compose the key and defines their order for sorting.
 XsKeyObject readFrom(XsObjectWithKey obj)
          Given an object exctract it's key fields and store them into this key object.
 XsObjectWithKey writeTo(XsObjectWithKey obj)
          Given an object fills it's key fields from this key.
 
Methods inherited from class texsoft.java.object.XsObjectSerializable
deserialize, serialize
 
Methods inherited from class texsoft.java.object.XsObjectWithReflection
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

XsKeyObject

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

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

XsKeyObject

public XsKeyObject(java.lang.Class iface)
            throws XsObjectException
Creates new XsKeyObject. The interface passed is ignored, no filter apply to XsKeyObject.

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

XsKeyObject

public XsKeyObject(java.lang.String serialized)
            throws XsObjectException
Creates a new XsKeyObject 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:
serialized - serialized rapresentation of an object of this class.
Throws:
XsObjectException - thrown if an error occurs during deserialization of the string.
Method Detail

readFrom

public final XsKeyObject readFrom(XsObjectWithKey obj)
                           throws XsObjectException
Given an object exctract it's key fields and store them into this key object.

Parameters:
obj - an object of a class for which this object is a key.
Returns:
the key object itself.
Throws:
XsObjectException - thrown if a reflection error occurs.

writeTo

public final XsObjectWithKey writeTo(XsObjectWithKey obj)
                              throws XsObjectException
Given an object fills it's key fields from this key. Returns the object.

Parameters:
obj - object belonging to a class for which this is a key object.
Returns:
the object passed as argument.
Throws:
XsObjectException - thrown if a reflection error occurs.

currentOrder

public java.lang.String[] currentOrder()
Gets the String array that defines the properties that compose the key and defines their order for sorting.

Returns:
the property names array.

defineOrder

public void defineOrder(java.lang.String[] order)
Sets the String array that defines the properties that compose the key and defines their order for sorting.

Parameters:
order - the property names array.

compareTo

public int compareTo(java.lang.Object obj)
Compares this object with the one passed as argument.

The argument object must be belong to the same class of this object.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - the object to be compared with this.
Returns:
-1, 0, 1 as the argument is lower, equal or higher than this object.

applyInterfaceFilter

public final void applyInterfaceFilter(java.lang.Class iface)
                                throws XsObjectException
Overloaded to avoid applying of filtering on key object.

Overrides:
applyInterfaceFilter in class XsObjectWithReflection
Parameters:
iface - specifies the interface on which the class inspected properties are to be filtered on
Throws:
XsObjectException - thrown if can't acquire the inspector for the class or the interface

applyInterfaceFilter

public final void applyInterfaceFilter(java.lang.String ifaceName)
                                throws XsObjectException
Overloaded to avoid applying of filtering on key object.

Overrides:
applyInterfaceFilter in class XsObjectWithReflection
Parameters:
ifaceName - specifies the name of the interface on which the class inspected properties are to be filtered on
Throws:
XsObjectException - thrown if can't acquire the inspector for the class or the interface or if no interface match the passed interface name