com.opensymphony.xwork2.validator.DelegatingValidatorContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xwork Show documentation
Show all versions of xwork Show documentation
XWork is an command-pattern framework that is used to power WebWork
as well as other applications. XWork provides an Inversion of Control
container, a powerful expression language, data type conversion,
validation, and pluggable configuration.
The newest version!
/*
* Copyright (c) 2002-2006 by OpenSymphony
* All rights reserved.
*/
package com.opensymphony.xwork2.validator;
import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import java.util.*;
/**
* A default implementation of the {@link ValidatorContext} interface.
*
* @author Jason Carreira
* @author Rainer Hermanns
*/
public class DelegatingValidatorContext implements ValidatorContext {
private LocaleProvider localeProvider;
private TextProvider textProvider;
private ValidationAware validationAware;
/**
* Creates a new validation context given a ValidationAware object, and a text and locale provider. These objects
* are used internally to set errors and get and set error text.
*/
public DelegatingValidatorContext(ValidationAware validationAware, TextProvider textProvider,
LocaleProvider localeProvider) {
this.textProvider = textProvider;
this.validationAware = validationAware;
this.localeProvider = localeProvider;
}
/**
* Creates a new validation context given an object - usually an Action. The internal objects
* (validation aware instance and a locale and text provider) are created based on the given action.
*
* @param object the object to use for validation (usually an Action).
*/
public DelegatingValidatorContext(Object object) {
this.localeProvider = makeLocaleProvider(object);
this.validationAware = makeValidationAware(object);
this.textProvider = makeTextProvider(object, localeProvider);
}
/**
* Create a new validation context given a Class definition. The locale provider, text provider and
* the validation context are created based on the class.
*
* @param clazz the class to initialize the context with.
*/
public DelegatingValidatorContext(Class clazz) {
localeProvider = new ActionContextLocaleProvider();
textProvider = new TextProviderFactory().createInstance(clazz, localeProvider);
validationAware = new LoggingValidationAware(clazz);
}
public void setActionErrors(Collection errorMessages) {
validationAware.setActionErrors(errorMessages);
}
public Collection getActionErrors() {
return validationAware.getActionErrors();
}
public void setActionMessages(Collection messages) {
validationAware.setActionMessages(messages);
}
public Collection getActionMessages() {
return validationAware.getActionMessages();
}
public void setFieldErrors(Map> errorMap) {
validationAware.setFieldErrors(errorMap);
}
public Map> getFieldErrors() {
return validationAware.getFieldErrors();
}
public String getFullFieldName(String fieldName) {
return fieldName;
}
public Locale getLocale() {
return localeProvider.getLocale();
}
public boolean hasKey(String key) {
return textProvider.hasKey(key);
}
public String getText(String aTextName) {
return textProvider.getText(aTextName);
}
public String getText(String aTextName, String defaultValue) {
return textProvider.getText(aTextName, defaultValue);
}
public String getText(String aTextName, String defaultValue, String obj) {
return textProvider.getText(aTextName, defaultValue, obj);
}
public String getText(String aTextName, List