NHibernate.Validator
Get all mapped classes.
All mapped classes for the current loader.
Contract for configuration sources.
Assembly qualified name for shared engine provider.
Configured properties.
Configured Mappings.
Configured Entity Type Inspectors.
Load all mappings configured in the nhv-configuration configuration section.
The list of configured mappings.
Adds all of the assembly's mappings.
The assembly full name to load.
Adds all of the assembly's mappings.
The assembly.
Create the attribute of a entity-validator from XML definitions.
The entity class where associate the attribute.
The attribute name in the mapping.
The instance.
We are using the conventions:
- The attribute must be defined in the same namespace of the .
- The attribute class may have the postfix "Attribute" without need to use it in the mapping.
Helper to parse nhv-configuration XmlNode.
The XML node name for hibernate configuration section in the App.config/Web.config and
for the hibernate.cfg.xml .
The XML Namespace for the nhibernate-configuration
XPath expression for shared-engine-class node
XPath expression for property nodes
XPath expression for mapping nodes
XPath expression for entity-type-inspector nodes
Convert a given string to a .
The string
The result .
when the string don't have a valid value.
Readonly NHV configuration section handler
NHibernate Validator properties
Apply DDL changes on Hibernate metamodel when using validator with Hibernate Annotations.
Default to true.
Enable listeners auto registration in Hibernate Annotations and EntityManager.
Default to true.
Message interpolator class used. The same instance is shared across all ClassValidators
Mapping loader implementor.
Constraint Validator Factory used to create Validators.
Define validation mode.
Default
Allowed values are available in .
Base name of resource file for embedded validators.
The configuration property name for the custom resource manager
Define the provider of shared engine between various logical layers.
The main target of shared engine is have only one engine for the NHibernate events of validator.
If an application configure a certain shared engine provider and use it to get the ValidatorEngine
the result is that the events for NH configure the ValidatorEngine and the application can
share the same engine ensuring that app and NH-event make the same validation.
The configuration of shared_engine_provider is ignored outside app/web config file.
Shared engine provider instance.
The Shared engine instance can be injected at run-time even if if not the better way to work with it.
Configuration parsed values for a mapping XML node
There are 3 possible combinations of mapping attributes
1 - resource and assembly: NHV will read the mapping resource from the specified assembly
2 - file only: NHV will read the mapping from the file.
3 - assembly only: NHV will find all the resources ending in nhv.xml from the assembly.
Initializes a new instance of the class.
Mapped file.
When is null or empty.
Initializes a new instance of the class.
The assembly name.
The mapped embedded resource.
When is null or empty.
Is the mapping element empty
True if the element is empty; false otherwise.
The file of a mapped validator.
The assembly name where validator mapping is.
The name of an embedded resource in the .
Extensions to integrate NHibernate.Validator with NHibernate
Initialize NHibernate's events and/or DLL.
The NHibernate.Cfg.Configuration before build the session factory.
If the was configured or the
was set, it will be used for the integration;
otherwise a new will be configured and used.
To have DDL-integration you must set the configuration property "apply_to_ddl" to true
To have events-integration you must set the configuration property "autoregister_listeners" to true
Initialize NHibernate's events and/or DLL.
The NHibernate.Cfg.Configuration before build the session factory.
A configured ValidatorEngine (after call )
To have DDL-integration you must set the configuration property "apply_to_ddl" to true
To have events-integration you must set the configuration property "autoregister_listeners" to true
Configuration parsed values for nhv-configuration section.
Initializes a new instance of the class.
An empty configuration.
Initializes a new instance of the class.
The XML reader to parse.
The nhv-configuration.xsd is applied to the XML.
When nhibernate-configuration.xsd can't be applied.
Configured properties
Configured Mappings
Adds all of the assembly's embedded resources whose names end with .nhv.xml.
The assembly.
This configuration object.
Load and return a mapping for a given type.
The given type.
The mapping.
The method use a convention to find the resource that represent the mapping for the given class.
- The mapping must be compiled like embedded resource in the same assembly of the given type
- The name o the resource must be the same name of the type and end with ".nhv.xml"
- The resource must stay in the same namespace of the type
The annotated element has to be false
Base class for all embedded validators, accepting Tags.
Define a validator-definition (Attribute) which accept tags.
Collection of tags.
This property should be used only by Attribute.
It is defined as object because language limitation
(see the end of http://msdn.microsoft.com/en-us/library/aa664616(VS.71).aspx).
[Max(100, Tags = new[] { typeof(Error), typeof(Warning) })]
public int Value { get; set; }
All validators attributes must implement this interface.
A validator for a particular attribute
does the object/element pass the constraints
Object to be validated
Context for the validator constraint
if the instance is valid
The annotated element has to be true
Max restriction on a numeric annotated element
Interface implemented by the validator
when a constraint may be represented in a
hibernate metadata property
Min restriction on a numeric annotated element (or the string representation of a numeric)
Define the contract for an object that can provide a Validator instance
instead a .
Checks wheter the member is a number having up to IntegerDigits,
and FractionalDigits fractional digits.
FractionalDigits default value: 0.
For example:
- With [Digits(3)] //here FractionalDigits is zero.
- Valid values: 0; 9; 99; 99.0; null; 01;
- Invalid values: 1000; 10.1; "aa"; new object();
- With [Digits(2,3)]
- Valid values: 0; 100.100; 99.99;
- Invalid values: 1000.0; 9.233; 1233;
- With [Digits(0,2)]
- Valid values: 0; 0.1; 0.12;
- Invalid values: 1.12; 0.123
does the object/element pass the constraints
Object to be validated
if the instance is valid
The Attribute element has to represent an EAN-13 or UPC-A
which aims to check for user mistake, not actual number validity!
http://en.wikipedia.org/wiki/European_Article_Number
The string has to be a well-formed email address
The file, where string is pointing to, must exist.
Check that a Date representation apply in the future
This expression matches an IBAN Code (International Bank Account Number)
Definitions of countries IBAN (Key=Country code as defined in ISO 3166; Value=IbanDefinition)
IBAN cleaner
Not cleaned IBAN
The validatable IBAN
true if the have all valid character; otherwise false
Validate the CIN for a given encoded IBAN
The encoded IBAN.
true if the CIN is valid (mod=1); otherwise false
Must be a valid IP address.
Check if string is a number.
Apply some length restrictions to the annotated element. It has to be a string
Max restriction on a numeric annotated element
Min restriction on a numeric annotated element (or the string representation of a numeric)
Check that a String is not empty (length > 0)
or that a IEnumerable is not empty (Count > 0)
To validate for NotNull and Not Empty use NotNullNotEmptyAttribute.
Ensure the member to be not null.
Ensure a IEnumerable (including string) to be not null and not empty.
Valid values: "abc"; new int[] {1}; new List<int>(new int[] { 1 });
Invalid values: null; ""; 123; new int[0]; new List<int>();
Check that a date representation apply in the past
The annotated element must follow the regex pattern
The annotated elemnt has to be in the appropriate range. Apply on numeric values or string
representation of the numeric value.
Size range for Arrays, Collections (do not use with strings).
-[SizeAttribute] range from 0 to int.MaxValue.
Valid values: new int[0];
[SizeAttribute(1,3)] range from 1 to 3.
Valid values: new int[1]; new int[3]
Invalid values: new int[0]; new int[4]; "123"; 123;
Min = 0
Max = int.MaxValue
Min and Max are specified in the parameters.
Min value to ensure
Max value to ensure
Enables recursive validation of an associated object
The annotated elemnt has to be in the appropriate range (excluding both limits).
Apply on numeric values can be converted to double ().
Engine that take a object and check every expressed attribute restrictions
Apply constraints on a entity instance and return all the failures.
if is null, an empty array is returned
object to apply the constraints
Apply constraints on a entity instance and return all the failures for the given property.
if is null, an empty array is returned.
Object to apply the constraints
The name of the property to validate.
Assert a valid Object. A
will be throw in a Invalid state.
Object to be asserted
Apply constraints of a particular property value of a entity type and return all the failures.
The InvalidValue objects returns return null for and .
Apply the registred constraints rules on the hibernate metadata (to be applied on DB schema)
hibernate metadata
Get the list of constraints declared for a give member of the entityValidator
The name of the property.
The list of attribute of the given property.
Apply constraints on a entity instance and return all the failures.
if is null, an empty array is returned
object to apply the constraints
list of tags enabled fpr the validation.
Invalid values
Apply constraints on a entity instance and return all the failures for the given property.
if is null, an empty array is returned.
Object to apply the constraints
The name of the property to validate.
list of tags enabled fpr the validation.
Invalid values
Apply constraints of a particular property value of a entity type and return all the failures.
The InvalidValue objects returns return null for and .
The name of the property to validate.
the potential value of the property.
list of tags enabled fpr the validation.
Invalid values
Return true if this contains rules for apply, false in other case.
Used to create an instance when deserialize
Create the validator engine for this entity type.
Used in Unit Testing.
Create the validator engine for a particular entity class, using a resource bundle
for message rendering on violation
Used in Unit Testing.
entity type
The CultureInfo for the .
Validator definition mode
Create the validator engine for a particular entity class, using a resource bundle
for message rendering on violation
Used in Unit Testing.
entity type
Custom interpolator.
The CultureInfo for the .
Validator definition mode
Initialize the type.
Apply constraints on a entity instance and return all the failures.
if is null, an empty array is returned
object to apply the constraints
Validate the child validation to objects and collections
Get the ClassValidator for the
parametter from . If doesn't exist, a
new is returned.
type
Create a from a attribute.
If the attribute is not a type return null.
attribute
the validator for the attribute
Create the validator for the children, who got the
on the fields or properties
Add recursively the inheritance tree of types (Classes and Interfaces)
to the parameter
Type to be analyzed
Collections of types
Assert a valid Object. A
will be throw in a Invalid state.
Object to be asserted
Apply constraints of a particular property value of a entity type and return all the failures.
The InvalidValue objects returns an empty enumerable for InvalidValue#Entity and InvalidValue#RootEntity.
Note: this is not recursive.
Name of the property or field to validate
Real value to validate. Is not an entity instance.
Apply the registred constraints rules on the hibernate metadata (to be applied on DB schema)
hibernate metadata
Return true if this contains rules for apply, false in other case.
Just In Time ClassValidatorFactory
An for proxy coming from NHibernate.
Inspector to find the real type of an entity instance.
En entity instace can be a dynamic proxy.
Implementors shoud recognize the proxy and return the
of the target.
If the type is not a proxy the implementors shouldn't recognize it.
Guess the type of the entity instance.
The entity instance
The of the entity if was recognized; otherwise null.
Contract for validator that need initialization.
The attribute that hold validator parameters.
Take the attribute values and Initialize the Validator
parameters
Responsible for validator message interpolation (variable replacement etc)
this extension point is useful if the call has some contextual informations to
interpolate in validator messages
A single violation of a class level or method level constraint.
Created by . The ctor is public only for test scope.
Interface implemented by the validator
when a constraint may be represented in the
hibernate metadata
Apply the constraint in the hibernate metadata
PersistentClass
Contract for Shared Engine Provider
The SharedEngineProvider is the service locator for the ValidatorEngine.
More information about why use the Shared Engine Provider are availables in this post :
http://fabiomaulo.blogspot.com/2009/02/diving-in-nhibernatevalidator.html
Provide the shared engine instance.
The validator engine.
Just In Time Class Mapping Factory
The JITClassMappingFactory work outside the engine configuration.
Allow multiple to work just a .
The iterate a list of
for the first position to the last and return the first match.
used to prevent circular state validation.
The equality of two instances if done by Reference instead use the possible override of each element.
The same for hash-code.
Get the validator for a type. If doesn't exists, will create one, add to the engine and return it.
Type for the validator
Validator encountered or created-and-added.
The element of an validation.
Create a new instance of for a root element.
The type of the entity.
The validator.
The root element is the entity it self.
Create a new instance of for a composite element.
The type of the composite element.
The validator of the composite element.
The getter of the composite element inside the root entity.
Add a .
The sub element
The type of the entity
The validator of the .
The getter of the composite element inside the root entity.
Composite Elements.
Has SubElements ?
In order to point to a validator in other assembly.
The engine of NHibernate Validator
The engine is the easy way to work with NHibernate.Validator.
It hold all class validators.
Usually an application will create a single .
.
Configure NHibernate.Validator using the <nhv-configuration> section
from the application config file, if found, or the file nhvalidator.cfg.xml if the
<nhv-configuration> section not include the session-factory configuration.
If both are found merge the two configuration.
To configure NHibernate explicitly using nhvalidator.cfg.xml, appling merge/override
of the application configuration file, use this code:
configuration.Configure("path/to/nhvalidator.cfg.xml");
Configure NHibernate.Validator using the file specified.
The location of the XML file to use to configure NHibernate.Validator.
Calling Configure(string) will override/merge the values set in app.config or web.config
Configure NHibernate.Validator using the specified .
The that contains the Xml to configure NHibernate.Validator.
Calling Configure(XmlReader) will overwrite the values set in app.config or web.config
Configure NHibernate.Validator using the specified .
The that is the configuration reader to configure NHibernate.Validator.
Calling Configure(INHVConfiguration) will overwrite the values set in app.config or web.config.
You can use this overload is you are working with Attributes or Xml-files.
Configure NHibernate.Validator using the specified .
The that is the configuration reader to configure NHibernate.Validator.
The instance.
Calling Configure(INHVConfiguration) will overwrite the values set in app.config or web.config
Apply constraints/rules on a entity instance.
The entity instance to validate
Tags included in the validation.
All the failures or an empty array if is null.
If the of the was never inspected, or
it was not configured, the will be automatic added to the engine.
Apply constraints/rules on a entity instance.
The entity instance to validate
Tags included in the validation.
False if there is one or more the failures; True otherwise (including when is null).
If the of the was never inspected, or
it was not configured, the will be automatic added to the engine.
Assert a valid entity.
The entity instance to validate
when have an invalid state.
If the of the was never inspected, or
it was not configured, the will be automatic added to the engine.
Use the for a given .
The entity type
The name of a property
The value of the property.
Tags included in the validation.
All the invalid values.
If the was never inspected, or
it was not configured, the will be automatic added to the engine.
Use the for a given .
The entity type
The property type.
The lamda expression of the property getter.
The potencial value of the property.
Tags included in the validation.
If the was never inspected, or
it was not configured, the will be automatic added to the engine.
Use the for a given entity instance.
The entity instance to validate
The name of a property
Tags included in the validation.
All the invalid values.
If the of the was never inspected, or
it was not configured, the will be automatic added to the engine.
Use the for a given entity instance.
The entity instance to validate
The name of a property
The value of the property.
Tags included in the validation.
All the invalid values.
Add a validator to the engine or override existing one.
The type of an entity.
Create an istance of for the given .
Add a validator to the engine or override existing one.
The type of an entity.
Inspector for sub-elements
Gets an acquaintance .
The type of an entity.
A acquaintance for the give type
or null if the the was never used in the engine instance.
Gets a for a given
The given .
A validator for a or null if the
is not supported by .
In general a common application don't need to use this method but it can be useful for some kind of framework.
Default MessageInterpolator
Default Mode to construct validators
Database schema-level validation enabled
NHibernate event-based validation
Define how to investigate validators of a class.
Validators are discovered, by reflection, only investigating the class attributes
Validator are discovered only parsing the xml of the class
Validators are discovered, by reflection, investigating the class attributes
and then using the xml(or any other external source), merging both.
Conflicts are solved using xml-configuration over attribute-configuration.
Validators are discovered, by reflection, investigating the class attributes
and then using the xml(or any other external source), merging both.
Conflicts are solved using attribute-configuration over xml-configuration.
Common environment for insert and update NH event listeners
Before insert, executes the validator framework
Because, usually, we validate on insert and on update we are
using the same environment for PreInsert and PreUpdate event listeners,
the initialization of the environment (the ValidatorEngine) was or will be done in
ValidatePreInsertEventListener by NH.
This give us better performance on NH startup.
Initialize the validators, any non significant validators are not kept
Before update, executes the validator framework
Because, usually, we validate on insert and on update we are
using the same environment for PreInsert and PreUpdate event listeners,
the initialization of the environment (the ValidatorEngine) was or will be done in
ValidatePreInsertEventListener by NH.
This give us better performance on NH startup.
Indicates failure of an assertion: a possible bug in NHibernate.Validator
Initializes a new instance of the class.
Initializes a new instance of the class.
The message that describes the error.
Initializes a new instance of the class.
The message that describes the error.
The exception that is the cause of the current exception. If the innerException parameter
is not a null reference, the current exception is raised in a catch block that handles
the inner exception.
Initializes a new instance of the class.
The that holds the serialized object
data about the exception being thrown.
The that contains contextual information about the source or destination.
Get the value of an Attribute's property or the value in the resource for a given key.
The property-name of the attribute or key to find in the resources.
The string in the resource or null where not found.
Override this method to obtain flexibility.
The default interpolator can replace the message with public property values.
Entity or value
Property name to be used.
The value of the property
Utils metods for attributes
Returns true if the attribute can be declared more than one time for the same element
Utils methods for type issues.
Get the Generic Arguments of a
Get the type of the a Field or Property.
If is a: Generic Collection or a Array, return the type of the elements.
MemberInfo, represent a property or field
type of the member or collection member
Indicates if a is
is enumerable or not
Get the of a .
Get the value of some Property or Field.