public StateFullClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode, IEntityTypeInspector entityTypeInspector) : base(constraintValidatorFactory, resourceManager, culture, userInterpolator, validatorMode, entityTypeInspector) { }
public StateFullClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode, IEntityTypeInspector entityTypeInspector) : base(constraintValidatorFactory, resourceManager, culture, userInterpolator, validatorMode, entityTypeInspector) { }
internal ClassValidator(System.Type clazz, IConstraintValidatorFactory constraintValidatorFactory, IDictionary <System.Type, IClassValidator> childClassValidators, IClassValidatorFactory factory) { if (!clazz.ShouldNeedValidation()) { throw new ArgumentOutOfRangeException("clazz", clazz, "Create a validator for a unsupported type."); } entityType = clazz; this.constraintValidatorFactory = constraintValidatorFactory; this.factory = factory; messageBundle = factory.ResourceManager ?? GetDefaultResourceManager(); defaultMessageBundle = GetDefaultResourceManager(); culture = factory.Culture; userInterpolator = factory.UserInterpolator; if (userInterpolator != null) { userInterpolatorType = factory.UserInterpolator.GetType(); } this.childClassValidators = childClassValidators; validatorMode = factory.ValidatorMode; //Initialize the ClassValidator InitValidator(entityType, childClassValidators); }
private static ClassValidator CreateValidator(System.Type type, ValidatorMode mode) { return(new ClassValidator(type, new ResourceManager("NHibernate.Validator.Tests.Resource.Messages", Assembly.GetExecutingAssembly()), new CultureInfo("en"), mode)); }
private static ClassValidator CreateValidator(System.Type type, ValidatorMode mode) { return new ClassValidator(type, new ResourceManager("NHibernate.Validator.Tests.Resource.Messages", Assembly.GetExecutingAssembly()), new CultureInfo("en"), mode); }
/// <summary> /// Create the validator engine for a particular entity class, using a resource bundle /// for message rendering on violation /// </summary> /// <remarks> /// Used in Unit Testing. /// </remarks> /// <param name="entityType">entity type</param> /// <param name="resourceManager"></param> /// <param name="userInterpolator">Custom interpolator.</param> /// <param name="culture">The CultureInfo for the <paramref name="entityType"/>.</param> /// <param name="validatorMode">Validator definition mode</param> public ClassValidator(System.Type entityType, ResourceManager resourceManager, IMessageInterpolator userInterpolator, CultureInfo culture, ValidatorMode validatorMode) : this( entityType, new DefaultConstraintValidatorFactory(), new Dictionary <System.Type, IClassValidator>(), new JITClassValidatorFactory(new DefaultConstraintValidatorFactory(), resourceManager, culture, userInterpolator, validatorMode, new DefaultEntityTypeInspector())) { }
public JITClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode, IEntityTypeInspector entityTypeInspector) : base(constraintValidatorFactory, resourceManager, culture, userInterpolator, validatorMode, entityTypeInspector) { classMappingFactory = new JITClassMappingFactory(); }
public AbstractClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode) { this.constraintValidatorFactory = constraintValidatorFactory; this.resourceManager = resourceManager; this.culture = culture; this.userInterpolator = userInterpolator; this.validatorMode = validatorMode; }
protected AbstractClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode, IEntityTypeInspector entityTypeInspector) { this.constraintValidatorFactory = constraintValidatorFactory; this.resourceManager = resourceManager; this.culture = culture; this.userInterpolator = userInterpolator; this.validatorMode = validatorMode; EntityTypeInspector = entityTypeInspector; }
protected AbstractClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode, IEntityTypeInspector entityTypeInspector) { this.constraintValidatorFactory = constraintValidatorFactory; this.resourceManager = resourceManager; this.culture = culture; this.userInterpolator = userInterpolator; this.validatorMode = validatorMode; EntityTypeInspector = entityTypeInspector; }
public NHibernateValidatorRulesProvider(ValidatorMode configMode) { this.configMode = configMode; ruleEmitters.AddSingle<LengthAttribute>(x => new StringLengthRule(x.Min, x.Max)); ruleEmitters.AddSingle<MinAttribute>(x => new RangeRule(x.Value, null)); ruleEmitters.AddSingle<MaxAttribute>(x => new RangeRule(null, x.Value)); ruleEmitters.AddSingle<RangeAttribute>(x => new RangeRule(x.Min, x.Max)); ruleEmitters.AddSingle<NotEmptyAttribute>(x => new RequiredRule()); ruleEmitters.AddSingle<NotNullNotEmptyAttribute>(x => new RequiredRule()); ruleEmitters.AddSingle<PatternAttribute>(x => new RegularExpressionRule(x.Regex, x.Flags)); ruleEmitters.AddSingle<EmailAttribute>(x => new DataTypeRule(DataTypeRule.DataType.EmailAddress)); ruleEmitters.AddSingle<DigitsAttribute>(MakeDigitsRule); }
public IClassMapping GetClassMapping(System.Type clazz, ValidatorMode mode) { IClassMapping externalDefinition; IClassMapping result = null; switch (mode) { case ValidatorMode.UseAttribute: break; case ValidatorMode.UseExternal: result = GetExternalDefinitionFor(clazz); if (result == null) { log.Warn(string.Format("External definition not foud for class {0} in ValidatorMode.UseExternal mode.", clazz.FullName)); return(null); // <<<<<=== } break; case ValidatorMode.OverrideAttributeWithExternal: externalDefinition = GetExternalDefinitionFor(clazz); if (externalDefinition != null) { log.Debug("XmlOverAttribute applied for " + clazz.FullName); result = new XmlOverAttributeClassMapping(externalDefinition); } break; case ValidatorMode.OverrideExternalWithAttribute: externalDefinition = GetExternalDefinitionFor(clazz); if (externalDefinition != null) { log.Debug("AttributeOverXml applied for " + clazz.FullName); result = new AttributeOverXmlClassMapping(externalDefinition); } break; } if (result != null) { return(result); } else { log.Debug("Reflection applied for " + clazz.FullName); return(new ReflectionClassMapping(clazz)); } }
public IClassMapping GetClassMapping(System.Type clazz, ValidatorMode mode) { IClassMapping externalDefinition; IClassMapping result = null; switch (mode) { case ValidatorMode.UseAttribute: break; case ValidatorMode.UseExternal: result = GetExternalDefinitionFor(clazz); if (result == null) { log.Warn(string.Format("External definition not foud for class {0} in ValidatorMode.UseExternal mode.", clazz.FullName)); return null; // <<<<<=== } break; case ValidatorMode.OverrideAttributeWithExternal: externalDefinition = GetExternalDefinitionFor(clazz); if (externalDefinition != null) { log.Debug("XmlOverAttribute applied for " + clazz.FullName); result = new XmlOverAttributeClassMapping(externalDefinition); } break; case ValidatorMode.OverrideExternalWithAttribute: externalDefinition = GetExternalDefinitionFor(clazz); if (externalDefinition != null) { log.Debug("AttributeOverXml applied for " + clazz.FullName); result = new AttributeOverXmlClassMapping(externalDefinition); } break; } if(result != null) { return result; } else { log.Debug("Reflection applied for " + clazz.FullName); return new ReflectionClassMapping(clazz); } }
private static string ValidatorModeConvertFrom(ValidatorMode validatorMode) { switch (validatorMode) { case ValidatorMode.UseAttribute: return("useattribute"); case ValidatorMode.UseExternal: return("useexternal"); case ValidatorMode.OverrideAttributeWithExternal: return("overrideattributewithexternal"); case ValidatorMode.OverrideExternalWithAttribute: return("overrideexternalwithattribute"); default: throw new ArgumentOutOfRangeException("validatorMode"); } }
public static IClassMapping GetClassMapping(Type type, ValidatorMode mode) { IClassMapping result = null; switch (mode) { case ValidatorMode.UseAttribute: break; case ValidatorMode.UseXml: result = new XmlClassMapping(GetXmlDefinitionFor(type)); break; case ValidatorMode.OverrideAttributeWithXml: var xmlDefinition = GetXmlDefinitionFor(type); if (xmlDefinition != null) result = new XmlOverAttributeClassMapping(xmlDefinition); break; case ValidatorMode.OverrideXmlWithAttribute: var xmlDefinition2 = GetXmlDefinitionFor(type); if (xmlDefinition2 != null) result = new AttributeOverXmlClassMapping(xmlDefinition2); break; } return result ?? new ReflectionClassMapping(type); }
/// <summary> /// Create the validator engine for a particular entity class, using a resource bundle /// for message rendering on violation /// </summary> /// <remarks> /// Used in Unit Testing. /// </remarks> /// <param name="entityType">entity type</param> /// <param name="resourceManager"></param> /// <param name="culture">The CultureInfo for the <paramref name="entityType"/>.</param> /// <param name="validatorMode">Validator definition mode</param> public ClassValidator(System.Type entityType, ResourceManager resourceManager, CultureInfo culture, ValidatorMode validatorMode) : this(entityType, new DefaultConstraintValidatorFactory(), new Dictionary<System.Type, IClassValidator>(), new JITClassValidatorFactory(new DefaultConstraintValidatorFactory(), resourceManager, culture, null, validatorMode, new DefaultEntityTypeInspector())) { }
public JITClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode, IEntityTypeInspector entityTypeInspector) : base(constraintValidatorFactory, resourceManager, culture, userInterpolator, validatorMode, entityTypeInspector) { classMappingFactory = new JITClassMappingFactory(); }
internal ClassValidator(System.Type clazz, IConstraintValidatorFactory constraintValidatorFactory, IDictionary<System.Type, IClassValidator> childClassValidators, IClassValidatorFactory factory) { if (!clazz.ShouldNeedValidation()) { throw new ArgumentOutOfRangeException("clazz", clazz, "Create a validator for a unsupported type."); } entityType = clazz; this.constraintValidatorFactory = constraintValidatorFactory; this.factory = factory; messageBundle = factory.ResourceManager ?? GetDefaultResourceManager(); defaultMessageBundle = GetDefaultResourceManager(); culture = factory.Culture; userInterpolator = factory.UserInterpolator; if (userInterpolator != null) { userInterpolatorType = factory.UserInterpolator.GetType(); } this.childClassValidators = childClassValidators; validatorMode = factory.ValidatorMode; //Initialize the ClassValidator InitValidator(entityType, childClassValidators); }
public IFluentConfiguration SetDefaultValidatorMode(ValidatorMode mode) { properties[Environment.ValidatorMode] = ValidatorModeConvertFrom(mode); return(this); }
/// <summary> /// Configure NHibernate.Validator using the specified <see cref="INHVConfiguration"/>. /// </summary> /// <param name="config">The <see cref="INHVConfiguration"/> that is the configuration reader to configure NHibernate.Validator.</param> /// <param name="mappingLoader">The <see cref="XmlMappingLoader"/> instance.</param> /// <remarks> /// Calling Configure(INHVConfiguration) will overwrite the values set in app.config or web.config /// </remarks> public virtual void Configure(INHVConfiguration config, IMappingLoader mappingLoader) { if (config == null) { throw new ValidatorConfigurationException("Could not configure NHibernate.Validator.", new ArgumentNullException("config")); } Clear(); applyToDDL = PropertiesHelper.GetBoolean(Environment.ApplyToDDL, config.Properties, true); autoRegisterListeners = PropertiesHelper.GetBoolean(Environment.AutoregisterListeners, config.Properties, true); defaultMode = CfgXmlHelper.ValidatorModeConvertFrom(PropertiesHelper.GetString(Environment.ValidatorMode, config.Properties, string.Empty)); interpolator = GetImplementation <IMessageInterpolator>( PropertiesHelper.GetString(Environment.MessageInterpolatorClass, config.Properties, string.Empty), "message interpolator"); if (Environment.ConstraintValidatorFactory == null) { constraintValidatorFactory = GetImplementation <IConstraintValidatorFactory>( PropertiesHelper.GetString(Environment.ConstraintValidatorFactoryClass, config.Properties, string.Empty), "Constraint Validator Factory") ?? new DefaultConstraintValidatorFactory(); } else { constraintValidatorFactory = Environment.ConstraintValidatorFactory; } var inspectorsTypes = new HashSet <System.Type>(config.EntityTypeInspectors) { typeof(DefaultEntityTypeInspector) }; if (inspectorsTypes.Count > 1) { var inspectors = config.EntityTypeInspectors.Select(typeInspector => Instatiate <IEntityTypeInspector>(typeInspector)).ToArray(); entityTypeInspector = new MultiEntityTypeInspector(inspectors); } else { entityTypeInspector = new DefaultEntityTypeInspector(); } ResourceManager customResourceManager = null; var customResourceManagerBaseName = PropertiesHelper.GetString(Environment.CustomResourceManager, config.Properties, null); if (!string.IsNullOrEmpty(customResourceManagerBaseName)) { var resourceAndAssembly = TypeNameParser.Parse(customResourceManagerBaseName); try { var assembly = Assembly.Load(resourceAndAssembly.Assembly); customResourceManager = new ResourceManager(resourceAndAssembly.Type, assembly); } catch (Exception e) { throw new ValidatorConfigurationException("Could not configure NHibernate.Validator (custom resource manager).", e); } } factory = new StateFullClassValidatorFactory(constraintValidatorFactory, customResourceManager, null, interpolator, defaultMode, entityTypeInspector); // UpLoad Mappings if (mappingLoader == null) { // Configured or Default loader (XmlMappingLoader) mappingLoader = GetImplementation <IMappingLoader>( PropertiesHelper.GetString(Environment.MappingLoaderClass, config.Properties, string.Empty), "mapping loader") ?? new XmlMappingLoader(); } mappingLoader.LoadMappings(config.Mappings); Initialize(mappingLoader); }
/// <summary> /// Create the validator engine for a particular entity class, using a resource bundle /// for message rendering on violation /// </summary> /// <remarks> /// Used in Unit Testing. /// </remarks> /// <param name="entityType">entity type</param> /// <param name="resourceManager"></param> /// <param name="userInterpolator">Custom interpolator.</param> /// <param name="culture">The CultureInfo for the <paramref name="entityType"/>.</param> /// <param name="validatorMode">Validator definition mode</param> public ClassValidator(System.Type entityType, ResourceManager resourceManager, IMessageInterpolator userInterpolator, CultureInfo culture, ValidatorMode validatorMode) : this(entityType, new DefaultConstraintValidatorFactory(), new Dictionary<System.Type, IClassValidator>(), new JITClassValidatorFactory(new DefaultConstraintValidatorFactory(), resourceManager, culture, userInterpolator, validatorMode)) { }