ca.grimoire.formtree.receiver.constructor
Class ConstructorReceiver<T>

java.lang.Object
  extended by ca.grimoire.formtree.receiver.constructor.ConstructorReceiver<T>
Type Parameters:
T - the type to return from form parsing.
All Implemented Interfaces:
FormElementReceiver, FormReceiver<T>

public class ConstructorReceiver<T>
extends java.lang.Object
implements FormReceiver<T>

A FormReceiver which populates arbitrary object graphs, rooted at an instance of a specific class. This strategy uses constructor invocation to create each node in the object graph.


Constructor Summary
ConstructorReceiver(java.lang.Class<T> formClass)
          Prepares to construct an instance of formClass using form data.
 
Method Summary
static boolean accepts(java.lang.Class<?> formClass)
          Checkes whether ConstructorReceiver is able to construct forms of a given class.
static
<T> ConstructorReceiver<T>
create(java.lang.Class<T> elementClass)
          A type-inferring alternative to ConstructorReceiver(Class).
 T finished()
          Condense the collected form data from this receiver and all receivers created from it into an instance of <T>.
 FormElementReceiver index(int index)
          Ignores index access entirely.
 FormElementReceiver key(java.lang.String field)
          Returns a FormElementReceiver appropriate for the named field.
 void values(java.lang.Iterable<java.lang.String> values)
          Ignores attempts to assign immediate values to a constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstructorReceiver

public ConstructorReceiver(java.lang.Class<T> formClass)
Prepares to construct an instance of formClass using form data. The class must have at least one form constructor (any constructor where all parameters are annotated with FormField).

If the class has multiple form constructors, the constructor used is unspecified.

Any fields in the form that cannot be mapped to the chosen form constructor will be ignored.

Parameters:
formClass - the class to construct.
Throws:
java.lang.IllegalArgumentException - if the class has no form constructors.
Method Detail

accepts

public static boolean accepts(java.lang.Class<?> formClass)
Checkes whether ConstructorReceiver is able to construct forms of a given class. ConstructorReceiver can construct any class that has at least one form constructor (any constructor where all parameters are annotated with FormField).

Parameters:
formClass - the class to interrogate.
Returns:
true if ConstructorReceiver can populate formClass.

create

public static <T> ConstructorReceiver<T> create(java.lang.Class<T> elementClass)
A type-inferring alternative to ConstructorReceiver(Class).

Type Parameters:
T - the type of the created form element.
Parameters:
elementClass - the class of <T>
Returns:
a new ConstructorReceiver.

finished

public T finished()
Condense the collected form data from this receiver and all receivers created from it into an instance of <T>.

Specified by:
finished in interface FormReceiver<T>
Returns:
the result of the form decoding process.
See Also:
FormReceiver.finished()

key

public FormElementReceiver key(java.lang.String field)
Returns a FormElementReceiver appropriate for the named field. Fields that don't map to constructor parameters will be silently ignored.

Specified by:
key in interface FormElementReceiver
Parameters:
field - the field to decode.
Returns:
a form receiver for the key's contents.
See Also:
FormElementReceiver.key(java.lang.String)

index

public FormElementReceiver index(int index)
Ignores index access entirely.

Specified by:
index in interface FormElementReceiver
Parameters:
index - the index to decode.
Returns:
a form receiver for the index's contents.
See Also:
FormElementReceiver.index(int)

values

public void values(java.lang.Iterable<java.lang.String> values)
Ignores attempts to assign immediate values to a constructor.

Specified by:
values in interface FormElementReceiver
Parameters:
values - the values to store.
See Also:
FormElementReceiver.values(java.lang.Iterable)


Copyright © 2011 Grimoire Alchymia. All Rights Reserved.