SPT Core API

com.sptci.echo2.binding
Class JDOViewValidator<V,M>

java.lang.Object
  extended by com.sptci.echo2.binding.ViewValidator<V>
      extended by com.sptci.echo2.binding.JDOViewValidator<V,M>
Type Parameters:
V - The class name of the view that is to be validated.
M - The class name of the model object that backs the view. This parameter is used only if using the constructor that takes two parameters.

public class JDOViewValidator<V,M>
extends ViewValidator<V>

A validator for view components that represent objects persisted using JDO. This validator attempts to perform standard validation on fields in the model object that have been annotated as unique. Runs a query to determine existence of an object and reports an appropriate error message.

© Copyright 2008 Sans Pareil Technologies, Inc.

Version:
$Id: JDOViewValidator.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2008-04-25

Field Summary
protected  M model
          The model object backing the ViewValidator.view.
 
Fields inherited from class com.sptci.echo2.binding.ViewValidator
fields, view
 
Constructor Summary
JDOViewValidator(V view)
          Create a new instance of the validator for the specified view.
JDOViewValidator(V view, M model)
          Create a new instance of the validator for the specified view and backing model.
 
Method Summary
protected  boolean checkUnique(Collection<Field> viewFields)
          Check that the combination of the values represented by the specified fields in the ViewValidator.view do not represent an existing model object in the data store.
protected  Collection<Field> fetchViewFields(javax.jdo.annotations.Unique unique)
          Process the unqiue annotation specified at the class level in model or its super-class.
protected  Object getValue(Field field)
          Return the value of the specified Field in ViewValidator.view.
protected  void processUnique(Collection<String> messages)
          Process unique constraint annotations in model and perform validation on the corresponding data in ViewValidator.view.
 Collection<String> validate()
          Perform the validation on the child components.
 
Methods inherited from class com.sptci.echo2.binding.ViewValidator
checkConfirm, checkText, processListComponent, processRegex, processTextComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected final M model
The model object backing the ViewValidator.view.

Constructor Detail

JDOViewValidator

public JDOViewValidator(V view)
                 throws BindingException
Create a new instance of the validator for the specified view. It is assumed that the view defines a getModel method that returns the model object.

Parameters:
view - The view that is to be validated.
Throws:
BindingException - If errors are encountered while executing the getModel method.

JDOViewValidator

public JDOViewValidator(V view,
                        M model)
Create a new instance of the validator for the specified view and backing model.

Parameters:
view - The view that is to be validated.
model - The model object backing the view.
Method Detail

validate

public Collection<String> validate()
Perform the validation on the child components. Over-ridden to process annotated constraints and check against the data store.

Overrides:
validate in class ViewValidator<V>
Returns:
A collection of messages that indicate failure(s) of validation for the child components.
See Also:
ViewValidator.validate()

processUnique

protected void processUnique(Collection<String> messages)
Process unique constraint annotations in model and perform validation on the corresponding data in ViewValidator.view.

Parameters:
messages - The collection to which appropriate error messages are to be added.
See Also:
fetchViewFields(javax.jdo.annotations.Unique), checkUnique(java.util.Collection)

fetchViewFields

protected Collection<Field> fetchViewFields(javax.jdo.annotations.Unique unique)
Process the unqiue annotation specified at the class level in model or its super-class. This method may be called recursively to process all annotations in the class hierarchy.

Parameters:
unique - The annotation that is to be processed.
Returns:
The collection of fields in the view whose values are to be checked for uniqueness.

checkUnique

protected boolean checkUnique(Collection<Field> viewFields)
Check that the combination of the values represented by the specified fields in the ViewValidator.view do not represent an existing model object in the data store.

Parameters:
viewFields - The fields corresponding to the fields in the model whose values are to be checked.
Returns:
Returns true if the values in the ViewValidator.view represents a unique combination that may be persisted to the data store.

getValue

protected Object getValue(Field field)
Return the value of the specified Field in ViewValidator.view.

Parameters:
field - The field whose value is to be retrieved.
Returns:
The object that represents the value of the field. The appropriate value is retrieved based upon the component displayed in the ViewValidator.view.

SPT Core API