Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.xillium.data.validation;
import org.xillium.base.Trace;
import org.xillium.data.DataBinder;
import org.xillium.data.DataObject;
import java.lang.reflect.*;
import java.util.*;
/**
* A dictionary of extended types for data validation.
*/
public class Dictionary {
protected static final Map, Map> _cachedValidators = new HashMap, Map>();
public static synchronized Validator cache(Class> type, String name, Validator validator) {
Map validators = _cachedValidators.get(type);
if (validators == null) {
validators = new HashMap();
_cachedValidators.put(type, validators);
}
validators.put(name, validator);
return validator;
}
public static synchronized Validator find(Class> type, String name) {
Map validators = _cachedValidators.get(type);
if (validators != null) {
return validators.get(name);
}
return null;
}
//String _namespace;
Map _namedValidators = new HashMap();
/**
* Constructs a Dictionary associated with the given name space.
*/
//public Dictionary() {
//_namespace = namespace;
//}
/**
* Adds a set of data type specifications.
* @param spec - a class that defines data types as member fields
*/
public Dictionary addTypeSet(Class> spec) {
for (Field field: spec.getDeclaredFields()) {
if (Modifier.isPublic(field.getModifiers())) {
String name = field.getName();
try {
_namedValidators.put(name, new Validator(name, field.getType(), field));
} catch (IllegalArgumentException x) {
Trace.g.std.note(Dictionary.class, "Ignored " + name + ": " + x.getMessage());
}
} else {
Trace.g.std.note(Dictionary.class, "Ignored non-public field: " + field.getName());
}
}
return this;
}
public Map getValidators() {
return _namedValidators;
}
/**
* Populates a data object by collecting and validating the named values from a DataBinder.
*
* @throws EmptyDataObjectException if a required member is missing and the data object is empty
* @throws MissingParameterException if a required member is missing but the data object has other members
* @throws DataValidationException if all other data validation fails
* @throws SecurityException if the data object is inproperly designed
*/
public T collect(T data, DataBinder binder) throws SecurityException, DataValidationException {
return collect(data, binder, null);
}
private final T collect(T data, DataBinder binder, String prefix) throws SecurityException, DataValidationException {
int present = 0;
String absent = null;
for (Field field: data.getClass().getFields()) {
if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) continue;
Class> ftype = field.getType();
String name = field.getName();
String qualified = prefix != null ? prefix + '.' + name : name;
Trace.g.std.note(Dictionary.class, "collect(): qualified = " + qualified);
if (ftype.isArray()) {
Trace.g.std.note(Dictionary.class, "collect(): field is an array");
ArrayList