forked from RestExpress/Syntaxe
-
Notifications
You must be signed in to change notification settings - Fork 0
Rails-inspired, annotations-based and functional-style syntactic and semantic validation framework for Java domain models. Supports requiredness, min, max, and length checks by default with the ability to create custom syntactic and semantic validations. Works 'expressly' well with the RestExpress services framework.
License
chriskchew/Syntaxe
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Syntaxe is an annotations-based, functional-style syntactic (and semantic) domain model validation framework for Java. Created to be simple, Syntaxe supports the following: 1) @BasicValidate (annotation) - which supports required, less-than, greater-than validations on fields. 2) Functional-style closures that allow users to create additional custom validations, whether syntactic or semantic. 3) Validatable interface which calls out the validation contract. 4) AbstractValidatable which is the default implementation of Validatable, which supports the use of @Validate and functional validations. 5) Validations utility class containing foreign methods to perform your own default validations such as requiredness, less-than, greater-than. 6) Validator utility class that implements validation on an instance that leverages the @BasicValidate annotation. Sample Usage: =================================================================================================== Option 1, extend AbstractValidatable --This provides the capability to override the validateInto(StringBuffer) method to provide custom validations. public class MyValidatableClass extends AbstractValidatable { @BasicValidate(name="ID", required=true) private String id; @BasicValidate(name="Name", required=true, minLength=5, maxLenth=25) private String name; @BasicValidate(name="Count", min=3, max=21) private int count; } ... elsewhere (e.g. before persisting to storage) call the validate() method on the MyValidatableClass instance. Option 2, Validatable implementor, no annotations. --This option allows complete customization of validations by implementing the validate() method and throwing a ValidationException when validation fails. public class MyValidatableClass implements Validatable { private String id; private String name; private int count; public void validate() { // provide validation throwing new ValidationException(List<String> errors) if validation // fails. } } Option 3, POJO with annotations. --This option enables POJO validations without requiring extension or implementation, using annotations and the ValidationEngine to accomplish validation. public class MyValidatableClass { @BasicValidate(name="ID", required=true) private String id; @BasicValidate(name="Name", required=true, maxLenth=25) private String name; @BasicValidate(name="Count", min=3, max=21) private int count; } ... elsewhere (e.g. before persisting to storage) call the ValidationEngine.validate(object) method passing the MyValidatableClass instance. If the returned List<String> list of error messages is not empty, validation failed. The validation error messages are in the list. Creating your own validator: ============================ 1. Create an annotation the captures the fields your validator needs to know about. 2. Create a class that implements com.strategicgains.syntaxe.annotation.ValidationProvider - AbstractValidationProvider might be a good start - The perform() method returns void, and should populate the List<String> errors parameters with any validation problems 3. Add a ValidationProvidedBy annotation to your custom validator annotation that points to your class from step 2. 4. See the com.strategicgains.syntaxe.validators.basic|regex for examples. Change History: =================================================================================================== Release 0.3 (Upcoming) * Refactored the ValidationEngine to support the notion of multiple validators per field. * This refactoring also now allows for extensible validators be created outside this library. * Renamed com.strategicgains.syntaxe.annotation.Validate to com.strategicgains.syntaxe.validators.basic.BasicValidate * Removed dependency on the bpel jar, for no other reason than pluggable validators went towards interfaces instead of closures. * Validators are now found by being Annotations with the ValidationProvidedBy annotation. * Added a Regular Expression validator. Release 0.2 * Refactored Validator into ValidationEngine. =================================================================================================== Release 0.1 * Initial extract from RestExpress. Base implementation on which to expand.
About
Rails-inspired, annotations-based and functional-style syntactic and semantic validation framework for Java domain models. Supports requiredness, min, max, and length checks by default with the ability to create custom syntactic and semantic validations. Works 'expressly' well with the RestExpress services framework.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- Java 100.0%