1 7 package com.inversoft.verge.mvc.controller.form.config; 8 9 10 import org.jdom.Element; 11 12 import com.inversoft.config.ConfigurationException; 13 import com.inversoft.error.ErrorList; 14 import com.inversoft.util.ReflectionException; 15 import com.inversoft.verge.mvc.config.BaseConfig; 16 import com.inversoft.verge.mvc.config.BaseFormConfig; 17 import com.inversoft.verge.mvc.config.BaseValidatorConfig; 18 import com.inversoft.verge.mvc.config.BaseValidatorConfigBuilder; 19 import com.inversoft.verge.mvc.config.FormConfigRegistry; 20 import com.inversoft.verge.mvc.config.OverrideValidator; 21 import com.inversoft.verge.mvc.config.PropertyConfig; 22 import com.inversoft.verge.mvc.validator.Validator; 23 24 25 33 public class ValidatorConfigBuilder extends BaseValidatorConfigBuilder { 34 35 41 public String getFailureElementName() { 42 return Constants.FAILURE_MAPPING_ATTRIBUTE; 43 } 44 45 48 public BaseConfig build(Element element) throws ConfigurationException { 49 BaseValidatorConfig base = (BaseValidatorConfig) super.build(element); 50 ValidatorConfig validator = new ValidatorConfig(base); 51 52 return validator; 53 } 54 55 58 public void validate(BaseValidatorConfig validator, BaseFormConfig config, 59 FormConfigRegistry registry) 60 throws ConfigurationException { 61 62 ErrorList errors = new ErrorList(); 64 ValidatorConfig valConfig = (ValidatorConfig) validator; 65 FormMVCConfigRegistry formRegistry = (FormMVCConfigRegistry) registry; 66 String name = valConfig.getFailureDefinition(); 67 if (name != null) { 68 MappingConfig mapping = formRegistry.lookupMapping(name, 69 (FormConfig) config); 70 if (mapping == null) { 71 errors.addError("Unable to locate mapping named: " + name + 72 " for validator: " + validator.getName()); 73 } 74 75 valConfig.setFailureMapping(mapping); 76 } 77 78 try { 79 super.validate(validator, config, registry); 80 } catch (ConfigurationException ce) { 81 errors.addErrorList(ce.getErrors()); 82 } 83 84 if (!errors.isEmpty()) { 85 throw new ConfigurationException(errors); 86 } 87 } 88 89 100 protected BaseValidatorConfig createProxy(BaseValidatorConfig config, 101 final PropertyConfig propConfig) { 102 103 ValidatorConfig valConfig = (ValidatorConfig) config; 104 return new ValidatorConfig(valConfig) { 105 public boolean isValidating() { 107 return true; 108 } 109 110 public Validator newValidator() throws ReflectionException { 112 return new OverrideValidator(propConfig); 113 } 114 }; 115 } 116 } | Popular Tags |