kusalk commented on code in PR #659:
URL: https://github.com/apache/struts/pull/659#discussion_r1105771667
##########
core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java:
##########
@@ -43,64 +60,292 @@
* @author James House
* @author Rainer Hermanns
*/
-public class DefaultActionValidatorManager extends
AbstractActionValidatorManager {
+public class DefaultActionValidatorManager implements ActionValidatorManager {
+
+ /**
+ * The file suffix for any validation file.
+ */
+ protected static final String VALIDATION_CONFIG_SUFFIX = "-validation.xml";
- private final static Logger LOG =
LogManager.getLogger(DefaultActionValidatorManager.class);
+ protected final Map<String, List<ValidatorConfig>> validatorCache =
synchronizedMap(new HashMap<>());
+ protected final Map<String, List<ValidatorConfig>> validatorFileCache =
synchronizedMap(new HashMap<>());
+ private static final Logger LOG =
LogManager.getLogger(DefaultActionValidatorManager.class);
+
+ protected ValidatorFactory validatorFactory;
+ protected ValidatorFileParser validatorFileParser;
+ protected FileManager fileManager;
+ protected boolean reloadingConfigs;
+ protected TextProviderFactory textProviderFactory;
+
+ @Inject
+ public void setValidatorFactory(ValidatorFactory fac) {
+ this.validatorFactory = fac;
+ }
+
+ @Inject
+ public void setValidatorFileParser(ValidatorFileParser parser) {
+ this.validatorFileParser = parser;
+ }
+
+ @Inject
+ public void setFileManagerFactory(FileManagerFactory fileManagerFactory) {
+ this.fileManager = fileManagerFactory.getFileManager();
+ }
+
+ @Inject(value = StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, required
= false)
+ public void setReloadingConfigs(String reloadingConfigs) {
+ this.reloadingConfigs = Boolean.parseBoolean(reloadingConfigs);
+ }
+
+ @Inject
+ public void setTextProviderFactory(TextProviderFactory
textProviderFactory) {
+ this.textProviderFactory = textProviderFactory;
+ }
@Override
- public synchronized List<Validator> getValidators(Class clazz, String
context) {
- return getValidators(clazz, context, null);
+ public void validate(Object object, String context) throws
ValidationException {
+ validate(object, context, (String) null);
+ }
+
+ @Override
+ public void validate(Object object, String context, String method) throws
ValidationException {
+ ValidatorContext validatorContext = new
DelegatingValidatorContext(object, textProviderFactory);
+ validate(object, context, validatorContext, method);
+ }
+
+ @Override
+ public void validate(Object object, String context, ValidatorContext
validatorContext) throws ValidationException {
+ validate(object, context, validatorContext, null);
+ }
+
+ /**
+ * Builds a key for validators - used when caching validators.
+ *
+ * @param clazz the action.
+ * @param context context
+ * @return a validator key which is the class name plus context.
+ */
+ protected String buildValidatorKey(Class clazz, String context) {
+ return clazz.getName() + "/" + context;
+ }
+
+ protected Validator getValidatorFromValidatorConfig(ValidatorConfig
config, ValueStack stack) {
+ Validator validator = validatorFactory.getValidator(config);
+ validator.setValidatorType(config.getType());
+ validator.setValueStack(stack);
+ return validator;
}
@Override
public synchronized List<Validator> getValidators(Class clazz, String
context, String method) {
Review Comment:
Given that both `AnnotationActionValidatorManager` and
`DefaultActionValidatorManager` use the same caching logic I presume both
should be synchronised on this method. Previously
`AnnotationActionValidatorManager` was not. Regardless, I don't think it will
hurt to add it here for the purpose of simplifying the code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]