net.vleu.visitomatic
Class VisitableReader

java.lang.Object
  extended by net.vleu.visitomatic.VisitableReader

public class VisitableReader
extends java.lang.Object

A VisitableReader gives informations about a Visitable.
More specifically, they analyze fields marked with ToVisit and give informations about them.
A VisitableReader built for a class can be used many times for all instances of this class. Doing so is more efficient.

See Also:
Visitable, ToVisit

Constructor Summary
VisitableReader(java.lang.Class<? extends Visitable> visitableClass)
          Builds a new VisitableReader.
A VisitableReader built for a class can be used many times for all instances of this class.
 
Method Summary
 int getNumberOfValues()
           
 java.lang.Object[] readValues(Visitable visitable)
          Reads the values from fields and methods marked with ToVisit in the provided Visitable and returns them as an array of objects.
protected  void readValues(Visitable visitable, java.lang.Object[] result)
          Reads the values from fields and methods marked with ToVisit in the provided Visitable and put their value in the provided array of objects.
Overloading this method allows to change the way values are allocated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VisitableReader

public VisitableReader(java.lang.Class<? extends Visitable> visitableClass)
Builds a new VisitableReader.
A VisitableReader built for a class can be used many times for all instances of this class. Doing so is more efficient.

Parameters:
visitableClass - The class for which to build a VisitableReader
Method Detail

readValues

public java.lang.Object[] readValues(Visitable visitable)
                              throws java.lang.IllegalArgumentException,
                                     java.lang.IllegalAccessException,
                                     java.lang.reflect.InvocationTargetException
Reads the values from fields and methods marked with ToVisit in the provided Visitable and returns them as an array of objects.

Parameters:
visitable - The Visitable to inspect
Returns:
An array containing the visitable and the values of its fields and methods marked with ToVisit, in the order specified by ToVisit
Throws:
java.lang.IllegalArgumentException - The visitable isn't
java.lang.IllegalAccessException - Java refuses to grant us the right to inspect this object
java.lang.reflect.InvocationTargetException - We tried to invoke a method which threw an exception
See Also:
ToVisit

readValues

protected void readValues(Visitable visitable,
                          java.lang.Object[] result)
                   throws java.lang.IllegalArgumentException,
                          java.lang.IllegalAccessException,
                          java.lang.reflect.InvocationTargetException
Reads the values from fields and methods marked with ToVisit in the provided Visitable and put their value in the provided array of objects.
Overloading this method allows to change the way values are allocated.

Parameters:
visitable - The Visitable to inspect
result - An array that will be modified to containing the visitable and the values of its fields and methods marked with ToVisit, in the order specified by ToVisit.
The size of this array must be the return value of getNumberOfValues().
Throws:
java.lang.IllegalArgumentException - The visitable isn't
java.lang.IllegalAccessException - Java refuses to grant us the right to inspect this object
java.lang.reflect.InvocationTargetException - We tried to invoke a method which threw an exception
See Also:
ToVisit

getNumberOfValues

public int getNumberOfValues()
Returns:
the size of the return value of readValues(Visitable), which is also the size of the second argument of readValues(Visitable, Object[])
This value do not change during the lifetime of the object.