diff --git a/documentation/src/main/docbook/en-US/hv.ent b/documentation/src/main/docbook/en-US/hv.ent deleted file mode 100644 index 40b50188f4..0000000000 --- a/documentation/src/main/docbook/en-US/hv.ent +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/documentation/src/main/docbook/en-US/master.xml b/documentation/src/main/docbook/en-US/master.xml deleted file mode 100644 index 1bbd4acbf1..0000000000 --- a/documentation/src/main/docbook/en-US/master.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - - Hibernate Validator - - JSR 349 Reference Implementation - - Reference Guide - - &version; - - &today; - - &version; - - - ©rightYear; - - ©rightHolder; - - - - - Hardy - - Ferentschik - - - - Gunnar - - Morling - - - - Shaozhuang - - Liu - - stliu@hibernate.org - - - - - - - - - - - - - - - - - - - - - - diff --git a/documentation/src/main/docbook/en-US/modules/annotation-processor.xml b/documentation/src/main/docbook/en-US/modules/annotation-processor.xml deleted file mode 100644 index 113d82cc51..0000000000 --- a/documentation/src/main/docbook/en-US/modules/annotation-processor.xml +++ /dev/null @@ -1,454 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Annotation Processor - - Have you ever caught yourself by unintentionally doing things - like - - - - specifying constraint annotations at unsupported data types (e.g. - by annotating a String with @Past) - - - - annotating the setter of a JavaBeans property (instead of the - getter method) - - - - annotating static fields/methods with constraint annotations - (which is not supported)? - - - - Then the Hibernate Validator Annotation Processor is the right thing - for you. It helps preventing such mistakes by plugging into the build - process and raising compilation errors whenever constraint annotations are - incorrectly used. - - - You can find the Hibernate Validator Annotation Processor as part of - the distribution bundle on Sourceforge - or in the usual Maven repositories such as Maven Central under the GAV - org.hibernate:hibernate-validator-annotation-processor:&version;. - - -
- Prerequisites - - The Hibernate Validator Annotation Processor is based on the - "Pluggable Annotation Processing API" as defined by JSR 269 which is part of - the Java Platform since Java 6. -
- -
- Features - - As of Hibernate Validator &version; the Hibernate Validator - Annotation Processor checks that: - - - - constraint annotations are allowed for the type of the annotated - element - - - - only non-static fields or methods are annotated with constraint - annotations - - - - only non-primitive fields or methods are annotated with - @Valid - - - - only such methods are annotated with constraint annotations - which are valid JavaBeans getter methods (optionally, see - below) - - - - only such annotation types are annotated with constraint - annotations which are constraint annotations themselves - - - - definition of dynamic default group sequence with - @GroupSequenceProvider is valid - - -
- -
- Options - - The behavior of the Hibernate Validator Annotation Processor can be - controlled using the processor - options listed in table : - - - Hibernate Validator Annotation Processor options - - - - - Option - - Explanation - - - - - - diagnosticKind - - Controls how constraint problems are reported. Must be the - string representation of one of the values from the enum - javax.tools.Diagnostic.Kind, e.g. - WARNING. A value of - ERROR will cause compilation to halt - whenever the AP detects a constraint problem. Defaults to - ERROR. - - - - methodConstraintsSupported - - Controls whether constraints are allowed at methods of any - kind. Must be set to true when working with - method level constraints as supported by Hibernate Validator. Can - be set to false to allow constraints only at - JavaBeans getter methods as defined by the Bean Validation API. - Defaults to true. - - - - verbose - - Controls whether detailed processing information shall be - displayed or not, useful for debugging purposes. Must be either - true or false. Defaults to - false. - - - -
-
- -
- Using the Annotation Processor - - This section shows in detail how to integrate the Hibernate - Validator Annotation Processor into command line builds (javac, Ant, - Maven) as well as IDE-based builds (Eclipse, IntelliJ IDEA, - NetBeans). - -
- Command line builds - -
- javac - - When compiling on the command line using javac, - specify the JAR hibernate-validator-annotation-processor-&version;.jar - using the "processorpath" option as shown in the following listing. - The processor will be detected automatically by the compiler and - invoked during compilation. - - - Using the annotation processor with javac - - javac src/main/java/org/hibernate/validator/ap/demo/Car.java \ - -cp /path/to/validation-api-&bvVersion;.jar \ - -processorpath /path/to/hibernate-validator-annotation-processor-&version;.jar - -
- -
- Apache Ant - - Similar to directly working with javac, the annotation processor - can be added as as compiler argument when invoking the javac - task for Apache - Ant: - - - Using the annotation processor with Ant - - <javac srcdir="src/main" - destdir="build/classes" - classpath="/path/to/validation-api-&bvVersion;.jar"> - <compilerarg value="-processorpath" /> - <compilerarg value="/path/to/hibernate-validator-annotation-processor-&version;.jar"/> -</javac> - -
- -
- Maven - - There are several options for integrating the annotation - processor with Apache - Maven. Generally it is sufficient to add the Hibernate - Validator Annotation Processor as dependency to your project: - - - Adding the HV Annotation Processor as dependency - - ... -<dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-validator-annotation-processor</artifactId> - <version>&version;</version> -</dependency> -... - - - The processor will then be executed automatically by the - compiler. This basically works, but comes with the disadavantage that - in some cases messages from the annotation processor are not displayed - (see MCOMPILER-66). - - Another option is using the Maven - Annotation Plugin. To work with this plugin, disable the - standard annotation processing performed by the compiler plugin and - configure the annotation plugin by specifying an execution and adding - the Hibernate Validator Annotation Processor as plugin dependency - (that way the processor is not visible on the project's actual - classpath): - - - Configuring the Maven Annotation Plugin - - ... -<plugin> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - <compilerArgument>-proc:none</compilerArgument> - </configuration> -</plugin> -<plugin> - <groupId>org.bsc.maven</groupId> - <artifactId>maven-processor-plugin</artifactId> - <version>2.2.1</version> - <executions> - <execution> - <id>process</id> - <goals> - <goal>process</goal> - </goals> - <phase>process-sources</phase> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-validator-annotation-processor</artifactId> - <version>&version;</version> - </dependency> - </dependencies> -</plugin> -... - - -
-
- -
- IDE builds - -
- Eclipse - - Do the following to use the annotation processor within the - Eclipse IDE: - - - - Right-click your project, choose "Properties" - - - - Go to "Java Compiler" and make sure, that "Compiler - compliance level" is set to "1.6". Otherwise the processor won't - be activated - - - - Go to "Java Compiler - Annotation Processing" and choose - "Enable annotation processing" - - - - Go to "Java Compiler - Annotation Processing - Factory Path" - and add the JAR - hibernate-validator-annotation-processor-&version;.jar - - - - Confirm the workspace rebuild - - - - You now should see any annotation problems as regular error - markers within the editor and in the "Problem" view: - - - - - - -
- -
- IntelliJ IDEA - - The following steps must be followed to use the annotation - processor within IntelliJ - IDEA (version 9 and above): - - - - Go to "File", then "Settings", - - - - Expand the node "Compiler", then "Annotation - Processors" - - - - Choose "Enable annotation processing" and enter the - following as "Processor path": - /path/to/hibernate-validator-annotation-processor-&version;.jar - - - - Add the processor's fully qualified name - org.hibernate.validator.ap.ConstraintValidationProcessor - to the "Annotation Processors" list - - - - If applicable add you module to the "Processed Modules" - list - - - - Rebuilding your project then should show any erronous constraint - annotations: - - - - - - -
- -
- NetBeans - - Starting with version 6.9, also the NetBeans IDE supports using - annotation processors within the IDE build. To do so, do the - following: - - - - Right-click your project, choose "Properties" - - - - Go to "Libraries", tab "Processor", and add the JAR - hibernate-validator-annotation-processor-&version;.jar - - - - Go to "Build - Compiling", select "Enable Annotation - Processing" and "Enable Annotation Processing in Editor". Add the - annotation processor by specifying its fully qualified name - org.hibernate.validator.ap.ConstraintValidationProcessor - - - - Any constraint annotation problems will then be marked directly - within the editor: - - - - - - -
-
-
- -
- Known issues - - The following known issues exist as of May 2010: - - - - HV-308: - Additional validators registered for a constraint using - XML are not evaluated by the annotation processor. - - - - Sometimes custom constraints can't be properly - evaluated when using the processor within Eclipse. Cleaning - the project can help in these situations. This seems to be an issue - with the Eclipse JSR 269 API implementation, but further investigation - is required here. - - - - When using the processor within Eclipse, the check of dynamic - default group sequence definitions doesn't work. After further - investigation, it seems to be an issue with the Eclipse JSR 269 API - implementation. - - -
-
diff --git a/documentation/src/main/docbook/en-US/modules/bean-constraints.xml b/documentation/src/main/docbook/en-US/modules/bean-constraints.xml deleted file mode 100644 index d3e217bd7a..0000000000 --- a/documentation/src/main/docbook/en-US/modules/bean-constraints.xml +++ /dev/null @@ -1,1266 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Declaring and validating bean constraints - - In this chapter you will learn how to declare (see ) and validate (see ) bean constraints. provides an overview of all built-in - constraints coming with Hibernate Validator. - - If you are interested in applying constraints to method parameters and - return values, refer to . - -
- Declaring bean constraints - - Constraints in Bean Validation are expressed via Java annotations. - In this section you will learn how to enhance an object model with these - annotations. There are the following three types of bean - constraints: - - - - field constraints - - - - property constraints - - - - class constraints - - - - - Not all constraints can be placed on all of these levels. In fact, - none of the default constraints defined by Bean Validation can be placed - at class level. The java.lang.annotation.Target - annotation in the constraint annotation itself determines on which - elements a constraint can be placed. See for more information. - - -
- Field-level constraints - - Constraints can be expressed by annotating a field of a class. - shows a field level configuration - example: - - - Field-level constraints - - package org.hibernate.validator.referenceguide.chapter02.fieldlevel; - -public class Car { - - @NotNull - private String manufacturer; - - @AssertTrue - private boolean isRegistered; - - public Car(String manufacturer, boolean isRegistered) { - this.manufacturer = manufacturer; - this.isRegistered = isRegistered; - } - - //getters and setters... -} - - - When using field-level constraints field access strategy is used - to access the value to be validated. This means the validation engine - directly accesses the instance variable and does not invoke the property - accessor method even if such an accessor exists. - - Constraints can be applied to fields of any access type (public, - private etc.). Constraints on static fields are not supported, - though. - - - When validating byte code enhanced objects property level - constraints should be used, because the byte code enhancing library - won't be able to determine a field access via reflection. - -
- -
- Property-level constraints - - If your model class adheres to the JavaBeans - standard, it is also possible to annotate the properties of a bean class - instead of its fields. uses the - same entity as in , however, - property level constraints are used. - - - Property-level constraints - - package org.hibernate.validator.referenceguide.chapter02.propertylevel; - -public class Car { - - private String manufacturer; - - private boolean isRegistered; - - public Car(String manufacturer, boolean isRegistered) { - this.manufacturer = manufacturer; - this.isRegistered = isRegistered; - } - - @NotNull - public String getManufacturer() { - return manufacturer; - } - - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; - } - - @AssertTrue - public boolean isRegistered() { - return isRegistered; - } - - public void setRegistered(boolean isRegistered) { - this.isRegistered = isRegistered; - } -} - - - - The property's getter method has to be annotated, not its - setter. That way also read-only properties can be constrained which - have no setter method. - - - When using property level constraints property access strategy is - used to access the value to be validated, i.e. the validation engine - accesses the state via the property accessor method. - - - It is recommended to stick either to field - or property annotations within one class. It is - not recommended to annotate a field and the - accompanying getter method as this would cause the field to be - validated twice. - -
- -
- Class-level - constraints - - Last but not least, a constraint can also be placed on the class - level. In this case not a single property is subject of the validation - but the complete object. Class-level constraints are useful if the - validation depends on a correlation between several properties of an - object. - - The Car class in has the two attributes - seatCount and passengers and it - should be ensured that the list of passengers has not more entries than - seats are available. For that purpose the - @ValidPassengerCount constraint is added on the - class level. The validator of that constraint has access to the complete - Car object, allowing to compare the numbers of - seats and passengers. - - Refer to to - learn in detail how to implement this custom constraint. - - - Class-level constraint - - package org.hibernate.validator.referenceguide.chapter02.classlevel; - -@ValidPassengerCount -public class Car { - - private int seatCount; - - private List<Person> passengers; - - //... -} - -
- -
- Constraint inheritance - - When a class implements an interface or extends another class, all - constraint annotations declared on the supertype apply in the same - manner as the constraints specified on the class itself. To make things - clearer let's have a look at the following example: - - - Constraint inheritance - - package org.hibernate.validator.referenceguide.chapter02.inheritance; - -public class Car { - - private String manufacturer; - - @NotNull - public String getManufacturer() { - return manufacturer; - } - - //... -} - - package org.hibernate.validator.referenceguide.chapter02.inheritance; - -public class RentalCar extends Car { - - private String rentalStation; - - @NotNull - public String getRentalStation() { - return rentalStation; - } - - //... -} - - - Here the class RentalCar is a subclass of - Car and adds the property - rentalStation. If an instance of - RentalCar is validated, not only the - @NotNull constraint on - rentalStation is evaluated, but also the constraint - on manufacturer from the parent class. - - The same would be true, if Car was not a - superclass but an interface implemented by - RentalCar. - - Constraint annotations are aggregated if methods are overridden. - So if RentalCar overrode the - getManufacturer() method from - Car, any constraints annotated at the overriding - method would be evaluated in addition to the - @NotNull constraint from the superclass. -
- -
- Object graphs - - The Bean Validation API does not only allow to validate single - class instances but also complete object graphs (cascaded validation). - To do so, just annotate a field or property representing a reference to - another object with @Valid as demonstrated in - . - - - Cascaded validation - - package org.hibernate.validator.referenceguide.chapter02.objectgraph; - -public class Car { - - @NotNull - @Valid - private Person driver; - - //... -} - - package org.hibernate.validator.referenceguide.chapter02.objectgraph; - -public class Person { - - @NotNull - private String name; - - //... -} - - - If an instance of Car is validated, the - referenced Person object will be validated as - well, as the driver field is annotated with - @Valid. Therefore the validation of a - Car will fail if the name - field of the referenced Person instance is - null. - - The validation of object graphs is recursive, i.e. if a reference - marked for cascaded validation points to an object which itself has - properties annotated with @Valid, these - references will be followed up by the validation engine as well. The - validation engine will ensure that no infinite loops occur during - cascaded validation, for example if two objects hold references to each - other. - - Note that null values are getting ignored - during cascaded validation. - - Object graph validation also works for collection-typed fields. - That means any attributes that - - - - are arrays - - - - implement java.lang.Iterable - (especially Collection, - List and Set) - - - - implement java.util.Map - - - - can be annotated with @Valid, which will - cause each contained element to be validated, when the parent object is - validated. - - - Cascaded validation of a collection - - package org.hibernate.validator.referenceguide.chapter02.objectgraph.list; - -public class Car { - - @NotNull - @Valid - private List<Person> passengers = new ArrayList<Person>(); - - //... -} - - - So when validating an instance of the Car - class shown in , a - ConstraintViolation will be created, if any of - the Person objects contained in the - passengers list has a null - name. -
-
- -
- Validating bean constraints - - The Validator interface is the most important - object in Bean Validation. The next section shows how to obtain an - Validator instance. Afterwards you'll learn how to - use the different methods of the Validator - interface. - -
- Obtaining a <classname>Validator</classname> instance - - The first step towards validating an entity instance is to get - hold of a Validator instance. The road to this - instance leads via the Validation class and a - ValidatorFactory. The easiest way is to use the - static method - Validation#buildDefaultValidatorFactory(): - - - Validation#buildDefaultValidatorFactory() - - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); -Validator validator = factory.getValidator(); - - - This bootstraps a validator in the default configuration. Refer to - to learn more about the - different bootstrapping methods and how to obtain a specifically - configured Validator instance. -
- -
- Validator methods - - The Validator interface contains three - methods that can be used to either validate entire entities or just - single properties of the entity. - - All three methods return a - Set<ConstraintViolation>. The set is empty, - if the validation succeeds. Otherwise a - ConstraintViolation instance is added for each - violated constraint. - - All the validation methods have a var-args parameter which can be - used to specify, which validation groups shall be considered when - performing the validation. If the parameter is not specified the default - validation group - (javax.validation.groups.Default) is used. The - topic of validation groups is discussed in detail in . - -
- <methodname>Validator#validate()</methodname> - - Use the validate() method to perform - validation of all constraints of a given bean. shows the validation of an - instance of the Car class from which fails to satisfy the - @NotNull constraint on the - manufacturer property. The validation call - therefore returns one ConstraintViolation - object. - - - Using <methodname>Validator#validate()</methodname> - - Car car = new Car( null, true ); - -Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car ); - -assertEquals( 1, constraintViolations.size() ); -assertEquals( "may not be null", constraintViolations.iterator().next().getMessage() ); - -
- -
- <methodname>Validator#validateProperty()</methodname> - - With help of the validateProperty() you - can validate a single named property of a given object. The property - name is the JavaBeans property name. - - - Using - <methodname>Validator#validateProperty()</methodname> - - Car car = new Car( null, true ); - -Set<ConstraintViolation<Car>> constraintViolations = validator.validateProperty( - car, - "manufacturer" -); - -assertEquals( 1, constraintViolations.size() ); -assertEquals( "may not be null", constraintViolations.iterator().next().getMessage() ); - -
- -
- <methodname>Validator#validateValue()</methodname> - - By using the validateValue() method you - can check whether a single property of a given class can be validated - successfully, if the property had the specified value: - - - Using - <methodname>Validator#validateValue()</methodname> - - Set<ConstraintViolation<Car>> constraintViolations = validator.validateValue( - Car.class, - "manufacturer", - null -); - -assertEquals( 1, constraintViolations.size() ); -assertEquals( "may not be null", constraintViolations.iterator().next().getMessage() ); - - - - @Valid is not honored by - validateProperty() or - validateValue(). - - - Validator#validateProperty() is for - example used in the integration of Bean Validation into JSF 2 (see - ) to perform a validation - of the values entered into a form before they are propagated to the - model. -
-
- -
- <classname>ConstraintViolation</classname> methods - - Now it is time to have a closer look at what a - ConstraintViolation is. Using the different - methods of ConstraintViolation a lot of useful - information about the cause of the validation failure can be determined. - gives an overview of these - methods. The values in the "Example" column refer to . - - - The various <classname>ConstraintViolation</classname> - methods - - - - - Method - - Usage - - Example - - - - - - getMessage() - - The interpolated error message - - "may not be null" - - - - getMessageTemplate() - - The non-interpolated error message - - "{... NotNull.message}" - - - - getRootBean() - - The root bean being validated - - car - - - - getRootBeanClass() - - The class of the root bean being validated - - Car.class - - - - getLeafBean() - - If a bean constraint, the bean instance the constraint is - applied on; If a property constraint, the bean instance hosting - the property the constraint is applied on - - car - - - - getPropertyPath() - - The property path to the validated value from root - bean - - contains one node with kind - PROPERTY and name "manufacturer" - - - - getInvalidValue() - - The value failing to pass the constraint - - null - - - - getConstraintDescriptor() - - Constraint metadata reported to fail - - descriptor for @NotNull - - - -
-
-
- -
- Built-in constraints - - Hibernate Validator comprises a basic set of commonly used - constraints. These are foremost the constraints defined by the Bean - Validation specification (see ). - Additionally, Hibernate Validator provides useful custom constraints (see - and ). - -
- Bean Validation constraints - - shows purpose and - supported data types of all constraints specified in the Bean Validation - API. All these constraints apply to the field/property level, there are - no class-level constraints defined in the Bean Validation specification. - If you are using the Hibernate object-relational mapper, some of the - constraints are taken into account when creating the DDL for your model - (see column "Hibernate metadata impact"). - - - Hibernate Validator allows some constraints to be applied to - more data types than required by the Bean Validation specification - (e.g. @Max can be applied to - Strings). Relying on this feature can impact - portability of your application between Bean Validation - providers. - - - - Bean Validation constraints - - - - - - - - - - - - - Annotation - - Supported data types - - Use - - Hibernate metadata impact - - - - - - @AssertFalse - - Boolean, - boolean - - Checks that the annotated element is - false - - None - - - - @AssertTrue - - Boolean, - boolean - - Checks that the annotated element is - true - - None - - - - @DecimalMax(value=, - inclusive=) - - BigDecimal, - BigInteger, - CharSequence, - byte, short, - int, long and the - respective wrappers of the primitive types; Additionally - supported by HV: any sub-type of - Number - - Checks whether the annotated value is less than the - specified maximum, when inclusive=false. - Otherwise whether the value is less than or equal to the - specified maximum. The parameter value is - the string representation of the max value according to the - BigDecimal string representation. - - None - - - - @DecimalMin(value=, - inclusive=) - - BigDecimal, - BigInteger, - CharSequence, - byte, short, - int, long and the - respective wrappers of the primitive types; Additionally - supported by HV: any sub-type of - Number - - Checks whether the annotated value is larger than the - specified minimum, when inclusive=false. - Otherwise whether the value is larger than or equal to the - specified minimum. The parameter value is - the string representation of the min value according to the - BigDecimal string representation. - - None - - - - @Digits(integer=, - fraction=) - - BigDecimal, - BigInteger, - CharSequence, - byte, short, - int, long and the - respective wrappers of the primitive types; Additionally - supported by HV: any sub-type of - Number - - Checks whether the annoted value is a number having up to - integer digits and - fraction fractional digits - - Defines column precision and scale - - - - @Future - - java.util.Date, - java.util.Calendar; Additionally - supported by HV, if the Joda Time - date/time API is on the class path: any implementations of - ReadablePartial and - ReadableInstant - - Checks whether the annotated date is in the - future - - None - - - - @Max(value=) - - BigDecimal, - BigInteger, byte, - short, int, - long and the respective wrappers of the - primitive types; Additionally supported by HV: any sub-type of - CharSequence (the numeric value - represented by the character sequence is evaluated), any - sub-type of Number - - Checks whether the annotated value is less than or equal - to the specified maximum - - Adds a check constraint on the column - - - - @Min(value=) - - BigDecimal, - BigInteger, byte, - short, int, - long and the respective wrappers of the - primitive types; Additionally supported by HV: any sub-type of - CharSequence (the numeric value - represented by the char sequence is evaluated), any sub-type of - Number - - Checks whether the annotated value is higher than or - equal to the specified minimum - - Adds a check constraint on the column - - - - @NotNull - - Any type - - Checks that the annotated value is not - null. - - Column(s) are not nullable - - - - @Null - - Any type - - Checks that the annotated value is - null - - None - - - - @Past - - java.util.Date, - java.util.Calendar; Additionally - supported by HV, if the Joda Time - date/time API is on the class path: any implementations of - ReadablePartial and - ReadableInstant - - Checks whether the annotated date is in the past - - None - - - - @Pattern(regex=, - flag=) - - CharSequence - - Checks if the annotated string matches the regular - expression regex considering the given - flag match - - None - - - - @Size(min=, max=) - - CharSequence, - Collection, Map - and arrays - - Checks if the annotated element's size is between min and - max (inclusive) - - Column length will be set to - max - - - - @Valid - - Any non-primitive type - - Performs validation recursively on the associated object. - If the object is a collection or an array, the elements are - validated recursively. If the object is a map, the value - elements are validated recursively. - - None - - - -
- - - On top of the parameters indicated in each constraint has the parameters - message, groups and - payload. This is a requirement of the Bean - Validation specification. - -
- -
- Additional constraints - - In addition to the constraints defined by the Bean Validation API - Hibernate Validator provides several useful custom constraints which are - listed in . With one exception - also these constraints apply to the field/property level, only - @ScriptAssert is a class-level constraint. - - - Custom constraints - - - - - - - - - - - - - Annotation - - Supported data types - - Use - - Hibernate metadata impact - - - - - - @CreditCardNumber - - CharSequence - - Checks that the annotated character sequence passes the - Luhn checksum test. Note, this validation aims to check for user - mistakes, not credit card validity! See also Anatomy of Credit - Card Numbers. - - None - - - - @EAN - - CharSequence - - Checks that the annotated character sequence is a valid - EAN - barcode. type determines the type of - barcode. The default is EAN-13. - - None - - - - @Email - - CharSequence - - Checks whether the specified character sequence is a - valid email address. The optional parameters - regexp and flags - allow to specify an additional regular expression (including - regular expression flags) which the email must match. - - None - - - - @Length(min=, max=) - - CharSequence - - Validates that the annotated character sequence is - between min and - max included - - Column length will be set to - max - - - - @LuhnCheck(startIndex=, - endIndex=, - checkDigitIndex=, - ignoreNonDigitCharacters=) - - CharSequence - - Checks that the digits within the annotated character - sequence pass the Luhn checksum algorithm (see also Luhn - algorithm). startIndex and - endIndex allow to only run the algorithm on - the specified sub-string. checkDigitIndex - allows to use an arbitrary digit within the character sequence - as the check digit. If not specified it is assumed that the - check digit is part of the specified range. Last but not least, - ignoreNonDigitCharacters allows to ignore - non digit characters. - - None - - - - @Mod10Check(multiplier=, - weight=, startIndex=, - endIndex=, - checkDigitIndex=, - ignoreNonDigitCharacters=) - - CharSequence - - Checks that the digits within the annotated character - sequence pass the generic mod 10 checksum algorithm. - multiplier determines the multiplier for - odd numbers (defaults to 3), weight the - weight for even numbers (defaults to 1). - startIndex and - endIndex allow to only run the algorithm on - the specified sub-string. checkDigitIndex - allows to use an arbitrary digit within the character sequence - as the check digit. If not specified it is assumed that the - check digit is part of the specified range. Last but not least, - ignoreNonDigitCharacters allows to ignore - non digit characters. - - None - - - - @Mod11Check(threshold=, - startIndex=, endIndex=, - checkDigitIndex=, - ignoreNonDigitCharacters=, - treatCheck10As=, - treatCheck11As=) - - CharSequence - - Checks that the digits within the annotated character - sequence pass the mod 11 checksum algorithm. - threshold specifies the threshold for the - mod11 multiplier growth; if no value is specified the multiplier - will grow indefinitely. treatCheck10As - and treatCheck11As specify the check - digits to be used when the mod 11 checksum equals 10 or 11, - respectively. Default to X and 0, respectively. - startIndex, endIndex - acheckDigitIndex and - ignoreNonDigitCharacters carry the same - semantics as in @Mod10Check. - - None - - - - @NotBlank - - CharSequence - - Checks that the annotated character sequence is not null - and the trimmed length is greater than 0. The difference to - @NotEmpty is that this constraint can - only be applied on strings and that trailing whitespaces are - ignored. - - None - - - - @NotEmpty - - CharSequence, - Collection, Map - and arrays - - Checks whether the annotated element is not - null nor empty - - None - - - - @Range(min=, max=) - - BigDecimal, - BigInteger, - CharSequence, - byte, short, - int, long and the - respective wrappers of the primitive types - - Checks whether the annotated value lies between - (inclusive) the specified minimum and maximum - - None - - - - @SafeHtml(whitelistType=, - additionalTags=, - additionalTagsWithAttributes=) - - CharSequence - - Checks whether the annotated value contains - potentially malicious fragments such as - <script/>. In order to use this constraint, - the jsoup library must be - part of the class path. With the - whitelistType attribute a predefined - whitelist type can be chosen which can be refined via - additionalTags or - additionalTagsWithAttributes. The - former allows to add tags without any attributes, whereas the - latter allows to specify tags and optionally allowed attributes - using the annotation - @SafeHtml.Tag. - - None - - - - @ScriptAssert(lang=, - script=, alias=) - - Any type - - Checks whether the given script can successfully be - evaluated against the annotated element. In order to use this - constraint, an implementation of the Java Scripting API as - defined by JSR 223 ("Scripting for the - JavaTM Platform") must part of the - class path. The expressions to be evaluated can be written in - any scripting or expression language, for which a JSR 223 - compatible engine can be found in the class path. - - None - - - - @URL(protocol=, host=, - port= regexp=, - flags=) - - CharSequence - - Checks if the annotated character sequence is a valid URL - according to RFC2396. If any of the optional parameters - protocol, host or - port are specified, the corresponding URL - fragments must match the specified values. The optional - parameters regexp and - flags allow to specify an additional - regular expression (including regular expression flags) which - the URL must match. - - None - - - -
- -
- Country specific constraints - - Hibernate Validator offers also some country specific - constraints, e.g. for the validation of social security numbers. - If you have to implement a country specific constraint, - consider making it a contribution to Hibernate Validator! - - - - Custom country specific constraints - - - - - - - - - - - - - - - Annotation - - Supported data types - - Use - - Country - - Hibernate metadata impact - - - - - - @CNPJ - - CharSequence - - Checks that the annotated character sequence represents - a Brazilian corporate tax payer registry number (Cadastro de - Pessoa Juríeddica) - - Brazil - - None - - - - @CPF - - CharSequence - - Checks that the annotated character sequence represents - a Brazilian individual taxpayer registry number (Cadastro de - Pessoa Fídsica) - - Brazil - - None - - - - @TituloEleitoral - - CharSequence - - Checks that the annotated character sequence represents - a Brazilian voter ID card number (Título - Eleitoral) - - Brazil - - None - - - -
- - - In some cases neither the Bean Validation constraints nor the - custom constraints provided by Hibernate Validator will fulfill your - requirements. In this case you can easily write your own constraint. - You can find more information in . - -
-
-
-
diff --git a/documentation/src/main/docbook/en-US/modules/bootstrapping.xml b/documentation/src/main/docbook/en-US/modules/bootstrapping.xml deleted file mode 100644 index bc32457ec8..0000000000 --- a/documentation/src/main/docbook/en-US/modules/bootstrapping.xml +++ /dev/null @@ -1,496 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Bootstrapping - - In you already saw one - way for creating a Validator instance - via - Validation#buildDefaultValidatorFactory(). In this - chapter you will learn how to use the other methods in - javax.validation.Validation in order to bootstrap - specifically configured validators. - -
- Retrieving <classname>ValidatorFactory</classname> and - <classname>Validator</classname> - - You obtain a Validator by retrieving a - ValidatorFactory via one of the static methods on - javax.validation.Validation and calling - getValidator() on the factory instance. - - shows how - to obtain a validator from the default validator factory: - - - Bootstrapping default <classname>ValidatorFactory</classname> and - <classname>Validator</classname> - - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); -Validator validator = factory.getValidator(); - - - - The generated ValidatorFactory and - Validator instances are thread-safe and can be - cached. As Hibernate Validator uses the factory as context for caching - constraint metadata it is recommended to work with one factory instance - within an application. - - - Bean Validation supports working with several providers such as - Hibernate Validator within one application. If more than one provider is - present on the classpath, it is not guaranteed which one is chosen when - creating a factory via - buildDefaultValidatorFactory(). - - In this case you can explicitly specify the provider to use via - Validation#byProvider(), passing the provider's - ValidationProvider class as shown in . - - - Bootstrapping <classname>ValidatorFactory</classname> and - <classname>Validator</classname> using a specific provider - - ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class ) - .configure() - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - - - Note that the configuration object returned by - configure() allows to specifically customize the - factory before calling buildValidatorFactory(). - The available options are discussed later in this chapter. - - Similarly you can retrieve the default validator factory for - configuration which is demonstrated in . - - - Retrieving the default <classname>ValidatorFactory</classname> - for configuration - - ValidatorFactory validatorFactory = Validation.byDefaultProvider() - .configure() - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - - - - If a ValidatorFactory instance is no longer - in use, it should be disposed by calling - ValidatorFactory#close(). This will free any - resources possibly allocated by the factory. - - -
- <classname>ValidationProviderResolver</classname> - - By default, available Bean Validation providers are discovered - using the Java - Service Provider mechanism. - - For that purpose, each provider includes the file - META-INF/services/javax.validation.spi.ValidationProvider, - containing the fully qualified classname of its - ValidationProvider implementation. In the case of - Hibernate Validator this is - org.hibernate.validator.HibernateValidator. - - Depending on your environment and its classloading specifics, - provider discovery via the Java's service loader mechanism might not - work. In this case you can plug in a custom - ValidationProviderResolver implementation which - performs the provider retrieval. An example is OSGi, where you could - implement a provider resolver which uses OSGi services for provider - discovery. - - To use a custom provider resolver pass it via - providerResolver() as shown shown in . - - - Using a custom - <classname>ValidationProviderResolver</classname> - - package org.hibernate.validator.referenceguide.chapter08; - -public class OsgiServiceDiscoverer implements ValidationProviderResolver { - - @Override - public List<ValidationProvider<?>> getValidationProviders() { - //... - } -} - - ValidatorFactory validatorFactory = Validation.byDefaultProvider() - .providerResolver( new OsgiServiceDiscoverer() ) - .configure() - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - -
-
- -
- Configuring a <classname>ValidatorFactory</classname> - - By default validator factories retrieved from - Validation and any validators they create are - configured as per the XML descriptor - META-INF/validation.xml (see ), if present. - - If you want to disable the XML based configuration, you can do so by - invoking - Configuration#ignoreXmlConfiguration(). - - The different values of the XML configuration can be accessed via - Configuration#getBootstrapConfiguration(). This - can for instance be helpful if you want to integrate Bean Validation into - a managed environment and want to create managed instances of the objects - configured via XML. - - Using the fluent configuration API, you can override one or more of - the settings when bootstrapping the factory. The following sections show - how to make use of the different options. Note that the - Configuration class exposes the default - implementations of the different extension points which can be useful if - you want to use these as delegates for your custom implementations. - -
- <classname>MessageInterpolator</classname> - - Message interpolators are used by the validation engine to create - user readable error messages from constraint message descriptors. - - In case the default message interpolation algorithm described in - is not sufficient for - your needs, you can pass in your own implementation of the - MessageInterpolator interface via - Configuration#messageInterpolator() as shown in - . - - - Using a custom - <classname>MessageInterpolator</classname> - - package org.hibernate.validator.referenceguide.chapter08; - -public class MyMessageInterpolator implements MessageInterpolator { - - @Override - public String interpolate(String messageTemplate, Context context) { - //... - } - - @Override - public String interpolate(String messageTemplate, Context context, Locale locale) { - //... - } -} - - ValidatorFactory validatorFactory = Validation.byDefaultProvider() - .configure() - .messageInterpolator( new MyMessageInterpolator() ) - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - -
- -
- <classname>TraversableResolver</classname> - - In some cases the validation engine should not access the state of - a bean property. The most obvious example for that is a lazily loaded - property or association of a JPA entity. Validating this lazy property - or association would mean that its state would have to be accessed, - triggering a load from the database. - - Which properties can be accessed and which ones not is controlled - by querying the TraversableResolver interface. - shows how to - use a custom traversable resolver implementation. - - - Using a custom - <classname>TraversableResolver</classname> - - package org.hibernate.validator.referenceguide.chapter08; - -public class MyTraversableResolver implements TraversableResolver { - - @Override - public boolean isReachable( - Object traversableObject, - Node traversableProperty, - Class<?> rootBeanType, - Path pathToTraversableObject, - ElementType elementType) { - //... - } - - @Override - public boolean isCascadable( - Object traversableObject, - Node traversableProperty, - Class<?> rootBeanType, - Path pathToTraversableObject, - ElementType elementType) { - //... - } -} - - ValidatorFactory validatorFactory = Validation.byDefaultProvider() - .configure() - .traversableResolver( new MyTraversableResolver() ) - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - - - Hibernate Validator provides two - TraversableResolvers out of the box which will be - enabled automatically depending on your environment. The first is - DefaultTraversableResolver which will always - return true for - isReachable() and - isTraversable(). The second is - JPATraversableResolver which gets enabled when - Hibernate Validator is used in combination with JPA 2. -
- -
- <classname>ConstraintValidatorFactory</classname> - - ConstraintValidatorFactory is the extension - point for customizing how constraint validators are instantiated and - released. - - The default ConstraintValidatorFactory - provided by Hibernate Validator requires a public no-arg constructor to - instantiate ConstraintValidator instances (see - ). Using a custom - ConstraintValidatorFactory offers for example the - possibility to use dependency injection in constraint validator - implementations. - - To configure a custom constraint validator factory call - Configuration#constraintValidatorFactory() (see - . - - - Using a custom - <classname>ConstraintValidatorFactory</classname> - - package org.hibernate.validator.referenceguide.chapter08; - -public class MyConstraintValidatorFactory implements ConstraintValidatorFactory { - - @Override - public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) { - //... - } - - @Override - public void releaseInstance(ConstraintValidator<?, ?> instance) { - //... - } -} - - ValidatorFactory validatorFactory = Validation.byDefaultProvider() - .configure() - .constraintValidatorFactory( new MyConstraintValidatorFactory() ) - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - - - - Any constraint implementations relying on - ConstraintValidatorFactory behaviors specific - to an implementation (dependency injection, no no-arg constructor and - so on) are not considered portable. - - - - ConstraintValidatorFactory - implementations should not cache validator instances as the state of - each instance can be altered in the - initialize() method. - -
- -
- <classname>ParameterNameProvider</classname> - - In case a method or constructor parameter constraint is violated, - the ParameterNameProvider interface is used to - retrieve the parameter's name and make it available to the user via the - constraint violation's property path. - - The default implementation returns parameter names in the form - arg0, arg1 etc., while custom - implementations could e.g. be based on parameter annotations, debug - symbols or a feature for retrieving parameter names at runtime possibly - provided by future Java versions. - - Custom ParameterNameProvider - implementations are used as demonstrated in . - - - Using a custom - <classname>ParameterNameProvider</classname> - - package org.hibernate.validator.referenceguide.chapter08; - -public class MyParameterNameProvider implements ParameterNameProvider { - - @Override - public List<String> getParameterNames(Constructor<?> constructor) { - //... - } - - @Override - public List<String> getParameterNames(Method method) { - //... - } -} - - ValidatorFactory validatorFactory = Validation.byDefaultProvider() - .configure() - .parameterNameProvider( new MyParameterNameProvider() ) - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - - - - Hibernate Validator comes with a custom - ParameterNameProvider implementation based on - the ParaNamer - library which provides several ways for obtaining parameter names at - runtime. Refer to to learn more - about this specific implementation. - -
- -
- Adding mapping streams - - As discussed earlier you can configure the constraints applying - for your Java beans using XML based constraint mappings. - - Besides the mapping files specified in - META-INF/validation.xml you can add further - mappings via Configuration#addMapping() (see - ). Note that the passed - input stream(s) must adhere to the XML schema for constraint mappings - presented in . - - - Adding constraint mapping streams - - InputStream constraintMapping1 = ...; -InputStream constraintMapping2 = ...; -ValidatorFactory validatorFactory = Validation.byDefaultProvider() - .configure() - .addMapping( constraintMapping1 ) - .addMapping( constraintMapping2 ) - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - - - You should close any passed input stream after the validator - factory has been created. -
- -
- Provider-specific settings - - Via the configuration object returned by - Validation#byProvider() provider specific - options can be configured. - - In case of Hibernate Validator this e.g. allows you to enable the - fail fast mode and pass one or more programmatic constraint mappings as - demonstrated in . - - - Setting Hibernate Validator specific options - - ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class ) - .configure() - .failFast( true ) - .addMapping( (ConstraintMapping) null ) - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - - - Alternatively, provider-specific options can be passed via - Configuration#addProperty(). Hibernate - Validator supports enabling the fail fast mode that way, too: - - - Enabling a Hibernate Validator specific option via - <methodname>addProperty()</methodname> - - ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class ) - .configure() - .addProperty( "hibernate.validator.fail_fast", "true" ) - .buildValidatorFactory(); -Validator validator = validatorFactory.getValidator(); - - - Refer to and to learn more about the fail fast - mode and the constraint declaration API. -
-
- -
- Configuring a <classname>Validator</classname> - - When working with a configured validator factory it can occasionally - be required to apply a different configuration to a single - Validator instance. shows how this can be achieved by - calling ValidatorFactory#usingContext(). - - - Configuring a <classname>Validator</classname> via - <methodname>usingContext()</methodname> - - ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); - -Validator validator = validatorFactory.usingContext() - .messageInterpolator( new MyMessageInterpolator() ) - .traversableResolver( new MyTraversableResolver() ) - .getValidator(); - -
-
diff --git a/documentation/src/main/docbook/en-US/modules/custom-constraints.xml b/documentation/src/main/docbook/en-US/modules/custom-constraints.xml deleted file mode 100644 index 003dfb2fcd..0000000000 --- a/documentation/src/main/docbook/en-US/modules/custom-constraints.xml +++ /dev/null @@ -1,864 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Creating custom constraints - - The Bean Validation API defines a whole set of standard constraint - annotations such as @NotNull, - @Size etc. In cases where these buit-in constraints - are not sufficient, you cean easily create custom constraints tailored to - your specific validation requirements. - -
- Creating a simple constraint - - To create a custom constraint, the following three steps are - required: - - - - Create a constraint annotation - - - - Implement a validator - - - - Define a default error message - - - -
- The constraint annotation - - This section shows how to write a constraint annotation which can - be used to ensure that a given string is either completely upper case or - lower case. Later on this constraint will be applied to the - licensePlate field of the - Car class from to ensure, that the field is always - an upper-case string. - - The first thing needed is a way to express the two case modes. - While you could use String constants, a better - approach is using a Java 5 enum for that purpose: - - - Enum <classname>CaseMode</classname> to express upper vs. lower - case - - package org.hibernate.validator.referenceguide.chapter06; - -public enum CaseMode { - UPPER, - LOWER; -} - - - The next step is to define the actual constraint annotation. If - you've never designed an annotation before, this may look a bit scary, - but actually it's not that hard: - - - Defining the <classname>@CheckCase</classname> constraint - annotation - - package org.hibernate.validator.referenceguide.chapter06; - -@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@Constraint(validatedBy = CheckCaseValidator.class) -@Documented -public @interface CheckCase { - - String message() default "{org.hibernate.validator.referenceguide.chapter06.CheckCase." + - "message}"; - - Class<?>[] groups() default { }; - - Class<? extends Payload>[] payload() default { }; - - CaseMode value(); - - @Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE }) - @Retention(RUNTIME) - @Documented - @interface List { - CheckCase[] value(); - } -} - - - An annotation type is defined using the @interface - keyword. All attributes of an annotation type are declared in a - method-like manner. The specification of the Bean Validation API - demands, that any constraint annotation defines - - - - an attribute message that returns the - default key for creating error messages in case the constraint is - violated - - - - an attribute groups that allows the - specification of validation groups, to which this constraint belongs - (see ). This must default to an - empty array of type Class<?>. - - - - an attribute payload that can be used - by clients of the Bean Validation API to assign custom payload - objects to a constraint. This attribute is not used by the API - itself. An example for a custom payload could be the definition of a - severity: - - public class Severity { - public interface Info extends Payload { - } - - public interface Error extends Payload { - } -} - -public class ContactDetails { - @NotNull(message = "Name is mandatory", payload = Severity.Error.class) - private String name; - - @NotNull(message = "Phone number not specified, but not mandatory", - payload = Severity.Info.class) - private String phoneNumber; - - // ... -} - - Now a client can after the validation of a - ContactDetails instance access the severity - of a constraint using - ConstraintViolation.getConstraintDescriptor().getPayload() - and adjust its behaviour depending on the severity. - - - - Besides these three mandatory attributes there is another one, - value, allowing for the required case mode to be - specified. The name value is a special one, which - can be omitted when using the annotation, if it is the only attribute - specified, as e.g. in @CheckCase(CaseMode.UPPER). - - In addition, the constraint annotation is decorated with a couple - of meta annotations: - - - - @Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE - }): Defines the supported target element types for the - constraint. @CheckCase may be used on fields - (element type FIELD), JavaBeans properties as - well as method return values (METHOD) and - method/constructor parameters (PARAMETER). - The element type ANNOTATION_TYPE allows for - the creation of composed constraints (see ) based on - @CheckCase. - - When creating a class-level constraint (see ), the element type - TYPE would have to be used. Constraints - targetting the return value of a constructor need to support the - element type CONSTRUCTOR. Cross-parameter - constraints (see ) which are used to - validate all the parameters of a method or constructor together, - must support METHOD or - CONSTRUCTOR, respectively. - - - - @Retention(RUNTIME): Specifies, that annotations - of this type will be available at runtime by the means of - reflection - - - - @Constraint(validatedBy = - CheckCaseValidator.class): Marks the annotation type as - constraint annotation and specifies the validator to be used to - validate elements annotated with @CheckCase. - If a constraint may be used on several data types, several - validators may be specified, one for each data type. - - - - @Documented: Says, that the use of - @CheckCase will be contained in the JavaDoc - of elements annotated with it - - - - Finally, there is an inner annotation type named - List. This annotation allows to specify several - @CheckCase annotations on the same element, e.g. - with different validation groups and messages. While also another name - could be used, the Bean Validation specification recommends to use the - name List and make the annotation an inner - annotation of the corresponding constraint type. -
- -
- The constraint - validator - - Having defined the annotation, you need to create a constraint - validator, which is able to validate elements with a - @CheckCase annotation. To do so, implement the - interface ConstraintValidator as shown - below: - - - Implementing a constraint validator for the constraint - <classname>@CheckCase</classname> - - package org.hibernate.validator.referenceguide.chapter06; - -public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> { - - private CaseMode caseMode; - - @Override - public void initialize(CheckCase constraintAnnotation) { - this.caseMode = constraintAnnotation.value(); - } - - @Override - public boolean isValid(String object, ConstraintValidatorContext constraintContext) { - if ( object == null ) { - return true; - } - - if ( caseMode == CaseMode.UPPER ) { - return object.equals( object.toUpperCase() ); - } - else { - return object.equals( object.toLowerCase() ); - } - } -} - - - The ConstraintValidator interface defines - two type parameters which are set in the implementation. The first one - specifies the annotation type to be validated - (CheckCase), the second one the type of elements, - which the validator can handle (String). In case - a constraint supports several data types, a - ConstraintValidator for each allowed type has to - be implemented and registered at the constraint annotation as shown - above. - - The implementation of the validator is straightforward. The - initialize() method gives you access to the - attribute values of the validated constraint and allows you to store - them in a field of the validator as shown in the example. - - The isValid() method contains the actual - validation logic. For @CheckCase this is the - check whether a given string is either completely lower case or upper - case, depending on the case mode retrieved in - initialize(). Note that the Bean Validation - specification recommends to consider null values as being - valid. If null is not a valid value for an element, it - should be annotated with @NotNull explicitly. - -
- The <classname>ConstraintValidatorContext</classname> - - relies on the - default error message generation by just returning - true or false from the - isValid() method. Using the passed - ConstraintValidatorContext object it is - possible to either add additional error messages or completely disable - the default error message generation and solely define custom error - messages. The ConstraintValidatorContext API is - modeled as fluent interface and is best demonstrated with an - example: - - - Using <classname>ConstraintValidatorContext</classname> to - define custom error messages - - package org.hibernate.validator.referenceguide.chapter06.constraintvalidatorcontext; - -public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> { - - private CaseMode caseMode; - - @Override - public void initialize(CheckCase constraintAnnotation) { - this.caseMode = constraintAnnotation.value(); - } - - @Override - public boolean isValid(String object, ConstraintValidatorContext constraintContext) { - if ( object == null ) { - return true; - } - - boolean isValid; - if ( caseMode == CaseMode.UPPER ) { - isValid = object.equals( object.toUpperCase() ); - } - else { - isValid = object.equals( object.toLowerCase() ); - } - - if ( !isValid ) { - constraintContext.disableDefaultConstraintViolation(); - constraintContext.buildConstraintViolationWithTemplate( - "{org.hibernate.validator.referenceguide.chapter03." + - "constraintvalidatorcontext.CheckCase.message}" - ) - .addConstraintViolation(); - } - - return isValid; - } -} - - - - shows how you can disable the default error message generation and add - a custom error message using a specified message template. In this - example the use of the - ConstraintValidatorContext results in the same - error message as the default error message generation. - - - It is important to add each configured constraint violation by - calling addConstraintViolation(). Only - after that the new constraint violation will be created. - - - Refer to to - learn how to use the ConstraintValidatorContext - API to control the property path of constraint violations for - class-level constraints. -
-
- -
- The error message - - The last missing building block is an error message which should - be used in case a @CheckCase constraint is - violated. To define this, create a file - ValidationMessages.properties with the following contents - (see also ): - - - Defining a custom error message for the - <classname>CheckCase</classname> constraint - - org.hibernate.validator.referenceguide.chapter06.CheckCase.message=Case mode must be {value}. - - - If a validation error occurs, the validation runtime will use the - default value, that you specified for the message attribute of the - @CheckCase annotation to look up the error - message in this resource bundle. -
- -
- Using the constraint - - You can now use the constraint in the Car - class from the chapter to - specify that the licensePlate field should only - contain upper-case strings: - - - Applying the <classname>@CheckCase</classname> - constraint - - package org.hibernate.validator.referenceguide.chapter06; - -public class Car { - - @NotNull - private String manufacturer; - - @NotNull - @Size(min = 2, max = 14) - @CheckCase(CaseMode.UPPER) - private String licensePlate; - - @Min(2) - private int seatCount; - - public Car ( String manufacturer, String licencePlate, int seatCount ) { - this.manufacturer = manufacturer; - this.licensePlate = licencePlate; - this.seatCount = seatCount; - } - - //getters and setters ... -} - - - Finally, demonstrates - how validating a Car object with an invalid - license plate causes the @CheckCase constraint to - be violated. - - - Validating objects with the @<classname>CheckCase</classname> - constraint - - //invalid license plate -Car car = new Car( "Morris", "dd-ab-123", 4 ); -Set<ConstraintViolation<Car>> constraintViolations = - validator.validate( car ); -assertEquals( 1, constraintViolations.size() ); -assertEquals( - "Case mode must be UPPER.", - constraintViolations.iterator().next().getMessage() -); - -//valid license plate -car = new Car( "Morris", "DD-AB-123", 4 ); - -constraintViolations = validator.validate( car ); - -assertEquals( 0, constraintViolations.size() ); - -
-
- -
- Class-level constraints - - As discussed earlier, constraints can also be applied on the class - level to validate the state of an entire object. Class-level constraints - are defined in the same was as are property constraints. shows constraint - annotation and validator of the - @ValidPassengerCount constraint you already saw in - use in . - - - Implementing a class-level constraint - - package org.hibernate.validator.referenceguide.chapter06.classlevel; - -@Target({ TYPE, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@Constraint(validatedBy = { ValidPassengerCountValidator.class }) -@Documented -public @interface ValidPassengerCount { - - String message() default "{org.hibernate.validator.referenceguide.chapter06.classlevel." + - "ValidPassengerCount.message}"; - - Class<?>[] groups() default { }; - - Class<? extends Payload>[] payload() default { }; -} - - package org.hibernate.validator.referenceguide.chapter06.classlevel; - -public class ValidPassengerCountValidator - implements ConstraintValidator<ValidPassengerCount, Car> { - - @Override - public void initialize(ValidPassengerCount constraintAnnotation) { - } - - @Override - public boolean isValid(Car car, ConstraintValidatorContext context) { - if ( car == null ) { - return true; - } - - return car.getPassengers().size() <= car.getSeatCount(); - } -} - - - As the example demonstrates, you need to use the element type - TYPE in the @Target - annotation. This allows the constraint to be put on type definitions. The - validator of the constraint in the example receives a - Car in the isValid() - method and can access the complete object state to decide whether the - given instance is valid or not. - -
- Custom property paths - - By default the constraint violation for a class-level constraint - is reported on the level of the annotated type, e.g. - Car. - - In some cases it is preferable though that the violation's - property path refers to one of the involved properties. For instance you - might want to report the @ValidPassengerCount - constraint against the passengers property instead - of the Car bean. - - shows how this can be done - by using the constraint validator context passed to - isValid() to build a custom constraint - violation with a property node for the property - passengers. Note that you also could add several - property nodes, pointing to a sub-entity of the validated bean. - - - Adding a new <classname>ConstraintViolation</classname> with - custom property path - - package org.hibernate.validator.referenceguide.chapter06.custompath; - -public class ValidPassengerCountValidator - implements ConstraintValidator<ValidPassengerCount, Car> { - - @Override - public void initialize(ValidPassengerCount constraintAnnotation) { - } - - @Override - public boolean isValid(Car car, ConstraintValidatorContext constraintValidatorContext) { - if ( car == null ) { - return true; - } - - boolean isValid = car.getPassengers().size() <= car.getSeatCount(); - - if ( !isValid ) { - constraintValidatorContext.disableDefaultConstraintViolation(); - constraintValidatorContext - .buildConstraintViolationWithTemplate( "{my.custom.template}" ) - .addPropertyNode( "passengers" ).addConstraintViolation(); - } - - return isValid; - } -} - -
-
- -
- Cross-parameter constraints - - Bean Validation distinguishes between two different kinds of - constraints. - - Generic constraints (which have been discussed so far) apply to the - annotated element, e.g. a type, field, method parameter or return value - etc. Cross-parameter constraints, in contrast, apply to the array of - parameters of a method or constructor and can be used to express - validation logic which depends on several parameter values. - - In order to define a cross-parameter constraint, its validator class - must be annotated with - @SupportedValidationTarget(ValidationTarget.PARAMETERS). - The type parameter T from the - ConstraintValidator interface must resolve to - either Object or Object[] in - order to receive the array of method/constructor arguments in the - isValid() method. - - The following example shows the definition of a cross-parameter - constraint which can be used to check that two Date - parameters of a method are in the correct order: - - - Cross-parameter constraint - - package org.hibernate.validator.referenceguide.chapter06.crossparameter; - -@Constraint(validatedBy = ConsistentDateParameterValidator.class) -@Target({ METHOD, CONSTRUCTOR, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@Documented -public @interface ConsistentDateParameters { - - String message() default "{org.hibernate.validator.referenceguide.chapter06." + - "crossparameter.ConsistentDateParameters.message}"; - - Class<?>[] groups() default { }; - - Class<? extends Payload>[] payload() default { }; -} - - - The definition of a cross-parameter constraint isn't any different - from defining a generic constraint, i.e. it must specify the members - message(), groups() and - payload() and be annotated with - @Constraint. This meta annotation also specifies - the corresponding validator, which is shown in . Note that besides the - element types METHOD and - CONSTRUCTOR also - ANNOTATION_TYPE is specified as target of the - annotation, in order to enable the creation of composed constraints based - on @ConsistentDateParameters (see ). - - - Cross-parameter constraints are specified directly on the - declaration of a method or constructor, which is also the case for - return value constraints. In order to improve code readability, it is - therefore recommended to chose constraint names - such as - @ConsistentDateParameters - which make the - constraint target apparent. - - - - Generic and cross-parameter constraint - - package org.hibernate.validator.referenceguide.chapter06.crossparameter; - -@SupportedValidationTarget(ValidationTarget.PARAMETERS) -public class ConsistentDateParameterValidator implements - ConstraintValidator<ConsistentDateParameters, Object[]> { - - @Override - public void initialize(ConsistentDateParameters constraintAnnotation) { - } - - @Override - public boolean isValid(Object[] value, ConstraintValidatorContext context) { - if ( value.length != 2 ) { - throw new IllegalArgumentException( "Illegal method signature" ); - } - - //leave null-checking to @NotNull on individual parameters - if ( value[0] == null || value[1] == null ) { - return true; - } - - if ( !( value[0] instanceof Date ) || !( value[1] instanceof Date ) ) { - throw new IllegalArgumentException( - "Illegal method signature, expected two " + - "parameters of type Date." - ); - } - - return ( (Date) value[0] ).before( (Date) value[1] ); - } -} - - - As discussed above, the validation target - PARAMETERS must be configured for a cross-parameter - validator by using the @SupportedValidationTarget - annotation. Since a cross-parameter constraint could be applied to any - method or constructor, it is considered a best practice to check for the - expected number and types of parameters in the validator - implementation. - - As with generic constraints, null parameters - should be considered valid and @NotNull on the - individual parameters should be used to make sure that parameters are not - null. - - - Similar to class-level constraints, you can create custom - constraint violations on single parameters instead of all parameters - when validating a cross-parameter constraint. Just obtain a node builder - from the ConstraintValidatorContext passed to - isValid() and add a parameter node by calling - addParameterNode(). In the example you could - use this to create a constraint violation on the end date parameter of - the validated method. - - - In rare situations a constraint is both, generic and - cross-parameter. This is the case if a constraint has a validator class - which is annotated with - @SupportedValidationTarget({ValidationTarget.PARAMETERS, - ValidationTarget.ANNOTATED_ELEMENT}) or if it has a generic and a - cross-parameter validator class. - - When declaring such a constraint on a method which has parameters - and also a return value, the intended constraint target can't be - determined. Constraints which are generic and cross-parameter at the same - time, must therefore define a member - validationAppliesTo() which allows the constraint - user to specify the constraint's target as shown in . - - - Generic and cross-parameter constraint - - package org.hibernate.validator.referenceguide.chapter06.crossparameter; - -@Constraint(validatedBy = { - ScriptAssertObjectValidator.class, - ScriptAssertParametersValidator.class -}) -@Target({ TYPE, FIELD, PARAMETER, METHOD, CONSTRUCTOR, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@Documented -public @interface ScriptAssert { - - String message() default "{org.hibernate.validator.referenceguide.chapter06." + - "crossparameter.ScriptAssert.message}"; - - Class<?>[] groups() default { }; - - Class<? extends Payload>[] payload() default { }; - - String script(); - - ConstraintTarget validationAppliesTo() default ConstraintTarget.IMPLICIT; -} - - - The @ScriptAssert constraint has two - validators (not shown), a generic and a cross-parameter one and thus - defines the member validationAppliesTo(). The - default value IMPLICIT allows to derive the target - automatically in situations where this is possible (e.g. if the constraint - is declared on a field or on a method which has parameters but no return - value). - - If the target can not be determined implicitly, it must be set by - the user to either PARAMETERS or - RETURN_VALUE as shown in . - - - Specifying the target for a generic and cross-parameter - constraint - - @ScriptAssert(script = "arg1.size() <= arg0", validationAppliesTo = ConstraintTarget.PARAMETERS) -public Car buildCar(int seatCount, List<Passenger> passengers) { - //... -} - -
- -
- Constraint composition - - Looking at the licensePlate field of the - Car class in , you see three constraint - annotations already. In complexer scenarios, where even more constraints - could be applied to one element, this might become a bit confusing easily. - Furthermore, if there was a licensePlate field in - another class, you would have to copy all constraint declarations to the - other class as well, violating the DRY principle. - - You can address this kind of problem by creating higher level - constraints, composed from several basic constraints. shows a composed constraint - annotation which comprises the constraints - @NotNull, @Size and - @CheckCase: - - - Creating a composing constraint - <classname>@ValidLicensePlate</classname> - - package org.hibernate.validator.referenceguide.chapter06.constraintcomposition; - -@NotNull -@Size(min = 2, max = 14) -@CheckCase(CaseMode.UPPER) -@Target({ METHOD, FIELD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@Constraint(validatedBy = { }) -@Documented -public @interface ValidLicensePlate { - - String message() default "{org.hibernate.validator.referenceguide.chapter06." + - "constraintcomposition.ValidLicensePlate.message}"; - - Class<?>[] groups() default { }; - - Class<? extends Payload>[] payload() default { }; -} - - - To create a composed constraint, simply annotate the constraint - declaration with its comprising constraints. If the composed constraint - itself requires a validator, this validator is to be specified within the - @Constraint annotation. For composed constraints - which don't need an additional validator such as - @ValidLicensePlate, just set - validatedBy() to an empty array. - - Using the new composed constraint at the - licensePlate field is fully equivalent to the - previous version, where the three constraints were declared directly at - the field itself: - - - Application of composing constraint - <classname>ValidLicensePlate</classname> - - package org.hibernate.validator.referenceguide.chapter06.constraintcomposition; - -public class Car { - - @ValidLicensePlate - private String licensePlate; - - //... -} - - - The set of ConstraintViolations retrieved - when validating a Car instance will contain an - entry for each violated composing constraint of the - @ValidLicensePlate constraint. If you rather prefer - a single ConstraintViolation in case any of the - composing constraints is violated, the - @ReportAsSingleViolation meta constraint can be - used as follows: - - - Using <classname>@ReportAsSingleViolation</classname> - - //... -@ReportAsSingleViolation -public @interface ValidLicensePlate { - - String message() default "{org.hibernate.validator.referenceguide.chapter06." + - "constraintcomposition.ValidLicensePlate.message}"; - - Class<?>[] groups() default { }; - - Class<? extends Payload>[] payload() default { }; -} - -
-
diff --git a/documentation/src/main/docbook/en-US/modules/custom-options.xml b/documentation/src/main/docbook/en-US/modules/custom-options.xml deleted file mode 100644 index d320464a6c..0000000000 --- a/documentation/src/main/docbook/en-US/modules/custom-options.xml +++ /dev/null @@ -1,701 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Hibernate Validator Specifics - - In this chapter you will learn how to make use of several features - provided by Hibernate Validator in addition to the functionality defined by - the Bean Validation specification. This includes the fail fast mode, the API - for programmatic constraint configuration and the boolean composition of - constraints. - - - Using the features described in the following sections may result in - application code which is not portable between Bean Validation - providers. - - -
- Public API - - Let's start, however, with a look at the public API of Hibernate - Validator. lists all packages - belonging to this API and describes their purpose. Note that when a - package is part of the public this is not necessarily true for its - sub-packages. - - - Hibernate Validator public API - - - - - Packages - - Description - - - - - - org.hibernate.validator - - Classes used by the Bean Validation bootstrap mechanism - (eg. validation provider, configuration class); For more details - see . - - - - org.hibernate.validator.cfg, - org.hibernate.validator.cfg.context, - org.hibernate.validator.cfg.defs - - Hibernate Validator's fluent API for constraint - declaration; In org.hibernate.validator.cfg you - will find the ConstraintMapping interface - and in org.hibernate.validator.cfg.defs all - constraint definitions. Refer to for the details. - - - - org.hibernate.validator.constraints, - org.hibernate.validator.constraints.br - - Some useful custom constraints provided by Hibernate - Validator in addition to the built-in constraints defined by the - Bean Validation specification; The constraints are described in - detail in . - - - - org.hibernate.validator.constraintvalidation - - Extended constraint validator context which allows to set - custom attributes for message interpolation. describes - how to make use of that feature. - - - - org.hibernate.validator.group, - org.hibernate.validator.spi.group - - The group sequence provider feature which allows you to - define dynamic default group sequences in function of the - validated object state; The specifics can be found in . - - - - org.hibernate.validator.messageinterpolation, - org.hibernate.validator.resourceloading, - org.hibernate.validator.spi.resourceloading - - Classes related to constraint message interpolation; The - first package contains Hibernate Validator's default message - interpolator, - ResourceBundleMessageInterpolator. The - latter two packages provide the - ResourceBundleLocator SPI for the loading of resource - bundles (see ) - and its default implementation. - - - - org.hibernate.validator.parameternameprovider - - A ParameterNameProvider based on the - ParaNamer library, see . - - - - org.hibernate.validator.valuehandling, - org.hibernate.validator.spi.valuehandling - - Classes related to the processing of values prior to their - validation, see . - - - -
- - - The public packages of Hibernate Validator fall into two - categories: while the actual API parts are intended to be - invoked or used by clients - (e.g. the API for programmatic constraint declaration or the custom - constraints), the SPI (service provider interface) packages contain - interfaces which are intended to be implemented by - clients (e.g. ResourceBundleLocator). - - - Any packages not listed in that table are internal packages of - Hibernate Validator and are not intended to be accessed by clients. The - contents of these internal packages can change from release to release - without notice, thus possibly breaking any client code relying on - it. -
- -
- Fail fast mode - - Using the fail fast mode, Hibernate Validator allows to return from - the current validation as soon as the first constraint violation occurs. - This can be useful for the validation of large object graphs where you are - only interested in a quick check whether there is any constraint violation - at all. - - shows how to bootstrap and - use a fail fast enabled validator. - - - Using the fail fast validation mode - - package org.hibernate.validator.referenceguide.chapter11.failfast; - -public class Car { - - @NotNull - private String manufacturer; - - @AssertTrue - private boolean isRegistered; - - public Car(String manufacturer, boolean isRegistered) { - this.manufacturer = manufacturer; - this.isRegistered = isRegistered; - } - - //getters and setters... -} - - Validator validator = Validation.byProvider( HibernateValidator.class ) - .configure() - .failFast( true ) - .buildValidatorFactory() - .getValidator(); - -Car car = new Car( null, false ); - -Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car ); - -assertEquals( 1, constraintViolations.size() ); - - - Here the validated object actually fails to satisfy both the - constraints declared on the Car class, yet the - validation call yields only one ConstraintViolation - since the fail fast mode is enabled. - - - There is no guarantee in which order the constraints are - evaluated, i.e. it is not deterministic whether the returned violation - originates from the @NotNull or the - @AssertTrue constraint. If required, a - deterministic evaluation order can be enforced using group sequences as - described in . - - - Refer to to - learn about the different ways of enabling the fail fast mode when - bootstrapping a validator. -
- -
- Programmatic constraint declaration - - As per the Bean Validation specification, you can declare - constraints using Java annotations and XML based constraint - mappings. - - In addition, Hibernate Validator provides a fluent API which allows - for the programmatic configuration of constraints. Use cases include the - dynamic addition of constraints at runtime depending on some application - state or tests where you need entities with different constraints in - different scenarios but don't want to implement actual Java classes for - each test case. - - By default, constraints added via the fluent API are additive to - constraints configured via the standard configuration capabilities. But it - is also possible to ignore annotation and XML configured constraints where - required. - - The API is centered around the - ConstraintMapping interface. You obtain a new - mapping via - HibernateValidatorConfiguration#createConstraintMapping() - which you then can configure in a fluent manner as shown in . - - - Programmatic constraint declaration - - HibernateValidatorConfiguration configuration = Validation - .byProvider( HibernateValidator.class ) - .configure(); - -ConstraintMapping constraintMapping = configuration.createConstraintMapping(); - -constraintMapping - .type( Car.class ) - .property( "manufacturer", FIELD ) - .constraint( new NotNullDef() ) - .property( "licensePlate", FIELD ) - .ignoreAnnotations() - .constraint( new NotNullDef() ) - .constraint( new SizeDef().min( 2 ).max( 14 ) ) - .type( RentalCar.class ) - .property( "rentalStation", METHOD ) - .constraint( new NotNullDef() ); - -Validator validator = configuration.addMapping( constraintMapping ) - .buildValidatorFactory() - .getValidator(); - - - Constraints can be configured on multiple classes and properties - using method chaining. The constraint definition classes - NotNullDef and SizeDef are - helper classes which allow to configure constraint parameters in a - type-safe fashion. Definition classes exist for all built-in constraints - in the org.hibernate.validator.cfg.defs package. By - calling ignoreAnnotations() any constraints - configured via annotations or XML are ignored for the given - element. - - - Each element (type, property, method etc.) may only be configured - once within all the constraint mappings used to set up one validator - factory. Otherwise a ValidationException is - raised. - - - - It is not supported to add constraints to non-overridden supertype - properties and methods by configuring a subtype. Instead you need to - configure the supertype in this case. - - - Having configured the mapping, you must add it back to the - configuration object from which you then can obtain a validator - factory. - - For custom constraints you can either create your own definition - classes extending ConstraintDef or you can use - GenericConstraintDef as seen in . - - - Programmatic declaration of a custom constraint - - ConstraintMapping constraintMapping = configuration.createConstraintMapping(); - -constraintMapping - .type( Car.class ) - .property( "licensePlate", FIELD ) - .constraint( new GenericConstraintDef<CheckCase>( CheckCase.class ) - .param( "value", CaseMode.UPPER ) - ); - - - By invoking valid() you can mark a member - for cascaded validation which is equivalent to annotating it with - @Valid. Configure any group conversions to be - applied during cascaded validation using the - convertGroup() method (equivalent to - @ConvertGroup). An example can be seen in . - - - Marking a property for cascaded validation - - ConstraintMapping constraintMapping = configuration.createConstraintMapping(); - -constraintMapping - .type( Car.class ) - .property( "driver", FIELD ) - .constraint( new NotNullDef() ) - .valid() - .convertGroup( Default.class ).to( PersonDefault.class ) - .type( Person.class ) - .property( "name", FIELD ) - .constraint( new NotNullDef().groups( PersonDefault.class ) ); - - - You can not only configure bean constraints using the fluent API but - also method and constructor constraints. As shown in constructors are identified - by their parameter types and methods by their name and parameter types. - Having selected a method or constructor, you can mark its parameters - and/or return value for cascaded validation and add constraints as well as - cross-parameter constraints. - - - Programmatic declaration of method and constructor - constraints - - ConstraintMapping constraintMapping = configuration.createConstraintMapping(); - -constraintMapping - .type( Car.class ) - .constructor( String.class ) - .parameter( 0 ) - .constraint( new SizeDef().min( 3 ).max( 50 ) ) - .returnValue() - .valid() - .method( "drive", int.class ) - .parameter( 0 ) - .constraint( new MaxDef().value ( 75 ) ) - .method( "load", List.class, List.class ) - .crossParameter() - .constraint( new GenericConstraintDef<LuggageCountMatchesPassengerCount>( - LuggageCountMatchesPassengerCount.class ).param( - "piecesOfLuggagePerPassenger", 2 - ) - ) - .method( "getDriver" ) - .returnValue() - .constraint( new NotNullDef() ) - .valid(); - - - Last but not least you can configure the default group sequence or - the default group sequence provider of a type as shown in the following - example. - - - Configuration of default group sequence and default group - sequence provider - - ConstraintMapping constraintMapping = configuration.createConstraintMapping(); - -constraintMapping - .type( Car.class ) - .defaultGroupSequence( Car.class, CarChecks.class ) - .type( RentalCar.class ) - .defaultGroupSequenceProviderClass( RentalCarGroupSequenceProvider.class ); - -
- -
- Boolean composition of constraints - - Bean Validation specifies that the constraints of a composed - constraint (see ) are all - combined via a logical AND. This means all of the - composing constraints need to return true in order - for an overall successful validation. - - Hibernate Validator offers an extension to this and allows you to - compose constraints via a logical OR or - NOT. To do so you have to use the - ConstraintComposition annotation and the enum - CompositionType with its values - AND, OR and - ALL_FALSE. - - shows how - to build a composed constraint @PatternOrSize where - only one of the composing constraints needs to be valid in order to pass - the validation. Either the validated string is all lower-cased or it is - between two and three characters long. - - - OR composition of constraints - - package org.hibernate.validator.referenceguide.chapter11.booleancomposition; - -@ConstraintComposition(OR) -@Pattern(regexp = "[a-z]") -@Size(min = 2, max = 3) -@ReportAsSingleViolation -@Target({ METHOD, FIELD }) -@Retention(RUNTIME) -@Constraint(validatedBy = { }) -public @interface PatternOrSize { - String message() default "{org.hibernate.validator.referenceguide.chapter11." + - "booleancomposition.PatternOrSize.message}"; - - Class<?>[] groups() default { }; - - Class<? extends Payload>[] payload() default { }; -} - - - - Using ALL_FALSE as composition type - implicitly enforces that only a single violation will get reported in - case validation of the constraint composition fails. - -
- -
- <classname>ResourceBundleLocator</classname> - - As described in , Bean Validation allows - to plug in custom message interpolator implementations. - - With ResourceBundleLocator, Hibernate - Validator provides an additional SPI which allows to retrieve error - messages from other resource bundles than - ValidationMessages while still using the actual - interpolation algorithm as defined by the specification. Refer to to learn how to make use of - that SPI. -
- -
- Custom contexts - - The Bean Validation specification offers at several points in its - API the possibility to unwrap a given interface to a implementor specific - subtype. In the case of constraint violation creation in - ConstraintValidator implementations as well as - message interpolation in Messageinterpolator - instances, there exist unwrap() methods for the - provided context instances - - ConstraintValidatorContext respectively - MessageInterpolatorContext. Hibernate Validator - provides custom extensions for both of these interfaces. - -
- <classname>HibernateConstraintValidatorContext</classname> - - HibernateConstraintValidatorContext - is a subtype of ConstraintValidatorContext which - allows you to set arbitrary parameters for interpolation via the - Expression Language message interpolation facility (see ). For example - the default error message for the @Future - constraint is "must be in the future". What if you would like to include - the current date to make the message more explicit? shows how this could be - achieved. - - - Custom <classname>@Future</classname> validator with message - parameters - - public class MyFutureValidator implements ConstraintValidator<Future, Date> { - - public void initialize(Future constraintAnnotation) { - } - - public boolean isValid(Date value, ConstraintValidatorContext context) { - Date now = GregorianCalendar.getInstance().getTime(); - - if ( value.before( now ) ) { - HibernateConstraintValidatorContext hibernateContext = - context.unwrap( HibernateConstraintValidatorContext.class ); - - hibernateContext.disableDefaultConstraintViolation(); - hibernateContext.addExpressionVariable( "now", now ) - .buildConstraintViolationWithTemplate( "Must be after ${now}" ) - .addConstraintViolation(); - - return false; - } - - return true; - } -} - - - - Note that the parameters specified via - addExpressionVariable(String, Object) are - global and apply for all constraint violations created by this - isValid() invocation. This includes the - default constraint violation, but also all violations created by the - ConstraintViolationBuilder. You can, however, - update the parameters between invocations of - ConstraintViolationBuilder#addConstraintViolation(). - - - - This functionality is currently experimental and might change in - future versions. - -
- -
- <classname>HibernateMessageInterpolatorContext</classname> - - Hibernate Validator also offers a custom extension of - MessageInterpolatorContext, namely - HibernateMessageInterpolatorContext (see ). This subtype - was introduced to allow a better integration of Hibernate Validator into - the Glassfish. The root bean type was in this case needed to determine - the right classloader for the message resource bundle. If you have any - other usecases, let us know. - - - <classname>HibernateMessageInterpolatorContext</classname> - - public interface HibernateMessageInterpolatorContext extends MessageInterpolator.Context { - - /** - * Returns the currently validated root bean type. - * - * @return The currently validated root bean type. - */ - Class<?> getRootBeanType(); -} - -
-
- -
- ParaNamer based - <classname>ParameterNameProvider</classname> - - Hibernate Validator comes with a - ParameterNameProvider implementation which - leverages the ParaNamer library. - - This library provides several ways for obtaining parameter names at - runtime, e.g. based on debug symbols created by the Java compiler, - constants with the parameter names woven into the bytecode in a - post-compile step or annotations such as the @Named - annotation from JSR 330. - - In order to use - ParanamerParameterNameProvider, either pass an - instance when bootstrapping a validator as shown in or specify - org.hibernate.validator.parameternameprovider.ParanamerParameterNameProvider - as value for the <parameter-name-provider> - element in the META-INF/validation.xml file. - - - When using this parameter name provider, you need to add the - ParaNamer library to your classpath. It is available in the Maven - Central repository with the group id - com.thoughtworks.paranamer and the artifact id - paranamer. - - - By default ParanamerParameterNameProvider - retrieves parameter names from constants added to the byte code at build - time (via DefaultParanamer) and debug symbols (via - BytecodeReadingParanamer). Alternatively you can - specify a Paranamer implementation of your choice - when creating a ParanamerParameterNameProvider - instance. -
- -
- Unwrapping values prior to validation - - Sometimes it is required to unwrap values prior to the validation. - E.g. in property types - as specified by JavaFX - are used to define an element of some domain model. - - - Using<classname>@UnwrapValidatedValue</classname> - - @Size(min = 3) -@UnwrapValidatedValue -private Property<String> name = new SimpleStringProperty( "Bob" ); - - - - The concept of value unwrapping is considered experimental at this - time and may evolve into more general means of value handling in future - releases. Please let us know about your use cases for such functionality. - - - - In JavaFX, bean properties are typically not of simple data types - like String or int, but are - wrapped in Property types which allows to make them - observable, use them for data binding etc. When applying a constraint such - as @Size to an element of type - Property<String> without further preparation, - an exception would be raised, indicating that no suitable validator for - that constraint and data type can be found. Thus the validated value must - be unwrapped from the containing property object before looking up a - validator and invoking it. - - To do so, put the @UnwrapValidatedValue - annotation to the element in question. This will advice the validation - engine to look for an unwrapper implementation which returns the data type - to be used for constraint validator resolution and unwraps the validated - value. Unwrapper types must extend the SPI class - ValidatedValueUnwrapper as shown in - . - - - Implementing the <classname>ValidatedValueUnwrapper</classname> - interface - - public class PropertyValueUnwrapper extends ValidatedValueUnwrapper<Property<?>> { - - @Override - public Object handleValidatedValue(Property<?> value) { - //... - } - - @Override - public Type getValidatedValueType(Type valueType) { - //... - } -} - - - Value unwrappers must be registered when obtaining a Validator - instance as follows: - - - Registering a <classname>ValidatedValueUnwrapper</classname> - - Validator validator = Validation.byProvider( HibernateValidator.class ) - .configure() - .addValidatedValueHandler( new PropertyValueUnwrapper() ) - .buildValidatorFactory() - .getValidator(); - - - Several unwrapper implementations can be registered when working - with different kinds of wrapper types in one application. Note that it is - not specified which of the unwrapper implementations is chosen when more - than one implementation is suitable to unwrap a given element. - - Alternatively, the fully-qualified names of one ore more unwrapper - implementations can be specified via the configuration property - hibernate.validator.validated_value_handlers which - can be useful when configuring the default validator factory using the - descriptor META-INF/validation.xml (see ). - -
-
diff --git a/documentation/src/main/docbook/en-US/modules/further-reading.xml b/documentation/src/main/docbook/en-US/modules/further-reading.xml deleted file mode 100644 index dd6f4f0a6b..0000000000 --- a/documentation/src/main/docbook/en-US/modules/further-reading.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Further reading - - Last but not least, a few pointers to further information. - - A great source for examples is the Bean Validation TCK which is - available for anonymous access on GitHub. - In particular the TCK's tests - might be of interest. The JSR 349 - specification itself is also a great way to deepen your understanding of - Bean Validation resp. Hibernate Validator. - - If you have any further questions to Hibernate Validator or want to - share some of your use cases have a look at the Hibernate Validator - Wiki and the Hibernate Validator - Forum. - - In case you would like to report a bug use Hibernate's - Jira instance. Feedback is always welcome! - diff --git a/documentation/src/main/docbook/en-US/modules/getting-started.xml b/documentation/src/main/docbook/en-US/modules/getting-started.xml deleted file mode 100644 index fe2fd33c0f..0000000000 --- a/documentation/src/main/docbook/en-US/modules/getting-started.xml +++ /dev/null @@ -1,404 +0,0 @@ - - - - %BOOK_ENTITIES; - ]> - - Getting started - - This chapter will show you how to get started with Hibernate - Validator, the reference implementation (RI) of Bean Validation. For the - following quickstart you need: - - - - - A JDK >= 6 - - - - - Apache Maven - - - - - An Internet connection (Maven has to download all required - libraries) - - - - -
- Project set up - - In order to use Hibernate Validator within a Maven project, simply - add the following dependency to your pom.xml: - - - - Hibernate Validator Maven dependency - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-validator</artifactId> - <version>&version;</version> - </dependency> - - - This transitively pulls in the dependency to the Bean Validation API - (javax.validation:validation-api:&bvVersion;). - - -
- Unified EL - - Hibernate Validator requires an implementation of the Unified - Expression Language (JSR - 341) for evaluating dynamic expressions in constraint violation - messages (see). When - your application runs in a Java EE container such as JBoss AS, an EL - implementation is already provided by the container. In a Java SE - environment, however, you have to add an implementation as dependency to - your POM file. For instance you can add the following two dependencies - to use the JSR 341reference - implementation: - - - - Maven dependencies for Unified EL reference - implementation - - - <dependency> - <groupId>javax.el</groupId> - <artifactId>javax.el-api</artifactId> - <version>2.2.4</version> - </dependency> - <dependency> - <groupId>org.glassfish.web</groupId> - <artifactId>javax.el</artifactId> - <version>2.2.4</version> - </dependency> - -
- -
- CDI - - Bean Validation defines integration points with CDI (Contexts and - Dependency Injection for Java - TM - EE,JSR 346). If your - application runs in an environment which does not provide this - integration out of the box, you may use the Hibernate Validator CDI - portable extension by adding the following Maven dependency to your - POM: - - - - Hibernate Validator CDI portable extension Maven - dependency - - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-validator-cdi</artifactId> - <version>&version;</version> - </dependency> - - - Note that adding this dependency is usually not required for - applications running on a Java EE application server. You can learn more - about the integration of Bean Validation and CDI in. - -
-
- -
- Applying constraints - - Lets dive directly into an example to see how to apply - constraints. - - - - Class - <classname>Car</classname> - annotated with - constraints - - - package org.hibernate.validator.referenceguide.chapter01; - - import javax.validation.constraints.Min; - import javax.validation.constraints.NotNull; - import javax.validation.constraints.Size; - - public class Car { - - @NotNull - private String manufacturer; - - @NotNull - @Size(min = 2, max = 14) - private String licensePlate; - - @Min(2) - private int seatCount; - - public Car(String manufacturer, String licencePlate, int seatCount) { - this.manufacturer = manufacturer; - this.licensePlate = licencePlate; - this.seatCount = seatCount; - } - - //getters and setters ... - } - - - - The@NotNull, - @Size - and - @Min - annotations are used to declare the - constraints which should be applied to the fields of a - Car - instance: - - - - - - manufacturer - must never be - null - - - - - - licensePlate - must never be - null - and must be between 2 and 14 characters - long - - - - - - seatCount - must be at least 2 - - - - You can find the complete source code of all examples used in - this reference guide in the Hibernate Validator - - source - repository - - on GitHub. - - - - -
- -
- Validating constraints - - To perform a validation of these constraints, you use a - Validator - instance. Let's have a look at a unit - test forCar: - - - - Class - <classname>CarTest</classname> - showing validation - examples - - - package org.hibernate.validator.referenceguide.chapter01; - - import java.util.Set; - import javax.validation.ConstraintViolation; - import javax.validation.Validation; - import javax.validation.Validator; - import javax.validation.ValidatorFactory; - - import org.junit.BeforeClass; - import org.junit.Test; - - import static org.junit.Assert.assertEquals; - - public class CarTest { - - private static Validator validator; - - @BeforeClass - public static void setUp() { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - validator = factory.getValidator(); - } - - @Test - public void manufacturerIsNull() { - Car car = new Car( null, "DD-AB-123", 4 ); - - Set<ConstraintViolation<Car>> constraintViolations = - validator.validate( car ); - - assertEquals( 1, constraintViolations.size() ); - assertEquals( "may not be null", constraintViolations.iterator().next().getMessage() ); - } - - @Test - public void licensePlateTooShort() { - Car car = new Car( "Morris", "D", 4 ); - - Set<ConstraintViolation<Car>> constraintViolations = - validator.validate( car ); - - assertEquals( 1, constraintViolations.size() ); - assertEquals( - "size must be between 2 and 14", - constraintViolations.iterator().next().getMessage() - ); - } - - @Test - public void seatCountTooLow() { - Car car = new Car( "Morris", "DD-AB-123", 1 ); - - Set<ConstraintViolation<Car>> constraintViolations = - validator.validate( car ); - - assertEquals( 1, constraintViolations.size() ); - assertEquals( - "must be greater than or equal to 2", - constraintViolations.iterator().next().getMessage() - ); - } - - @Test - public void carIsValid() { - Car car = new Car( "Morris", "DD-AB-123", 2 ); - - Set<ConstraintViolation<Car>> constraintViolations = - validator.validate( car ); - - assertEquals( 0, constraintViolations.size() ); - } - } - - - - In the - setUp() - method a - Validator - object is retrieved from the - ValidatorFactory. A - Validator - instance is thread-safe and may be reused - multiple times. It thus can safely be stored in a static field and be used - in the test methods to validate the different - Car - instances. - - - The - validate() - method returns a set of - ConstraintViolation - instances, which you can - iterate over in order to see which validation errors occurred. The first - three test methods show some expected constraint violations: - - - - - The - @NotNull - constraint on manufacturer - is violated in - manufacturerIsNull() - - - - - The - @Size - constraint on licensePlate is - violated in - licensePlateTooShort() - - - - - The - @Min - constraint on seatCount is - violated in - seatCountTooLow() - - - - - If the object validates successfully, - validate() - returns an empty set as you can see in - carIsValid(). - - - Note that only classes from the package - javax.validation - are used. These are provided from the - Bean Validation API. No classes from Hibernate Validator are directly - referenced, resulting in portable code. - -
- -
- Where to go next? - - That concludes the 5 minute tour through the world of Hibernate - Validator and Bean Validation. Continue exploring the code examples or - look at further examples referenced in. - - - To learn more about the validation of beans and properties, just - continue reading. If you are - interested in using Bean Validation for the validation of method pre- and - postcondition refer to. In - case your application has specific validation requirements have a look at - . - -
-
diff --git a/documentation/src/main/docbook/en-US/modules/groups.xml b/documentation/src/main/docbook/en-US/modules/groups.xml deleted file mode 100644 index 9165f518c8..0000000000 --- a/documentation/src/main/docbook/en-US/modules/groups.xml +++ /dev/null @@ -1,637 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Grouping constraints - - All validation methods on Validator and - ExecutableValidator discussed in earlier chapters - also take a var-arg argument groups. So far we have - been ignoring this parameter, but it is time to have a closer look. - -
- Requesting groups - - Groups allow you to restrict the set of constraints applied during - validation. One use case for validation groups are UI wizards where in - each step only a specified subset of constraints should get validated. The - groups targeted are passed as var-arg parameters to the appropriate - validate method. - - Let's have a look at an example. The class - Person in has a - @NotNull constraint on name. - Since no group is specified for this annotation the default group - javax.validation.groups.Default is assumed. - - - When more than one group is requested, the order in which the - groups are evaluated is not deterministic. If no group is specified the - default group javax.validation.groups.Default is - assumed. - - - - Person - - package org.hibernate.validator.referenceguide.chapter05; - -public class Person { - - @NotNull - private String name; - - public Person(String name) { - this.name = name; - } - - // getters and setters ... -} - - - The class Driver in extends Person and adds - the properties age and - hasDrivingLicense. Drivers must be at least 18 years - old (@Min(18)) and have a driving license - (@AssertTrue). Both constraints defined on these - properties belong to the group DriverChecks which - is just a simple tagging interface. - - - Using interfaces makes the usage of groups type-safe and allows - for easy refactoring. It also means that groups can inherit from each - other via class inheritance. - - - - Driver - - package org.hibernate.validator.referenceguide.chapter05; - -public class Driver extends Person { - - @Min( - value = 18, - message = "You have to be 18 to drive a car", - groups = DriverChecks.class - ) - public int age; - - @AssertTrue( - message = "You first have to pass the driving test", - groups = DriverChecks.class - ) - public boolean hasDrivingLicense; - - public Driver(String name) { - super( name ); - } - - public void passedDrivingTest(boolean b) { - hasDrivingLicense = b; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } -} - - package org.hibernate.validator.referenceguide.chapter05; - -public interface DriverChecks { -} - - - Finally the class Car () has some - constraints which are part of the default group as well as - @AssertTrue in the group - CarChecks on the property - passedVehicleInspection which indicates whether a car - passed the road worthy tests. - - - Car - - package org.hibernate.validator.referenceguide.chapter05; - -public class Car { - @NotNull - private String manufacturer; - - @NotNull - @Size(min = 2, max = 14) - private String licensePlate; - - @Min(2) - private int seatCount; - - @AssertTrue( - message = "The car has to pass the vehicle inspection first", - groups = CarChecks.class - ) - private boolean passedVehicleInspection; - - @Valid - private Driver driver; - - public Car(String manufacturer, String licencePlate, int seatCount) { - this.manufacturer = manufacturer; - this.licensePlate = licencePlate; - this.seatCount = seatCount; - } - - // getters and setters ... -} - - package org.hibernate.validator.referenceguide.chapter05; - -public interface CarChecks { -} - - - Overall three different groups are used in the example: - - - - The constraints on Person.name, - Car.manufacturer, - Car.licensePlate and - Car.seatCount all belong to the - Default group - - - - The constraints on Driver.age and - Driver.hasDrivingLicense belong to - DriverChecks - - - - The constraint on - Car.passedVehicleInspection belongs to the group - CarChecks - - - - shows how passing different - group combinations to the Validator#validate() - method results in different validation results. - - - Using validation groups - - // create a car and check that everything is ok with it. -Car car = new Car( "Morris", "DD-AB-123", 2 ); -Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car ); -assertEquals( 0, constraintViolations.size() ); - -// but has it passed the vehicle inspection? -constraintViolations = validator.validate( car, CarChecks.class ); -assertEquals( 1, constraintViolations.size() ); -assertEquals( - "The car has to pass the vehicle inspection first", - constraintViolations.iterator().next().getMessage() -); - -// let's go to the vehicle inspection -car.setPassedVehicleInspection( true ); -assertEquals( 0, validator.validate( car ).size() ); - -// now let's add a driver. He is 18, but has not passed the driving test yet -Driver john = new Driver( "John Doe" ); -john.setAge( 18 ); -car.setDriver( john ); -constraintViolations = validator.validate( car, DriverChecks.class ); -assertEquals( 1, constraintViolations.size() ); -assertEquals( - "You first have to pass the driving test", - constraintViolations.iterator().next().getMessage() -); - -// ok, John passes the test -john.passedDrivingTest( true ); -assertEquals( 0, validator.validate( car, DriverChecks.class ).size() ); - -// just checking that everything is in order now -assertEquals( - 0, validator.validate( - car, - Default.class, - CarChecks.class, - DriverChecks.class -).size() -); - - - The first validate() call in is done using no explicit group. There are - no validation errors, even though the property - passedVehicleInspection is per default - false. However, the constraint defined on this - property does not belong to the default group. - - The next validation using the CarChecks group - fails until the car passes the vehicle inspection. Adding a driver to the - car and validating against DriverChecks again - yields one constraint violation due to the fact that the driver has not - yet passed the driving test. Only after setting - passedDrivingTest to true the - validation against DriverChecks passes. - - The last validate() call finally shows that all constraints are - passing by validating against all defined groups. -
- -
- Defining group sequences - - By default, constraints are evaluated in no particular order, - regardless of which groups they belong to. In some situations, however, it - is useful to control the order constraints are evaluated. - - In the example from it could - for instance be required that first all default car constraints are - passing before checking the road worthiness of the car. Finally, before - driving away, the actual driver constraints should be checked. - - In order to implement such a validation order you just need to - define an interface and annotate it with - @GroupSequence, defining the order in which the - groups have to be validated (see ). If at least one constraint - fails in a sequenced group none of the constraints of the following groups - in the sequence get validated. - - - Defining a group sequence - - package org.hibernate.validator.referenceguide.chapter05; - -@GroupSequence({ Default.class, CarChecks.class, DriverChecks.class }) -public interface OrderedChecks { -} - - - - Groups defining a sequence and groups composing a sequence must - not be involved in a cyclic dependency either directly or indirectly, - either through cascaded sequence definition or group inheritance. If a - group containing such a circularity is evaluated, a - GroupDefinitionException is raised. - You then can use the new sequence as shown in in . - - - Using a group sequence - - Car car = new Car( "Morris", "DD-AB-123", 2 ); -car.setPassedVehicleInspection( true ); - -Driver john = new Driver( "John Doe" ); -john.setAge( 18 ); -john.passedDrivingTest( true ); -car.setDriver( john ); - -assertEquals( 0, validator.validate( car, OrderedChecks.class ).size() ); - -
- -
- Redefining the default group sequence - -
- <classname>@GroupSequence</classname> - - Besides defining group sequences, the - @GroupSequence annotation also allows to redefine - the default group for a given class. To do so, just add the - @GroupSequence annotation to the class and - specify the sequence of groups which substitute - Default for this class within the - annotation. - - introduces a new class - RentalCar with a redefined default group. - - - Class <classname>RentalCar</classname> with redefined default - group - - package org.hibernate.validator.referenceguide.chapter05; - -@GroupSequence({ RentalChecks.class, CarChecks.class, RentalCar.class }) -public class RentalCar extends Car { - @AssertFalse(message = "The car is currently rented out", groups = RentalChecks.class) - private boolean rented; - - public RentalCar(String manufacturer, String licencePlate, int seatCount) { - super( manufacturer, licencePlate, seatCount ); - } - - public boolean isRented() { - return rented; - } - - public void setRented(boolean rented) { - this.rented = rented; - } -} - - package org.hibernate.validator.referenceguide.chapter05; - -public interface RentalChecks { -} - - - With this definition you can evaluate the constraints belonging to - RentalChecks, CarChecks - and RentalCar by just requesting the - Default group as seen in . - - - Validating an object with redefined default group - - RentalCar rentalCar = new RentalCar( "Morris", "DD-AB-123", 2 ); -rentalCar.setPassedVehicleInspection( true ); -rentalCar.setRented( true ); - -Set<ConstraintViolation<RentalCar>> constraintViolations = validator.validate( rentalCar ); - -assertEquals( 1, constraintViolations.size() ); -assertEquals( - "Wrong message", - "The car is currently rented out", - constraintViolations.iterator().next().getMessage() -); - -rentalCar.setRented( false ); -constraintViolations = validator.validate( rentalCar ); - -assertEquals( 0, constraintViolations.size() ); - - - - Since there must no cyclic dependency in the group and group - sequence definitions one cannot just add - Default to the sequence redefining - Default for a class. Instead the class itself - has to be added! - - - The Default group sequence overriding is - local to the class it is defined on and is not propagated to associated - objects. For the example this means that adding - DriverChecks to the default group sequence of - RentalCar would not have any effects. Only the - group Default will be propagated to the - driver association. - - Note that you can control the propagated group(s) by declaring a - group conversion rule (see ). -
- -
- <classname>@GroupSequenceProvider</classname> - - In addition to statically redefining default group sequences via - @GroupSequence, Hibernate Validator also provides - an SPI for the dynamic redefinition of default group sequences depending - on the object state. - - For that purpose you need to implement the interface - DefaultGroupSequenceProvider and register this - implementation with the target class via the - @GroupSequenceProvider annotation. In the rental - car scenario you could for instance dynamically add the - CarChecks as seen in . - - - Implementing and using a default group sequence - provider - - package org.hibernate.validator.referenceguide.chapter05.groupsequenceprovider; - -public class RentalCarGroupSequenceProvider - implements DefaultGroupSequenceProvider<RentalCar> { - - @Override - public List<Class<?>> getValidationGroups(RentalCar car) { - List<Class<?>> defaultGroupSequence = new ArrayList<Class<?>>(); - defaultGroupSequence.add( RentalCar.class ); - - if ( car != null && !car.isRented() ) { - defaultGroupSequence.add( CarChecks.class ); - } - - return defaultGroupSequence; - } -} - - package org.hibernate.validator.referenceguide.chapter05.groupsequenceprovider; - -@GroupSequenceProvider(RentalCarGroupSequenceProvider.class) -public class RentalCar extends Car { - - @AssertFalse(message = "The car is currently rented out", groups = RentalChecks.class) - private boolean rented; - - public RentalCar(String manufacturer, String licencePlate, int seatCount) { - super( manufacturer, licencePlate, seatCount ); - } - - public boolean isRented() { - return rented; - } - - public void setRented(boolean rented) { - this.rented = rented; - } -} - -
-
- -
- Group conversion - - What if you wanted to validate the car related checks together with - the driver checks? Of course you could pass the required groups to the - validate call explicitly, but what if you wanted to make these validations - occur as part of the Default group validation? Here - @ConvertGroup comes into play which allows you - during cascaded validation to use a different group than the originally - requested one. - - Let's have a look at . Here - @GroupSequence({ CarChecks.class, Car.class }) is used to - combine the car related constraints under the - Default group (see ). There is also a - @ConvertGroup(from = Default.class, to = DriverChecks.class) - which ensures the Default group gets converted to - the DriverChecks group during cascaded validation - of the driver association. - - - <classname>@ConvertGroup</classname> usage - - package org.hibernate.validator.referenceguide.chapter05.groupconversion; - -public class Driver { - - @NotNull - private String name; - - @Min( - value = 18, - message = "You have to be 18 to drive a car", - groups = DriverChecks.class - ) - public int age; - - @AssertTrue( - message = "You first have to pass the driving test", - groups = DriverChecks.class - ) - public boolean hasDrivingLicense; - - public Driver(String name) { - this.name = name; - } - - public void passedDrivingTest(boolean b) { - hasDrivingLicense = b; - } - - // getters and setters ... -} - - package org.hibernate.validator.referenceguide.chapter05.groupconversion; - -@GroupSequence({ CarChecks.class, Car.class }) -public class Car { - - @NotNull - private String manufacturer; - - @NotNull - @Size(min = 2, max = 14) - private String licensePlate; - - @Min(2) - private int seatCount; - - @AssertTrue( - message = "The car has to pass the vehicle inspection first", - groups = CarChecks.class - ) - private boolean passedVehicleInspection; - - @Valid - @ConvertGroup(from = Default.class, to = DriverChecks.class) - private Driver driver; - - public Car(String manufacturer, String licencePlate, int seatCount) { - this.manufacturer = manufacturer; - this.licensePlate = licencePlate; - this.seatCount = seatCount; - } - - // getters and setters ... -} - - - As a result the validation in succeeds, even though the - constraint on hasDrivingLicense belongs to the - DriverChecks group and only the - Default group is requested in the - validate() call. - - - Test case for @ConvertGroup - - // create a car and validate. The Driver is still null and does not get validated -Car car = new Car( "VW", "USD-123", 4 ); -car.setPassedVehicleInspection( true ); -Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car ); -assertEquals( 0, constraintViolations.size() ); - -// create a driver who has not passed the driving test -Driver john = new Driver( "John Doe" ); -john.setAge( 18 ); - -// now let's add a driver to the car -car.setDriver( john ); -constraintViolations = validator.validate( car ); -assertEquals( 1, constraintViolations.size() ); -assertEquals( - "The driver constraint should also be validated as part of the default group", - constraintViolations.iterator().next().getMessage(), - "You first have to pass the driving test" -); - - - You can define group conversions wherever - @Valid can be used, namely associations as well as - method and constructor parameters and return values. Multiple conversions - can be specified using @ConvertGroup.List. - - However, the following restrictions apply: - - @ConvertGroup must only be used in - combination with @Valid. If used without, a - ConstraintDeclarationException is - thrown. - - - - It is not legal to have multiple conversion rules on the same - element with the same from value. In this - case, a ConstraintDeclarationException is - raised. - - - - The from attribute must not refer to a - group sequence. A - ConstraintDeclarationException is raised in - this situation. - - - Rules are not executed recursively. The first matching - conversion rule is used and subsequent rules are ignored. For example - if a set of @ConvertGroup declarations chains - group A to B and B to C, the group A will be converted to B and not to - C. - -
-
diff --git a/documentation/src/main/docbook/en-US/modules/integration.xml b/documentation/src/main/docbook/en-US/modules/integration.xml deleted file mode 100644 index f65beb1910..0000000000 --- a/documentation/src/main/docbook/en-US/modules/integration.xml +++ /dev/null @@ -1,624 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Integrating with other frameworks - - Hibernate Validator is intended to be used to implement multi-layered - data validation, where constraints are expressed in a single place (the - annotated domain model) and checked in various different layers of the - application. For this reason there are multiple integration points with - other technologies. - -
- ORM integration - - Hibernate Validator integrates with both Hibernate and all pure Java - Persistence providers. - - - When lazy loaded associations are supposed to be validated it is - recommended to place the constraint on the getter of the association. - Hibernate replaces lazy loaded associations with proxy instances which - get initialized/loaded when requested via the getter. If, in such a - case, the constraint is placed on field level the actual proxy instance - is used which will lead to validation errors. - - -
- Database schema-level validation - - Out of the box, Hibernate (as of version 3.5.x) will translate the - constraints you have defined for your entities into mapping metadata. - For example, if a property of your entity is annotated - @NotNull, its columns will be declared as - not null in the DDL schema generated by - Hibernate. - - If, for some reason, the feature needs to be disabled, set - hibernate.validator.apply_to_ddl to - false. See also and . - - You can also limit the DDL constraint generation to a subset of - the defined constraints by setting the property - org.hibernate.validator.group.ddl. The property - specifies the comma-separated, fully specified class names of the groups - a constraint has to be part of in order to be considered for DDL schema - generation. -
- -
- Hibernate event-based validation - - Hibernate Validator has a built-in Hibernate event listener - - org.hibernate.cfg.beanvalidation.BeanValidationEventListener - - which is part of Hibernate Annotations (as of Hibernate 3.5.x). - Whenever a PreInsertEvent, - PreUpdateEvent or - PreDeleteEvent occurs, the listener will verify - all constraints of the entity instance and throw an exception if any - constraint is violated. Per default objects will be checked before any - inserts or updates are made by Hibernate. Pre deletion events will per - default not trigger a validation. You can configure the groups to be - validated per event type using the properties - javax.persistence.validation.group.pre-persist, - javax.persistence.validation.group.pre-update and - javax.persistence.validation.group.pre-remove. The - values of these properties are the comma-separated, fully specified - class names of the groups to validate. shows the default - values for these properties. In this case they could also be - omitted. - - On constraint violation, the event will raise a runtime - ConstraintViolationException which contains a set - of ConstraintViolations describing each - failure. - - If Hibernate Validator is present in the classpath, Hibernate - Annotations (or Hibernate EntityManager) will use it transparently. To - avoid validation even though Hibernate Validator is in the classpath set - javax.persistence.validation.mode to - none. - - - If the beans are not annotated with validation annotations, - there is no runtime performance cost. - - - In case you need to manually set the event listeners for Hibernate - Core, use the following configuration in - hibernate.cfg.xml: - - - Manual configuration of - <classname>BeanValidationEvenListener</classname> - - <hibernate-configuration> - <session-factory> - ... - <property name="javax.persistence.validation.group.pre-persist"> - javax.validation.groups.Default - </property> - <property name="javax.persistence.validation.group.pre-update"> - javax.validation.groups.Default - </property> - <property name="javax.persistence.validation.group.pre-remove"></property> - ... - <event type="pre-update"> - <listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/> - </event> - <event type="pre-insert"> - <listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/> - </event> - <event type="pre-delete"> - <listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/> - </event> - </session-factory> -</hibernate-configuration> - -
- -
- JPA - - If you are using JPA 2 and Hibernate Validator is in the classpath - the JPA2 specification requires that Bean Validation gets enabled. The - properties - javax.persistence.validation.group.pre-persist, - javax.persistence.validation.group.pre-update and - javax.persistence.validation.group.pre-remove as - described in can in this - case be configured in persistence.xml. - persistence.xml also defines a node validation-mode - which can be set to AUTO, - CALLBACK, NONE. The default is - AUTO. - - In a JPA 1 you will have to create and register Hibernate - Validator yourself. In case you are using Hibernate EntityManager you - can add a customized version of the - BeanValidationEventListener described in to your - project and register it manually. -
-
- -
- JSF & Seam - - When working with JSF2 or JBoss Seam and - Hibernate Validator (Bean Validation) is present in the runtime - environment, validation is triggered for every field in the application. - shows an example of the f:validateBean tag - in a JSF page. The validationGroups attribute is - optional and can be used to specify a comma seperated list of validation - groups. The default is - javax.validation.groups.Default. For more - information refer to the Seam documentation or the JSF 2 - specification. - - - Usage of Bean Validation within JSF2 - - <h:form> - <f:validateBean validationGroups="javax.validation.groups.Default"> - <h:inputText value=”#{model.property}” /> - <h:selectOneRadio value=”#{model.radioProperty}” > ... </h:selectOneRadio> - <!-- other input components here --> - </f:validateBean> -</h:form> - - - - - The integration between JSF 2 and Bean Validation is described in - the "Bean Validation Integration" chapter of JSR-314. It is - interesting to know that JSF 2 implements a custom - MessageInterpolator to ensure ensure proper - localization. To encourage the use of the Bean Validation message - facility, JSF 2 will per default only display the generated Bean - Validation message. This can, however, be configured via the application - resource bundle by providing the following configuration - ({0} is replaced with the Bean Validation message - and {1} is replaced with the JSF component - label): - - javax.faces.validator.BeanValidator.MESSAGE={1}: {0} - - The default is: - - javax.faces.validator.BeanValidator.MESSAGE={0} - -
- -
- CDI - - As of version 1.1, Bean Validation is integrated with CDI (Contexts - and Dependency Injection for JavaTM EE). - - This integration provides CDI managed beans for - Validator and - ValidatorFactory and enables dependency injection - in constraint validators as well as custom message interpolators, - traversable resolvers, constraint validator factories and parameter name - providers. - - Furthermore, parameter and return value constraints on the methods - and constructors of CDI managed beans will automatically be validated upon - invocation. - - When your application runs on a Jave EE container, this integration - is enabled by default. When working with CDI in a Servlet container or in - a pure Java SE environment, you can use the CDI portable extension - provided by Hibernate Validator. To do so, add the portable extension to - your class path as described in . - -
- Dependency injection - - CDI's dependency injection mechanism makes it very easy to - retrieve ValidatorFactory and - Validator instances and use them in your managed - beans. Just annotate instance fields of your bean with - @javax.inject.Inject as shown in . - - - Retrieving validator factory and validator via - <classname>@Inject</classname> - - package org.hibernate.validator.referenceguide.chapter10.cdi.validator; - -@ApplicationScoped -public class RentalStation { - - @Inject - private ValidatorFactory validatorFactory; - - @Inject - private Validator validator; - - //... -} - - - The injected beans are the default validator factory and validator - instances. In order to configure them - e.g. to use a custom message - interpolator - you can use the Bean Validation XML descriptors as - discussed in . - - If you are working with several Bean Validation providers you can - make sure that factory and validator from Hibernate Validator are - injected by annotating the injection points with the - @HibernateValidator qualifier which is - demonstrated in . - - - Using the @HibernateValidator qualifier annotation - - package org.hibernate.validator.referenceguide.chapter10.cdi.validator.qualifier; - -@ApplicationScoped -public class RentalStation { - - @Inject - @HibernateValidator - private ValidatorFactory validatorFactory; - - @Inject - @HibernateValidator - private Validator validator; - - //... -} - - - - The fully-qualified name of the qualifier annotation is - org.hibernate.validator.cdi.HibernateValidator. - Be sure to not import - org.hibernate.validator.HibernateValidator - instead which is the ValidationProvider - implementation used for selecting Hibernate Validator when working - with the bootstrapping API (see ). - - - Via @Inject you also can inject - dependencies into constraint validators and other Bean Validation - objects such as MessageInterpolator - implementations etc. - - - demonstrates how an injected CDI bean is used in a - ConstraintValidator implementation to determine - whether the given constraint is valid or not. As the example shows, you - also can work with the @PostConstruct and - @PreDestroy callbacks to implement any required - construction and destruction logic. - - - Constraint validator with injected bean - - package org.hibernate.validator.referenceguide.chapter10.cdi.injection; - -public class ValidLicensePlateValidator - implements ConstraintValidator<ValidLicensePlate, String> { - - @Inject - private VehicleRegistry vehicleRegistry; - - @PostConstruct - public void postConstruct() { - //do initialization logic... - } - - @PreDestroy - public void preDestroy() { - //do destruction logic... - } - - @Override - public void initialize(ValidLicensePlate constraintAnnotation) { - } - - @Override - public boolean isValid(String licensePlate, ConstraintValidatorContext constraintContext) { - return vehicleRegistry.isValidLicensePlate( licensePlate ); - } -} - -
- -
- Method validation - - The method interception facilities of CDI allow for a very tight - integration with Bean Validation's method validation functionality. Just - put constraint annotations to the parameters and return values of the - executables of your CDI beans and they will be validated automatically - before (parameter constraints) and after (return value constraints) a - method or constructor is invoked. - - Note that no explicit interceptor binding is required, instead the - required method validation interceptor will automatically be registered - for all managed beans with constrained methods and constructors. - - You can see an example in . - - - CDI managed beans with method-level constraints - - package org.hibernate.validator.referenceguide.chapter10.cdi.methodvalidation; - -@ApplicationScoped -public class RentalStation { - - @Valid - public RentalStation() { - //... - } - - @NotNull - @Valid - public Car rentCar( - @NotNull Customer customer, - @NotNull @Future Date startDate, - @Min(1) int durationInDays) { - //... - } - - @NotNull - List<Car> getAvailableCars() { - //... - } -} - - package org.hibernate.validator.referenceguide.chapter10.cdi.methodvalidation; - -@RequestScoped -public class RentCarRequest { - - @Inject - private RentalStation rentalStation; - - public void rentCar(String customerId, Date startDate, int duration) { - //causes ConstraintViolationException - rentalStation.rentCar( null, null, -1 ); - } -} - - - Here the RentalStation bean hosts several - method constraints. When invoking one of the - RentalStation methods from another bean such as - RentCarRequest, the constraints of the invoked - method are automatically validated. If any illegal parameter values are - passed as in the example, a - ConstraintViolationException will be thrown by - the method interceptor, providing detailed information on the violated - constraints. The same is the case if the method's return value violates - any return value constraints. - - Similarly, constructor constraints are validated automatically - upon invocation. In the example the RentalStation - object returned by the constructor will be validated since the - constructor return value is marked with - @Valid. - -
- Validated executable types - - Bean Validation allows for a fine-grained control of the - executable types which are automatically validated. By default, - constraints on constructors and non-getter methods are validated. - Therefore the @NotNull constraint on the method - RentalStation#getAvailableCars() in gets not validated when the - method is invoked. - - You have the following options to configure which types of - executables are validated upon invocation: - - - - Configure the executable types globally via the XML - descriptor META-INF/validation.xml; see for an - example - - - - Use the @ValidateOnExecution - annotation on the executable or type level - - - - If several sources of configuration are specified for a given - executable, @ValidateOnExecution on the - executable level takes precedence over - @ValidateOnExecution on the type level and - @ValidateOnExecution generally takes precedence - over the globally configured types in - META-INF/validation.xml. - - shows how to - use the @ValidateOnExecution annotation: - - - Using <classname>@ValidateOnExecution</classname> - - package org.hibernate.validator.referenceguide.chapter10.cdi.methodvalidation.configuration; - -@ApplicationScoped -@ValidateOnExecution(type = ExecutableType.ALL) -public class RentalStation { - - @Valid - public RentalStation() { - //... - } - - @NotNull - @Valid - @ValidateOnExecution(type = ExecutableType.NONE) - public Car rentCar( - @NotNull Customer customer, - @NotNull @Future Date startDate, - @Min(1) int durationInDays) { - //... - } - - @NotNull - public List<Car> getAvailableCars() { - //... - } -} - - - Here the method rentCar() won't be - validated upon invocation because it is annotated with - @ValidateOnExecution(type = - ExecutableType.NONE). In contrast, the constructor and the - method getAvailableCars() will be validated - due to @ValidateOnExecution(type = - ExecutableType.ALL) being given on the type level. - ExecutableType.ALL is a more compact form for - explicitly specifying all the types - CONSTRUCTORS, - GETTER_METHODS and - NON_GETTER_METHODS. - - - Executable validation can be turned off globally by specifying - <executable-validation enabled="false"/> in - META-INF/validation.xml. In this case, any - @ValidateOnExecution annotations are - ignored. - - - Note that when a method overrides or implements a super-type - method the configuration will be taken from that overridden or - implemented method (as given via - @ValidateOnExecution on the method itself or on - the super-type). This protects a client of the super-type method from - an unexpected alteration of the configuration, e.g. disabling - validation of an overridden executable in a sub-type. - - In case a CDI managed bean overrides or implements a super-type - method and this super-type method hosts any constraints, it can happen - that the validation interceptor is not properly registered with the - bean, resulting in the bean's methods not being validated upon - invocation. In this case you can specify the executable type IMPLICIT - on the sub-class as shown in , which makes sure - that all required metadata is discovered an the validation interceptor - kicks in when the methods on - ExpressRentalStation are invoked. - - - Using <classname>ExecutableType.IMPLICIT</classname> - - package org.hibernate.validator.referenceguide.chapter10.cdi.methodvalidation.implicit; - -@ValidateOnExecution(type = ExecutableType.ALL) -public interface RentalStation { - - @NotNull - @Valid - Car rentCar( - @NotNull Customer customer, - @NotNull @Future Date startDate, - @Min(1) int durationInDays); -} - - package org.hibernate.validator.referenceguide.chapter10.cdi.methodvalidation.implicit; - -@ApplicationScoped -@ValidateOnExecution(type = ExecutableType.IMPLICIT) -public class ExpressRentalStation implements RentalStation { - - @Override - public Car rentCar(Customer customer, Date startDate, @Min(1) int durationInDays) { - //... - } -} - -
-
-
- -
- Java EE - - When your application runs on a Java EE application server such as - WildFly, you also can obtain Validator and - ValidatorFactory instances via - @Resource injection in managed objects such as EJBs - etc., as shown in . - - - Retrieving <classname>Validator</classname> and - <classname>ValidatorFactory</classname> via - <classname>@Resource</classname> injection - - package org.hibernate.validator.referenceguide.chapter10.javaee; - -@Stateless -public class RentalStationBean { - - @Resource - private ValidatorFactory validatorFactory; - - @Resource - private Validator validator; - - //... -} - - - Alternatively you can obtain a validator and a validator factory - from JNDI under the names "java:comp/Validator" and - "java:comp/ValidatorFactory", respectively. - - Similar to CDI-based injection via @Inject, - these objects represent default validator and validator factory and thus - can be configured using the XML descriptor - META-INF/validation.xml (see ). - - When your application is CDI-enabled, the injected objects are - CDI-aware as well and e.g. support dependency injection in constraint - validators. -
-
diff --git a/documentation/src/main/docbook/en-US/modules/message-interpolation.xml b/documentation/src/main/docbook/en-US/modules/message-interpolation.xml deleted file mode 100644 index a5895e971a..0000000000 --- a/documentation/src/main/docbook/en-US/modules/message-interpolation.xml +++ /dev/null @@ -1,428 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Interpolating constraint error messages - - Message interpolation is the process of creating error messages for - violated Bean Validation constraints. In this chapter you will learn how - such messages are defined and resolved and how you can plug in custom - message interpolators in case the default algorithm is not sufficient for - your requirements. - -
- Default message interpolation - - Constraint violation messages are retrieved from so called message - descriptors. Each constraint defines its default message descriptor using - the message attribute. At declaration time, the - default descriptor can be overridden with a specific value as shown in - . - - - Specifying a message descriptor using the - <methodname>message</methodname> attribute - - package org.hibernate.validator.referenceguide.chapter04; - -public class Car { - - @NotNull(message = "The manufacturer name must not be null") - private String manufacturer; - - //constructor, getters and setters ... -} - - - If a constraint is violated, its descriptor will be interpolated by - the validation engine using the currently configured - MessageInterpolator. The interpolated error message - can then be retrieved from the resulting constraint violation by calling - ConstraintViolation#getMessage(). - - Message descriptors can contain message - parameters as well as message expressions - which will be resolved during interpolation. Message parameters are string - literals enclosed in {}, while message expressions are - string literals enclosed in ${}. The following - algorithm is applied during method interpolation: - - - - Resolve any message parameters by using them as key for the - resource bundle ValidationMessages. If this - bundle contains an entry for a given message parameter, that parameter - will be replaced in the message with the corresponding value from the - bundle. This step will be executed recursively in case the replaced - value again contains message parameters. The resource bundle is - expected to be provided by the application developer, e.g. by adding a - file named ValidationMessages.properties to the - classpath. You can also create localized error messages by providing - locale specific variations of this bundle, such as - ValidationMessages_en_US.properties. By default, - the JVM's default locale - (Locale#getDefault()) will be used when - looking up messages in the bundle. - - - - Resolve any message parameters by using them as key for a - resource bundle containing the standard error messages for the - built-in constraints as defined in Appendix B of the Bean Validation - specification. In the case of Hibernate Validator, this bundle is - named - org.hibernate.validator.ValidationMessages. If - this step triggers a replacement, step 1 is executed again, otherwise - step 3 is applied. - - - - Resolve any message parameters by replacing them with the value - of the constraint annotation member of the same name. This allows to - refer to attribute values of the constraint (e.g. - Size#min()) in the error message (e.g. "must - be at least ${min}"). - - - - Resolve any message expressions by evaluating them as - expressions of the Unified Expression Language. See to learn - more about the usage of Unified EL in error messages. - - - - - You can find the formal definition of the interpolation algorithm - in section 5.3.1.1 - of the Bean Validation specification. - - -
- Special characters - - Since the characters {, } - and $ have a special meaning in message descriptors - they need to be escaped if you want to use them literally. The following - rules apply: - - \{ is considered as - the literal { - - - - \} is considered as the literal - } - - - - \$ is considered as the literal - $ - - - - \\ is considered as the literal - \ - - -
- -
- Interpolation with message expressions - - As of Hibernate Validator 5 (Bean Validation 1.1) it is possible - to use the Unified Expression Language (as defined by JSR 341) in constraint - violation messages. This allows to define error messages based on - conditional logic and also enables advanced formatting options. The - validation engine makes the following objects available in the EL - context: - - - - the attribute values of the constraint mapped to the attribute - names - - - - the currently validated value (property, bean, method - parameter etc.) under the name - validatedValue - - - - a bean mapped to the name formatter - exposing the var-arg method format(String format, - Object... args) which behaves like - java.util.Formatter.format(String format, Object... - args). - - - - The following section provides several examples for using EL - expressions in error messages. -
- -
- Examples - - shows how to make - use of the different options for specifying message descriptors. - - - Specifying message descriptors - - package org.hibernate.validator.referenceguide.chapter04.complete; - -public class Car { - - @NotNull - private String manufacturer; - - @Size( - min = 2, - max = 14, - message = "The license plate '${validatedValue}' must be between {min} and {max} characters long" - ) - private String licensePlate; - - @Min( - value = 2, - message = "There must be at least {value} seat${value > 1 ? 's' : ''}" - ) - private int seatCount; - - @DecimalMax( - value = "350", - message = "The top speed ${formatter.format('%1$.2f', validatedValue)} is higher " + - "than {value}" - ) - private double topSpeed; - - @DecimalMax(value = "100000", message = "Price must not be higher than ${value}") - private BigDecimal price; - - public Car( - String manufacturer, - String licensePlate, - int seatCount, - double topSpeed, - BigDecimal price) { - this.manufacturer = manufacturer; - this.licensePlate = licensePlate; - this.seatCount = seatCount; - this.topSpeed = topSpeed; - this.price = price; - } - - //getters and setters ... -} - - - Validating an invalid Car instance yields - constraint violations with the messages shown by the assertions in : - - - - the @NotNull constraint on the - manufacturer field causes the error message "may - not be null", as this is the default message defined by the Bean - Validation specification and no specific descriptor is given in the - message attribute - - - - the @Size constraint on the - licensePlate field shows the interpolation of - message parameters ({min}, - {max}) and how to add the validated value to the - error message using the EL expression ${validatedValue} - - - - - the @Min constraint on - seatCount demonstrates how use an EL expression - with a ternery expression to dynamically chose singular or plural - form, depending on an attribute of the constraint ("There must be at - least 1 seat" vs. "There must be at least 2 seats") - - - - the message for the @DecimalMax - constraint on topSpeed shows how to format the - validated value using the formatter object - - - - finally, the @DecimalMax constraint on - price shows that parameter interpolation has - precedence over expression evaluation, causing the - $ sign to show up in front of the maximum - price - - - - - Only actual constraint attributes can be interpolated using - message parameters in the form {attributeName}. When - referring to the validated value or custom expression variables added - to the interpolation context (see ), an EL - expression in the form ${attributeName} must be - used. - - - - Expected error messages - - Car car = new Car( null, "A", 1, 400.123456, BigDecimal.valueOf( 200000 ) ); - -String message = validator.validateProperty( car, "manufacturer" ) - .iterator() - .next() - .getMessage(); -assertEquals( "may not be null", message ); - -message = validator.validateProperty( car, "licensePlate" ) - .iterator() - .next() - .getMessage(); -assertEquals( - "The license plate must be between 2 and 14 characters long", - message -); - -message = validator.validateProperty( car, "seatCount" ).iterator().next().getMessage(); -assertEquals( "There must be at least 2 seats", message ); - -message = validator.validateProperty( car, "topSpeed" ).iterator().next().getMessage(); -assertEquals( "The top speed 400.12 is higher than 350", message ); - -message = validator.validateProperty( car, "price" ).iterator().next().getMessage(); -assertEquals( "Price must not be higher than $100000", message ); - -
-
- -
- Custom message interpolation - - If the default message interpolation algorithm does not fit your - requirements it is also possible to plug in a custom - MessageInterpolator implementation. - - Custom interpolators must implement the interface - javax.validation.MessageInterpolator. Note that - implementations must be thread-safe. It is recommended that custom message - interpolators delegate final implementation to the default interpolator, - which can be obtained via - Configuration#getDefaultMessageInterpolator(). - - In order to use a custom message interpolator it must be registered - either by configuring it in the Bean Validation XML descriptor - META-INF/validation.xml (see ) or by passing it when - bootstrapping a ValidatorFactory or - Validator (see and , respectively). - -
- <classname>ResourceBundleLocator</classname> - - In some use cases you want to use the message interpolation - algorithm as defined by the Bean Validation specification, but retrieve - error messages from other resource bundles than - ValidationMessages. In this situation Hibernate - Validator's ResourceBundleLocator SPI can - help. - - The default message interpolator in Hibernate Validator, - ResourceBundleMessageInterpolator, delegates - retrieval of resource bundles to that SPI. Using an alternative bundle - only requires passing an instance of - PlatformResourceBundleLocator with the bundle - name when bootstrapping the ValidatorFactory as - shown in . - - - Using a specific resource bundle - - Validator validator = Validation.byDefaultProvider() - .configure() - .messageInterpolator( - new ResourceBundleMessageInterpolator( - new PlatformResourceBundleLocator( "MyMessages" ) - ) - ) - .buildValidatorFactory() - .getValidator(); - - - Of course you also could implement a completely different - ResourceBundleLocator, which for instance returns - bundles backed by records in a database. In this case you can obtain the - default locator via - HibernateValidatorConfiguration#getDefaultResourceBundleLocator(), - which you e.g. could use as fallback for your custom locator. - - Besides PlatformResourceBundleLocator, - Hibernate Validator provides another resource bundle locator - implementation out of the box, namely - AggregateResourceBundleLocator, which allows to - retrieve error messages from more than one resource bundle. You could - for instance use this implementation in a multi-module application where - you want to have one message bundle per module. shows how to - use AggregateResourceBundleLocator. - - - Using - <classname>AggregateResourceBundleLocator</classname> - - Validator validator = Validation.byDefaultProvider() - .configure() - .messageInterpolator( - new ResourceBundleMessageInterpolator( - new AggregateResourceBundleLocator( - Arrays.asList( - "MyMessages", - "MyOtherMessages" - ) - ) - ) - ) - .buildValidatorFactory() - .getValidator(); - - - Note that the bundles are processed in the order as passed to the - constructor. That means if several bundles contain an entry for a given - message key, the value will be taken from the first bundle in the list - containing the key. -
-
-
diff --git a/documentation/src/main/docbook/en-US/modules/metadata-api.xml b/documentation/src/main/docbook/en-US/modules/metadata-api.xml deleted file mode 100644 index 82dff3552e..0000000000 --- a/documentation/src/main/docbook/en-US/modules/metadata-api.xml +++ /dev/null @@ -1,684 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Using constraint metadata - - The Bean Validation specification provides not only a validation - engine, but also an API for retrieving constraint metadata in a uniform way, - no matter whether the constraints are declared using annotations or via XML - mappings. Read this chapter to learn more about this API and its - possibilities. You can find all the metadata API types in the package - javax.validation.metadata. - - The examples presented in this chapter are based on the classes and - constraint declarations shown in . - - - Example classes - - package org.hibernate.validator.referenceguide.chapter07; - -public class Person { - - public interface Basic { - } - - @NotNull - private String name; - - //getters and setters ... -} - - public interface Vehicle { - - public interface Basic { - } - - @NotNull(groups = Vehicle.Basic.class) - String getManufacturer(); -} - - @ValidCar -public class Car implements Vehicle { - - public interface SeverityInfo extends Payload { - } - - private String manufacturer; - - @NotNull - @Size(min = 2, max = 14) - private String licensePlate; - - private Person driver; - - private String modelName; - - public Car() { - } - - public Car( - @NotNull String manufacturer, - String licencePlate, - Person driver, - String modelName) { - - this.manufacturer = manufacturer; - this.licensePlate = licencePlate; - this.driver = driver; - this.modelName = modelName; - } - - public void driveAway(@Max(75) int speed) { - //... - } - - @LuggageCountMatchesPassengerCount( - piecesOfLuggagePerPassenger = 2, - validationAppliesTo = ConstraintTarget.PARAMETERS, - payload = SeverityInfo.class, - message = "There must not be more than {piecesOfLuggagePerPassenger} pieces of " + - "luggage per passenger." - ) - public void load(List<Person> passengers, List<PieceOfLuggage> luggage) { - //... - } - - @Override - @Size(min = 3) - public String getManufacturer() { - return manufacturer; - } - - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; - } - - @Valid - @ConvertGroup(from = Default.class, to = Person.Basic.class) - public Person getDriver() { - return driver; - } - - //further getters and setters... -} - - -
- <classname - id="section-bean-descriptor">BeanDescriptor</classname> - - The entry point into the metadata API is the method - Validator#getConstraintsForClass(), which returns an instance - of the BeanDescriptor - interface. Using this descriptor, you can obtain metadata for constraints - declared directly on the bean itself (class- or property-level), but also - retrieve metadata descriptors representing single properties, methods and - constructors. - - demonstrates - how to retrieve a BeanDescriptor for the - Car class and how to use this descriptor in form of - assertions. - - - If a constraint declaration hosted by the requested class is - invalid, a ValidationException is - thrown. - - - - Using <classname>BeanDescriptor</classname> - - Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); - -BeanDescriptor carDescriptor = validator.getConstraintsForClass( Car.class ); - -assertTrue( carDescriptor.isBeanConstrained() ); - -//one class-level constraint -assertEquals( 1, carDescriptor.getConstraintDescriptors().size() ); - -//manufacturer, licensePlate, driver -assertEquals( 3, carDescriptor.getConstrainedProperties().size() ); - -//property has constraint -assertNotNull( carDescriptor.getConstraintsForProperty( "licensePlate" ) ); - -//property is marked with @Valid -assertNotNull( carDescriptor.getConstraintsForProperty( "driver" ) ); - -//constraints from getter method in interface and implementation class are returned -assertEquals( - 2, - carDescriptor.getConstraintsForProperty( "manufacturer" ) - .getConstraintDescriptors() - .size() -); - -//property is not constrained -assertNull( carDescriptor.getConstraintsForProperty( "modelName" ) ); - -//driveAway(int), load(List<Person>, List<PieceOfLuggage>) -assertEquals( 2, carDescriptor.getConstrainedMethods( MethodType.NON_GETTER ).size() ); - -//driveAway(int), getManufacturer(), getDriver(), load(List<Person>, List<PieceOfLuggage>) -assertEquals( - 4, - carDescriptor.getConstrainedMethods( MethodType.NON_GETTER, MethodType.GETTER ) - .size() -); - -//driveAway(int) -assertNotNull( carDescriptor.getConstraintsForMethod( "driveAway", int.class ) ); - -//getManufacturer() -assertNotNull( carDescriptor.getConstraintsForMethod( "getManufacturer" ) ); - -//setManufacturer() is not constrained -assertNull( carDescriptor.getConstraintsForMethod( "setManufacturer", String.class ) ); - -//Car(String, String, Person, String) -assertEquals( 1, carDescriptor.getConstrainedConstructors().size() ); - -//Car(String, String, Person, String) -assertNotNull( - carDescriptor.getConstraintsForConstructor( - String.class, - String.class, - Person.class, - String.class - ) -); - - - You can determine whether the specified class hosts any class- or - property-level constraints via isBeanConstrained(). Method or - constructor constraints are not considered by - isBeanConstrained(). - - The method getConstraintDescriptors() is common to all - descriptors derived from ElementDescriptor (see - ) and returns a - set of descriptors representing the constraints directly declared on the - given element. In case of BeanDescriptor, the - bean's class-level constraints are returned. More details on - ConstraintDescriptor can be found in . - - Via getConstraintsForProperty(), - getConstraintsForMethod() and - getConstraintsForConstructor() you can obtain a - descriptor representing one given property or executable element, - identified by its name and, in case of methods and constructors, parameter - types. The different descriptor types returned by these methods are - described in the following sections. - - Note that these methods consider constraints declared at super-types - according to the rules for constraint inheritance as described in . An example is the descriptor - for the manufacturer property, which provides access to - all constraints defined on - Vehicle#getManufacturer() and the implementing - method Car#getManufacturer(). - null is returned in case the specified element does not - exist or is not constrained. - - The methods getConstrainedProperties(), - getConstrainedMethods() and - getConstrainedConstructors() return (potentially - empty) sets with all constrained properties, methods and constructors, - respectively. An element is considered constrained, if it has at least one - constraint or is marked for cascaded validation. When invoking - getConstrainedMethods(), you can specify the type - of the methods to be returned (getters, non-getters or both). -
- -
- <classname>PropertyDescriptor</classname> - - The interface PropertyDescriptor - represents one given property of a class. It is transparent whether - constraints are declared on a field or a property getter, provided the - JavaBeans naming conventions are respected. shows how to use the - PropertyDescriptor interface. - - - Using <classname>PropertyDescriptor</classname> - - PropertyDescriptor licensePlateDescriptor = carDescriptor.getConstraintsForProperty( - "licensePlate" -); - -//"licensePlate" has two constraints, is not marked with @Valid and defines no group conversions -assertEquals( "licensePlate", licensePlateDescriptor.getPropertyName() ); -assertEquals( 2, licensePlateDescriptor.getConstraintDescriptors().size() ); -assertTrue( licensePlateDescriptor.hasConstraints() ); -assertFalse( licensePlateDescriptor.isCascaded() ); -assertTrue( licensePlateDescriptor.getGroupConversions().isEmpty() ); - -PropertyDescriptor driverDescriptor = carDescriptor.getConstraintsForProperty( "driver" ); - -//"driver" has no constraints, is marked with @Valid and defines one group conversion -assertEquals( "driver", driverDescriptor.getPropertyName() ); -assertTrue( driverDescriptor.getConstraintDescriptors().isEmpty() ); -assertFalse( driverDescriptor.hasConstraints() ); -assertTrue( driverDescriptor.isCascaded() ); -assertEquals( 1, driverDescriptor.getGroupConversions().size() ); - - - Using getConstrainedDescriptors(), you can - retrieve a set of ConstraintDescriptors providing - more information on the individual constraints of a given property. The - method isCascaded() returns - true, if the property is marked for cascaded validation - (either using the @Valid annotation or via XML), - false otherwise. Any configured group conversions are - returned by getGroupConversions(). See for more details on - GroupConversionDescriptor. -
- -
- <classname>MethodDescriptor</classname> and - <classname>ConstructorDescriptor</classname> - - Constrained methods and constructors are represented by the - interfaces MethodDescriptor - and ConstructorDescriptor, - respectively. - demonstrates how to work with these descriptors. - - - Using <classname>MethodDescriptor</classname> and - <classname>ConstructorDescriptor</classname> - - //driveAway(int) has a constrained parameter and an unconstrained return value -MethodDescriptor driveAwayDescriptor = carDescriptor.getConstraintsForMethod( - "driveAway", - int.class -); -assertEquals( "driveAway", driveAwayDescriptor.getName() ); -assertTrue( driveAwayDescriptor.hasConstrainedParameters() ); -assertFalse( driveAwayDescriptor.hasConstrainedReturnValue() ); - -//always returns an empty set; constraints are retrievable by navigating to -//one of the sub-descriptors, e.g. for the return value -assertTrue( driveAwayDescriptor.getConstraintDescriptors().isEmpty() ); - -ParameterDescriptor speedDescriptor = driveAwayDescriptor.getParameterDescriptors() - .get( 0 ); - -//The "speed" parameter is located at index 0, has one constraint and is not cascaded -//nor does it define group conversions -assertEquals( "arg0", speedDescriptor.getName() ); -assertEquals( 0, speedDescriptor.getIndex() ); -assertEquals( 1, speedDescriptor.getConstraintDescriptors().size() ); -assertFalse( speedDescriptor.isCascaded() ); -assert speedDescriptor.getGroupConversions().isEmpty(); - -//getDriver() has no constrained parameters but its return value is marked for cascaded -//validation and declares one group conversion -MethodDescriptor getDriverDescriptor = carDescriptor.getConstraintsForMethod( - "getDriver" -); -assertFalse( getDriverDescriptor.hasConstrainedParameters() ); -assertTrue( getDriverDescriptor.hasConstrainedReturnValue() ); - -ReturnValueDescriptor returnValueDescriptor = getDriverDescriptor.getReturnValueDescriptor(); -assertTrue( returnValueDescriptor.getConstraintDescriptors().isEmpty() ); -assertTrue( returnValueDescriptor.isCascaded() ); -assertEquals( 1, returnValueDescriptor.getGroupConversions().size() ); - -//load(List<Person>, List<PieceOfLuggage>) has one cross-parameter constraint -MethodDescriptor loadDescriptor = carDescriptor.getConstraintsForMethod( - "load", - List.class, - List.class -); -assertTrue( loadDescriptor.hasConstrainedParameters() ); -assertFalse( loadDescriptor.hasConstrainedReturnValue() ); -assertEquals( - 1, - loadDescriptor.getCrossParameterDescriptor().getConstraintDescriptors().size() -); - -//Car(String, String, Person, String) has one constrained parameter -ConstructorDescriptor constructorDescriptor = carDescriptor.getConstraintsForConstructor( - String.class, - String.class, - Person.class, - String.class -); - -assertEquals( "Car", constructorDescriptor.getName() ); -assertFalse( constructorDescriptor.hasConstrainedReturnValue() ); -assertTrue( constructorDescriptor.hasConstrainedParameters() ); -assertEquals( - 1, - constructorDescriptor.getParameterDescriptors() - .get( 0 ) - .getConstraintDescriptors() - .size() -); - - - getName() returns the name of the given - method or constructor. The methods - hasConstrainedParameters() and - hasConstrainedReturnValue() can be used to - perform a quick check whether an executable element has any parameter - constraints (either constraints on single parameters or cross-parameter - constraints) or return value constraints. - - Note that any constraints are not directly exposed on - MethodDescriptor and - ConstructorDescriptor, but rather on dedicated - descriptors representing an executable's parameters, its return value and - its cross-parameter constraints. To get hold of one of these descriptors, - invoke getParameterDescriptors(), - getReturnValueDescriptor() or - getCrossParameterDescriptor(), - respectively. - - These descriptors provide access to the element's constraints - (getConstraintDescriptors()) and, in case of - parameters and return value, to its configuration for cascaded validation - (isValid() and - getGroupConversions()). For parameters, you also - can retrieve the index and the name, as returned by the currently used - parameter name provider (see ) via - getName() and - getIndex(). - - - Getter methods following the JavaBeans naming conventions are - considered as bean properties but also as constrained methods. - - That means you can retrieve the related metadata either by - obtaining a PropertyDescriptor (e.g. - BeanDescriptor.getConstraintsForProperty("foo")) or by - examining the return value descriptor of the getter's - MethodDescriptor (e.g. - BeanDescriptor.getConstraintsForMethod("getFoo").getReturnValueDescriptor()). - -
- -
- <classname>ElementDescriptor</classname> - - The ElementDiscriptor - interface is the common base class for the individual descriptor types - such as BeanDescriptor, - PropertyDescriptor etc. Besides - getConstraintDescriptors() it provides some more - methods common to all descriptors. - - hasConstraints() allows for a quick check whether an - element has any direct constraints (e.g. class-level constraints in case - of BeanDescriptor). - getElementClass() returns the Java type of the - element represented by a given descriptor. More specifically, the method - returns - - - - the object type when invoked on - BeanDescriptor, - - - - the type of a property or parameter when invoked on - PropertyDescriptor or - ParameterDescriptor respectively, - - - - Object[].class when invoked on - CrossParameterDescriptor, - - - - the return type when invoked on - ConstructorDescriptor, - MethodDescriptor or - ReturnValueDescriptor. - void.class will be returned for methods which - don't have a return value. - - - - shows how - these methods are used. - - - Using <classname>ElementDescriptor</classname> methods - - PropertyDescriptor manufacturerDescriptor = carDescriptor.getConstraintsForProperty( - "manufacturer" -); - -assertTrue( manufacturerDescriptor.hasConstraints() ); -assertEquals( String.class, manufacturerDescriptor.getElementClass() ); - -CrossParameterDescriptor loadCrossParameterDescriptor = carDescriptor.getConstraintsForMethod( - "load", - List.class, - List.class -).getCrossParameterDescriptor(); - -assertTrue( loadCrossParameterDescriptor.hasConstraints() ); -assertEquals( Object[].class, loadCrossParameterDescriptor.getElementClass() ); - - - Finally, ElementDescriptor offers access to - the ConstraintFinder API which allows you to query - for constraint metadata in a fine grained way. shows how to retrieve a - ConstraintFinder instance via - findConstraints() and use the API to query for - constraint metadata. - - - Usage of ConstraintFinder - - PropertyDescriptor manufacturerDescriptor = carDescriptor.getConstraintsForProperty( - "manufacturer" -); - -//"manufacturer" constraints are declared on the getter, not the field -assertTrue( - manufacturerDescriptor.findConstraints() - .declaredOn( ElementType.FIELD ) - .getConstraintDescriptors() - .isEmpty() -); - -//@NotNull on Vehicle#getManufacturer() is part of another group -assertEquals( - 1, - manufacturerDescriptor.findConstraints() - .unorderedAndMatchingGroups( Default.class ) - .getConstraintDescriptors() - .size() -); - -//@Size on Car#getManufacturer() -assertEquals( - 1, - manufacturerDescriptor.findConstraints() - .lookingAt( Scope.LOCAL_ELEMENT ) - .getConstraintDescriptors() - .size() -); - -//@Size on Car#getManufacturer() and @NotNull on Vehicle#getManufacturer() -assertEquals( - 2, - manufacturerDescriptor.findConstraints() - .lookingAt( Scope.HIERARCHY ) - .getConstraintDescriptors() - .size() -); - -//Combining several filter options -assertEquals( - 1, - manufacturerDescriptor.findConstraints() - .declaredOn( ElementType.METHOD ) - .lookingAt( Scope.HIERARCHY ) - .unorderedAndMatchingGroups( Vehicle.Basic.class ) - .getConstraintDescriptors() - .size() -); - - - Via declaredOn() you can search for - ConstraintDescriptors declared on certain element - types. This is useful to find property constraints declared on either - fields or getter methods. - - unorderedAndMatchingGroups() restricts the - resulting constraints to those matching the given validation - group(s). - - lookingAt() allows to distinguish between - constraints directly specified on the element - (Scope.LOCAL_ELEMENT) or constraints belonging to the - element but hosted anywhere in the class hierarchy - (Scope.HIERARCHY). - - You can also combine the different options as shown in the last - example. - - - Order is not respected by - unorderedAndMatchingGroups(), but group - inheritance and inheritance via sequence are. - -
- -
- <classname>GroupConversionDescriptor</classname> - - All those descriptor types that represent elements which can be - subject of cascaded validation (i.e., - PropertyDescriptor, - ParameterDescriptor and - ReturnValueDescriptor) provide access to the - element's group conversions via - getGroupConversions(). The returned set contains - a GroupConversionDescriptor - for each configured conversion, allowing to retrieve source and target - groups of the conversion. shows an - example. - - - Using <classname>GroupConversionDescriptor</classname> - - PropertyDescriptor driverDescriptor = carDescriptor.getConstraintsForProperty( "driver" ); - -Set<GroupConversionDescriptor> groupConversions = driverDescriptor.getGroupConversions(); -assertEquals( 1, groupConversions.size() ); - -GroupConversionDescriptor groupConversionDescriptor = groupConversions.iterator() - .next(); -assertEquals( Default.class, groupConversionDescriptor.getFrom() ); -assertEquals( Person.Basic.class, groupConversionDescriptor.getTo() ); - -
- -
- <classname>ConstraintDescriptor</classname> - - Last but not least, the ConstraintDescriptor - interface describes a single constraint together with its composing - constraints. Via an instance of this interface you get access to the - constraint annotation and its parameters. - - shows - how to retrieve default constraint attributes (such as message template, - groups etc.) as well as custom constraint attributes - (piecesOfLuggagePerPassenger) and other metadata such - as the constraint's annotation type and its validators from a - ConstraintDescriptor. - - - Using <classname>ConstraintDescriptor</classname> - - //descriptor for the @LuggageCountMatchesPassengerCount constraint on the -//load(List<Person>, List<PieceOfLuggage>) method -ConstraintDescriptor<?> constraintDescriptor = carDescriptor.getConstraintsForMethod( - "load", - List.class, - List.class -).getCrossParameterDescriptor().getConstraintDescriptors().iterator().next(); - -//constraint type -assertEquals( - LuggageCountMatchesPassengerCount.class, - constraintDescriptor.getAnnotation().annotationType() -); - -//standard constraint attributes -assertEquals( SeverityInfo.class, constraintDescriptor.getPayload().iterator().next() ); -assertEquals( - ConstraintTarget.PARAMETERS, - constraintDescriptor.getValidationAppliesTo() -); -assertEquals( Default.class, constraintDescriptor.getGroups().iterator().next() ); -assertEquals( - "There must not be more than {piecesOfLuggagePerPassenger} pieces of luggage per " + - "passenger.", - constraintDescriptor.getMessageTemplate() -); - -//custom constraint attribute -assertEquals( - 2, - constraintDescriptor.getAttributes().get( "piecesOfLuggagePerPassenger" ) -); - -//no composing constraints -assertTrue( constraintDescriptor.getComposingConstraints().isEmpty() ); - -//validator class -assertEquals( - Arrays.<Class<?>>asList( LuggageCountMatchesPassengerCount.Validator.class ), - constraintDescriptor.getConstraintValidatorClasses() -); - -
-
diff --git a/documentation/src/main/docbook/en-US/modules/method-constraints.xml b/documentation/src/main/docbook/en-US/modules/method-constraints.xml deleted file mode 100644 index ad8e39743f..0000000000 --- a/documentation/src/main/docbook/en-US/modules/method-constraints.xml +++ /dev/null @@ -1,931 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Declaring and validating method constraints - - As of Bean Validation 1.1, constraints can not only be applied to - JavaBeans and their properties, but also to the parameters and return values - of the methods and constructors of any Java type. That way Bean Validation - constraints can be used to specify - - - - the preconditions that must be satisfied by the caller before a - method or constructor may be invoked (by applying constraints to the - parameters of an executable) - - - - the postconditions that are guaranteed to the caller after a - method or constructor invocation returns (by applying constraints to the - return value of an executable) - - - - - For the purpose of this reference guide, the term method - constraint refers to both, method and constructor constraints, - if not stated otherwise. Ocassionally, the term - executable is used when referering to methods and - constructors. - - - This approach has several advantages over traditional ways of checking - the correctness of parameters and return values: - - - - the checks don't have to be performed manually (e.g. by throwing - IllegalArgumentExceptions or similar), resulting - in less code to write and maintain - - - - an executable's pre- and postconditions don't have to be expressed - again in its documentation, since the constraint annotations will - automatically be included in the generated JavaDoc. This avoids - redundancies and reduces the chance of inconsistencies between - implementation and documentation - - - - - In order to make annotations show up in the JavaDoc of annoted - elements, the annotation types themselves must be annotated with the meta - annotation @Documented. This is the case for all - built-in constraints and is considered a best practice for any custom - constraints. - - - In the remainder of this chapter you will learn how to declare - parameter and return value constraints and how to validate them using the - ExecutableValidator API. - -
- Declaring method constraints - -
- Parameter constraints - - You specify the preconditions of a method or constructor by adding - constraint annotations to its parameters as demonstrated in . - - - Declaring method and constructor parameter constraints - - package org.hibernate.validator.referenceguide.chapter03.parameter; - -public class RentalStation { - - public RentalStation(@NotNull String name) { - //... - } - - public void rentCar( - @NotNull Customer customer, - @NotNull @Future Date startDate, - @Min(1) int durationInDays) { - //... - } -} - - - The following preconditions are declared here: - - - - The name passed to the RentalCar - constructor must not be null - - - - When invoking the rentCar() method, - the given customer must not be null, the rental's - start date must not be null and must be in the - future and the rental duration must be at least one day - - - - Note that declaring method or constructor constraints itself does - not automatically cause their validation upon invocation of the - executable. Instead, the ExecutableValidator API (see ) must be used to - perform the validation, which is often done using a method interception - facility such as AOP, proxy objects etc. - - Constraints may only be applied to instance methods, i.e. - declaring constraints on static methods is not supported. Depending on - the interception facility you use for triggering method validation, - additional restrictions may apply, e.g. with respect to the visibility - of methods supported as target of interception. Refer to the - documentation of the interception technology to find out whether any - such limitations exist. - -
- Cross-parameter constraints - - Sometimes validation does not only depend on a single parameter - but on several or even all parameters of a method or constructor. This - kind of requirement can be fulfilled with help of a cross-parameter - constraint. - - Cross-parameter constraints can be considered as the method - validation equivalent to class-level constraints. Both can be used to - implement validation requirements which are based on several elements. - While class-level constraints apply to several properties of a bean, - cross-parameter constraints apply to several parameters of an - executable. - - In contrast to single-parameter constraints, cross-parameter - constraints are declared on the method or constructor as you can see - in . Here - the cross-parameter constraint - @LuggageCountMatchesPassengerCount declared on - the load() method is used to ensure that no - passenger has more than two pieces of luggage. - - - Declaring a cross-parameter constraint - - package org.hibernate.validator.referenceguide.chapter03.crossparameter; - -public class Car { - - @LuggageCountMatchesPassengerCount(piecesOfLuggagePerPassenger = 2) - public void load(List<Person> passengers, List<PieceOfLuggage> luggage) { - //... - } -} - - - As you will learn in the next section, return value constraints - are also declared on the method level. In order to distinguish - cross-parameter constraints from return value constraints, the - constraint target is configured in the - ConstraintValidator implementation using the - @SupportedValidationTarget annotation. You can - find out about the details in which shows how to - implement your own cross-parameter constraint. - - In some cases a constraint can be applied to an executable's - parameters (i.e. it is a cross-parameter constraint), but also to the - return value. One example for this are custom constraints which allow - to specify validation rules using expression or script - languages. - - Such constraints must define a member - validationAppliesTo() which can be used at - declaration time to specify the constraint target. As shown in you apply the - constraint to an executable's parameters by specifying - validationAppliesTo = ConstraintTarget.PARAMETERS, - while ConstraintTarget.RETURN_VALUE is used to - apply the constraint to the executable return value. - - - Specifying a constraint's target - - package org.hibernate.validator.referenceguide.chapter03.crossparameter.constrainttarget; - -public class Garage { - - @ELAssert(expression = "...", validationAppliesTo = ConstraintTarget.PARAMETERS) - public Car buildCar(List<Part> parts) { - //... - } - - @ELAssert(expression = "...", validationAppliesTo = ConstraintTarget.RETURN_VALUE) - public Car paintCar(int color) { - //... - } -} - - - Although such a constraint is applicable to the parameters and - return value of an executable, the target can often be inferred - automatically. This is the case, if the constraint is declared - on - - - - a void method with parameters (the constraint applies to the - parameters) - - - - an executable with return value but no parameters (the - constraint applies to the return value) - - - - neither a method nor a constructor, but a field, parameter - etc. (the constraint applies to the annotated element) - - - - In these situations you don't have to specify the constraint - target. It is still recommended to do so if it increases readability - of the source code. If the constraint target is not specified in - situations where it can't be determined automatically, a - ConstraintDeclarationException is - raised. -
-
- -
- Return value constraints - - The postconditions of a method or constructor are declared by - adding constraint annotations to the executable as shown in . - - - Declaring method and constructor return value - constraints - - package org.hibernate.validator.referenceguide.chapter03.returnvalue; - -public class RentalStation { - - @ValidRentalStation - public RentalStation() { - //... - } - - @NotNull - @Size(min = 1) - public List<Customer> getCustomers() { - //... - } -} - - - The following constraints apply to the executables of - RentalStation: - - - - Any newly created RentalStation object - must satisfy the @ValidRentalStation - constraint - - - - The customer list returned by - getCustomers() must not be - null and must contain at least on element - - -
- -
- Cascaded - validation - - Similar to the cascaded validation of JavaBeans properties (see - ), the - @Valid annotation can be used to mark executable - parameters and return values for cascaded validation. When validating a - parameter or return value annotated with @Valid, - the constraints declared on the parameter or return value object are - validated as well. - - In , the - car parameter of the method - Garage#checkCar() as well as the return value - of the Garage constructor are marked for cascaded - validation. - - - Marking executable parameters and return values for cascaded - validation - - package org.hibernate.validator.referenceguide.chapter03.cascaded; - -public class Garage { - - @NotNull - private String name; - - @Valid - public Garage(String name) { - this.name = name; - } - - public boolean checkCar(@Valid @NotNull Car car) { - //... - } -} - - package org.hibernate.validator.referenceguide.chapter03.cascaded; - -public class Car { - - @NotNull - private String manufacturer; - - @NotNull - @Size(min = 2, max = 14) - private String licensePlate; - - public Car(String manufacturer, String licencePlate) { - this.manufacturer = manufacturer; - this.licensePlate = licencePlate; - } - - //getters and setters ... -} - - - When validating the arguments of the - checkCar() method, the constraints on the - properties of the passed Car object are evaluated - as well. Similarly, the @NotNull constraint on - the name field of Garage is - checked when validating the return value of the - Garage constructor. - - Generally, the cascaded validation works for executables in - exactly the same way as it does for JavaBeans properties. - - In particular, null values are ignored during - cascaded validation (naturally this can't happen during constructor - return value validation) and cascaded validation is performed - recursively, i.e. if a parameter or return value object which is marked - for cascaded validation itself has properties marked with - @Valid, the constraints declared on the - referenced elements will be validated as well. - - Cascaded validation can not only be applied to simple object - references but also to collection-typed parameters and return values. - This means when putting the @Valid annotation to - a parameter or return value which - - - - is an array - - - - implements java.lang.Iterable - - - - or implements java.util.Map - - - - each contained element gets validated. So when validating the - arguments of the checkCars() method in , each - element instance of the passed list will be validated and a - ConstraintViolation created when any of the - contained Car objects is invalid. - - - List-typed method parameter marked for cascaded - validation - - package org.hibernate.validator.referenceguide.chapter03.cascaded.collection; - -public class Garage { - - public boolean checkCars(@Valid @NotNull List<Car> cars) { - //... - } -} - -
- -
- Method constraints in - inheritance hierarchies - - When declaring method constraints in inheritance hierarchies, it - is important to be aware of the following rules: - - - - The preconditions to be satisified by the caller of a method - may not be strengthened in subtypes - - - - The postconditions guaranteed to the caller of a method may - not be weakened in subtypes - - - - These rules are motivated by the concept of behavioral - subtyping which requires that wherever a type - T is used, also a subtype - S of T may be used without - altering the program's behavior. - - As an example, consider a class invoking a method on an object - with the static type T. If the runtime type of - that object was S and S - imposed additional preconditions, the client class might fail to satisfy - these preconditions as is not aware of them. The rules of behavioral - subtyping are also known as the Liskov - substitution principle. - - The Bean Validation specification implements the first rule by - disallowing parameter constraints on methods which override or implement - a method declared in a supertype (superclass or interface). shows a violation of - this rule. - - - Illegal method parameter constraint in subtype - - package org.hibernate.validator.referenceguide.chapter03.inheritance.parameter; - -public interface Vehicle { - - void drive(@Max(75) int speedInMph); -} - - package org.hibernate.validator.referenceguide.chapter03.inheritance.parameter; - -public class Car implements Vehicle { - - @Override - public void drive(@Max(55) int speedInMph) { - //... - } -} - - - The @Max constraint on - Car#drive() is illegal since this method - implements the interface method - Vehicle#drive(). Note that parameter - constraints on overriding methods are also disallowed, if the supertype - method itself doesn't declare any parameter constraints. - - Furthermore, if a method overrides or implements a method declared - in several parallel supertypes (e.g. two interfaces not extending each - other or a class and an interface not implemented by that class), no - parameter constraints may be specified for the method in any of the - involved types. The types in - demonstrate a violation of that rule. The method - RacingCar#drive() overrides - Vehicle#drive() as well as - Car#drive(). Therefore the constraint on - Vehicle#drive() is illegal. - - - Illegal method parameter constraint in parallel types of a - hierarchy - - package org.hibernate.validator.referenceguide.chapter03.inheritance.parallel; - -public interface Vehicle { - - void drive(@Max(75) int speedInMph); -} - - package org.hibernate.validator.referenceguide.chapter03.inheritance.parallel; - -public interface Car { - - public void drive(int speedInMph); -} - - package org.hibernate.validator.referenceguide.chapter03.inheritance.parallel; - -public class RacingCar implements Car, Vehicle { - - @Override - public void drive(int speedInMph) { - //... - } -} - - - The previously described restrictions only apply to parameter - constraints. In contrast, return value constraints may be added in - methods overriding or implementing any supertype methods. - - In this case, all the method's return value constraints apply for - the subtype method, i.e. the constraints declared on the subtype method - itself as well as any return value constraints on overridden/implemented - supertype methods. This is legal as putting additional return value - constraints in place may never represent a weakening of the - postconditions guaranteed to the caller of a method. - - So when validating the return value of the method - Car#getPassengers() shown in , the - @Size constraint on the method itself as well as - the @NotNull constraint on the implemented - interface method Vehicle#getPassengers() - apply. - - - Return value constraints on supertype and subtype - method - - package org.hibernate.validator.referenceguide.chapter03.inheritance.returnvalue; - -public interface Vehicle { - - @NotNull - List<Person> getPassengers(); -} - - package org.hibernate.validator.referenceguide.chapter03.inheritance.returnvalue; - -public class Car implements Vehicle { - - @Override - @Size(min = 1) - public List<Person> getPassengers() { - //... - } -} - - - If the validation engine detects a violation of any of the - aforementioned rules, a - ConstraintDeclarationException will be - raised. - - - The rules described in this section only apply to methods but - not constructors. By definition, constructors never override supertype - constructors. Therefore, when validating the parameters or the return - value of a constructor invocation only the constraints declared on the - constructor itself apply, but never any constraints declared on - supertype constructors. - -
-
- -
- Validating method constraints - - The validation of method constraints is done using the - ExecutableValidator interface. - - In you will - learn how to obtain an ExecutableValidator instance - while shows how to - use the different methods offered by this interface. - - Instead of calling the ExecutableValidator methods directly from - within application code, they are usually invoked via a method - interception technology such as AOP, proxy objects, etc. This causes - executable constraints to be validated automatically and transparently - upon method or constructor invocation. Typically a - ConstraintViolationException is raised by the - integration layer in case any of the constraints is violated. - -
- Obtaining an <classname>ExecutableValidator</classname> - instance - - You can retrieve an ExecutableValidator - instance via Validator#forExecutables() as shown - in . - - - Obtaining an ExecutableValidator - - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); -executableValidator = factory.getValidator().forExecutables(); - - - In the example the executable validator is retrieved from the - default validator factory, but if required you could also bootstrap a - specifically configured factory as described in , for instance in order to use a - specific parameter name provider (see ). -
- -
- <classname>ExecutableValidator</classname> methods - - The ExecutableValidator interface offers - altogether four methods: - - - - validateParameters() and - validateReturnValue() for method - validation - - - - validateConstructorParameters() and - validateConstructorReturnValue() for - constructor validation - - - - Just as the methods on Validator, all these - methods return a Set<ConstraintViolation> - which contains a ConstraintViolation instance for - each violated constraint and which is empty if the validation succeeds. - Also all the methods have a var-args groups parameter - by which you can pass the validation groups to be considered for - validation. - - The examples in the following sections are based on the methods on - constructors of the Car class shown in . - - - Class <classname>Car</classname> with constrained methods and - constructors - - package org.hibernate.validator.referenceguide.chapter03.validation; - -public class Car { - - public Car(@NotNull String manufacturer) { - //... - } - - @ValidRacingCar - public Car(String manufacturer, String team) { - //... - } - - public void drive(@Max(75) int speedInMph) { - //... - } - - @Size(min = 1) - public List<Passenger> getPassengers() { - //... - } -} - - -
- <methodname>ExecutableValidator#validateParameters()</methodname> - - The method validateParameters() is used - to validate the arguments of a method invocation. shows an - example. The validation results in a violation of the - @Max constraint on the parameter of the - drive() method. - - - Using - <methodname>ExecutableValidator#validateParameters()</methodname> - - Car object = new Car( "Morris" ); -Method method = Car.class.getMethod( "drive", int.class ); -Object[] parameterValues = { 80 }; -Set<ConstraintViolation<Car>> violations = executableValidator.validateParameters( - object, - method, - parameterValues -); - -assertEquals( 1, violations.size() ); -Class<? extends Annotation> constraintType = violations.iterator() - .next() - .getConstraintDescriptor() - .getAnnotation() - .annotationType(); -assertEquals( Max.class, constraintType ); - - - Note that validateParameters() - validates all the parameter constraints of a method, i.e. constraints - on individual parameters as well as cross-parameter - constraints. -
- -
- <methodname>ExecutableValidator#validateReturnValue()</methodname> - - Using validateReturnValue() the return - value of a method can can be validated. The validation in yields - one constraint violation since the - getPassengers() method is expect to return at - least one Passenger object. - - - Using - <methodname>ExecutableValidator#validateReturnValue()</methodname> - - Car object = new Car( "Morris" ); -Method method = Car.class.getMethod( "getPassengers" ); -Object returnValue = Collections.<Passenger>emptyList(); -Set<ConstraintViolation<Car>> violations = executableValidator.validateReturnValue( - object, - method, - returnValue -); - -assertEquals( 1, violations.size() ); -Class<? extends Annotation> constraintType = violations.iterator() - .next() - .getConstraintDescriptor() - .getAnnotation() - .annotationType(); -assertEquals( Size.class, constraintType ); - -
- -
- <methodname>ExecutableValidator#validateConstructorParameters()</methodname> - - The arguments of constructor invocations can be validated with - validateConstructorParameters() as shown in - method . - Due to the @NotNull constraint on the - manufacturer parameter, the validation call returns - one constraint violation. - - - Using - <methodname>ExecutableValidator#validateConstructorParameters()</methodname> - - Constructor<Car> constructor = Car.class.getConstructor( String.class ); -Object[] parameterValues = { null }; -Set<ConstraintViolation<Car>> violations = executableValidator.validateConstructorParameters( - constructor, - parameterValues -); - -assertEquals( 1, violations.size() ); -Class<? extends Annotation> constraintType = violations.iterator() - .next() - .getConstraintDescriptor() - .getAnnotation() - .annotationType(); -assertEquals( NotNull.class, constraintType ); - -
- -
- <methodname>ExecutableValidator#validateConstructorReturnValue()</methodname> - - Finally, by using - validateConstructorReturnValue() you can - valide a constructor's return value. In , - validateConstructorReturnValue() returns one - constraint violation, since the Car object - returned by the constructor doesn't satisfy the - @ValidRacingCar constraint (not shown). - - - Using - <methodname>ExecutableValidator#validateConstructorReturnValue()</methodname> - - //constructor for creating racing cars -Constructor<Car> constructor = Car.class.getConstructor( String.class, String.class ); -Car createdObject = new Car( "Morris", null ); -Set<ConstraintViolation<Car>> violations = executableValidator.validateConstructorReturnValue( - constructor, - createdObject -); - -assertEquals( 1, violations.size() ); -Class<? extends Annotation> constraintType = violations.iterator() - .next() - .getConstraintDescriptor() - .getAnnotation() - .annotationType(); -assertEquals( ValidRacingCar.class, constraintType ); - -
-
- -
- <classname>ConstraintViolation</classname> methods for method - validation - - In addition to the methods introduced in , - ConstraintViolation provides two more methods - specific to the validation of executable parameters and return - values. - - ConstraintViolation#getExecutableParameters() - returns the validated parameter array in case of method or constructor - parameter validation, while - ConstraintViolation#getExecutableReturnValue() - provides access to the validated object in case of return value - validation. - - All the other ConstraintViolation methods - generally work for method validation in the same way as for validation - of beans. Refer to the JavaDoc - to learn more about the behavior of the individual methods and their - return values during bean and method validation. - - Note that getPropertyPath() can be very - useful in order to obtain detailed information about the validated - parameter or return value, e.g. for logging purposes. In particular, you - can retrieve name and argument types of the concerned method as well as - the index of the concerned parameter from the path nodes. How this can - be done is shown in . - - - Retrieving method and parameter information - - Car object = new Car( "Morris" ); -Method method = Car.class.getMethod( "drive", int.class ); -Object[] parameterValues = { 80 }; -Set<ConstraintViolation<Car>> violations = executableValidator.validateParameters( - object, - method, - parameterValues -); - -assertEquals( 1, violations.size() ); -Iterator<Node> propertyPath = violations.iterator() - .next() - .getPropertyPath() - .iterator(); - -MethodNode methodNode = propertyPath.next().as( MethodNode.class ); -assertEquals( "drive", methodNode.getName() ); -assertEquals( Arrays.<Class<?>>asList( int.class ), methodNode.getParameterTypes() ); - -ParameterNode parameterNode = propertyPath.next().as( ParameterNode.class ); -assertEquals( "arg0", parameterNode.getName() ); -assertEquals( 0, parameterNode.getParameterIndex() ); - - - The parameter name is determined using the current - ParameterNameProvider (see ) and defaults to - arg0, arg1 etc. -
-
- -
- Built-in method constraints - - In addition to the built-in bean and property-level constraints - discussed in , Hibernate - Validator currently provides one method-level constraint, - @ParameterScriptAssert. This is a generic - cross-parameter constraint which allows to implement validation routines - using any JSR 223 compatible ("Scripting for the - JavaTM Platform") scripting language, provided - an engine for this language is available on the classpath. - - To refer to the executable's parameters from within the expression, - use their name as obtained from the active parameter name provider (see - ). shows how the validation logic - of the @LuggageCountMatchesPassengerCount - constraint from - could be expressed with the help of - @ParameterScriptAssert. - - - Using <classname>@ParameterScriptAssert</classname> - - package org.hibernate.validator.referenceguide.chapter03.parametersscriptassert; - -public class Car { - - @ParameterScriptAssert(lang = "javascript", script = "arg1.size() <= arg0.size() * 2") - public void load(List<Person> passengers, List<PieceOfLuggage> luggage) { - //... - } -} - -
-
diff --git a/documentation/src/main/docbook/en-US/modules/preface.xml b/documentation/src/main/docbook/en-US/modules/preface.xml deleted file mode 100644 index 84e1e6dd7f..0000000000 --- a/documentation/src/main/docbook/en-US/modules/preface.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Preface - - Validating data is a common task that occurs throughout all - application layers, from the presentation to the persistence layer. Often - the same validation logic is implemented in each layer which is time - consuming and error-prone. To avoid duplication of these validations, - developers often bundle validation logic directly into the domain model, - cluttering domain classes with validation code which is really metadata - about the class itself. - - - - - - - - - - - - JSR 349 - Bean Validation 1.1 - defines a metadata model and API for - entity and method validation. The default metadata source are annotations, - with the ability to override and extend the meta-data through the use of - XML. The API is not tied to a specific application tier nor programming - model. It is specifically not tied to either web or persistence tier, and is - available for both server-side application programming, as well as rich - client Swing application developers. - - - - - - - - - - - - Hibernate Validator is the reference implementation of this JSR 349. - The implementation itself as well as the Bean Validation API and TCK are all - provided and distributed under the Apache Software License - 2.0. - diff --git a/documentation/src/main/docbook/en-US/modules/xml-configuration.xml b/documentation/src/main/docbook/en-US/modules/xml-configuration.xml deleted file mode 100644 index 7ec6349e05..0000000000 --- a/documentation/src/main/docbook/en-US/modules/xml-configuration.xml +++ /dev/null @@ -1,371 +0,0 @@ - - - -%BOOK_ENTITIES; -]> - - Configuring via XML - - So far we have used the default configuration source for Bean - Validation, namely annotations. However, there also exist two kinds of XML - descriptors allowing configuration via XML. The first descriptor describes - general Bean Validation behaviour and is provided as - META-INF/validation.xml. The second one describes - constraint declarations and closely matches the constraint declaration - approach via annotations. Let's have a look at these two document - types. - The XSD files are available via http://www.jboss.org/xml/ns/javax/validation/configuration - and http://www.jboss.org/xml/ns/javax/validation/mapping. - - -
- Configuring the validator factory in - <filename>validation.xml</filename> - - The key to enable XML configuration for Hibernate Validator is the - file META-INF/validation.xml. If this file exists on - the classpath its configuration will be applied when the - ValidatorFactory gets created. shows a model view of the XML - schema to which validation.xml has to adhere. - validation-configuration-1.1.xsd - - - - - - - - - - - - - shows the several - configuration options of validation.xml. All settings - are optional and the same configuration options are also available - programmatically through - javax.validation.Configuration. In fact the XML - configuration will be overridden by values explicitly specified via the - programmatic API. It is even possible to ignore the XML configuration - completely via - Configuration#ignoreXmlConfiguration(). See also - . - - - validation.xml - - <validation-config - xmlns="http://jboss.org/xml/ns/javax/validation/configuration" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration"> - - <default-provider>com.acme.ValidationProvider</default-provider> - - <message-interpolator>com.acme.MessageInterpolator</message-interpolator> - <traversable-resolver>com.acme.TraversableResolver</traversable-resolver> - <constraint-validator-factory> - com.acme.ConstraintValidatorFactory - </constraint-validator-factory> - <parameter-name-provider>com.acme.ParameterNameProvider</parameter-name-provider> - - <executable-validation enabled="true"> - <default-validated-executable-types> - <executable-type>CONSTRUCTORS</executable-type> - <executable-type>NON_GETTER_METHODS</executable-type> - <executable-type>GETTER_METHODS</executable-type> - </default-validated-executable-types> - </executable-validation> - - <constraint-mapping>META-INF/validation/constraints-car.xml</constraint-mapping> - - <property name="hibernate.validator.fail_fast">false</property> -</validation-config> - - - - There must only be one file named - META-INF/validation.xml on the classpath. If more - than one is found an exception is thrown. - - - The node default-provider allows to choose the - Bean Validation provider. This is useful if there is more than one - provider on the classpath. message-interpolator, - traversable-resolver, - constraint-validator-factory and - parameter-name-provider allow to customize the used - implementations for the interfaces - MessageInterpolator, - TraversableResolver, - ConstraintValidatorFactory and - ParameterNameProvider defined in the - javax.validation package. See the sub-sections of - for more - information about these interfaces. - - executable-validation and its subnodes define - defaults for method validation. The Bean Validation specification defines - constructor and non getter methods as defaults. The - enabled attribute acts as global switch to turn - method validation on and off (see also ). - - Via the constraint-mapping element you can list - an arbitrary number of additional XML files containing the actual - constraint configuration. Mapping file names must be specified using their - fully-qualified name on the classpath. Details on writing mapping files - can be found in the next section. - - Last but not least, you can specify provider specific properties via - the property nodes. In the example we are using the - Hibernate Validator specific - hibernate.validator.fail_fast property (see ). -
- -
- Mapping constraints via - <property>constraint-mappings</property> - - Expressing constraints in XML is possible via files adhering to the - schema seen in . Note that - these mapping files are only processed if listed via - constraint-mapping in - validation.xml. - - - validation-mapping-1.1.xsd - - - - - - - - - - - - - shows how the classes - Car and RentalCar from resp. could - be mapped in XML. - - - Bean constraints configured via XML - - <constraint-mappings - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.1.xsd" - xmlns="http://jboss.org/xml/ns/javax/validation/mapping" version="1.1"> - - <default-package>org.hibernate.validator.referenceguide.chapter05</default-package> - <bean class="Car" ignore-annotations="true"> - <field name="manufacturer"> - <constraint annotation="javax.validation.constraints.NotNull"/> - </field> - <field name="licensePlate"> - <constraint annotation="javax.validation.constraints.NotNull"/> - </field> - <field name="seatCount"> - <constraint annotation="javax.validation.constraints.Min"> - <element name="value">2</element> - </constraint> - </field> - <field name="driver"> - <valid/> - </field> - <getter name="passedVehicleInspection" ignore-annotations="true"> - <constraint annotation="javax.validation.constraints.AssertTrue"> - <message>The car has to pass the vehicle inspection first</message> - <groups> - <value>CarChecks</value> - </groups> - <element name="max">10</element> - </constraint> - </getter> - </bean> - <bean class="RentalCar" ignore-annotations="true"> - <class ignore-annotations="true"> - <group-sequence> - <value>RentalCar</value> - <value>CarChecks</value> - </group-sequence> - </class> - </bean> - <constraint-definition annotation="org.mycompany.CheckCase"> - <validated-by include-existing-validators="false"> - <value>org.mycompany.CheckCaseValidator</value> - </validated-by> - </constraint-definition> -</constraint-mappings> - - - shows how the - constraints from , and can be expressed in - XML. - - - Method constraints configured via XML - - <constraint-mappings - xmlns="http://jboss.org/xml/ns/javax/validation/mapping" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation= - "http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.1.xsd" version="1.1"> - - <default-package>org.hibernate.validator.referenceguide.chapter07</default-package> - - <bean class="RentalStation" ignore-annotations="true"> - <constructor> - <return-value> - <constraint annotation="ValidRentalStation"/> - </return-value> - </constructor> - - <constructor> - <parameter type="java.lang.String"> - <constraint annotation="javax.validation.constraints.NotNull"/> - </parameter> - </constructor> - - <method name="getCustomers"> - <return-value> - <constraint annotation="javax.validation.constraints.NotNull"/> - <constraint annotation="javax.validation.constraints.Size"> - <element name="min">1</element> - </constraint> - </return-value> - </method> - - <method name="rentCar"> - <parameter type="Customer"> - <constraint annotation="javax.validation.constraints.NotNull"/> - </parameter> - <parameter type="java.util.Date"> - <constraint annotation="javax.validation.constraints.NotNull"/> - <constraint annotation="javax.validation.constraints.Future"/> - </parameter> - <parameter type="int"> - <constraint annotation="javax.validation.constraints.Min"> - <element name="value">1</element> - </constraint> - </parameter> - </method> - </bean> - - <bean class="Garage" ignore-annotations="true"> - <method name="buildCar"> - <parameter type="java.util.List"/> - <cross-parameter> - <constraint annotation="ELAssert"> - <element name="expression">...</element> - <element name="validationAppliesTo">PARAMETERS</element> - </constraint> - </cross-parameter> - </method> - <method name="paintCar"> - <parameter type="int"/> - <return-value> - <constraint annotation="ELAssert"> - <element name="expression">...</element> - <element name="validationAppliesTo">RETURN_VALUE</element> - </constraint> - </return-value> - </method> - </bean> - -</constraint-mappings> - - - The XML configuration is closely mirroring the programmatic API. For - this reason it should suffice to just add some comments. - default-package is used for all fields where a class - name is expected. If the specified class is not fully qualified the - configured default package will be used. Every mapping file can then have - several bean nodes, each describing the constraints - on the entity with the specified class name. - A given entity can only be configured once across all - configuration files. The same applies for constraint definitions for a - given constraint annotation. It can only occur in one mapping file. If - these rules are violated a ValidationException - is thrown. - Setting ignore-annotations to - true means that constraint annotations placed on the - configured bean are ignored. The default for this value is - true. ignore-annotations is also available for the - nodes class, fields, - getter, constructor, - method, parameter, - cross-parameter and - return-value. If not explicitly specified on these - levels the configured bean value applies. - - The nodes class, field, - getter, constructor and - method (and its sub node - parameter) determine on which level the constraint - gets placed. The constraint node is then used to add - a constraint on the corresponding level. Each constraint definition must - define the class via the annotation attribute. The - constraint attributes required by the Bean Validation specification - (message, groups and - payload) have dedicated nodes. All other constraint - specific attributes are configured using the element - node. - - The class node also allows to reconfigure the - default group sequence (see ) - via the group-sequence node. Not shown in the example - is the use of convert-group to specify group - conversions (see ). This node is - available on field, getter, - parameter and return-value and - specifies a from and to - attribute to specify the groups. - - Last but not least, the list of - ConstraintValidators associated to a given - constraint can be altered via the - constraint-definition node. The - annotation attribute represents the constraint - annotation being altered. The validated-by elements - represent the (ordered) list of ConstraintValidator - implementations associated to the constraint. If - include-existing-validator is set to - false, validators defined on the constraint - annotation are ignored. If set to true, the list of - constraint validators described in XML is concatenated to the list of - validators specified on the annotation. -
-
diff --git a/documentation/src/main/docbook/pot/master.pot b/documentation/src/main/docbook/pot/master.pot deleted file mode 100644 index 450491b2fc..0000000000 --- a/documentation/src/main/docbook/pot/master.pot +++ /dev/null @@ -1,64 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: master.xml:25 -#, no-c-format -msgid "Hibernate Validator" -msgstr "" - -#. Tag: subtitle -#: master.xml:27 -#, no-c-format -msgid "JSR 349 Reference Implementation" -msgstr "" - -#. Tag: subtitle -#: master.xml:29 -#, no-c-format -msgid "Reference Guide" -msgstr "" - -#. Tag: releaseinfo -#: master.xml:31 -#, no-c-format -msgid "&version;" -msgstr "" - -#. Tag: holder -#: master.xml:40 -#, no-c-format -msgid "©rightHolder;" -msgstr "" - -#. Tag: author -#: master.xml:44 -#, no-c-format -msgid "Hardy Ferentschik" -msgstr "" - -#. Tag: author -#: master.xml:50 -#, no-c-format -msgid "Gunnar Morling" -msgstr "" - -#. Tag: othercredit -#: master.xml:56 -#, no-c-format -msgid "Shaozhuang Liu stliu@hibernate.org" -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/annotation-processor.pot b/documentation/src/main/docbook/pot/modules/annotation-processor.pot deleted file mode 100644 index 47238d8bda..0000000000 --- a/documentation/src/main/docbook/pot/modules/annotation-processor.pot +++ /dev/null @@ -1,532 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: annotation-processor.xml:24 -#, no-c-format -msgid "Annotation Processor" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:26 -#, no-c-format -msgid "Have you ever caught yourself by unintentionally doing things like" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:31 -#, no-c-format -msgid "specifying constraint annotations at unsupported data types (e.g. by annotating a String with @Past)" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:36 -#, no-c-format -msgid "annotating the setter of a JavaBeans property (instead of the getter method)" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:41 -#, no-c-format -msgid "annotating static fields/methods with constraint annotations (which is not supported)?" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:46 -#, no-c-format -msgid "Then the Hibernate Validator Annotation Processor is the right thing for you. It helps preventing such mistakes by plugging into the build process and raising compilation errors whenever constraint annotations are incorrectly used." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:52 -#, no-c-format -msgid "You can find the Hibernate Validator Annotation Processor as part of the distribution bundle on Sourceforge or in the usual Maven repositories such as Maven Central under the GAV org.hibernate:hibernate-validator-annotation-processor:&version;." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:60 -#, no-c-format -msgid "Prerequisites" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:62 -#, no-c-format -msgid "The Hibernate Validator Annotation Processor is based on the \"Pluggable Annotation Processing API\" as defined by JSR 269 which is part of the Java Platform since Java 6." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:69 -#, no-c-format -msgid "Features" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:71 -#, no-c-format -msgid "As of Hibernate Validator &version; the Hibernate Validator Annotation Processor checks that:" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:76 -#, no-c-format -msgid "constraint annotations are allowed for the type of the annotated element" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:81 -#, no-c-format -msgid "only non-static fields or methods are annotated with constraint annotations" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:86 -#, no-c-format -msgid "only non-primitive fields or methods are annotated with @Valid" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:91 -#, no-c-format -msgid "only such methods are annotated with constraint annotations which are valid JavaBeans getter methods (optionally, see below)" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:97 -#, no-c-format -msgid "only such annotation types are annotated with constraint annotations which are constraint annotations themselves" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:102 -#, no-c-format -msgid "definition of dynamic default group sequence with @GroupSequenceProvider is valid" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:109 -#, no-c-format -msgid "Options" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:111 -#, no-c-format -msgid "The behavior of the Hibernate Validator Annotation Processor can be controlled using the processor options listed in table :" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:118 -#, no-c-format -msgid "Hibernate Validator Annotation Processor options" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:123 -#, no-c-format -msgid "Option" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:125 -#, no-c-format -msgid "Explanation" -msgstr "" - -#. Tag: varname -#: annotation-processor.xml:131 -#, no-c-format -msgid "diagnosticKind" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:133 -#, no-c-format -msgid "Controls how constraint problems are reported. Must be the string representation of one of the values from the enum javax.tools.Diagnostic.Kind, e.g. WARNING. A value of ERROR will cause compilation to halt whenever the AP detects a constraint problem. Defaults to ERROR." -msgstr "" - -#. Tag: varname -#: annotation-processor.xml:143 -#, no-c-format -msgid "methodConstraintsSupported" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:145 -#, no-c-format -msgid "Controls whether constraints are allowed at methods of any kind. Must be set to true when working with method level constraints as supported by Hibernate Validator. Can be set to false to allow constraints only at JavaBeans getter methods as defined by the Bean Validation API. Defaults to true." -msgstr "" - -#. Tag: varname -#: annotation-processor.xml:154 -#, no-c-format -msgid "verbose" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:156 -#, no-c-format -msgid "Controls whether detailed processing information shall be displayed or not, useful for debugging purposes. Must be either true or false. Defaults to false." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:167 -#, no-c-format -msgid "Using the Annotation Processor" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:169 -#, no-c-format -msgid "This section shows in detail how to integrate the Hibernate Validator Annotation Processor into command line builds (javac, Ant, Maven) as well as IDE-based builds (Eclipse, IntelliJ IDEA, NetBeans)." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:175 -#, no-c-format -msgid "Command line builds" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:178 -#, no-c-format -msgid "javac" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:180 -#, no-c-format -msgid "When compiling on the command line using javac, specify the JAR hibernate-validator-annotation-processor-&version;.jar using the \"processorpath\" option as shown in the following listing. The processor will be detected automatically by the compiler and invoked during compilation." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:188 -#, no-c-format -msgid "Using the annotation processor with javac" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:190 -#, no-c-format -msgid "" - "javac src/main/java/org/hibernate/validator/ap/demo/Car.java \\\n" - " -cp /path/to/validation-api-&bvVersion;.jar \\\n" - " -processorpath /path/to/hibernate-validator-annotation-processor-&version;.jar" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:195 -#, no-c-format -msgid "Apache Ant" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:197 -#, no-c-format -msgid "Similar to directly working with javac, the annotation processor can be added as as compiler argument when invoking the javac task for Apache Ant:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:204 -#, no-c-format -msgid "Using the annotation processor with Ant" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:206 -#, no-c-format -msgid "" - "<javac srcdir=\"src/main\"\n" - " destdir=\"build/classes\"\n" - " classpath=\"/path/to/validation-api-&bvVersion;.jar\">\n" - " <compilerarg value=\"-processorpath\" />\n" - " <compilerarg value=\"/path/to/hibernate-validator-annotation-processor-&version;.jar\"/>\n" - "</javac>" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:211 -#, no-c-format -msgid "Maven" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:213 -#, no-c-format -msgid "There are several options for integrating the annotation processor with Apache Maven. Generally it is sufficient to add the Hibernate Validator Annotation Processor as dependency to your project:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:219 -#, no-c-format -msgid "Adding the HV Annotation Processor as dependency" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:221 -#, no-c-format -msgid "" - "...\n" - "<dependency>\n" - " <groupId>org.hibernate</groupId>\n" - " <artifactId>hibernate-validator-annotation-processor</artifactId>\n" - " <version>&version;</version>\n" - "</dependency>\n" - "..." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:224 -#, no-c-format -msgid "The processor will then be executed automatically by the compiler. This basically works, but comes with the disadavantage that in some cases messages from the annotation processor are not displayed (see MCOMPILER-66)." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:230 -#, no-c-format -msgid "Another option is using the Maven Annotation Plugin. At the time of this writing the plugin is not yet available in any of the well-known repositories. Therefore you have to add the project's own repository to your settings.xml or pom.xml:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:238 -#, no-c-format -msgid "Adding the Maven Annotation Plugin repository" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:240 -#, no-c-format -msgid "" - "...\n" - "<pluginRepositories>\n" - " <pluginRepository>\n" - " <id>maven-annotation-plugin-repo</id>\n" - " <url>http://maven-annotation-plugin.googlecode.com/svn/trunk/mavenrepo</url>\n" - " </pluginRepository>\n" - "</pluginRepositories>\n" - "..." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:243 -#, no-c-format -msgid "Now disable the standard annotation processing performed by the compiler plugin and configure the annotation plugin by specifying an execution and adding the Hibernate Validator Annotation Processor as plugin dependency (that way the AP is not visible on the project's actual classpath):" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:250 -#, no-c-format -msgid "Configuring the Maven Annotation Plugin" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:252 -#, no-c-format -msgid "" - "...\n" - "<plugin>\n" - " <artifactId>maven-compiler-plugin</artifactId>\n" - " <configuration>\n" - " <source>1.6</source>\n" - " <target>1.6</target>\n" - " <compilerArgument>-proc:none</compilerArgument>\n" - " </configuration>\n" - "</plugin>\n" - "<plugin>\n" - " <groupId>org.bsc.maven</groupId>\n" - " <artifactId>maven-processor-plugin</artifactId>\n" - " <version>1.3.4</version>\n" - " <executions>\n" - " <execution>\n" - " <id>process</id>\n" - " <goals>\n" - " <goal>process</goal>\n" - " </goals>\n" - " <phase>process-sources</phase>\n" - " </execution>\n" - " </executions>\n" - " <dependencies>\n" - " <dependency>\n" - " <groupId>org.hibernate</groupId>\n" - " <artifactId>hibernate-validator-annotation-processor</artifactId>\n" - " <version>&version;</version>\n" - " </dependency>\n" - " </dependencies>\n" - "</plugin>\n" - "..." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:258 -#, no-c-format -msgid "IDE builds" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:261 -#, no-c-format -msgid "Eclipse" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:263 -#, no-c-format -msgid "Do the following to use the annotation processor within the Eclipse IDE:" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:268 annotation-processor.xml:360 -#, no-c-format -msgid "Right-click your project, choose \"Properties\"" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:272 -#, no-c-format -msgid "Go to \"Java Compiler\" and make sure, that \"Compiler compliance level\" is set to \"1.6\". Otherwise the processor won't be activated" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:278 -#, no-c-format -msgid "Go to \"Java Compiler - Annotation Processing\" and choose \"Enable annotation processing\"" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:283 -#, no-c-format -msgid "Go to \"Java Compiler - Annotation Processing - Factory Path\" and add the JAR hibernate-validator-annotation-processor-&version;.jar" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:289 -#, no-c-format -msgid "Confirm the workspace rebuild" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:293 -#, no-c-format -msgid "You now should see any annotation problems as regular error markers within the editor and in the \"Problem\" view:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:305 -#, no-c-format -msgid "IntelliJ IDEA" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:307 -#, no-c-format -msgid "The following steps must be followed to use the annotation processor within IntelliJ IDEA (version 9 and above):" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:313 -#, no-c-format -msgid "Go to \"File\", then \"Settings\"," -msgstr "" - -#. Tag: para -#: annotation-processor.xml:317 -#, no-c-format -msgid "Expand the node \"Compiler\", then \"Annotation Processors\"" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:322 -#, no-c-format -msgid "Choose \"Enable annotation processing\" and enter the following as \"Processor path\": /path/to/hibernate-validator-annotation-processor-&version;.jar" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:328 -#, no-c-format -msgid "Add the processor's fully qualified name org.hibernate.validator.ap.ConstraintValidationProcessor to the \"Annotation Processors\" list" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:334 -#, no-c-format -msgid "If applicable add you module to the \"Processed Modules\" list" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:339 -#, no-c-format -msgid "Rebuilding your project then should show any erronous constraint annotations:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:351 -#, no-c-format -msgid "NetBeans" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:353 -#, no-c-format -msgid "Starting with version 6.9, also the NetBeans IDE supports using annotation processors within the IDE build. To do so, do the following:" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:364 -#, no-c-format -msgid "Go to \"Libraries\", tab \"Processor\", and add the JAR hibernate-validator-annotation-processor-&version;.jar" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:369 -#, no-c-format -msgid "Go to \"Build - Compiling\", select \"Enable Annotation Processing\" and \"Enable Annotation Processing in Editor\". Add the annotation processor by specifying its fully qualified name org.hibernate.validator.ap.ConstraintValidationProcessor" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:376 -#, no-c-format -msgid "Any constraint annotation problems will then be marked directly within the editor:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:390 -#, no-c-format -msgid "Known issues" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:392 -#, no-c-format -msgid "The following known issues exist as of May 2010:" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:396 -#, no-c-format -msgid "HV-308: Additional validators registered for a constraint using XML are not evaluated by the annotation processor." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:404 -#, no-c-format -msgid "Sometimes custom constraints can't be properly evaluated when using the processor within Eclipse. Cleaning the project can help in these situations. This seems to be an issue with the Eclipse JSR 269 API implementation, but further investigation is required here." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:413 -#, no-c-format -msgid "When using the processor within Eclipse, the check of dynamic default group sequence definitions doesn't work. After further investigation, it seems to be an issue with the Eclipse JSR 269 API implementation." -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/annotationprocessor.pot b/documentation/src/main/docbook/pot/modules/annotationprocessor.pot deleted file mode 100644 index ce918da08f..0000000000 --- a/documentation/src/main/docbook/pot/modules/annotationprocessor.pot +++ /dev/null @@ -1,535 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2012-05-09 09:42+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: annotationprocessor.xml:24 -#, no-c-format -msgid "Annotation Processor" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:26 -#, no-c-format -msgid "Have you ever caught yourself by unintentionally doing things like" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:31 -#, no-c-format -msgid "specifying constraint annotations at unsupported data types (e.g. by annotating a String with @Past)" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:36 -#, no-c-format -msgid "annotating the setter of a JavaBean property (instead of the getter method)" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:41 -#, no-c-format -msgid "annotating static fields/methods with constraint annotations (which is not supported)?" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:46 -#, no-c-format -msgid "Then the Hibernate Validator Annotation Processor is the right thing for you. It helps preventing such mistakes by plugging into the build process and raising compilation errors whenever constraint annotations are incorrectly used." -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:52 -#, no-c-format -msgid "You can find the Hibernate Validator Annotation Processor as part of the distribution bundle on Sourceforge or in the JBoss Maven Repository (see ) under the GAV org.hibernate:hibernate-validator-annotation-processor." -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:61 -#, no-c-format -msgid "Prerequisites" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:63 -#, no-c-format -msgid "The Hibernate Validator Annotation Processor is based on the \"Pluggable Annotation Processing API\" as defined by JSR 269 which is part of the Java Platform since Java 6." -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:70 -#, no-c-format -msgid "Features" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:72 -#, no-c-format -msgid "As of Hibernate Validator &version; the Hibernate Validator Annotation Processor checks that:" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:77 -#, no-c-format -msgid "constraint annotations are allowed for the type of the annotated element" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:82 -#, no-c-format -msgid "only non-static fields or methods are annotated with constraint annotations" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:87 -#, no-c-format -msgid "only non-primitive fields or methods are annotated with @Valid" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:92 -#, no-c-format -msgid "only such methods are annotated with constraint annotations which are valid JavaBeans getter methods (optionally, see below)" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:98 -#, no-c-format -msgid "only such annotation types are annotated with constraint annotations which are constraint annotations themselves" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:103 -#, no-c-format -msgid "definition of dynamic default group sequence with @GroupSequenceProvider is valid" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:110 -#, no-c-format -msgid "Options" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:112 -#, no-c-format -msgid "The behavior of the Hibernate Validator Annotation Processor can be controlled using the processor options listed in table:" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:119 -#, no-c-format -msgid "Hibernate Validator Annotation Processor options" -msgstr "" - -#. Tag: entry -#: annotationprocessor.xml:124 -#, no-c-format -msgid "Option" -msgstr "" - -#. Tag: entry -#: annotationprocessor.xml:126 -#, no-c-format -msgid "Explanation" -msgstr "" - -#. Tag: varname -#: annotationprocessor.xml:132 -#, no-c-format -msgid "diagnosticKind" -msgstr "" - -#. Tag: entry -#: annotationprocessor.xml:134 -#, no-c-format -msgid "Controls how constraint problems are reported. Must be the string representation of one of the values from the enum javax.tools.Diagnostic.Kind, e.g. WARNING. A value of ERROR will cause compilation to halt whenever the AP detects a constraint problem. Defaults to ERROR." -msgstr "" - -#. Tag: varname -#: annotationprocessor.xml:144 -#, no-c-format -msgid "methodConstraintsSupported" -msgstr "" - -#. Tag: entry -#: annotationprocessor.xml:146 -#, no-c-format -msgid "Controls whether constraints are allowed at methods of any kind. Must be set to true when working with method level constraints as supported by Hibernate Validator. Can be set to false to allow constraints only at JavaBeans getter methods as defined by the Bean Validation API. Defaults to true." -msgstr "" - -#. Tag: varname -#: annotationprocessor.xml:155 -#, no-c-format -msgid "verbose" -msgstr "" - -#. Tag: entry -#: annotationprocessor.xml:157 -#, no-c-format -msgid "Controls whether detailed processing information shall be displayed or not, useful for debugging purposes. Must be either true or false. Defaults to false." -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:168 -#, no-c-format -msgid "Using the Annotation Processor" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:170 -#, no-c-format -msgid "This section shows in detail how to integrate the Hibernate Validator Annotation Processor into command line builds (javac, Ant, Maven) as well as IDE-based builds (Eclipse, IntelliJ IDEA, NetBeans)." -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:176 -#, no-c-format -msgid "Command line builds" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:179 -#, no-c-format -msgid "javac" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:181 -#, no-c-format -msgid "When compiling on the command line using javac, specify the JAR hibernate-validator-annotation-processor-&version;.jar using the \"processorpath\" option as shown in the following listing. The processor will be detected automatically by the compiler and invoked during compilation." -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:189 -#, no-c-format -msgid "Using the annotation processor with javac" -msgstr "" - -#. Tag: programlisting -#: annotationprocessor.xml:191 -#, no-c-format -msgid "" - "javac src/main/java/org/hibernate/validator/ap/demo/Car.java \\\n" - " -cp /path/to/validation-api-&bvVersion;.jar \\\n" - " -processorpath /path/to/hibernate-validator-annotation-processor-&version;.jar" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:196 -#, no-c-format -msgid "Apache Ant" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:198 -#, no-c-format -msgid "Similar to directly working with javac, the annotation processor can be added as as compiler argument when invoking the javac task for Apache Ant:" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:205 -#, no-c-format -msgid "Using the annotation processor with Ant" -msgstr "" - -#. Tag: programlisting -#: annotationprocessor.xml:207 -#, no-c-format -msgid "" - "<javac srcdir=\"src/main\"\n" - " destdir=\"build/classes\"\n" - " classpath=\"/path/to/validation-api-&bvVersion;.jar\">\n" - " <compilerarg value=\"-processorpath\" />\n" - " <compilerarg value=\"/path/to/hibernate-validator-annotation-processor-&version;.jar\"/>\n" - "</javac>" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:212 -#, no-c-format -msgid "Maven" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:214 -#, no-c-format -msgid "There are several options for integrating the annotation processor with Apache Maven. Generally it is sufficient to add the Hibernate Validator Annotation Processor as dependency to your project:" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:220 -#, no-c-format -msgid "Adding the HV Annotation Processor as dependency" -msgstr "" - -#. Tag: programlisting -#: annotationprocessor.xml:222 -#, no-c-format -msgid "" - "...\n" - "<dependency>\n" - " <groupId>org.hibernate</groupId>\n" - " <artifactId>hibernate-validator-annotation-processor</artifactId>\n" - " <version>&version;</version>\n" - " <scope>compile</scope>\n" - "</dependency>\n" - "..." -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:225 -#, no-c-format -msgid "The processor will then be executed automatically by the compiler. This basically works, but comes with the disadavantage that in some cases messages from the annotation processor are not displayed (see MCOMPILER-66)." -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:231 -#, no-c-format -msgid "Another option is using the Maven Annotation Plugin. At the time of this writing the plugin is not yet available in any of the well-known repositories. Therefore you have to add the project's own repository to your settings.xml or pom.xml:" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:239 -#, no-c-format -msgid "Adding the Maven Annotation Plugin repository" -msgstr "" - -#. Tag: programlisting -#: annotationprocessor.xml:241 -#, no-c-format -msgid "" - "...\n" - "<pluginRepositories>\n" - " <pluginRepository>\n" - " <id>maven-annotation-plugin-repo</id>\n" - " <url>http://maven-annotation-plugin.googlecode.com/svn/trunk/mavenrepo</url>\n" - " </pluginRepository>\n" - "</pluginRepositories>\n" - "..." -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:244 -#, no-c-format -msgid "Now disable the standard annotation processing performed by the compiler plugin and configure the annotation plugin by specifying an execution and adding the Hibernate Validator Annotation Processor as plugin dependency (that way the AP is not visible on the project's actual classpath):" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:251 -#, no-c-format -msgid "Configuring the Maven Annotation Plugin" -msgstr "" - -#. Tag: programlisting -#: annotationprocessor.xml:253 -#, no-c-format -msgid "" - "...\n" - "<plugin>\n" - " <artifactId>maven-compiler-plugin</artifactId>\n" - " <configuration>\n" - " <source>1.6</source>\n" - " <target>1.6</target>\n" - " <compilerArgument>-proc:none</compilerArgument>\n" - " </configuration>\n" - "</plugin>\n" - "<plugin>\n" - " <groupId>org.bsc.maven</groupId>\n" - " <artifactId>maven-processor-plugin</artifactId>\n" - " <version>1.3.4</version>\n" - " <executions>\n" - " <execution>\n" - " <id>process</id>\n" - " <goals>\n" - " <goal>process</goal>\n" - " </goals>\n" - " <phase>process-sources</phase>\n" - " </execution>\n" - " </executions>\n" - " <dependencies>\n" - " <dependency>\n" - " <groupId>org.hibernate</groupId>\n" - " <artifactId>hibernate-validator-annotation-processor</artifactId>\n" - " <version>&version;</version>\n" - " <scope>compile</scope>\n" - " </dependency>\n" - " </dependencies>\n" - "</plugin>\n" - "..." -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:259 -#, no-c-format -msgid "IDE builds" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:262 -#, no-c-format -msgid "Eclipse" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:264 -#, no-c-format -msgid "Do the following to use the annotation processor within the Eclipse IDE:" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:269 annotationprocessor.xml:361 -#, no-c-format -msgid "Right-click your project, choose \"Properties\"" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:273 -#, no-c-format -msgid "Go to \"Java Compiler\" and make sure, that \"Compiler compliance level\" is set to \"1.6\". Otherwise the processor won't be activated" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:279 -#, no-c-format -msgid "Go to \"Java Compiler - Annotation Processing\" and choose \"Enable annotation processing\"" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:284 -#, no-c-format -msgid "Go to \"Java Compiler - Annotation Processing - Factory Path\" and add the JAR hibernate-validator-annotation-processor-&version;.jar" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:290 -#, no-c-format -msgid "Confirm the workspace rebuild" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:294 -#, no-c-format -msgid "You now should see any annotation problems as regular error markers within the editor and in the \"Problem\" view:" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:306 -#, no-c-format -msgid "IntelliJ IDEA" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:308 -#, no-c-format -msgid "The following steps must be followed to use the annotation processor within IntelliJ IDEA (version 9 and above):" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:314 -#, no-c-format -msgid "Go to \"File\", then \"Settings\"," -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:318 -#, no-c-format -msgid "Expand the node \"Compiler\", then \"Annotation Processors\"" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:323 -#, no-c-format -msgid "Choose \"Enable annotation processing\" and enter the following as \"Processor path\": /path/to/hibernate-validator-annotation-processor-&version;.jar" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:329 -#, no-c-format -msgid "Add the processor's fully qualified name org.hibernate.validator.ap.ConstraintValidationProcessor to the \"Annotation Processors\" list" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:335 -#, no-c-format -msgid "If applicable add you module to the \"Processed Modules\" list" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:340 -#, no-c-format -msgid "Rebuilding your project then should show any erronous constraint annotations:" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:352 -#, no-c-format -msgid "NetBeans" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:354 -#, no-c-format -msgid "Starting with version 6.9, also the NetBeans IDE supports using annotation processors within the IDE build. To do so, do the following:" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:365 -#, no-c-format -msgid "Go to \"Libraries\", tab \"Processor\", and add the JAR hibernate-validator-annotation-processor-&version;.jar" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:370 -#, no-c-format -msgid "Go to \"Build - Compiling\", select \"Enable Annotation Processing\" and \"Enable Annotation Processing in Editor\". Add the annotation processor by specifying its fully qualified name org.hibernate.validator.ap.ConstraintValidationProcessor" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:377 -#, no-c-format -msgid "Any constraint annotation problems will then be marked directly within the editor:" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:391 -#, no-c-format -msgid "Known issues" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:393 -#, no-c-format -msgid "The following known issues exist as of May 2010:" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:397 -#, no-c-format -msgid "HV-308: Additional validators registered for a constraint using XML are not evaluated by the annotation processor." -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:405 -#, no-c-format -msgid "Sometimes custom constraints can't be properly evaluated when using the processor within Eclipse. Cleaning the project can help in these situations. This seems to be an issue with the Eclipse JSR 269 API implementation, but further investigation is required here." -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:414 -#, no-c-format -msgid "When using the processor within Eclipse, the check of dynamic default group sequence definitions doesn't work. After further investigation, it seems to be an issue with the Eclipse JSR 269 API implementation." -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/bean-constraints.pot b/documentation/src/main/docbook/pot/modules/bean-constraints.pot deleted file mode 100644 index 71d9b382f3..0000000000 --- a/documentation/src/main/docbook/pot/modules/bean-constraints.pot +++ /dev/null @@ -1,1318 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: bean-constraints.xml:24 -#, no-c-format -msgid "Declaring and validating bean constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:26 -#, no-c-format -msgid "Read this chapter in order to learn how to declare bean constraints (see ) and validate the same (see ). provides an overview of all built-in constraints coming with Hibernate Validator." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:32 -#, no-c-format -msgid "If you are interested in applying constraints to method parameters and return values, refer to ." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:36 -#, no-c-format -msgid "Declaring bean constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:38 -#, no-c-format -msgid "Constraints in Bean Validation are expressed via Java annotations. In this section we show how to enhance an object model with these annotations. We have to differentiate between several types of constraint annotations:" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:45 -#, no-c-format -msgid "field constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:49 -#, no-c-format -msgid "property constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:53 -#, no-c-format -msgid "class constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:58 -#, no-c-format -msgid "Not all constraints can be placed on all of these levels. In fact, none of the default constraints defined by Bean Validation can be placed at class level. The java.lang.annotation.Target annotation in the constraint annotation itself determines on which elements a constraint can be placed. See for more information." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:67 bean-constraints.xml:74 -#, no-c-format -msgid "Field-level constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:69 -#, no-c-format -msgid "Constraints can be expressed by annotating a field of a class. shows a field level configuration example:" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:76 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter02.fieldlevel;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @AssertTrue\n" - " private boolean isRegistered;\n" - "\n" - " public Car(String manufacturer, boolean isRegistered) {\n" - " this.manufacturer = manufacturer;\n" - " this.isRegistered = isRegistered;\n" - " }\n" - "\n" - " //getters and setters...\n" - "}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:79 -#, no-c-format -msgid "When using field-level constraints field access strategy is used to access the value to be validated. This means the validation engine directly accesses the instance variable and does not invoke the property accessor method also if such a method exists." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:84 -#, no-c-format -msgid "Constraints can be applied to fields of any access type (public, private etc.). Constraints on static fields are not supported, though." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:89 -#, no-c-format -msgid "When validating byte code enhanced objects property level constraints should be used, because the byte code enhancing library won't be able to determine a field access via reflection." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:96 bean-constraints.xml:110 -#, no-c-format -msgid "Property-level constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:98 -#, no-c-format -msgid "If your model class adheres to the JavaBeans standard, it is also possible to annotate the properties of a bean class instead of its fields. uses the same entity as in , however, property level constraints are used." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:104 -#, no-c-format -msgid "The property's getter method has to be annotated, not its setter. That way also read-only properties can be constrained which have no setter method." -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:112 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter02.propertylevel;\n" - "\n" - "public class Car {\n" - "\n" - " private String manufacturer;\n" - "\n" - " private boolean isRegistered;\n" - "\n" - " public Car(String manufacturer, boolean isRegistered) {\n" - " this.manufacturer = manufacturer;\n" - " this.isRegistered = isRegistered;\n" - " }\n" - "\n" - " @NotNull\n" - " public String getManufacturer() {\n" - " return manufacturer;\n" - " }\n" - "\n" - " public void setManufacturer(String manufacturer) {\n" - " this.manufacturer = manufacturer;\n" - " }\n" - "\n" - " @AssertTrue\n" - " public boolean isRegistered() {\n" - " return isRegistered;\n" - " }\n" - "\n" - " public void setRegistered(boolean isRegistered) {\n" - " this.isRegistered = isRegistered;\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:115 -#, no-c-format -msgid "When using property level constraints property access strategy is used to access the value to be validated, i.e. the validation engine accesses the state via the property accessor method." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:119 -#, no-c-format -msgid "One advantage of annotating properties instead of fields is that the constraints become part of the type's API that way. Thus users are aware of the existing constraints without having to examine the type's implementation." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:125 -#, no-c-format -msgid "It is recommended to stick either to field or property annotations within one class. It is not recommended to annotate a field and the accompanying getter method as this would cause the field to be validated twice." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:134 -#, no-c-format -msgid "Class-level constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:137 -#, no-c-format -msgid "Last but not least, a constraint can also be placed on the class level. In this case not a single property is subject of the validation but the complete object. Class-level constraints are useful if the validation depends on a correlation between several properties of an object." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:143 -#, no-c-format -msgid "The Car class in has the two attributes seatCount and passengers and it should be ensured that the list of passengers has not more entries than seats are available. For that purpose the @PassengerCount constraint is added on the class level. The validator of that constraint has access to the complete Car object, allowing to compare the numbers of seats and passengers. Refer to to learn in detail how this custom constraint is implemented." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:156 -#, no-c-format -msgid "Class-level constraint" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:158 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter02.classlevel;\n" - "\n" - "@PassengerCount\n" - "public class Car {\n" - "\n" - " private int seatCount;\n" - "\n" - " private List<Person> passengers;\n" - "\n" - " //...\n" - "}" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:163 bean-constraints.xml:171 -#, no-c-format -msgid "Constraint inheritance" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:165 -#, no-c-format -msgid "When a class implements an interface or extends another class, all constraint annotations declared on the supertype apply in the same manner as the constraints specified on the class itself. To make things clearer let's have a look at the following example:" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:173 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter02.inheritance;\n" - "\n" - "public class Car {\n" - "\n" - " private String manufacturer;\n" - "\n" - " @NotNull\n" - " public String getManufacturer() {\n" - " return manufacturer;\n" - " }\n" - "\n" - " //...\n" - "}" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:175 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter02.inheritance;\n" - "\n" - "public class RentalCar extends Car {\n" - "\n" - " private String rentalStation;\n" - "\n" - " @NotNull\n" - " public String getRentalStation() {\n" - " return rentalStation;\n" - " }\n" - "\n" - " //...\n" - "}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:178 -#, no-c-format -msgid "Here the class RentalCar is a subclass of Car and adds the property rentalStation. If an instance of RentalCar is validated, not only the @NotNull constraint on rentalStation is evaluated, but also the constraint on manufacturer from the parent class." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:186 -#, no-c-format -msgid "The same would be true, if Car was not a superclass but an interface implemented by RentalCar." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:190 -#, no-c-format -msgid "Constraint annotations are aggregated if methods are overridden. So if RentalCar overrode the getManufacturer() method from Car, any constraints annotated at the overriding method would be evaluated in addition to the @NotNull constraint from the superclass." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:199 -#, no-c-format -msgid "Object graphs" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:201 -#, no-c-format -msgid "The Bean Validation API does not only allow to validate single class instances but also complete object graphs (cascaded validation). To do so, just annotate a field or property representing a reference to another object with @Valid as demonstrated in ." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:208 -#, no-c-format -msgid "Cascaded validation" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:210 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter02.objectgraph;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " @Valid\n" - " private Person driver;\n" - "\n" - " //...\n" - "}" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:212 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter02.objectgraph;\n" - "\n" - "public class Person {\n" - "\n" - " @NotNull\n" - " private String name;\n" - "\n" - " //...\n" - "}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:215 -#, no-c-format -msgid "If an instance of Car is validated, the referenced Person object will be validated as well, as the driver field is annotated with @Valid. Therefore the validation of a Car will fail if the name field of the referenced Person instance is null." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:223 -#, no-c-format -msgid "The validation of object graphs is done recursively, i.e. if a reference marked for cacaded validation points to an object which itself has properties annotated with @Valid, these references will be followed up by the validation engine as well. It is ensured that no infinite loops occur during cascaded validation, if for instance two objects hold references to each other." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:230 -#, no-c-format -msgid "Note that null values are getting ignored during cascaded validation." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:233 -#, no-c-format -msgid "Object graph validation also works for collection-typed fields. That means any attributes that" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:238 -#, no-c-format -msgid "are arrays" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:242 -#, no-c-format -msgid "implement java.lang.Iterable (especially Collection, List and Set)" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:248 -#, no-c-format -msgid "implement java.util.Map" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:252 -#, no-c-format -msgid "can be annotated with @Valid, which will cause each contained element to be validated, when the parent object is validated." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:257 -#, no-c-format -msgid "Cascaded validation of a collection" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:259 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter02.objectgraph.list;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " @Valid\n" - " private List<Person> passengers = new ArrayList<Person>();\n" - "\n" - " //...\n" - "}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:262 -#, no-c-format -msgid "So when validating an instance of the Car class shown in , a ConstraintViolation will be created, if any of the Person objects contained in the passengers list has a null name." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:272 -#, no-c-format -msgid "Validating bean constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:274 -#, no-c-format -msgid "The Validator interface is the most important object in Bean Validation. The next section shows how to obtain an Validator instance. Afterwards you'll learn how to use the different methods of the Validator interface." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:281 -#, no-c-format -msgid "Obtaining a Validator instance" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:283 -#, no-c-format -msgid "The first step towards validating an entity instance is to get hold of a Validator instance. The road to this instance leads via the Validation class and a ValidatorFactory. The easiest way is to use the static method Validation#buildDefaultValidatorFactory():" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:291 -#, no-c-format -msgid "Validation#buildDefaultValidatorFactory()" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:293 -#, no-c-format -msgid "" - "ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - "Validator validator = factory.getValidator();" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:296 -#, no-c-format -msgid "For other ways of obtaining a Validator instance see . For now we just want to see how we can use the Validator instance to validate entity instances." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:303 -#, no-c-format -msgid "Validator methods" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:305 -#, no-c-format -msgid "The Validator interface contains three methods that can be used to either validate entire entities or just single properties of the entity." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:309 -#, no-c-format -msgid "All three methods return a Set<ConstraintViolation>. The set is empty, if the validation succeeds. Otherwise a ConstraintViolation instance is added for each violated constraint." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:315 -#, no-c-format -msgid "All the validation methods have a var-args parameter which can be used to specify, which validation groups shall be considered when performing the validation. If the parameter is not specified the default validation group (javax.validation.groups.Default) is used. The topic of validation groups is discussed in detail in ." -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:324 -#, no-c-format -msgid "validate()" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:326 -#, no-c-format -msgid "Use the validate() method to perform validation of all constraints of a given bean. shows the validation of an instance of the Car class from which fails to satisfy the @NotNull constraint on the manufacturer property. The validation call therefore returns one ConstraintViolation object." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:337 -#, no-c-format -msgid "Using Validator#validate()" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:339 -#, no-c-format -msgid "" - "Car car = new Car( null, true );\n" - "\n" - "Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );\n" - "\n" - "assertEquals( 1, constraintViolations.size() );\n" - "assertEquals( \"may not be null\", constraintViolations.iterator().next().getMessage() );" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:344 -#, no-c-format -msgid "validateProperty()" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:346 -#, no-c-format -msgid "With help of the validateProperty() you can validate a single named property of a given object. The property name is the JavaBeans property name." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:351 -#, no-c-format -msgid "Using Validator#validateProperty()" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:354 -#, no-c-format -msgid "" - "Car car = new Car( null, true );\n" - "\n" - "Set<ConstraintViolation<Car>> constraintViolations = validator.validateProperty(\n" - " car,\n" - " \"manufacturer\"\n" - ");\n" - "\n" - "assertEquals( 1, constraintViolations.size() );\n" - "assertEquals( \"may not be null\", constraintViolations.iterator().next().getMessage() );" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:359 -#, no-c-format -msgid "validateValue()" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:361 -#, no-c-format -msgid "By using the validateValue() method you can check whether a single property of a given class can be validated successfully, if the property had the specified value:" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:366 -#, no-c-format -msgid "Using Validator#validateValue()" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:369 -#, no-c-format -msgid "" - "Set<ConstraintViolation<Car>> constraintViolations = validator.validateValue(\n" - " Car.class,\n" - " \"manufacturer\",\n" - " null\n" - ");\n" - "\n" - "assertEquals( 1, constraintViolations.size() );\n" - "assertEquals( \"may not be null\", constraintViolations.iterator().next().getMessage() );" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:373 -#, no-c-format -msgid "@Valid is not honored by validateProperty() or validateValue()." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:378 -#, no-c-format -msgid "Validator#validateProperty() is for example used in the integration of Bean Validation into JSF 2 (see ) to perform a validation of the values entered into a form before they are propagated to the model." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:387 -#, no-c-format -msgid "ConstraintViolation methods" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:389 -#, no-c-format -msgid "Now it is time to have a closer look at what a ConstraintViolation is. Using the different methods of ConstraintViolation a lot of useful information about the cause of the validation failure can be determined. gives an overview of these methods. The values in the \"Example\" column refer to ." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:398 -#, no-c-format -msgid "The various ConstraintViolation methods" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:404 -#, no-c-format -msgid "Method" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:406 -#, no-c-format -msgid "Usage" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:408 -#, no-c-format -msgid "Example" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:414 -#, no-c-format -msgid "getMessage()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:416 -#, no-c-format -msgid "The interpolated error message" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:418 -#, no-c-format -msgid "\"may not be null\"" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:422 -#, no-c-format -msgid "getMessageTemplate()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:424 -#, no-c-format -msgid "The non-interpolated error message" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:426 -#, no-c-format -msgid "\"{... NotNull.message}\"" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:430 -#, no-c-format -msgid "getRootBean()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:432 -#, no-c-format -msgid "The root bean being validated" -msgstr "" - -#. Tag: varname -#: bean-constraints.xml:434 bean-constraints.xml:452 -#, no-c-format -msgid "car" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:438 -#, no-c-format -msgid "getRootBeanClass()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:440 -#, no-c-format -msgid "The class of the root bean being validated" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:442 -#, no-c-format -msgid "Car.class" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:446 -#, no-c-format -msgid "getLeafBean()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:448 -#, no-c-format -msgid "If a bean constraint, the bean instance the constraint is applied on; If a property constraint, the bean instance hosting the property the constraint is applied on" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:456 -#, no-c-format -msgid "getPropertyPath()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:458 -#, no-c-format -msgid "The property path to the validated value from root bean" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:461 -#, no-c-format -msgid "contains one node with kind PROPERTY and name \"manufacturer\"" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:466 -#, no-c-format -msgid "getInvalidValue()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:468 -#, no-c-format -msgid "The value failing to pass the constraint" -msgstr "" - -#. Tag: literal -#: bean-constraints.xml:470 -#, no-c-format -msgid "null" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:474 -#, no-c-format -msgid "getConstraintDescriptor()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:476 -#, no-c-format -msgid "Constraint metadata reported to fail" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:478 -#, no-c-format -msgid "descriptor for @NotNull" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:487 -#, no-c-format -msgid "Built-in constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:489 -#, no-c-format -msgid "Hibernate Validator comprises a basic set of commonly used constraints. These are foremost the constraints defined by the Bean Validation specification (see ). Additionally, Hibernate Validator provides useful custom constraints (see and )." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:497 bean-constraints.xml:517 -#, no-c-format -msgid "Bean Validation constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:499 -#, no-c-format -msgid "shows purpose and supported data types of all constraints specified in the Bean Validation API. All these constraints apply to the field/property level, there are no class-level constraints defined in the Bean Validation specification. If you are using the Hibernate object-relational mapper, some of the constraints are taken into account when creating the DDL for your model (see column \"Hibernate metadata impact\")." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:508 -#, no-c-format -msgid "Hibernate Validator allows some constraints to be applied to more data types than required by the Bean Validation specification (e.g. @Max can be applied to Strings). Relying on this feature can impact portability of your application between Bean Validation providers." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:530 bean-constraints.xml:797 bean-constraints.xml:1003 -#, no-c-format -msgid "Annotation" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:532 bean-constraints.xml:799 bean-constraints.xml:1005 -#, no-c-format -msgid "Supported data types" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:534 bean-constraints.xml:801 bean-constraints.xml:1007 -#, no-c-format -msgid "Use" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:536 bean-constraints.xml:803 bean-constraints.xml:1011 -#, no-c-format -msgid "Hibernate metadata impact" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:542 -#, no-c-format -msgid "@AssertFalse" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:544 bean-constraints.xml:556 -#, no-c-format -msgid "Boolean, boolean" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:547 -#, no-c-format -msgid "Checks that the annotated element is false" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:550 bean-constraints.xml:562 bean-constraints.xml:585 bean-constraints.xml:608 bean-constraints.xml:645 bean-constraints.xml:703 bean-constraints.xml:719 bean-constraints.xml:732 bean-constraints.xml:759 bean-constraints.xml:819 bean-constraints.xml:833 bean-constraints.xml:874 bean-constraints.xml:887 bean-constraints.xml:900 bean-constraints.xml:916 bean-constraints.xml:934 bean-constraints.xml:952 bean-constraints.xml:972 bean-constraints.xml:1027 bean-constraints.xml:1041 bean-constraints.xml:1056 -#, no-c-format -msgid "None" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:554 -#, no-c-format -msgid "@AssertTrue" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:559 -#, no-c-format -msgid "Checks that the annotated element is true" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:566 -#, no-c-format -msgid "@DecimalMax(value=, inclusive=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:569 bean-constraints.xml:592 bean-constraints.xml:615 -#, no-c-format -msgid "BigDecimal, BigInteger, CharSequence, byte, short, int, long and the respective wrappers of the primitive types; Additionally supported by HV: any sub-type of Number" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:578 -#, no-c-format -msgid "Checks whether the annotated value is less than the specified maximum, when inclusive=false. Otherwise whether the value is less than or equal to the specified maximum. The parameter value is the string representation of the max value according to the BigDecimal string representation." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:589 -#, no-c-format -msgid "@DecimalMin(value=, inclusive=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:601 -#, no-c-format -msgid "Checks whether the annotated value is larger than the specified minimum, when inclusive=false. Otherwise whether the value is larger than or equal to the specified minimum. The parameter value is the string representation of the min value according to the BigDecimal string representation." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:612 -#, no-c-format -msgid "@Digits(integer=, fraction=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:624 -#, no-c-format -msgid "Checks whether the annoted value is a number having up to integer digits and fraction fractional digits" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:628 -#, no-c-format -msgid "Defines column precision and scale" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:632 -#, no-c-format -msgid "@Future" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:634 bean-constraints.xml:709 -#, no-c-format -msgid "java.util.Date, java.util.Calendar; Additionally supported by HV, if the Joda Time date/time API is on the class path: any implementations of ReadablePartial and ReadableInstant" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:642 -#, no-c-format -msgid "Checks whether the annotated date is in the future" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:649 -#, no-c-format -msgid "@Max(value=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:651 -#, no-c-format -msgid "BigDecimal, BigInteger, byte, short, int, long and the respective wrappers of the primitive types; Additionally supported by HV: any sub-type of CharSequence (the numeric value represented by the character sequence is evaluated), any sub-type of Number" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:660 -#, no-c-format -msgid "Checks whether the annotated value is less than or equal to the specified maximum" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:663 bean-constraints.xml:681 -#, no-c-format -msgid "Adds a check constraint on the column" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:667 -#, no-c-format -msgid "@Min(value=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:669 -#, no-c-format -msgid "BigDecimal, BigInteger, byte, short, int, long and the respective wrappers of the primitive types; Additionally supported by HV: any sub-type of CharSequence (the numeric value represented by the char sequence is evaluated), any sub-type of Number" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:678 -#, no-c-format -msgid "Checks whether the annotated value is higher than or equal to the specified minimum" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:685 -#, no-c-format -msgid "@NotNull" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:687 bean-constraints.xml:698 bean-constraints.xml:941 -#, no-c-format -msgid "Any type" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:689 -#, no-c-format -msgid "Checks that the annotated value is not null." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:692 -#, no-c-format -msgid "Column(s) are not nullable" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:696 -#, no-c-format -msgid "@Null" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:700 -#, no-c-format -msgid "Checks that the annotated value is null" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:707 -#, no-c-format -msgid "@Past" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:717 -#, no-c-format -msgid "Checks whether the annotated date is in the past" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:723 -#, no-c-format -msgid "@Pattern(regex=, flag=)" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:726 bean-constraints.xml:811 bean-constraints.xml:825 bean-constraints.xml:839 bean-constraints.xml:856 bean-constraints.xml:880 bean-constraints.xml:923 bean-constraints.xml:960 bean-constraints.xml:1019 bean-constraints.xml:1033 bean-constraints.xml:1047 -#, no-c-format -msgid "CharSequence" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:728 -#, no-c-format -msgid "Checks if the annotated string matches the regular expression regex considering the given flag match" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:736 -#, no-c-format -msgid "@Size(min=, max=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:738 -#, no-c-format -msgid "CharSequence, Collection, Map and arrays" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:742 -#, no-c-format -msgid "Checks if the annotated element's size is between min and max (inclusive)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:745 bean-constraints.xml:845 -#, no-c-format -msgid "Column length will be set to max" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:750 -#, no-c-format -msgid "@Valid" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:752 -#, no-c-format -msgid "Any non-primitive type" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:754 -#, no-c-format -msgid "Performs validation recursively on the associated object. If the object is a collection or an array, the elements are validated recursively. If the object is a map, the value elements are validated recursively." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:766 -#, no-c-format -msgid "On top of the parameters indicated in each constraint has the parameters message, groups and payload. This is a requirement of the Bean Validation specification." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:775 -#, no-c-format -msgid "Additional constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:777 -#, no-c-format -msgid "In addition to the constraints defined by the Bean Validation API Hibernate Validator provides several useful custom constraints which are listed in . With one exception also these constraints apply to the field/property level, only @ScriptAssert is a class-level constraint." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:784 -#, no-c-format -msgid "Custom constraints" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:809 -#, no-c-format -msgid "@CreditCardNumber" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:813 -#, no-c-format -msgid "Checks that the annotated character sequence passes the Luhn checksum test. Note, this validation aims to check for user mistakes, not credit card validity! See also Anatomy of Credit Card Numbers." -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:823 -#, no-c-format -msgid "@Email" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:827 -#, no-c-format -msgid "Checks whether the specified character sequence is a valid email address. The optional parameters regexp and flags allow to specify an additional regular expression (including regular expression flags) which the email must match." -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:837 -#, no-c-format -msgid "@Length(min=, max=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:841 -#, no-c-format -msgid "Validates that the annotated character sequence is between min and max included" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:850 -#, no-c-format -msgid "@ModCheck(modType=, multiplier=, startIndex=, endIndex=, checkDigitPosition=, ignoreNonDigitCharacters=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:858 -#, no-c-format -msgid "Checks that the digits within the annotated character sequence pass the mod 10 or mod 11 checksum algorithm. modType is used to select the modulo type and the multiplier determines the algorithm specific multiplier (see also Luhn algorithm). startIndex and endIndex allow to only run the modulo algorithm on the specified sub-string. checkDigitPosition allows to use an arbitrary digit within the character sequence to be the check digit. If not specified it is assumed that the check digit is part of the specified range. Last but not least, ignoreNonDigitCharacters allows to ignore non digit characters." -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:878 -#, no-c-format -msgid "@NotBlank" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:882 -#, no-c-format -msgid "Checks that the annotated character sequence is not null and the trimmed length is greater than 0. The difference to @NotEmpty is that this constraint can only be applied on strings and that trailing whitespaces are ignored." -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:891 -#, no-c-format -msgid "@NotEmpty" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:893 -#, no-c-format -msgid "CharSequence, Collection, Map and arrays" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:897 -#, no-c-format -msgid "Checks whether the annotated element is not null nor empty" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:904 -#, no-c-format -msgid "@Range(min=, max=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:906 -#, no-c-format -msgid "BigDecimal, BigInteger, CharSequence, byte, short, int, long and the respective wrappers of the primitive types" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:913 -#, no-c-format -msgid "Checks whether the annotated value lies between (inclusive) the specified minimum and maximum" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:920 -#, no-c-format -msgid "@SafeHtml(whitelistType=, additionalTags=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:925 -#, no-c-format -msgid "Checks whether the annotated value contains potentially malicious fragments such as <script/>. In order to use this constraint, the jsoup library must be part of the class path. With the whitelistType attribute predefined whitelist types can be chosen. You can also specify additional html tags for the whitelist with the additionalTags attribute." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:938 -#, no-c-format -msgid "@ScriptAssert(lang=, script=, alias=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:943 -#, no-c-format -msgid "Checks whether the given script can successfully be evaluated against the annotated element. In order to use this constraint, an implementation of the Java Scripting API as defined by JSR 223 (\"Scripting for the JavaTM Platform\") must part of the class path. The expressions to be evaluated can be written in any scripting or expression language, for which a JSR 223 compatible engine can be found in the class path." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:956 -#, no-c-format -msgid "@URL(protocol=, host=, port= regexp=, flags=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:962 -#, no-c-format -msgid "Checks if the annotated character sequence is a valid URL according to RFC2396. If any of the optional parameters protocol, host or port are specified, the corresponding URL fragments must match the specified values. The optional parameters regexp and flags allow to specify an additional regular expression (including regular expression flags) which the URL must match." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:979 -#, no-c-format -msgid "Country specific constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:981 -#, no-c-format -msgid "Hibernate Validator offers also some country specific constraints, e.g. for the validation of social security numbers." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:983 -#, no-c-format -msgid "If you have to implement a country specific constraint, consider making it a contribution to Hibernate Validator!" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:988 -#, no-c-format -msgid "Custom country specific constraints" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1009 -#, no-c-format -msgid "Country" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:1017 -#, no-c-format -msgid "@CNPJ" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1021 -#, no-c-format -msgid "Checks that the annotated character sequence represents a Brazilian corporate tax payer registry number (Cadastro de Pessoa Juríeddica)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1025 bean-constraints.xml:1039 bean-constraints.xml:1054 -#, no-c-format -msgid "Brazil" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:1031 -#, no-c-format -msgid "@CPF" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1035 -#, no-c-format -msgid "Checks that the annotated character sequence represents a Brazilian individual taxpayer registry number (Cadastro de Pessoa Fídsica)" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:1045 -#, no-c-format -msgid "@TituloEleitoral" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1049 -#, no-c-format -msgid "Checks that the annotated character sequence represents a Brazilian voter ID card number (Título Eleitoral)" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:1063 -#, no-c-format -msgid "In some cases neither the Bean Validation constraints nor the custom constraints provided by Hibernate Validator will fulfill your requirements. In this case you can easily write your own constraint. We will discuss this in ." -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/bootstrapping.pot b/documentation/src/main/docbook/pot/modules/bootstrapping.pot deleted file mode 100644 index 616ec5eb65..0000000000 --- a/documentation/src/main/docbook/pot/modules/bootstrapping.pot +++ /dev/null @@ -1,619 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: bootstrapping.xml:24 -#, no-c-format -msgid "Bootstrapping" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:26 -#, no-c-format -msgid "In you already saw one way for creating a Validator instance — via Validation#buildDefaultValidatorFactory(). In this chapter you will learn how to use the other methods in javax.validation.Validation in order to bootstrap specifically configured validators." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:34 -#, no-c-format -msgid "Retrieving ValidatorFactory and Validator" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:37 -#, no-c-format -msgid "You obtain a Validator by retrieving a ValidatorFactory via one of the static methods on javax.validation.Validation and calling getValidator() on the factory instance." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:42 -#, no-c-format -msgid "shows how to obtain a validator from the default validator factory:" -msgstr "" - -#. Tag: title -#: bootstrapping.xml:46 -#, no-c-format -msgid "Bootstrapping default ValidatorFactory and Validator" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:49 -#, no-c-format -msgid "" - "ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - "Validator validator = factory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:53 -#, no-c-format -msgid "The generated ValidatorFactory and Validator instances are thread-safe and can be cached. As Hibernate Validator uses the factory as context for caching constraint metadata it is recommended to work with one factory instance within an application." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:60 -#, no-c-format -msgid "Bean Validation supports working with several providers such as Hibernate Validator within one application. If more than one provider is present on the classpath, it is not guaranteed which one is chosen when creating a factory via buildDefaultValidatorFactory()." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:66 -#, no-c-format -msgid "In this case you can explicitly specify the provider to use via Validation#byProvider(), passing the provider's ValidationProvider class as shown in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:72 -#, no-c-format -msgid "Bootstrapping ValidatorFactory and Validator using a specific provider" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:75 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class )\n" - " .configure()\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:78 -#, no-c-format -msgid "Note that the configuration object returned by configure() allows to specifically customize the factory before calling buildValidatorFactory(). The available options are discussed later in this chapter." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:83 -#, no-c-format -msgid "Similarly you can retrieve the default validator factory for configuration which is demonstrated in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:88 -#, no-c-format -msgid "Retrieving the default ValidatorFactory for configuration" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:91 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" - " .configure()\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:95 -#, no-c-format -msgid "If a ValidatorFactory instance is no longer in use, it should be disposed by calling ValidatorFactory#close(). This will free any resources possibly allocated by the factory." -msgstr "" - -#. Tag: classname -#: bootstrapping.xml:102 -#, no-c-format -msgid "ValidationProviderResolver" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:104 -#, no-c-format -msgid "By default, available Bean Validation providers are discovered using the Java Service Provider mechanism." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:109 -#, no-c-format -msgid "For that purpose, each provider includes the file META-INF/services/javax.validation.spi.ValidationProvider, containing the fully qualified classname of its ValidationProvider implementation. In the case of Hibernate Validator this is org.hibernate.validator.HibernateValidator." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:116 -#, no-c-format -msgid "Depending on your environment and its classloading specifics, provider discovery via the Java's service loader mechanism might not work. In this case you can plug in a custom ValidationProviderResolver implementation which performs the provider retrieval. An example is OSGi, where you could implement a provider resolver which uses OSGi services for provider discovery." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:124 -#, no-c-format -msgid "To use a custom provider resolver pass it via providerResolver() as shown shown in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:129 -#, no-c-format -msgid "Using a custom ValidationProviderResolver" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:132 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter08;\n" - "\n" - "public class OsgiServiceDiscoverer implements ValidationProviderResolver {\n" - "\n" - " @Override\n" - " public List<ValidationProvider<?>> getValidationProviders() {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:134 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" - " .providerResolver( new OsgiServiceDiscoverer() )\n" - " .configure()\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: title -#: bootstrapping.xml:140 -#, no-c-format -msgid "Configuring a ValidatorFactory" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:142 -#, no-c-format -msgid "By default validator factories retrieved from Validation and any validators they create are configured as per the XML descriptor META-INF/validation.xml (see ), if present." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:148 -#, no-c-format -msgid "If you want to disable the XML based configuration, you can do so by invoking Configuration#ignoreXmlConfiguration()." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:152 -#, no-c-format -msgid "The different values of the XML configuration can be accessed via Configuration#getBootstrapConfiguration(). This can for instance be helpful if you want to integrate Bean Validation into a managed environment and want to create managed instances of the objects configured via XML." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:158 -#, no-c-format -msgid "Using the fluent configuration API, you can override one or more of the settings when bootstrapping the factory. The following sections show how to make use of the different options. Note that the Configuration class exposes the default implementations of the different extension points which can be useful if you want to use these as delegates for your custom implementations." -msgstr "" - -#. Tag: classname -#: bootstrapping.xml:166 -#, no-c-format -msgid "MessageInterpolator" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:168 -#, no-c-format -msgid "Message interpolators are used by the validation engine to create user readable error messages from constraint message descriptors." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:171 -#, no-c-format -msgid "In case the default message interpolation algorithm described in is not sufficient for your needs, you can pass in your own implementation of the MessageInterpolator interface via Configuration#messageInterpolator() as shown in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:179 -#, no-c-format -msgid "Using a custom MessageInterpolator" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:182 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter08;\n" - "\n" - "public class MyMessageInterpolator implements MessageInterpolator {\n" - "\n" - " @Override\n" - " public String interpolate(String messageTemplate, Context context) {\n" - " //...\n" - " }\n" - "\n" - " @Override\n" - " public String interpolate(String messageTemplate, Context context, Locale locale) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:184 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" - " .configure()\n" - " .messageInterpolator( new MyMessageInterpolator() )\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: classname -#: bootstrapping.xml:189 -#, no-c-format -msgid "TraversableResolver" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:191 -#, no-c-format -msgid "In some cases the validation engine should not access the state of a bean property. The most obvious example for that is a lazily loaded property or association of a JPA entity. Validating this lazy property or association would mean that its state would have to be accessed, triggering a load from the database." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:197 -#, no-c-format -msgid "Which properties can be accessed and which ones not is controlled by querying the TraversableResolver interface. shows how to use a custom traversable resolver implementation." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:203 -#, no-c-format -msgid "Using a custom TraversableResolver" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:206 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter08;\n" - "\n" - "public class MyTraversableResolver implements TraversableResolver {\n" - "\n" - " @Override\n" - " public boolean isReachable(\n" - " Object traversableObject,\n" - " Node traversableProperty,\n" - " Class<?> rootBeanType,\n" - " Path pathToTraversableObject,\n" - " ElementType elementType) {\n" - " //...\n" - " }\n" - "\n" - " @Override\n" - " public boolean isCascadable(\n" - " Object traversableObject,\n" - " Node traversableProperty,\n" - " Class<?> rootBeanType,\n" - " Path pathToTraversableObject,\n" - " ElementType elementType) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:208 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" - " .configure()\n" - " .traversableResolver( new MyTraversableResolver() )\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:211 -#, no-c-format -msgid "Hibernate Validator provides two TraversableResolvers out of the box which will be enabled automatically depending on your environment. The first is DefaultTraversableResolver which will always return true for isReachable() and isTraversable(). The second is JPATraversableResolver which gets enabled when Hibernate Validator is used in combination with JPA 2." -msgstr "" - -#. Tag: classname -#: bootstrapping.xml:223 -#, no-c-format -msgid "ConstraintValidatorFactory" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:225 -#, no-c-format -msgid "ConstraintValidatorFactory is the extension point for customizing how constraint validators are instantiated and released." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:229 -#, no-c-format -msgid "The default ConstraintValidatorFactory provided by Hibernate Validator requires a public no-arg constructor to instantiate ConstraintValidator instances (see ). Using a custom ConstraintValidatorFactory offers for example the possibility to use dependency injection in constraint validator implementations." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:237 -#, no-c-format -msgid "To configure a custom constraint validator factory call Configuration#constraintValidatorFactory() (see ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:243 -#, no-c-format -msgid "Using a custom ConstraintValidatorFactory" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:246 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter08;\n" - "\n" - "public class MyConstraintValidatorFactory implements ConstraintValidatorFactory {\n" - "\n" - " @Override\n" - " public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {\n" - " //...\n" - " }\n" - "\n" - " @Override\n" - " public void releaseInstance(ConstraintValidator<?, ?> instance) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:248 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" - " .configure()\n" - " .constraintValidatorFactory( new MyConstraintValidatorFactory() )\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:252 -#, no-c-format -msgid "Any constraint implementations relying on ConstraintValidatorFactory behaviors specific to an implementation (dependency injection, no no-arg constructor and so on) are not considered portable." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:259 -#, no-c-format -msgid "ConstraintValidatorFactory implementations should not cache validator instances as the state of each instance can be altered in the initialize() method." -msgstr "" - -#. Tag: classname -#: bootstrapping.xml:267 -#, no-c-format -msgid "ParameterNameProvider" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:269 -#, no-c-format -msgid "In case a method or constructor parameter constraint is violated, the ParameterNameProvider interface is used to retrieve the parameter's name and make it available to the user via the constraint violation's property path." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:274 -#, no-c-format -msgid "The default implementation returns parameter names in the form arg0, arg1 etc., while custom implementations could e.g. be based on parameter annotations, debug symbols or a feature for retrieving parameter names at runtime possibly provided by future Java versions." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:280 -#, no-c-format -msgid "Custom ParameterNameProvider implementations are used as demonstrated in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:285 -#, no-c-format -msgid "Using a custom ParameterNameProvider" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:288 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter08;\n" - "\n" - "public class MyParameterNameProvider implements ParameterNameProvider {\n" - "\n" - " @Override\n" - " public List<String> getParameterNames(Constructor<?> constructor) {\n" - " //...\n" - " }\n" - "\n" - " @Override\n" - " public List<String> getParameterNames(Method method) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:290 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" - " .configure()\n" - " .parameterNameProvider( new MyParameterNameProvider() )\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: title -#: bootstrapping.xml:295 -#, no-c-format -msgid "Adding mapping streams" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:297 -#, no-c-format -msgid "As discussed earlier you can configure the constraints applying for your Java beans using XML based constraint mappings." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:300 -#, no-c-format -msgid "Besides the mapping files specified in META-INF/validation.xml you can add further mappings via Configuration#addMapping() (see ). Note that the passed input stream(s) must adhere to the XML schema for constraint mappings presented in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:308 -#, no-c-format -msgid "Adding constraint mapping streams" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:310 -#, no-c-format -msgid "" - "InputStream constraintMapping1 = ...;\n" - "InputStream constraintMapping2 = ...;\n" - "ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" - " .configure()\n" - " .addMapping( constraintMapping1 )\n" - " .addMapping( constraintMapping2 )\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:313 -#, no-c-format -msgid "You should close any passed input stream after the validator factory has been created." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:318 -#, no-c-format -msgid "Provider-specific settings" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:320 -#, no-c-format -msgid "Via the configuration object returned by Validation#byProvider() provider specific options can be configured." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:324 -#, no-c-format -msgid "In case of Hibernate Validator this allows you to enable the fail fast mode and pass one or more programmatic constraint mappings as demonstrated in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:330 -#, no-c-format -msgid "Setting Hibernate Validator specific options" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:332 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class )\n" - " .configure()\n" - " .failFast( true )\n" - " .addMapping( (ConstraintMapping) null )\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:335 -#, no-c-format -msgid "Alternatively, provider-specific options can be passed via Configuration#addProperty(). Hibernate Validator supports enabling the fail fast mode that way, too:" -msgstr "" - -#. Tag: title -#: bootstrapping.xml:340 -#, no-c-format -msgid "Enabling a Hibernate Validator specific option via addProperty()" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:343 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.byProvider( HibernateValidator.class )\n" - " .configure()\n" - " .addProperty( \"hibernate.validator.fail_fast\", \"true\" )\n" - " .buildValidatorFactory();\n" - "Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:346 -#, no-c-format -msgid "Refer to and to learn more about the fail fast mode and the constraint declaration API." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:353 -#, no-c-format -msgid "Configuring a Validator" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:355 -#, no-c-format -msgid "When working with a configured validator factory it can occasionally be required to apply a different configuration to a single Validator instance. shows how this can be achieved by calling ValidatorFactory#usingContext()." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:362 -#, no-c-format -msgid "Configuring a Validator via usingContext()" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:365 -#, no-c-format -msgid "" - "ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();\n" - "\n" - "Validator validator = validatorFactory.usingContext()\n" - " .messageInterpolator( new MyMessageInterpolator() )\n" - " .traversableResolver( new MyTraversableResolver() )\n" - " .getValidator();" -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/custom-constraints.pot b/documentation/src/main/docbook/pot/modules/custom-constraints.pot deleted file mode 100644 index 610578f041..0000000000 --- a/documentation/src/main/docbook/pot/modules/custom-constraints.pot +++ /dev/null @@ -1,858 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: custom-constraints.xml:24 -#, no-c-format -msgid "Creating custom constraints" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:26 -#, no-c-format -msgid "Though the Bean Validation API defines a whole set of standard constraint annotations one can easily think of situations in which these standard annotations won't suffice. For these cases you are able to create custom constraints tailored to your specific validation requirements in a simple manner." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:33 -#, no-c-format -msgid "Creating a simple constraint" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:35 -#, no-c-format -msgid "To create a custom constraint, the following three steps are required:" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:40 -#, no-c-format -msgid "Create a constraint annotation" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:44 -#, no-c-format -msgid "Implement a validator" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:48 -#, no-c-format -msgid "Define a default error message" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:53 -#, no-c-format -msgid "The constraint annotation" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:55 -#, no-c-format -msgid "Let's write a constraint annotation, that can be used to express that a given string shall either be upper case or lower case. We'll apply it later on to the licensePlate field of the Car class from to ensure, that the field is always an upper-case string." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:62 -#, no-c-format -msgid "First we need a way to express the two case modes. We might use String constants, but a better way to go is to use a Java 5 enum for that purpose:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:67 -#, no-c-format -msgid "Enum CaseMode to express upper vs. lower case" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:70 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06;\n" - "\n" - "public enum CaseMode {\n" - " UPPER,\n" - " LOWER;\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:73 -#, no-c-format -msgid "Now we can define the actual constraint annotation. If you've never designed an annotation before, this may look a bit scary, but actually it's not that hard:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:78 -#, no-c-format -msgid "Defining the CheckCase constraint annotation" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:81 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06;\n" - "\n" - "@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE })\n" - "@Retention(RUNTIME)\n" - "@Constraint(validatedBy = CheckCaseValidator.class)\n" - "@Documented\n" - "public @interface CheckCase {\n" - "\n" - " String message() default \"{org.hibernate.validator.referenceguide.chapter06.CheckCase.message}\";\n" - "\n" - " Class<?>[] groups() default { };\n" - "\n" - " Class<? extends Payload>[] payload() default { };\n" - "\n" - " CaseMode value();\n" - "\n" - " @Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE })\n" - " @Retention(RUNTIME)\n" - " @Documented\n" - " @interface List {\n" - " CheckCase[] value();\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:84 -#, no-c-format -msgid "An annotation type is defined using the @interface keyword. All attributes of an annotation type are declared in a method-like manner. The specification of the Bean Validation API demands, that any constraint annotation defines" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:91 -#, no-c-format -msgid "an attribute message that returns the default key for creating error messages in case the constraint is violated" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:97 -#, no-c-format -msgid "an attribute groups that allows the specification of validation groups, to which this constraint belongs (see ). This must default to an empty array of type Class<?>." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:104 -#, no-c-format -msgid "an attribute payload that can be used by clients of the Bean Validation API to assign custom payload objects to a constraint. This attribute is not used by the API itself. An example for a custom payload could be the definition of a severity:" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:110 -#, no-c-format -msgid "" - "public class Severity {\n" - " public interface Info extends Payload {\n" - " }\n" - "\n" - " public interface Error extends Payload {\n" - " }\n" - "}\n" - "\n" - "public class ContactDetails {\n" - " @NotNull(message = \"Name is mandatory\", payload = Severity.Error.class)\n" - " private String name;\n" - "\n" - " @NotNull(message = \"Phone number not specified, but not mandatory\",\n" - " payload = Severity.Info.class)\n" - " private String phoneNumber;\n" - "\n" - " // ...\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:112 -#, no-c-format -msgid "Now a client can after the validation of a ContactDetails instance access the severity of a constraint using ConstraintViolation.getConstraintDescriptor().getPayload() and adjust its behaviour depending on the severity." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:120 -#, no-c-format -msgid "Besides these three mandatory attributes we add another one, value, allowing for the required case mode to be specified. The name value is a special one, which can be omitted when using the annotation, if it is the only attribute specified, as e.g. in @CheckCase(CaseMode.UPPER)." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:126 -#, no-c-format -msgid "In addition we annotate the annotation type with a couple of meta annotations:" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:131 -#, no-c-format -msgid "@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE }): Defines the supported target element types for the constraint. @CheckCase may be used on fields (element type FIELD), JavaBeans properties as well as method return values (METHOD) and method/constructor parameters (PARAMETER). By adding the element type ANNOTATION_TYPE, we allow for the creation composed constraints (see ) based on @CheckCase." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:142 -#, no-c-format -msgid "Would we create a class-level constraint (see ), the element type TYPE had to be used. Constraints targetting the return value of a constructor need to support the element type CONSTRUCTOR. Cross-parameter constraints (see TODO) which are used to validate all the parameters of a method or constructor together, must support METHOD or CONSTRUCTOR, respectively." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:153 -#, no-c-format -msgid "@Retention(RUNTIME): Specifies, that annotations of this type will be available at runtime by the means of reflection" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:159 -#, no-c-format -msgid "@Constraint(validatedBy = CheckCaseValidator.class): Marks the annotation type as constraint annotation and specifies the validator to be used to validate elements annotated with @CheckCase. If a constraint may be used on several data types, several validators may be specified, one for each data type." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:168 -#, no-c-format -msgid "@Documented: Says, that the use of @CheckCase will be contained in the JavaDoc of elements annotated with it" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:174 -#, no-c-format -msgid "Finally, there is an inner annotation type named List. This annotation allows to specify several @CheckCase annotations on the same element, e.g. with different validation groups and messages. Note that while also another name could be used, we follow the Bean Validation, which recommends to use the name List and make the annotation an inner annotation of the corresponding constraint type." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:185 -#, no-c-format -msgid "The constraint validator" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:188 -#, no-c-format -msgid "Next, we need to implement a constraint validator, which is able to validate elements with a @CheckCase annotation. To do so, we implement the interface ConstraintValidator as shown below:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:194 -#, no-c-format -msgid "Implementing a constraint validator for the constraint CheckCase" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:197 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06;\n" - "\n" - "public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> {\n" - "\n" - " private CaseMode caseMode;\n" - "\n" - " @Override\n" - " public void initialize(CheckCase constraintAnnotation) {\n" - " this.caseMode = constraintAnnotation.value();\n" - " }\n" - "\n" - " @Override\n" - " public boolean isValid(String object, ConstraintValidatorContext constraintContext) {\n" - " if ( object == null ) {\n" - " return true;\n" - " }\n" - "\n" - " if ( caseMode == CaseMode.UPPER ) {\n" - " return object.equals( object.toUpperCase() );\n" - " }\n" - " else {\n" - " return object.equals( object.toLowerCase() );\n" - " }\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:200 -#, no-c-format -msgid "The ConstraintValidator interface defines two type parameters, which we set in our implementation. The first one specifies the annotation type to be validated (in our example CheckCase), the second one the type of elements, which the validator can handle (here String)." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:207 -#, no-c-format -msgid "In case a constraint annotation is allowed at elements of different types, a ConstraintValidator for each allowed type has to be implemented and registered at the constraint annotation as shown above." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:212 -#, no-c-format -msgid "The implementation of the validator is straightforward. The initialize() method gives us access to the attribute values of the annotation to be validated. In the example we store the CaseMode in a field of the validator for further usage." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:218 -#, no-c-format -msgid "In the isValid() method we implement the logic, that determines, whether a String is valid according to a given @CheckCase annotation or not. This decision depends on the case mode retrieved in initialize(). As the Bean Validation specification recommends, we consider null values as being valid. If null is not a valid value for an element, it should be annotated with @NotNull explicitly." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:228 -#, no-c-format -msgid "The ConstraintValidatorContext" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:230 -#, no-c-format -msgid "relies on the default error message generation by just returning true or false from the isValid call. Using the passed ConstraintValidatorContext object it is possible to either add additional error messages or completely disable the default error message generation and solely define custom error messages. The ConstraintValidatorContext API is modeled as fluent interface and is best demonstrated with an example:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:242 -#, no-c-format -msgid "Use of ConstraintValidatorContext to define custom error messages" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:245 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06.constraintvalidatorcontext;\n" - "\n" - "public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> {\n" - "\n" - " private CaseMode caseMode;\n" - "\n" - " @Override\n" - " public void initialize(CheckCase constraintAnnotation) {\n" - " this.caseMode = constraintAnnotation.value();\n" - " }\n" - "\n" - " @Override\n" - " public boolean isValid(String object, ConstraintValidatorContext constraintContext) {\n" - " if ( object == null ) {\n" - " return true;\n" - " }\n" - "\n" - " boolean isValid;\n" - " if ( caseMode == CaseMode.UPPER ) {\n" - " isValid = object.equals( object.toUpperCase() );\n" - " }\n" - " else {\n" - " isValid = object.equals( object.toLowerCase() );\n" - " }\n" - "\n" - " if ( !isValid ) {\n" - " constraintContext.disableDefaultConstraintViolation();\n" - " constraintContext.buildConstraintViolationWithTemplate(\n" - " \"{org.hibernate.validator.referenceguide.chapter06.constraintvalidatorcontext.CheckCase.message}\"\n" - " )\n" - " .addConstraintViolation();\n" - " }\n" - "\n" - " return isValid;\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:248 -#, no-c-format -msgid "shows how you can disable the default error message generation and add a custom error message using a specified message template. In this example the use of the ConstraintValidatorContext results in the same error message as the default error message generation." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:254 -#, no-c-format -msgid "It is important to add each configured constraint violation by calling addConstraintViolation(). Only after that the new constraint violation will be created." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:259 -#, no-c-format -msgid "In case you are implementing a ConstraintValidator for a class-level constraint it is also possible to adjust the property path for the created constraint violations. This is important for the case where you validate multiple properties of the class or even traverse the object graph and want the constraint violation to point to one of the involved properties only. As an example, shows the validator of a custom class-level constraint @ValidPassengerCount which makes sure that a car has not more passengers than seats. If this constraint is violated, this violation is reported at the passengers property." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:273 -#, no-c-format -msgid "Adding new ConstraintViolation with custom property path" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:276 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06.custompath;\n" - "\n" - "public class ValidPassengerCountValidator\n" - " implements ConstraintValidator<ValidPassengerCount, Car> {\n" - "\n" - " @Override\n" - " public void initialize(ValidPassengerCount constraintAnnotation) {\n" - " }\n" - "\n" - " @Override\n" - " public boolean isValid(Car car, ConstraintValidatorContext constraintValidatorContext) {\n" - " if ( car == null ) {\n" - " return true;\n" - " }\n" - "\n" - " boolean isValid = car.getPassengers().size() <= car.getSeatCount();\n" - "\n" - " if ( !isValid ) {\n" - " constraintValidatorContext.disableDefaultConstraintViolation();\n" - " constraintValidatorContext\n" - " .buildConstraintViolationWithTemplate( \"{my.custom.template}\" )\n" - " .addPropertyNode( \"passengers\" ).addConstraintViolation();\n" - " }\n" - "\n" - " return isValid;\n" - " }\n" - "}" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:282 -#, no-c-format -msgid "The error message" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:284 -#, no-c-format -msgid "Finally we need to specify the error message, that shall be used, in case a @CheckCase constraint is violated. To do so, we add the following to our custom ValidationMessages.properties (see also )" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:291 -#, no-c-format -msgid "Defining a custom error message for the CheckCase constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:294 -#, no-c-format -msgid "org.hibernate.validator.referenceguide.chapter06.CheckCase.message=Case mode must be {value}." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:297 -#, no-c-format -msgid "If a validation error occurs, the validation runtime will use the default value, that we specified for the message attribute of the @CheckCase annotation to look up the error message in this file." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:304 -#, no-c-format -msgid "Using the constraint" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:306 -#, no-c-format -msgid "Now that our first custom constraint is completed, we can use it in the Car class from the chapter to specify that the licensePlate field shall only contain upper-case strings:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:313 -#, no-c-format -msgid "Applying the CheckCase constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:316 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private final String manufacturer;\n" - "\n" - " @NotNull\n" - " @Size(min = 2, max = 14)\n" - " @CheckCase(CaseMode.UPPER)\n" - " private final String licensePlate;\n" - "\n" - " @Min(2)\n" - " private final int seatCount;\n" - "\n" - " public Car ( String manufacturer, String licencePlate, int seatCount ) {\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licencePlate;\n" - " this.seatCount = seatCount;\n" - " }\n" - "\n" - " //getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:319 -#, no-c-format -msgid "Finally let's demonstrate in a little test that the @CheckCase constraint is properly validated:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:324 -#, no-c-format -msgid "Testcase demonstrating the CheckCase validation" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:327 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06;\n" - "\n" - "public class CarTest {\n" - "\n" - " private static Validator validator;\n" - "\n" - " @BeforeClass\n" - " public static void setUp() {\n" - " ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - " validator = factory.getValidator();\n" - " }\n" - "\n" - " @Test\n" - " public void testLicensePlateNotUpperCase() {\n" - "\n" - " Car car = new Car( \"Morris\", \"dd-ab-123\", 4 );\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate( car );\n" - " assertEquals( 1, constraintViolations.size() );\n" - " assertEquals(\n" - " \"Case mode must be UPPER.\",\n" - " constraintViolations.iterator().next().getMessage()\n" - " );\n" - " }\n" - "\n" - " @Test\n" - " public void carIsValid() {\n" - "\n" - " Car car = new Car( \"Morris\", \"DD-AB-123\", 4 );\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate( car );\n" - "\n" - " assertEquals( 0, constraintViolations.size() );\n" - " }\n" - "}" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:333 -#, no-c-format -msgid "Cross-parameter constraints" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:335 -#, no-c-format -msgid "Bean Validation distinguishes between two different kinds of constraints." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:338 -#, no-c-format -msgid "Generic constraints (which have been discussed so far) apply to the annotated element, e.g. a type, field, method parameter or return value etc. Cross-parameter constraints, in contrast, apply to the array of parameters of a method or constructor and can be used to express validation logic which depends on several parameter values." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:344 -#, no-c-format -msgid "In order to define a cross-parameter constraint, its validator class must be annotated with @SupportedValidationTarget(ValidationTarget.PARAMETERS). The type parameter T from the ConstraintValidator interface must resolve to either Object or Object[] in order to receive the array of method/constructor arguments in the isValid() method." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:353 -#, no-c-format -msgid "The following example shows the definition of a cross-parameter constraint which can be used to check that two Date parameters of a method are in the correct order:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:358 -#, no-c-format -msgid "Cross-parameter constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:360 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06.crossparameter;\n" - "\n" - "@Constraint(validatedBy = ConsistentDateParameterValidator.class)\n" - "@Target({ METHOD, CONSTRUCTOR, ANNOTATION_TYPE })\n" - "@Retention(RUNTIME)\n" - "@Documented\n" - "public @interface ConsistentDateParameters {\n" - "\n" - " String message() default \"{org.hibernate.validator.referenceguide.chapter06.\" +\n" - " \"crossparameter.ConsistentDateParameters.message}\";\n" - "\n" - " Class<?>[] groups() default { };\n" - "\n" - " Class<? extends Payload>[] payload() default { };\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:363 -#, no-c-format -msgid "The definition of a cross-parameter constraint isn't any different from defining a generic constraint, i.e. it must specify the members message(), groups() and payload() and be annotated with @Constraint. This meta annotation also specifies the corresponding validator, which is shown in . Note that besides the element types METHOD and CONSTRUCTOR also ANNOTATION_TYPE is specified as target of the annotation, in order to enable the creation of composed constraints based on @ConsistentDateParameters (see )." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:378 -#, no-c-format -msgid "Cross-parameter constraints are specified directly on the declaration of a method or constructor, which is also the case for return value constraints. In order to improve code readability, it is therefore recommended to chose constraint names — such as @ConsistentDateParameters — which make the constraint target aparent." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:387 custom-constraints.xml:419 -#, no-c-format -msgid "Generic and cross-parameter constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:389 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06.crossparameter;\n" - "\n" - "@SupportedValidationTarget(ValidationTarget.PARAMETERS)\n" - "public class ConsistentDateParameterValidator implements\n" - " ConstraintValidator<ConsistentDateParameters, Object[]> {\n" - "\n" - " @Override\n" - " public void initialize(ConsistentDateParameters constraintAnnotation) {\n" - " }\n" - "\n" - " @Override\n" - " public boolean isValid(Object[] value, ConstraintValidatorContext context) {\n" - " if ( value.length != 2 ) {\n" - " throw new IllegalArgumentException( \"Illegal method signature\" );\n" - " }\n" - "\n" - " //leave null-checking to @NotNull on individual parameters\n" - " if ( value[0] == null || value[1] == null ) {\n" - " return true;\n" - " }\n" - "\n" - " if ( !( value[0] instanceof Date ) || !( value[1] instanceof Date ) ) {\n" - " throw new IllegalArgumentException(\n" - " \"Illegal method signature, expected two \" +\n" - " \"parameters of type Date.\"\n" - " );\n" - " }\n" - "\n" - " return ( (Date) value[0] ).before( (Date) value[1] );\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:392 -#, no-c-format -msgid "As discussed above, the validation target PARAMETERS must be configured for a cross-parameter validator by using the @SupportedValidationTarget annotation. Since a cross-parameter constraint could be applied to any method or constructor, it is considered a best practice to check for the expected number and types of parameters in the validator implementation. As with generic constraints, null parameters should be considered valid and @NotNull on the individual parameters should be used to make sure that parameters are not null." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:403 -#, no-c-format -msgid "In rare situations a constraint is both, generic and cross-parameter. This is the case if a constraint has a validator class which is annotated with @SupportedValidationTarget({ValidationTarget.PARAMETERS, ValidationTarget.ANNOTATED_ELEMENT}) or if it has a generic and a cross-parameter validator class." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:410 -#, no-c-format -msgid "When declaring such a constraint on a method which has parameters and also a return value, the intended constraint target can't be determined. Constraints which are generic and cross-parameter at the same time, must therefore define a member validationAppliesTo() which allows the constraint user to specify the constraint's target as shown in ." -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:421 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06.crossparameter;\n" - "\n" - "@Constraint(validatedBy = {\n" - " ScriptAssertObjectValidator.class,\n" - " ScriptAssertParametersValidator.class\n" - "})\n" - "@Target({ TYPE, FIELD, PARAMETER, METHOD, CONSTRUCTOR, ANNOTATION_TYPE })\n" - "@Retention(RUNTIME)\n" - "@Documented\n" - "public @interface ScriptAssert {\n" - "\n" - " String message() default \"{org.hibernate.validator.referenceguide.chapter06.\" +\n" - " \"crossparameter.ScriptAssert.message}\";\n" - "\n" - " Class<?>[] groups() default { };\n" - "\n" - " Class<? extends Payload>[] payload() default { };\n" - "\n" - " String script();\n" - "\n" - " ConstraintTarget validationAppliesTo() default ConstraintTarget.IMPLICIT;\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:424 -#, no-c-format -msgid "The @ScriptAssert constraint has two validators (not shown), a generic and a cross-parameter one and thus defines the member validationAppliesTo(). The default value IMPLICIT allows to derive the target automatically in situations where this is possible (e.g. if the constraint is declared on a field or on a method which has parameters but no return value)." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:432 -#, no-c-format -msgid "If the target can not be determined implicitly, it must be set by the user to either PARAMETERS or RETURN_VALUE as shown in ." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:438 -#, no-c-format -msgid "Specifying the target for a generic and cross-parameter constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:441 -#, no-c-format -msgid "" - "@ScriptAssert(script = \"arg1.size() <= arg0\", validationAppliesTo = ConstraintTarget.PARAMETERS)\n" - "public Car buildCar(int seatCount, List<Passenger> passengers) {\n" - " //...\n" - "}" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:446 -#, no-c-format -msgid "Constraint composition" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:448 -#, no-c-format -msgid "In the following, we'll discuss how to create higher level constraints by composing several basic constraints." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:451 -#, no-c-format -msgid "Looking at the licensePlate field of the Car class in , we see three constraint annotations already. In complexer scenarios, where even more constraints could be applied to one element, this might become a bit confusing easily. Furthermore, if we had a licensePlate field in another class, we would have to copy all constraint declarations to the other class as well, violating the DRY principle." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:460 -#, no-c-format -msgid "This problem can be tackled using composed constraints. In the following we create a new constraint annotation @ValidLicensePlate, that comprises the constraints @NotNull, @Size and @CheckCase:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:467 -#, no-c-format -msgid "Creating a composing constraint ValidLicensePlate" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:470 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06.constraintcomposition;\n" - "\n" - "@NotNull\n" - "@Size(min = 2, max = 14)\n" - "@CheckCase(CaseMode.UPPER)\n" - "@Target({ METHOD, FIELD, ANNOTATION_TYPE })\n" - "@Retention(RUNTIME)\n" - "@Constraint(validatedBy = { })\n" - "@Documented\n" - "public @interface ValidLicensePlate {\n" - "\n" - " String message() default \"{org.hibernate.validator.referenceguide.chapter06.constraintcomposition.ValidLicensePlate.message}\";\n" - "\n" - " Class<?>[] groups() default { };\n" - "\n" - " Class<? extends Payload>[] payload() default { };\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:473 -#, no-c-format -msgid "To do so, we just have to annotate the constraint declaration with its comprising constraints (btw. that's exactly why we allowed annotation types as target for the @CheckCase annotation). As no additional validation is required for the @ValidLicensePlate annotation itself, we don't declare a validator within the @Constraint meta annotation." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:481 -#, no-c-format -msgid "Using the new composed constraint at the licensePlate field is fully equivalent to the previous version, where we declared the three constraints directly at the field itself:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:487 -#, no-c-format -msgid "Application of composing constraint ValidLicensePlate" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:490 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter06.constraintcomposition;\n" - "\n" - "public class Car {\n" - "\n" - " @ValidLicensePlate\n" - " private String licensePlate;\n" - "\n" - " //...\n" - "}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:493 -#, no-c-format -msgid "The set of ConstraintViolations retrieved when validating a Car instance will contain an entry for each violated composing constraint of the @ValidLicensePlate constraint. If you rather prefer a single ConstraintViolation in case any of the composing constraints is violated, the @ReportAsSingleViolation meta constraint can be used as follows:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:503 -#, no-c-format -msgid "Usage of @ReportAsSingleViolation" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:505 -#, no-c-format -msgid "" - "//...\n" - "@ReportAsSingleViolation\n" - "public @interface ValidLicensePlate {\n" - "\n" - " String message() default \"{org.hibernate.validator.referenceguide.chapter06.constraintcomposition.ValidLicensePlate.message}\";\n" - "\n" - " Class<?>[] groups() default { };\n" - "\n" - " Class<? extends Payload>[] payload() default { };\n" - "}" -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/custom-options.pot b/documentation/src/main/docbook/pot/modules/custom-options.pot deleted file mode 100644 index 484a424247..0000000000 --- a/documentation/src/main/docbook/pot/modules/custom-options.pot +++ /dev/null @@ -1,471 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: custom-options.xml:24 -#, no-c-format -msgid "Hibernate Validator Specifics" -msgstr "" - -#. Tag: para -#: custom-options.xml:26 -#, no-c-format -msgid "In this chapter you will learn how to make use of several features provided by Hibernate Validator in addition to the functionality defined by the Bean Validation specification. This includes the fail fast mode, the API for programmatic constraint configuration and the boolean composition of constraints." -msgstr "" - -#. Tag: para -#: custom-options.xml:33 -#, no-c-format -msgid "Using the features described in the following sections may result in application code which is not portable between Bean Validation providers." -msgstr "" - -#. Tag: title -#: custom-options.xml:39 -#, no-c-format -msgid "Public API" -msgstr "" - -#. Tag: para -#: custom-options.xml:41 -#, no-c-format -msgid "Let's start, however, with a look at the public API of Hibernate Validator. lists all packages belonging to this API and describes their purpose. Note that when a package is part of the public this is not necessarily true for its sub-packages." -msgstr "" - -#. Tag: title -#: custom-options.xml:48 -#, no-c-format -msgid "Hibernate Validator public API" -msgstr "" - -#. Tag: entry -#: custom-options.xml:53 -#, no-c-format -msgid "Packages" -msgstr "" - -#. Tag: entry -#: custom-options.xml:55 -#, no-c-format -msgid "Description" -msgstr "" - -#. Tag: package -#: custom-options.xml:61 -#, no-c-format -msgid "org.hibernate.validator" -msgstr "" - -#. Tag: entry -#: custom-options.xml:63 -#, no-c-format -msgid "Classes used by the Bean Validation bootstrap mechanism (eg. validation provider, configuration class); For more details see ." -msgstr "" - -#. Tag: entry -#: custom-options.xml:69 -#, no-c-format -msgid "org.hibernate.validator.cfg, org.hibernate.validator.cfg.context, org.hibernate.validator.cfg.defs" -msgstr "" - -#. Tag: entry -#: custom-options.xml:73 -#, no-c-format -msgid "Hibernate Validator's fluent API for constraint declaration; In org.hibernate.validator.cfg you will find the ConstraintMapping interface and in org.hibernate.validator.cfg.defs all constraint definitions. Refer to for the details." -msgstr "" - -#. Tag: entry -#: custom-options.xml:82 -#, no-c-format -msgid "org.hibernate.validator.constraints, org.hibernate.validator.constraints.br" -msgstr "" - -#. Tag: entry -#: custom-options.xml:85 -#, no-c-format -msgid "Some useful custom constraints provided by Hibernate Validator in addition to the built-in constraints defined by the Bean Validation specification; The constraints are described in detail in ." -msgstr "" - -#. Tag: entry -#: custom-options.xml:93 -#, no-c-format -msgid "org.hibernate.validator.group, org.hibernate.validator.spi.group" -msgstr "" - -#. Tag: entry -#: custom-options.xml:96 -#, no-c-format -msgid "The group sequence provider feature which allows you to define dynamic default group sequences in function of the validated object state; The specifics can be found in ." -msgstr "" - -#. Tag: entry -#: custom-options.xml:103 -#, no-c-format -msgid "org.hibernate.validator.messageinterpolation, org.hibernate.validator.resourceloading, org.hibernate.validator.spi.resourceloading" -msgstr "" - -#. Tag: entry -#: custom-options.xml:107 -#, no-c-format -msgid "Classes related to constraint message interpolation; The first package contains Hibernate Validator's default message interpolator, ResourceBundleMessageInterpolator. The latter two packages provide the ResourceBundleLocator SPI for the loading of resource bundles (see ) and its default implementation." -msgstr "" - -#. Tag: para -#: custom-options.xml:121 -#, no-c-format -msgid "The public packages of Hibernate Validator fall into two categories: while the actual API parts are intended to be invoked or used by clients (e.g. the API for programmatic constraint declaration or the custom constraints), the SPI (service provider interface) packages contain interfaces which are intended to be implemented by clients (e.g. ResourceBundleLocator)." -msgstr "" - -#. Tag: para -#: custom-options.xml:130 -#, no-c-format -msgid "Any packages not listed in that table are internal packages of Hibernate Validator and are not intended to be accessed by clients. The contents of these internal packages can change from release to release without notice, thus possibly breaking any client code relying on it." -msgstr "" - -#. Tag: title -#: custom-options.xml:138 -#, no-c-format -msgid "Fail fast mode" -msgstr "" - -#. Tag: para -#: custom-options.xml:140 -#, no-c-format -msgid "Using the fail fast mode, Hibernate Validator allows to return from the current validation as soon as the first constraint violation occurs. This can be useful for the validation of large object graphs where you are only interested in a quick check whether there is any constraint violation at all." -msgstr "" - -#. Tag: para -#: custom-options.xml:146 -#, no-c-format -msgid "shows how to bootstrap and use a fail fast enabled validator." -msgstr "" - -#. Tag: title -#: custom-options.xml:150 -#, no-c-format -msgid "Using the fail fast validation mode" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:152 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter11.failfast;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @AssertTrue\n" - " private boolean isRegistered;\n" - "\n" - " public Car(String manufacturer, boolean isRegistered) {\n" - " this.manufacturer = manufacturer;\n" - " this.isRegistered = isRegistered;\n" - " }\n" - "\n" - " //getters and setters...\n" - "}" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:154 -#, no-c-format -msgid "" - "Validator validator = Validation.byProvider( HibernateValidator.class )\n" - " .configure()\n" - " .failFast( true )\n" - " .buildValidatorFactory()\n" - " .getValidator();\n" - "\n" - "Car car = new Car( null, false );\n" - "\n" - "Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );\n" - "\n" - "assertEquals( 1, constraintViolations.size() );" -msgstr "" - -#. Tag: para -#: custom-options.xml:157 -#, no-c-format -msgid "Here the validated object actually fails to satisfy both the constraints declared on the Car class, yet the validation call yields only one ConstraintViolation since the fail fast mode is enabled." -msgstr "" - -#. Tag: para -#: custom-options.xml:163 -#, no-c-format -msgid "There is no guarantee in which order the constraints are evaluated, i.e. it is not deterministic whether the returned violation originates from the @NotNull or the @AssertTrue constraint. If required, a deterministic evaluation order can be enforced using group sequences as described in ." -msgstr "" - -#. Tag: para -#: custom-options.xml:171 -#, no-c-format -msgid "Refer to to learn about the different ways of enabling the fail fast mode when bootstrapping a validator." -msgstr "" - -#. Tag: title -#: custom-options.xml:177 custom-options.xml:203 -#, no-c-format -msgid "Programmatic constraint declaration" -msgstr "" - -#. Tag: para -#: custom-options.xml:179 -#, no-c-format -msgid "As per the Bean Validation specification, you can declare constraints using Java annotations and XML based constraint mappings." -msgstr "" - -#. Tag: para -#: custom-options.xml:183 -#, no-c-format -msgid "In addition, Hibernate Validator provides a fluent API which allows for the programmatic configuration of constraints. Use cases include the dynamic addition of constraints at runtime depending on some application state or tests where you need entities with different constraints in different scenarios but don't want to implement actual Java classes for each test case." -msgstr "" - -#. Tag: para -#: custom-options.xml:190 -#, no-c-format -msgid "By default, constraints added via the fluent API are additive to constraints configured via the standard configuration capabilities. But it is also possible to ignore annotation and XML configured constraints where required." -msgstr "" - -#. Tag: para -#: custom-options.xml:195 -#, no-c-format -msgid "The API is centered around the ConstraintMapping interface. You obtain a new mapping via HibernateValidatorConfiguration#createConstraintMapping() which you then can configure in a fluent manner as shown in ." -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:205 -#, no-c-format -msgid "" - "HibernateValidatorConfiguration configuration = Validation\n" - " .byProvider( HibernateValidator.class )\n" - " .configure();\n" - "\n" - "ConstraintMapping constraintMapping = configuration.createConstraintMapping();\n" - "\n" - "constraintMapping\n" - " .type( Car.class )\n" - " .property( \"manufacturer\", FIELD )\n" - " .constraint( new NotNullDef() )\n" - " .property( \"licensePlate\", FIELD )\n" - " .ignoreAnnotations()\n" - " .constraint( new NotNullDef() )\n" - " .constraint( new SizeDef().min( 2 ).max( 14 ) )\n" - " .type( RentalCar.class )\n" - " .property( \"rentalStation\", METHOD )\n" - " .constraint( new NotNullDef() );\n" - "\n" - "Validator validator = configuration.addMapping( constraintMapping )\n" - " .buildValidatorFactory()\n" - " .getValidator();" -msgstr "" - -#. Tag: para -#: custom-options.xml:208 -#, no-c-format -msgid "Constraints can be configured on multiple classes and properties using method chaining. The constraint definition classes NotNullDef and SizeDef are helper classes which allow to configure constraint parameters in a type-safe fashion. Definition classes exist for all built-in constraints in the org.hibernate.validator.cfg.defs package. By calling ignoreAnnotations() any constraints configured via annotations or XML are ignored for the given element." -msgstr "" - -#. Tag: para -#: custom-options.xml:218 -#, no-c-format -msgid "Having configured the mapping, you must add it back to the configuration object from which you then can obtain a validator factory." -msgstr "" - -#. Tag: para -#: custom-options.xml:222 -#, no-c-format -msgid "For custom constraints you can either create your own definition classes extending ConstraintDef or you can use GenericConstraintDef as seen in ." -msgstr "" - -#. Tag: title -#: custom-options.xml:228 -#, no-c-format -msgid "Programmatic declaration of a custom constraint" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:230 -#, no-c-format -msgid "" - "ConstraintMapping constraintMapping = configuration.createConstraintMapping();\n" - "\n" - "constraintMapping\n" - " .type( Car.class )\n" - " .property( \"licensePlate\", FIELD )\n" - " .constraint( new GenericConstraintDef<CheckCase>( CheckCase.class )\n" - " .param( \"value\", CaseMode.UPPER )\n" - " );" -msgstr "" - -#. Tag: para -#: custom-options.xml:233 -#, no-c-format -msgid "By invoking valid() a member is marked for cascasded validation which is equivalent to annotating it with @Valid. An example can be seen in ." -msgstr "" - -#. Tag: title -#: custom-options.xml:239 -#, no-c-format -msgid "Marking a property for cascaded validation" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:241 -#, no-c-format -msgid "" - "ConstraintMapping constraintMapping = configuration.createConstraintMapping();\n" - "\n" - "constraintMapping\n" - " .type( Car.class )\n" - " .property( \"driver\", FIELD )\n" - " .constraint( new NotNullDef() )\n" - " .valid()\n" - " .type( Person.class )\n" - " .property( \"name\", FIELD )\n" - " .constraint( new NotNullDef() );" -msgstr "" - -#. Tag: para -#: custom-options.xml:244 -#, no-c-format -msgid "Not only bean constraints but also method constraints can be configured using the fluent API. As shown in methods are identified by their name and parameter types. Having selected a method, you can marke its parameters and/or return value for cascaded validation and add constraints." -msgstr "" - -#. Tag: title -#: custom-options.xml:252 -#, no-c-format -msgid "Programmatic declaration of method constraints" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:254 -#, no-c-format -msgid "" - "ConstraintMapping constraintMapping = configuration.createConstraintMapping();\n" - "\n" - "constraintMapping\n" - " .type( Car.class )\n" - " .method( \"drive\", int.class )\n" - " .parameter( 0 )\n" - " .constraint( new MaxDef().value ( 75 ) )\n" - " .method( \"getDriver\" )\n" - " .returnValue()\n" - " .constraint( new NotNullDef() )\n" - " .valid();" -msgstr "" - -#. Tag: para -#: custom-options.xml:257 -#, no-c-format -msgid "Last but not least you can configure the default group sequence or the default group sequence provider of a type as shown in the following example." -msgstr "" - -#. Tag: title -#: custom-options.xml:262 -#, no-c-format -msgid "Configuration of default group sequence and default group sequence provider" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:265 -#, no-c-format -msgid "" - "ConstraintMapping constraintMapping = configuration.createConstraintMapping();\n" - "\n" - "constraintMapping\n" - " .type( Car.class )\n" - " .defaultGroupSequence( Car.class, CarChecks.class )\n" - " .type( RentalCar.class )\n" - " .defaultGroupSequenceProviderClass( RentalCarGroupSequenceProvider.class );" -msgstr "" - -#. Tag: title -#: custom-options.xml:270 -#, no-c-format -msgid "Boolean composition of constraints" -msgstr "" - -#. Tag: para -#: custom-options.xml:272 -#, no-c-format -msgid "Bean Validation specificies that the constraints of a composed constraint (see ) are all combined via a logical AND. This means all of the composing constraints need to return true in order for an overall successful validation." -msgstr "" - -#. Tag: para -#: custom-options.xml:278 -#, no-c-format -msgid "Hibernate Validator offers an extension to this and allows you to compose constraints via a logical OR or NOT. To do so you have to use the ConstraintComposition annotation and the enum CompositionType with its values AND, OR and ALL_FALSE." -msgstr "" - -#. Tag: para -#: custom-options.xml:286 -#, no-c-format -msgid "shows how to build a composed constraint @PatternOrSize where only one of the composing constraints needs to be valid in order to pass the validation. Either the validated string is all lower-cased or it is between two and three characters long." -msgstr "" - -#. Tag: title -#: custom-options.xml:293 -#, no-c-format -msgid "OR composition of constraints" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:295 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter11.booleancomposition;\n" - "\n" - "@ConstraintComposition(OR)\n" - "@Pattern(regexp = \"[a-z]\")\n" - "@Size(min = 2, max = 3)\n" - "@ReportAsSingleViolation\n" - "@Target({ METHOD, FIELD })\n" - "@Retention(RUNTIME)\n" - "@Constraint(validatedBy = { })\n" - "public @interface PatternOrSize {\n" - " String message() default \"{org.hibernate.validator.referenceguide.chapter11.\" +\n" - " \"booleancomposition.PatternOrSize.message}\";\n" - "\n" - " Class<?>[] groups() default { };\n" - "\n" - " Class<? extends Payload>[] payload() default { };\n" - "}" -msgstr "" - -#. Tag: para -#: custom-options.xml:299 -#, no-c-format -msgid "Using ALL_FALSE as composition type implicitly enforces that only a single violation will get reported in case validation of the constraint composition fails." -msgstr "" - -#. Tag: classname -#: custom-options.xml:306 -#, no-c-format -msgid "ResourceBundleLocator" -msgstr "" - -#. Tag: para -#: custom-options.xml:308 -#, no-c-format -msgid "As described in , Bean Validation allows to plug in custom message interpolator implementations." -msgstr "" - -#. Tag: para -#: custom-options.xml:312 -#, no-c-format -msgid "With ResourceBundleLocator, Hibernate Validator provides an additional SPI which allows to retrieve error messages from other resource bundles than ValidationMessages while still using the actual interpolation algorithm as defined by the specification. Refer to to learn how to make use of that SPI." -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/customconstraints.pot b/documentation/src/main/docbook/pot/modules/customconstraints.pot deleted file mode 100644 index 19dc028e45..0000000000 --- a/documentation/src/main/docbook/pot/modules/customconstraints.pot +++ /dev/null @@ -1,687 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2011-11-14 10:37+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: customconstraints.xml:24 -#, no-c-format -msgid "Creating custom constraints" -msgstr "" - -#. Tag: para -#: customconstraints.xml:26 -#, no-c-format -msgid "Though the Bean Validation API defines a whole set of standard constraint annotations one can easily think of situations in which these standard annotations won't suffice. For these cases you are able to create custom constraints tailored to your specific validation requirements in a simple manner." -msgstr "" - -#. Tag: title -#: customconstraints.xml:33 -#, no-c-format -msgid "Creating a simple constraint" -msgstr "" - -#. Tag: para -#: customconstraints.xml:35 -#, no-c-format -msgid "To create a custom constraint, the following three steps are required:" -msgstr "" - -#. Tag: para -#: customconstraints.xml:40 -#, no-c-format -msgid "Create a constraint annotation" -msgstr "" - -#. Tag: para -#: customconstraints.xml:44 -#, no-c-format -msgid "Implement a validator" -msgstr "" - -#. Tag: para -#: customconstraints.xml:48 -#, no-c-format -msgid "Define a default error message" -msgstr "" - -#. Tag: title -#: customconstraints.xml:53 -#, no-c-format -msgid "The constraint annotation" -msgstr "" - -#. Tag: para -#: customconstraints.xml:55 -#, no-c-format -msgid "Let's write a constraint annotation, that can be used to express that a given string shall either be upper case or lower case. We'll apply it later on to the licensePlate field of the Car class from to ensure, that the field is always an upper-case string." -msgstr "" - -#. Tag: para -#: customconstraints.xml:62 -#, no-c-format -msgid "First we need a way to express the two case modes. We might use String constants, but a better way to go is to use a Java 5 enum for that purpose:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:67 -#, no-c-format -msgid "Enum CaseMode to express upper vs. lower case" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:70 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "public enum CaseMode {\n" - " UPPER, \n" - " LOWER;\n" - "}" -msgstr "" - -#. Tag: para -#: customconstraints.xml:73 -#, no-c-format -msgid "Now we can define the actual constraint annotation. If you've never designed an annotation before, this may look a bit scary, but actually it's not that hard:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:78 -#, no-c-format -msgid "Defining CheckCase constraint annotation" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:80 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import static java.lang.annotation.ElementType.*;\n" - "import static java.lang.annotation.RetentionPolicy.*;\n" - "\n" - "import java.lang.annotation.Documented;\n" - "import java.lang.annotation.Retention;\n" - "import java.lang.annotation.Target;\n" - "\n" - "import javax.validation.Constraint;\n" - "import javax.validation.Payload;\n" - "\n" - "@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n" - "@Retention(RUNTIME)\n" - "@Constraint(validatedBy = CheckCaseValidator.class)\n" - "@Documented\n" - "public @interface CheckCase {\n" - "\n" - " String message() default \"{com.mycompany.constraints.checkcase}\";\n" - "\n" - " Class<?>[] groups() default {};\n" - "\n" - " Class<? extends Payload>[] payload() default {};\n" - " \n" - " CaseMode value();\n" - "\n" - "}" -msgstr "" - -#. Tag: para -#: customconstraints.xml:83 -#, no-c-format -msgid "An annotation type is defined using the @interface keyword. All attributes of an annotation type are declared in a method-like manner. The specification of the Bean Validation API demands, that any constraint annotation defines" -msgstr "" - -#. Tag: para -#: customconstraints.xml:90 -#, no-c-format -msgid "an attribute message that returns the default key for creating error messages in case the constraint is violated" -msgstr "" - -#. Tag: para -#: customconstraints.xml:96 -#, no-c-format -msgid "an attribute groups that allows the specification of validation groups, to which this constraint belongs (see ). This must default to an empty array of type Class<?>." -msgstr "" - -#. Tag: para -#: customconstraints.xml:104 -#, no-c-format -msgid "an attribute payload that can be used by clients of the Bean Validation API to assign custom payload objects to a constraint. This attribute is not used by the API itself." -msgstr "" - -#. Tag: para -#: customconstraints.xml:108 -#, no-c-format -msgid "An example for a custom payload could be the definition of a severity." -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:111 -#, no-c-format -msgid "" - "public class Severity {\n" - " public static class Info extends Payload {};\n" - " public static class Error extends Payload {};\n" - "}\n" - "\n" - "public class ContactDetails {\n" - " @NotNull(message=\"Name is mandatory\", payload=Severity.Error.class)\n" - " private String name;\n" - "\n" - " @NotNull(message=\"Phone number not specified, but not mandatory\", payload=Severity.Info.class)\n" - " private String phoneNumber;\n" - "\n" - " // ...\n" - "}" -msgstr "" - -#. Tag: para -#: customconstraints.xml:113 -#, no-c-format -msgid "Now a client can after the validation of a ContactDetails instance access the severity of a constraint using ConstraintViolation.getConstraintDescriptor().getPayload() and adjust its behaviour depending on the severity." -msgstr "" - -#. Tag: para -#: customconstraints.xml:122 -#, no-c-format -msgid "Besides those three mandatory attributes (message, groups and payload) we add another one allowing for the required case mode to be specified. The name value is a special one, which can be omitted upon using the annotation, if it is the only attribute specified, as e.g. in @CheckCase(CaseMode.UPPER)." -msgstr "" - -#. Tag: para -#: customconstraints.xml:130 -#, no-c-format -msgid "In addition we annotate the annotation type with a couple of so-called meta annotations:" -msgstr "" - -#. Tag: para -#: customconstraints.xml:135 -#, no-c-format -msgid "@Target({ METHOD, FIELD, ANNOTATION_TYPE }): Says, that methods, fields and annotation declarations may be annotated with @CheckCase (but not type declarations e.g.)" -msgstr "" - -#. Tag: para -#: customconstraints.xml:141 -#, no-c-format -msgid "@Retention(RUNTIME): Specifies, that annotations of this type will be available at runtime by the means of reflection" -msgstr "" - -#. Tag: para -#: customconstraints.xml:147 -#, no-c-format -msgid "@Constraint(validatedBy = CheckCaseValidator.class): Specifies the validator to be used to validate elements annotated with @CheckCase" -msgstr "" - -#. Tag: para -#: customconstraints.xml:153 -#, no-c-format -msgid "@Documented: Says, that the use of @CheckCase will be contained in the JavaDoc of elements annotated with it" -msgstr "" - -#. Tag: para -#: customconstraints.xml:160 -#, no-c-format -msgid "Hibernate Validator provides support for the validation of method parameters using constraint annotations (see )." -msgstr "" - -#. Tag: para -#: customconstraints.xml:164 -#, no-c-format -msgid "In order to use a custom constraint for parameter validation the ElementType.PARAMETER must be specified within the @Target annotation. This is already the case for all constraints defined by the Bean Validation API and also the custom constraints provided by Hibernate Validator." -msgstr "" - -#. Tag: title -#: customconstraints.xml:173 -#, no-c-format -msgid "The constraint validator" -msgstr "" - -#. Tag: para -#: customconstraints.xml:176 -#, no-c-format -msgid "Next, we need to implement a constraint validator, that's able to validate elements with a @CheckCase annotation. To do so, we implement the interface ConstraintValidator as shown below:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:182 -#, no-c-format -msgid "Implementing a constraint validator for the constraint CheckCase" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:185 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.ConstraintValidator;\n" - "import javax.validation.ConstraintValidatorContext;\n" - "\n" - "public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> {\n" - "\n" - " private CaseMode caseMode;\n" - "\n" - " public void initialize(CheckCase constraintAnnotation) {\n" - " this.caseMode = constraintAnnotation.value();\n" - " }\n" - "\n" - " public boolean isValid(String object, ConstraintValidatorContext constraintContext) {\n" - "\n" - " if (object == null)\n" - " return true;\n" - "\n" - " if (caseMode == CaseMode.UPPER)\n" - " return object.equals(object.toUpperCase());\n" - " else\n" - " return object.equals(object.toLowerCase());\n" - " }\n" - "\n" - "}" -msgstr "" - -#. Tag: para -#: customconstraints.xml:188 -#, no-c-format -msgid "The ConstraintValidator interface defines two type parameters, which we set in our implementation. The first one specifies the annotation type to be validated (in our example CheckCase), the second one the type of elements, which the validator can handle (here String)." -msgstr "" - -#. Tag: para -#: customconstraints.xml:195 -#, no-c-format -msgid "In case a constraint annotation is allowed at elements of different types, a ConstraintValidator for each allowed type has to be implemented and registered at the constraint annotation as shown above." -msgstr "" - -#. Tag: para -#: customconstraints.xml:200 -#, no-c-format -msgid "The implementation of the validator is straightforward. The initialize() method gives us access to the attribute values of the annotation to be validated. In the example we store the CaseMode in a field of the validator for further usage." -msgstr "" - -#. Tag: para -#: customconstraints.xml:206 -#, no-c-format -msgid "In the isValid() method we implement the logic, that determines, whether a String is valid according to a given @CheckCase annotation or not. This decision depends on the case mode retrieved in initialize(). As the Bean Validation specification recommends, we consider null values as being valid. If null is not a valid value for an element, it should be annotated with @NotNull explicitly." -msgstr "" - -#. Tag: title -#: customconstraints.xml:216 -#, no-c-format -msgid "The ConstraintValidatorContext" -msgstr "" - -#. Tag: para -#: customconstraints.xml:218 -#, no-c-format -msgid "relies on the default error message generation by just returning true or false from the isValid call. Using the passed ConstraintValidatorContext object it is possible to either add additional error messages or completely disable the default error message generation and solely define custom error messages. The ConstraintValidatorContext API is modeled as fluent interface and is best demonstrated with an example:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:230 -#, no-c-format -msgid "Use of ConstraintValidatorContext to define custom error messages" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:233 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.ConstraintValidator;\n" - "import javax.validation.ConstraintValidatorContext;\n" - "\n" - "public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> {\n" - "\n" - " private CaseMode caseMode;\n" - "\n" - " public void initialize(CheckCase constraintAnnotation) {\n" - " this.caseMode = constraintAnnotation.value();\n" - " }\n" - "\n" - " public boolean isValid(String object, ConstraintValidatorContext constraintContext) {\n" - "\n" - " if (object == null)\n" - " return true;\n" - " \n" - " boolean isValid;\n" - " if (caseMode == CaseMode.UPPER) {\n" - " isValid = object.equals(object.toUpperCase());\n" - " }\n" - " else {\n" - " isValid = object.equals(object.toLowerCase());\n" - " }\n" - " \n" - " if(!isValid) {\n" - " constraintContext.disableDefaultConstraintViolation();\n" - " constraintContext.buildConstraintViolationWithTemplate( \"{com.mycompany.constraints.CheckCase.message}\" ).addConstraintViolation();\n" - " }\n" - " return result;\n" - " }\n" - "\n" - "}" -msgstr "" - -#. Tag: para -#: customconstraints.xml:236 -#, no-c-format -msgid "shows how you can disable the default error message generation and add a custom error message using a specified message template. In this example the use of the ConstraintValidatorContext results in the same error message as the default error message generation." -msgstr "" - -#. Tag: para -#: customconstraints.xml:242 -#, no-c-format -msgid "It is important to end each new constraint violation with addConstraintViolation. Only after that the new constraint violation will be created." -msgstr "" - -#. Tag: para -#: customconstraints.xml:247 -#, no-c-format -msgid "In case you are implementing a ConstraintValidator a class level constraint it is also possible to adjust set the property path for the created constraint violations. This is important for the case where you validate multiple properties of the class or even traverse the object graph. A custom property path creation could look like ." -msgstr "" - -#. Tag: title -#: customconstraints.xml:256 -#, no-c-format -msgid "Adding new ConstraintViolation with custom property path" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:259 -#, no-c-format -msgid "" - "public boolean isValid(Group group, ConstraintValidatorContext constraintValidatorContext) {\n" - " boolean isValid = false;\n" - " ...\n" - "\n" - " if(!isValid) {\n" - " constraintValidatorContext\n" - " .buildConstraintViolationWithTemplate( \"{my.custom.template}\" )\n" - " .addNode( \"myProperty\" ).addConstraintViolation();\n" - " }\n" - " return isValid;\n" - "}" -msgstr "" - -#. Tag: title -#: customconstraints.xml:265 -#, no-c-format -msgid "The error message" -msgstr "" - -#. Tag: para -#: customconstraints.xml:267 -#, no-c-format -msgid "Finally we need to specify the error message, that shall be used, in case a @CheckCase constraint is violated. To do so, we add the following to our custom ValidationMessages.properties (see also )" -msgstr "" - -#. Tag: title -#: customconstraints.xml:274 -#, no-c-format -msgid "Defining a custom error message for the CheckCase constraint" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:277 -#, no-c-format -msgid "com.mycompany.constraints.CheckCase.message=Case mode must be {value}." -msgstr "" - -#. Tag: para -#: customconstraints.xml:280 -#, no-c-format -msgid "If a validation error occurs, the validation runtime will use the default value, that we specified for the message attribute of the @CheckCase annotation to look up the error message in this file." -msgstr "" - -#. Tag: title -#: customconstraints.xml:287 -#, no-c-format -msgid "Using the constraint" -msgstr "" - -#. Tag: para -#: customconstraints.xml:289 -#, no-c-format -msgid "Now that our first custom constraint is completed, we can use it in the Car class from the chapter to specify that the licensePlate field shall only contain upper-case strings:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:296 -#, no-c-format -msgid "Applying the CheckCase constraint" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:299 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.constraints.Min;\n" - "import javax.validation.constraints.NotNull;\n" - "import javax.validation.constraints.Size;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @NotNull\n" - " @Size(min = 2, max = 14)\n" - " @CheckCase(CaseMode.UPPER)\n" - " private String licensePlate;\n" - "\n" - " @Min(2)\n" - " private int seatCount;\n" - " \n" - " public Car(String manufacturer, String licencePlate, int seatCount) {\n" - "\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licencePlate;\n" - " this.seatCount = seatCount;\n" - " }\n" - "\n" - " //getters and setters ...\n" - "\n" - "}" -msgstr "" - -#. Tag: para -#: customconstraints.xml:302 -#, no-c-format -msgid "Finally let's demonstrate in a little test that the @CheckCase constraint is properly validated:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:307 -#, no-c-format -msgid "Testcase demonstrating the CheckCase validation" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:310 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import static org.junit.Assert.*;\n" - "\n" - "import java.util.Set;\n" - "\n" - "import javax.validation.ConstraintViolation;\n" - "import javax.validation.Validation;\n" - "import javax.validation.Validator;\n" - "import javax.validation.ValidatorFactory;\n" - "\n" - "import org.junit.BeforeClass;\n" - "import org.junit.Test;\n" - "\n" - "public class CarTest {\n" - "\n" - " private static Validator validator;\n" - "\n" - " @BeforeClass\n" - " public static void setUp() {\n" - " ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - " validator = factory.getValidator();\n" - " }\n" - "\n" - " @Test\n" - " public void testLicensePlateNotUpperCase() {\n" - "\n" - " Car car = new Car(\"Morris\", \"dd-ab-123\", 4);\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate(car);\n" - " assertEquals(1, constraintViolations.size());\n" - " assertEquals(\n" - " \"Case mode must be UPPER.\", \n" - " constraintViolations.iterator().next().getMessage());\n" - " }\n" - "\n" - " @Test\n" - " public void carIsValid() {\n" - "\n" - " Car car = new Car(\"Morris\", \"DD-AB-123\", 4);\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate(car);\n" - "\n" - " assertEquals(0, constraintViolations.size());\n" - " }\n" - "}" -msgstr "" - -#. Tag: title -#: customconstraints.xml:316 -#, no-c-format -msgid "Constraint composition" -msgstr "" - -#. Tag: para -#: customconstraints.xml:318 -#, no-c-format -msgid "Looking at the licensePlate field of the Car class in , we see three constraint annotations already. In complexer scenarios, where even more constraints could be applied to one element, this might become a bit confusing easily. Furthermore, if we had a licensePlate field in another class, we would have to copy all constraint declarations to the other class as well, violating the DRY principle." -msgstr "" - -#. Tag: para -#: customconstraints.xml:327 -#, no-c-format -msgid "This problem can be tackled using compound constraints. In the following we create a new constraint annotation @ValidLicensePlate, that comprises the constraints @NotNull, @Size and @CheckCase:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:334 -#, no-c-format -msgid "Creating a composing constraint ValidLicensePlate" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:337 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import static java.lang.annotation.ElementType.*;\n" - "import static java.lang.annotation.RetentionPolicy.*;\n" - "\n" - "import java.lang.annotation.Documented;\n" - "import java.lang.annotation.Retention;\n" - "import java.lang.annotation.Target;\n" - "\n" - "import javax.validation.Constraint;\n" - "import javax.validation.Payload;\n" - "import javax.validation.constraints.NotNull;\n" - "import javax.validation.constraints.Size;\n" - "\n" - "@NotNull\n" - "@Size(min = 2, max = 14)\n" - "@CheckCase(CaseMode.UPPER)\n" - "@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n" - "@Retention(RUNTIME)\n" - "@Constraint(validatedBy = {})\n" - "@Documented\n" - "public @interface ValidLicensePlate {\n" - "\n" - " String message() default \"{com.mycompany.constraints.validlicenseplate}\";\n" - "\n" - " Class<?>[] groups() default {};\n" - "\n" - " Class<? extends Payload>[] payload() default {};\n" - "\n" - "}" -msgstr "" - -#. Tag: para -#: customconstraints.xml:340 -#, no-c-format -msgid "To do so, we just have to annotate the constraint declaration with its comprising constraints (btw. that's exactly why we allowed annotation types as target for the @CheckCase annotation). As no additional validation is required for the @ValidLicensePlate annotation itself, we don't declare a validator within the @Constraint meta annotation." -msgstr "" - -#. Tag: para -#: customconstraints.xml:348 -#, no-c-format -msgid "Using the new compound constraint at the licensePlate field now is fully equivalent to the previous version, where we declared the three constraints directly at the field itself:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:354 -#, no-c-format -msgid "Application of composing constraint ValidLicensePlate" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:357 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "public class Car {\n" - "\n" - " @ValidLicensePlate\n" - " private String licensePlate;\n" - "\n" - " //...\n" - "\n" - "}" -msgstr "" - -#. Tag: para -#: customconstraints.xml:360 -#, no-c-format -msgid "The set of ConstraintViolations retrieved when validating a Car instance will contain an entry for each violated composing constraint of the @ValidLicensePlate constraint. If you rather prefer a single ConstraintViolation in case any of the composing constraints is violated, the @ReportAsSingleViolation meta constraint can be used as follows:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:370 -#, no-c-format -msgid "Usage of @ReportAsSingleViolation" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:372 -#, no-c-format -msgid "" - "//...\n" - "@ReportAsSingleViolation\n" - "public @interface ValidLicensePlate {\n" - "\n" - " String message() default \"{com.mycompany.constraints.validlicenseplate}\";\n" - "\n" - " Class<?>[] groups() default {};\n" - "\n" - " Class<? extends Payload>[] payload() default {};\n" - "\n" - "}" -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/customoptions.pot b/documentation/src/main/docbook/pot/modules/customoptions.pot deleted file mode 100644 index a4318f9636..0000000000 --- a/documentation/src/main/docbook/pot/modules/customoptions.pot +++ /dev/null @@ -1,841 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2012-05-09 09:42+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: customoptions.xml:24 -#, no-c-format -msgid "Hibernate Validator Specifics" -msgstr "" - -#. Tag: para -#: customoptions.xml:26 -#, no-c-format -msgid "In the following sections we are having a closer look at some of the Hibernate Validator specific features (features which are not part of the Bean Validation specification). This includes the fail fast mode, the programmatic constraint configuration API and boolean composition of composing constraints." -msgstr "" - -#. Tag: para -#: customoptions.xml:33 -#, no-c-format -msgid "The features described in the following sections are not portable between Bean Validation providers/implementations." -msgstr "" - -#. Tag: title -#: customoptions.xml:38 -#, no-c-format -msgid "Public API" -msgstr "" - -#. Tag: para -#: customoptions.xml:40 -#, no-c-format -msgid "Let's start, however, with a look at the public API of Hibernate Validator. lists all packages belonging to this API and describes their purpose." -msgstr "" - -#. Tag: para -#: customoptions.xml:44 -#, no-c-format -msgid "Any packages not listed in that table are internal packages of Hibernate Validator and are not intended to be accessed by clients. The contents of these internal packages can change from release to release without notice, thus possibly breaking any client code relying on it." -msgstr "" - -#. Tag: para -#: customoptions.xml:51 -#, no-c-format -msgid "In the following table, when a package is public its not necessarily true for its nested packages." -msgstr "" - -#. Tag: title -#: customoptions.xml:56 -#, no-c-format -msgid "Hibernate Validator public API" -msgstr "" - -#. Tag: entry -#: customoptions.xml:61 -#, no-c-format -msgid "Packages" -msgstr "" - -#. Tag: entry -#: customoptions.xml:63 -#, no-c-format -msgid "Description" -msgstr "" - -#. Tag: package -#: customoptions.xml:69 -#, no-c-format -msgid "org.hibernate.validator" -msgstr "" - -#. Tag: entry -#: customoptions.xml:71 -#, no-c-format -msgid "This package contains the classes used by the Bean Validation bootstrap mechanism (eg. validation provider, configuration class). For more details see ." -msgstr "" - -#. Tag: entry -#: customoptions.xml:78 -#, no-c-format -msgid "org.hibernate.validator.cfg, org.hibernate.validator.cfg.context, org.hibernate.validator.cfg.defs" -msgstr "" - -#. Tag: entry -#: customoptions.xml:82 -#, no-c-format -msgid "With Hibernate Validator you can define constraints via a fluent API. These packages contain all classes needed to use this feature. In the package org.hibernate.validator.cfg you will find the ConstraintMapping class and in package org.hibernate.validator.cfg.defs all constraint definitions. For more details see ." -msgstr "" - -#. Tag: entry -#: customoptions.xml:93 -#, no-c-format -msgid "org.hibernate.validator.constraints, org.hibernate.validator.constraints.br" -msgstr "" - -#. Tag: entry -#: customoptions.xml:96 -#, no-c-format -msgid "In addition to Bean Validation constraints, Hibernate Validator provides some useful custom constraints. These packages contain all custom annotation classes. For more details see ." -msgstr "" - -#. Tag: entry -#: customoptions.xml:103 -#, no-c-format -msgid "org.hibernate.validator.group, org.hibernate.validator.spi.group" -msgstr "" - -#. Tag: entry -#: customoptions.xml:106 -#, no-c-format -msgid "With Hibernate Validator you can define dynamic default group sequences in function of the validated object state. These packages contain all classes needed to use this feature (GroupSequenceProvider annotation and DefaultGroupSequenceProvider contract). For more details see ." -msgstr "" - -#. Tag: entry -#: customoptions.xml:116 -#, no-c-format -msgid "org.hibernate.validator.messageinterpolation, org.hibernate.validator.resourceloading, org.hibernate.validator.spi.resourceloading" -msgstr "" - -#. Tag: entry -#: customoptions.xml:120 -#, no-c-format -msgid "These packages contain the classes related to constraint message interpolation. The first package contains two implementations of MessageInterpolator. The first one, ValueFormatterMessageInterpolator allows to interpolate the validated value into the constraint message, see . The second implementation named ResourceBundleMessageInterpolator is the implementation used by default by Hibernate Validator. This implementation relies on a ResourceBundleLocator, see . Hibernate Validator provides different ResourceBundleLocator implementations located in the package org.hibernate.validator.resourceloading." -msgstr "" - -#. Tag: entry -#: customoptions.xml:139 -#, no-c-format -msgid "org.hibernate.validator.method, org.hibernate.validator.method.metadata" -msgstr "" - -#. Tag: entry -#: customoptions.xml:142 -#, no-c-format -msgid "Hibernate Validator provides support for method-level constraints based on appendix C of the Bean Validation specification. The first package contains the MethodValidator interface allowing you to validate method return values and parameters. The second package contains meta data for constraints hosted on parameters and methods which can be retrieved via the MethodValidator." -msgstr "" - -#. Tag: para -#: customoptions.xml:156 -#, no-c-format -msgid "The public packages of Hibernate Validator fall into two categories: while the actual API parts are intended to be invoked or used by clients (e.g. the API for programmatic constraint declaration or the custom constraints), the SPI (service provider interface) packages contain interfaces which are intended to be implemented by clients (e.g. ResourceBundleLocator)." -msgstr "" - -#. Tag: title -#: customoptions.xml:167 -#, no-c-format -msgid "Fail fast mode" -msgstr "" - -#. Tag: para -#: customoptions.xml:169 -#, no-c-format -msgid "First off, the fail fast mode. Hibernate Validator allows to return from the current validation as soon as the first constraint violation occurs. This is called the fail fast mode and can be useful for validation of large object graphs where one is only interested whether there is a constraint violation or not. , and show multiple ways to enable the fail fast mode." -msgstr "" - -#. Tag: title -#: customoptions.xml:180 -#, no-c-format -msgid "Enabling via a property" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:182 -#, no-c-format -msgid "" - "HibernateValidatorConfiguration configuration = Validation.byProvider( HibernateValidator.class ).configure();\n" - "ValidatorFactory factory = configuration.addProperty( \"hibernate.validator.fail_fast\", \"true\" ).buildValidatorFactory();\n" - "Validator validator = factory.getValidator();\n" - "\n" - "// do some actual fail fast validation\n" - "..." -msgstr "" - -#. Tag: title -#: customoptions.xml:186 -#, no-c-format -msgid "Enabling at the Configuration level" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:189 -#, no-c-format -msgid "" - "HibernateValidatorConfiguration configuration = Validation.byProvider( HibernateValidator.class ).configure();\n" - "ValidatorFactory factory = configuration.failFast( true ).buildValidatorFactory();\n" - "Validator validator = factory.getValidator();\n" - "\n" - "// do some actual fail fast validation\n" - "..." -msgstr "" - -#. Tag: title -#: customoptions.xml:193 -#, no-c-format -msgid "Enabling at the ValidatorFactory level" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:196 -#, no-c-format -msgid "" - "HibernateValidatorConfiguration configuration = Validation.byProvider( HibernateValidator.class ).configure();\n" - "ValidatorFactory factory = configuration.buildValidatorFactory();\n" - "\n" - "Validator validator = factory.getValidator();\n" - "\n" - "// do some non fail fast validation\n" - "...\n" - "\n" - "validator = factory.unwrap( HibernateValidatorFactory.class )\n" - " .usingContext()\n" - " .failFast( true )\n" - " .getValidator();\n" - "\n" - "// do fail fast validation\n" - "..." -msgstr "" - -#. Tag: title -#: customoptions.xml:201 -#, no-c-format -msgid "Method validation" -msgstr "" - -#. Tag: para -#: customoptions.xml:203 -#, no-c-format -msgid "The Bean Validation API allows to specify constraints for fields, properties and types. Hibernate Validator goes one step further and allows to place contraint annotations also on method parameters and method return values, thus enabling a programming style known as \"Programming by Contract\"." -msgstr "" - -#. Tag: para -#: customoptions.xml:209 -#, no-c-format -msgid "More specifically this means that Bean Validation constraints can be used to specify" -msgstr "" - -#. Tag: para -#: customoptions.xml:214 -#, no-c-format -msgid "the preconditions that must be met before a method invocation (by annotating method parameters with constraints) and" -msgstr "" - -#. Tag: para -#: customoptions.xml:219 -#, no-c-format -msgid "the postconditions that are guaranteed after a method invocation (by annotating methods)" -msgstr "" - -#. Tag: para -#: customoptions.xml:224 -#, no-c-format -msgid "This approach has several advantages over traditional ways of parameter and return value checking:" -msgstr "" - -#. Tag: para -#: customoptions.xml:229 -#, no-c-format -msgid "The checks don't have to be performed manually (e.g. by throwing IllegalArgumentExceptions or similar), resulting in less code to write and maintain." -msgstr "" - -#. Tag: para -#: customoptions.xml:235 -#, no-c-format -msgid "A method's pre- and postconditions don't have to be expressed again in the method's JavaDoc, since the constraint annotations will automatically be included in the generated JavaDoc. This avoids redundancy and reduces the chance of inconsistencies between implementation and documentation." -msgstr "" - -#. Tag: para -#: customoptions.xml:244 -#, no-c-format -msgid "Method validation was also considered to be included in the Bean Validation API as defined by JSR 303, but it didn't become part of the 1.0 version. A basic draft is outlined in appendix C of the specification, and the implementation in Hibernate Validator is largely influenced by this draft. The feature is considered again for inclusion in BV 1.1." -msgstr "" - -#. Tag: title -#: customoptions.xml:253 -#, no-c-format -msgid "Defining method-level constraints" -msgstr "" - -#. Tag: para -#: customoptions.xml:255 -#, no-c-format -msgid "demonstrates the definition of method-level constraints." -msgstr "" - -#. Tag: title -#: customoptions.xml:258 -#, no-c-format -msgid "Using method-level constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:260 -#, no-c-format -msgid "" - "public class RentalStation {\n" - "\n" - " @NotNull \n" - " public Car rentCar(@NotNull Customer customer, @NotNull @Future Date startDate, @Min(1) int durationInDays) { \n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: customoptions.xml:263 -#, no-c-format -msgid "Here the following pre- and postconditions for the rentCar() method are declared:" -msgstr "" - -#. Tag: para -#: customoptions.xml:268 -#, no-c-format -msgid "The renting customer may not be null" -msgstr "" - -#. Tag: para -#: customoptions.xml:272 -#, no-c-format -msgid "The rental's start date must not be null and must be in the future" -msgstr "" - -#. Tag: para -#: customoptions.xml:277 -#, no-c-format -msgid "The rental duration must be at least one day" -msgstr "" - -#. Tag: para -#: customoptions.xml:281 -#, no-c-format -msgid "The returned Car instance may not be null" -msgstr "" - -#. Tag: para -#: customoptions.xml:286 -#, no-c-format -msgid "Using the @Valid annotation it's also possible to define that a cascaded validation of parameter or return value objects shall be performed. An example can be found in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:292 -#, no-c-format -msgid "Cascaded validation of method-level constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:294 -#, no-c-format -msgid "" - "public class RentalStation {\n" - "\n" - " @Valid\n" - " public Set<Rental> getRentalsByCustomer(@Valid Customer customer) { \n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: customoptions.xml:297 -#, no-c-format -msgid "Here all the constraints declared at the Customer type will be evaluated when validating the method parameter and all constraints declared at the returned Rental objects will be evaluated when validating the method's return value." -msgstr "" - -#. Tag: title -#: customoptions.xml:304 -#, no-c-format -msgid "Using method constraints in type hierarchies" -msgstr "" - -#. Tag: para -#: customoptions.xml:306 -#, no-c-format -msgid "Special care must be taken when defining parameter constraints in inheritance hierarchies." -msgstr "" - -#. Tag: para -#: customoptions.xml:309 -#, no-c-format -msgid "When a method is overridden in sub-types method parameter constraints can only be declared at the base type. The reason for this restriction is that the preconditions to be fulfilled by a type's client must not be strengthened in sub-types (which may not even be known to the base type's client). Note that also if the base method doesn't declare any parameter constraints at all, no parameter constraints may be added in overriding methods." -msgstr "" - -#. Tag: para -#: customoptions.xml:317 -#, no-c-format -msgid "The same restriction applies to interface methods: no parameter constraints may be defined at the implementing method (or the same method declared in sub-interfaces)." -msgstr "" - -#. Tag: para -#: customoptions.xml:321 -#, no-c-format -msgid "If a violation of this rule is detected by the validation engine, a javax.validation.ConstraintDeclarationException will be thrown. In some examples for illegal parameter constraints declarations are shown." -msgstr "" - -#. Tag: title -#: customoptions.xml:329 -#, no-c-format -msgid "Illegal parameter constraint declarations" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:331 -#, no-c-format -msgid "" - "public class Car {\n" - "\n" - " public void drive(Person driver) { ... }\n" - "\n" - "}\n" - "\n" - "public class RentalCar extends Car {\n" - "\n" - " //not allowed, parameter constraint added in overriding method\n" - " public void drive(@NotNull Person driver) { ... }\n" - "\n" - "}\n" - "\n" - "public interface ICar {\n" - "\n" - " void drive(Person driver);\n" - "\n" - "}\n" - "\n" - "public class CarImpl implements ICar {\n" - "\n" - " //not allowed, parameter constraint added in implementation of interface method\n" - " public void drive(@NotNull Person driver) { ... }\n" - "\n" - "}" -msgstr "" - -#. Tag: para -#: customoptions.xml:334 -#, no-c-format -msgid "This rule only applies to parameter constraints, return value constraints may be added in sub-types without any restrictions as it is alright to strengthen the postconditions guaranteed to a type's client." -msgstr "" - -#. Tag: title -#: customoptions.xml:342 -#, no-c-format -msgid "Evaluating method-level constraints" -msgstr "" - -#. Tag: para -#: customoptions.xml:344 -#, no-c-format -msgid "To validate method-level constraints Hibernate Validator provides the interface org.hibernate.validator.method.MethodValidator." -msgstr "" - -#. Tag: para -#: customoptions.xml:348 -#, no-c-format -msgid "As shown in this interface defines methods for the evaluation of parameter as well as return value constraints and for retrieving an extended type descriptor providing method constraint related meta data." -msgstr "" - -#. Tag: title -#: customoptions.xml:354 -#, no-c-format -msgid "The MethodValidator interface" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:356 -#, no-c-format -msgid "" - "public interface MethodValidator {\n" - "\n" - " <T> Set<MethodConstraintViolation<T>> validateParameter(T object, Method method, Object parameterValue, int parameterIndex, Class<?>... groups);\n" - " \n" - " <T> Set<MethodConstraintViolation<T>> validateAllParameters(T object, Method method, Object[] parameterValues, Class<?>... groups);\n" - " \n" - " <T> Set<MethodConstraintViolation<T>> validateReturnValue(T object, Method method, Object returnValue, Class<?>... groups);\n" - " \n" - " TypeDescriptor getConstraintsForType(Class<?> clazz);\n" - "}" -msgstr "" - -#. Tag: para -#: customoptions.xml:359 -#, no-c-format -msgid "To retrieve a method validator get hold of an instance of HV's javax.validation.Validator implementation and unwrap it to MethodValidator as shown in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:365 -#, no-c-format -msgid "Retrieving a MethodValidator instance" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:368 -#, no-c-format -msgid "" - "MethodValidator methodValidator = Validation.byProvider( HibernateValidator.class )\n" - " .configure()\n" - " .buildValidatorFactory()\n" - " .getValidator()\n" - " .unwrap( MethodValidator.class );" -msgstr "" - -#. Tag: para -#: customoptions.xml:371 -#, no-c-format -msgid "The validation methods defined on MethodValidator each return a Set<MethodConstraintViolation>. The type MethodConstraintViolation (see ) extends javax.validation.ConstraintViolation and provides additional method level validation specific information such as the method and index of the parameter which caused the constraint violation." -msgstr "" - -#. Tag: title -#: customoptions.xml:382 -#, no-c-format -msgid "The MethodConstraintViolation type" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:385 -#, no-c-format -msgid "" - "public interface MethodConstraintViolation<T> extends ConstraintViolation<T> {\n" - " \n" - " public static enum Kind { PARAMETER, RETURN_VALUE }\n" - "\n" - " Method getMethod();\n" - "\n" - " Integer getParameterIndex();\n" - "\n" - " String getParameterName();\n" - "\n" - " Kind getKind();\n" - "}" -msgstr "" - -#. Tag: para -#: customoptions.xml:389 -#, no-c-format -msgid "The method getParameterName() currently returns synthetic parameter identifiers such as \"arg0\", \"arg1\" etc. In a future version of Hibernate Validator support for specifying parameter identifiers might be added." -msgstr "" - -#. Tag: para -#: customoptions.xml:395 -#, no-c-format -msgid "Typically the validation of method-level constraints is not invoked manually but automatically upon method invocation by an integration layer using AOP (aspect-oriented programming) or similar method interception facilities such as the JDK's java.lang.reflect.Proxy API or CDI (\"JSR 299: Contexts and Dependency Injection for the JavaTM EE platform\")." -msgstr "" - -#. Tag: para -#: customoptions.xml:403 -#, no-c-format -msgid "If a parameter or return value constraint can't be validated sucessfully such an integration layer typically will throw a MethodConstraintViolationException which similar to javax.validation.ConstraintViolationException contains a set with the occurred constraint violations." -msgstr "" - -#. Tag: para -#: customoptions.xml:410 -#, no-c-format -msgid "If you are using CDI you might be interested in the Seam Validation project. This Seam module provides an interceptor which integrates the method validation functionality with CDI." -msgstr "" - -#. Tag: title -#: customoptions.xml:418 -#, no-c-format -msgid "Retrieving method-level constraint meta data" -msgstr "" - -#. Tag: para -#: customoptions.xml:420 -#, no-c-format -msgid "As outlined in the Bean Validation API provides rich capabilities for retrieving constraint related meta data. Hibernate Validator extends this API and allows to retrieve constraint meta data also for method-level constraints." -msgstr "" - -#. Tag: para -#: customoptions.xml:426 -#, no-c-format -msgid "shows how to use this extended API to retrieve constraint meta data for the rentCar() method from the RentalStation type." -msgstr "" - -#. Tag: title -#: customoptions.xml:432 -#, no-c-format -msgid "Retrieving meta data for method-level constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:434 -#, no-c-format -msgid "" - "TypeDescriptor typeDescriptor = methodValidator.getConstraintsForType(RentalStation.class)\n" - "\n" - "//retrieve a descriptor for the rentCar() method\n" - "MethodDescriptor rentCarMethod = typeDescriptor.getConstraintsForMethod(\"rentCar\", Customer.class, Date.class, int.class);\n" - "assertEquals(rentCarMethod.getMethodName(), \"rentCar\");\n" - "assertTrue(rentCarMethod.hasConstraints());\n" - "assertFalse(rentCarMethod.isCascaded());\n" - "\n" - "//retrieve constraints from the return value\n" - "Set<ConstraintDescriptor<?>> returnValueConstraints = rentCarMethod.findConstraints().getConstraintDescriptors();\n" - "assertEquals(returnValueConstraints.size(), 1);\n" - "assertEquals(returnValueConstraints.iterator().next().getAnnotation().annotationType(), NotNull.class);\n" - "\n" - "List<ParameterDescriptor> allParameters = rentCarMethod.getParameterDescriptors();\n" - "assertEquals(allParameters.size(), 3);\n" - "\n" - "//retrieve a descriptor for the startDate parameter\n" - "ParameterDescriptor startDateParameter = allParameters.get(1);\n" - "assertEquals(startDateParameter.getIndex(), 1);\n" - "assertFalse(startDateParameter.isCascaded());\n" - "assertEquals(startDateParameter.findConstraints().getConstraintDescriptors().size(), 2);" -msgstr "" - -#. Tag: para -#: customoptions.xml:437 -#, no-c-format -msgid "Refer to the JavaDoc of the package org.hibernate.validator.method.metadata for more details on the extended meta data API." -msgstr "" - -#. Tag: title -#: customoptions.xml:446 customoptions.xml:462 -#, no-c-format -msgid "Programmatic constraint definition" -msgstr "" - -#. Tag: para -#: customoptions.xml:448 -#, no-c-format -msgid "Another addition to the Bean Validation specification is the ability to configure constraints via a fluent API. This API can be used exclusively or in combination with annotations and xml. If used in combination programmatic constraints are additive to constraints configured via the standard configuration capabilities." -msgstr "" - -#. Tag: para -#: customoptions.xml:454 -#, no-c-format -msgid "The API is centered around the ConstraintMapping class which can be found in the package org.hibernate.validator.cfg. Starting with the instantiation of a new ConstraintMapping, constraints can be defined in a fluent manner as shown in ." -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:464 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "mapping.type( Car.class )\n" - " .property( \"manufacturer\", FIELD )\n" - " .constraint( new NotNullDef() )\n" - " .property( \"licensePlate\", FIELD )\n" - " .constraint( new NotNullDef() )\n" - " .constraint( new SizeDef().min( 2 ).max( 14 ) )\n" - " .property( \"seatCount\", FIELD )\n" - " .constraint( new MinDef()value ( 2 ) )\n" - ".type( RentalCar.class )\n" - " .property( \"rentalStation\", METHOD )\n" - " .constraint( new NotNullDef() );" -msgstr "" - -#. Tag: para -#: customoptions.xml:467 -#, no-c-format -msgid "As you can see constraints can be configured on multiple classes and properties using method chaining. The constraint definition classes NotNullDef, SizeDef and MinDef are helper classes which allow to configure constraint parameters in a type-safe fashion. Definition classes exist for all built-in constraints in the org.hibernate.validator.cfg.defs package." -msgstr "" - -#. Tag: para -#: customoptions.xml:475 -#, no-c-format -msgid "For custom constraints you can either create your own definition classes extending ConstraintDef or you can use GenericConstraintDef as seen in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:481 -#, no-c-format -msgid "Programmatic constraint definition using createGeneric()" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:484 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "mapping.type( Car.class )\n" - " .property( \"licensePlate\", FIELD )\n" - " .constraint( new GenericConstraintDef<CheckCase.class>( CheckCase.class ).param( \"value\", CaseMode.UPPER ) );" -msgstr "" - -#. Tag: para -#: customoptions.xml:487 -#, no-c-format -msgid "Not only standard class- and property-level constraints but also method constraints can be configured using the API. As shown in methods are identified by their name and their parameters (if there are any). Having selected a method, constraints can be placed on the method's parameters and/or return value." -msgstr "" - -#. Tag: title -#: customoptions.xml:495 -#, no-c-format -msgid "Programmatic definition of method constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:497 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "mapping.type( Car.class )\n" - " .method( \"drive\", String.class, Integer.class )\n" - " .parameter( 0 )\n" - " .constraint( new NotNullDef() )\n" - " .constraint( new MinDef().value ( 1 ) )\n" - " .parameter( 1 )\n" - " .constraint( new NotNullDef() )\n" - " .returnValue()\n" - " .constraint( new NotNullDef() )\n" - " .method( \"check\" )\n" - " .returnValue()\n" - " .constraint( new NotNullDef() );" -msgstr "" - -#. Tag: para -#: customoptions.xml:500 -#, no-c-format -msgid "Using the API it's also possible to mark properties, method parameters and method return values as cascading (equivalent to annotating them with @Valid). An example can be found in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:506 -#, no-c-format -msgid "Marking constraints for cascaded validation" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:508 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "mapping.type( Car.class )\n" - " .property( \"manufacturer\", FIELD )\n" - " .valid()\n" - " .property( \"licensePlate\", METHOD )\n" - " .valid()\n" - " .method( \"drive\", String.class, Integer.class )\n" - " .parameter( 0 )\n" - " .valid()\n" - " .parameter( 1 )\n" - " .valid()\n" - " .returnValue()\n" - " .valid()\n" - ".type( RentalCar.class )\n" - " .property( \"rentalStation\", METHOD )\n" - " .valid();" -msgstr "" - -#. Tag: para -#: customoptions.xml:511 -#, no-c-format -msgid "Last but not least you can configure the default group sequence or the default group sequence provider of a type as shown in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:514 -#, no-c-format -msgid "Configuration of default group sequence and default group sequence provider" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:517 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "mapping.type( Car.class )\n" - " .defaultGroupSequence( Car.class, CarChecks.class )\n" - ".type( RentalCar.class )\n" - " .defaultGroupSequenceProvider( RentalCarGroupSequenceProvider.class );" -msgstr "" - -#. Tag: para -#: customoptions.xml:520 -#, no-c-format -msgid "Once a ConstraintMapping is set up it has to be passed to the configuration. Since the programmatic API is not part of the official Bean Validation specification you need to get hold of a HibernateValidatorConfiguration instance as shown in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:527 -#, no-c-format -msgid "Creating a Hibernate Validator specific configuration" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:529 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "// configure mapping instance\n" - "\n" - "HibernateValidatorConfiguration config = Validation.byProvider( HibernateValidator.class ).configure();\n" - "config.addMapping( mapping );\n" - "ValidatorFactory factory = config.buildValidatorFactory();\n" - "Validator validator = factory.getValidator();" -msgstr "" - -#. Tag: title -#: customoptions.xml:534 -#, no-c-format -msgid "Boolean composition for constraint composition" -msgstr "" - -#. Tag: para -#: customoptions.xml:536 -#, no-c-format -msgid "As per Bean Validation specification the constraints of a composed constraint (see ) are all combined via a logical AND. This means all of the composing constraints need to return true in order for an overall successful validation. Hibernate Validator offers an extension to this logical AND combination which allows you to compose constraints via a logical OR or NOT. To do so you have to use the ConstraintComposition annotation and the enum CompositionType with its values AND, OR and ALL_FALSE. shows how to build a composing constraint where only one of the constraints has to be successful in order to pass the validation. Either the validated string is all lowercased or it is between two and three characters long." -msgstr "" - -#. Tag: title -#: customoptions.xml:554 -#, no-c-format -msgid "OR composition of constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:556 -#, no-c-format -msgid "" - "@ConstraintComposition(OR)\n" - "@Pattern(regexp = \"[a-z]\")\n" - "@Size(min = 2, max = 3)\n" - "@ReportAsSingleViolation\n" - "@Target({ METHOD, FIELD })\n" - "@Retention(RUNTIME)\n" - "@Constraint(validatedBy = { })\n" - "public @interface PatternOrSize {\n" - " public abstract String message() default \"{PatternOrSize.message}\";\n" - " public abstract Class<?>[] groups() default { };\n" - " public abstract Class<? extends Payload>[] payload() default { };\n" - "}" -msgstr "" - -#. Tag: para -#: customoptions.xml:560 -#, no-c-format -msgid "Using ALL_FALSE as composition type implicitly enforces that only a single violation will get reported in case validation of the constraint composition fails." -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/further-reading.pot b/documentation/src/main/docbook/pot/modules/further-reading.pot deleted file mode 100644 index 9306fd1ec4..0000000000 --- a/documentation/src/main/docbook/pot/modules/further-reading.pot +++ /dev/null @@ -1,45 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: further-reading.xml:24 -#, no-c-format -msgid "Further reading" -msgstr "" - -#. Tag: para -#: further-reading.xml:26 -#, no-c-format -msgid "Last but not least, a few pointers to further information." -msgstr "" - -#. Tag: para -#: further-reading.xml:28 -#, no-c-format -msgid "A great source for examples is the Bean Validation TCK which is available for anonymous access on GitHub. In particular the TCK's tests might be of interest. The JSR 349 specification itself is also a great way to deepen your understanding of Bean Validation resp. Hibernate Validator." -msgstr "" - -#. Tag: para -#: further-reading.xml:38 -#, no-c-format -msgid "If you have any further questions to Hibernate Validator or want to share some of your use cases have a look at the Hibernate Validator Wiki and the Hibernate Validator Forum." -msgstr "" - -#. Tag: para -#: further-reading.xml:45 -#, no-c-format -msgid "In case you would like to report a bug use Hibernate's Jira instance. Feedback is always welcome!" -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/furtherreading.pot b/documentation/src/main/docbook/pot/modules/furtherreading.pot deleted file mode 100644 index e71b4f3fe4..0000000000 --- a/documentation/src/main/docbook/pot/modules/furtherreading.pot +++ /dev/null @@ -1,46 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-03 09:59+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: furtherreading.xml:24 -#, no-c-format -msgid "Further reading" -msgstr "" - -#. Tag: para -#: furtherreading.xml:26 -#, no-c-format -msgid "Last but not least, a few pointers to further information." -msgstr "" - -#. Tag: para -#: furtherreading.xml:28 -#, no-c-format -msgid "A great source for examples is the Bean Validation TCK which is available for anonymous access on GitHub. In particular the TCK's tests might be of interest. The JSR 303 specification itself is also a great way to deepen your understanding of Bean Validation resp. Hibernate Validator." -msgstr "" - -#. Tag: para -#: furtherreading.xml:37 -#, no-c-format -msgid "If you have any further questions to Hibernate Validator or want to share some of your use cases have a look at the Hibernate Validator Wiki and the Hibernate Validator Forum." -msgstr "" - -#. Tag: para -#: furtherreading.xml:44 -#, no-c-format -msgid "In case you would like to report a bug use Hibernate's Jira instance. Feedback is always welcome!" -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/getting-started.pot b/documentation/src/main/docbook/pot/modules/getting-started.pot deleted file mode 100644 index 70310070a2..0000000000 --- a/documentation/src/main/docbook/pot/modules/getting-started.pot +++ /dev/null @@ -1,397 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: getting-started.xml:24 -#, no-c-format -msgid "Getting started" -msgstr "" - -#. Tag: para -#: getting-started.xml:26 -#, no-c-format -msgid "This chapter will show you how to get started with Hibernate Validator, the reference implementation (RI) of Bean Validation. For the following quickstart you need:" -msgstr "" - -#. Tag: para -#: getting-started.xml:32 -#, no-c-format -msgid "A JDK >= 6" -msgstr "" - -#. Tag: ulink -#: getting-started.xml:36 -#, no-c-format -msgid "Apache Maven" -msgstr "" - -#. Tag: para -#: getting-started.xml:40 -#, no-c-format -msgid "An Internet connection (Maven has to download all required libraries)" -msgstr "" - -#. Tag: title -#: getting-started.xml:46 -#, no-c-format -msgid "Project set up" -msgstr "" - -#. Tag: para -#: getting-started.xml:48 -#, no-c-format -msgid "In order to use Hibernate Validator within a Maven project, simply add the following dependency to your pom.xml:" -msgstr "" - -#. Tag: title -#: getting-started.xml:52 -#, no-c-format -msgid "Hibernate Validator Maven dependency" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:54 -#, no-c-format -msgid "" - "<dependency>\n" - " <groupId>org.hibernate</groupId>\n" - " <artifactId>hibernate-validator</artifactId>\n" - " <version>&version;</version>\n" - "</dependency>" -msgstr "" - -#. Tag: para -#: getting-started.xml:57 -#, no-c-format -msgid "This transitively pulls in the dependency to the Bean Validation API (javax.validation:validation-api:&bvVersion;)." -msgstr "" - -#. Tag: title -#: getting-started.xml:61 -#, no-c-format -msgid "Logging" -msgstr "" - -#. Tag: para -#: getting-started.xml:63 -#, no-c-format -msgid "For the purposes of logging, Hibernate Validator uses the JBoss Logging API. This is an abstraction layer which supports several known logging solutions (e.g. log4j or the logging framework provided by the JDK) as implementation. Just add your preferred logging library as dependency to your project and all log requests from Hibernate Validator will automatically be delegated to that logging provider." -msgstr "" - -#. Tag: para -#: getting-started.xml:70 -#, no-c-format -msgid "If there are several logging implementations part of the classpath, you can explicitely specify a provider using the system property org.jboss.logging.provider. Supported values currently are jboss, jdk, log4j and slf4j." -msgstr "" - -#. Tag: title -#: getting-started.xml:78 -#, no-c-format -msgid "Unified EL" -msgstr "" - -#. Tag: para -#: getting-started.xml:80 -#, no-c-format -msgid "Hibernate Validator requires an implementation of the Unified Expression Language (JSR 341) for evaluating dynamic expressions in constraint violation messages (see ). When your application runs in a Java EE container such as JBoss AS, an EL implementation is already provided by the container. In a Java SE environment, however, you have to add an implementation as dependency to your POM file. For instance you can add the following two dependencies to use the JSR 341 reference implementation:" -msgstr "" - -#. Tag: title -#: getting-started.xml:92 -#, no-c-format -msgid "Maven dependencies for Unified EL reference implementation" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:95 -#, no-c-format -msgid "" - "<dependency>\n" - " <groupId>javax.el</groupId>\n" - " <artifactId>javax.el-api</artifactId>\n" - " <version>2.2.4</version>\n" - "</dependency>\n" - "<dependency>\n" - " <groupId>org.glassfish.web</groupId>\n" - " <artifactId>javax.el</artifactId>\n" - " <version>2.2.4</version>\n" - "</dependency>" -msgstr "" - -#. Tag: title -#: getting-started.xml:100 -#, no-c-format -msgid "CDI" -msgstr "" - -#. Tag: para -#: getting-started.xml:102 -#, no-c-format -msgid "Bean Validation defines integration points with CDI (Contexts and Dependency Injection for JavaTM EE, JSR 346). If your application runs in an environment which does not provide this integration out of the box, you may use the Hibernate Validator CDI portable extension by adding the following Maven dependency to your POM:" -msgstr "" - -#. Tag: title -#: getting-started.xml:111 -#, no-c-format -msgid "Hibernate Validator CDI portable extension Maven dependency" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:114 -#, no-c-format -msgid "" - "<dependency>\n" - " <groupId>org.hibernate</groupId>\n" - " <artifactId>hibernate-validator-cdi</artifactId>\n" - " <version>&version;</version>\n" - "</dependency>" -msgstr "" - -#. Tag: para -#: getting-started.xml:117 -#, no-c-format -msgid "Note that adding this dependency is usually not required for applications running on a Java EE application server. You can learn more about the integration of Bean Validation and CDI in ." -msgstr "" - -#. Tag: title -#: getting-started.xml:125 -#, no-c-format -msgid "Applying constraints" -msgstr "" - -#. Tag: para -#: getting-started.xml:127 -#, no-c-format -msgid "Lets dive directly into an example to see how to apply constraints." -msgstr "" - -#. Tag: title -#: getting-started.xml:131 -#, no-c-format -msgid "Class Car annotated with constraints" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:133 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter01;\n" - "\n" - "import javax.validation.constraints.Min;\n" - "import javax.validation.constraints.NotNull;\n" - "import javax.validation.constraints.Size;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @NotNull\n" - " @Size(min = 2, max = 14)\n" - " private String licensePlate;\n" - "\n" - " @Min(2)\n" - " private int seatCount;\n" - "\n" - " public Car(String manufacturer, String licencePlate, int seatCount) {\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licencePlate;\n" - " this.seatCount = seatCount;\n" - " }\n" - "\n" - " //getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: getting-started.xml:136 -#, no-c-format -msgid "The @NotNull, @Size and @Min annotations are used to declare the constraints which should be applied to the fields of a Car instance:" -msgstr "" - -#. Tag: para -#: getting-started.xml:143 -#, no-c-format -msgid "manufacturer must never be null" -msgstr "" - -#. Tag: para -#: getting-started.xml:148 -#, no-c-format -msgid "licensePlate must never be null and must be between 2 and 14 characters long" -msgstr "" - -#. Tag: para -#: getting-started.xml:154 -#, no-c-format -msgid "seatCount must be at least 2" -msgstr "" - -#. Tag: title -#: getting-started.xml:160 -#, no-c-format -msgid "Validating constraints" -msgstr "" - -#. Tag: para -#: getting-started.xml:162 -#, no-c-format -msgid "To perform a validation of these constraints, you use a Validator instance. Let's have a look at a unit test for Car:" -msgstr "" - -#. Tag: title -#: getting-started.xml:167 -#, no-c-format -msgid "Class CarTest showing validation examples" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:169 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter01;\n" - "\n" - "import java.util.Set;\n" - "import javax.validation.ConstraintViolation;\n" - "import javax.validation.Validation;\n" - "import javax.validation.Validator;\n" - "import javax.validation.ValidatorFactory;\n" - "\n" - "import org.junit.BeforeClass;\n" - "import org.junit.Test;\n" - "\n" - "import static org.junit.Assert.assertEquals;\n" - "\n" - "public class CarTest {\n" - "\n" - " private static Validator validator;\n" - "\n" - " @BeforeClass\n" - " public static void setUp() {\n" - " ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - " validator = factory.getValidator();\n" - " }\n" - "\n" - " @Test\n" - " public void manufacturerIsNull() {\n" - " Car car = new Car( null, \"DD-AB-123\", 4 );\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate( car );\n" - "\n" - " assertEquals( 1, constraintViolations.size() );\n" - " assertEquals( \"may not be null\", constraintViolations.iterator().next().getMessage() );\n" - " }\n" - "\n" - " @Test\n" - " public void licensePlateTooShort() {\n" - " Car car = new Car( \"Morris\", \"D\", 4 );\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate( car );\n" - "\n" - " assertEquals( 1, constraintViolations.size() );\n" - " assertEquals(\n" - " \"size must be between 2 and 14\",\n" - " constraintViolations.iterator().next().getMessage()\n" - " );\n" - " }\n" - "\n" - " @Test\n" - " public void seatCountTooLow() {\n" - " Car car = new Car( \"Morris\", \"DD-AB-123\", 1 );\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate( car );\n" - "\n" - " assertEquals( 1, constraintViolations.size() );\n" - " assertEquals(\n" - " \"must be greater than or equal to 2\",\n" - " constraintViolations.iterator().next().getMessage()\n" - " );\n" - " }\n" - "\n" - " @Test\n" - " public void carIsValid() {\n" - " Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate( car );\n" - "\n" - " assertEquals( 0, constraintViolations.size() );\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: getting-started.xml:172 -#, no-c-format -msgid "In the setUp() method a Validator object is retrieved from the ValidatorFactory. A Validator instance is thread-safe and may be reused multiple times. It thus can safely be stored in a static field and be used in the test methods to validate the different Car instances." -msgstr "" - -#. Tag: para -#: getting-started.xml:180 -#, no-c-format -msgid "The validate() method returns a set of ConstraintViolation instances, which you can iterate ovr in order to see which validation errors occurred. The first three test methods show some expected constraint violations:" -msgstr "" - -#. Tag: para -#: getting-started.xml:187 -#, no-c-format -msgid "The @NotNull constraint on manufacturer is violated in manufacturerIsNull()" -msgstr "" - -#. Tag: para -#: getting-started.xml:192 -#, no-c-format -msgid "The @Size constraint on licensePlate is violated in licensePlateTooShort()" -msgstr "" - -#. Tag: para -#: getting-started.xml:197 -#, no-c-format -msgid "The @Min constraint on seatCount is violated in seatCountTooLow()" -msgstr "" - -#. Tag: para -#: getting-started.xml:202 -#, no-c-format -msgid "If the object validates successfully, validate() returns an empty set as you can see in carIsValid()." -msgstr "" - -#. Tag: para -#: getting-started.xml:206 -#, no-c-format -msgid "Note that only use classes from the package javax.validation from the Bean Validation API are used. No classes from Hibernate Validator are directly referenced, resulting in portable code." -msgstr "" - -#. Tag: title -#: getting-started.xml:213 -#, no-c-format -msgid "Where to go next?" -msgstr "" - -#. Tag: para -#: getting-started.xml:215 -#, no-c-format -msgid "That concludes the 5 minute tour through the world of Hibernate Validator and Bean Validaiton. Continue exploring the code examples or look at further examples referenced in ." -msgstr "" - -#. Tag: para -#: getting-started.xml:220 -#, no-c-format -msgid "To learn more about the validation of beans and properties, just continue reading . If you are interested in using Bean Validation for the validation of method pre- and postcondition refer to . In case your application has specific validation requirements have a look at ." -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/gettingstarted.pot b/documentation/src/main/docbook/pot/modules/gettingstarted.pot deleted file mode 100644 index a6dce20b0f..0000000000 --- a/documentation/src/main/docbook/pot/modules/gettingstarted.pot +++ /dev/null @@ -1,381 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-03 09:59+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: gettingstarted.xml:24 -#, no-c-format -msgid "Getting started" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:26 -#, no-c-format -msgid "This chapter will show you how to get started with Hibernate Validator, the reference implementation (RI) of Bean Validation. For the following quickstart you need:" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:32 -#, no-c-format -msgid "A JDK >= 6" -msgstr "" - -#. Tag: ulink -#: gettingstarted.xml:36 -#, no-c-format -msgid "Apache Maven" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:40 -#, no-c-format -msgid "An Internet connection (Maven has to download all required libraries)" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:46 -#, no-c-format -msgid "Project set up" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:48 -#, no-c-format -msgid "In order to use Hibernate Validator within a Maven project, simply add the following dependency to your pom.xml:" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:50 -#, no-c-format -msgid "Hibernate Validator Maven dependency" -msgstr "" - -#. Tag: programlisting -#: gettingstarted.xml:52 -#, no-c-format -msgid "" - "<dependency>\n" - " <groupId>org.hibernate</groupId>\n" - " <artifactId>hibernate-validator</artifactId>\n" - " <version>&version;</version>\n" - "</dependency>" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:55 -#, no-c-format -msgid "This transitively pulls in the dependency to the Bean Validation API (javax.validation:validation-api:&bvVersion;)." -msgstr "" - -#. Tag: para -#: gettingstarted.xml:59 -#, no-c-format -msgid "For the purposes of logging, Hibernate Validator uses the JBoss Logging API. This is an abstraction layer which supports several known logging solutions (e.g. log4j or the logging framework provided by the JDK) as implementation. Just add your preferred logging library to the classpath and all log requests from Hibernate Validator will automatically be delegated to that logging provider." -msgstr "" - -#. Tag: para -#: gettingstarted.xml:66 -#, no-c-format -msgid "Alternatively, you can explicitely specify a provider using the system property org.jboss.logging.provider. Supported values currently are jboss, jdk, log4j and slf4j." -msgstr "" - -#. Tag: title -#: gettingstarted.xml:73 -#, no-c-format -msgid "Unified EL" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:75 -#, no-c-format -msgid "Hibernate Validator requires an implementation of the Unified Expression Language (JSR 341) for evaluating dynamic expressions in constraint violation messages (see ). When your application runs in a Java EE container such as JBoss AS, an EL implementation is already provided by the container. In a Java SE environment, however, you have to add an implementation as dependency to your POM file. For instance you can add the following two dependencies to use the JSR 341 reference implementation:" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:87 -#, no-c-format -msgid "Maven dependencies for Unified EL reference implementation" -msgstr "" - -#. Tag: programlisting -#: gettingstarted.xml:90 -#, no-c-format -msgid "" - "<dependency>\n" - " <groupId>javax.el</groupId>\n" - " <artifactId>javax.el-api</artifactId>\n" - " <version>2.2.4</version>\n" - "</dependency>\n" - "<dependency>\n" - " <groupId>org.glassfish.web</groupId>\n" - " <artifactId>javax.el</artifactId>\n" - " <version>2.2.4</version>\n" - "</dependency>" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:95 -#, no-c-format -msgid "CDI" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:97 -#, no-c-format -msgid "Bean Validation defines integration points with CDI (Contexts and Dependency Injection for JavaTM EE, JSR 346). If your application runs in an environment which does not provide this integration out of the box, you may use the Hibernate Validator CDI portable extension by adding the following Maven dependency to your POM:" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:106 -#, no-c-format -msgid "Hibernate Validator CDI portable extension Maven dependency" -msgstr "" - -#. Tag: programlisting -#: gettingstarted.xml:109 -#, no-c-format -msgid "" - "<dependency>\n" - " <groupId>org.hibernate</groupId>\n" - " <artifactId>hibernate-validator-cdi</artifactId>\n" - " <version>&version;</version>\n" - "</dependency>" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:112 -#, no-c-format -msgid "Note that adding this dependency is usually not required for applications running on a Java EE application server. You can learn more about the integration of Bean Validation and CDI in section TODO." -msgstr "" - -#. Tag: title -#: gettingstarted.xml:119 -#, no-c-format -msgid "Applying constraints" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:121 -#, no-c-format -msgid "Lets dive directly into an example to see how to apply constraints." -msgstr "" - -#. Tag: title -#: gettingstarted.xml:125 -#, no-c-format -msgid "Class Car annotated with constraints" -msgstr "" - -#. Tag: programlisting -#: gettingstarted.xml:127 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.constraints.Min;\n" - "import javax.validation.constraints.NotNull;\n" - "import javax.validation.constraints.Size;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @NotNull\n" - " @Size(min = 2, max = 14)\n" - " private String licensePlate;\n" - "\n" - " @Min(2)\n" - " private int seatCount;\n" - " \n" - " public Car(String manufacturer, String licencePlate, int seatCount) {\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licencePlate;\n" - " this.seatCount = seatCount;\n" - " }\n" - "\n" - " //getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:130 -#, no-c-format -msgid "@NotNull, @Size and @Min are so-called constraint annotations, that we use to declare constraints, which shall be applied to the fields of a Car instance:" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:137 -#, no-c-format -msgid "manufacturer shall never be null" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:141 -#, no-c-format -msgid "licensePlate shall never be null and must be between 2 and 14 characters long" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:146 -#, no-c-format -msgid "seatCount shall be at least 2." -msgstr "" - -#. Tag: title -#: gettingstarted.xml:152 -#, no-c-format -msgid "Validating constraints" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:154 -#, no-c-format -msgid "To perform a validation of these constraints, we use a Validator instance. Let's have a look at a unit test for Car:" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:159 -#, no-c-format -msgid "Class CarTest showing validation examples" -msgstr "" - -#. Tag: programlisting -#: gettingstarted.xml:161 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import static org.junit.Assert.*;\n" - "\n" - "import java.util.Set;\n" - "\n" - "import javax.validation.ConstraintViolation;\n" - "import javax.validation.Validation;\n" - "import javax.validation.Validator;\n" - "import javax.validation.ValidatorFactory;\n" - "\n" - "import org.junit.BeforeClass;\n" - "import org.junit.Test;\n" - "\n" - "public class CarTest {\n" - "\n" - " private static Validator validator;\n" - "\n" - " @BeforeClass\n" - " public static void setUp() {\n" - " ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - " validator = factory.getValidator();\n" - " }\n" - "\n" - " @Test\n" - " public void manufacturerIsNull() {\n" - " Car car = new Car(null, \"DD-AB-123\", 4);\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate(car);\n" - "\n" - " assertEquals(1, constraintViolations.size());\n" - " assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());\n" - " }\n" - "\n" - " @Test\n" - " public void licensePlateTooShort() {\n" - " Car car = new Car(\"Morris\", \"D\", 4);\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations = \n" - " validator.validate(car);\n" - "\n" - " assertEquals(1, constraintViolations.size());\n" - " assertEquals(\"size must be between 2 and 14\", constraintViolations.iterator().next().getMessage());\n" - " }\n" - " \n" - " @Test\n" - " public void seatCountTooLow() {\n" - " Car car = new Car(\"Morris\", \"DD-AB-123\", 1);\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate(car);\n" - "\n" - " assertEquals(1, constraintViolations.size());\n" - " assertEquals(\"must be greater than or equal to 2\", constraintViolations.iterator().next().getMessage());\n" - " }\n" - "\n" - " @Test\n" - " public void carIsValid() {\n" - " Car car = new Car(\"Morris\", \"DD-AB-123\", 2);\n" - "\n" - " Set<ConstraintViolation<Car>> constraintViolations =\n" - " validator.validate(car);\n" - "\n" - " assertEquals(0, constraintViolations.size());\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:164 -#, no-c-format -msgid "In the setUp() method we get a Validator instance from the ValidatorFactory. A Validator instance is thread-safe and may be reused multiple times. For this reason we store it as field of our test class. We can use the Validator now to validate the different car instances in the test methods." -msgstr "" - -#. Tag: para -#: gettingstarted.xml:172 -#, no-c-format -msgid "The validate() method returns a set of ConstraintViolation instances, which we can iterate in order to see which validation errors occurred. The first three test methods show some expected constraint violations:" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:179 -#, no-c-format -msgid "The @NotNull constraint on manufacturer is violated in manufacturerIsNull()" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:184 -#, no-c-format -msgid "The @Size constraint on licensePlate is violated in licensePlateTooShort()" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:189 -#, no-c-format -msgid "The @Min constraint on seatCount is violated in seatCountTooLow()" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:194 -#, no-c-format -msgid "If the object validates successfully, validate() returns an empty set." -msgstr "" - -#. Tag: para -#: gettingstarted.xml:197 -#, no-c-format -msgid "Note that we only use classes from the package javax.validation from the Bean Validation API. As we don't reference any classes of the RI directly, it would be no problem to switch to another implementation of the API, should that need arise." -msgstr "" - -#. Tag: title -#: gettingstarted.xml:205 -#, no-c-format -msgid "Where to go next?" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:207 -#, no-c-format -msgid "That concludes our 5 minute tour through the world of Hibernate Validator. Continue exploring the code examples or look at further examples referenced in . To deepen your understanding of Hibernate Validator just continue reading . In case your application has specific validation requirements have a look at ." -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/groups.pot b/documentation/src/main/docbook/pot/modules/groups.pot deleted file mode 100644 index eaf983d5bd..0000000000 --- a/documentation/src/main/docbook/pot/modules/groups.pot +++ /dev/null @@ -1,731 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: groups.xml:24 -#, no-c-format -msgid "Grouping constraints" -msgstr "" - -#. Tag: para -#: groups.xml:26 -#, no-c-format -msgid "All validation methods on Validator and ExecutableValidator discussed in earlier chapters also take a var-arg argument groups. So far we have been ignoring this parameter, but it is time to have a closer look." -msgstr "" - -#. Tag: title -#: groups.xml:32 -#, no-c-format -msgid "Requesting groups" -msgstr "" - -#. Tag: para -#: groups.xml:34 -#, no-c-format -msgid "Groups allow you to restrict the set of constraints applied during validation. A possible use-case for groups are UI wizards where in each step only a specified subset of constraints get validated. The groups targeted are passed as var-arg parameters to the appropriate validate method. Let's have a look at an extended Car with Driver example. First we have the class Person () which has a @NotNull constraint on name. Since no group is specified for this annotation the default group javax.validation.groups.Default is assumed." -msgstr "" - -#. Tag: para -#: groups.xml:46 -#, no-c-format -msgid "When more than one group is requested, the order in which the groups are evaluated is not deterministic. If no group is specified the default group javax.validation.groups.Default is assumed." -msgstr "" - -#. Tag: title -#: groups.xml:53 -#, no-c-format -msgid "Person" -msgstr "" - -#. Tag: programlisting -#: groups.xml:55 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups;\n" - "\n" - "public class Person {\n" - " @NotNull\n" - " private String name;\n" - "\n" - " public Person(String name) {\n" - " this.name = name;\n" - " }\n" - "\n" - " // getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: groups.xml:58 -#, no-c-format -msgid "Next we have the class Driver () extending Person. Here we are adding the properties age and hasDrivingLicense. In order to drive you must be at least 18 (@Min(18)) and you must have a driving license (@AssertTrue). Both constraints defined on these properties belong to the group DriverChecks. As you can see in the group DriverChecks is just a simple tagging interface. Using interfaces makes the usage of groups type safe and allows for easy refactoring. It also means that groups can inherit from each other via class inheritance." -msgstr "" - -#. Tag: title -#: groups.xml:72 -#, no-c-format -msgid "Driver" -msgstr "" - -#. Tag: programlisting -#: groups.xml:74 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups;\n" - "\n" - "public class Driver extends Person {\n" - " @Min(\n" - " value = 18,\n" - " message = \"You have to be 18 to drive a car\",\n" - " groups = DriverChecks.class\n" - " )\n" - " public int age;\n" - "\n" - " @AssertTrue(\n" - " message = \"You first have to pass the driving test\",\n" - " groups = DriverChecks.class\n" - " )\n" - " public boolean hasDrivingLicense;\n" - "\n" - " public Driver(String name) {\n" - " super( name );\n" - " }\n" - "\n" - " public void passedDrivingTest(boolean b) {\n" - " hasDrivingLicense = b;\n" - " }\n" - "\n" - " public int getAge() {\n" - " return age;\n" - " }\n" - "\n" - " public void setAge(int age) {\n" - " this.age = age;\n" - " }\n" - "}" -msgstr "" - -#. Tag: title -#: groups.xml:78 -#, no-c-format -msgid "Group interfaces" -msgstr "" - -#. Tag: programlisting -#: groups.xml:80 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups;\n" - "\n" - "public interface DriverChecks {\n" - "}" -msgstr "" - -#. Tag: programlisting -#: groups.xml:82 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups;\n" - "\n" - "public interface CarChecks {\n" - "}" -msgstr "" - -#. Tag: para -#: groups.xml:85 -#, no-c-format -msgid "Last but not least we add the property passedVehicleInspection to the Car class () indicating whether a car passed the road worthy tests." -msgstr "" - -#. Tag: title -#: groups.xml:91 -#, no-c-format -msgid "Car" -msgstr "" - -#. Tag: programlisting -#: groups.xml:93 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups;\n" - "\n" - "public class Car {\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @NotNull\n" - " @Size(min = 2, max = 14)\n" - " private String licensePlate;\n" - "\n" - " @Min(2)\n" - " private int seatCount;\n" - "\n" - " @AssertTrue(\n" - " message = \"The car has to pass the vehicle inspection first\",\n" - " groups = CarChecks.class\n" - " )\n" - " private boolean passedVehicleInspection;\n" - "\n" - " @Valid\n" - " private Driver driver;\n" - "\n" - " public Car(String manufacturer, String licencePlate, int seatCount) {\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licencePlate;\n" - " this.seatCount = seatCount;\n" - " }\n" - "\n" - " public boolean isPassedVehicleInspection() {\n" - " return passedVehicleInspection;\n" - " }\n" - "\n" - " public void setPassedVehicleInspection(boolean passedVehicleInspection) {\n" - " this.passedVehicleInspection = passedVehicleInspection;\n" - " }\n" - "\n" - " public Driver getDriver() {\n" - " return driver;\n" - " }\n" - "\n" - " public void setDriver(Driver driver) {\n" - " this.driver = driver;\n" - " }\n" - "\n" - " // getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: groups.xml:96 -#, no-c-format -msgid "Overall three different groups are used in our example. Person.name, Car.manufacturer, Car.licensePlate and Car.seatCount all belong to the Default group. Driver.age and Driver.hasDrivingLicense belong to DriverChecks and last but not least Car.passedVehicleInspection belongs to the group CarChecks. shows how passing different group combinations to the Validator.validate method result in different validation results." -msgstr "" - -#. Tag: title -#: groups.xml:110 -#, no-c-format -msgid "Drive away" -msgstr "" - -#. Tag: programlisting -#: groups.xml:112 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups;\n" - "\n" - "public class GroupTest {\n" - "\n" - " private static Validator validator;\n" - "\n" - " @BeforeClass\n" - " public static void setUp() {\n" - " ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - " validator = factory.getValidator();\n" - " }\n" - "\n" - " @Test\n" - " public void driveAway() {\n" - " // create a car and check that everything is ok with it.\n" - " Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" - " Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );\n" - " assertEquals( 0, constraintViolations.size() );\n" - "\n" - " // but has it passed the vehicle inspection?\n" - " constraintViolations = validator.validate( car, CarChecks.class );\n" - " assertEquals( 1, constraintViolations.size() );\n" - " assertEquals(\n" - " \"The car has to pass the vehicle inspection first\",\n" - " constraintViolations.iterator().next().getMessage()\n" - " );\n" - "\n" - " // let's go to the vehicle inspection\n" - " car.setPassedVehicleInspection( true );\n" - " assertEquals( 0, validator.validate( car ).size() );\n" - "\n" - " // now let's add a driver. He is 18, but has not passed the driving test yet\n" - " Driver john = new Driver( \"John Doe\" );\n" - " john.setAge( 18 );\n" - " car.setDriver( john );\n" - " constraintViolations = validator.validate( car, DriverChecks.class );\n" - " assertEquals( 1, constraintViolations.size() );\n" - " assertEquals(\n" - " \"You first have to pass the driving test\",\n" - " constraintViolations.iterator().next().getMessage()\n" - " );\n" - "\n" - " // ok, John passes the test\n" - " john.passedDrivingTest( true );\n" - " assertEquals( 0, validator.validate( car, DriverChecks.class ).size() );\n" - "\n" - " // just checking that everything is in order now\n" - " assertEquals(\n" - " 0, validator.validate(\n" - " car,\n" - " Default.class,\n" - " CarChecks.class,\n" - " DriverChecks.class\n" - " ).size()\n" - " );\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: groups.xml:115 -#, no-c-format -msgid "In we first create a car and validate it using no explicit group. There are no validation errors, even though the property passedVehicleInspection is per default false. However, the constraint defined on this property does not belong to the default group. Next we just validate the CarChecks group which will fail until we make sure that the car passes the vehicle inspection. When we then add a driver to the car and validate against DriverChecks we get again a constraint violation due to the fact that the driver has not yet passed the driving test. Only after setting passedDrivingTest to true the validation against DriverChecks will pass. Last but not least, we show that all constraints are passing by validating against all defined groups." -msgstr "" - -#. Tag: title -#: groups.xml:132 -#, no-c-format -msgid "Defining group sequences" -msgstr "" - -#. Tag: para -#: groups.xml:134 -#, no-c-format -msgid "By default, constraints are evaluated in no particular order, regardless of which groups they belong to. In some situations, however, it is useful to control the order constraints are evaluated. In our example from we could for example require that first all default car constraints are passing before we check the road worthiness of the car. Finally before we drive away we check the actual driver constraints. In order to implement such an order one would define a new interface and annotate it with @GroupSequence defining the order in which the groups have to be validated." -msgstr "" - -#. Tag: para -#: groups.xml:146 -#, no-c-format -msgid "If at least one constraint fails in a sequenced group none of the constraints of the following groups in the sequence get validated." -msgstr "" - -#. Tag: title -#: groups.xml:152 -#, no-c-format -msgid "Interface with @GroupSequence" -msgstr "" - -#. Tag: programlisting -#: groups.xml:154 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups;\n" - "\n" - "@GroupSequence({ Default.class, CarChecks.class, DriverChecks.class })\n" - "public interface OrderedChecks {\n" - "}" -msgstr "" - -#. Tag: para -#: groups.xml:158 -#, no-c-format -msgid "Groups defining a sequence and groups composing a sequence must not be involved in a cyclic dependency either directly or indirectly, either through cascaded sequence definition or group inheritance. If a group containing such a circularity is evaluated, a GroupDefinitionException is raised." -msgstr "" - -#. Tag: para -#: groups.xml:162 -#, no-c-format -msgid "The usage of the new sequence could then look like in ." -msgstr "" - -#. Tag: title -#: groups.xml:167 -#, no-c-format -msgid "Usage of a group sequence" -msgstr "" - -#. Tag: programlisting -#: groups.xml:169 -#, no-c-format -msgid "" - "@Test\n" - "public void testOrderedChecks() {\n" - " Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" - " car.setPassedVehicleInspection( true );\n" - "\n" - " Driver john = new Driver( \"John Doe\" );\n" - " john.setAge( 18 );\n" - " john.passedDrivingTest( true );\n" - " car.setDriver( john );\n" - "\n" - " assertEquals( 0, validator.validate( car, OrderedChecks.class ).size() );\n" - "}" -msgstr "" - -#. Tag: title -#: groups.xml:174 -#, no-c-format -msgid "Redefining the default group sequence" -msgstr "" - -#. Tag: title -#: groups.xml:177 -#, no-c-format -msgid "@GroupSequence" -msgstr "" - -#. Tag: para -#: groups.xml:179 -#, no-c-format -msgid "The @GroupSequence annotation also fulfills a second purpose. It allows you to redefine what the Default group means for a given class. To redefine Default for a given class, add a @GroupSequence annotation to the class. The defined groups in the annotation express the sequence of groups that substitute Default for this class. introduces a new class RentalCar with a redefined default group. With this definition you can evaluate the constraints belonging to RentalChecks, CarChecks and RentalCar by just requesting the Default group as seen in ." -msgstr "" - -#. Tag: title -#: groups.xml:195 -#, no-c-format -msgid "RentalCar with @GroupSequence" -msgstr "" - -#. Tag: programlisting -#: groups.xml:197 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups;\n" - "\n" - "@GroupSequence({ RentalChecks.class, CarChecks.class, RentalCar.class })\n" - "public class RentalCar extends Car {\n" - " @AssertFalse(message = \"The car is currently rented out\", groups = RentalChecks.class)\n" - " private boolean rented;\n" - "\n" - " public RentalCar(String manufacturer, String licencePlate, int seatCount) {\n" - " super( manufacturer, licencePlate, seatCount );\n" - " }\n" - "\n" - " public boolean isRented() {\n" - " return rented;\n" - " }\n" - "\n" - " public void setRented(boolean rented) {\n" - " this.rented = rented;\n" - " }\n" - "}" -msgstr "" - -#. Tag: title -#: groups.xml:201 -#, no-c-format -msgid "RentalCar with redefined default group" -msgstr "" - -#. Tag: programlisting -#: groups.xml:203 -#, no-c-format -msgid "" - "/**\n" - " * Validating the default group leads to validation on the default group sequence of {@code RentalCar}.\n" - " */\n" - "@Test\n" - "public void carIsRented() {\n" - " RentalCar rentalCar = new RentalCar( \"Morris\", \"DD-AB-123\", 2 );\n" - " rentalCar.setPassedVehicleInspection( true );\n" - " rentalCar.setRented( true );\n" - "\n" - " Set<ConstraintViolation<RentalCar>> constraintViolations = validator.validate( rentalCar );\n" - "\n" - " assertEquals( 1, constraintViolations.size() );\n" - " assertEquals(\n" - " \"Wrong message\",\n" - " \"The car is currently rented out\",\n" - " constraintViolations.iterator().next().getMessage()\n" - " );\n" - "\n" - " rentalCar.setRented( false );\n" - " constraintViolations = validator.validate( rentalCar );\n" - "\n" - " assertEquals( 0, constraintViolations.size() );\n" - "}" -msgstr "" - -#. Tag: para -#: groups.xml:207 -#, no-c-format -msgid "Due to the fact that there cannot be a cyclic dependency in the group and group sequence definitions one cannot just add Default to the sequence redefining Default for a class. Instead the class itself has to be added!" -msgstr "" - -#. Tag: para -#: groups.xml:215 -#, no-c-format -msgid "The Default group sequence overriding is local to the class it is defined on and is not propagated to the associated objects. This means in particular that adding DriverChecks to the default group sequence of RentalCar would not have any effects. Only the group Default will be propagated to the driver association when validation a rental car instance." -msgstr "" - -#. Tag: title -#: groups.xml:226 -#, no-c-format -msgid "@GroupSequenceProvider" -msgstr "" - -#. Tag: para -#: groups.xml:228 -#, no-c-format -msgid "The @javax.validation.GroupSequence annotation is a standardized Bean Validation annotation. As seen in the previous section it allows you to statically redefine the default group sequence for a class. Hibernate Validator also offers a custom, non standardized annotation - org.hibernate.validator.group.GroupSequenceProvider - which allows for dynamic redefinition of the default group sequence. Using the rental car scenario again, one could dynamically add the CarChecks as seen in and ." -msgstr "" - -#. Tag: title -#: groups.xml:241 -#, no-c-format -msgid "RentalCar with @GroupSequenceProvider" -msgstr "" - -#. Tag: programlisting -#: groups.xml:243 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups.groupsequenceprovider;\n" - "\n" - "@GroupSequenceProvider(RentalCarGroupSequenceProvider.class)\n" - "public class RentalCar extends Car {\n" - " @AssertFalse(message = \"The car is currently rented out\", groups = RentalChecks.class)\n" - " private boolean rented;\n" - "\n" - " public RentalCar(String manufacturer, String licencePlate, int seatCount) {\n" - " super( manufacturer, licencePlate, seatCount );\n" - " }\n" - "\n" - " public boolean isRented() {\n" - " return rented;\n" - " }\n" - "\n" - " public void setRented(boolean rented) {\n" - " this.rented = rented;\n" - " }\n" - "}" -msgstr "" - -#. Tag: title -#: groups.xml:247 -#, no-c-format -msgid "DefaultGroupSequenceProvider implementation" -msgstr "" - -#. Tag: programlisting -#: groups.xml:249 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups.groupsequenceprovider;\n" - "\n" - "public class RentalCarGroupSequenceProvider implements DefaultGroupSequenceProvider<RentalCar> {\n" - " public List<Class<?>> getValidationGroups(RentalCar car) {\n" - " List<Class<?>> defaultGroupSequence = new ArrayList<Class<?>>();\n" - " defaultGroupSequence.add( RentalCar.class );\n" - "\n" - " if ( car != null && !car.isRented() ) {\n" - " defaultGroupSequence.add( CarChecks.class );\n" - " }\n" - "\n" - " return defaultGroupSequence;\n" - " }\n" - "}" -msgstr "" - -#. Tag: title -#: groups.xml:255 -#, no-c-format -msgid "Group conversion" -msgstr "" - -#. Tag: para -#: groups.xml:257 -#, no-c-format -msgid "What if you wanted to validate the car related checks together with the driver checks. Of course you could pass the required groups to the validate call explicitly, but what if you wanted to make these validations occur as part of the Default group validation. Here @ConvertGroup comes into play which allows you during cascaded validation to use a different group than the originally requested one." -msgstr "" - -#. Tag: para -#: groups.xml:265 -#, no-c-format -msgid "Let's have a look at . Here @GroupSequence({ CarChecks.class, Car.class }) is used to combine the car related constraints under the Default group (see ). There is also a @ConvertGroup(from = Default.class, to = DriverChecks.class) which ensures the Default group gets converted to the DriverChecks group during cascaded validation of the driver association." -msgstr "" - -#. Tag: title -#: groups.xml:277 -#, no-c-format -msgid "@ConvertGroup usage" -msgstr "" - -#. Tag: programlisting -#: groups.xml:279 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups.groupconversion;\n" - "\n" - "@GroupSequence({ CarChecks.class, Car.class })\n" - "public class Car {\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @NotNull\n" - " @Size(min = 2, max = 14)\n" - " private String licensePlate;\n" - "\n" - " @Min(2)\n" - " private int seatCount;\n" - "\n" - " @AssertTrue(\n" - " message = \"The car has to pass the vehicle inspection first\",\n" - " groups = CarChecks.class\n" - " )\n" - " private boolean passedVehicleInspection;\n" - "\n" - " @Valid\n" - " @ConvertGroup(from = Default.class, to = DriverChecks.class)\n" - " private Driver driver;\n" - "\n" - " public Car(String manufacturer, String licencePlate, int seatCount) {\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licencePlate;\n" - " this.seatCount = seatCount;\n" - " }\n" - "\n" - " public boolean isPassedVehicleInspection() {\n" - " return passedVehicleInspection;\n" - " }\n" - "\n" - " public void setPassedVehicleInspection(boolean passedVehicleInspection) {\n" - " this.passedVehicleInspection = passedVehicleInspection;\n" - " }\n" - "\n" - " public Driver getDriver() {\n" - " return driver;\n" - " }\n" - "\n" - " public void setDriver(Driver driver) {\n" - " this.driver = driver;\n" - " }\n" - "\n" - " // getters and setters ...\n" - "}" -msgstr "" - -#. Tag: programlisting -#: groups.xml:281 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups.groupconversion;\n" - "\n" - "public class Driver extends Person {\n" - " @Min(\n" - " value = 18,\n" - " message = \"You have to be 18 to drive a car\",\n" - " groups = DriverChecks.class\n" - " )\n" - " public int age;\n" - "\n" - " @AssertTrue(\n" - " message = \"You first have to pass the driving test\",\n" - " groups = DriverChecks.class\n" - " )\n" - " public boolean hasDrivingLicense;\n" - "\n" - " public Driver(String name) {\n" - " super( name );\n" - " }\n" - "\n" - " public void passedDrivingTest(boolean b) {\n" - " hasDrivingLicense = b;\n" - " }\n" - "\n" - " public int getAge() {\n" - " return age;\n" - " }\n" - "\n" - " public void setAge(int age) {\n" - " this.age = age;\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: groups.xml:284 -#, no-c-format -msgid "As a result the validateDriverChecksTogetherWithCarChecks test in will pass even though the constraint on hasDrivingLicense belongs to the DriverChecks group and only the Default group is requested in the validate call." -msgstr "" - -#. Tag: title -#: groups.xml:293 -#, no-c-format -msgid "Test case for @ConvertGroup" -msgstr "" - -#. Tag: programlisting -#: groups.xml:295 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter05.groups.groupconversion;\n" - "\n" - "public class GroupConversionTest {\n" - "\n" - " private static Validator validator;\n" - "\n" - " @BeforeClass\n" - " public static void setUp() {\n" - " ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - " validator = factory.getValidator();\n" - " }\n" - "\n" - " @Test\n" - " public void validateDriverChecksTogetherWithCarChecks() {\n" - " // create a car and validate. The Driver is still null and does not get validated\n" - " Car car = new Car( \"VW\", \"USD-123\", 4 );\n" - " car.setPassedVehicleInspection( true );\n" - " Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );\n" - " assertEquals( 0, constraintViolations.size() );\n" - "\n" - " // create a driver who has not passed the driving test\n" - " Driver john = new Driver( \"John Doe\" );\n" - " john.setAge( 18 );\n" - "\n" - " // now let's add a driver to the car\n" - " car.setDriver( john );\n" - " constraintViolations = validator.validate( car );\n" - " assertEquals( 1, constraintViolations.size() );\n" - " assertEquals(\n" - " \"The driver constraint should also be validated as part of the default group\",\n" - " constraintViolations.iterator().next().getMessage(),\n" - " \"You first have to pass the driving test\"\n" - " );\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: groups.xml:298 -#, no-c-format -msgid "Group conversions can be used everywhere @Valid can be used, namely associations, method and constructor parameters and return values. In order to specify multiple conversions @ConvertGroup.List can be used." -msgstr "" - -#. Tag: para -#: groups.xml:303 -#, no-c-format -msgid "However, there are several restrictionsas well :" -msgstr "" - -#. Tag: para -#: groups.xml:305 -#, no-c-format -msgid "@ConvertGroup must be used in combination with @Valid. If used without a ConstraintDeclarationException is thrown." -msgstr "" - -#. Tag: para -#: groups.xml:312 -#, no-c-format -msgid "It is not legal to have multiple conversion rules on the same element with the same from value. In this case, a ConstraintDeclarationException is raised." -msgstr "" - -#. Tag: para -#: groups.xml:319 -#, no-c-format -msgid "The from attribute cannot refer to a group sequence. A ConstraintDeclarationException is raised in this situation." -msgstr "" - -#. Tag: para -#: groups.xml:325 -#, no-c-format -msgid "Rules are not executed recursively. The first matching conversion rule is used and subsequent rules are ignored. For example if a set of @ConvertGroup declarations chains group A to B and B to C, the group A will be converted to B and not to C." -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/integration.pot b/documentation/src/main/docbook/pot/modules/integration.pot deleted file mode 100644 index c3fdb58759..0000000000 --- a/documentation/src/main/docbook/pot/modules/integration.pot +++ /dev/null @@ -1,346 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: integration.xml:24 -#, no-c-format -msgid "Integrating with other frameworks" -msgstr "" - -#. Tag: para -#: integration.xml:26 -#, no-c-format -msgid "Hibernate Validator is intended to be used to implement multi-layered data validation, where constraints are expressed in a single place (the annotated domain model) and checked in various different layers of the application." -msgstr "" - -#. Tag: title -#: integration.xml:32 -#, no-c-format -msgid "OSGi" -msgstr "" - -#. Tag: para -#: integration.xml:34 -#, no-c-format -msgid "The Hibernate Validator jar file is conform to the OSGi specification and can be used within any OSGi container. The following lists represent the packages imported and exported by Hibernate Validator. The classes within the exported packages are considered part of Hibernate Validator public API." -msgstr "" - -#. Tag: para -#: integration.xml:41 -#, no-c-format -msgid "The Java Service Provider mechanism used by Bean Validation to automatically discover validation providers doesn't work in an OSGi environment. To solve this, you have to provide a custom ValidationProviderResolver (see )." -msgstr "" - -#. Tag: title -#: integration.xml:49 -#, no-c-format -msgid "Exported packages" -msgstr "" - -#. Tag: package -#: integration.xml:52 -#, no-c-format -msgid "org.hibernate.validator" -msgstr "" - -#. Tag: package -#: integration.xml:56 -#, no-c-format -msgid "org.hibernate.validator.cfg.*" -msgstr "" - -#. Tag: package -#: integration.xml:60 -#, no-c-format -msgid "org.hibernate.validator.constraints.*" -msgstr "" - -#. Tag: package -#: integration.xml:64 -#, no-c-format -msgid "org.hibernate.validator.group" -msgstr "" - -#. Tag: package -#: integration.xml:68 -#, no-c-format -msgid "org.hibernate.validator.messageinterpolation" -msgstr "" - -#. Tag: package -#: integration.xml:72 -#, no-c-format -msgid "org.hibernate.validator.resourceloading" -msgstr "" - -#. Tag: package -#: integration.xml:76 -#, no-c-format -msgid "org.hibernate.validator.spi.*" -msgstr "" - -#. Tag: title -#: integration.xml:81 -#, no-c-format -msgid "Imported packages" -msgstr "" - -#. Tag: para -#: integration.xml:84 -#, no-c-format -msgid "javax.persistence.*, [2.0.0,3.0.0), optional" -msgstr "" - -#. Tag: para -#: integration.xml:89 -#, no-c-format -msgid "javax.validation.*, [1.0.0,2.0.0)" -msgstr "" - -#. Tag: package -#: integration.xml:93 -#, no-c-format -msgid "javax.xml.*" -msgstr "" - -#. Tag: para -#: integration.xml:97 -#, no-c-format -msgid "javax.el.*, [2.0.0,4.0.0)" -msgstr "" - -#. Tag: package -#: integration.xml:101 -#, no-c-format -msgid "org.xml.sax.*" -msgstr "" - -#. Tag: para -#: integration.xml:105 -#, no-c-format -msgid "org.jboss.logging.*, [3.1.0,4.0.0)" -msgstr "" - -#. Tag: para -#: integration.xml:109 -#, no-c-format -msgid "com.fasterxml.classmate.*, 0.8.0" -msgstr "" - -#. Tag: para -#: integration.xml:113 -#, no-c-format -msgid "org.joda.time.*, [1.6.0,2.0.0), optional" -msgstr "" - -#. Tag: para -#: integration.xml:118 -#, no-c-format -msgid "org.jsoup.*, [1.5.2,2.0.0), optional" -msgstr "" - -#. Tag: title -#: integration.xml:124 -#, no-c-format -msgid "Database schema-level validation" -msgstr "" - -#. Tag: para -#: integration.xml:126 -#, no-c-format -msgid "Out of the box, Hibernate Annotations (as of Hibernate 3.5.x) will translate the constraints you have defined for your entities into mapping metadata. For example, if a property of your entity is annotated @NotNull, its columns will be declared as not null in the DDL schema generated by Hibernate." -msgstr "" - -#. Tag: para -#: integration.xml:132 -#, no-c-format -msgid "If, for some reason, the feature needs to be disabled, set hibernate.validator.apply_to_ddl to false. See also and ." -msgstr "" - -#. Tag: para -#: integration.xml:138 -#, no-c-format -msgid "You can also limit the DDL constraint generation to a subset of the defined constraints by setting the property org.hibernate.validator.group.ddl. The property specifies the comma-separated, fully specified class names of the groups a constraint has to be part of in order to be considered for DDL schema generation." -msgstr "" - -#. Tag: title -#: integration.xml:147 -#, no-c-format -msgid "ORM integration" -msgstr "" - -#. Tag: para -#: integration.xml:149 -#, no-c-format -msgid "Hibernate Validator integrates with both Hibernate and all pure Java Persistence providers." -msgstr "" - -#. Tag: para -#: integration.xml:153 -#, no-c-format -msgid "When lazy loaded associations are supposed to be validated it is recommended to place the constraint on the getter of the association. Hibernate replaces lazy loaded associations with proxy instances which get initialized/loaded when requested via the getter. If, in such a case, the constraint is placed on field level the actual proxy instance is used which will lead to validation errors." -msgstr "" - -#. Tag: title -#: integration.xml:162 -#, no-c-format -msgid "Hibernate event-based validation" -msgstr "" - -#. Tag: para -#: integration.xml:164 -#, no-c-format -msgid "Hibernate Validator has a built-in Hibernate event listener - org.hibernate.cfg.beanvalidation.BeanValidationEventListener - which is part of Hibernate Annotations (as of Hibernate 3.5.x). Whenever a PreInsertEvent, PreUpdateEvent or PreDeleteEvent occurs, the listener will verify all constraints of the entity instance and throw an exception if any constraint is violated. Per default objects will be checked before any inserts or updates are made by Hibernate. Pre deletion events will per default not trigger a validation. You can configure the groups to be validated per event type using the properties javax.persistence.validation.group.pre-persist, javax.persistence.validation.group.pre-update and javax.persistence.validation.group.pre-remove. The values of these properties are the comma-separated, fully specified class names of the groups to validate. shows the default values for these properties. In this case they could also be omitted." -msgstr "" - -#. Tag: para -#: integration.xml:185 -#, no-c-format -msgid "On constraint violation, the event will raise a runtime ConstraintViolationException which contains a set of ConstraintViolations describing each failure." -msgstr "" - -#. Tag: para -#: integration.xml:190 -#, no-c-format -msgid "If Hibernate Validator is present in the classpath, Hibernate Annotations (or Hibernate EntityManager) will use it transparently. To avoid validation even though Hibernate Validator is in the classpath set javax.persistence.validation.mode to none." -msgstr "" - -#. Tag: para -#: integration.xml:197 -#, no-c-format -msgid "If the beans are not annotated with validation annotations, there is no runtime performance cost." -msgstr "" - -#. Tag: para -#: integration.xml:201 -#, no-c-format -msgid "In case you need to manually set the event listeners for Hibernate Core, use the following configuration in hibernate.cfg.xml:" -msgstr "" - -#. Tag: title -#: integration.xml:206 -#, no-c-format -msgid "Manual configuration of BeanValidationEvenListener" -msgstr "" - -#. Tag: programlisting -#: integration.xml:209 -#, no-c-format -msgid "" - "<hibernate-configuration>\n" - " <session-factory>\n" - " ...\n" - " <property name=\"javax.persistence.validation.group.pre-persist\">javax.validation.groups.Default</property>\n" - " <property name=\"javax.persistence.validation.group.pre-update\">javax.validation.groups.Default</property>\n" - " <property name=\"javax.persistence.validation.group.pre-remove\"></property>\n" - " ...\n" - " <event type=\"pre-update\">\n" - " <listener class=\"org.hibernate.cfg.beanvalidation.BeanValidationEventListener\"/>\n" - " </event>\n" - " <event type=\"pre-insert\">\n" - " <listener class=\"org.hibernate.cfg.beanvalidation.BeanValidationEventListener\"/>\n" - " </event>\n" - " <event type=\"pre-delete\">\n" - " <listener class=\"org.hibernate.cfg.beanvalidation.BeanValidationEventListener\"/>\n" - " </event>\n" - " </session-factory>\n" - "</hibernate-configuration>" -msgstr "" - -#. Tag: title -#: integration.xml:214 -#, no-c-format -msgid "JPA" -msgstr "" - -#. Tag: para -#: integration.xml:216 -#, no-c-format -msgid "If you are using JPA 2 and Hibernate Validator is in the classpath the JPA2 specification requires that Bean Validation gets enabled. The properties javax.persistence.validation.group.pre-persist, javax.persistence.validation.group.pre-update and javax.persistence.validation.group.pre-remove as described in can in this case be configured in persistence.xml. persistence.xml also defines a node validation-mode which can be set to AUTO, CALLBACK, NONE. The default is AUTO." -msgstr "" - -#. Tag: para -#: integration.xml:230 -#, no-c-format -msgid "In a JPA 1 you will have to create and register Hibernate Validator yourself. In case you are using Hibernate EntityManager you can add a customized version of the BeanValidationEventListener described in to your project and register it manually." -msgstr "" - -#. Tag: title -#: integration.xml:240 -#, no-c-format -msgid "Presentation layer validation" -msgstr "" - -#. Tag: para -#: integration.xml:242 -#, no-c-format -msgid "When working with JSF2 or JBoss Seam and Hibernate Validator (Bean Validation) is present in the runtime environment validation is triggered for every field in the application. shows an example of the f:validateBean tag in a JSF page. For more information refer to the Seam documentation or the JSF 2 specification." -msgstr "" - -#. Tag: title -#: integration.xml:250 -#, no-c-format -msgid "Usage of Bean Validation within JSF2" -msgstr "" - -#. Tag: programlisting -#: integration.xml:252 -#, no-c-format -msgid "" - "<h:form>\n" - " <f:validateBean>\n" - " <h:inputText value=”#{model.property}” />\n" - " <h:selectOneRadio value=”#{model.radioProperty}” > ... </h:selectOneRadio>\n" - " <!-- other input components here -->\n" - " </f:validateBean>\n" - "</h:form>" -msgstr "" - -#. Tag: para -#: integration.xml:256 -#, no-c-format -msgid "The integration between JSF 2 and Bean Validation is described in the \"Bean Validation Integration\" chapter of JSR-314. It is interesting to know that JSF 2 implements a custom MessageInterpolator to ensure ensure proper localization. To encourage the use of the Bean Validation message facility, JSF 2 will per default only display the generated Bean Validation message. This can, however, be configured via the application resource bundle by providing the following configuration ({0} is replaced with the Bean Validation message and {1} is replaced with the JSF component label):" -msgstr "" - -#. Tag: programlisting -#: integration.xml:268 -#, no-c-format -msgid "javax.faces.validator.BeanValidator.MESSAGE={1}: {0}" -msgstr "" - -#. Tag: para -#: integration.xml:270 -#, no-c-format -msgid "The default is:" -msgstr "" - -#. Tag: programlisting -#: integration.xml:272 -#, no-c-format -msgid "javax.faces.validator.BeanValidator.MESSAGE={0}" -msgstr "" - -#. Tag: title -#: integration.xml:277 -#, no-c-format -msgid "CDI" -msgstr "" - -#. Tag: para -#: integration.xml:279 -#, no-c-format -msgid "TODO" -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/message-interpolation.pot b/documentation/src/main/docbook/pot/modules/message-interpolation.pot deleted file mode 100644 index bed5dbfe83..0000000000 --- a/documentation/src/main/docbook/pot/modules/message-interpolation.pot +++ /dev/null @@ -1,423 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: message-interpolation.xml:24 -#, no-c-format -msgid "Message interpolation" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:26 -#, no-c-format -msgid "Message interpolation is the process of creating error messages for violated Bean Validation constraints. In this chapter you will learn how such messages are defined and resolved and how you can plug in custom message interpolators in case the default algorithm is not sufficient for your requirements." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:33 -#, no-c-format -msgid "Default message interpolation" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:35 -#, no-c-format -msgid "Constraint violation messages are retrieved from so called message descriptors. Each constraint defines its default message descriptor using the message attribute. At declaration time, the default descriptor can be overridden with a specific value as shown in ." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:42 -#, no-c-format -msgid "Specifying a message descriptor using the message attribute" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:45 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter04;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull(message = \"The manufacturer name must not be null\")\n" - " private String manufacturer;\n" - "\n" - " //constructor, getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:48 -#, no-c-format -msgid "If a constraint is violated, its descriptor will be interpolated by the runtime using the currently configured MessageInterpolator. The interpolated error message can then be retrieved from the resulting constraint violation by calling ConstraintViolation#getMessage()." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:54 -#, no-c-format -msgid "Message descriptors can contain message parameters as well as message expressions which will be resolved during interpolation. Message parameters are string literals enclosed in {}, while message expressions are string literals enclosed in ${}. The following algorithm is applied during method interpolation:" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:63 -#, no-c-format -msgid "Resolve any message parameters by using them as key for the resource bundle ValidationMessages. If this bundle contains an entry for a given message parameter, that parameter will be replaced in the message with the corresponding value from the bundle. This step will be executed recursively if the replaced value again contains message parameters. The resource bundle is expected to be provided by the application developer, e.g. by adding a file named ValidationMessages.properties to the classpath. You can also create localized error messages by providing locale specific variations of this bundle, such as ValidationMessages_en_US.properties. By default, the JVM's default locale (Locale#getDefault()) will be used when looking up messages in the bundle." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:80 -#, no-c-format -msgid "Resolve any message parameters by using them as key for a resource bundle containing the standard error messages for the built-in constraints as defined in Appendix B of the Bean Validation specification. In the case of Hibernate Validator, this bundle is named org.hibernate.validator.ValidationMessages. If this step triggers a replacement, step 1 is executed again, otherwise step 3 is applied." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:91 -#, no-c-format -msgid "Resolve any message parameters by replacing them with the value of the constraint annotation member of the same name. This allows to refer to attribute values of the constraint (e.g. Size#min()) in the error message (e.g. \"must be at least ${min}\")." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:99 -#, no-c-format -msgid "Resolve any message expressions by evaluating them as expressions of the Unified Expression Language. See to learn more about the usage of Unified EL in error messages." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:107 -#, no-c-format -msgid "You can find the formal definition of the interpolation algorithm in section 5.3.1.1 of the Bean Validation specification." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:114 -#, no-c-format -msgid "Special characters" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:116 -#, no-c-format -msgid "Since the characters {, } and $ have a special meaning in message descriptors they need to be escaped if you want to use them literally. The following rules apply:" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:121 -#, no-c-format -msgid "\\{ is considered as the literal {" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:126 -#, no-c-format -msgid "\\} is considered as the literal }" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:131 -#, no-c-format -msgid "\\$ is considered as the literal $" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:136 -#, no-c-format -msgid "\\\\ is considered as the literal \\" -msgstr "" - -#. Tag: title -#: message-interpolation.xml:143 -#, no-c-format -msgid "Interpolation with message expressions" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:145 -#, no-c-format -msgid "Since Bean Validation 1.1 / Hibernate Validator 5 it is possible to use the Unified Expression Language (as defined by JSR 341) in constraint violation messages. This allows to define error messages based on conditional logic and also enables advanced formatting options. The validation engine makes the following objects available in the EL context:" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:155 -#, no-c-format -msgid "the attribute values of the constraint mapped to the attribute names" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:160 -#, no-c-format -msgid "the currently validated value (property, bean, method parameter etc.) under the name validatedValue" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:166 -#, no-c-format -msgid "a bean mapped to the name formatter exposing the var-arg method format(String format, Object... args) which behaves like java.util.Formatter.format(String format, Object... args)." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:174 -#, no-c-format -msgid "The following section provides several examples for using EL expressions in error messages." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:179 -#, no-c-format -msgid "Examples" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:181 -#, no-c-format -msgid "shows how to make use of the different options for specifying message descriptors." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:185 -#, no-c-format -msgid "Specifying message descriptors" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:187 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter04.complete;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @Size(\n" - " min = 2,\n" - " max = 14,\n" - " message = \"The license plate must be between {min} and {max} characters long\"\n" - " )\n" - " private String licensePlate;\n" - "\n" - " @Min(\n" - " value = 2,\n" - " message = \"There must be at least {value} seat${value > 1 ? 's' : ''}\"\n" - " )\n" - " private int seatCount;\n" - "\n" - " @DecimalMax(\n" - " value = \"350\",\n" - " message = \"The top speed ${formatter.format('%1$.2f', validatedValue)} is higher \" +\n" - " \"than {value}\"\n" - " )\n" - " private double topSpeed;\n" - "\n" - " @DecimalMax(value = \"100000\", message = \"Price must not be higher than ${value}\")\n" - " private BigDecimal price;\n" - "\n" - " public Car(\n" - " String manufacturer,\n" - " String licensePlate,\n" - " int seatCount,\n" - " double topSpeed,\n" - " BigDecimal price) {\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licensePlate;\n" - " this.seatCount = seatCount;\n" - " this.topSpeed = topSpeed;\n" - " this.price = price;\n" - " }\n" - "\n" - " //getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:190 -#, no-c-format -msgid "Validating an invalid Car instance yields constraint violations with the messages shown by the assertions in :" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:196 -#, no-c-format -msgid "the @NotNull constraint on the manufacturer field causes the error message \"may not be null\", as this is the default message defined by the Bean Validation specification and no specific descriptor is given in the message attribute" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:204 -#, no-c-format -msgid "the @Size constraint on the licensePlate field shows the interpolation of message parameters ({min}, {max})" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:211 -#, no-c-format -msgid "the @Min constraint on seatCount demonstrates how use an EL expression with a ternery expression to dynamically chose singular or plural form, depending on an attribute of the constraint (\"There must be at least 1 seat\" vs. \"There must be at least 2 seats\")" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:219 -#, no-c-format -msgid "the message for the @DecimalMax constraint on topSpeed shows how to refer to the validated object in the error message and format it using the formatter object" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:226 -#, no-c-format -msgid "finally, the @DecimalMax constraint on price shows that parameter interpolation has precedence over expression evaluation, causing the $ sign to show up in front of the maximum price" -msgstr "" - -#. Tag: title -#: message-interpolation.xml:235 -#, no-c-format -msgid "Expected error messages" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:237 -#, no-c-format -msgid "" - "Car car = new Car( null, \"A\", 1, 400.123456, BigDecimal.valueOf( 200000 ) );\n" - "\n" - "String message = validator.validateProperty( car, \"manufacturer\" )\n" - " .iterator()\n" - " .next()\n" - " .getMessage();\n" - "assertEquals( \"may not be null\", message );\n" - "\n" - "message = validator.validateProperty( car, \"licensePlate\" )\n" - " .iterator()\n" - " .next()\n" - " .getMessage();\n" - "assertEquals(\n" - " \"The license plate must be between 2 and 14 characters long\",\n" - " message\n" - ");\n" - "\n" - "message = validator.validateProperty( car, \"seatCount\" ).iterator().next().getMessage();\n" - "assertEquals( \"There must be at least 2 seats\", message );\n" - "\n" - "message = validator.validateProperty( car, \"topSpeed\" ).iterator().next().getMessage();\n" - "assertEquals( \"The top speed 400.12 is higher than 350\", message );\n" - "\n" - "message = validator.validateProperty( car, \"price\" ).iterator().next().getMessage();\n" - "assertEquals( \"Price must not be higher than $100000\", message );" -msgstr "" - -#. Tag: title -#: message-interpolation.xml:243 -#, no-c-format -msgid "Custom message interpolation" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:245 -#, no-c-format -msgid "If the default message interpolation algorithm does not fit your requirements it is also possible to plug in a custom MessageInterpolator implementation." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:249 -#, no-c-format -msgid "Custom interpolators must implement the interface javax.validation.MessageInterpolator. Note that implementations must be thread-safe. It is recommended that custom message interpolators delegate final implementation to the runtime's default interpolator, which can be obtained via Configuration#getDefaultMessageInterpolator()." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:256 -#, no-c-format -msgid "In order to use a custom message interpolator it must be registered with the validation runtime. You can do this by either configuring it in the Bean Validation XML descriptor META-INF/validation.xml (see ) or passing it when bootstrapping a ValidatorFactory or Validator (see and , respectively)." -msgstr "" - -#. Tag: classname -#: message-interpolation.xml:267 -#, no-c-format -msgid "ResourceBundleLocator" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:269 -#, no-c-format -msgid "It is a common case that you want to use the message interpolation algorithm as defined by the Bean Validation specification but retrieve error messages from other resource bundles than ValidationMessages. In this situation Hibernate Validator's ResourceBundleLocator SPI can help." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:276 -#, no-c-format -msgid "The default message interpolator in Hibernate Validator, ResourceBundleMessageInterpolator, delegates retrieval of resource bundles to that SPI. Using an alternative bundle only requires passing an instance of PlatformResourceBundleLocator with the bundle name when bootstrapping the ValidatorFactory as shown in ." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:286 -#, no-c-format -msgid "Using a specific resource bundle" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:288 -#, no-c-format -msgid "" - "Validator validator = Validation.byDefaultProvider()\n" - " .configure()\n" - " .messageInterpolator(\n" - " new ResourceBundleMessageInterpolator(\n" - " new PlatformResourceBundleLocator( \"MyMessages\" )\n" - " )\n" - " )\n" - " .buildValidatorFactory()\n" - " .getValidator();" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:291 -#, no-c-format -msgid "Of course you also could implement a completely different ResourceBundleLocator, which for instance returns bundles backed by records in a database. In this case you can obtain the default locator via HibernateValidatorConfiguration#getDefaultResourceBundleLocator(), which you e.g. could use as fallback for your custom locator." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:298 -#, no-c-format -msgid "Besides PlatformResourceBundleLocator, Hibernate Validator provides another resource bundle locator implementation out of the box, namely AggregateResourceBundleLocator, which allows to retrieve error messages from more than one resource bundle. You could for instance use this implementation in a multi-module application where you want to have one message bundle per module. shows how to use AggregateResourceBundleLocator." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:309 -#, no-c-format -msgid "Using AggregateResourceBundleLocator" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:312 -#, no-c-format -msgid "" - "Validator validator = Validation.byDefaultProvider()\n" - " .configure()\n" - " .messageInterpolator(\n" - " new ResourceBundleMessageInterpolator(\n" - " new AggregateResourceBundleLocator(\n" - " Arrays.asList(\n" - " \"MyMessages\",\n" - " \"MyOtherMessages\"\n" - " )\n" - " )\n" - " )\n" - " )\n" - " .buildValidatorFactory()\n" - " .getValidator();" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:315 -#, no-c-format -msgid "Note that the bundles are processed in the order as passed to the constructor. That means if several bundles contain an entry for a given message key, the value will be taken from the first bundle in the list containing the key." -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/metadata-api.pot b/documentation/src/main/docbook/pot/modules/metadata-api.pot deleted file mode 100644 index 3df8c6f3de..0000000000 --- a/documentation/src/main/docbook/pot/modules/metadata-api.pot +++ /dev/null @@ -1,713 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: metadata-api.xml:24 -#, no-c-format -msgid "Metadata API" -msgstr "" - -#. Tag: para -#: metadata-api.xml:26 -#, no-c-format -msgid "The Bean Validation specification provides not only a validation engine, but also an API for retrieving constraint metadata in a uniform way, no matter whether the constraints are declared using annotations or via XML mappings. We'll have a closer look at this API and its possibilities in the following sections. All the introduced API types can be found in the javax.validation.metadata package." -msgstr "" - -#. Tag: para -#: metadata-api.xml:33 -#, no-c-format -msgid "The examples presented in this chapter are based on the classes and constraint declarations shown in ." -msgstr "" - -#. Tag: title -#: metadata-api.xml:38 -#, no-c-format -msgid "Example classes" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:40 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter07;\n" - "\n" - "public class Person {\n" - "\n" - " public interface Basic {\n" - " }\n" - "\n" - " @NotNull\n" - " private String name;\n" - "\n" - " //getters and setters ...\n" - "}" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:42 -#, no-c-format -msgid "" - "public interface Vehicle {\n" - "\n" - " public interface Basic {\n" - " }\n" - "\n" - " @NotNull(groups = Vehicle.Basic.class)\n" - " String getManufacturer();\n" - "}" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:44 -#, no-c-format -msgid "" - "@ValidCar\n" - "public class Car implements Vehicle {\n" - "\n" - " public interface SeverityInfo extends Payload {\n" - " }\n" - "\n" - " private String manufacturer;\n" - "\n" - " @NotNull\n" - " @Size(min = 2, max = 14)\n" - " private String licensePlate;\n" - "\n" - " private Person driver;\n" - "\n" - " private String modelName;\n" - "\n" - " public Car() {\n" - " }\n" - "\n" - " public Car(\n" - " @NotNull String manufacturer,\n" - " String licencePlate,\n" - " Person driver,\n" - " String modelName) {\n" - "\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licencePlate;\n" - " this.driver = driver;\n" - " this.modelName = modelName;\n" - " }\n" - "\n" - " public void driveAway(@Max(75) int speed) {\n" - " //...\n" - " }\n" - "\n" - " @LuggageCountMatchesPassengerCount(\n" - " piecesOfLuggagePerPassenger = 2,\n" - " validationAppliesTo = ConstraintTarget.PARAMETERS,\n" - " payload = SeverityInfo.class,\n" - " message = \"There must not be more than {piecesOfLuggagePerPassenger} pieces of \" +\n" - " \"luggage per passenger.\"\n" - " )\n" - " public void load(List<Person> passengers, List<PieceOfLuggage> luggage) {\n" - " //...\n" - " }\n" - "\n" - " @Override\n" - " @Size(min = 3)\n" - " public String getManufacturer() {\n" - " return manufacturer;\n" - " }\n" - "\n" - " public void setManufacturer(String manufacturer) {\n" - " this.manufacturer = manufacturer;\n" - " }\n" - "\n" - " @Valid\n" - " @ConvertGroup(from = Default.class, to = Person.Basic.class)\n" - " public Person getDriver() {\n" - " return driver;\n" - " }\n" - "\n" - " //further getters and setters...\n" - "}" -msgstr "" - -#. Tag: classname -#: metadata-api.xml:49 -#, no-c-format -msgid "BeanDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:51 -#, no-c-format -msgid "The entry point into the metadata API is the method Validator.getConstraintsForClass(), which returns an instance of the BeanDescriptor interface. Using this descriptor, you can obtain metadata for constraints declared directly on the bean itself (class- or property-level), but also retrieve metadata descriptors representing single properties, methods and constructors." -msgstr "" - -#. Tag: para -#: metadata-api.xml:60 -#, no-c-format -msgid "demonstrates how to retrieve a BeanDescriptor for the Car class and how to use this descriptor in form of assertions." -msgstr "" - -#. Tag: para -#: metadata-api.xml:66 -#, no-c-format -msgid "If a constraint declaration hosted by the requested class is invalid, a ValidationException is thrown." -msgstr "" - -#. Tag: title -#: metadata-api.xml:72 -#, no-c-format -msgid "Using BeanDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:74 -#, no-c-format -msgid "" - "Validator validator = Validation.buildDefaultValidatorFactory().getValidator();\n" - "\n" - "BeanDescriptor carDescriptor = validator.getConstraintsForClass( Car.class );\n" - "\n" - "assertTrue( carDescriptor.isBeanConstrained() );\n" - "\n" - "//one class-level constraint\n" - "assertEquals( 1, carDescriptor.getConstraintDescriptors().size() );\n" - "\n" - "//manufacturer, licensePlate, driver\n" - "assertEquals( 3, carDescriptor.getConstrainedProperties().size() );\n" - "\n" - "//property has constraint\n" - "assertNotNull( carDescriptor.getConstraintsForProperty( \"licensePlate\" ) );\n" - "\n" - "//property is marked with @Valid\n" - "assertNotNull( carDescriptor.getConstraintsForProperty( \"driver\" ) );\n" - "\n" - "//constraints from getter method in interface and implementation class are returned\n" - "assertEquals(\n" - " 2,\n" - " carDescriptor.getConstraintsForProperty( \"manufacturer\" )\n" - " .getConstraintDescriptors()\n" - " .size()\n" - ");\n" - "\n" - "//property is not constrained\n" - "assertNull( carDescriptor.getConstraintsForProperty( \"modelName\" ) );\n" - "\n" - "//driveAway(int), load(List<Person>, List<PieceOfLuggage>)\n" - "assertEquals( 2, carDescriptor.getConstrainedMethods( MethodType.NON_GETTER ).size() );\n" - "\n" - "//driveAway(int), getManufacturer(), getDriver(), load(List<Person>, List<PieceOfLuggage>)\n" - "assertEquals(\n" - " 4,\n" - " carDescriptor.getConstrainedMethods( MethodType.NON_GETTER, MethodType.GETTER )\n" - " .size()\n" - ");\n" - "\n" - "//driveAway(int)\n" - "assertNotNull( carDescriptor.getConstraintsForMethod( \"driveAway\", int.class ) );\n" - "\n" - "//getManufacturer()\n" - "assertNotNull( carDescriptor.getConstraintsForMethod( \"getManufacturer\" ) );\n" - "\n" - "//setManufacturer() is not constrained\n" - "assertNull( carDescriptor.getConstraintsForMethod( \"setManufacturer\", String.class ) );\n" - "\n" - "//Car(String, String, Person, String)\n" - "assertEquals( 1, carDescriptor.getConstrainedConstructors().size() );\n" - "\n" - "//Car(String, String, Person, String)\n" - "assertNotNull(\n" - " carDescriptor.getConstraintsForConstructor(\n" - " String.class,\n" - " String.class,\n" - " Person.class,\n" - " String.class\n" - " )\n" - ");" -msgstr "" - -#. Tag: para -#: metadata-api.xml:77 -#, no-c-format -msgid "You can determine whether the specified class hosts any class- or property-level constraints via isBeanConstrained(). Method or constructor constraints are not considered by isBeanConstrained()." -msgstr "" - -#. Tag: para -#: metadata-api.xml:82 -#, no-c-format -msgid "The method getConstraintDescriptors() is common to all descriptors derived from ElementDescriptor (see ) and returns a set of descriptors representing the constraints directly declared on the given element. In case of BeanDescriptor, the bean's class-level constraints are returned. More details on ConstraintDescriptor can be found in ." -msgstr "" - -#. Tag: para -#: metadata-api.xml:91 -#, no-c-format -msgid "Via getConstraintsForProperty(), getConstraintsForMethod() and getConstraintsForConstructor() you can obtain a descriptor representing one given property or executable element, identified by its name and, in case of methods and constructors, parameter types. The different descriptor types returned by these methods are described in the following sections." -msgstr "" - -#. Tag: para -#: metadata-api.xml:99 -#, no-c-format -msgid "Note that these methods consider constraints declared at super-types according to the rules for constraint inheritance as described in TODO. An example is the descriptor for the manufacturer property, which provides access to all constraints defined on Vehicle#getManufacturer() and the implementing method Car#getManufacturer(). null is returned in case the specified element does not exist or is not constrained." -msgstr "" - -#. Tag: para -#: metadata-api.xml:108 -#, no-c-format -msgid "The methods getConstrainedProperties(), getConstrainedMethods() and getConstrainedConstructors() return (potentially empty) sets with all constrained properties, methods and constructors, respectively. An element is considered constrained, if it has at least one constraint or is marked for cascaded validation. When invoking getConstrainedMethods(), you can specify the type of the methods to be returned (getters, non-getters or both)." -msgstr "" - -#. Tag: classname -#: metadata-api.xml:119 -#, no-c-format -msgid "PropertyDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:121 -#, no-c-format -msgid "The interface PropertyDescriptor represents one given property of a class. It is transparent whether constraints are declared on a field or a property getter, provided the JavaBeans naming conventions are respected. shows how to use the PropertyDescriptor interface." -msgstr "" - -#. Tag: title -#: metadata-api.xml:130 -#, no-c-format -msgid "Using PropertyDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:132 -#, no-c-format -msgid "" - "PropertyDescriptor licensePlateDescriptor = carDescriptor.getConstraintsForProperty(\n" - " \"licensePlate\"\n" - ");\n" - "\n" - "//\"licensePlate\" has two constraints, is not marked with @Valid and defines no group conversions\n" - "assertEquals( \"licensePlate\", licensePlateDescriptor.getPropertyName() );\n" - "assertEquals( 2, licensePlateDescriptor.getConstraintDescriptors().size() );\n" - "assertTrue( licensePlateDescriptor.hasConstraints() );\n" - "assertFalse( licensePlateDescriptor.isCascaded() );\n" - "assertTrue( licensePlateDescriptor.getGroupConversions().isEmpty() );\n" - "\n" - "PropertyDescriptor driverDescriptor = carDescriptor.getConstraintsForProperty( \"driver\" );\n" - "\n" - "//\"driver\" has no constraints, is marked with @Valid and defines one group conversion\n" - "assertEquals( \"driver\", driverDescriptor.getPropertyName() );\n" - "assertTrue( driverDescriptor.getConstraintDescriptors().isEmpty() );\n" - "assertFalse( driverDescriptor.hasConstraints() );\n" - "assertTrue( driverDescriptor.isCascaded() );\n" - "assertEquals( 1, driverDescriptor.getGroupConversions().size() );" -msgstr "" - -#. Tag: para -#: metadata-api.xml:135 -#, no-c-format -msgid "Using getConstrainedDescriptors(), you can retrieve a set of ConstraintDescriptors providing more information on the individual constraints of a given property. The method isCascaded() returns true, if the property is marked for cascaded validation (either using the @Valid annotation or via XML), false otherwise. Any configured group conversions are returned by getGroupConversions(). See for more details on GroupConversionDescriptor." -msgstr "" - -#. Tag: title -#: metadata-api.xml:148 -#, no-c-format -msgid "MethodDescriptor and ConstructorDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:150 -#, no-c-format -msgid "Constrained methods and constructors (together referred to as \"executables\" in the following) are represented by the interfaces MethodDescriptor and ConstructorDescriptor, respectively. demonstrates how to work with these descriptors." -msgstr "" - -#. Tag: title -#: metadata-api.xml:160 -#, no-c-format -msgid "Using MethodDescriptor and ConstructorDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:163 -#, no-c-format -msgid "" - "//driveAway(int) has a constrained parameter and an unconstrained return value\n" - "MethodDescriptor driveAwayDescriptor = carDescriptor.getConstraintsForMethod(\n" - " \"driveAway\",\n" - " int.class\n" - ");\n" - "assertEquals( \"driveAway\", driveAwayDescriptor.getName() );\n" - "assertTrue( driveAwayDescriptor.hasConstrainedParameters() );\n" - "assertFalse( driveAwayDescriptor.hasConstrainedReturnValue() );\n" - "\n" - "//always returns an empty set; constraints are retrievable by navigating to\n" - "//one of the sub-descriptors, e.g. for the return value\n" - "assertTrue( driveAwayDescriptor.getConstraintDescriptors().isEmpty() );\n" - "\n" - "ParameterDescriptor speedDescriptor = driveAwayDescriptor.getParameterDescriptors()\n" - " .get( 0 );\n" - "\n" - "//The \"speed\" parameter is located at index 0, has one constraint and is not cascaded\n" - "//nor does it define group conversions\n" - "assertEquals( \"arg0\", speedDescriptor.getName() );\n" - "assertEquals( 0, speedDescriptor.getIndex() );\n" - "assertEquals( 1, speedDescriptor.getConstraintDescriptors().size() );\n" - "assertFalse( speedDescriptor.isCascaded() );\n" - "assert speedDescriptor.getGroupConversions().isEmpty();\n" - "\n" - "//getDriver() has no constrained parameters but its return value is marked for cascaded\n" - "//validation and declares one group conversion\n" - "MethodDescriptor getDriverDescriptor = carDescriptor.getConstraintsForMethod(\n" - " \"getDriver\"\n" - ");\n" - "assertFalse( getDriverDescriptor.hasConstrainedParameters() );\n" - "assertTrue( getDriverDescriptor.hasConstrainedReturnValue() );\n" - "\n" - "ReturnValueDescriptor returnValueDescriptor = getDriverDescriptor.getReturnValueDescriptor();\n" - "assertTrue( returnValueDescriptor.getConstraintDescriptors().isEmpty() );\n" - "assertTrue( returnValueDescriptor.isCascaded() );\n" - "assertEquals( 1, returnValueDescriptor.getGroupConversions().size() );\n" - "\n" - "//load(List<Person>, List<PieceOfLuggage>) has one cross-parameter constraint\n" - "MethodDescriptor loadDescriptor = carDescriptor.getConstraintsForMethod(\n" - " \"load\",\n" - " List.class,\n" - " List.class\n" - ");\n" - "assertTrue( loadDescriptor.hasConstrainedParameters() );\n" - "assertFalse( loadDescriptor.hasConstrainedReturnValue() );\n" - "assertEquals(\n" - " 1,\n" - " loadDescriptor.getCrossParameterDescriptor().getConstraintDescriptors().size()\n" - ");\n" - "\n" - "//Car(String, String, Person, String) has one constrained parameter\n" - "ConstructorDescriptor constructorDescriptor = carDescriptor.getConstraintsForConstructor(\n" - " String.class,\n" - " String.class,\n" - " Person.class,\n" - " String.class\n" - ");\n" - "\n" - "assertEquals( \"Car\", constructorDescriptor.getName() );\n" - "assertFalse( constructorDescriptor.hasConstrainedReturnValue() );\n" - "assertTrue( constructorDescriptor.hasConstrainedParameters() );\n" - "assertEquals(\n" - " 1,\n" - " constructorDescriptor.getParameterDescriptors()\n" - " .get( 0 )\n" - " .getConstraintDescriptors()\n" - " .size()\n" - ");" -msgstr "" - -#. Tag: para -#: metadata-api.xml:166 -#, no-c-format -msgid "getName() returns the name of the given method or constructor. The methods hasConstrainedParameters() and hasConstrainedReturnValue() can be used to perform a quick check whether an executable element has any parameter constraints (either constraints on single parameters or cross-parameter constraints) or return value constraints." -msgstr "" - -#. Tag: para -#: metadata-api.xml:174 -#, no-c-format -msgid "Note that any constraints are not directly exposed on MethodDescriptor and ConstructorDescriptor, but rather on dedicated descriptors representing an executable's parameters, its return value and its cross-parameter constraints. To get hold of one of these descriptors, invoke getParameterDescriptors(), getReturnValueDescriptor() or getCrossParameterDescriptor(), respectively." -msgstr "" - -#. Tag: para -#: metadata-api.xml:184 -#, no-c-format -msgid "These descriptors provide access to the element's constraints (getConstraintDescriptors()) and, in case of parameters and return value, to its configuration for cascaded validation (isValid() and getGroupConversions()). For parameters, you also can retrieve the index and the name, as returned by the currently used parameter name provider (see TODO) via getName() and getIndex()." -msgstr "" - -#. Tag: para -#: metadata-api.xml:194 -#, no-c-format -msgid "Getter methods following the JavaBeans naming conventions are considered as bean properties but also as constrained methods." -msgstr "" - -#. Tag: para -#: metadata-api.xml:197 -#, no-c-format -msgid "That means you can retrieve the related metadata either by obtaining a PropertyDescriptor (e.g. BeanDescriptor.getConstraintsForProperty(\"foo\")) or by examining the return value descriptor of the getter's MethodDescriptor (e.g. BeanDescriptor.getConstraintsForMethod(\"getFoo\").getReturnValueDescriptor())." -msgstr "" - -#. Tag: classname -#: metadata-api.xml:207 -#, no-c-format -msgid "ElementDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:209 -#, no-c-format -msgid "The ElementDiscriptor interface is the common base class for the individual descriptor types such as BeanDescriptor, PropertyDescriptor etc. Besides getConstraintDescriptors() it provides some more methods common to all descriptors." -msgstr "" - -#. Tag: para -#: metadata-api.xml:217 -#, no-c-format -msgid "hasConstraints() allows for a quick check whether an element has any direct constraints (e.g. class-level constraints in case of BeanDescriptor). getElementClass() returns the Java type of the element represented by a given descriptor. More specifically, the method returns" -msgstr "" - -#. Tag: para -#: metadata-api.xml:226 -#, no-c-format -msgid "the object type when invoked on BeanDescriptor," -msgstr "" - -#. Tag: para -#: metadata-api.xml:231 -#, no-c-format -msgid "the type of a property or parameter when invoked on PropertyDescriptor or ParameterDescriptor respectively," -msgstr "" - -#. Tag: para -#: metadata-api.xml:237 -#, no-c-format -msgid "Object[].class when invoked on CrossParameterDescriptor," -msgstr "" - -#. Tag: para -#: metadata-api.xml:242 -#, no-c-format -msgid "the return type when invoked on ConstructorDescriptor, MethodDescriptor or ReturnValueDescriptor. void.class will be returned for methods which don't have a return value." -msgstr "" - -#. Tag: para -#: metadata-api.xml:251 -#, no-c-format -msgid "shows how these methods are used." -msgstr "" - -#. Tag: title -#: metadata-api.xml:255 -#, no-c-format -msgid "Using ElementDescriptor methods" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:257 -#, no-c-format -msgid "" - "PropertyDescriptor manufacturerDescriptor = carDescriptor.getConstraintsForProperty(\n" - " \"manufacturer\"\n" - ");\n" - "\n" - "assertTrue( manufacturerDescriptor.hasConstraints() );\n" - "assertEquals( String.class, manufacturerDescriptor.getElementClass() );\n" - "\n" - "CrossParameterDescriptor loadCrossParameterDescriptor = carDescriptor.getConstraintsForMethod(\n" - " \"load\",\n" - " List.class,\n" - " List.class\n" - ").getCrossParameterDescriptor();\n" - "\n" - "assertTrue( loadCrossParameterDescriptor.hasConstraints() );\n" - "assertEquals( Object[].class, loadCrossParameterDescriptor.getElementClass() );" -msgstr "" - -#. Tag: para -#: metadata-api.xml:260 -#, no-c-format -msgid "Finally, ElementDescriptor offers access to the ConstraintFinder API which allows you to query for constraint metadata in a fine grained way. shows how to retrieve a ConstraintFinder instance via findConstraints() and use the API to query for constraint metadata." -msgstr "" - -#. Tag: title -#: metadata-api.xml:269 -#, no-c-format -msgid "Usage of ConstraintFinder" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:271 -#, no-c-format -msgid "" - "PropertyDescriptor manufacturerDescriptor = carDescriptor.getConstraintsForProperty(\n" - " \"manufacturer\"\n" - ");\n" - "\n" - "//\"manufacturer\" constraints are declared on the getter, not the field\n" - "assertTrue(\n" - " manufacturerDescriptor.findConstraints()\n" - " .declaredOn( ElementType.FIELD )\n" - " .getConstraintDescriptors()\n" - " .isEmpty()\n" - ");\n" - "\n" - "//@NotNull on Vehicle#getManufacturer() is part of another group\n" - "assertEquals(\n" - " 1,\n" - " manufacturerDescriptor.findConstraints()\n" - " .unorderedAndMatchingGroups( Default.class )\n" - " .getConstraintDescriptors()\n" - " .size()\n" - ");\n" - "\n" - "//@Size on Car#getManufacturer()\n" - "assertEquals(\n" - " 1,\n" - " manufacturerDescriptor.findConstraints()\n" - " .lookingAt( Scope.LOCAL_ELEMENT )\n" - " .getConstraintDescriptors()\n" - " .size()\n" - ");\n" - "\n" - "//@Size on Car#getManufacturer() and @NotNull on Vehicle#getManufacturer()\n" - "assertEquals(\n" - " 2,\n" - " manufacturerDescriptor.findConstraints()\n" - " .lookingAt( Scope.HIERARCHY )\n" - " .getConstraintDescriptors()\n" - " .size()\n" - ");\n" - "\n" - "//Combining several filter options\n" - "assertEquals(\n" - " 1,\n" - " manufacturerDescriptor.findConstraints()\n" - " .declaredOn( ElementType.METHOD )\n" - " .lookingAt( Scope.HIERARCHY )\n" - " .unorderedAndMatchingGroups( Vehicle.Basic.class )\n" - " .getConstraintDescriptors()\n" - " .size()\n" - ");" -msgstr "" - -#. Tag: para -#: metadata-api.xml:274 -#, no-c-format -msgid "Via declaredOn(), the API allows to return only ConstraintDescriptors declared on certain element types. This is useful to search for property constraints declared on either fields or getter methods." -msgstr "" - -#. Tag: para -#: metadata-api.xml:279 -#, no-c-format -msgid "unorderedAndMatchingGroups() restricts the resulting constraints to those matching the given validation group(s)." -msgstr "" - -#. Tag: para -#: metadata-api.xml:283 -#, no-c-format -msgid "lookingAt() allows to distinguish between constraints directly specified on the element (Scope.LOCAL_ELEMENT) or constraints belonging to the element but hosted anywhere in the class hierarchy (Scope.HIERARCHY)." -msgstr "" - -#. Tag: para -#: metadata-api.xml:289 -#, no-c-format -msgid "The different options also can be combined as shown in the last example." -msgstr "" - -#. Tag: para -#: metadata-api.xml:293 -#, no-c-format -msgid "Order is not respected by unorderedAndMatchingGroups(), but group inheritance and inheritance via sequence are." -msgstr "" - -#. Tag: classname -#: metadata-api.xml:300 -#, no-c-format -msgid "GroupConversionDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:302 -#, no-c-format -msgid "All those descriptor types that represent elements which can be subject of cascaded validation (i.e., PropertyDescriptor, ParameterDescriptor and ReturnValueDescriptor) provide access to the element's group conversions via getGroupConversions(). The returned set contains a GroupConversionDescriptor for each configured conversion, allowing to retrieve source and target groups of the conversion. shows an example." -msgstr "" - -#. Tag: title -#: metadata-api.xml:317 -#, no-c-format -msgid "Using GroupConversionDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:319 -#, no-c-format -msgid "" - "PropertyDescriptor driverDescriptor = carDescriptor.getConstraintsForProperty( \"driver\" );\n" - "\n" - "Set<GroupConversionDescriptor> groupConversions = driverDescriptor.getGroupConversions();\n" - "assertEquals( 1, groupConversions.size() );\n" - "\n" - "GroupConversionDescriptor groupConversionDescriptor = groupConversions.iterator()\n" - " .next();\n" - "assertEquals( Default.class, groupConversionDescriptor.getFrom() );\n" - "assertEquals( Person.Basic.class, groupConversionDescriptor.getTo() );" -msgstr "" - -#. Tag: classname -#: metadata-api.xml:324 -#, no-c-format -msgid "ConstraintDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:326 -#, no-c-format -msgid "Last but not least, the ConstraintDescriptor interface describes a single constraint together with its composing constraints. Via an instance of this interface you get access to the constraint annotation and its parameters." -msgstr "" - -#. Tag: para -#: metadata-api.xml:332 -#, no-c-format -msgid "shows how to retrieve default constraint attributes (such as message template, groups etc.) as well as custom constraint attributes (piecesOfLuggagePerPassenger) and other metadata such as the constraint's annotation type and its validators from a ConstraintDescriptor." -msgstr "" - -#. Tag: title -#: metadata-api.xml:340 -#, no-c-format -msgid "Using ConstraintDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:342 -#, no-c-format -msgid "" - "//descriptor for the @LuggageCountMatchesPassengerCount constraint on the\n" - "//load(List<Person>, List<PieceOfLuggage>) method\n" - "ConstraintDescriptor<?> constraintDescriptor = carDescriptor.getConstraintsForMethod(\n" - " \"load\",\n" - " List.class,\n" - " List.class\n" - ").getCrossParameterDescriptor().getConstraintDescriptors().iterator().next();\n" - "\n" - "//constraint type\n" - "assertEquals(\n" - " LuggageCountMatchesPassengerCount.class,\n" - " constraintDescriptor.getAnnotation().annotationType()\n" - ");\n" - "\n" - "//standard constraint attributes\n" - "assertEquals( SeverityInfo.class, constraintDescriptor.getPayload().iterator().next() );\n" - "assertEquals(\n" - " ConstraintTarget.PARAMETERS,\n" - " constraintDescriptor.getValidationAppliesTo()\n" - ");\n" - "assertEquals( Default.class, constraintDescriptor.getGroups().iterator().next() );\n" - "assertEquals(\n" - " \"There must not be more than {piecesOfLuggagePerPassenger} pieces of luggage per passenger.\",\n" - " constraintDescriptor.getMessageTemplate()\n" - ");\n" - "\n" - "//custom constraint attribute\n" - "assertEquals(\n" - " 2,\n" - " constraintDescriptor.getAttributes().get( \"piecesOfLuggagePerPassenger\" )\n" - ");\n" - "\n" - "//no composing constraints\n" - "assertTrue( constraintDescriptor.getComposingConstraints().isEmpty() );\n" - "\n" - "//validator class\n" - "assertEquals(\n" - " Arrays.<Class<?>>asList( LuggageCountMatchesPassengerCount.Validator.class ),\n" - " constraintDescriptor.getConstraintValidatorClasses()\n" - ");" -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/metadataapi.pot b/documentation/src/main/docbook/pot/modules/metadataapi.pot deleted file mode 100644 index fc1bb1c890..0000000000 --- a/documentation/src/main/docbook/pot/modules/metadataapi.pot +++ /dev/null @@ -1,126 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2011-11-14 10:37+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: metadataapi.xml:24 -#, no-c-format -msgid "Metadata API" -msgstr "" - -#. Tag: para -#: metadataapi.xml:26 -#, no-c-format -msgid "The Bean Validation specification provides not only a validation engine, but also a metadata repository for all defined constraints. The following paragraphs are discussing this API. All the introduced classes can be found in the javax.validation.metadata package." -msgstr "" - -#. Tag: classname -#: metadataapi.xml:33 -#, no-c-format -msgid "BeanDescriptor" -msgstr "" - -#. Tag: para -#: metadataapi.xml:35 -#, no-c-format -msgid "The entry into the metadata API is via Validator.getConstraintsForClass which returns an instance of the BeanDescriptor interface. Using this bean descriptor you can determine whether the specified class hosts any constraints at all via beanDescriptor.isBeanConstrained." -msgstr "" - -#. Tag: para -#: metadataapi.xml:42 -#, no-c-format -msgid "If a constraint declaration hosted by the requested class is invalid, a ValidationException is thrown." -msgstr "" - -#. Tag: para -#: metadataapi.xml:47 -#, no-c-format -msgid "You can then call beanDescriptor.getConstraintDescriptors to get a set of ConstraintDescriptors representing all class level constraints." -msgstr "" - -#. Tag: para -#: metadataapi.xml:52 -#, no-c-format -msgid "If you are interested in property level constraints, you can call beanDescriptor.getConstraintsForProperty or beanDescriptor.getConstrainedProperties to get a single resp. set of PropertyDescriptors (see )." -msgstr "" - -#. Tag: classname -#: metadataapi.xml:60 -#, no-c-format -msgid "PropertyDescriptor" -msgstr "" - -#. Tag: para -#: metadataapi.xml:62 -#, no-c-format -msgid "The PropertyDescriptor interface extends the ElementDescriptor interface and represents constraints on properties of a class. The constraint can be declared on the attribute itself or on the getter of the attribute - provided Java Bean naming conventions are respected. A PropertyDescriptor adds isCascaded (returning true if the property is marked with @Valid) and getPropertyName to the ElementDescriptor functionality." -msgstr "" - -#. Tag: classname -#: metadataapi.xml:75 -#, no-c-format -msgid "ElementDescriptor" -msgstr "" - -#. Tag: para -#: metadataapi.xml:77 -#, no-c-format -msgid "The ElementDiscriptor interface is the common base class for BeanDescriptor and PropertyDescriptor. Next to the hasConstraints and getConstraintDescriptors methods it also offers access to the ConstraintFinder API which allows you to query the metadata API in a more fine grained way. For example you can restrict your search to constraints described on fields or on getters or a given set of groups. Given an ElementDescriptor instance you just call findConstraints to retrieve a ConstraintFinder instance." -msgstr "" - -#. Tag: title -#: metadataapi.xml:92 -#, no-c-format -msgid "Usage of ConstraintFinder" -msgstr "" - -#. Tag: programlisting -#: metadataapi.xml:94 -#, no-c-format -msgid "" - "Validator validator = Validation.buildDefaultValidatorFactory().getValidator();\n" - "BeanDescriptor beanDescriptor = validator.getConstraintsForClass(Person.class);\n" - "PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(\"name\");\n" - "Set<ConstraintDescriptor<?>> constraints = propertyDescriptor.findConstraints()\n" - " .declaredOn(ElementType.METHOD)\n" - " .unorderedAndMatchingGroups(Default.class)\n" - " .lookingAt(Scope.LOCAL_ELEMENT)\n" - " .getConstraintDescriptors();" -msgstr "" - -#. Tag: para -#: metadataapi.xml:97 -#, no-c-format -msgid "shows an example on how to use the ConstraintFinder API. Interesting are especially the restrictions unorderedAndMatchingGroups and lookingAt(Scope.LOCAL_ELEMENT). The former allows to only return ConstraintDescriptors matching a specified set of groups wheras the latter allows to distinguish between constraint directly specified on the element (Scope.LOCAL_ELEMENT) or constraints belonging to the element but hosted anywhere in the class hierarchy (Scope.HIERARCHY)." -msgstr "" - -#. Tag: para -#: metadataapi.xml:108 -#, no-c-format -msgid "Order is not respected by unorderedAndMatchingGroups, but group inheritance and inheritance via sequence are." -msgstr "" - -#. Tag: classname -#: metadataapi.xml:114 -#, no-c-format -msgid "ConstraintDescriptor" -msgstr "" - -#. Tag: para -#: metadataapi.xml:116 -#, no-c-format -msgid "Last but not least, the ConstraintDescriptor interface describes a single constraint together with its composing constraints. Via an instance of this interface you get access to the constraint annotation and its parameters, as well as the groups the constraint is supposed to be applied on. It also also you to access the pass-through constraint payload (see )." -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/method-constraints.pot b/documentation/src/main/docbook/pot/modules/method-constraints.pot deleted file mode 100644 index 9ee30dcd71..0000000000 --- a/documentation/src/main/docbook/pot/modules/method-constraints.pot +++ /dev/null @@ -1,1022 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: method-constraints.xml:24 -#, no-c-format -msgid "Declaring and validating method constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:26 -#, no-c-format -msgid "As of Bean Validation 1.1, constraints can not only be applied to Java beans and their properties, but also to the parameters and return values of the methods and constructors of any Java type. That way Bean Validation constraints can be used to specify" -msgstr "" - -#. Tag: para -#: method-constraints.xml:33 -#, no-c-format -msgid "the preconditions that must be satisfied by the caller before a method or constructor may be invoked (by applying constraints to the parameters of an executable)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:39 -#, no-c-format -msgid "the postconditions that are guaranteed to the caller after a method or constructor invocation returns (by applying constraints to the return value of an executable)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:46 -#, no-c-format -msgid "For the purpose of this reference guide, the term method constraint refers to both, method and constructor constraints, if not stated otherwise. Ocassionally, the term executable is used when referering to methods and constructors." -msgstr "" - -#. Tag: para -#: method-constraints.xml:53 -#, no-c-format -msgid "This approach has several advantages over traditional ways of checking the correctness of parameters and return values:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:58 -#, no-c-format -msgid "the checks don't have to be performed manually (e.g. by throwing IllegalArgumentExceptions or similar), resulting in less code to write and maintain" -msgstr "" - -#. Tag: para -#: method-constraints.xml:64 -#, no-c-format -msgid "an executable's pre- and postconditions don't have to be expressed again in its documentation, since the constraint annotations will automatically be included in the generated JavaDoc. This avoids redundancies and reduces the chance of inconsistencies between implementation and documentation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:73 -#, no-c-format -msgid "In order to make annotations show up in the JavaDoc of annoted elements, the annotation types themselves must be annotated with the meta annotation @Documented. This is the case for all built-in constraints and is considered a best practice for any custom constraints." -msgstr "" - -#. Tag: para -#: method-constraints.xml:80 -#, no-c-format -msgid "In the remainder of this chapter you will learn how to declare parameter and return value constraints and how to validate the same using the ExecutableValidator API." -msgstr "" - -#. Tag: title -#: method-constraints.xml:85 -#, no-c-format -msgid "Declaring method constraints" -msgstr "" - -#. Tag: title -#: method-constraints.xml:88 -#, no-c-format -msgid "Parameter constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:90 -#, no-c-format -msgid "You specify the preconditions of a method or constructor by adding constraint annotations to its parameters as demonstrated in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:95 -#, no-c-format -msgid "Declaring method and constructor parameter constraints" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:97 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.parameter;\n" - "\n" - "public class RentalStation {\n" - "\n" - " public RentalStation(@NotNull String name) {\n" - " //...\n" - " }\n" - "\n" - " public void rentCar(\n" - " @NotNull Customer customer,\n" - " @NotNull @Future Date startDate,\n" - " @Min(1) int durationInDays) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:100 -#, no-c-format -msgid "The following preconditions are declared here:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:104 -#, no-c-format -msgid "The name passed to the RentalCar constructor must not be null" -msgstr "" - -#. Tag: para -#: method-constraints.xml:109 -#, no-c-format -msgid "When invoking the rentCar() method, the given customer must not be null, the rental's start date must not be null and must be in the future and the rental duration must be at least one day" -msgstr "" - -#. Tag: para -#: method-constraints.xml:116 -#, no-c-format -msgid "Note that declaring method or constructor constraints itself does not automatically cause their validation upon invocation of the executable. Instead, the ExecutableValidator API (see ) must be used to perform the validation, which is often done using a method interception facility such as AOP, proxy objects etc." -msgstr "" - -#. Tag: para -#: method-constraints.xml:123 -#, no-c-format -msgid "Constraints may only be applied to instance methods, i.e. declaring constraints on static methods is not supported. Depending on the interception facility you use for triggering method validation, additional restrictions may apply, e.g. with respect to the visibility of methods supported as target of interception. Refer to the documentation of the interception technology to find out whether any such limitations exist." -msgstr "" - -#. Tag: title -#: method-constraints.xml:132 -#, no-c-format -msgid "Cross-parameter constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:134 -#, no-c-format -msgid "Sometimes validation does not only depend on a single parameter but on several or even all parameters of a method or constructor. This kind of requirement can be fulfilled with help of a cross-parameter constraint." -msgstr "" - -#. Tag: para -#: method-constraints.xml:139 -#, no-c-format -msgid "Cross-parameter constraints can be considered as the method validation equivalent to class-level constraints. Both can be used to implement validation requirements which are based on several elements. While class-level constraints apply to several properties of a bean, cross-parameter constraints apply to several parameters of an executable." -msgstr "" - -#. Tag: para -#: method-constraints.xml:146 -#, no-c-format -msgid "In contrast to single-parameter constraints, cross-parameter constraints are declared on the method or constructor as you can see in . Here the cross-parameter constraint @LuggageCountMatchesPassengerCount declared on the load() method is used to ensure that no passenger has more than two pieces of luggage." -msgstr "" - -#. Tag: title -#: method-constraints.xml:155 -#, no-c-format -msgid "Declaring a cross-parameter constraint" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:157 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.crossparameter;\n" - "\n" - "public class Car {\n" - "\n" - " @LuggageCountMatchesPassengerCount(piecesOfLuggagePerPassenger = 2)\n" - " public void load(List<Person> passengers, List<PieceOfLuggage> luggage) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:160 -#, no-c-format -msgid "As you will learn in the next section, return value constraints are also declared on the method level. In order to distinguish cross-parameter constraints from return value constraints, a constraint's target is configured at its validator implementation(s). You can find out about the details in which shows how to implement your own cross-parameter constraints." -msgstr "" - -#. Tag: para -#: method-constraints.xml:168 -#, no-c-format -msgid "In some cases a constraint can be applied to an executable's parameters (i.e. it is a cross-parameter constraint), but also to the return value. One example for this are custom constraints which allow to specify validation rules using expression or script languages." -msgstr "" - -#. Tag: para -#: method-constraints.xml:174 -#, no-c-format -msgid "Such constraints must define a member validationAppliesTo() which can be used at declaration time to specify the constraint target. As shown in you apply the constraint to an executable's parameters by specifying validationAppliesTo = ConstraintTarget.PARAMETERS, while ConstraintTarget.RETURN_VALUE is used to apply the constraint to the executable return value." -msgstr "" - -#. Tag: title -#: method-constraints.xml:184 -#, no-c-format -msgid "Specifying a constraint's target" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:186 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.crossparameter.constrainttarget;\n" - "\n" - "public class Garage {\n" - "\n" - " @ELAssert(expression = \"...\", validationAppliesTo = ConstraintTarget.PARAMETERS)\n" - " public Car buildCar(List<Part> parts) {\n" - " //...\n" - " }\n" - "\n" - " @ELAssert(expression = \"...\", validationAppliesTo = ConstraintTarget.RETURN_VALUE)\n" - " public Car paintCar(int color) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:189 -#, no-c-format -msgid "Although such a constraint is applicable to the parameters and return value of an executable, the target can often be inferred automatically. This is the case, if the constraint is declared on" -msgstr "" - -#. Tag: para -#: method-constraints.xml:196 -#, no-c-format -msgid "a void method with parameters (the constraint applies to the parameters)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:201 -#, no-c-format -msgid "an executable with return value but no parameters (the constraint applies to the return value)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:206 -#, no-c-format -msgid "neither a method nor a constructor, but a field, parameter etc. (the constraint applies to the annotated element)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:211 -#, no-c-format -msgid "In these situations you don't have to specify the constraint target. It is still recommended to do so if it increases readability of the source code. If the constraint target is not specified in situations where it can't be determined automatically, a ConstraintDeclarationException is raised." -msgstr "" - -#. Tag: title -#: method-constraints.xml:221 -#, no-c-format -msgid "Return value constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:223 -#, no-c-format -msgid "The postconditions of a method or constructor are declared by adding constraint annotations to the executable as shown in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:228 -#, no-c-format -msgid "Declaring method and constructor return value constraints" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:231 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.returnvalue;\n" - "\n" - "public class RentalStation {\n" - "\n" - " @ValidRentalStation\n" - " public RentalStation() {\n" - " //...\n" - " }\n" - "\n" - " @NotNull\n" - " @Size(min = 1)\n" - " public List<Customer> getCustomers() {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:234 -#, no-c-format -msgid "The following constraints apply to the executables of RentalStation:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:239 -#, no-c-format -msgid "Any newly created RentalStation object must satisfy the @ValidRentalStation constraint" -msgstr "" - -#. Tag: para -#: method-constraints.xml:245 -#, no-c-format -msgid "The customer list returned by getCustomers() must not be null and must contain at least on element" -msgstr "" - -#. Tag: title -#: method-constraints.xml:253 -#, no-c-format -msgid "Cascaded validation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:256 -#, no-c-format -msgid "Similar to the cascaded validation of JavaBeans properties (see ), the @Valid annotation can be used to mark executable parameters and return values for cascaded validation. When validating a parameter or return value annotated with @Valid, the constraints declared on the parameter or return value object are validated as well." -msgstr "" - -#. Tag: para -#: method-constraints.xml:264 -#, no-c-format -msgid "In , the car parameter of the method Garage#checkCar() as well as the return value of the Garage constructor are marked for cascaded validation." -msgstr "" - -#. Tag: title -#: method-constraints.xml:271 -#, no-c-format -msgid "Marking executable parameters and return values for cascaded validation" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:274 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.cascaded;\n" - "\n" - "public class Garage {\n" - "\n" - " @NotNull\n" - " private final String name;\n" - "\n" - " @Valid\n" - " public Garage(String name) {\n" - " this.name = name;\n" - " }\n" - "\n" - " public boolean checkCar(@Valid @NotNull Car car) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:276 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.cascaded;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private final String manufacturer;\n" - "\n" - " @NotNull\n" - " @Size(min = 2, max = 14)\n" - " private final String licensePlate;\n" - "\n" - " public Car(String manufacturer, String licencePlate) {\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licencePlate;\n" - " }\n" - "\n" - " //getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:279 -#, no-c-format -msgid "When validating the arguments of the checkCar() method, the constraints on the properties of the passed Car object are evaluated as well. Similarly, the @NotNull constraint on the name field of Garage is checked when validating the return value of the Garage constructor." -msgstr "" - -#. Tag: para -#: method-constraints.xml:287 -#, no-c-format -msgid "Generally, the cascaded validation works for executables in exactly the same way as it does for JavaBeans properties." -msgstr "" - -#. Tag: para -#: method-constraints.xml:290 -#, no-c-format -msgid "In particular, null values are ignored during cascaded validation (naturally this can't happen during constructor return value validation) and cascaded validation is performed recursively, i.e. if a parameter or return value object which is marked for cascaded validation itself has properties marked with @Valid, the constraints declared on the referenced elements will be validated as well." -msgstr "" - -#. Tag: para -#: method-constraints.xml:298 -#, no-c-format -msgid "Cascaded validation can not only be applied to simple object references but also to collection-typed parameters and return values. This means when putting the @Valid annotation to a parameter or return value which" -msgstr "" - -#. Tag: para -#: method-constraints.xml:305 -#, no-c-format -msgid "is an array" -msgstr "" - -#. Tag: para -#: method-constraints.xml:309 -#, no-c-format -msgid "implements java.lang.Iterable" -msgstr "" - -#. Tag: para -#: method-constraints.xml:313 -#, no-c-format -msgid "implements java.util.Map" -msgstr "" - -#. Tag: para -#: method-constraints.xml:317 -#, no-c-format -msgid "then each contained element gets checked, when the parameter or return value is validated. So when validating the arguments of the checkCars() method in , each element instance of the passed list will be validated and a ConstraintViolation created when any of the contained Car objects is invalid." -msgstr "" - -#. Tag: title -#: method-constraints.xml:326 -#, no-c-format -msgid "List-typed method parameter marked for cascaded validation" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:329 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.cascaded.collection;\n" - "\n" - "public class Garage {\n" - "\n" - " public boolean checkCars(@Valid @NotNull List<Car> cars) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: title -#: method-constraints.xml:334 -#, no-c-format -msgid "Method constraints in inheritance hierarchies" -msgstr "" - -#. Tag: para -#: method-constraints.xml:337 -#, no-c-format -msgid "When declaring method constraints in inheritance hierarchies, it's important to be aware of the following rules:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:342 -#, no-c-format -msgid "The preconditions to be satisified by the caller of a method may not be strengthened in subtypes" -msgstr "" - -#. Tag: para -#: method-constraints.xml:347 -#, no-c-format -msgid "The postconditions guaranteed to the caller of a method may not be weakened in subtypes" -msgstr "" - -#. Tag: para -#: method-constraints.xml:352 -#, no-c-format -msgid "These rules are motivated by the concept of behavioral subtyping which requires that wherever a type T is used, also a subtype S of T may be used without altering the program's behavior." -msgstr "" - -#. Tag: para -#: method-constraints.xml:358 -#, no-c-format -msgid "As an example, consider a class invoking a method on an object with the static type T. If the runtime type of that object was S and S imposed additional preconditions, the client class might fail to satisfy these preconditions as is not aware of them. The rules of behavioral subtyping are also known as the Liskov substitution principle." -msgstr "" - -#. Tag: para -#: method-constraints.xml:367 -#, no-c-format -msgid "The Bean Validation specification implements the first rule by disallowing parameter constraints on methods which override or implement a method declared in a supertype (superclass or interface). shows a violation of this rule." -msgstr "" - -#. Tag: title -#: method-constraints.xml:374 -#, no-c-format -msgid "Illegal method parameter constraint in subtype" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:376 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.inheritance.parameter;\n" - "\n" - "public interface Vehicle {\n" - "\n" - " void drive(@Max(75) int speedInMph);\n" - "}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:378 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.inheritance.parameter;\n" - "\n" - "import javax.validation.constraints.Max;\n" - "\n" - "public class Car implements Vehicle {\n" - "\n" - " @Override\n" - " public void drive(@Max(55) int speedInMph) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:381 -#, no-c-format -msgid "The @Max constraint on Car#drive() is illegal since this method implements the interface method Vehicle#drive(). Note that parameter constraints on overriding methods are also disallowed, if the supertype method itself doesn't declare any parameter constraints." -msgstr "" - -#. Tag: para -#: method-constraints.xml:388 -#, no-c-format -msgid "Furthermore, if a method overrides or implements a method declared in several parallel supertypes (e.g. two interfaces not extending each other or a class and an interface not implemented by that class), no parameter constraints may be specified for the method in any of the involved types. The types in demonstrate a violation of that rule. The method RacingCar#drive() overrides Vehicle#drive() as well as Car#drive(). Therefore the constraint on Vehicle#drive() is illegal." -msgstr "" - -#. Tag: title -#: method-constraints.xml:401 -#, no-c-format -msgid "Illegal method parameter constraint in parallel types of a hierarchy" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:404 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.inheritance.parallel;\n" - "\n" - "public interface Vehicle {\n" - "\n" - " void drive(@Max(75) int speedInMph);\n" - "}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:406 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.inheritance.parallel;\n" - "\n" - "public interface Car {\n" - "\n" - " public void drive(int speedInMph);\n" - "}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:408 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.inheritance.parallel;\n" - "\n" - "public class RacingCar implements Car, Vehicle {\n" - "\n" - " @Override\n" - " public void drive(int speedInMph) {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:411 -#, no-c-format -msgid "The previously described restrictions only apply to parameter constraints. In contrast, return value constraints may be added in methods overriding or implementing any supertype methods." -msgstr "" - -#. Tag: para -#: method-constraints.xml:415 -#, no-c-format -msgid "In this case, all the method's return value constraints apply for the subtype method, i.e. the constraints declared on the subtype method itself as well as any return value constraints on overridden/implemented supertype methods. This is legal as putting additional return value constraints in place may never represent a weakening of the postconditions guaranteed to the caller of a method." -msgstr "" - -#. Tag: para -#: method-constraints.xml:422 -#, no-c-format -msgid "So when validating the return value of the method Car#getPassengers() shown in , the @Size constraint on the method itself as well as the @NotNull constraint on the implemented interface method Vehicle#getPassengers() apply." -msgstr "" - -#. Tag: title -#: method-constraints.xml:431 -#, no-c-format -msgid "Return value constraints on supertype and subtype method" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:434 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.inheritance.returnvalue;\n" - "\n" - "public interface Vehicle {\n" - "\n" - " @NotNull\n" - " List<Person> getPassengers();\n" - "}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:436 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.inheritance.returnvalue;\n" - "\n" - "public class Car implements Vehicle {\n" - "\n" - " @Override\n" - " @Size(min = 1)\n" - " public List<Person> getPassengers() {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:439 -#, no-c-format -msgid "If the validation engine detects a violation of any of the aforementioned rules, a ConstraintDeclarationException will be raised." -msgstr "" - -#. Tag: para -#: method-constraints.xml:445 -#, no-c-format -msgid "The rules described in this section only apply to methods but not constructors. By definition, constructors never override supertype constructors. Therefore, when validating the parameters or the return value of a constructor invocation only the constraints declared on the constructor itself apply, but never any constraints declared on supertype constructors." -msgstr "" - -#. Tag: title -#: method-constraints.xml:456 -#, no-c-format -msgid "Validating method constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:458 -#, no-c-format -msgid "The validation of method constraints is done using the ExecutableValidator interface." -msgstr "" - -#. Tag: para -#: method-constraints.xml:461 -#, no-c-format -msgid "In you'll learn how to obtain an ExecutableValidator instance while shows how to use the different methods offered by this interface." -msgstr "" - -#. Tag: para -#: method-constraints.xml:466 -#, no-c-format -msgid "Instead of calling the ExecutableValidator methods directly from within application code, they are usually invoked via a method interception technology such as AOP, proxy objects, etc. This causes executable constraints to be validated automatically and transparently upon method or constructor invocation. Typically a ConstraintViolationException is raised by the integration layer in case any of the constraints is violated." -msgstr "" - -#. Tag: title -#: method-constraints.xml:475 -#, no-c-format -msgid "Obtaining an ExecutableValidator instance" -msgstr "" - -#. Tag: para -#: method-constraints.xml:478 -#, no-c-format -msgid "You can retrieve an ExecutableValidator instance via Validator#forExecutables() as shown in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:483 -#, no-c-format -msgid "Obtaining an ExecutableValidator" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:485 -#, no-c-format -msgid "" - "ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - "executableValidator = factory.getValidator().forExecutables();" -msgstr "" - -#. Tag: para -#: method-constraints.xml:488 -#, no-c-format -msgid "In the example the executable validator is retrieved from the default validator factory, but if required you could also bootstrap a specifically configured factory as described in , for instance in order to use a specific parameter name provider (see )." -msgstr "" - -#. Tag: title -#: method-constraints.xml:497 -#, no-c-format -msgid "ExecutableValidator methods" -msgstr "" - -#. Tag: para -#: method-constraints.xml:499 -#, no-c-format -msgid "The ExecutableValidator interface offers altogether four methods:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:504 -#, no-c-format -msgid "validateParameters() and validateReturnValue() for method validation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:510 -#, no-c-format -msgid "validateConstructorParameters() and validateConstructorReturnValue() for constructor validation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:516 -#, no-c-format -msgid "Just as the methods on Validator, all these methods return a Set<ConstraintViolation> which contains a ConstraintViolation instance for each violated constraint and which is empty if the validation succeeds. Also all the methods have a var-args groups parameter by which you can pass the validation groups to be considered for validation." -msgstr "" - -#. Tag: para -#: method-constraints.xml:524 -#, no-c-format -msgid "The examples in the following sections are based on the methods on constructors of the Car class shown in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:529 -#, no-c-format -msgid "Class Car with constrained methods and constructors" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:532 -#, no-c-format -msgid "" - "package org.hibernate.validator.referenceguide.chapter03.validation;\n" - "\n" - "public class Car {\n" - "\n" - " public Car(@NotNull String manufacturer) {\n" - " //...\n" - " }\n" - "\n" - " @ValidRacingCar\n" - " public Car(String manufacturer, String team) {\n" - " //...\n" - " }\n" - "\n" - " public void drive(@Max(75) int speedInMph) {\n" - " //...\n" - " }\n" - "\n" - " @Size(min = 1)\n" - " public List<Passenger> getPassengers() {\n" - " //...\n" - " }\n" - "}" -msgstr "" - -#. Tag: methodname -#: method-constraints.xml:536 -#, no-c-format -msgid "validateParameters()" -msgstr "" - -#. Tag: para -#: method-constraints.xml:538 -#, no-c-format -msgid "The method validateParameters() is used to validate the arguments of a method invocation. shows an example. The validation results in a violation of the @Max constraint on the parameter of the drive() method." -msgstr "" - -#. Tag: title -#: method-constraints.xml:546 -#, no-c-format -msgid "Using ExecutableValidator#validateParameters()" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:549 -#, no-c-format -msgid "" - "Car object = new Car( \"Morris\" );\n" - "Method method = Car.class.getMethod( \"drive\", int.class );\n" - "Object[] parameterValues = { 80 };\n" - "Set<ConstraintViolation<Car>> violations = executableValidator.validateParameters(\n" - " object,\n" - " method,\n" - " parameterValues\n" - ");\n" - "\n" - "assertEquals( 1, violations.size() );\n" - "Class<? extends Annotation> constraintType = violations.iterator()\n" - " .next()\n" - " .getConstraintDescriptor()\n" - " .getAnnotation()\n" - " .annotationType();\n" - "assertEquals( Max.class, constraintType );" -msgstr "" - -#. Tag: para -#: method-constraints.xml:552 -#, no-c-format -msgid "Note that validateParameters() validates all the parameter constraints of a method, i.e. constraints on individual parameters as well as cross-parameter constraints." -msgstr "" - -#. Tag: methodname -#: method-constraints.xml:559 -#, no-c-format -msgid "validateReturnValue()" -msgstr "" - -#. Tag: para -#: method-constraints.xml:561 -#, no-c-format -msgid "Using validateReturnValue() the return value of a method can can be validated. The validation in yields one constraint violation since the getPassengers() method is expect to return at least one Passenger object." -msgstr "" - -#. Tag: title -#: method-constraints.xml:569 -#, no-c-format -msgid "Using ExecutableValidator#validateReturnValue()" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:572 -#, no-c-format -msgid "" - "Car object = new Car( \"Morris\" );\n" - "Method method = Car.class.getMethod( \"getPassengers\" );\n" - "Object returnValue = Collections.<Passenger>emptyList();\n" - "Set<ConstraintViolation<Car>> violations = executableValidator.validateReturnValue(\n" - " object,\n" - " method,\n" - " returnValue\n" - ");\n" - "\n" - "assertEquals( 1, violations.size() );\n" - "Class<? extends Annotation> constraintType = violations.iterator()\n" - " .next()\n" - " .getConstraintDescriptor()\n" - " .getAnnotation()\n" - " .annotationType();\n" - "assertEquals( Size.class, constraintType );" -msgstr "" - -#. Tag: methodname -#: method-constraints.xml:577 -#, no-c-format -msgid "validateConstructorParameters()" -msgstr "" - -#. Tag: para -#: method-constraints.xml:579 -#, no-c-format -msgid "The arguments of constructor invocations can be validated with validateConstructorParameters() as shown in method . Due to the @NotNull constraint on the manufacturer parameter, the validation call returns one constraint violation." -msgstr "" - -#. Tag: title -#: method-constraints.xml:588 -#, no-c-format -msgid "Using ExecutableValidator#validateConstructorParameters()" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:591 -#, no-c-format -msgid "" - "Constructor<Car> constructor = Car.class.getConstructor( String.class );\n" - "Object[] parameterValues = { null };\n" - "Set<ConstraintViolation<Car>> violations = executableValidator.validateConstructorParameters(\n" - " constructor,\n" - " parameterValues\n" - ");\n" - "\n" - "assertEquals( 1, violations.size() );\n" - "Class<? extends Annotation> constraintType = violations.iterator()\n" - " .next()\n" - " .getConstraintDescriptor()\n" - " .getAnnotation()\n" - " .annotationType();\n" - "assertEquals( NotNull.class, constraintType );" -msgstr "" - -#. Tag: methodname -#: method-constraints.xml:596 -#, no-c-format -msgid "validateConstructorReturnValue()" -msgstr "" - -#. Tag: para -#: method-constraints.xml:598 -#, no-c-format -msgid "Finally, by using validateConstructorReturnValue() you can valide a constructor's return value. In , validateConstructorReturnValue() returns one constraint violation, since the Car object returned by the constructor doesn't satisfy the @ValidRacingCar constraint (not shown)." -msgstr "" - -#. Tag: title -#: method-constraints.xml:608 -#, no-c-format -msgid "Using ExecutableValidator#validateConstructorReturnValue()" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:611 -#, no-c-format -msgid "" - "//constructor for creating racing cars\n" - "Constructor<Car> constructor = Car.class.getConstructor( String.class, String.class );\n" - "Car createdObject = new Car( \"Morris\", null );\n" - "Set<ConstraintViolation<Car>> violations = executableValidator.validateConstructorReturnValue(\n" - " constructor,\n" - " createdObject\n" - ");\n" - "\n" - "assertEquals( 1, violations.size() );\n" - "Class<? extends Annotation> constraintType = violations.iterator()\n" - " .next()\n" - " .getConstraintDescriptor()\n" - " .getAnnotation()\n" - " .annotationType();\n" - "assertEquals( ValidRacingCar.class, constraintType );" -msgstr "" - -#. Tag: title -#: method-constraints.xml:617 -#, no-c-format -msgid "ConstraintViolation methods for method validation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:620 -#, no-c-format -msgid "In addition to the methods introduced in , ConstraintViolation provides two more methods specific to the validation of executable parameters and return values." -msgstr "" - -#. Tag: para -#: method-constraints.xml:626 -#, no-c-format -msgid "ConstraintViolation#getExecutableParameters() returns the validated parameter array in case of method or constructor parameter validation, while ConstraintViolation#getExecutableReturnValue() provides access to the validated object in case of return value validation." -msgstr "" - -#. Tag: para -#: method-constraints.xml:633 -#, no-c-format -msgid "All the other ConstraintViolation methods generally work for method validation in the same way as for validation of beans. Refer to the JavaDoc to learn more about the behavior of the individual methods and their return values during bean and method validation." -msgstr "" - -#. Tag: para -#: method-constraints.xml:640 -#, no-c-format -msgid "Note that getPropertyPath() can be very useful in order to obtain detailed information about the validated parameter or return value, e.g. for logging purposes. In particular, you can retrieve name and argument types of the concerned method as well as the index of the concerned parameter from the path nodes. How this can be done is shown in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:649 -#, no-c-format -msgid "Retrieving method and parameter information" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:651 -#, no-c-format -msgid "" - "Car object = new Car( \"Morris\" );\n" - "Method method = Car.class.getMethod( \"drive\", int.class );\n" - "Object[] parameterValues = { 80 };\n" - "Set<ConstraintViolation<Car>> violations = executableValidator.validateParameters(\n" - " object,\n" - " method,\n" - " parameterValues\n" - ");\n" - "\n" - "assertEquals( 1, violations.size() );\n" - "Iterator<Node> propertyPath = violations.iterator()\n" - " .next()\n" - " .getPropertyPath()\n" - " .iterator();\n" - "\n" - "MethodNode methodNode = propertyPath.next().as( MethodNode.class );\n" - "assertEquals( \"drive\", methodNode.getName() );\n" - "assertEquals( Arrays.<Class<?>>asList( int.class ), methodNode.getParameterTypes() );\n" - "\n" - "ParameterNode parameterNode = propertyPath.next().as( ParameterNode.class );\n" - "assertEquals( \"arg0\", parameterNode.getName() );\n" - "assertEquals( 0, parameterNode.getParameterIndex() );" -msgstr "" - -#. Tag: para -#: method-constraints.xml:654 -#, no-c-format -msgid "The parameter name is determined using the current ParameterNameProvider (see TODO) and defaults to arg0, arg1 etc." -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/preface.pot b/documentation/src/main/docbook/pot/modules/preface.pot deleted file mode 100644 index 755160f3da..0000000000 --- a/documentation/src/main/docbook/pot/modules/preface.pot +++ /dev/null @@ -1,40 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: preface.xml:24 -#, no-c-format -msgid "Preface" -msgstr "" - -#. Tag: para -#: preface.xml:26 -#, no-c-format -msgid "Validating data is a common task that occurs throughout any application, from the presentation layer to the persistence layer. Often the same validation logic is implemented in each layer, proving time consuming and error-prone. To avoid duplication of these validations in each layer, developers often bundle validation logic directly into the domain model, cluttering domain classes with validation code which is really metadata about the class itself." -msgstr "" - -#. Tag: para -#: preface.xml:45 -#, no-c-format -msgid "JSR 349 - Bean Validation 1.1 - defines a metadata model and API for entity validation. The default metadata source is annotations, with the ability to override and extend the meta-data through the use of XML. The API is not tied to a specific application tier or programming model. It is specifically not tied to either the web tier or the persistence tier, and is available for both server-side application programming, as well as rich client Swing application developers." -msgstr "" - -#. Tag: para -#: preface.xml:64 -#, no-c-format -msgid "Hibernate Validator is the reference implementation of this JSR. The implementation itself as well as the Bean Validation API and TCK are all provided and distributed under the Apache Software License 2.0." -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/programmaticapi.pot b/documentation/src/main/docbook/pot/modules/programmaticapi.pot deleted file mode 100644 index 90b286de4b..0000000000 --- a/documentation/src/main/docbook/pot/modules/programmaticapi.pot +++ /dev/null @@ -1,132 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2011-01-12 15:42+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: application/x-xml2pot; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: programmaticapi.xml:24 programmaticapi.xml:47 -#, no-c-format -msgid "Programmatic constraint definition" -msgstr "" - -#. Tag: para -#: programmaticapi.xml:27 -#, no-c-format -msgid "Use of the features described in the following sections is not portable between Bean Validation providers/implementations." -msgstr "" - -#. Tag: para -#: programmaticapi.xml:31 -#, no-c-format -msgid "Hibernate Validator allows to configure constraints not only via annotations and xml, but also via a programmatic API. This API can be used exclusively or in combination with annotations and xml. If used in combination programmatic constraints are additive to otherwise configured constraints." -msgstr "" - -#. Tag: para -#: programmaticapi.xml:37 -#, no-c-format -msgid "The programmatic API is centered around the ConstraintMapping class which can be found together with its supporting classes in the org.hibernate.validator.cfg package. ConstraintMapping is the entry point to a fluent API allowing the definition of constraints. shows how the API can be used." -msgstr "" - -#. Tag: programlisting -#: programmaticapi.xml:49 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "mapping.type( Car.class )\n" - " .property( \"manufacturer\", FIELD )\n" - " .constraint( NotNullDef.class )\n" - " .property( \"licensePlate\", FIELD )\n" - " .constraint( NotNullDef.class )\n" - " .constraint( SizeDef.class )\n" - " .min( 2 )\n" - " .max( 14 )\n" - " .property( \"seatCount\", FIELD )\n" - " .constraint( MinDef.class )\n" - " .value ( 2 )\n" - ".type( RentalCar.class )\n" - " .property( \"rentalStation\", METHOD)\n" - " .constraint( NotNullDef.class );" -msgstr "" - -#. Tag: para -#: programmaticapi.xml:52 -#, no-c-format -msgid "As you can see you can configure constraints on multiple classes and properties using method chaining. The constraint definition classes NotNullDef, SizeDef and MinDef are helper classes which allow to configure constraint parameters in a type-safe fashion. Definition classes exists for all built-in constraints in the org.hibernate.validator.cfg.defs package. For a custom constraint you can either create your own definition class extending ConstraintDef or you can use the genericConstraint method as seen in ." -msgstr "" - -#. Tag: title -#: programmaticapi.xml:65 -#, no-c-format -msgid "Programmatic constraint definition using GenericConstraintDef" -msgstr "" - -#. Tag: programlisting -#: programmaticapi.xml:68 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "mapping.type( Car.class )\n" - " .property( \"licensePlate\", FIELD )\n" - " .genericConstraint( CheckCase.class )\n" - " .param( \"value\", CaseMode.UPPER );" -msgstr "" - -#. Tag: para -#: programmaticapi.xml:71 -#, no-c-format -msgid "Last but not least, you can also define cascading constraints as well as the default group sequence of an entity." -msgstr "" - -#. Tag: title -#: programmaticapi.xml:75 -#, no-c-format -msgid "Cascading constraints and group redefinition" -msgstr "" - -#. Tag: programlisting -#: programmaticapi.xml:77 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "mapping.type( Car.class )\n" - " .valid( \"driver\", FIELD )\n" - ".type( RentalCar.class)\n" - " .defaultGroupSequence( RentalCar.class, CarChecks.class );" -msgstr "" - -#. Tag: para -#: programmaticapi.xml:80 -#, no-c-format -msgid "Once you have your ConstraintMapping you will have to pass it to the configuration. Since the programmatic configuration is not part of the official Bean Validation specification you will have to get hold of the Hibernate Validator specific configuration instance. See ." -msgstr "" - -#. Tag: title -#: programmaticapi.xml:87 -#, no-c-format -msgid "Creating a Hibernate Validator specific configuration" -msgstr "" - -#. Tag: programlisting -#: programmaticapi.xml:89 -#, no-c-format -msgid "" - "ConstraintMapping mapping = new ConstraintMapping();\n" - "// configure mapping instance\n" - "\n" - "HibernateValidatorConfiguration config = Validation.byProvider( HibernateValidator.class ).configure();\n" - "config.addMapping( mapping );\n" - "ValidatorFactory factory = config.buildValidatorFactory();\n" - "Validator validator = factory.getValidator();" -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/usingvalidator.pot b/documentation/src/main/docbook/pot/modules/usingvalidator.pot deleted file mode 100644 index a966529400..0000000000 --- a/documentation/src/main/docbook/pot/modules/usingvalidator.pot +++ /dev/null @@ -1,1416 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-03 09:59+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: usingvalidator.xml:24 -#, no-c-format -msgid "Declaring and validating constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:26 -#, no-c-format -msgid "In this chapter we will see in more detail how to use Hibernate Validator to validate constraints for a given entity model. We will also learn which default constraints the Bean Validation specification provides and which additional constraints are only provided by Hibernate Validator. Let's start with how to add constraints to an entity." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:33 -#, no-c-format -msgid "Defining constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:35 -#, no-c-format -msgid "Constraints in Bean Validation are expressed via Java annotations. In this section we show how to enhance an object model with these annotations. We have to differentiate between several types of constraint annotations:" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:42 -#, no-c-format -msgid "field constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:46 -#, no-c-format -msgid "property constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:50 -#, no-c-format -msgid "class constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:54 -#, no-c-format -msgid "method constraints (parameter, cross-parameter and return value constraints)" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:60 -#, no-c-format -msgid "Not all constraints can be placed on all of these levels. In fact, none of the default constraints defined by Bean Validation can be placed at class level. The java.lang.annotation.Target annotation in the constraint annotation itself determines on which elements a constraint can be placed. See for more information." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:69 -#, no-c-format -msgid "Field-level constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:71 -#, no-c-format -msgid "Constraints can be expressed by annotating a field of a class. shows a field level configuration example:" -msgstr "" - -#. Tag: title -#: usingvalidator.xml:76 -#, no-c-format -msgid "Field level constraint" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:78 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.constraints.NotNull;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @AssertTrue\n" - " private boolean isRegistered;\n" - "\n" - " public Car(String manufacturer, boolean isRegistered) {\n" - " super();\n" - " this.manufacturer = manufacturer;\n" - " this.isRegistered = isRegistered;\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:81 -#, no-c-format -msgid "When using field level constraints field access strategy is used to access the value to be validated. This means the bean validation provider directly accesses the instance variable and does not invoke the property accessor method also if such a method exists." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:87 -#, no-c-format -msgid "The access type (private, protected or public) does not matter." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:92 -#, no-c-format -msgid "Static fields and properties cannot be validated." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:96 -#, no-c-format -msgid "When validating byte code enhanced objects property level constraints should be used, because the byte code enhancing library won't be able to determine a field access via reflection." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:103 -#, no-c-format -msgid "Property-level constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:105 -#, no-c-format -msgid "If your model class adheres to the JavaBeans standard, it is also possible to annotate the properties of a bean class instead of its fields. uses the same entity as in , however, property level constraints are used." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:111 -#, no-c-format -msgid "The property's getter method has to be annotated, not its setter." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:116 -#, no-c-format -msgid "Property level constraint" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:118 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.constraints.AssertTrue;\n" - "import javax.validation.constraints.NotNull;\n" - "\n" - "public class Car {\n" - "\n" - " private String manufacturer;\n" - "\n" - " private boolean isRegistered;\n" - " \n" - " public Car(String manufacturer, boolean isRegistered) {\n" - " super();\n" - " this.manufacturer = manufacturer;\n" - " this.isRegistered = isRegistered;\n" - " }\n" - "\n" - " @NotNull\n" - " public String getManufacturer() {\n" - " return manufacturer;\n" - " }\n" - "\n" - " public void setManufacturer(String manufacturer) {\n" - " this.manufacturer = manufacturer;\n" - " }\n" - "\n" - " @AssertTrue\n" - " public boolean isRegistered() {\n" - " return isRegistered;\n" - " }\n" - "\n" - " public void setRegistered(boolean isRegistered) {\n" - " this.isRegistered = isRegistered;\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:121 -#, no-c-format -msgid "When using property level constraints property access strategy is used to access the value to be validated. This means the bean validation provider accesses the state via the property accessor method. One advantage of annotating properties instead of fields is that the constraints become part of the constrained type's API that way and users are aware of the existing constraints without having to examine the type's implementation." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:130 -#, no-c-format -msgid "It is recommended to stick either to field or property annotations within one class. It is not recommended to annotate a field and the accompanying getter method as this would cause the field to be validated twice." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:139 -#, no-c-format -msgid "Class-level constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:142 -#, no-c-format -msgid "Last but not least, a constraint can also be placed on class level. When a constraint annotation is placed on this level the class instance itself passed to the ConstraintValidator. Class level constraints are useful if it is necessary to inspect more than a single property of the class to validate it or if a correlation between different state variables has to be evaluated. In we add the property passengers to the class Car. We also add the constraint PassengerCount on the class level. We will later see how we can actually create this custom constraint (see ). For now it is enough to know that PassengerCount will ensure that there cannot be more passengers in a car than there are seats." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:158 -#, no-c-format -msgid "Class level constraint" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:160 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.constraints.Min;\n" - "import javax.validation.constraints.NotNull;\n" - "import javax.validation.constraints.Size;\n" - "\n" - "@PassengerCount\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " private String manufacturer;\n" - "\n" - " @NotNull\n" - " @Size(min = 2, max = 14)\n" - " private String licensePlate;\n" - "\n" - " @Min(2)\n" - " private int seatCount;\n" - " \n" - " private List<Person> passengers;\n" - " \n" - " public Car(String manufacturer, String licencePlate, int seatCount) {\n" - " this.manufacturer = manufacturer;\n" - " this.licensePlate = licencePlate;\n" - " this.seatCount = seatCount;\n" - " }\n" - "\n" - " //getters and setters ...\n" - "}" -msgstr "" - -#. Tag: title -#: usingvalidator.xml:165 -#, no-c-format -msgid "Constraint inheritance" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:167 -#, no-c-format -msgid "When validating an object that implements an interface or extends another class, all constraint annotations on the implemented interface and parent class apply in the same manner as the constraints specified on the validated object itself. To make things clearer let's have a look at the following example:" -msgstr "" - -#. Tag: title -#: usingvalidator.xml:174 -#, no-c-format -msgid "Constraint inheritance using RentalCar" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:176 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.constraints.NotNull;\n" - "\n" - "public class RentalCar extends Car {\n" - "\n" - " private String rentalStation;\n" - " \n" - " public RentalCar(String manufacturer, String rentalStation) {\n" - " super(manufacturer);\n" - " this.rentalStation = rentalStation;\n" - " }\n" - " \n" - " @NotNull\n" - " public String getRentalStation() {\n" - " return rentalStation;\n" - " }\n" - "\n" - " public void setRentalStation(String rentalStation) {\n" - " this.rentalStation = rentalStation;\n" - " }\n" - "}" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:179 -#, no-c-format -msgid "Our well-known class Car is now extended by RentalCar with the additional property rentalStation. If an instance of RentalCar is validated, not only the @NotNull constraint on rentalStation is validated, but also the constraint on manufacturer from the parent class." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:187 -#, no-c-format -msgid "The same would hold true, if Car were an interface implemented by RentalCar." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:190 -#, no-c-format -msgid "Constraint annotations are aggregated if methods are overridden. If RentalCar would override the getManufacturer() method from Car any constraints annotated at the overriding method would be evaluated in addition to the @NotNull constraint from the super-class." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:199 -#, no-c-format -msgid "Object graphs" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:201 -#, no-c-format -msgid "The Bean Validation API does not only allow to validate single class instances but also complete object graphs. To do so, just annotate a field or property representing a reference to another object with @Valid. If the parent object is validated, all referenced objects annotated with @Valid will be validated as well (as will be their children etc.). See ." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:210 -#, no-c-format -msgid "Class Person" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:212 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.constraints.NotNull;\n" - "\n" - "public class Person {\n" - "\n" - " @NotNull\n" - " private String name;\n" - " \n" - " public Person(String name) {\n" - " super();\n" - " this.name = name;\n" - " }\n" - "\n" - " public String getName() {\n" - " return name;\n" - " }\n" - "\n" - " public void setName(String name) {\n" - " this.name = name;\n" - " }\n" - "}" -msgstr "" - -#. Tag: title -#: usingvalidator.xml:216 -#, no-c-format -msgid "Adding a driver to the car" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:218 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import javax.validation.Valid;\n" - "import javax.validation.constraints.NotNull;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " @Valid\n" - " private Person driver;\n" - " \n" - " public Car(Person driver) {\n" - " this.driver = driver;\n" - " }\n" - "\n" - " //getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:221 -#, no-c-format -msgid "If an instance of Car is validated, the referenced Person object will be validated as well, as the driver field is annotated with @Valid. Therefore the validation of a Car will fail if the name field of the referenced Person instance is null." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:229 -#, no-c-format -msgid "Object graph validation also works for collection-typed fields. That means any attributes that" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:234 -#, no-c-format -msgid "are arrays" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:238 -#, no-c-format -msgid "implement java.lang.Iterable (especially Collection, List and Set)" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:244 -#, no-c-format -msgid "implement java.util.Map" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:248 -#, no-c-format -msgid "can be annotated with @Valid, which will cause each contained element to be validated, when the parent object is validated." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:253 -#, no-c-format -msgid "Car with a list of passengers" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:255 -#, no-c-format -msgid "" - "package com.mycompany;\n" - "\n" - "import java.util.ArrayList;\n" - "import java.util.List;\n" - "\n" - "import javax.validation.Valid;\n" - "import javax.validation.constraints.NotNull;\n" - "\n" - "public class Car {\n" - "\n" - " @NotNull\n" - " @Valid\n" - " private List<Person> passengers = new ArrayList<Person>();\n" - "\n" - " public Car(List<Person> passengers) {\n" - " this.passengers = passengers;\n" - " }\n" - "\n" - " //getters and setters ...\n" - "}" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:258 -#, no-c-format -msgid "If a Car instance is validated, a ConstraintValidation will be created, if any of the Person objects contained in the passengers list has a null name." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:262 -#, no-c-format -msgid "null values are getting ignored when validating object graphs." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:269 -#, no-c-format -msgid "Validating constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:271 -#, no-c-format -msgid "The Validator interface is the main entry point to Bean Validation. In we will first show how to obtain an Validator instance. Afterwards we will learn how to use the different methods of the Validator interface." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:278 -#, no-c-format -msgid "Obtaining a Validator instance" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:280 -#, no-c-format -msgid "The first step towards validating an entity instance is to get hold of a Validator instance. The road to this instance leads via the Validation class and a ValidatorFactory. The easiest way is to use the static Validation.buildDefaultValidatorFactory() method:" -msgstr "" - -#. Tag: title -#: usingvalidator.xml:289 -#, no-c-format -msgid "Validation.buildDefaultValidatorFactory()" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:291 -#, no-c-format -msgid "" - "ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - "Validator validator = factory.getValidator();" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:294 -#, no-c-format -msgid "For other ways of obtaining a Validator instance see . For now we just want to see how we can use the Validator instance to validate entity instances." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:301 -#, no-c-format -msgid "Validator methods" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:303 -#, no-c-format -msgid "The Validator interface contains three methods that can be used to either validate entire entities or just a single properties of the entity." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:307 -#, no-c-format -msgid "All three methods return a Set<ConstraintViolation>. The set is empty, if the validation succeeds. Otherwise a ConstraintViolation instance is added for each violated constraint." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:313 -#, no-c-format -msgid "All the validation methods have a var-args parameter which can be used to specify, which validation groups shall be considered when performing the validation. If the parameter is not specified the default validation group (javax.validation.groups.Default) will be used. We will go into more detail on the topic of validation groups in " -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:322 -#, no-c-format -msgid "validate" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:324 -#, no-c-format -msgid "Use the validate() method to perform validation of all constraints of a given entity instance (see )." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:329 -#, no-c-format -msgid "Usage of Validator.validate()" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:332 -#, no-c-format -msgid "" - "ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" - "Validator validator = factory.getValidator();\n" - "\n" - "Car car = new Car(null);\n" - "\n" - "Set<ConstraintViolation<Car>> constraintViolations = validator.validate(car);\n" - "\n" - "assertEquals(1, constraintViolations.size());\n" - "assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());" -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:337 -#, no-c-format -msgid "validateProperty" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:339 -#, no-c-format -msgid "With help of the validateProperty() a single named property of a given object can be validated. The property name is the JavaBeans property name." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:344 -#, no-c-format -msgid "Usage of Validator.validateProperty()" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:347 -#, no-c-format -msgid "" - "Validator validator = Validation.buildDefaultValidatorFactory().getValidator();\n" - "\n" - "Car car = new Car(null);\n" - "\n" - "Set<ConstraintViolation<Car>> constraintViolations = validator.validateProperty(car, \"manufacturer\");\n" - "\n" - "assertEquals(1, constraintViolations.size());\n" - "assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:350 -#, no-c-format -msgid "Validator.validateProperty is for example used in the integration of Bean Validation into JSF 2 (see )." -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:356 -#, no-c-format -msgid "validateValue" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:358 -#, no-c-format -msgid "Using the validateValue() method you can check, whether a single property of a given class can be validated successfully, if the property had the specified value:" -msgstr "" - -#. Tag: title -#: usingvalidator.xml:363 -#, no-c-format -msgid "Usage of Validator.validateValue()" -msgstr "" - -#. Tag: programlisting -#: usingvalidator.xml:366 -#, no-c-format -msgid "" - "Validator validator = Validation.buildDefaultValidatorFactory().getValidator();\n" - "\n" - "Set<ConstraintViolation<Car>> constraintViolations = validator.validateValue(Car.class, \"manufacturer\", null);\n" - "\n" - "assertEquals(1, constraintViolations.size());\n" - "assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:370 -#, no-c-format -msgid "@Valid is not honored by validateProperty() or validateValue()." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:378 -#, no-c-format -msgid "ConstraintViolation methods" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:380 -#, no-c-format -msgid "Now it is time to have a closer look at what a ConstraintViolation. Using the different methods of ConstraintViolation a lot of useful information about the cause of the validation failure can be determined. gives an overview of these methods:" -msgstr "" - -#. Tag: title -#: usingvalidator.xml:388 -#, no-c-format -msgid "The various ConstraintViolation methods" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:394 -#, no-c-format -msgid "Method" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:396 -#, no-c-format -msgid "Usage" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:398 -#, no-c-format -msgid "Example (referring to )" -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:405 -#, no-c-format -msgid "getMessage()" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:407 -#, no-c-format -msgid "The interpolated error message." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:409 -#, no-c-format -msgid "may not be null" -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:413 -#, no-c-format -msgid "getMessageTemplate()" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:415 -#, no-c-format -msgid "The non-interpolated error message." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:417 -#, no-c-format -msgid "{javax.validation.constraints.NotNull.message}" -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:421 -#, no-c-format -msgid "getRootBean()" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:423 -#, no-c-format -msgid "The root bean being validated." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:425 usingvalidator.xml:443 -#, no-c-format -msgid "car" -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:429 -#, no-c-format -msgid "getRootBeanClass()" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:431 -#, no-c-format -msgid "The class of the root bean being validated." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:433 -#, no-c-format -msgid "Car.class" -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:437 -#, no-c-format -msgid "getLeafBean()" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:439 -#, no-c-format -msgid "If a bean constraint, the bean instance the constraint is applied on. If a property constraint, the bean instance hosting the property the constraint is applied on." -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:447 -#, no-c-format -msgid "getPropertyPath()" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:449 -#, no-c-format -msgid "The property path to the value from root bean." -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:455 -#, no-c-format -msgid "getInvalidValue()" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:457 -#, no-c-format -msgid "The value failing to pass the constraint." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:459 -#, no-c-format -msgid "passengers" -msgstr "" - -#. Tag: methodname -#: usingvalidator.xml:463 -#, no-c-format -msgid "getConstraintDescriptor()" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:465 -#, no-c-format -msgid "Constraint metadata reported to fail." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:475 -#, no-c-format -msgid "Message interpolation" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:477 -#, no-c-format -msgid "As we will see in each constraint definition must define a default message descriptor. This message can be overridden at declaration time using the message attribute of the constraint. You can see this in . This message descriptors get interpolated when a constraint validation fails using the configured MessageInterpolator. The interpolator will try to resolve any message parameters, meaning string literals enclosed in braces. In order to resolve these parameters Hibernate Validator's default MessageInterpolator first recursively resolves parameters against a custom ResourceBundle called ValidationMessages.properties at the root of the classpath (It is up to you to create this file). If no further replacements are possible against the custom bundle the default ResourceBundle under /org/hibernate/validator/ValidationMessages.properties gets evaluated. If a replacement occurs against the default bundle the algorithm looks again at the custom bundle (and so on). Once no further replacements against these two resource bundles are possible remaining parameters are getting resolved against the attributes of the constraint to be validated." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:500 -#, no-c-format -msgid "Since the braces { and } have special meaning in the messages they need to be escaped if they are used literally. The following The following rules apply:" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:504 -#, no-c-format -msgid "\\{ is considered as the literal {" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:508 -#, no-c-format -msgid "\\} is considered as the literal }" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:512 -#, no-c-format -msgid "\\\\ is considered as the literal \\" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:516 -#, no-c-format -msgid "If the default message interpolator does not fit your requirements it is possible to plug a custom MessageInterpolator when the ValidatorFactory gets created. This can be seen in ." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:525 -#, no-c-format -msgid "Built-in constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:527 -#, no-c-format -msgid "Hibernate Validator comprises a basic set of commonly used constraints. These are foremost the constraints defined by the Bean Validation specification (see ). Additionally, Hibernate Validator provides useful custom constraints (see and )." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:535 usingvalidator.xml:554 -#, no-c-format -msgid "Bean Validation constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:537 -#, no-c-format -msgid "shows purpose and supported data types of all constraints specified in the Bean Validation API. All these constraints apply to the field/property level, there are no class-level constraints defined in the Bean Validation specification. If you are using the Hibernate object-relational mapper, some of the constraints are taken into account when creating the DDL for your model (see column \"Hibernate metadata impact\")." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:546 -#, no-c-format -msgid "Hibernate Validator allows some constraints to be applied to more data types than required by the Bean Validation specification (e.g. @Max can be applied to Strings). Relying on this feature can impact portability of your application between Bean Validation providers." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:567 usingvalidator.xml:827 usingvalidator.xml:1025 -#, no-c-format -msgid "Annotation" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:569 usingvalidator.xml:829 usingvalidator.xml:1027 -#, no-c-format -msgid "Supported data types" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:571 usingvalidator.xml:831 usingvalidator.xml:1029 -#, no-c-format -msgid "Use" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:573 usingvalidator.xml:833 usingvalidator.xml:1033 -#, no-c-format -msgid "Hibernate metadata impact" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:579 -#, no-c-format -msgid "@AssertFalse" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:581 usingvalidator.xml:593 -#, no-c-format -msgid "Boolean, boolean" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:584 -#, no-c-format -msgid "Checks that the annotated element is false." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:587 usingvalidator.xml:599 usingvalidator.xml:619 usingvalidator.xml:639 usingvalidator.xml:675 usingvalidator.xml:733 usingvalidator.xml:749 usingvalidator.xml:762 usingvalidator.xml:789 usingvalidator.xml:849 usingvalidator.xml:863 usingvalidator.xml:900 usingvalidator.xml:913 usingvalidator.xml:926 usingvalidator.xml:942 usingvalidator.xml:959 usingvalidator.xml:976 usingvalidator.xml:994 usingvalidator.xml:1049 usingvalidator.xml:1063 usingvalidator.xml:1078 -#, no-c-format -msgid "none" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:591 -#, no-c-format -msgid "@AssertTrue" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:596 -#, no-c-format -msgid "Checks that the annotated element is true." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:603 -#, no-c-format -msgid "@DecimalMax" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:605 usingvalidator.xml:645 -#, no-c-format -msgid "BigDecimal, BigInteger, String, byte, short, int, long and the respective wrappers of the primitive types. Additionally supported by HV: any sub-type of Number and CharSequence." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:614 -#, no-c-format -msgid "The annotated element must be a number whose value must be lower or equal to the specified maximum. The parameter value is the string representation of the max value according to the BigDecimal string representation." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:623 -#, no-c-format -msgid "@DecimalMin" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:625 -#, no-c-format -msgid "BigDecimal, BigInteger, String, byte, short, int, long and the respective wrappers of the primitive types. Additionally supported by HV: any sub-type of Number and CharSequence." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:634 -#, no-c-format -msgid "The annotated element must be a number whose value must be higher or equal to the specified minimum. The parameter value is the string representation of the min value according to the BigDecimal string representation." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:643 -#, no-c-format -msgid "@Digits(integer=, fraction=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:654 -#, no-c-format -msgid "Checks whether the annoted value is a number having up to integer digits and fraction fractional digits." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:658 -#, no-c-format -msgid "Define column precision and scale." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:662 -#, no-c-format -msgid "@Future" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:664 usingvalidator.xml:739 -#, no-c-format -msgid "java.util.Date, java.util.Calendar; Additionally supported by HV, if the Joda Time date/time API is on the class path: any implementations of ReadablePartial and ReadableInstant." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:672 -#, no-c-format -msgid "Checks whether the annotated date is in the future." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:679 -#, no-c-format -msgid "@Max" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:681 -#, no-c-format -msgid "BigDecimal, BigInteger, byte, short, int, long and the respective wrappers of the primitive types. Additionally supported by HV: any sub-type ofCharSequence (the numeric value represented by the character sequence is evaluated), any sub-type of Number." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:690 -#, no-c-format -msgid "Checks whether the annotated value is less than or equal to the specified maximum." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:693 usingvalidator.xml:711 -#, no-c-format -msgid "Add a check constraint on the column." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:697 -#, no-c-format -msgid "@Min" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:699 -#, no-c-format -msgid "BigDecimal, BigInteger, byte, short, int, long and the respective wrappers of the primitive types. Additionally supported by HV: any sub-type of CharSequence (the numeric value represented by the char sequence is evaluated), any sub-type of Number." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:708 -#, no-c-format -msgid "Checks whether the annotated value is higher than or equal to the specified minimum." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:715 -#, no-c-format -msgid "@NotNull" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:717 usingvalidator.xml:728 usingvalidator.xml:965 -#, no-c-format -msgid "Any type" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:719 -#, no-c-format -msgid "Checks that the annotated value is not null." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:722 -#, no-c-format -msgid "Column(s) are not null." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:726 -#, no-c-format -msgid "@Null" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:730 -#, no-c-format -msgid "Checks that the annotated value is null." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:737 -#, no-c-format -msgid "@Past" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:747 -#, no-c-format -msgid "Checks whether the annotated date is in the past." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:753 -#, no-c-format -msgid "@Pattern(regex=, flag=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:755 -#, no-c-format -msgid "String. Additionally supported by HV: any sub-type of CharSequence." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:758 -#, no-c-format -msgid "Checks if the annotated string matches the regular expression regex considering the given flag match." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:766 -#, no-c-format -msgid "@Size(min=, max=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:768 -#, no-c-format -msgid "String, Collection, Map and arrays. Additionally supported by HV: any sub-type of CharSequence." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:773 -#, no-c-format -msgid "Checks if the annotated element's size is between min and max (inclusive)." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:776 usingvalidator.xml:875 -#, no-c-format -msgid "Column length will be set to max." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:780 -#, no-c-format -msgid "@Valid" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:782 -#, no-c-format -msgid "Any non-primitive type" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:784 -#, no-c-format -msgid "Performs validation recursively on the associated object. If the object is a collection or an array, the elements are validated recursively. If the object is a map, the value elements are validated recursively." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:796 -#, no-c-format -msgid "On top of the parameters indicated in each constraint supports the parameters message, groups and payload. This is a requirement of the Bean Validation specification." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:805 -#, no-c-format -msgid "Additional constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:807 -#, no-c-format -msgid "In addition to the constraints defined by the Bean Validation API Hibernate Validator provides several useful custom constraints which are listed in . With one exception also these constraints apply to the field/property level, only @ScriptAssert is a class-level constraint." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:814 -#, no-c-format -msgid "Custom constraints" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:839 -#, no-c-format -msgid "@CreditCardNumber" -msgstr "" - -#. Tag: classname -#: usingvalidator.xml:841 usingvalidator.xml:855 usingvalidator.xml:869 usingvalidator.xml:882 usingvalidator.xml:906 usingvalidator.xml:948 usingvalidator.xml:982 usingvalidator.xml:1041 usingvalidator.xml:1055 usingvalidator.xml:1069 -#, no-c-format -msgid "CharSequence" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:843 -#, no-c-format -msgid "Checks that the annotated character sequence passes the Luhn checksum test. Note, this validation aims to check for user mistakes, not credit card validity! See also Anatomy of Credit Card Numbers." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:853 -#, no-c-format -msgid "@Email" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:857 -#, no-c-format -msgid "Checks whether the specified character sequence is a valid email address. The optional parameters regexp and flags allow to specify an additional regular expression (including regular expression flags) which the email must match." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:867 -#, no-c-format -msgid "@Length(min=, max=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:871 -#, no-c-format -msgid "Validates that the annotated character sequence is between min and max included." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:879 -#, no-c-format -msgid "@ModCheck(modType=, multiplier=, startIndex=, endIndex=, checkDigitPosition=, ignoreNonDigitCharacters=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:884 -#, no-c-format -msgid "Checks that the digits within the annotated character sequence pass the mod 10 or mod 11 checksum algorithm. modType is used to select the modulo type and the multiplier determines the algorithm specific multiplier (see also Luhn algorithm). startIndex and endIndex allow to only run the modulo algorithm on the specified sub-string. checkDigitPosition allows to use an arbitrary digit within the character sequence to be the check digit. If not specified it is assumed that the check digit is part of the specified range. Last but not least, ignoreNonDigitCharacters allows to ignore non digit characters." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:904 -#, no-c-format -msgid "@NotBlank" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:908 -#, no-c-format -msgid "Checks that the annotated character sequence is not null and the trimmed length is greater than 0. The difference to @NotEmpty is that this constraint can only be applied on strings and that trailing whitespaces are ignored." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:917 -#, no-c-format -msgid "@NotEmpty" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:919 -#, no-c-format -msgid "CharSequence, Collection, Map and arrays" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:923 -#, no-c-format -msgid "Checks whether the annotated element is not null nor empty." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:930 -#, no-c-format -msgid "@Range(min=, max=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:932 -#, no-c-format -msgid "BigDecimal, BigInteger, CharSequence, byte, short, int, long and the respective wrappers of the primitive types" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:939 -#, no-c-format -msgid "Checks whether the annotated value lies between (inclusive) the specified minimum and maximum." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:946 -#, no-c-format -msgid "@SafeHtml(whitelistType=, additionalTags=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:950 -#, no-c-format -msgid "Checks whether the annotated value contains potentially malicious fragments such as <script/>. In order to use this constraint, the jsoup library must be part of the class path. With the whitelistType attribute predefined whitelist types can be chosen. You can also specify additional html tags for the whitelist with the additionalTags attribute." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:963 -#, no-c-format -msgid "@ScriptAssert(lang=, script=, alias=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:967 -#, no-c-format -msgid "Checks whether the given script can successfully be evaluated against the annotated element. In order to use this constraint, an implementation of the Java Scripting API as defined by JSR 223 (\"Scripting for the JavaTM Platform\") must part of the class path. The expressions to be evaluated can be written in any scripting or expression language, for which a JSR 223 compatible engine can be found in the class path." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:980 -#, no-c-format -msgid "@URL(protocol=, host=, port=, regexp=, flags=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:984 -#, no-c-format -msgid "Checks if the annotated character sequence is a valid URL according to RFC2396. If any of the optional parameters protocol, host or port are specified, the corresponding URL fragments must match the specified values. The optional parameters regexp and flags allow to specify an additional regular expression (including regular expression flags) which the URL must match." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:1001 -#, no-c-format -msgid "Country specific constraints" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:1003 -#, no-c-format -msgid "Hibernate Validator offers also some country specific constraints, e.g. for the validation of social security numbers." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:1005 -#, no-c-format -msgid "If you have to implement a country specific constraint, consider making it a contribution to Hibernate Validator!" -msgstr "" - -#. Tag: title -#: usingvalidator.xml:1010 -#, no-c-format -msgid "Custom country specific constraints" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1031 -#, no-c-format -msgid "Country" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1039 -#, no-c-format -msgid "@CNPJ" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1043 -#, no-c-format -msgid "Checks that the annotated character sequence represents a Brazilian corporate tax payer registry number (Cadastro de Pessoa Juríeddica)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1047 usingvalidator.xml:1061 usingvalidator.xml:1076 -#, no-c-format -msgid "Brazil" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1053 -#, no-c-format -msgid "@CPF" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1057 -#, no-c-format -msgid "Checks that the annotated character sequence represents a Brazilian individual taxpayer registry number (Cadastro de Pessoa Fídsica)." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1067 -#, no-c-format -msgid "@TituloEleitoral" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1071 -#, no-c-format -msgid "Checks that the annotated character sequence represents a Brazilian voter ID card number (Título Eleitoral)." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:1085 -#, no-c-format -msgid "In some cases neither the Bean Validation constraints nor the custom constraints provided by Hibernate Validator will fulfill your requirements. In this case you can easily write your own constraint. We will discuss this in ." -msgstr "" - diff --git a/documentation/src/main/docbook/pot/modules/xml-configuration.pot b/documentation/src/main/docbook/pot/modules/xml-configuration.pot deleted file mode 100644 index 29d55f8a03..0000000000 --- a/documentation/src/main/docbook/pot/modules/xml-configuration.pot +++ /dev/null @@ -1,224 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: xml-configuration.xml:24 -#, no-c-format -msgid "Configuring via XML" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:26 -#, no-c-format -msgid "So far we have used the default configuration source for Bean Validation, namely annotations. However, there also exist two kinds of XML descriptors allowing configuration via XML. The first descriptor describes general Bean Validation behaviour and is provided as META-INF/validation.xml. The second one describes constraint declarations and closely matches the constraint declaration approach via annotations. Let's have a look at these two document types." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:34 -#, no-c-format -msgid "The xsd files are available via http://www.jboss.org/xml/ns/javax/validation/configuration and http://www.jboss.org/xml/ns/javax/validation/mapping." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:41 -#, no-c-format -msgid "Configuring ValidationFactory in validation.xml" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:44 -#, no-c-format -msgid "The key to enable XML configuration for Hibernate Validator is the file META-INF/validation.xml. If this file exists on the classpath its configuration will be applied when the ValidationFactory gets created. shows a model view of the XML schema to which validation.xml has to adhere." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:51 -#, no-c-format -msgid "validation-configuration-1.1.xsd" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:67 -#, no-c-format -msgid "shows the several configuration options of validation.xml. All settings are optional and the same configuration options are also available programmatically through javax.validation.Configuration. In fact the XML configuration will be overridden by values explicitly specified via the programmatic API. It is even possible to ignore the XML configuration completely via Configuration.ignoreXmlConfiguration(). See also ." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:79 -#, no-c-format -msgid "validation.xml" -msgstr "" - -#. Tag: programlisting -#: xml-configuration.xml:81 -#, no-c-format -msgid "" - "<validation-config\n" - " xmlns=\"http://jboss.org/xml/ns/javax/validation/configuration\"\n" - " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" - " xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/configuration\">\n" - "\n" - " <default-provider>com.acme.ValidationProvider</default-provider>\n" - "\n" - " <message-interpolator>com.acme.MessageInterpolator</message-interpolator>\n" - " <traversable-resolver>com.acme.TraversableResolver</traversable-resolver>\n" - " <constraint-validator-factory>\n" - " com.acme.ConstraintValidatorFactory\n" - " </constraint-validator-factory>\n" - " <parameter-name-provider>com.acme.ParameterNameProvider</parameter-name-provider>\n" - "\n" - " <executable-validation enabled=\"true\">\n" - " <default-validated-executable-types>\n" - " <executable-type>CONSTRUCTORS</executable-type>\n" - " <executable-type>NON_GETTER_METHODS</executable-type>\n" - " <executable-type>GETTER_METHODS</executable-type>\n" - " </default-validated-executable-types>\n" - " </executable-validation>\n" - "\n" - " <constraint-mapping>META-INF/validation/constraints-car.xml</constraint-mapping>\n" - "\n" - " <property name=\"hibernate.validator.fail_fast\">false</property>\n" - "</validation-config>" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:85 -#, no-c-format -msgid "There must only be one file named META-INF/validation.xml on the classpath. If more than one is found an exception is thrown." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:90 -#, no-c-format -msgid "The node default-provider allows to choose the Bean Validation provider. This is useful if there is more than one provider on the classpath. message-interpolator, traversable-resolver, constraint-validator-factory and parameter-name-provider allow to customize the used implementations for the interfaces MessageInterpolator, TraversableResolver, ConstraintValidatorFactory and ParameterNameProvider defined in the javax.validation package. See the sub-sections of for more information about these interfaces." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:105 -#, no-c-format -msgid "executable-validation and its subnodes define defaults for method validation. The Bean Validation specification defines constructor and non getter methods as defaults. The enabled attribute acts as global switch to turn method validation on and off (see also )." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:112 -#, no-c-format -msgid "Via the constraint-mapping element you can list an arbitrary number of additional XML files containing the actual constraint configuration. Mapping file names must be specified using their fully-qualified name on the classpath. Details on writing mapping files can be found in the next section." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:118 -#, no-c-format -msgid "Last but not least, you can specify provider specific properties via the property nodes. In the example we are using the Hibernate Validator specific hibernate.validator.fail_fast property (see )." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:126 -#, no-c-format -msgid "Mapping constraints via constraint-mappings" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:129 -#, no-c-format -msgid "Expressing constraints in XML is possible via files adhering to the schema seen in . Note that these mapping files are only processed if listed via constraint-mapping in validation.xml." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:136 -#, no-c-format -msgid "validation-mapping-1.1.xsd" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:151 -#, no-c-format -msgid "shows how our classes Car and RentalCar from resp. could be mapped in XML. Example x shows how method validation from example y can be expressed in xml. (TODO create example)" -msgstr "" - -#. Tag: title -#: xml-configuration.xml:158 -#, no-c-format -msgid "constraints.xml" -msgstr "" - -#. Tag: programlisting -#: xml-configuration.xml:160 -#, no-c-format -msgid "" - "<constraint-mappings\n" - " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" - " xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.1.xsd\"\n" - " xmlns=\"http://jboss.org/xml/ns/javax/validation/mapping\" version=\"1.1\">\n" - "\n" - " <default-package>org.hibernate.validator.quickstart</default-package>\n" - " <bean class=\"Car\" ignore-annotations=\"true\">\n" - " <field name=\"manufacturer\">\n" - " <constraint annotation=\"javax.validation.constraints.NotNull\"/>\n" - " </field>\n" - " <field name=\"licensePlate\">\n" - " <constraint annotation=\"javax.validation.constraints.NotNull\"/>\n" - " </field>\n" - " <field name=\"seatCount\">\n" - " <constraint annotation=\"javax.validation.constraints.Min\">\n" - " <element name=\"value\">2</element>\n" - " </constraint>\n" - " </field>\n" - " <field name=\"driver\">\n" - " <valid/>\n" - " </field>\n" - " <getter name=\"passedVehicleInspection\" ignore-annotations=\"true\">\n" - " <constraint annotation=\"javax.validation.constraints.AssertTrue\">\n" - " <message>The car has to pass the vehicle inspection first</message>\n" - " <groups>\n" - " <value>CarChecks</value>\n" - " </groups>\n" - " <element name=\"max\">10</element>\n" - " </constraint>\n" - " </getter>\n" - " </bean>\n" - " <bean class=\"RentalCar\" ignore-annotations=\"true\">\n" - " <class ignore-annotations=\"true\">\n" - " <group-sequence>\n" - " <value>RentalCar</value>\n" - " <value>CarChecks</value>\n" - " </group-sequence>\n" - " </class>\n" - " </bean>\n" - " <constraint-definition annotation=\"org.mycompany.CheckCase\">\n" - " <validated-by include-existing-validators=\"false\">\n" - " <value>org.mycompany.CheckCaseValidator</value>\n" - " </validated-by>\n" - " </constraint-definition>\n" - "</constraint-mappings>" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:163 -#, no-c-format -msgid "The XML configuration is closely mirroring the programmatic API. For this reason it should suffice to just add some comments. default-package is used for all fields where a class name is expected. If the specified class is not fully qualified the configured default package will be used. Every mapping file can then have several bean nodes, each describing the constraints on the entity with the specified class name. A given entity can only be configured once across all configuration files. The same applies for constraint definitions for a given constraint annotation. It can only occur in one mapping file. If these rules are violated a ValidationException is thrown. Setting ignore-annotations to true means that constraint annotations placed on the configured bean are ignored. The default for this value is true. ignore-annotations is also available for the nodes class, fields and getter. If not explicitly specified on these levels the configured bean value applies. Otherwise do the nodes class, fields and getter determine on which level the constraints are placed (see ). The constraint node is then used to add a constraint on the corresponding level. Each constraint definition must define the class via the annotation attribute. The constraint attributes required by the Bean Validation specification (message, groups and payload) have dedicated nodes. All other constraint specific attributes are configured using the element node." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:194 -#, no-c-format -msgid "The class node also allows to reconfigure the default group sequence (see ) via the group-sequence node." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:198 -#, no-c-format -msgid "Last but not least, the list of ConstraintValidators associated to a given constraint can be altered via the constraint-definition node. The annotation attribute represents the constraint annotation being altered. The validated-by elements represent the (ordered) list of ConstraintValidator implementations associated to the constraint. If include-existing-validator is set to false, validators defined on the constraint annotation are ignored. If set to true, the list of constraint validators described in XML is concatenated to the list of validators specified on the annotation." -msgstr "" diff --git a/documentation/src/main/docbook/pot/modules/xmlconfiguration.pot b/documentation/src/main/docbook/pot/modules/xmlconfiguration.pot deleted file mode 100644 index fc5c31f309..0000000000 --- a/documentation/src/main/docbook/pot/modules/xmlconfiguration.pot +++ /dev/null @@ -1,200 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-03 09:59+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: xmlconfiguration.xml:24 -#, no-c-format -msgid "XML configuration" -msgstr "" - -#. Tag: filename -#: xmlconfiguration.xml:27 -#, no-c-format -msgid "validation.xml" -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:29 -#, no-c-format -msgid "The key to enable XML configuration for Hibernate Validator is the file META-INF/validation.xml. If this file exists on the classpath its configuration will be applied when the ValidationFactory gets created. shows a model view of the XML schema to which validation.xml has to adhere." -msgstr "" - -#. Tag: title -#: xmlconfiguration.xml:36 -#, no-c-format -msgid "validation-configuration-1.0.xsd" -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:51 -#, no-c-format -msgid "shows the several configuration options of validation.xml." -msgstr "" - -#. Tag: title -#: xmlconfiguration.xml:55 -#, no-c-format -msgid "validation.xml" -msgstr "" - -#. Tag: programlisting -#: xmlconfiguration.xml:57 -#, no-c-format -msgid "" - "<validation-config\n" - " xmlns=\"http://jboss.org/xml/ns/javax/validation/configuration\"\n" - " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" - " xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/configuration\">\n" - "\n" - " <default-provider>org.hibernate.validator.HibernateValidator</default-provider>\n" - " <message-interpolator>org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator</message-interpolator>\n" - " <traversable-resolver>org.hibernate.validator.engine.resolver.DefaultTraversableResolver</traversable-resolver>\n" - " <constraint-validator-factory>org.hibernate.validator.engine.ConstraintValidatorFactoryImpl</constraint-validator-factory>\n" - " <constraint-mapping>META-INF/validation/constraints-car.xml</constraint-mapping>\n" - " <property name=\"prop1\">value1</property>\n" - " <property name=\"prop2\">value2</property>\n" - "</validation-config>" -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:61 -#, no-c-format -msgid "There must only be one file named META-INF/validation.xml on the classpath. If more than one is found an exception is thrown." -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:66 -#, no-c-format -msgid "The node default-provider allows to choose the Bean Validation provider. This is useful if there is more than one provider on the classpath. message-interpolator, traversable-resolver and constraint-validator-factory allow to customize the used implementations for javax.validation.MessageInterpolator, javax.validation.TraversableResolver resp. javax.validation.ConstraintValidatorFactory." -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:76 -#, no-c-format -msgid "All these settings are optional. shows the defaults used within Hibernate Validator. The same configuration options are also available programmatically through javax.validation.Configuration. In fact XML configuration will be overridden by values explicitly specified via the API. It is even possible to ignore the XML configuration completely via Configuration.ignoreXmlConfiguration(). See also ." -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:86 -#, no-c-format -msgid "Via the constraint-mapping element you can list an arbitrary number of additional XML files containing the actual constraint configuration. Mapping file names must be specified using their fully-qualified name on the classpath. Details on writing mapping files can be found in the next section." -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:92 -#, no-c-format -msgid "Last but not least, you can specify provider specific properties via the property nodes." -msgstr "" - -#. Tag: title -#: xmlconfiguration.xml:97 -#, no-c-format -msgid "Mapping constraints" -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:99 -#, no-c-format -msgid "Expressing constraints in XML is possible via files adhering to the schema seen in . Note that these mapping files are only processed if listed via constraint-mapping in your validation.xml." -msgstr "" - -#. Tag: title -#: xmlconfiguration.xml:106 -#, no-c-format -msgid "validation-mapping-1.0.xsd" -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:121 -#, no-c-format -msgid "shows how our classes Car and RentalCar from resp. could be mapped in XML." -msgstr "" - -#. Tag: title -#: xmlconfiguration.xml:127 -#, no-c-format -msgid "constraints-car.xml" -msgstr "" - -#. Tag: programlisting -#: xmlconfiguration.xml:129 -#, no-c-format -msgid "" - "<constraint-mappings\n" - " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" - " xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd\"\n" - " xmlns=\"http://jboss.org/xml/ns/javax/validation/mapping\">\n" - "\n" - " <default-package>org.hibernate.validator.quickstart</default-package>\n" - " <bean class=\"Car\" ignore-annotations=\"true\">\n" - " <field name=\"manufacturer\">\n" - " <constraint annotation=\"javax.validation.constraints.NotNull\"/>\n" - " </field>\n" - " <field name=\"licensePlate\">\n" - " <constraint annotation=\"javax.validation.constraints.NotNull\"/>\n" - " </field>\n" - " <field name=\"seatCount\">\n" - " <constraint annotation=\"javax.validation.constraints.Min\">\n" - " <element name=\"value\">2</element>\n" - " </constraint>\n" - " </field>\n" - " <field name=\"driver\">\n" - " <valid/>\n" - " </field>\n" - " <getter name=\"passedVehicleInspection\" ignore-annotations=\"true\">\n" - " <constraint annotation=\"javax.validation.constraints.AssertTrue\">\n" - " <message>The car has to pass the vehicle inspection first</message>\n" - " <groups>\n" - " <value>CarChecks</value>\n" - " </groups>\n" - " <element name=\"max\">10</element>\n" - " </constraint>\n" - " </getter>\n" - " </bean>\n" - " <bean class=\"RentalCar\" ignore-annotations=\"true\">\n" - " <class ignore-annotations=\"true\">\n" - " <group-sequence>\n" - " <value>RentalCar</value>\n" - " <value>CarChecks</value>\n" - " </group-sequence>\n" - " </class>\n" - " </bean>\n" - " <constraint-definition annotation=\"org.mycompany.CheckCase\">\n" - " <validated-by include-existing-validators=\"false\">\n" - " <value>org.mycompany.CheckCaseValidator</value>\n" - " </validated-by>\n" - " </constraint-definition>\n" - "</constraint-mappings>" -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:132 -#, no-c-format -msgid "The XML configuration is closely mirroring the programmatic API. For this reason it should suffice to just add some comments. default-package is used for all fields where a class name is expected. If the specified class is not fully qualified the configured default package will be used. Every mapping file can then have several bean nodes, each describing the constraints on the entity with the specified class name. A given entity can only be configured once across all configuration files. If the same class is configured more than once an exception is thrown. Setting ignore-annotations to true means that constraint annotations placed on the configured bean are ignored. The default for this value is true. ignore-annotations is also available for the nodes class, fields and getter. If not explicitly specified on these levels the configured bean value applies. Otherwise do the nodes class, fields and getter determine on which level the constraints are placed (see ). The constraint node is then used to add a constraint on the corresponding level. Each constraint definition must define the class via the annotation attribute. The constraint attributes required by the Bean Validation specification (message, groups and payload) have dedicated nodes. All other constraint specific attributes are configured using the element node." -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:161 -#, no-c-format -msgid "The class node also allows to reconfigure the default group sequence (see ) via the group-sequence node." -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:165 -#, no-c-format -msgid "Last but not least, the list of ConstraintValidators associated to a given constraint can be altered via the constraint-definition node. The annotation attribute represents the constraint annotation being altered. The validated-by elements represent the (ordered) list of ConstraintValidator implementations associated to the constraint. If include-existing-validator is set to false, validators defined on the constraint annotation are ignored. If set to true, the list of constraint validators described in XML is concatenated to the list of validators specified on the annotation." -msgstr "" - diff --git a/documentation/src/main/docbook/zh-CN/master.po b/documentation/src/main/docbook/zh-CN/master.po deleted file mode 100644 index dedcfc72a8..0000000000 --- a/documentation/src/main/docbook/zh-CN/master.po +++ /dev/null @@ -1,65 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2010-08-14 14:38+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: master.xml:25 -#, no-c-format -msgid "Hibernate Validator" -msgstr "Hibernate Validator" - -#. Tag: subtitle -#: master.xml:27 -#, fuzzy, no-c-format -msgid "JSR 349 Reference Implementation" -msgstr "JSR 303 的参考实现" - -#. Tag: subtitle -#: master.xml:29 -#, no-c-format -msgid "Reference Guide" -msgstr "使用指南" - -#. Tag: releaseinfo -#: master.xml:31 -#, no-c-format -msgid "&version;" -msgstr "" - -#. Tag: holder -#: master.xml:40 -#, no-c-format -msgid "©rightHolder;" -msgstr "©rightHolder;" - -#. Tag: author -#: master.xml:44 -#, no-c-format -msgid "Hardy Ferentschik" -msgstr "Hardy Ferentschik" - -#. Tag: author -#: master.xml:50 -#, no-c-format -msgid "Gunnar Morling" -msgstr "Gunnar Morling" - -#. Tag: othercredit -#: master.xml:56 -#, fuzzy, no-c-format -msgid "" -"Shaozhuang Liu " -"stliu@hibernate.org" -msgstr "Gunnar Morling" diff --git a/documentation/src/main/docbook/zh-CN/modules/annotation-processor.po b/documentation/src/main/docbook/zh-CN/modules/annotation-processor.po deleted file mode 100644 index 5e62d5b24c..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/annotation-processor.po +++ /dev/null @@ -1,656 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: annotation-processor.xml:24 -#, no-c-format -msgid "Annotation Processor" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:26 -#, no-c-format -msgid "Have you ever caught yourself by unintentionally doing things like" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:31 -#, no-c-format -msgid "" -"specifying constraint annotations at unsupported data types (e.g. by " -"annotating a String with @Past)" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:36 -#, no-c-format -msgid "" -"annotating the setter of a JavaBeans property (instead of the getter method)" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:41 -#, no-c-format -msgid "" -"annotating static fields/methods with constraint annotations (which is not " -"supported)?" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:46 -#, no-c-format -msgid "" -"Then the Hibernate Validator Annotation Processor is the right thing for " -"you. It helps preventing such mistakes by plugging into the build process " -"and raising compilation errors whenever constraint annotations are " -"incorrectly used." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:52 -#, no-c-format -msgid "" -"You can find the Hibernate Validator Annotation Processor as part of the " -"distribution bundle on Sourceforge or in the usual " -"Maven repositories such as Maven Central under the GAV org.hibernate:" -"hibernate-validator-annotation-processor:&version;." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:60 -#, no-c-format -msgid "Prerequisites" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:62 -#, no-c-format -msgid "" -"The Hibernate Validator Annotation Processor is based on the \"Pluggable " -"Annotation Processing API\" as defined by JSR 269 which is part of the Java Platform since " -"Java 6." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:69 -#, no-c-format -msgid "Features" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:71 -#, no-c-format -msgid "" -"As of Hibernate Validator &version; the Hibernate Validator Annotation " -"Processor checks that:" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:76 -#, no-c-format -msgid "" -"constraint annotations are allowed for the type of the annotated element" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:81 -#, no-c-format -msgid "" -"only non-static fields or methods are annotated with constraint annotations" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:86 -#, no-c-format -msgid "only non-primitive fields or methods are annotated with @Valid" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:91 -#, no-c-format -msgid "" -"only such methods are annotated with constraint annotations which are valid " -"JavaBeans getter methods (optionally, see below)" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:97 -#, no-c-format -msgid "" -"only such annotation types are annotated with constraint annotations which " -"are constraint annotations themselves" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:102 -#, no-c-format -msgid "" -"definition of dynamic default group sequence with @GroupSequenceProvider is " -"valid" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:109 -#, no-c-format -msgid "Options" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:111 -#, no-c-format -msgid "" -"The behavior of the Hibernate Validator Annotation Processor can be " -"controlled using the processor options " -"listed in table :" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:118 -#, no-c-format -msgid "Hibernate Validator Annotation Processor options" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:123 -#, no-c-format -msgid "Option" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:125 -#, no-c-format -msgid "Explanation" -msgstr "" - -#. Tag: varname -#: annotation-processor.xml:131 -#, no-c-format -msgid "diagnosticKind" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:133 -#, no-c-format -msgid "" -"Controls how constraint problems are reported. Must be the string " -"representation of one of the values from the enum javax.tools." -"Diagnostic.Kind, e.g. WARNING. A value of " -"ERROR will cause compilation to halt whenever the AP " -"detects a constraint problem. Defaults to ERROR." -msgstr "" - -#. Tag: varname -#: annotation-processor.xml:143 -#, no-c-format -msgid "methodConstraintsSupported" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:145 -#, no-c-format -msgid "" -"Controls whether constraints are allowed at methods of any kind. Must be set " -"to true when working with method level constraints as " -"supported by Hibernate Validator. Can be set to false to " -"allow constraints only at JavaBeans getter methods as defined by the Bean " -"Validation API. Defaults to true." -msgstr "" - -#. Tag: varname -#: annotation-processor.xml:154 -#, no-c-format -msgid "verbose" -msgstr "" - -#. Tag: entry -#: annotation-processor.xml:156 -#, no-c-format -msgid "" -"Controls whether detailed processing information shall be displayed or not, " -"useful for debugging purposes. Must be either true or " -"false. Defaults to false." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:167 -#, no-c-format -msgid "Using the Annotation Processor" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:169 -#, no-c-format -msgid "" -"This section shows in detail how to integrate the Hibernate Validator " -"Annotation Processor into command line builds (javac, Ant, Maven) as well as " -"IDE-based builds (Eclipse, IntelliJ IDEA, NetBeans)." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:175 -#, no-c-format -msgid "Command line builds" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:178 -#, no-c-format -msgid "javac" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:180 -#, no-c-format -msgid "" -"When compiling on the command line using javac, specify the " -"JAR hibernate-validator-annotation-processor-&version;.jar using the " -"\"processorpath\" option as shown in the following listing. The processor " -"will be detected automatically by the compiler and invoked during " -"compilation." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:188 -#, no-c-format -msgid "Using the annotation processor with javac" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:190 -#, no-c-format -msgid "" -"javac src/main/java/org/hibernate/validator/ap/demo/Car.java \\\n" -" -cp /path/to/validation-api-&bvVersion;.jar \\\n" -" -processorpath /path/to/hibernate-validator-annotation-processor-" -"&version;.jar" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:195 -#, no-c-format -msgid "Apache Ant" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:197 -#, no-c-format -msgid "" -"Similar to directly working with javac, the annotation processor can be " -"added as as compiler argument when invoking the javac task for Apache Ant:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:204 -#, no-c-format -msgid "Using the annotation processor with Ant" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:206 -#, no-c-format -msgid "" -"<javac srcdir=\"src/main\"\n" -" destdir=\"build/classes\"\n" -" classpath=\"/path/to/validation-api-&bvVersion;.jar\">\n" -" <compilerarg value=\"-processorpath\" />\n" -" <compilerarg value=\"/path/to/hibernate-validator-annotation-" -"processor-&version;.jar\"/>\n" -"</javac>" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:211 -#, no-c-format -msgid "Maven" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:213 -#, no-c-format -msgid "" -"There are several options for integrating the annotation processor with " -"Apache Maven. Generally it " -"is sufficient to add the Hibernate Validator Annotation Processor as " -"dependency to your project:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:219 -#, no-c-format -msgid "Adding the HV Annotation Processor as dependency" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:221 -#, no-c-format -msgid "" -"...\n" -"<dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator-annotation-processor</" -"artifactId>\n" -" <version>&version;</version>\n" -"</dependency>\n" -"..." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:224 -#, no-c-format -msgid "" -"The processor will then be executed automatically by the compiler. This " -"basically works, but comes with the disadavantage that in some cases " -"messages from the annotation processor are not displayed (see MCOMPILER-66)." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:230 -#, no-c-format -msgid "" -"Another option is using the Maven Annotation Plugin. At the time of this " -"writing the plugin is not yet available in any of the well-known " -"repositories. Therefore you have to add the project's own repository to your " -"settings.xml or pom.xml:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:238 -#, no-c-format -msgid "Adding the Maven Annotation Plugin repository" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:240 -#, no-c-format -msgid "" -"...\n" -"<pluginRepositories>\n" -" <pluginRepository>\n" -" <id>maven-annotation-plugin-repo</id>\n" -" <url>http://maven-annotation-plugin.googlecode.com/svn/trunk/" -"mavenrepo</url>\n" -" </pluginRepository>\n" -"</pluginRepositories>\n" -"..." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:243 -#, no-c-format -msgid "" -"Now disable the standard annotation processing performed by the compiler " -"plugin and configure the annotation plugin by specifying an execution and " -"adding the Hibernate Validator Annotation Processor as plugin dependency " -"(that way the AP is not visible on the project's actual classpath):" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:250 -#, no-c-format -msgid "Configuring the Maven Annotation Plugin" -msgstr "" - -#. Tag: programlisting -#: annotation-processor.xml:252 -#, no-c-format -msgid "" -"...\n" -"<plugin>\n" -" <artifactId>maven-compiler-plugin</artifactId>\n" -" <configuration>\n" -" <source>1.6</source>\n" -" <target>1.6</target>\n" -" <compilerArgument>-proc:none</compilerArgument>\n" -" </configuration>\n" -"</plugin>\n" -"<plugin>\n" -" <groupId>org.bsc.maven</groupId>\n" -" <artifactId>maven-processor-plugin</artifactId>\n" -" <version>1.3.4</version>\n" -" <executions>\n" -" <execution>\n" -" <id>process</id>\n" -" <goals>\n" -" <goal>process</goal>\n" -" </goals>\n" -" <phase>process-sources</phase>\n" -" </execution>\n" -" </executions>\n" -" <dependencies>\n" -" <dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator-annotation-processor</" -"artifactId>\n" -" <version>&version;</version>\n" -" </dependency>\n" -" </dependencies>\n" -"</plugin>\n" -"..." -msgstr "" - -#. Tag: title -#: annotation-processor.xml:258 -#, no-c-format -msgid "IDE builds" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:261 -#, no-c-format -msgid "Eclipse" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:263 -#, no-c-format -msgid "" -"Do the following to use the annotation processor within the Eclipse IDE:" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:268 annotation-processor.xml:360 -#, no-c-format -msgid "Right-click your project, choose \"Properties\"" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:272 -#, no-c-format -msgid "" -"Go to \"Java Compiler\" and make sure, that \"Compiler compliance level\" is " -"set to \"1.6\". Otherwise the processor won't be activated" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:278 -#, no-c-format -msgid "" -"Go to \"Java Compiler - Annotation Processing\" and choose \"Enable " -"annotation processing\"" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:283 -#, no-c-format -msgid "" -"Go to \"Java Compiler - Annotation Processing - Factory Path\" and add the " -"JAR hibernate-validator-annotation-processor-&version;.jar" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:289 -#, no-c-format -msgid "Confirm the workspace rebuild" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:293 -#, no-c-format -msgid "" -"You now should see any annotation problems as regular error markers within " -"the editor and in the \"Problem\" view:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:305 -#, no-c-format -msgid "IntelliJ IDEA" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:307 -#, no-c-format -msgid "" -"The following steps must be followed to use the annotation processor within " -"IntelliJ IDEA (version " -"9 and above):" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:313 -#, no-c-format -msgid "Go to \"File\", then \"Settings\"," -msgstr "" - -#. Tag: para -#: annotation-processor.xml:317 -#, no-c-format -msgid "Expand the node \"Compiler\", then \"Annotation Processors\"" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:322 -#, no-c-format -msgid "" -"Choose \"Enable annotation processing\" and enter the following as " -"\"Processor path\": /path/to/hibernate-validator-annotation-processor-" -"&version;.jar" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:328 -#, no-c-format -msgid "" -"Add the processor's fully qualified name org.hibernate.validator." -"ap.ConstraintValidationProcessor to the \"Annotation Processors" -"\" list" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:334 -#, no-c-format -msgid "If applicable add you module to the \"Processed Modules\" list" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:339 -#, no-c-format -msgid "" -"Rebuilding your project then should show any erronous constraint annotations:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:351 -#, no-c-format -msgid "NetBeans" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:353 -#, no-c-format -msgid "" -"Starting with version 6.9, also the NetBeans IDE supports using annotation processors within the IDE " -"build. To do so, do the following:" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:364 -#, no-c-format -msgid "" -"Go to \"Libraries\", tab \"Processor\", and add the JAR hibernate-validator-" -"annotation-processor-&version;.jar" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:369 -#, no-c-format -msgid "" -"Go to \"Build - Compiling\", select \"Enable Annotation Processing\" and " -"\"Enable Annotation Processing in Editor\". Add the annotation processor by " -"specifying its fully qualified name org.hibernate.validator.ap." -"ConstraintValidationProcessor" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:376 -#, no-c-format -msgid "" -"Any constraint annotation problems will then be marked directly within the " -"editor:" -msgstr "" - -#. Tag: title -#: annotation-processor.xml:390 -#, no-c-format -msgid "Known issues" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:392 -#, no-c-format -msgid "The following known issues exist as of May 2010:" -msgstr "" - -#. Tag: para -#: annotation-processor.xml:396 -#, no-c-format -msgid "" -"HV-308: Additional validators registered for a constraint " -"using XML are not evaluated by the annotation " -"processor." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:404 -#, no-c-format -msgid "" -"Sometimes custom constraints can't be properly evaluated " -"when using the processor within Eclipse. Cleaning the project can help in " -"these situations. This seems to be an issue with the Eclipse JSR 269 API " -"implementation, but further investigation is required here." -msgstr "" - -#. Tag: para -#: annotation-processor.xml:413 -#, no-c-format -msgid "" -"When using the processor within Eclipse, the check of dynamic default group " -"sequence definitions doesn't work. After further investigation, it seems to " -"be an issue with the Eclipse JSR 269 API implementation." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/annotationprocessor.po b/documentation/src/main/docbook/zh-CN/modules/annotationprocessor.po deleted file mode 100644 index 60a544203f..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/annotationprocessor.po +++ /dev/null @@ -1,841 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2012-05-09 09:42+0000\n" -"PO-Revision-Date: 2010-08-24 00:50+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: annotationprocessor.xml:24 -#, fuzzy, no-c-format -msgid "Annotation Processor" -msgstr "使用标注处理器" - -#. Tag: para -#: annotationprocessor.xml:26 -#, no-c-format -msgid "Have you ever caught yourself by unintentionally doing things like" -msgstr "你碰到过下面这些让人抓狂的情况么:" - -#. Tag: para -#: annotationprocessor.xml:31 -#, no-c-format -msgid "" -"specifying constraint annotations at unsupported data types (e.g. by " -"annotating a String with @Past)" -msgstr "" - -#. Tag: para -#: annotationprocessor.xml:36 -#, no-c-format -msgid "" -"annotating the setter of a JavaBean property (instead of the getter method)" -msgstr "对一个JavaBean的setter方法进行标注(而不是getter)" - -#. Tag: para -#: annotationprocessor.xml:41 -#, no-c-format -msgid "" -"annotating static fields/methods with constraint annotations (which is not " -"supported)?" -msgstr "对一个静态的变量或者方法进行约束条件标注(这样是不支持滴)" - -#. Tag: para -#: annotationprocessor.xml:46 -#, no-c-format -msgid "" -"Then the Hibernate Validator Annotation Processor is the right thing for " -"you. It helps preventing such mistakes by plugging into the build process " -"and raising compilation errors whenever constraint annotations are " -"incorrectly used." -msgstr "" -"这样的话, 你就应该看看Hibernate Validator 的约束处理器了. 它会被插入到编译过" -"程中, 然后如果发现如果哪个约束标注用错了的话, 则汇报编译错误." - -#. Tag: para -#: annotationprocessor.xml:52 -#, no-c-format -msgid "" -"You can find the Hibernate Validator Annotation Processor as part of the " -"distribution bundle on Sourceforge or in the JBoss " -"Maven Repository (see ) under the " -"GAV org.hibernate:hibernate-validator-annotation-processor." -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:61 -#, no-c-format -msgid "Prerequisites" -msgstr "前提条件" - -#. Tag: para -#: annotationprocessor.xml:63 -#, fuzzy, no-c-format -msgid "" -"The Hibernate Validator Annotation Processor is based on the \"Pluggable " -"Annotation Processing API\" as defined by JSR 269 which is part of the Java Platform since " -"Java 6." -msgstr "" -"Hibernate Validator的标注处理器是基于JSR 269所定义的\"可插入式标注处理API\"的. 这个API从" -"Java 6开始已经是Java 平台的一部分了, 所以请确保使用这个或者以后的版本." - -#. Tag: title -#: annotationprocessor.xml:70 -#, no-c-format -msgid "Features" -msgstr "特性" - -#. Tag: para -#: annotationprocessor.xml:72 -#, fuzzy, no-c-format -msgid "" -"As of Hibernate Validator &version; the Hibernate Validator Annotation " -"Processor checks that:" -msgstr "Hibernate Validator 4.1中的标注处理器可以检查:" - -#. Tag: para -#: annotationprocessor.xml:77 -#, no-c-format -msgid "" -"constraint annotations are allowed for the type of the annotated element" -msgstr "应用了约束标注的属性的类型是否被该约束所支持" - -#. Tag: para -#: annotationprocessor.xml:82 -#, fuzzy, no-c-format -msgid "" -"only non-static fields or methods are annotated with constraint annotations" -msgstr "只有非静态字段或者方法才能够应用约束条件标注." - -#. Tag: para -#: annotationprocessor.xml:87 -#, fuzzy, no-c-format -msgid "only non-primitive fields or methods are annotated with @Valid" -msgstr "只有非原始类型的属性或字段才能够应用@Valid标注" - -#. Tag: para -#: annotationprocessor.xml:92 -#, fuzzy, no-c-format -msgid "" -"only such methods are annotated with constraint annotations which are valid " -"JavaBeans getter methods (optionally, see below)" -msgstr "" -"only such annotation types are annotated with constraint annotations which " -"are constraint annotations themselves" - -#. Tag: para -#: annotationprocessor.xml:98 -#, no-c-format -msgid "" -"only such annotation types are annotated with constraint annotations which " -"are constraint annotations themselves" -msgstr "" -"only such annotation types are annotated with constraint annotations which " -"are constraint annotations themselves" - -#. Tag: para -#: annotationprocessor.xml:103 -#, no-c-format -msgid "" -"definition of dynamic default group sequence with @GroupSequenceProvider is " -"valid" -msgstr "" - -#. Tag: title -#: annotationprocessor.xml:110 -#, no-c-format -msgid "Options" -msgstr "配置项" - -#. Tag: para -#: annotationprocessor.xml:112 -#, no-c-format -msgid "" -"The behavior of the Hibernate Validator Annotation Processor can be " -"controlled using the processor options " -"listed in table:" -msgstr "" -"Hibernate Validator标注处理器的行为可以通过中列出的处理器配置项加以控制." - -#. Tag: title -#: annotationprocessor.xml:119 -#, no-c-format -msgid "Hibernate Validator Annotation Processor options" -msgstr "Hibernate Validator 标注处理器配置项" - -#. Tag: entry -#: annotationprocessor.xml:124 -#, no-c-format -msgid "Option" -msgstr "配置项" - -#. Tag: entry -#: annotationprocessor.xml:126 -#, no-c-format -msgid "Explanation" -msgstr "功能" - -#. Tag: varname -#: annotationprocessor.xml:132 -#, no-c-format -msgid "diagnosticKind" -msgstr "diagnosticKind" - -#. Tag: entry -#: annotationprocessor.xml:134 -#, no-c-format -msgid "" -"Controls how constraint problems are reported. Must be the string " -"representation of one of the values from the enum javax.tools." -"Diagnostic.Kind, e.g. WARNING. A value of " -"ERROR will cause compilation to halt whenever the AP " -"detects a constraint problem. Defaults to ERROR." -msgstr "" -"控制编译错误级别. 必须是枚举类型javax.tools.Diagnostic.Kind中的值(字符串形式), 例如WARNING. 如果是" -"ERROR的话, 那么如果API检测到约束信息应用的错误的话, 会" -"让编译过程终止, 默认是ERROR." - -#. Tag: varname -#: annotationprocessor.xml:144 -#, no-c-format -msgid "methodConstraintsSupported" -msgstr "" - -#. Tag: entry -#: annotationprocessor.xml:146 -#, no-c-format -msgid "" -"Controls whether constraints are allowed at methods of any kind. Must be set " -"to true when working with method level constraints as " -"supported by Hibernate Validator. Can be set to false to " -"allow constraints only at JavaBeans getter methods as defined by the Bean " -"Validation API. Defaults to true." -msgstr "" - -#. Tag: varname -#: annotationprocessor.xml:155 -#, no-c-format -msgid "verbose" -msgstr "verbose" - -#. Tag: entry -#: annotationprocessor.xml:157 -#, fuzzy, no-c-format -msgid "" -"Controls whether detailed processing information shall be displayed or not, " -"useful for debugging purposes. Must be either true or " -"false. Defaults to false." -msgstr "" -"控制是否显示详细的处理信息, 对debug有帮助. 它的值只能是truefalse, 默认是false." - -#. Tag: title -#: annotationprocessor.xml:168 -#, no-c-format -msgid "Using the Annotation Processor" -msgstr "使用标注处理器" - -#. Tag: para -#: annotationprocessor.xml:170 -#, no-c-format -msgid "" -"This section shows in detail how to integrate the Hibernate Validator " -"Annotation Processor into command line builds (javac, Ant, Maven) as well as " -"IDE-based builds (Eclipse, IntelliJ IDEA, NetBeans)." -msgstr "" -"本小节详细介绍了如何把Hibernate Validator标注处理器与命令行编译(javac, Ant, " -"Maven)以及IDE (Eclipse, IntelliJ IDEA, NetBeans)集成." - -#. Tag: title -#: annotationprocessor.xml:176 -#, no-c-format -msgid "Command line builds" -msgstr "命令行编译" - -#. Tag: title -#: annotationprocessor.xml:179 -#, no-c-format -msgid "javac" -msgstr "javac" - -#. Tag: para -#: annotationprocessor.xml:181 -#, fuzzy, no-c-format -msgid "" -"When compiling on the command line using javac, specify the " -"JAR hibernate-validator-annotation-processor-&version;.jar using the " -"\"processorpath\" option as shown in the following listing. The processor " -"will be detected automatically by the compiler and invoked during " -"compilation." -msgstr "" -"当使用命令行(javac)编译的时候, 通过\"processorpath\"属性指定下" -"列jar:" - -#. Tag: title -#: annotationprocessor.xml:189 -#, no-c-format -msgid "Using the annotation processor with javac" -msgstr "在javac中使用标注处理器" - -#. Tag: programlisting -#: annotationprocessor.xml:191 -#, fuzzy, no-c-format -msgid "" -"javac src/main/java/org/hibernate/validator/ap/demo/Car.java \\\n" -" -cp /path/to/validation-api-&bvVersion;.jar \\\n" -" -processorpath /path/to/hibernate-validator-annotation-processor-" -"&version;.jar" -msgstr "" -"javac src/main/java/org/hibernate/validator/ap/demo/Car.java \\\n" -" -cp /path/to/validation-api-&bvVersion;.jar \\ \n" -" -processorpath /path/to/validation-api-&bvVersion;.jar:/path/to/hibernate-" -"validator-annotation-processor-&version;.jar" - -#. Tag: title -#: annotationprocessor.xml:196 -#, no-c-format -msgid "Apache Ant" -msgstr "Apache Ant" - -#. Tag: para -#: annotationprocessor.xml:198 -#, no-c-format -msgid "" -"Similar to directly working with javac, the annotation processor can be " -"added as as compiler argument when invoking the javac task for Apache Ant:" -msgstr "" -"和直接使用javac差不多, 可以在Apache " -"Antjavac task中添加上面例子中的参数:" - -#. Tag: title -#: annotationprocessor.xml:205 -#, no-c-format -msgid "Using the annotation processor with Ant" -msgstr "在Ant中使用标注处理器" - -#. Tag: programlisting -#: annotationprocessor.xml:207 -#, fuzzy, no-c-format -msgid "" -"<javac srcdir=\"src/main\"\n" -" destdir=\"build/classes\"\n" -" classpath=\"/path/to/validation-api-&bvVersion;.jar\">\n" -" <compilerarg value=\"-processorpath\" />\n" -" <compilerarg value=\"/path/to/hibernate-validator-annotation-" -"processor-&version;.jar\"/>\n" -"</javac>" -msgstr "" -"<javac srcdir=\"src/main\"\n" -" destdir=\"build/classes\"\n" -" classpath=\"/path/to/validation-api-&bvVersion;.jar\">\n" -" <compilerarg value=\"-processorpath\" />\n" -" <compilerarg value=\"/path/to/validation-api-&bvVersion;.jar:/path/" -"to/hibernate-validator-annotation-processor-&version;.jar\"/>\n" -"</javac>" - -#. Tag: title -#: annotationprocessor.xml:212 -#, no-c-format -msgid "Maven" -msgstr "Maven" - -#. Tag: para -#: annotationprocessor.xml:214 -#, no-c-format -msgid "" -"There are several options for integrating the annotation processor with " -"Apache Maven. Generally it " -"is sufficient to add the Hibernate Validator Annotation Processor as " -"dependency to your project:" -msgstr "" -"对于和Apache Maven集成来说我" -"们有很多选择, 通常, 我们可以把Hibenrate Validator标注处理器作为依赖添加到你的" -"项目当中:" - -#. Tag: title -#: annotationprocessor.xml:220 -#, no-c-format -msgid "Adding the HV Annotation Processor as dependency" -msgstr "添加HV 标注处理器为依赖" - -#. Tag: programlisting -#: annotationprocessor.xml:222 -#, no-c-format -msgid "" -"...\n" -"<dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator-annotation-processor</" -"artifactId>\n" -" <version>&version;</version>\n" -" <scope>compile</scope>\n" -"</dependency>\n" -"..." -msgstr "" -"...\n" -"<dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator-annotation-processor</" -"artifactId>\n" -" <version>&version;</version>\n" -" <scope>compile</scope>\n" -"</dependency>\n" -"..." - -#. Tag: para -#: annotationprocessor.xml:225 -#, no-c-format -msgid "" -"The processor will then be executed automatically by the compiler. This " -"basically works, but comes with the disadavantage that in some cases " -"messages from the annotation processor are not displayed (see MCOMPILER-66)." -msgstr "" -"这样, 这个处理器就能够自动的被编译器所调用. 虽然基本上能工作,但是还是有一些缺" -"点, 在某些情况下, 标注处理器的输出信息可能不能够被显示出来. (请参考MCOMPILER-66)." - -#. Tag: para -#: annotationprocessor.xml:231 -#, no-c-format -msgid "" -"Another option is using the Maven Annotation Plugin. At the time of this " -"writing the plugin is not yet available in any of the well-known " -"repositories. Therefore you have to add the project's own repository to your " -"settings.xml or pom.xml:" -msgstr "" -"另外的一个选择是使用Maven Annotation Plugin. 不过在此文档撰写的时候, 这个插件还" -"没有被上传到任何一个广泛被使用的仓库中. 所以, 你需要自己把这个插件自己的仓库" -"添加到你的settings.xml 或 pom.xml中:" - -#. Tag: title -#: annotationprocessor.xml:239 -#, no-c-format -msgid "Adding the Maven Annotation Plugin repository" -msgstr "添加Maven Annotation Plugin的仓库" - -#. Tag: programlisting -#: annotationprocessor.xml:241 -#, no-c-format -msgid "" -"...\n" -"<pluginRepositories>\n" -" <pluginRepository>\n" -" <id>maven-annotation-plugin-repo</id>\n" -" <url>http://maven-annotation-plugin.googlecode.com/svn/trunk/" -"mavenrepo</url>\n" -" </pluginRepository>\n" -"</pluginRepositories>\n" -"..." -msgstr "" -"...\n" -"<pluginRepositories>\n" -" <pluginRepository>\n" -" <id>maven-annotation-plugin-repo</id>\n" -" <url>http://maven-annotation-plugin.googlecode.com/svn/trunk/" -"mavenrepo</url>\n" -" </pluginRepository>\n" -"</pluginRepositories>\n" -"..." - -#. Tag: para -#: annotationprocessor.xml:244 -#, no-c-format -msgid "" -"Now disable the standard annotation processing performed by the compiler " -"plugin and configure the annotation plugin by specifying an execution and " -"adding the Hibernate Validator Annotation Processor as plugin dependency " -"(that way the AP is not visible on the project's actual classpath):" -msgstr "" -"现在, 禁用compiler插件所调用的标准的标注处理过程, 然后再通过定义一个execution" -"来配置annotation plugin的运行, 还需要把Hibernate Validator标注处理器作为该插" -"件的依赖添加进去(这样, 此标注处理器就不会被当成你的项目的依赖而出现在类路径中" -"了):" - -#. Tag: title -#: annotationprocessor.xml:251 -#, no-c-format -msgid "Configuring the Maven Annotation Plugin" -msgstr "配置Maven Annotation Plugin" - -#. Tag: programlisting -#: annotationprocessor.xml:253 -#, no-c-format -msgid "" -"...\n" -"<plugin>\n" -" <artifactId>maven-compiler-plugin</artifactId>\n" -" <configuration>\n" -" <source>1.6</source>\n" -" <target>1.6</target>\n" -" <compilerArgument>-proc:none</compilerArgument>\n" -" </configuration>\n" -"</plugin>\n" -"<plugin>\n" -" <groupId>org.bsc.maven</groupId>\n" -" <artifactId>maven-processor-plugin</artifactId>\n" -" <version>1.3.4</version>\n" -" <executions>\n" -" <execution>\n" -" <id>process</id>\n" -" <goals>\n" -" <goal>process</goal>\n" -" </goals>\n" -" <phase>process-sources</phase>\n" -" </execution>\n" -" </executions>\n" -" <dependencies>\n" -" <dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator-annotation-processor</" -"artifactId>\n" -" <version>&version;</version>\n" -" <scope>compile</scope>\n" -" </dependency>\n" -" </dependencies>\n" -"</plugin>\n" -"..." -msgstr "" -"...\n" -"<plugin>\n" -" <artifactId>maven-compiler-plugin</artifactId>\n" -" <configuration>\n" -" <source>1.6</source>\n" -" <target>1.6</target>\n" -" <compilerArgument>-proc:none</compilerArgument>\n" -" </configuration>\n" -"</plugin>\n" -"<plugin>\n" -" <groupId>org.bsc.maven</groupId>\n" -" <artifactId>maven-processor-plugin</artifactId>\n" -" <version>1.3.4</version>\n" -" <executions>\n" -" <execution>\n" -" <id>process</id>\n" -" <goals>\n" -" <goal>process</goal>\n" -" </goals>\n" -" <phase>process-sources</phase>\n" -" </execution>\n" -" </executions>\n" -" <dependencies>\n" -" <dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator-annotation-processor</" -"artifactId>\n" -" <version>&version;</version>\n" -" <scope>compile</scope>\n" -" </dependency>\n" -" </dependencies>\n" -"</plugin>\n" -"..." - -#. Tag: title -#: annotationprocessor.xml:259 -#, no-c-format -msgid "IDE builds" -msgstr "IDE集成" - -#. Tag: title -#: annotationprocessor.xml:262 -#, no-c-format -msgid "Eclipse" -msgstr "Eclipse" - -#. Tag: para -#: annotationprocessor.xml:264 -#, no-c-format -msgid "" -"Do the following to use the annotation processor within the Eclipse IDE:" -msgstr "" -"请参考以下步骤来在Eclipse中使" -"用标注处理器:" - -#. Tag: para -#: annotationprocessor.xml:269 annotationprocessor.xml:361 -#, no-c-format -msgid "Right-click your project, choose \"Properties\"" -msgstr "右键点击你的项目, 然后选择\"属性\"" - -#. Tag: para -#: annotationprocessor.xml:273 -#, no-c-format -msgid "" -"Go to \"Java Compiler\" and make sure, that \"Compiler compliance level\" is " -"set to \"1.6\". Otherwise the processor won't be activated" -msgstr "" -"在\"Java Compiler\"页面确认\"编译级别\"设置的是\"1.6\". 否则的话是无法使用标" -"注处理器的." - -#. Tag: para -#: annotationprocessor.xml:279 -#, no-c-format -msgid "" -"Go to \"Java Compiler - Annotation Processing\" and choose \"Enable " -"annotation processing\"" -msgstr "" -"到\"Java Compiler\"下面的\"Annotation Processing\" 页面, 然后选择\"启用标注处" -"理\"(译注: 我的电脑是英文版的, 所以真的不知道中文版的eclipse上, 这些翻译成了" -"什么:(" - -#. Tag: para -#: annotationprocessor.xml:284 -#, fuzzy, no-c-format -msgid "" -"Go to \"Java Compiler - Annotation Processing - Factory Path\" and add the " -"JAR hibernate-validator-annotation-processor-&version;.jar" -msgstr "" -"到\"Java Compiler - Annotation Processing - Factory Path\"页面, 然后添加下面" -"的jar文件:" - -#. Tag: para -#: annotationprocessor.xml:290 -#, no-c-format -msgid "Confirm the workspace rebuild" -msgstr "确认工作空间重新编译" - -#. Tag: para -#: annotationprocessor.xml:294 -#, no-c-format -msgid "" -"You now should see any annotation problems as regular error markers within " -"the editor and in the \"Problem\" view:" -msgstr "" -"现在你应该能够看到所有的标注错误都在编辑窗口中显示出了错误标记,也都显示在了" -"\"问题\"视图:" - -#. Tag: title -#: annotationprocessor.xml:306 -#, no-c-format -msgid "IntelliJ IDEA" -msgstr "IntelliJ IDEA" - -#. Tag: para -#: annotationprocessor.xml:308 -#, no-c-format -msgid "" -"The following steps must be followed to use the annotation processor within " -"IntelliJ IDEA (version " -"9 and above):" -msgstr "" -"请参考以下步骤来在IntelliJ " -"IDEA (9.0及以上):中使用标注处理器:" - -#. Tag: para -#: annotationprocessor.xml:314 -#, no-c-format -msgid "Go to \"File\", then \"Settings\"," -msgstr "选择 \"File\", 然后 \"Settings\"," - -#. Tag: para -#: annotationprocessor.xml:318 -#, no-c-format -msgid "Expand the node \"Compiler\", then \"Annotation Processors\"" -msgstr "展开\"Compiler\"节点, 然后点击\"Annotation Processors\"" - -#. Tag: para -#: annotationprocessor.xml:323 -#, fuzzy, no-c-format -msgid "" -"Choose \"Enable annotation processing\" and enter the following as " -"\"Processor path\": /path/to/hibernate-validator-annotation-processor-" -"&version;.jar" -msgstr "" -"选中 \"Enable annotation processing\" 并且输入下面的内容作为\"Processor path" -"\": /path/to/validation-api-&bvVersion;.jar:/path/to/hibernate-validator-" -"annotation-processor-&version;.jar" - -#. Tag: para -#: annotationprocessor.xml:329 -#, no-c-format -msgid "" -"Add the processor's fully qualified name org.hibernate.validator." -"ap.ConstraintValidationProcessor to the \"Annotation Processors" -"\" list" -msgstr "" -"添加处理器的全路径名称org.hibernate.validator.ap." -"ConstraintValidationProcessor到\"Annotation Processors\"列表" - -#. Tag: para -#: annotationprocessor.xml:335 -#, no-c-format -msgid "If applicable add you module to the \"Processed Modules\" list" -msgstr "如果需要的话, 添加你的模块到\"Processed Modules\"列表" - -#. Tag: para -#: annotationprocessor.xml:340 -#, no-c-format -msgid "" -"Rebuilding your project then should show any erronous constraint annotations:" -msgstr "重新编译你的项目, 然后应该能看到关于约束标注的错误信息了:" - -#. Tag: title -#: annotationprocessor.xml:352 -#, no-c-format -msgid "NetBeans" -msgstr "NetBeans" - -#. Tag: para -#: annotationprocessor.xml:354 -#, no-c-format -msgid "" -"Starting with version 6.9, also the NetBeans IDE supports using annotation processors within the IDE " -"build. To do so, do the following:" -msgstr "" -"从6.9这个版本开始, NetBeans也" -"支持标注处理了. 可以通过下面的步骤来启用它:" - -#. Tag: para -#: annotationprocessor.xml:365 -#, fuzzy, no-c-format -msgid "" -"Go to \"Libraries\", tab \"Processor\", and add the JAR hibernate-validator-" -"annotation-processor-&version;.jar" -msgstr "hibernate-validator-annotation-processor-&version;.jar" - -#. Tag: para -#: annotationprocessor.xml:370 -#, no-c-format -msgid "" -"Go to \"Build - Compiling\", select \"Enable Annotation Processing\" and " -"\"Enable Annotation Processing in Editor\". Add the annotation processor by " -"specifying its fully qualified name org.hibernate.validator.ap." -"ConstraintValidationProcessor" -msgstr "" -"到\"Build - Compiling\"页面选中\"Enable Annotation Processing\" 和 \"Enable " -"Annotation Processing in Editor\", 并且指定标注处理器的全路径名称" -"org.hibernate.validator.ap.ConstraintValidationProcessor." - -#. Tag: para -#: annotationprocessor.xml:377 -#, no-c-format -msgid "" -"Any constraint annotation problems will then be marked directly within the " -"editor:" -msgstr "所有的约束标注问题应该都会在编辑器里面直接被标记出来了:" - -#. Tag: title -#: annotationprocessor.xml:391 -#, no-c-format -msgid "Known issues" -msgstr "已知问题" - -#. Tag: para -#: annotationprocessor.xml:393 -#, no-c-format -msgid "The following known issues exist as of May 2010:" -msgstr "以下是截止到2010年五月我们发现(但尚未解决)的问题:" - -#. Tag: para -#: annotationprocessor.xml:397 -#, no-c-format -msgid "" -"HV-308: Additional validators registered for a constraint " -"using XML are not evaluated by the annotation " -"processor." -msgstr "" -"HV-308: Additional validators registered for a constraint " -"using XML are not evaluated by the annotation " -"processor." - -#. Tag: para -#: annotationprocessor.xml:405 -#, no-c-format -msgid "" -"Sometimes custom constraints can't be properly evaluated " -"when using the processor within Eclipse. Cleaning the project can help in " -"these situations. This seems to be an issue with the Eclipse JSR 269 API " -"implementation, but further investigation is required here." -msgstr "" -"有时候, 在eclipse里面自定义的约束条件不能够被正确的检查. 清理这个" -"项目可能会有帮助. 这可能是因为Eclipse中对 JSR 269 API的实现有问题, 但是还需要" -"进一步的研究." - -#. Tag: para -#: annotationprocessor.xml:414 -#, no-c-format -msgid "" -"When using the processor within Eclipse, the check of dynamic default group " -"sequence definitions doesn't work. After further investigation, it seems to " -"be an issue with the Eclipse JSR 269 API implementation." -msgstr "" - -#~ msgid "validation-api-&bvVersion;.jar" -#~ msgstr "validation-api-&bvVersion;.jar" - -#, fuzzy -#~ msgid "hibernate-validator-&version;.jar" -#~ msgstr "hibernate-validator-annotation-processor-&version;.jar" - -#~ msgid "" -#~ "The following listing shows an example. The processor will be detected " -#~ "automatically by the compiler and invoked during compilation." -#~ msgstr "" -#~ "下面显示了一个具体的示例. 这样, 标注处理器就会自动被编译器检测到并且调用." - -#, fuzzy -#~ msgid "Go to \"Libraries\", tab \"Processor\", and add the following JARs:" -#~ msgstr "选择\"Libraries\"的\"Processor\"选项卡, 然后添加下面两个jar文件:" - -#~ msgid "Annotation Processor (EXPERIMENTAL)" -#~ msgstr "标注处理器(实验)" - -#~ msgid "" -#~ "annotating Strings with @Min to specify a minimum length (instead of " -#~ "using @Size)" -#~ msgstr "把@Min赋给一个String来指定其的最小长度(而不是使用@Size)" - -#~ msgid "" -#~ "A first version of the Hibernate Validator Annotation Processor is part " -#~ "of Hibernate Validator since release 4.1. It is currently still under " -#~ "development and should therefore be considered as an experimental " -#~ "feature. Some known issues " -#~ "can be found at the end of this chapter. In case any problems arise when " -#~ "using the processor feel free to ask for help at the forum or create an issue " -#~ "within JIRA." -#~ msgstr "" -#~ "Hibernate Validator 4.1 包含了标注处理器的第一个版本. 它当前正处于开发阶" -#~ "段, 所以应该被看作是实验性质的功能. 在本章的结尾列出了一些已知的缺陷. 如果在使用这个功能的时候碰到任" -#~ "何问题, 请在我们的论坛寻求帮助或者请在 JIRA" -#~ "中创建一个缺陷报告." - -#~ msgid "JavaBean getter methods are annotated in case of property validation" -#~ msgstr "如果是使用属性模式的话, 那么需要定义在JavaBean的getter上" diff --git a/documentation/src/main/docbook/zh-CN/modules/bean-constraints.po b/documentation/src/main/docbook/zh-CN/modules/bean-constraints.po deleted file mode 100644 index 207bdcc4db..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/bean-constraints.po +++ /dev/null @@ -1,1658 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: bean-constraints.xml:24 -#, no-c-format -msgid "Declaring and validating bean constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:26 -#, no-c-format -msgid "" -"Read this chapter in order to learn how to declare bean constraints (see " -") and validate the " -"same (see ). provides an overview of all built-" -"in constraints coming with Hibernate Validator." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:32 -#, no-c-format -msgid "" -"If you are interested in applying constraints to method parameters and " -"return values, refer to ." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:36 -#, no-c-format -msgid "Declaring bean constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:38 -#, no-c-format -msgid "" -"Constraints in Bean Validation are expressed via Java annotations. In this " -"section we show how to enhance an object model with these annotations. We " -"have to differentiate between several types of constraint annotations:" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:45 -#, no-c-format -msgid "field constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:49 -#, no-c-format -msgid "property constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:53 -#, no-c-format -msgid "class constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:58 -#, no-c-format -msgid "" -"Not all constraints can be placed on all of these levels. In fact, none of " -"the default constraints defined by Bean Validation can be placed at class " -"level. The java.lang.annotation.Target annotation in " -"the constraint annotation itself determines on which elements a constraint " -"can be placed. See for more " -"information." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:67 bean-constraints.xml:74 -#, no-c-format -msgid "Field-level constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:69 -#, no-c-format -msgid "" -"Constraints can be expressed by annotating a field of a class. shows a field level configuration example:" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:76 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter02.fieldlevel;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @AssertTrue\n" -" private boolean isRegistered;\n" -"\n" -" public Car(String manufacturer, boolean isRegistered) {\n" -" this.manufacturer = manufacturer;\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"\n" -" //getters and setters...\n" -"}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:79 -#, no-c-format -msgid "" -"When using field-level constraints field access strategy is used to access " -"the value to be validated. This means the validation engine directly " -"accesses the instance variable and does not invoke the property accessor " -"method also if such a method exists." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:84 -#, no-c-format -msgid "" -"Constraints can be applied to fields of any access type (public, private " -"etc.). Constraints on static fields are not supported, though." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:89 -#, no-c-format -msgid "" -"When validating byte code enhanced objects property level constraints should " -"be used, because the byte code enhancing library won't be able to determine " -"a field access via reflection." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:96 bean-constraints.xml:110 -#, no-c-format -msgid "Property-level constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:98 -#, no-c-format -msgid "" -"If your model class adheres to the JavaBeans " -"standard, it is also possible to annotate the properties of a bean class " -"instead of its fields. uses the " -"same entity as in , however, property " -"level constraints are used." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:104 -#, no-c-format -msgid "" -"The property's getter method has to be annotated, not its setter. That way " -"also read-only properties can be constrained which have no setter method." -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:112 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter02.propertylevel;\n" -"\n" -"public class Car {\n" -"\n" -" private String manufacturer;\n" -"\n" -" private boolean isRegistered;\n" -"\n" -" public Car(String manufacturer, boolean isRegistered) {\n" -" this.manufacturer = manufacturer;\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"\n" -" @NotNull\n" -" public String getManufacturer() {\n" -" return manufacturer;\n" -" }\n" -"\n" -" public void setManufacturer(String manufacturer) {\n" -" this.manufacturer = manufacturer;\n" -" }\n" -"\n" -" @AssertTrue\n" -" public boolean isRegistered() {\n" -" return isRegistered;\n" -" }\n" -"\n" -" public void setRegistered(boolean isRegistered) {\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:115 -#, no-c-format -msgid "" -"When using property level constraints property access strategy is used to " -"access the value to be validated, i.e. the validation engine accesses the " -"state via the property accessor method." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:119 -#, no-c-format -msgid "" -"One advantage of annotating properties instead of fields is that the " -"constraints become part of the type's API that way. Thus users are aware of " -"the existing constraints without having to examine the type's implementation." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:125 -#, no-c-format -msgid "" -"It is recommended to stick either to field or property " -"annotations within one class. It is not recommended to annotate a field " -"and the accompanying getter method as this would cause " -"the field to be validated twice." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:134 -#, no-c-format -msgid "Class-level constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:137 -#, no-c-format -msgid "" -"Last but not least, a constraint can also be placed on the class level. In " -"this case not a single property is subject of the validation but the " -"complete object. Class-level constraints are useful if the validation " -"depends on a correlation between several properties of an object." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:143 -#, no-c-format -msgid "" -"The Car class in has the two attributes seatCount and " -"passengers and it should be ensured that the list of " -"passengers has not more entries than seats are available. For that purpose " -"the @PassengerCount constraint is added on the class " -"level. The validator of that constraint has access to the complete " -"Car object, allowing to compare the numbers of seats " -"and passengers. Refer to to " -"learn in detail how this custom constraint is implemented." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:156 -#, no-c-format -msgid "Class-level constraint" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:158 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter02.classlevel;\n" -"\n" -"@PassengerCount\n" -"public class Car {\n" -"\n" -" private int seatCount;\n" -"\n" -" private List<Person> passengers;\n" -"\n" -" //...\n" -"}" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:163 bean-constraints.xml:171 -#, no-c-format -msgid "Constraint inheritance" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:165 -#, no-c-format -msgid "" -"When a class implements an interface or extends another class, all " -"constraint annotations declared on the supertype apply in the same manner as " -"the constraints specified on the class itself. To make things clearer let's " -"have a look at the following example:" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:173 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter02.inheritance;\n" -"\n" -"public class Car {\n" -"\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" public String getManufacturer() {\n" -" return manufacturer;\n" -" }\n" -"\n" -" //...\n" -"}" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:175 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter02.inheritance;\n" -"\n" -"public class RentalCar extends Car {\n" -"\n" -" private String rentalStation;\n" -"\n" -" @NotNull\n" -" public String getRentalStation() {\n" -" return rentalStation;\n" -" }\n" -"\n" -" //...\n" -"}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:178 -#, no-c-format -msgid "" -"Here the class RentalCar is a subclass of " -"Car and adds the property rentalStation. If an instance of RentalCar is validated, " -"not only the @NotNull constraint on " -"rentalStation is evaluated, but also the constraint on " -"manufacturer from the parent class." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:186 -#, no-c-format -msgid "" -"The same would be true, if Car was not a superclass " -"but an interface implemented by RentalCar." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:190 -#, no-c-format -msgid "" -"Constraint annotations are aggregated if methods are overridden. So if " -"RentalCar overrode the getManufacturer() method from Car, any constraints " -"annotated at the overriding method would be evaluated in addition to the " -"@NotNull constraint from the superclass." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:199 -#, no-c-format -msgid "Object graphs" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:201 -#, no-c-format -msgid "" -"The Bean Validation API does not only allow to validate single class " -"instances but also complete object graphs (cascaded validation). To do so, " -"just annotate a field or property representing a reference to another object " -"with @Valid as demonstrated in ." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:208 -#, no-c-format -msgid "Cascaded validation" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:210 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter02.objectgraph;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" @Valid\n" -" private Person driver;\n" -"\n" -" //...\n" -"}" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:212 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter02.objectgraph;\n" -"\n" -"public class Person {\n" -"\n" -" @NotNull\n" -" private String name;\n" -"\n" -" //...\n" -"}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:215 -#, no-c-format -msgid "" -"If an instance of Car is validated, the referenced " -"Person object will be validated as well, as the " -"driver field is annotated with @Valid. Therefore the validation of a Car will " -"fail if the name field of the referenced " -"Person instance is null." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:223 -#, no-c-format -msgid "" -"The validation of object graphs is done recursively, i.e. if a reference " -"marked for cacaded validation points to an object which itself has " -"properties annotated with @Valid, these references " -"will be followed up by the validation engine as well. It is ensured that no " -"infinite loops occur during cascaded validation, if for instance two objects " -"hold references to each other." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:230 -#, no-c-format -msgid "" -"Note that null values are getting ignored during cascaded " -"validation." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:233 -#, no-c-format -msgid "" -"Object graph validation also works for collection-typed fields. That means " -"any attributes that" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:238 -#, no-c-format -msgid "are arrays" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:242 -#, no-c-format -msgid "" -"implement java.lang.Iterable (especially " -"Collection, List and " -"Set)" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:248 -#, no-c-format -msgid "implement java.util.Map" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:252 -#, no-c-format -msgid "" -"can be annotated with @Valid, which will cause each " -"contained element to be validated, when the parent object is validated." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:257 -#, no-c-format -msgid "Cascaded validation of a collection" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:259 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter02.objectgraph.list;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" @Valid\n" -" private List<Person> passengers = new ArrayList<Person>" -"();\n" -"\n" -" //...\n" -"}" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:262 -#, no-c-format -msgid "" -"So when validating an instance of the Car class shown " -"in , a " -"ConstraintViolation will be created, if any of the " -"Person objects contained in the passengers list has a null name." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:272 -#, no-c-format -msgid "Validating bean constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:274 -#, no-c-format -msgid "" -"The Validator interface is the most important object " -"in Bean Validation. The next section shows how to obtain an " -"Validator instance. Afterwards you'll learn how to " -"use the different methods of the Validator interface." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:281 -#, no-c-format -msgid "Obtaining a Validator instance" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:283 -#, no-c-format -msgid "" -"The first step towards validating an entity instance is to get hold of a " -"Validator instance. The road to this instance leads " -"via the Validation class and a " -"ValidatorFactory. The easiest way is to use the " -"static method Validation#buildDefaultValidatorFactory():" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:291 -#, no-c-format -msgid "Validation#buildDefaultValidatorFactory()" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:293 -#, no-c-format -msgid "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"Validator validator = factory.getValidator();" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:296 -#, no-c-format -msgid "" -"For other ways of obtaining a Validator instance see . For now we just want to see how we can use the " -"Validator instance to validate entity instances." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:303 -#, no-c-format -msgid "Validator methods" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:305 -#, no-c-format -msgid "" -"The Validator interface contains three methods that " -"can be used to either validate entire entities or just single properties of " -"the entity." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:309 -#, no-c-format -msgid "" -"All three methods return a Set<ConstraintViolation>. The set is empty, if the validation succeeds. Otherwise a " -"ConstraintViolation instance is added for each " -"violated constraint." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:315 -#, no-c-format -msgid "" -"All the validation methods have a var-args parameter which can be used to " -"specify, which validation groups shall be considered when performing the " -"validation. If the parameter is not specified the default validation group " -"(javax.validation.groups.Default) is used. The topic " -"of validation groups is discussed in detail in ." -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:324 -#, no-c-format -msgid "validate()" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:326 -#, no-c-format -msgid "" -"Use the validate() method to perform validation of " -"all constraints of a given bean. shows the validation of an instance of the Car " -"class from which fails to satisfy " -"the @NotNull constraint on the manufacturer property. The validation call therefore returns one " -"ConstraintViolation object." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:337 -#, no-c-format -msgid "Using Validator#validate()" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:339 -#, no-c-format -msgid "" -"Car car = new Car( null, true );\n" -"\n" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validate( car );\n" -"\n" -"assertEquals( 1, constraintViolations.size() );\n" -"assertEquals( \"may not be null\", constraintViolations.iterator().next()." -"getMessage() );" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:344 -#, no-c-format -msgid "validateProperty()" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:346 -#, no-c-format -msgid "" -"With help of the validateProperty() you can " -"validate a single named property of a given object. The property name is the " -"JavaBeans property name." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:351 -#, no-c-format -msgid "Using Validator#validateProperty()" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:354 -#, no-c-format -msgid "" -"Car car = new Car( null, true );\n" -"\n" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validateProperty(\n" -" car,\n" -" \"manufacturer\"\n" -");\n" -"\n" -"assertEquals( 1, constraintViolations.size() );\n" -"assertEquals( \"may not be null\", constraintViolations.iterator().next()." -"getMessage() );" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:359 -#, no-c-format -msgid "validateValue()" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:361 -#, no-c-format -msgid "" -"By using the validateValue() method you can check " -"whether a single property of a given class can be validated successfully, if " -"the property had the specified value:" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:366 -#, no-c-format -msgid "Using Validator#validateValue()" -msgstr "" - -#. Tag: programlisting -#: bean-constraints.xml:369 -#, no-c-format -msgid "" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validateValue(\n" -" Car.class,\n" -" \"manufacturer\",\n" -" null\n" -");\n" -"\n" -"assertEquals( 1, constraintViolations.size() );\n" -"assertEquals( \"may not be null\", constraintViolations.iterator().next()." -"getMessage() );" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:373 -#, no-c-format -msgid "" -"@Valid is not honored by validateProperty" -"() or validateValue()." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:378 -#, no-c-format -msgid "" -"Validator#validateProperty() is for example used in " -"the integration of Bean Validation into JSF 2 (see ) to perform a validation of the values entered into a " -"form before they are propagated to the model." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:387 -#, no-c-format -msgid "ConstraintViolation methods" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:389 -#, no-c-format -msgid "" -"Now it is time to have a closer look at what a " -"ConstraintViolation is. Using the different methods " -"of ConstraintViolation a lot of useful information " -"about the cause of the validation failure can be determined. gives an overview of these methods. The " -"values in the \"Example\" column refer to ." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:398 -#, no-c-format -msgid "The various ConstraintViolation methods" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:404 -#, no-c-format -msgid "Method" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:406 -#, no-c-format -msgid "Usage" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:408 -#, no-c-format -msgid "Example" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:414 -#, no-c-format -msgid "getMessage()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:416 -#, no-c-format -msgid "The interpolated error message" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:418 -#, no-c-format -msgid "\"may not be null\"" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:422 -#, no-c-format -msgid "getMessageTemplate()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:424 -#, no-c-format -msgid "The non-interpolated error message" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:426 -#, no-c-format -msgid "\"{... NotNull.message}\"" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:430 -#, no-c-format -msgid "getRootBean()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:432 -#, no-c-format -msgid "The root bean being validated" -msgstr "" - -#. Tag: varname -#: bean-constraints.xml:434 bean-constraints.xml:452 -#, no-c-format -msgid "car" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:438 -#, no-c-format -msgid "getRootBeanClass()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:440 -#, no-c-format -msgid "The class of the root bean being validated" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:442 -#, no-c-format -msgid "Car.class" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:446 -#, no-c-format -msgid "getLeafBean()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:448 -#, no-c-format -msgid "" -"If a bean constraint, the bean instance the constraint is applied on; If a " -"property constraint, the bean instance hosting the property the constraint " -"is applied on" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:456 -#, no-c-format -msgid "getPropertyPath()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:458 -#, no-c-format -msgid "The property path to the validated value from root bean" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:461 -#, no-c-format -msgid "" -"contains one node with kind PROPERTY and name " -"\"manufacturer\"" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:466 -#, no-c-format -msgid "getInvalidValue()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:468 -#, no-c-format -msgid "The value failing to pass the constraint" -msgstr "" - -#. Tag: literal -#: bean-constraints.xml:470 -#, no-c-format -msgid "null" -msgstr "" - -#. Tag: methodname -#: bean-constraints.xml:474 -#, no-c-format -msgid "getConstraintDescriptor()" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:476 -#, no-c-format -msgid "Constraint metadata reported to fail" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:478 -#, no-c-format -msgid "descriptor for @NotNull" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:487 -#, no-c-format -msgid "Built-in constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:489 -#, no-c-format -msgid "" -"Hibernate Validator comprises a basic set of commonly used constraints. " -"These are foremost the constraints defined by the Bean Validation " -"specification (see ). " -"Additionally, Hibernate Validator provides useful custom constraints (see " -" and )." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:497 bean-constraints.xml:517 -#, no-c-format -msgid "Bean Validation constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:499 -#, no-c-format -msgid "" -"shows purpose and supported data types of all constraints specified in the " -"Bean Validation API. All these constraints apply to the field/property " -"level, there are no class-level constraints defined in the Bean Validation " -"specification. If you are using the Hibernate object-relational mapper, some " -"of the constraints are taken into account when creating the DDL for your " -"model (see column \"Hibernate metadata impact\")." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:508 -#, no-c-format -msgid "" -"Hibernate Validator allows some constraints to be applied to more data types " -"than required by the Bean Validation specification (e.g. @Max can be applied to Strings). Relying on " -"this feature can impact portability of your application between Bean " -"Validation providers." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:530 bean-constraints.xml:797 bean-constraints.xml:1003 -#, no-c-format -msgid "Annotation" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:532 bean-constraints.xml:799 bean-constraints.xml:1005 -#, no-c-format -msgid "Supported data types" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:534 bean-constraints.xml:801 bean-constraints.xml:1007 -#, no-c-format -msgid "Use" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:536 bean-constraints.xml:803 bean-constraints.xml:1011 -#, no-c-format -msgid "Hibernate metadata impact" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:542 -#, no-c-format -msgid "@AssertFalse" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:544 bean-constraints.xml:556 -#, no-c-format -msgid "Boolean, boolean" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:547 -#, no-c-format -msgid "Checks that the annotated element is false" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:550 bean-constraints.xml:562 bean-constraints.xml:585 -#: bean-constraints.xml:608 bean-constraints.xml:645 bean-constraints.xml:703 -#: bean-constraints.xml:719 bean-constraints.xml:732 bean-constraints.xml:759 -#: bean-constraints.xml:819 bean-constraints.xml:833 bean-constraints.xml:874 -#: bean-constraints.xml:887 bean-constraints.xml:900 bean-constraints.xml:916 -#: bean-constraints.xml:934 bean-constraints.xml:952 bean-constraints.xml:972 -#: bean-constraints.xml:1027 bean-constraints.xml:1041 -#: bean-constraints.xml:1056 -#, no-c-format -msgid "None" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:554 -#, no-c-format -msgid "@AssertTrue" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:559 -#, no-c-format -msgid "Checks that the annotated element is true" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:566 -#, no-c-format -msgid "" -"@DecimalMax(value=, inclusive=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:569 bean-constraints.xml:592 bean-constraints.xml:615 -#, no-c-format -msgid "" -"BigDecimal, BigInteger, " -"CharSequence, byte, " -"short, int, long and the respective wrappers of the primitive types; Additionally " -"supported by HV: any sub-type of Number" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:578 -#, no-c-format -msgid "" -"Checks whether the annotated value is less than the specified maximum, when " -"inclusive=false. Otherwise whether the value is less " -"than or equal to the specified maximum. The parameter value is the string representation of the max value according to the " -"BigDecimal string representation." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:589 -#, no-c-format -msgid "" -"@DecimalMin(value=, inclusive=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:601 -#, no-c-format -msgid "" -"Checks whether the annotated value is larger than the specified minimum, " -"when inclusive=false. Otherwise whether the value is " -"larger than or equal to the specified minimum. The parameter " -"value is the string representation of the min value " -"according to the BigDecimal string representation." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:612 -#, no-c-format -msgid "" -"@Digits(integer=, fraction=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:624 -#, no-c-format -msgid "" -"Checks whether the annoted value is a number having up to integer digits and fraction fractional digits" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:628 -#, no-c-format -msgid "Defines column precision and scale" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:632 -#, no-c-format -msgid "@Future" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:634 bean-constraints.xml:709 -#, no-c-format -msgid "" -"java.util.Date, java.util.Calendar; Additionally supported by HV, if the Joda Time date/time API is on the class " -"path: any implementations of ReadablePartial and " -"ReadableInstant" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:642 -#, no-c-format -msgid "Checks whether the annotated date is in the future" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:649 -#, no-c-format -msgid "@Max(value=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:651 -#, no-c-format -msgid "" -"BigDecimal, BigInteger, " -"byte, short, int, long and the respective wrappers of the " -"primitive types; Additionally supported by HV: any sub-type of " -"CharSequence (the numeric value represented by the " -"character sequence is evaluated), any sub-type of Number" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:660 -#, no-c-format -msgid "" -"Checks whether the annotated value is less than or equal to the specified " -"maximum" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:663 bean-constraints.xml:681 -#, no-c-format -msgid "Adds a check constraint on the column" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:667 -#, no-c-format -msgid "@Min(value=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:669 -#, no-c-format -msgid "" -"BigDecimal, BigInteger, " -"byte, short, int, long and the respective wrappers of the " -"primitive types; Additionally supported by HV: any sub-type of " -"CharSequence (the numeric value represented by the " -"char sequence is evaluated), any sub-type of Number" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:678 -#, no-c-format -msgid "" -"Checks whether the annotated value is higher than or equal to the specified " -"minimum" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:685 -#, no-c-format -msgid "@NotNull" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:687 bean-constraints.xml:698 bean-constraints.xml:941 -#, no-c-format -msgid "Any type" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:689 -#, no-c-format -msgid "Checks that the annotated value is not null." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:692 -#, no-c-format -msgid "Column(s) are not nullable" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:696 -#, no-c-format -msgid "@Null" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:700 -#, no-c-format -msgid "Checks that the annotated value is null" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:707 -#, no-c-format -msgid "@Past" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:717 -#, no-c-format -msgid "Checks whether the annotated date is in the past" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:723 -#, no-c-format -msgid "@Pattern(regex=, flag=)" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:726 bean-constraints.xml:811 bean-constraints.xml:825 -#: bean-constraints.xml:839 bean-constraints.xml:856 bean-constraints.xml:880 -#: bean-constraints.xml:923 bean-constraints.xml:960 bean-constraints.xml:1019 -#: bean-constraints.xml:1033 bean-constraints.xml:1047 -#, no-c-format -msgid "CharSequence" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:728 -#, no-c-format -msgid "" -"Checks if the annotated string matches the regular expression " -"regex considering the given flag match" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:736 -#, no-c-format -msgid "@Size(min=, max=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:738 -#, no-c-format -msgid "" -"CharSequence, Collection, " -"Map and arrays" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:742 -#, no-c-format -msgid "" -"Checks if the annotated element's size is between min and max (inclusive)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:745 bean-constraints.xml:845 -#, no-c-format -msgid "Column length will be set to max" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:750 -#, no-c-format -msgid "@Valid" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:752 -#, no-c-format -msgid "Any non-primitive type" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:754 -#, no-c-format -msgid "" -"Performs validation recursively on the associated object. If the object is a " -"collection or an array, the elements are validated recursively. If the " -"object is a map, the value elements are validated recursively." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:766 -#, no-c-format -msgid "" -"On top of the parameters indicated in each constraint has the parameters message, " -"groups and payload. This is a " -"requirement of the Bean Validation specification." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:775 -#, no-c-format -msgid "Additional constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:777 -#, no-c-format -msgid "" -"In addition to the constraints defined by the Bean Validation API Hibernate " -"Validator provides several useful custom constraints which are listed in " -". With one exception also these " -"constraints apply to the field/property level, only " -"@ScriptAssert is a class-level constraint." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:784 -#, no-c-format -msgid "Custom constraints" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:809 -#, no-c-format -msgid "@CreditCardNumber" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:813 -#, no-c-format -msgid "" -"Checks that the annotated character sequence passes the Luhn checksum test. " -"Note, this validation aims to check for user mistakes, not credit card " -"validity! See also Anatomy of Credit Card Numbers." -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:823 -#, no-c-format -msgid "@Email" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:827 -#, no-c-format -msgid "" -"Checks whether the specified character sequence is a valid email address. " -"The optional parameters regexp and flags allow to specify an additional regular expression (including " -"regular expression flags) which the email must match." -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:837 -#, no-c-format -msgid "@Length(min=, max=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:841 -#, no-c-format -msgid "" -"Validates that the annotated character sequence is between min and max included" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:850 -#, no-c-format -msgid "" -"@ModCheck(modType=, multiplier=, " -"startIndex=, endIndex=, " -"checkDigitPosition=, " -"ignoreNonDigitCharacters=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:858 -#, no-c-format -msgid "" -"Checks that the digits within the annotated character sequence pass the mod " -"10 or mod 11 checksum algorithm. modType is used to " -"select the modulo type and the multiplier determines " -"the algorithm specific multiplier (see also Luhn algorithm). startIndex and endIndex allow to only run the modulo " -"algorithm on the specified sub-string. checkDigitPosition allows to use an arbitrary digit within the character sequence to " -"be the check digit. If not specified it is assumed that the check digit is " -"part of the specified range. Last but not least, " -"ignoreNonDigitCharacters allows to ignore non digit " -"characters." -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:878 -#, no-c-format -msgid "@NotBlank" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:882 -#, no-c-format -msgid "" -"Checks that the annotated character sequence is not null and the trimmed " -"length is greater than 0. The difference to @NotEmpty is that this " -"constraint can only be applied on strings and that trailing whitespaces are " -"ignored." -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:891 -#, no-c-format -msgid "@NotEmpty" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:893 -#, no-c-format -msgid "" -"CharSequence, Collection, " -"Map and arrays" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:897 -#, no-c-format -msgid "" -"Checks whether the annotated element is not null nor " -"empty" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:904 -#, no-c-format -msgid "@Range(min=, max=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:906 -#, no-c-format -msgid "" -"BigDecimal, BigInteger, " -"CharSequence, byte, " -"short, int, long and the respective wrappers of the primitive types" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:913 -#, no-c-format -msgid "" -"Checks whether the annotated value lies between (inclusive) the specified " -"minimum and maximum" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:920 -#, no-c-format -msgid "" -"@SafeHtml(whitelistType=, additionalTags=)" -"" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:925 -#, no-c-format -msgid "" -"Checks whether the annotated value contains potentially malicious fragments " -"such as <script/>. In order to use this constraint, the " -"jsoup library must be part of the " -"class path. With the whitelistType attribute " -"predefined whitelist types can be chosen. You can also specify additional " -"html tags for the whitelist with the additionalTags " -"attribute." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:938 -#, no-c-format -msgid "" -"@ScriptAssert(lang=, script=, alias=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:943 -#, no-c-format -msgid "" -"Checks whether the given script can successfully be evaluated against the " -"annotated element. In order to use this constraint, an implementation of the " -"Java Scripting API as defined by JSR 223 (\"Scripting for the " -"JavaTM Platform\") must part of the class path. " -"The expressions to be evaluated can be written in any scripting or " -"expression language, for which a JSR 223 compatible engine can be found in " -"the class path." -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:956 -#, no-c-format -msgid "" -"@URL(protocol=, host=, port= " -"regexp=, flags=)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:962 -#, no-c-format -msgid "" -"Checks if the annotated character sequence is a valid URL according to " -"RFC2396. If any of the optional parameters protocol, " -"host or port are specified, " -"the corresponding URL fragments must match the specified values. The " -"optional parameters regexp and flags allow to specify an additional regular expression (including " -"regular expression flags) which the URL must match." -msgstr "" - -#. Tag: title -#: bean-constraints.xml:979 -#, no-c-format -msgid "Country specific constraints" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:981 -#, no-c-format -msgid "" -"Hibernate Validator offers also some country specific constraints, e.g. for " -"the validation of social security numbers." -msgstr "" - -#. Tag: para -#: bean-constraints.xml:983 -#, no-c-format -msgid "" -"If you have to implement a country specific constraint, consider making it a " -"contribution to Hibernate Validator!" -msgstr "" - -#. Tag: title -#: bean-constraints.xml:988 -#, no-c-format -msgid "Custom country specific constraints" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1009 -#, no-c-format -msgid "Country" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:1017 -#, no-c-format -msgid "@CNPJ" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1021 -#, no-c-format -msgid "" -"Checks that the annotated character sequence represents a Brazilian " -"corporate tax payer registry number (Cadastro de Pessoa Juríeddica)" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1025 bean-constraints.xml:1039 -#: bean-constraints.xml:1054 -#, no-c-format -msgid "Brazil" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:1031 -#, no-c-format -msgid "@CPF" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1035 -#, no-c-format -msgid "" -"Checks that the annotated character sequence represents a Brazilian " -"individual taxpayer registry number (Cadastro de Pessoa Fídsica)" -msgstr "" - -#. Tag: classname -#: bean-constraints.xml:1045 -#, no-c-format -msgid "@TituloEleitoral" -msgstr "" - -#. Tag: entry -#: bean-constraints.xml:1049 -#, no-c-format -msgid "" -"Checks that the annotated character sequence represents a Brazilian voter ID " -"card number (Título " -"Eleitoral)" -msgstr "" - -#. Tag: para -#: bean-constraints.xml:1063 -#, no-c-format -msgid "" -"In some cases neither the Bean Validation constraints nor the custom " -"constraints provided by Hibernate Validator will fulfill your requirements. " -"In this case you can easily write your own constraint. We will discuss this " -"in ." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/bootstrapping.po b/documentation/src/main/docbook/zh-CN/modules/bootstrapping.po deleted file mode 100644 index cea477cc53..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/bootstrapping.po +++ /dev/null @@ -1,1325 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2010-08-23 21:26+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: bootstrapping.xml:24 -#, no-c-format -msgid "Bootstrapping" -msgstr "Bootstrapping" - -#. Tag: para -#: bootstrapping.xml:26 -#, fuzzy, no-c-format -msgid "" -"In you already saw one way " -"for creating a Validator instance — via " -"Validation#buildDefaultValidatorFactory(). In this " -"chapter you will learn how to use the other methods in javax." -"validation.Validation in order to bootstrap specifically " -"configured validators." -msgstr "" -"在中我们说道过, 最简单的创建一" -"个Validator实例的方法是通过Validation." -"buildDefaultValidatorFactory. 在本章中我们会继续介绍" -"javax.validation.Validation中的其他方法, 以及如何通过" -"这些方法在Bean Validation初始化的时候对其进行配置的." - -#. Tag: title -#: bootstrapping.xml:34 -#, fuzzy, no-c-format -msgid "" -"Retrieving ValidatorFactory and Validator" -msgstr "" -"ConfigurationValidatorFactory" - -#. Tag: para -#: bootstrapping.xml:37 -#, no-c-format -msgid "" -"You obtain a Validator by retrieving a " -"ValidatorFactory via one of the static methods on " -"javax.validation.Validation and calling " -"getValidator() on the factory instance." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:42 -#, no-c-format -msgid "shows how to obtain a validator from the default validator factory:" -msgstr "" - -#. Tag: title -#: bootstrapping.xml:46 -#, fuzzy, no-c-format -msgid "" -"Bootstrapping default ValidatorFactory and " -"Validator" -msgstr "" -"ConfigurationValidatorFactory" - -#. Tag: programlisting -#: bootstrapping.xml:49 -#, no-c-format -msgid "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"Validator validator = factory.getValidator();" -msgstr "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"Validator validator = factory.getValidator();" - -#. Tag: para -#: bootstrapping.xml:53 -#, no-c-format -msgid "" -"The generated ValidatorFactory and " -"Validator instances are thread-safe and can be " -"cached. As Hibernate Validator uses the factory as context for caching " -"constraint metadata it is recommended to work with one factory instance " -"within an application." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:60 -#, no-c-format -msgid "" -"Bean Validation supports working with several providers such as Hibernate " -"Validator within one application. If more than one provider is present on " -"the classpath, it is not guaranteed which one is chosen when creating a " -"factory via buildDefaultValidatorFactory()." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:66 -#, no-c-format -msgid "" -"In this case you can explicitly specify the provider to use via " -"Validation#byProvider(), passing the provider's " -"ValidationProvider class as shown in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:72 -#, fuzzy, no-c-format -msgid "" -"Bootstrapping ValidatorFactory and " -"Validator using a specific provider" -msgstr "" -"ConfigurationValidatorFactory" - -#. Tag: programlisting -#: bootstrapping.xml:75 -#, fuzzy, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.byProvider" -"( HibernateValidator.class )\n" -" .configure()\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"Validator validator = factory.getValidator();" - -#. Tag: para -#: bootstrapping.xml:78 -#, no-c-format -msgid "" -"Note that the configuration object returned by configure() allows to specifically customize the factory before calling " -"buildValidatorFactory(). The available options are " -"discussed later in this chapter." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:83 -#, no-c-format -msgid "" -"Similarly you can retrieve the default validator factory for configuration " -"which is demonstrated in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:88 -#, no-c-format -msgid "" -"Retrieving the default ValidatorFactory for " -"configuration" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:91 -#, fuzzy, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" -" .configure()\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"Validator validator = factory.getValidator();" - -#. Tag: para -#: bootstrapping.xml:95 -#, no-c-format -msgid "" -"If a ValidatorFactory instance is no longer in use, " -"it should be disposed by calling ValidatorFactory#close(). This will free any resources possibly allocated by the factory." -msgstr "" - -#. Tag: classname -#: bootstrapping.xml:102 -#, no-c-format -msgid "ValidationProviderResolver" -msgstr "ValidationProviderResolver" - -#. Tag: para -#: bootstrapping.xml:104 -#, no-c-format -msgid "" -"By default, available Bean Validation providers are discovered using the " -"Java Service Provider mechanism." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:109 -#, fuzzy, no-c-format -msgid "" -"For that purpose, each provider includes the file META-INF/" -"services/javax.validation.spi.ValidationProvider, containing the " -"fully qualified classname of its ValidationProvider " -"implementation. In the case of Hibernate Validator this is org." -"hibernate.validator.HibernateValidator." -msgstr "" -"The different bootstrapping options allow, amongst other things, to " -"bootstrap any Bean Validation implementation on the classpath. 通常, 一个服务" -"的提供者是能够被Java Service Provider发现的. 对于Bean " -"Validation的实现(服务提供者)来说, 他们的META-INF/services目录下需要包含一个名为javax.validation.spi." -"ValidationProvider的文件. 此文件中包含了一个" -"ValidationProvider接口的实现类的全路径名称, 具体到" -"Hibernate Validator来说, 就是org.hibernate.validator." -"HibernateValidator." - -#. Tag: para -#: bootstrapping.xml:116 -#, no-c-format -msgid "" -"Depending on your environment and its classloading specifics, provider " -"discovery via the Java's service loader mechanism might not work. In this " -"case you can plug in a custom ValidationProviderResolver implementation which performs the provider retrieval. An example " -"is OSGi, where you could implement a provider resolver which uses OSGi " -"services for provider discovery." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:124 -#, no-c-format -msgid "" -"To use a custom provider resolver pass it via providerResolver()" -" as shown shown in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:129 -#, fuzzy, no-c-format -msgid "Using a custom ValidationProviderResolver" -msgstr "使用自定义的ValidationProviderResolver" - -#. Tag: programlisting -#: bootstrapping.xml:132 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter08;\n" -"\n" -"public class OsgiServiceDiscoverer implements ValidationProviderResolver {\n" -"\n" -" @Override\n" -" public List<ValidationProvider<?>> getValidationProviders" -"() {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:134 -#, fuzzy, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" -" .providerResolver( new OsgiServiceDiscoverer() )\n" -" .configure()\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" -"Configuration<?> config = Validation.byDefaultProvider()\n" -" .providerResolver( new OSGiServiceDiscoverer() )\n" -" .configure();\n" -"\n" -"ValidatorFactory factory = config.buildValidatorFactory();\n" -"Validator validator = factory.getValidator();" - -#. Tag: title -#: bootstrapping.xml:140 -#, fuzzy, no-c-format -msgid "Configuring a ValidatorFactory" -msgstr "" -"ConfigurationValidatorFactory" - -#. Tag: para -#: bootstrapping.xml:142 -#, no-c-format -msgid "" -"By default validator factories retrieved from Validation and any validators they create are configured as per the XML " -"descriptor META-INF/validation.xml (see ), if present." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:148 -#, no-c-format -msgid "" -"If you want to disable the XML based configuration, you can do so by " -"invoking Configuration#ignoreXmlConfiguration()." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:152 -#, no-c-format -msgid "" -"The different values of the XML configuration can be accessed via " -"Configuration#getBootstrapConfiguration(). This can " -"for instance be helpful if you want to integrate Bean Validation into a " -"managed environment and want to create managed instances of the objects " -"configured via XML." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:158 -#, no-c-format -msgid "" -"Using the fluent configuration API, you can override one or more of the " -"settings when bootstrapping the factory. The following sections show how to " -"make use of the different options. Note that the Configuration class exposes the default implementations of the different " -"extension points which can be useful if you want to use these as delegates " -"for your custom implementations." -msgstr "" - -#. Tag: classname -#: bootstrapping.xml:166 -#, no-c-format -msgid "MessageInterpolator" -msgstr "MessageInterpolator" - -#. Tag: para -#: bootstrapping.xml:168 -#, no-c-format -msgid "" -"Message interpolators are used by the validation engine to create user " -"readable error messages from constraint message descriptors." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:171 -#, no-c-format -msgid "" -"In case the default message interpolation algorithm described in is not sufficient for your " -"needs, you can pass in your own implementation of the " -"MessageInterpolator interface via " -"Configuration#messageInterpolator() as shown in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:179 -#, fuzzy, no-c-format -msgid "Using a custom MessageInterpolator" -msgstr "自定义的MessageInterpolator" - -#. Tag: programlisting -#: bootstrapping.xml:182 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter08;\n" -"\n" -"public class MyMessageInterpolator implements MessageInterpolator {\n" -"\n" -" @Override\n" -" public String interpolate(String messageTemplate, Context context) " -"{\n" -" //...\n" -" }\n" -"\n" -" @Override\n" -" public String interpolate(String messageTemplate, Context context, " -"Locale locale) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:184 -#, fuzzy, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" -" .configure()\n" -" .messageInterpolator( new MyMessageInterpolator() )\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" -"Configuration<?> configuration = Validation.byDefaultProvider()." -"configure();\n" -"ValidatorFactory factory = configuration\n" -" .messageInterpolator(new ContextualMessageInterpolator(configuration." -"getDefaultMessageInterpolator()))\n" -" .buildValidatorFactory();\n" -"\n" -"Validator validator = factory.getValidator();" - -#. Tag: classname -#: bootstrapping.xml:189 -#, no-c-format -msgid "TraversableResolver" -msgstr "TraversableResolver" - -#. Tag: para -#: bootstrapping.xml:191 -#, no-c-format -msgid "" -"In some cases the validation engine should not access the state of a bean " -"property. The most obvious example for that is a lazily loaded property or " -"association of a JPA entity. Validating this lazy property or association " -"would mean that its state would have to be accessed, triggering a load from " -"the database." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:197 -#, no-c-format -msgid "" -"Which properties can be accessed and which ones not is controlled by " -"querying the TraversableResolver interface. shows how to use a " -"custom traversable resolver implementation." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:203 -#, fuzzy, no-c-format -msgid "Using a custom TraversableResolver" -msgstr "自定义的TraversableResolver" - -#. Tag: programlisting -#: bootstrapping.xml:206 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter08;\n" -"\n" -"public class MyTraversableResolver implements TraversableResolver {\n" -"\n" -" @Override\n" -" public boolean isReachable(\n" -" Object traversableObject,\n" -" Node traversableProperty,\n" -" Class<?> rootBeanType,\n" -" Path pathToTraversableObject,\n" -" ElementType elementType) {\n" -" //...\n" -" }\n" -"\n" -" @Override\n" -" public boolean isCascadable(\n" -" Object traversableObject,\n" -" Node traversableProperty,\n" -" Class<?> rootBeanType,\n" -" Path pathToTraversableObject,\n" -" ElementType elementType) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:208 -#, fuzzy, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" -" .configure()\n" -" .traversableResolver( new MyTraversableResolver() )\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" -"Configuration<?> configuration = Validation.byDefaultProvider()." -"configure();\n" -"ValidatorFactory factory = configuration\n" -" .traversableResolver(new MyTraversableResolver())\n" -" .buildValidatorFactory();\n" -"\n" -"Validator validator = factory.getValidator();" - -#. Tag: para -#: bootstrapping.xml:211 -#, fuzzy, no-c-format -msgid "" -"Hibernate Validator provides two TraversableResolvers " -"out of the box which will be enabled automatically depending on your " -"environment. The first is DefaultTraversableResolver " -"which will always return true for isReachable" -"() and isTraversable(). The second is " -"JPATraversableResolver which gets enabled when " -"Hibernate Validator is used in combination with JPA 2." -msgstr "" -"Hibernate Validator包含了两个TraversableResolver接口的" -"实现, 并且会根据你的环境来决定自动判断使用哪个实现. 首先是" -"DefaultTraversableResolver, 它的" -"isReachable()isTraversable()总是返回true. 而另外一个, JPATraversableResolver, 会在把Hibernate Validator 和JPA2一起使用的时候被启用. 如果你想提" -"供自己的实现, 可以参照." - -#. Tag: classname -#: bootstrapping.xml:223 -#, no-c-format -msgid "ConstraintValidatorFactory" -msgstr "ConstraintValidatorFactory" - -#. Tag: para -#: bootstrapping.xml:225 -#, no-c-format -msgid "" -"ConstraintValidatorFactory is the extension point for " -"customizing how constraint validators are instantiated and released." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:229 -#, fuzzy, no-c-format -msgid "" -"The default ConstraintValidatorFactory provided by " -"Hibernate Validator requires a public no-arg constructor to instantiate " -"ConstraintValidator instances (see ). Using a custom " -"ConstraintValidatorFactory offers for example the " -"possibility to use dependency injection in constraint validator " -"implementations." -msgstr "" -"最后, 还有个配置项得提一下, 那就是ConstraintValidatorFactory类. Hibernate Validator中默认的" -"ConstraintValidatorFactory需要一个无参的构造方法来初始" -"化ConstraintValidator的实例(参考). 对于自定义的" -"ConstraintValidatorFactory实现来说, 例如, 你可以让其支" -"持对约束条件的依赖注入等功能. 配置使用这个自定义的" -"ConstraintValidatorFactory的方法还是老样子()." - -#. Tag: para -#: bootstrapping.xml:237 -#, no-c-format -msgid "" -"To configure a custom constraint validator factory call " -"Configuration#constraintValidatorFactory() (see " -"." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:243 -#, fuzzy, no-c-format -msgid "Using a custom ConstraintValidatorFactory" -msgstr "自定义的ConstraintValidatorFactory" - -#. Tag: programlisting -#: bootstrapping.xml:246 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter08;\n" -"\n" -"public class MyConstraintValidatorFactory implements " -"ConstraintValidatorFactory {\n" -"\n" -" @Override\n" -" public <T extends ConstraintValidator<?, ?>> T " -"getInstance(Class<T> key) {\n" -" //...\n" -" }\n" -"\n" -" @Override\n" -" public void releaseInstance(ConstraintValidator<?, ?> " -"instance) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:248 -#, fuzzy, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" -" .configure()\n" -" .constraintValidatorFactory( new MyConstraintValidatorFactory" -"() )\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" -"Configuration<?> configuration = Validation.byDefaultProvider()." -"configure();\n" -"ValidatorFactory factory = configuration\n" -" .constraintValidatorFactory(new IOCConstraintValidatorFactory())\n" -" .buildValidatorFactory();\n" -"\n" -"Validator validator = factory.getValidator();" - -#. Tag: para -#: bootstrapping.xml:252 -#, fuzzy, no-c-format -msgid "" -"Any constraint implementations relying on " -"ConstraintValidatorFactory behaviors specific to an " -"implementation (dependency injection, no no-arg constructor and so on) are " -"not considered portable." -msgstr "" -"如果一个约束条件的实现需要依赖ConstraintValidatorFactory的某个特定的行为(例如依赖注入或者没有无参的构造方法等) 都可能导致不" -"可移植." - -#. Tag: para -#: bootstrapping.xml:259 -#, fuzzy, no-c-format -msgid "" -"ConstraintValidatorFactory implementations should not " -"cache validator instances as the state of each instance can be altered in " -"the initialize() method." -msgstr "" -"ConstraintValidatorFactory不应该缓存其创建的实例, 因为每个实例都可能在其的初" -"始化方法中被修改." - -#. Tag: classname -#: bootstrapping.xml:267 -#, no-c-format -msgid "ParameterNameProvider" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:269 -#, no-c-format -msgid "" -"In case a method or constructor parameter constraint is violated, the " -"ParameterNameProvider interface is used to retrieve " -"the parameter's name and make it available to the user via the constraint " -"violation's property path." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:274 -#, no-c-format -msgid "" -"The default implementation returns parameter names in the form " -"arg0, arg1 etc., while custom " -"implementations could e.g. be based on parameter annotations, debug symbols " -"or a feature for retrieving parameter names at runtime possibly provided by " -"future Java versions." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:280 -#, no-c-format -msgid "" -"Custom ParameterNameProvider implementations are used " -"as demonstrated in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:285 -#, no-c-format -msgid "Using a custom ParameterNameProvider" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:288 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter08;\n" -"\n" -"public class MyParameterNameProvider implements ParameterNameProvider {\n" -"\n" -" @Override\n" -" public List<String> getParameterNames(Constructor<?> " -"constructor) {\n" -" //...\n" -" }\n" -"\n" -" @Override\n" -" public List<String> getParameterNames(Method method) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:290 -#, fuzzy, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" -" .configure()\n" -" .parameterNameProvider( new MyParameterNameProvider() )\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" -"Configuration<?> configuration = Validation.byDefaultProvider()." -"configure();\n" -"ValidatorFactory factory = configuration\n" -" .traversableResolver(new MyTraversableResolver())\n" -" .buildValidatorFactory();\n" -"\n" -"Validator validator = factory.getValidator();" - -#. Tag: title -#: bootstrapping.xml:295 -#, no-c-format -msgid "Adding mapping streams" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:297 -#, no-c-format -msgid "" -"As discussed earlier you can configure the constraints applying for your " -"Java beans using XML based constraint mappings." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:300 -#, no-c-format -msgid "" -"Besides the mapping files specified in META-INF/validation.xml you can add further mappings via " -"Configuration#addMapping() (see ). Note that the passed input stream(s) " -"must adhere to the XML schema for constraint mappings presented in ." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:308 -#, no-c-format -msgid "Adding constraint mapping streams" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:310 -#, no-c-format -msgid "" -"InputStream constraintMapping1 = ...;\n" -"InputStream constraintMapping2 = ...;\n" -"ValidatorFactory validatorFactory = Validation.byDefaultProvider()\n" -" .configure()\n" -" .addMapping( constraintMapping1 )\n" -" .addMapping( constraintMapping2 )\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:313 -#, no-c-format -msgid "" -"You should close any passed input stream after the validator factory has " -"been created." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:318 -#, no-c-format -msgid "Provider-specific settings" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:320 -#, no-c-format -msgid "" -"Via the configuration object returned by Validation#byProvider()" -" provider specific options can be configured." -msgstr "" - -#. Tag: para -#: bootstrapping.xml:324 -#, no-c-format -msgid "" -"In case of Hibernate Validator this allows you to enable the fail fast mode " -"and pass one or more programmatic constraint mappings as demonstrated in " -"." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:330 -#, no-c-format -msgid "Setting Hibernate Validator specific options" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:332 -#, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.byProvider" -"( HibernateValidator.class )\n" -" .configure()\n" -" .failFast( true )\n" -" .addMapping( (ConstraintMapping) null )\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:335 -#, no-c-format -msgid "" -"Alternatively, provider-specific options can be passed via " -"Configuration#addProperty(). Hibernate Validator " -"supports enabling the fail fast mode that way, too:" -msgstr "" - -#. Tag: title -#: bootstrapping.xml:340 -#, no-c-format -msgid "" -"Enabling a Hibernate Validator specific option via addProperty()" -"" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:343 -#, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.byProvider" -"( HibernateValidator.class )\n" -" .configure()\n" -" .addProperty( \"hibernate.validator.fail_fast\", \"true\" )\n" -" .buildValidatorFactory();\n" -"Validator validator = validatorFactory.getValidator();" -msgstr "" - -#. Tag: para -#: bootstrapping.xml:346 -#, no-c-format -msgid "" -"Refer to and to learn more about the fail fast mode and the " -"constraint declaration API." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:353 -#, fuzzy, no-c-format -msgid "Configuring a Validator" -msgstr "" -"ConfigurationValidatorFactory" - -#. Tag: para -#: bootstrapping.xml:355 -#, no-c-format -msgid "" -"When working with a configured validator factory it can occasionally be " -"required to apply a different configuration to a single " -"Validator instance. shows how this can be achieved by calling " -"ValidatorFactory#usingContext()." -msgstr "" - -#. Tag: title -#: bootstrapping.xml:362 -#, no-c-format -msgid "" -"Configuring a Validator via usingContext()" -"" -msgstr "" - -#. Tag: programlisting -#: bootstrapping.xml:365 -#, no-c-format -msgid "" -"ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory" -"();\n" -"\n" -"Validator validator = validatorFactory.usingContext()\n" -" .messageInterpolator( new MyMessageInterpolator() )\n" -" .traversableResolver( new MyTraversableResolver() )\n" -" .getValidator();" -msgstr "" - -#~ msgid "" -#~ "If there are more than one Bean Validation implementation providers in " -#~ "the classpath and Validation.buildDefaultValidatorFactory() is used, there is no guarantee which provider will be chosen. " -#~ "To enforce the provider Validation.byProvider() " -#~ "should be used." -#~ msgstr "" -#~ "如果当前类路径下存在多个Bean Validation的实现, 那么Validation." -#~ "buildDefaultValidatorFactory()并不能保证具体那个实现会被使" -#~ "用. 如果想指定某一个的话, 请使用Validation.byProvider()." - -#~ msgid "" -#~ "There are three different methods in the Validation class to create a " -#~ "Validator instance. The easiest in shown in ." -#~ msgstr "" -#~ "Validation类提供了三种方法来创建一个Validator的实例, 中显示的是最简单的方法." - -#~ msgid "Validation.buildDefaultValidatorFactory()" -#~ msgstr "Validation.buildDefaultValidatorFactory()" - -#~ msgid "" -#~ "You can also use the method Validation.byDefaultProvider() which will allow you to configure several aspects of the " -#~ "created Validator instance:" -#~ msgstr "" -#~ "你也可以通过Validation.byDefaultProvider()现获取" -#~ "一个Configuration对象, 这样可以对要创建的Validator进行配置." - -#~ msgid "Validation.byDefaultProvider()" -#~ msgstr "Validation.byDefaultProvider()" - -#~ msgid "" -#~ "Configuration<?> config = Validation.byDefaultProvider().configure" -#~ "();\n" -#~ "config.messageInterpolator(new MyMessageInterpolator())\n" -#~ " .traversableResolver( new MyTraversableResolver())\n" -#~ " .constraintValidatorFactory(new MyConstraintValidatorFactory());\n" -#~ "\n" -#~ "ValidatorFactory factory = config.buildValidatorFactory();\n" -#~ "Validator validator = factory.getValidator();" -#~ msgstr "" -#~ "Configuration<?> config = Validation.byDefaultProvider().configure" -#~ "();\n" -#~ "config.messageInterpolator(new MyMessageInterpolator())\n" -#~ " .traversableResolver( new MyTraversableResolver())\n" -#~ " .constraintValidatorFactory(new MyConstraintValidatorFactory());\n" -#~ "\n" -#~ "ValidatorFactory factory = config.buildValidatorFactory();\n" -#~ "Validator validator = factory.getValidator();" - -#~ msgid "" -#~ "We will learn more about MessageInterpolator, " -#~ "TraversableResolver and " -#~ "ConstraintValidatorFactory in the following " -#~ "sections." -#~ msgstr "" -#~ "MessageInterpolator, " -#~ "TraversableResolver 和 " -#~ "ConstraintValidatorFactory会在后面详细介绍." - -#~ msgid "" -#~ "Last but not least you can ask for a Configuration object of a specific " -#~ "Bean Validation provider. This is useful if you have more than one Bean " -#~ "Validation provider in your classpath. In this situation you can make an " -#~ "explicit choice about which implementation to use. In the case of " -#~ "Hibernate Validator the Validator creation looks " -#~ "like:" -#~ msgstr "" -#~ "最后, 你可以指定使用哪个Bean Validation的实现. 如果类路径下存在多个Bean " -#~ "Validation的实现的话,这样就很有必要了. 例如, 如果你想使用Hibernate " -#~ "Validator来作为内部实现来创建Validator的话:" - -#~ msgid "Validation.byProvider( HibernateValidator.class )" -#~ msgstr "Validation.byProvider( HibernateValidator.class )" - -#~ msgid "" -#~ "HibernateValidatorConfiguration config = Validation.byProvider" -#~ "( HibernateValidator.class ).configure();\n" -#~ "config.messageInterpolator(new MyMessageInterpolator())\n" -#~ " .traversableResolver( new MyTraversableResolver())\n" -#~ " .constraintValidatorFactory(new MyConstraintValidatorFactory());\n" -#~ "\n" -#~ "ValidatorFactory factory = config.buildValidatorFactory();\n" -#~ "Validator validator = factory.getValidator();" -#~ msgstr "" -#~ "HibernateValidatorConfiguration config = Validation.byProvider" -#~ "( HibernateValidator.class ).configure();\n" -#~ "config.messageInterpolator(new MyMessageInterpolator())\n" -#~ " .traversableResolver( new MyTraversableResolver())\n" -#~ " .constraintValidatorFactory(new MyConstraintValidatorFactory());\n" -#~ "\n" -#~ "ValidatorFactory factory = config.buildValidatorFactory();\n" -#~ "Validator validator = factory.getValidator();" - -#~ msgid "" -#~ "The generated Validator instance is thread safe " -#~ "and can be cached." -#~ msgstr "" -#~ "创建出来的Validator实例是线程安全的, 所以你可以把它" -#~ "缓存起来." - -#~ msgid "" -#~ "In the case that the Java Service Provider mechanism does not work in " -#~ "your environment or you have a special classloader setup, you are able to " -#~ "provide a custom ValidationProviderResolver. An " -#~ "example in an OSGi environment you could plug your custom provider " -#~ "resolver like seen in ." -#~ msgstr "" -#~ "如果 Java Service Provider机制在你的环境中不能够正常工作, 或者你有特别的" -#~ "classloader设置的话, 你也可以提供一个自定义的" -#~ "ValidationProviderResolver.显示了如何在OSGi环境中插入自定义的provider resolver." - -#~ msgid "" -#~ "Your OSGiServiceDiscoverer must in this case " -#~ "implement the interface ValidationProviderResolver:" -#~ msgstr "" -#~ "在这种情况下, 你的OSGiServiceDiscoverer类需要实现" -#~ "ValidationProviderResolver接口:" - -#~ msgid "ValidationProviderResolver interface" -#~ msgstr "ValidationProviderResolver接口" - -#~ msgid "" -#~ "public interface ValidationProviderResolver {\n" -#~ " /**\n" -#~ " * Returns a list of ValidationProviders available in the runtime " -#~ "environment.\n" -#~ " *\n" -#~ " * @return list of validation providers. \n" -#~ " */\n" -#~ " List<ValidationProvider<?>> getValidationProviders();\n" -#~ "}" -#~ msgstr "" -#~ "public interface ValidationProviderResolver {\n" -#~ " /**\n" -#~ " * Returns a list of ValidationProviders available in the runtime " -#~ "environment.\n" -#~ " *\n" -#~ " * @return list of validation providers. \n" -#~ " */\n" -#~ " List<ValidationProvider<?>> getValidationProviders();\n" -#~ "}" - -#, fuzzy -#~ msgid "" -#~ "already discussed the default message interpolation algorithm. If you " -#~ "have special requirements for your message interpolation you can provide " -#~ "a custom interpolator using Configuration.messageInterpolator" -#~ "(). This message interpolator will be shared by all " -#~ "validators generated by the ValidatorFactory " -#~ "created from this Configuration. shows an interpolator (available in " -#~ "Hibernate Validator) which can interpolate the value being validated in " -#~ "the constraint message. To refer to this value in the constraint message " -#~ "you can use:" -#~ msgstr "" -#~ "已经讨轮过默认的错误消息解析机制. 如果这个默认的实现不能满足你的需求的话, " -#~ "你还可以通过Configuration.messageInterpolator()方" -#~ "法来提供你自定义的消息解析器. 这样, 所有通过Configuration创建出来的ValidatorFactory生成的校验器都" -#~ "会使用此消息解析器(请参考 )." - -#~ msgid "" -#~ "It is recommended that MessageInterpolator " -#~ "implementations delegate final interpolation to the Bean Validation " -#~ "default MessageInterpolator to ensure standard " -#~ "Bean Validation interpolation rules are followed. The default " -#~ "implementation is accessible through Configuration." -#~ "getDefaultMessageInterpolator()." -#~ msgstr "" -#~ "It is recommended that MessageInterpolator " -#~ "implementations delegate final interpolation to the Bean Validation " -#~ "default MessageInterpolator to ensure standard " -#~ "Bean Validation interpolation rules are followed. The default " -#~ "implementation is accessible through Configuration." -#~ "getDefaultMessageInterpolator()." - -#~ msgid "ResourceBundleLocator" -#~ msgstr "ResourceBundleLocator" - -#~ msgid "" -#~ "A common use case is the ability to specify your own resource bundles for " -#~ "message interpolation. The default MessageInterpolator implementation in Hibernate Validator is called " -#~ "ResourceBundleMessageInterpolator and per default " -#~ "loads resource bundles via ResourceBundle.getBundle. However, ResourceBundleMessageInterpolator also allows you to specify a custom implementation of " -#~ "ResourceBundleLocator allowing you to provide your " -#~ "own resource bundles. " -#~ "shows an example. In the example " -#~ "HibernateValidatorConfiguration.getDefaultResourceBundleLocator is used to retrieve the default " -#~ "ResourceBundleLocator which then can be passed to " -#~ "the custom implementation in order implement delegation." -#~ msgstr "" -#~ "一个普遍的需求是你可能需要为错误消息解析指定你自己的resource bundles. " -#~ "ResourceBundleMessageInterpolator是Hibernate " -#~ "Validator中默认的MessageInterpolator的实现, 它默认" -#~ "情况下是通过ResourceBundle.getBundle来获取" -#~ "resource bundle的. 不过, ResourceBundleMessageInterpolator也支持你指定一个自定义的ResourceBundleLocator实现来提供你自己的resource bundle. 提供了一个示例. 在这个例子中, 先通过" -#~ " HibernateValidatorConfiguration." -#~ "getDefaultResourceBundleLocator获取默认的" -#~ "ResourceBundleLocator实现, 然后再用你自定义的实现把" -#~ "默认的包装起来, 代理模式." - -#~ msgid "Providing a custom ResourceBundleLocator" -#~ msgstr "自定义的ResourceBundleLocator" - -#~ msgid "" -#~ "HibernateValidatorConfiguration configure = Validation.byProvider" -#~ "(HibernateValidator.class).configure();\n" -#~ "\n" -#~ "ResourceBundleLocator defaultResourceBundleLocator = configure." -#~ "getDefaultResourceBundleLocator(); \n" -#~ "ResourceBundleLocator myResourceBundleLocator = new " -#~ "MyCustomResourceBundleLocator(defaultResourceBundleLocator);\n" -#~ "\n" -#~ "configure.messageInterpolator(new ResourceBundleMessageInterpolator" -#~ "(myResourceBundleLocator));" -#~ msgstr "" -#~ "HibernateValidatorConfiguration configure = Validation.byProvider" -#~ "(HibernateValidator.class).configure();\n" -#~ "\n" -#~ "ResourceBundleLocator defaultResourceBundleLocator = configure." -#~ "getDefaultResourceBundleLocator(); \n" -#~ "ResourceBundleLocator myResourceBundleLocator = new " -#~ "MyCustomResourceBundleLocator(defaultResourceBundleLocator);\n" -#~ "\n" -#~ "configure.messageInterpolator(new ResourceBundleMessageInterpolator" -#~ "(myResourceBundleLocator));" - -#~ msgid "" -#~ "Hibernate Validator provides the following implementation of " -#~ "ResourceBundleLocator - " -#~ "PlatformResourceBundleLocator (the default) and " -#~ "AggregateResourceBundleLocator. The latter can be " -#~ "used to specify a list of resource bundle names which will get loaded and " -#~ "merged into a single resource bundle. Refer to the JavaDoc documentation " -#~ "for more information." -#~ msgstr "" -#~ "Hibernate Validator提供了两个ResourceBundleLocator" -#~ "的实现 - PlatformResourceBundleLocator (默认) 和 " -#~ "AggregateResourceBundleLocator. 后者可以定义一系列" -#~ "的resource bundle, 然后它会读取这些文件, 并且把它们组合成一个. 更多信息请" -#~ "参考此类的javadoc 文档." - -#~ msgid "" -#~ "The usage of the TraversableResolver has so far " -#~ "not been discussed. The idea is that in some cases, the state of a " -#~ "property should not be accessed. The most obvious example for that is a " -#~ "lazy loaded property or association of a Java Persistence provider. " -#~ "Validating this lazy property or association would mean that its state " -#~ "would have to be accessed triggering a load from the database. Bean " -#~ "Validation controls which property can and cannot be accessed via the " -#~ "TraversableResolver interface (see ). In the example " -#~ "HibernateValidatorConfiguration." -#~ msgstr "" -#~ "到目前位置我们还没有讨论过TraversableResolver接口, " -#~ "它的设计目的是在某些情况下, 我们可能不应该去获取一个属性的状态. 最典型的情" -#~ "况就是一个延迟加载的属性或者与JPA中涉及到关联关系的时候. 当验证这两种情况" -#~ "的属性的时候, 很可能会触发一次对数据库的查询.Bean Validation正是通过" -#~ "TraversableResolver接口来控制能否访问某一个属性的 " -#~ "()." - -#~ msgid "TraversableResolver interface" -#~ msgstr "TraversableResolver接口" - -#~ msgid "" -#~ "/**\n" -#~ " * Contract determining if a property can be accessed by the Bean " -#~ "Validation provider\n" -#~ " * This contract is called for each property that is being either " -#~ "validated or cascaded.\n" -#~ " *\n" -#~ " * A traversable resolver implementation must be thread-safe.\n" -#~ " *\n" -#~ " */\n" -#~ "public interface TraversableResolver {\n" -#~ " /**\n" -#~ " * Determine if the Bean Validation provider is allowed to reach the " -#~ "property state\n" -#~ " *\n" -#~ " * @param traversableObject object hosting <code>" -#~ "traversableProperty</code> or null \n" -#~ " * if validateValue is called\n" -#~ " * @param traversableProperty the traversable property.\n" -#~ " * @param rootBeanType type of the root object passed to the " -#~ "Validator.\n" -#~ " * @param pathToTraversableObject path from the root object to\n" -#~ " * <code>traversableObject</code>\n" -#~ " * (using the path specification defined by Bean Validator).\n" -#~ " * @param elementType either <code>FIELD</code> or <" -#~ "code>METHOD</code>.\n" -#~ " *\n" -#~ " * @return <code>true</code> if the Bean Validation " -#~ "provider is allowed to\n" -#~ " * reach the property state, <code>false</code> " -#~ "otherwise.\n" -#~ " */\n" -#~ " boolean isReachable(Object traversableObject,\n" -#~ " Path.Node traversableProperty,\n" -#~ " Class<?> rootBeanType,\n" -#~ " Path pathToTraversableObject,\n" -#~ " ElementType elementType);\n" -#~ "\n" -#~ " /**\n" -#~ " * Determine if the Bean Validation provider is allowed to cascade " -#~ "validation on\n" -#~ " * the bean instance returned by the property value\n" -#~ " * marked as <code>@Valid</code>.\n" -#~ " * Note that this method is called only if isReachable returns true " -#~ "for the same set of\n" -#~ " * arguments and if the property is marked as <code>@Valid</" -#~ "code>\n" -#~ " *\n" -#~ " * @param traversableObject object hosting <code>" -#~ "traversableProperty</code> or null\n" -#~ " * if validateValue is called\n" -#~ " * @param traversableProperty the traversable property.\n" -#~ " * @param rootBeanType type of the root object passed to the " -#~ "Validator.\n" -#~ " * @param pathToTraversableObject path from the root object to\n" -#~ " * <code>traversableObject</code>\n" -#~ " * (using the path specification defined by Bean Validator).\n" -#~ " * @param elementType either <code>FIELD</code> or <" -#~ "code>METHOD</code>.\n" -#~ " *\n" -#~ " * @return <code>true</code> if the Bean Validation " -#~ "provider is allowed to\n" -#~ " * cascade validation, <code>false</code> " -#~ "otherwise.\n" -#~ " */\n" -#~ " boolean isCascadable(Object traversableObject,\n" -#~ " Path.Node traversableProperty,\n" -#~ " Class<?> rootBeanType,\n" -#~ " Path pathToTraversableObject,\n" -#~ " ElementType elementType);\n" -#~ "}" -#~ msgstr "" -#~ "/**\n" -#~ " * Contract determining if a property can be accessed by the Bean " -#~ "Validation provider\n" -#~ " * This contract is called for each property that is being either " -#~ "validated or cascaded.\n" -#~ " *\n" -#~ " * A traversable resolver implementation must be thread-safe.\n" -#~ " *\n" -#~ " */\n" -#~ "public interface TraversableResolver {\n" -#~ " /**\n" -#~ " * Determine if the Bean Validation provider is allowed to reach the " -#~ "property state\n" -#~ " *\n" -#~ " * @param traversableObject object hosting <code>" -#~ "traversableProperty</code> or null \n" -#~ " * if validateValue is called\n" -#~ " * @param traversableProperty the traversable property.\n" -#~ " * @param rootBeanType type of the root object passed to the " -#~ "Validator.\n" -#~ " * @param pathToTraversableObject path from the root object to\n" -#~ " * <code>traversableObject</code>\n" -#~ " * (using the path specification defined by Bean Validator).\n" -#~ " * @param elementType either <code>FIELD</code> or <" -#~ "code>METHOD</code>.\n" -#~ " *\n" -#~ " * @return <code>true</code> if the Bean Validation " -#~ "provider is allowed to\n" -#~ " * reach the property state, <code>false</code> " -#~ "otherwise.\n" -#~ " */\n" -#~ " boolean isReachable(Object traversableObject,\n" -#~ " Path.Node traversableProperty,\n" -#~ " Class<?> rootBeanType,\n" -#~ " Path pathToTraversableObject,\n" -#~ " ElementType elementType);\n" -#~ "\n" -#~ " /**\n" -#~ " * Determine if the Bean Validation provider is allowed to cascade " -#~ "validation on\n" -#~ " * the bean instance returned by the property value\n" -#~ " * marked as <code>@Valid</code>.\n" -#~ " * Note that this method is called only if isReachable returns true " -#~ "for the same set of\n" -#~ " * arguments and if the property is marked as <code>@Valid</" -#~ "code>\n" -#~ " *\n" -#~ " * @param traversableObject object hosting <code>" -#~ "traversableProperty</code> or null\n" -#~ " * if validateValue is called\n" -#~ " * @param traversableProperty the traversable property.\n" -#~ " * @param rootBeanType type of the root object passed to the " -#~ "Validator.\n" -#~ " * @param pathToTraversableObject path from the root object to\n" -#~ " * <code>traversableObject</code>\n" -#~ " * (using the path specification defined by Bean Validator).\n" -#~ " * @param elementType either <code>FIELD</code> or <" -#~ "code>METHOD</code>.\n" -#~ " *\n" -#~ " * @return <code>true</code> if the Bean Validation " -#~ "provider is allowed to\n" -#~ " * cascade validation, <code>false</code> " -#~ "otherwise.\n" -#~ " */\n" -#~ " boolean isCascadable(Object traversableObject,\n" -#~ " Path.Node traversableProperty,\n" -#~ " Class<?> rootBeanType,\n" -#~ " Path pathToTraversableObject,\n" -#~ " ElementType elementType);\n" -#~ "}" - -#~ msgid "The interface you have to implement is:" -#~ msgstr "你需要实现此接口:" - -#~ msgid "ConstraintValidatorFactory interface" -#~ msgstr "ConstraintValidatorFactory接口" - -#~ msgid "" -#~ "public interface ConstraintValidatorFactory {\n" -#~ " /**\n" -#~ " * @param key The class of the constraint validator to instantiate.\n" -#~ " *\n" -#~ " * @return A constraint validator instance of the specified class.\n" -#~ " */\n" -#~ " <T extends ConstraintValidator<?,?>> T getInstance" -#~ "(Class<T> key);\n" -#~ "}" -#~ msgstr "" -#~ "public interface ConstraintValidatorFactory {\n" -#~ " /**\n" -#~ " * @param key The class of the constraint validator to instantiate.\n" -#~ " *\n" -#~ " * @return A constraint validator instance of the specified class.\n" -#~ " */\n" -#~ " <T extends ConstraintValidator<?,?>> T getInstance" -#~ "(Class<T> key);\n" -#~ "}" diff --git a/documentation/src/main/docbook/zh-CN/modules/custom-constraints.po b/documentation/src/main/docbook/zh-CN/modules/custom-constraints.po deleted file mode 100644 index 8f35435b30..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/custom-constraints.po +++ /dev/null @@ -1,1137 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: custom-constraints.xml:24 -#, no-c-format -msgid "Creating custom constraints" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:26 -#, no-c-format -msgid "" -"Though the Bean Validation API defines a whole set of standard constraint " -"annotations one can easily think of situations in which these standard " -"annotations won't suffice. For these cases you are able to create custom " -"constraints tailored to your specific validation requirements in a simple " -"manner." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:33 -#, no-c-format -msgid "Creating a simple constraint" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:35 -#, no-c-format -msgid "To create a custom constraint, the following three steps are required:" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:40 -#, no-c-format -msgid "Create a constraint annotation" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:44 -#, no-c-format -msgid "Implement a validator" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:48 -#, no-c-format -msgid "Define a default error message" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:53 -#, no-c-format -msgid "The constraint annotation" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:55 -#, no-c-format -msgid "" -"Let's write a constraint annotation, that can be used to express that a " -"given string shall either be upper case or lower case. We'll apply it later " -"on to the licensePlate field of the Car class from to " -"ensure, that the field is always an upper-case string." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:62 -#, no-c-format -msgid "" -"First we need a way to express the two case modes. We might use " -"String constants, but a better way to go is to use a " -"Java 5 enum for that purpose:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:67 -#, no-c-format -msgid "Enum CaseMode to express upper vs. lower case" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:70 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06;\n" -"\n" -"public enum CaseMode {\n" -" UPPER,\n" -" LOWER;\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:73 -#, no-c-format -msgid "" -"Now we can define the actual constraint annotation. If you've never designed " -"an annotation before, this may look a bit scary, but actually it's not that " -"hard:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:78 -#, no-c-format -msgid "Defining the CheckCase constraint annotation" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:81 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06;\n" -"\n" -"@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE })\n" -"@Retention(RUNTIME)\n" -"@Constraint(validatedBy = CheckCaseValidator.class)\n" -"@Documented\n" -"public @interface CheckCase {\n" -"\n" -" String message() default \"{org.hibernate.validator.referenceguide." -"chapter06.CheckCase.message}\";\n" -"\n" -" Class<?>[] groups() default { };\n" -"\n" -" Class<? extends Payload>[] payload() default { };\n" -"\n" -" CaseMode value();\n" -"\n" -" @Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE })\n" -" @Retention(RUNTIME)\n" -" @Documented\n" -" @interface List {\n" -" CheckCase[] value();\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:84 -#, no-c-format -msgid "" -"An annotation type is defined using the @interface keyword. All " -"attributes of an annotation type are declared in a method-like manner. The " -"specification of the Bean Validation API demands, that any constraint " -"annotation defines" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:91 -#, no-c-format -msgid "" -"an attribute message that returns the default key for " -"creating error messages in case the constraint is violated" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:97 -#, no-c-format -msgid "" -"an attribute groups that allows the specification of " -"validation groups, to which this constraint belongs (see ). This must default to an empty array of type " -"Class<?>." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:104 -#, no-c-format -msgid "" -"an attribute payload that can be used by clients of " -"the Bean Validation API to assign custom payload objects to a constraint. " -"This attribute is not used by the API itself. An example for a custom " -"payload could be the definition of a severity:" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:110 -#, no-c-format -msgid "" -"public class Severity {\n" -" public interface Info extends Payload {\n" -" }\n" -"\n" -" public interface Error extends Payload {\n" -" }\n" -"}\n" -"\n" -"public class ContactDetails {\n" -" @NotNull(message = \"Name is mandatory\", payload = Severity.Error." -"class)\n" -" private String name;\n" -"\n" -" @NotNull(message = \"Phone number not specified, but not mandatory" -"\",\n" -" payload = Severity.Info.class)\n" -" private String phoneNumber;\n" -"\n" -" // ...\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:112 -#, no-c-format -msgid "" -"Now a client can after the validation of a ContactDetails instance access the severity of a constraint using " -"ConstraintViolation.getConstraintDescriptor().getPayload() and adjust its behaviour depending on the severity." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:120 -#, no-c-format -msgid "" -"Besides these three mandatory attributes we add another one, " -"value, allowing for the required case mode to be " -"specified. The name value is a special one, which can " -"be omitted when using the annotation, if it is the only attribute specified, " -"as e.g. in @CheckCase(CaseMode.UPPER)." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:126 -#, no-c-format -msgid "" -"In addition we annotate the annotation type with a couple of meta " -"annotations:" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:131 -#, no-c-format -msgid "" -"@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE }): Defines " -"the supported target element types for the constraint. " -"@CheckCase may be used on fields (element type " -"FIELD), JavaBeans properties as well as method return " -"values (METHOD) and method/constructor parameters " -"(PARAMETER). By adding the element type " -"ANNOTATION_TYPE, we allow for the creation composed " -"constraints (see ) based " -"on @CheckCase." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:142 -#, no-c-format -msgid "" -"Would we create a class-level constraint (see ), the element type TYPE " -"had to be used. Constraints targetting the return value of a constructor " -"need to support the element type CONSTRUCTOR. Cross-" -"parameter constraints (see TODO) which are used to validate all the " -"parameters of a method or constructor together, must support " -"METHOD or CONSTRUCTOR, " -"respectively." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:153 -#, no-c-format -msgid "" -"@Retention(RUNTIME): Specifies, that annotations of this type " -"will be available at runtime by the means of reflection" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:159 -#, no-c-format -msgid "" -"@Constraint(validatedBy = CheckCaseValidator.class): Marks the " -"annotation type as constraint annotation and specifies the validator to be " -"used to validate elements annotated with @CheckCase. " -"If a constraint may be used on several data types, several validators may be " -"specified, one for each data type." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:168 -#, no-c-format -msgid "" -"@Documented: Says, that the use of @CheckCase will be contained in the JavaDoc of elements annotated with it" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:174 -#, no-c-format -msgid "" -"Finally, there is an inner annotation type named List. This annotation allows to specify several @CheckCase annotations on the same element, e.g. with different validation " -"groups and messages. Note that while also another name could be used, we " -"follow the Bean Validation, which recommends to use the name " -"List and make the annotation an inner annotation of " -"the corresponding constraint type." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:185 -#, no-c-format -msgid "The constraint validator" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:188 -#, no-c-format -msgid "" -"Next, we need to implement a constraint validator, which is able to validate " -"elements with a @CheckCase annotation. To do so, we " -"implement the interface ConstraintValidator as shown " -"below:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:194 -#, no-c-format -msgid "" -"Implementing a constraint validator for the constraint CheckCase" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:197 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06;\n" -"\n" -"public class CheckCaseValidator implements ConstraintValidator<CheckCase, " -"String> {\n" -"\n" -" private CaseMode caseMode;\n" -"\n" -" @Override\n" -" public void initialize(CheckCase constraintAnnotation) {\n" -" this.caseMode = constraintAnnotation.value();\n" -" }\n" -"\n" -" @Override\n" -" public boolean isValid(String object, ConstraintValidatorContext " -"constraintContext) {\n" -" if ( object == null ) {\n" -" return true;\n" -" }\n" -"\n" -" if ( caseMode == CaseMode.UPPER ) {\n" -" return object.equals( object.toUpperCase() );\n" -" }\n" -" else {\n" -" return object.equals( object.toLowerCase() );\n" -" }\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:200 -#, no-c-format -msgid "" -"The ConstraintValidator interface defines two type " -"parameters, which we set in our implementation. The first one specifies the " -"annotation type to be validated (in our example CheckCase), the second one the type of elements, which the validator can " -"handle (here String)." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:207 -#, no-c-format -msgid "" -"In case a constraint annotation is allowed at elements of different types, a " -"ConstraintValidator for each allowed type has to be " -"implemented and registered at the constraint annotation as shown above." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:212 -#, no-c-format -msgid "" -"The implementation of the validator is straightforward. The " -"initialize() method gives us access to the " -"attribute values of the annotation to be validated. In the example we store " -"the CaseMode in a field of the validator for further " -"usage." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:218 -#, no-c-format -msgid "" -"In the isValid() method we implement the logic, " -"that determines, whether a String is valid according " -"to a given @CheckCase annotation or not. This " -"decision depends on the case mode retrieved in initialize(). As the Bean Validation specification recommends, we consider " -"null values as being valid. If null is not a valid " -"value for an element, it should be annotated with @NotNull " -"explicitly." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:228 -#, no-c-format -msgid "The ConstraintValidatorContext" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:230 -#, no-c-format -msgid "" -"relies on the default error message generation by just returning " -"true or false from the " -"isValid call. Using the passed " -"ConstraintValidatorContext object it is possible to " -"either add additional error messages or completely disable the default error " -"message generation and solely define custom error messages. The " -"ConstraintValidatorContext API is modeled as fluent " -"interface and is best demonstrated with an example:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:242 -#, no-c-format -msgid "Use of ConstraintValidatorContext to define custom error messages" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:245 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06." -"constraintvalidatorcontext;\n" -"\n" -"public class CheckCaseValidator implements ConstraintValidator<CheckCase, " -"String> {\n" -"\n" -" private CaseMode caseMode;\n" -"\n" -" @Override\n" -" public void initialize(CheckCase constraintAnnotation) {\n" -" this.caseMode = constraintAnnotation.value();\n" -" }\n" -"\n" -" @Override\n" -" public boolean isValid(String object, ConstraintValidatorContext " -"constraintContext) {\n" -" if ( object == null ) {\n" -" return true;\n" -" }\n" -"\n" -" boolean isValid;\n" -" if ( caseMode == CaseMode.UPPER ) {\n" -" isValid = object.equals( object.toUpperCase() );\n" -" }\n" -" else {\n" -" isValid = object.equals( object.toLowerCase() );\n" -" }\n" -"\n" -" if ( !isValid ) {\n" -" constraintContext.disableDefaultConstraintViolation" -"();\n" -" constraintContext." -"buildConstraintViolationWithTemplate(\n" -" \"{org.hibernate.validator." -"referenceguide.chapter06.constraintvalidatorcontext.CheckCase.message}\"\n" -" )\n" -" .addConstraintViolation();\n" -" }\n" -"\n" -" return isValid;\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:248 -#, no-c-format -msgid "" -"shows how you can disable the default error message generation and add a " -"custom error message using a specified message template. In this example the " -"use of the ConstraintValidatorContext results in the " -"same error message as the default error message generation." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:254 -#, no-c-format -msgid "" -"It is important to add each configured constraint violation by calling " -"addConstraintViolation(). Only after that the new " -"constraint violation will be created." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:259 -#, no-c-format -msgid "" -"In case you are implementing a ConstraintValidator " -"for a class-level constraint it is also possible to adjust the property path " -"for the created constraint violations. This is important for the case where " -"you validate multiple properties of the class or even traverse the object " -"graph and want the constraint violation to point to one of the involved " -"properties only. As an example, " -"shows the validator of a custom class-level constraint " -"@ValidPassengerCount which makes sure that a car has " -"not more passengers than seats. If this constraint is violated, this " -"violation is reported at the passengers property." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:273 -#, no-c-format -msgid "" -"Adding new ConstraintViolation with custom property " -"path" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:276 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06.custompath;\n" -"\n" -"public class ValidPassengerCountValidator\n" -" implements ConstraintValidator<ValidPassengerCount, " -"Car> {\n" -"\n" -" @Override\n" -" public void initialize(ValidPassengerCount constraintAnnotation) {\n" -" }\n" -"\n" -" @Override\n" -" public boolean isValid(Car car, ConstraintValidatorContext " -"constraintValidatorContext) {\n" -" if ( car == null ) {\n" -" return true;\n" -" }\n" -"\n" -" boolean isValid = car.getPassengers().size() <= car." -"getSeatCount();\n" -"\n" -" if ( !isValid ) {\n" -" constraintValidatorContext." -"disableDefaultConstraintViolation();\n" -" constraintValidatorContext\n" -" .buildConstraintViolationWithTemplate" -"( \"{my.custom.template}\" )\n" -" .addPropertyNode( \"passengers\" )." -"addConstraintViolation();\n" -" }\n" -"\n" -" return isValid;\n" -" }\n" -"}" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:282 -#, no-c-format -msgid "The error message" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:284 -#, no-c-format -msgid "" -"Finally we need to specify the error message, that shall be used, in case a " -"@CheckCase constraint is violated. To do so, we add " -"the following to our custom ValidationMessages.properties (see also )" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:291 -#, no-c-format -msgid "" -"Defining a custom error message for the CheckCase " -"constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:294 -#, no-c-format -msgid "" -"org.hibernate.validator.referenceguide.chapter06.CheckCase.message=Case mode " -"must be {value}." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:297 -#, no-c-format -msgid "" -"If a validation error occurs, the validation runtime will use the default " -"value, that we specified for the message attribute of the " -"@CheckCase annotation to look up the error message in " -"this file." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:304 -#, no-c-format -msgid "Using the constraint" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:306 -#, no-c-format -msgid "" -"Now that our first custom constraint is completed, we can use it in the " -"Car class from the chapter to specify that the licensePlate field shall only contain upper-case strings:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:313 -#, no-c-format -msgid "Applying the CheckCase constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:316 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private final String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" @CheckCase(CaseMode.UPPER)\n" -" private final String licensePlate;\n" -"\n" -" @Min(2)\n" -" private final int seatCount;\n" -"\n" -" public Car ( String manufacturer, String licencePlate, int " -"seatCount ) {\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:319 -#, no-c-format -msgid "" -"Finally let's demonstrate in a little test that the @CheckCase constraint is properly validated:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:324 -#, no-c-format -msgid "Testcase demonstrating the CheckCase validation" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:327 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06;\n" -"\n" -"public class CarTest {\n" -"\n" -" private static Validator validator;\n" -"\n" -" @BeforeClass\n" -" public static void setUp() {\n" -" ValidatorFactory factory = Validation." -"buildDefaultValidatorFactory();\n" -" validator = factory.getValidator();\n" -" }\n" -"\n" -" @Test\n" -" public void testLicensePlateNotUpperCase() {\n" -"\n" -" Car car = new Car( \"Morris\", \"dd-ab-123\", 4 );\n" -"\n" -" Set<ConstraintViolation<Car>> " -"constraintViolations =\n" -" validator.validate( car );\n" -" assertEquals( 1, constraintViolations.size() );\n" -" assertEquals(\n" -" \"Case mode must be UPPER.\",\n" -" constraintViolations.iterator().next()." -"getMessage()\n" -" );\n" -" }\n" -"\n" -" @Test\n" -" public void carIsValid() {\n" -"\n" -" Car car = new Car( \"Morris\", \"DD-AB-123\", 4 );\n" -"\n" -" Set<ConstraintViolation<Car>> " -"constraintViolations =\n" -" validator.validate( car );\n" -"\n" -" assertEquals( 0, constraintViolations.size() );\n" -" }\n" -"}" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:333 -#, no-c-format -msgid "Cross-parameter constraints" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:335 -#, no-c-format -msgid "" -"Bean Validation distinguishes between two different kinds of constraints." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:338 -#, no-c-format -msgid "" -"Generic constraints (which have been discussed so far) apply to the " -"annotated element, e.g. a type, field, method parameter or return value etc. " -"Cross-parameter constraints, in contrast, apply to the array of parameters " -"of a method or constructor and can be used to express validation logic which " -"depends on several parameter values." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:344 -#, no-c-format -msgid "" -"In order to define a cross-parameter constraint, its validator class must be " -"annotated with @SupportedValidationTarget(ValidationTarget." -"PARAMETERS). The type parameter T from the " -"ConstraintValidator interface must resolve to either " -"Object or Object[] in order to " -"receive the array of method/constructor arguments in the isValid" -"() method." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:353 -#, no-c-format -msgid "" -"The following example shows the definition of a cross-parameter constraint " -"which can be used to check that two Date parameters " -"of a method are in the correct order:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:358 -#, no-c-format -msgid "Cross-parameter constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:360 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06.crossparameter;\n" -"\n" -"@Constraint(validatedBy = ConsistentDateParameterValidator.class)\n" -"@Target({ METHOD, CONSTRUCTOR, ANNOTATION_TYPE })\n" -"@Retention(RUNTIME)\n" -"@Documented\n" -"public @interface ConsistentDateParameters {\n" -"\n" -" String message() default \"{org.hibernate.validator.referenceguide." -"chapter06.\" +\n" -" \"crossparameter.ConsistentDateParameters." -"message}\";\n" -"\n" -" Class<?>[] groups() default { };\n" -"\n" -" Class<? extends Payload>[] payload() default { };\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:363 -#, no-c-format -msgid "" -"The definition of a cross-parameter constraint isn't any different from " -"defining a generic constraint, i.e. it must specify the members " -"message(), groups() and " -"payload() and be annotated with " -"@Constraint. This meta annotation also specifies the " -"corresponding validator, which is shown in . Note that besides the element types " -"METHOD and CONSTRUCTOR also " -"ANNOTATION_TYPE is specified as target of the " -"annotation, in order to enable the creation of composed constraints based on " -"@ConsistentDateParameters (see )." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:378 -#, no-c-format -msgid "" -"Cross-parameter constraints are specified directly on the declaration of a " -"method or constructor, which is also the case for return value constraints. " -"In order to improve code readability, it is therefore recommended to chose " -"constraint names — such as @ConsistentDateParameters " -"— which make the constraint target aparent." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:387 custom-constraints.xml:419 -#, no-c-format -msgid "Generic and cross-parameter constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:389 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06.crossparameter;\n" -"\n" -"@SupportedValidationTarget(ValidationTarget.PARAMETERS)\n" -"public class ConsistentDateParameterValidator implements\n" -" ConstraintValidator<ConsistentDateParameters, Object[]" -"> {\n" -"\n" -" @Override\n" -" public void initialize(ConsistentDateParameters " -"constraintAnnotation) {\n" -" }\n" -"\n" -" @Override\n" -" public boolean isValid(Object[] value, ConstraintValidatorContext " -"context) {\n" -" if ( value.length != 2 ) {\n" -" throw new IllegalArgumentException( \"Illegal method " -"signature\" );\n" -" }\n" -"\n" -" //leave null-checking to @NotNull on individual parameters\n" -" if ( value[0] == null || value[1] == null ) {\n" -" return true;\n" -" }\n" -"\n" -" if ( !( value[0] instanceof Date ) || !( value[1] instanceof " -"Date ) ) {\n" -" throw new IllegalArgumentException(\n" -" \"Illegal method signature, expected " -"two \" +\n" -" \"parameters of type " -"Date.\"\n" -" );\n" -" }\n" -"\n" -" return ( (Date) value[0] ).before( (Date) value[1] );\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:392 -#, no-c-format -msgid "" -"As discussed above, the validation target PARAMETERS must " -"be configured for a cross-parameter validator by using the " -"@SupportedValidationTarget annotation. Since a cross-" -"parameter constraint could be applied to any method or constructor, it is " -"considered a best practice to check for the expected number and types of " -"parameters in the validator implementation. As with generic constraints, " -"null parameters should be considered valid and " -"@NotNull on the individual parameters should be used " -"to make sure that parameters are not null." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:403 -#, no-c-format -msgid "" -"In rare situations a constraint is both, generic and cross-parameter. This " -"is the case if a constraint has a validator class which is annotated with " -"@SupportedValidationTarget({ValidationTarget.PARAMETERS, " -"ValidationTarget.ANNOTATED_ELEMENT}) or if it has a generic and " -"a cross-parameter validator class." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:410 -#, no-c-format -msgid "" -"When declaring such a constraint on a method which has parameters and also a " -"return value, the intended constraint target can't be determined. " -"Constraints which are generic and cross-parameter at the same time, must " -"therefore define a member validationAppliesTo() " -"which allows the constraint user to specify the constraint's target as shown " -"in ." -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:421 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06.crossparameter;\n" -"\n" -"@Constraint(validatedBy = {\n" -" ScriptAssertObjectValidator.class,\n" -" ScriptAssertParametersValidator.class\n" -"})\n" -"@Target({ TYPE, FIELD, PARAMETER, METHOD, CONSTRUCTOR, ANNOTATION_TYPE })\n" -"@Retention(RUNTIME)\n" -"@Documented\n" -"public @interface ScriptAssert {\n" -"\n" -" String message() default \"{org.hibernate.validator.referenceguide." -"chapter06.\" +\n" -" \"crossparameter.ScriptAssert.message}\";\n" -"\n" -" Class<?>[] groups() default { };\n" -"\n" -" Class<? extends Payload>[] payload() default { };\n" -"\n" -" String script();\n" -"\n" -" ConstraintTarget validationAppliesTo() default ConstraintTarget." -"IMPLICIT;\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:424 -#, no-c-format -msgid "" -"The @ScriptAssert constraint has two validators (not " -"shown), a generic and a cross-parameter one and thus defines the member " -"validationAppliesTo(). The default value " -"IMPLICIT allows to derive the target automatically in " -"situations where this is possible (e.g. if the constraint is declared on a " -"field or on a method which has parameters but no return value)." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:432 -#, no-c-format -msgid "" -"If the target can not be determined implicitly, it must be set by the user " -"to either PARAMETERS or RETURN_VALUE " -"as shown in ." -msgstr "" - -#. Tag: title -#: custom-constraints.xml:438 -#, no-c-format -msgid "Specifying the target for a generic and cross-parameter constraint" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:441 -#, no-c-format -msgid "" -"@ScriptAssert(script = \"arg1.size() <= arg0\", validationAppliesTo = " -"ConstraintTarget.PARAMETERS)\n" -"public Car buildCar(int seatCount, List<Passenger> passengers) {\n" -" //...\n" -"}" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:446 -#, no-c-format -msgid "Constraint composition" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:448 -#, no-c-format -msgid "" -"In the following, we'll discuss how to create higher level constraints by " -"composing several basic constraints." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:451 -#, no-c-format -msgid "" -"Looking at the licensePlate field of the " -"Car class in , we see three constraint annotations already. In complexer " -"scenarios, where even more constraints could be applied to one element, this " -"might become a bit confusing easily. Furthermore, if we had a " -"licensePlate field in another class, we would have to " -"copy all constraint declarations to the other class as well, violating the " -"DRY principle." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:460 -#, no-c-format -msgid "" -"This problem can be tackled using composed constraints. In the following we " -"create a new constraint annotation @ValidLicensePlate, that comprises the constraints @NotNull, " -"@Size and @CheckCase:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:467 -#, no-c-format -msgid "" -"Creating a composing constraint ValidLicensePlate" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:470 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06." -"constraintcomposition;\n" -"\n" -"@NotNull\n" -"@Size(min = 2, max = 14)\n" -"@CheckCase(CaseMode.UPPER)\n" -"@Target({ METHOD, FIELD, ANNOTATION_TYPE })\n" -"@Retention(RUNTIME)\n" -"@Constraint(validatedBy = { })\n" -"@Documented\n" -"public @interface ValidLicensePlate {\n" -"\n" -" String message() default \"{org.hibernate.validator.referenceguide." -"chapter06.constraintcomposition.ValidLicensePlate.message}\";\n" -"\n" -" Class<?>[] groups() default { };\n" -"\n" -" Class<? extends Payload>[] payload() default { };\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:473 -#, no-c-format -msgid "" -"To do so, we just have to annotate the constraint declaration with its " -"comprising constraints (btw. that's exactly why we allowed annotation types " -"as target for the @CheckCase annotation). As no " -"additional validation is required for the @ValidLicensePlate annotation itself, we don't declare a validator within the " -"@Constraint meta annotation." -msgstr "" - -#. Tag: para -#: custom-constraints.xml:481 -#, no-c-format -msgid "" -"Using the new composed constraint at the licensePlate " -"field is fully equivalent to the previous version, where we declared the " -"three constraints directly at the field itself:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:487 -#, no-c-format -msgid "" -"Application of composing constraint ValidLicensePlate" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:490 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter06." -"constraintcomposition;\n" -"\n" -"public class Car {\n" -"\n" -" @ValidLicensePlate\n" -" private String licensePlate;\n" -"\n" -" //...\n" -"}" -msgstr "" - -#. Tag: para -#: custom-constraints.xml:493 -#, no-c-format -msgid "" -"The set of ConstraintViolations retrieved when " -"validating a Car instance will contain an entry for " -"each violated composing constraint of the @ValidLicensePlate constraint. If you rather prefer a single " -"ConstraintViolation in case any of the composing " -"constraints is violated, the @ReportAsSingleViolation " -"meta constraint can be used as follows:" -msgstr "" - -#. Tag: title -#: custom-constraints.xml:503 -#, no-c-format -msgid "Usage of @ReportAsSingleViolation" -msgstr "" - -#. Tag: programlisting -#: custom-constraints.xml:505 -#, no-c-format -msgid "" -"//...\n" -"@ReportAsSingleViolation\n" -"public @interface ValidLicensePlate {\n" -"\n" -" String message() default \"{org.hibernate.validator.referenceguide." -"chapter06.constraintcomposition.ValidLicensePlate.message}\";\n" -"\n" -" Class<?>[] groups() default { };\n" -"\n" -" Class<? extends Payload>[] payload() default { };\n" -"}" -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/custom-options.po b/documentation/src/main/docbook/zh-CN/modules/custom-options.po deleted file mode 100644 index c5e7e7ca5e..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/custom-options.po +++ /dev/null @@ -1,619 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: custom-options.xml:24 -#, no-c-format -msgid "Hibernate Validator Specifics" -msgstr "" - -#. Tag: para -#: custom-options.xml:26 -#, no-c-format -msgid "" -"In this chapter you will learn how to make use of several features provided " -"by Hibernate Validator in addition to the functionality defined by the Bean " -"Validation specification. This includes the fail fast mode, the API for " -"programmatic constraint configuration and the boolean composition of " -"constraints." -msgstr "" - -#. Tag: para -#: custom-options.xml:33 -#, no-c-format -msgid "" -"Using the features described in the following sections may result in " -"application code which is not portable between Bean Validation providers." -msgstr "" - -#. Tag: title -#: custom-options.xml:39 -#, no-c-format -msgid "Public API" -msgstr "" - -#. Tag: para -#: custom-options.xml:41 -#, no-c-format -msgid "" -"Let's start, however, with a look at the public API of Hibernate Validator. " -" lists all packages belonging to " -"this API and describes their purpose. Note that when a package is part of " -"the public this is not necessarily true for its sub-packages." -msgstr "" - -#. Tag: title -#: custom-options.xml:48 -#, no-c-format -msgid "Hibernate Validator public API" -msgstr "" - -#. Tag: entry -#: custom-options.xml:53 -#, no-c-format -msgid "Packages" -msgstr "" - -#. Tag: entry -#: custom-options.xml:55 -#, no-c-format -msgid "Description" -msgstr "" - -#. Tag: package -#: custom-options.xml:61 -#, no-c-format -msgid "org.hibernate.validator" -msgstr "" - -#. Tag: entry -#: custom-options.xml:63 -#, no-c-format -msgid "" -"Classes used by the Bean Validation bootstrap mechanism (eg. validation " -"provider, configuration class); For more details see ." -msgstr "" - -#. Tag: entry -#: custom-options.xml:69 -#, no-c-format -msgid "" -"org.hibernate.validator.cfg, org.hibernate." -"validator.cfg.context, org.hibernate.validator.cfg.defs" -msgstr "" - -#. Tag: entry -#: custom-options.xml:73 -#, no-c-format -msgid "" -"Hibernate Validator's fluent API for constraint declaration; In org." -"hibernate.validator.cfg you will find the " -"ConstraintMapping interface and in org." -"hibernate.validator.cfg.defs all constraint definitions. Refer to " -" for the details." -msgstr "" - -#. Tag: entry -#: custom-options.xml:82 -#, no-c-format -msgid "" -"org.hibernate.validator.constraints, org." -"hibernate.validator.constraints.br" -msgstr "" - -#. Tag: entry -#: custom-options.xml:85 -#, no-c-format -msgid "" -"Some useful custom constraints provided by Hibernate Validator in addition " -"to the built-in constraints defined by the Bean Validation specification; " -"The constraints are described in detail in ." -msgstr "" - -#. Tag: entry -#: custom-options.xml:93 -#, no-c-format -msgid "" -"org.hibernate.validator.group, org.hibernate." -"validator.spi.group" -msgstr "" - -#. Tag: entry -#: custom-options.xml:96 -#, no-c-format -msgid "" -"The group sequence provider feature which allows you to define dynamic " -"default group sequences in function of the validated object state; The " -"specifics can be found in ." -msgstr "" - -#. Tag: entry -#: custom-options.xml:103 -#, no-c-format -msgid "" -"org.hibernate.validator.messageinterpolation, " -"org.hibernate.validator.resourceloading, org." -"hibernate.validator.spi.resourceloading" -msgstr "" - -#. Tag: entry -#: custom-options.xml:107 -#, no-c-format -msgid "" -"Classes related to constraint message interpolation; The first package " -"contains Hibernate Validator's default message interpolator, " -"ResourceBundleMessageInterpolator. The latter two " -"packages provide the ResourceBundleLocator SPI for " -"the loading of resource bundles (see ) and its default implementation." -msgstr "" - -#. Tag: para -#: custom-options.xml:121 -#, no-c-format -msgid "" -"The public packages of Hibernate Validator fall into two categories: while " -"the actual API parts are intended to be invoked or " -"used by clients (e.g. the API for programmatic " -"constraint declaration or the custom constraints), the SPI (service provider " -"interface) packages contain interfaces which are intended to be " -"implemented by clients (e.g. " -"ResourceBundleLocator)." -msgstr "" - -#. Tag: para -#: custom-options.xml:130 -#, no-c-format -msgid "" -"Any packages not listed in that table are internal packages of Hibernate " -"Validator and are not intended to be accessed by clients. The contents of " -"these internal packages can change from release to release without notice, " -"thus possibly breaking any client code relying on it." -msgstr "" - -#. Tag: title -#: custom-options.xml:138 -#, no-c-format -msgid "Fail fast mode" -msgstr "" - -#. Tag: para -#: custom-options.xml:140 -#, no-c-format -msgid "" -"Using the fail fast mode, Hibernate Validator allows to return from the " -"current validation as soon as the first constraint violation occurs. This " -"can be useful for the validation of large object graphs where you are only " -"interested in a quick check whether there is any constraint violation at all." -msgstr "" - -#. Tag: para -#: custom-options.xml:146 -#, no-c-format -msgid "shows how to bootstrap and use a fail fast enabled validator." -msgstr "" - -#. Tag: title -#: custom-options.xml:150 -#, no-c-format -msgid "Using the fail fast validation mode" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:152 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter11.failfast;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @AssertTrue\n" -" private boolean isRegistered;\n" -"\n" -" public Car(String manufacturer, boolean isRegistered) {\n" -" this.manufacturer = manufacturer;\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"\n" -" //getters and setters...\n" -"}" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:154 -#, no-c-format -msgid "" -"Validator validator = Validation.byProvider( HibernateValidator.class )\n" -" .configure()\n" -" .failFast( true )\n" -" .buildValidatorFactory()\n" -" .getValidator();\n" -"\n" -"Car car = new Car( null, false );\n" -"\n" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validate( car );\n" -"\n" -"assertEquals( 1, constraintViolations.size() );" -msgstr "" - -#. Tag: para -#: custom-options.xml:157 -#, no-c-format -msgid "" -"Here the validated object actually fails to satisfy both the constraints " -"declared on the Car class, yet the validation call " -"yields only one ConstraintViolation since the fail " -"fast mode is enabled." -msgstr "" - -#. Tag: para -#: custom-options.xml:163 -#, no-c-format -msgid "" -"There is no guarantee in which order the constraints are evaluated, i.e. it " -"is not deterministic whether the returned violation originates from the " -"@NotNull or the @AssertTrue " -"constraint. If required, a deterministic evaluation order can be enforced " -"using group sequences as described in ." -msgstr "" - -#. Tag: para -#: custom-options.xml:171 -#, no-c-format -msgid "" -"Refer to to learn " -"about the different ways of enabling the fail fast mode when bootstrapping a " -"validator." -msgstr "" - -#. Tag: title -#: custom-options.xml:177 custom-options.xml:203 -#, no-c-format -msgid "Programmatic constraint declaration" -msgstr "" - -#. Tag: para -#: custom-options.xml:179 -#, no-c-format -msgid "" -"As per the Bean Validation specification, you can declare constraints using " -"Java annotations and XML based constraint mappings." -msgstr "" - -#. Tag: para -#: custom-options.xml:183 -#, no-c-format -msgid "" -"In addition, Hibernate Validator provides a fluent API which allows for the " -"programmatic configuration of constraints. Use cases include the dynamic " -"addition of constraints at runtime depending on some application state or " -"tests where you need entities with different constraints in different " -"scenarios but don't want to implement actual Java classes for each test case." -msgstr "" - -#. Tag: para -#: custom-options.xml:190 -#, no-c-format -msgid "" -"By default, constraints added via the fluent API are additive to constraints " -"configured via the standard configuration capabilities. But it is also " -"possible to ignore annotation and XML configured constraints where required." -msgstr "" - -#. Tag: para -#: custom-options.xml:195 -#, no-c-format -msgid "" -"The API is centered around the ConstraintMapping " -"interface. You obtain a new mapping via " -"HibernateValidatorConfiguration#createConstraintMapping() which you then can configure in a fluent manner as shown in ." -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:205 -#, no-c-format -msgid "" -"HibernateValidatorConfiguration configuration = Validation\n" -" .byProvider( HibernateValidator.class )\n" -" .configure();\n" -"\n" -"ConstraintMapping constraintMapping = configuration.createConstraintMapping" -"();\n" -"\n" -"constraintMapping\n" -" .type( Car.class )\n" -" .property( \"manufacturer\", FIELD )\n" -" .constraint( new NotNullDef() )\n" -" .property( \"licensePlate\", FIELD )\n" -" .ignoreAnnotations()\n" -" .constraint( new NotNullDef() )\n" -" .constraint( new SizeDef().min( 2 ).max( 14 ) )\n" -" .type( RentalCar.class )\n" -" .property( \"rentalStation\", METHOD )\n" -" .constraint( new NotNullDef() );\n" -"\n" -"Validator validator = configuration.addMapping( constraintMapping )\n" -" .buildValidatorFactory()\n" -" .getValidator();" -msgstr "" - -#. Tag: para -#: custom-options.xml:208 -#, no-c-format -msgid "" -"Constraints can be configured on multiple classes and properties using " -"method chaining. The constraint definition classes NotNullDef and SizeDef are helper classes which allow " -"to configure constraint parameters in a type-safe fashion. Definition " -"classes exist for all built-in constraints in the org.hibernate." -"validator.cfg.defs package. By calling " -"ignoreAnnotations() any constraints configured via " -"annotations or XML are ignored for the given element." -msgstr "" - -#. Tag: para -#: custom-options.xml:218 -#, no-c-format -msgid "" -"Having configured the mapping, you must add it back to the configuration " -"object from which you then can obtain a validator factory." -msgstr "" - -#. Tag: para -#: custom-options.xml:222 -#, no-c-format -msgid "" -"For custom constraints you can either create your own definition classes " -"extending ConstraintDef or you can use " -"GenericConstraintDef as seen in ." -msgstr "" - -#. Tag: title -#: custom-options.xml:228 -#, no-c-format -msgid "Programmatic declaration of a custom constraint" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:230 -#, no-c-format -msgid "" -"ConstraintMapping constraintMapping = configuration.createConstraintMapping" -"();\n" -"\n" -"constraintMapping\n" -" .type( Car.class )\n" -" .property( \"licensePlate\", FIELD )\n" -" .constraint( new GenericConstraintDef<" -"CheckCase>( CheckCase.class )\n" -" .param( \"value\", CaseMode.UPPER )\n" -" );" -msgstr "" - -#. Tag: para -#: custom-options.xml:233 -#, no-c-format -msgid "" -"By invoking valid() a member is marked for " -"cascasded validation which is equivalent to annotating it with " -"@Valid. An example can be seen in ." -msgstr "" - -#. Tag: title -#: custom-options.xml:239 -#, no-c-format -msgid "Marking a property for cascaded validation" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:241 -#, no-c-format -msgid "" -"ConstraintMapping constraintMapping = configuration.createConstraintMapping" -"();\n" -"\n" -"constraintMapping\n" -" .type( Car.class )\n" -" .property( \"driver\", FIELD )\n" -" .constraint( new NotNullDef() )\n" -" .valid()\n" -" .type( Person.class )\n" -" .property( \"name\", FIELD )\n" -" .constraint( new NotNullDef() );" -msgstr "" - -#. Tag: para -#: custom-options.xml:244 -#, no-c-format -msgid "" -"Not only bean constraints but also method constraints can be configured " -"using the fluent API. As shown in methods are identified by their name and parameter " -"types. Having selected a method, you can marke its parameters and/or return " -"value for cascaded validation and add constraints." -msgstr "" - -#. Tag: title -#: custom-options.xml:252 -#, no-c-format -msgid "Programmatic declaration of method constraints" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:254 -#, no-c-format -msgid "" -"ConstraintMapping constraintMapping = configuration.createConstraintMapping" -"();\n" -"\n" -"constraintMapping\n" -" .type( Car.class )\n" -" .method( \"drive\", int.class )\n" -" .parameter( 0 )\n" -" .constraint( new MaxDef().value ( 75 ) )\n" -" .method( \"getDriver\" )\n" -" .returnValue()\n" -" .constraint( new NotNullDef() )\n" -" .valid();" -msgstr "" - -#. Tag: para -#: custom-options.xml:257 -#, no-c-format -msgid "" -"Last but not least you can configure the default group sequence or the " -"default group sequence provider of a type as shown in the following example." -msgstr "" - -#. Tag: title -#: custom-options.xml:262 -#, no-c-format -msgid "" -"Configuration of default group sequence and default group sequence provider" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:265 -#, no-c-format -msgid "" -"ConstraintMapping constraintMapping = configuration.createConstraintMapping" -"();\n" -"\n" -"constraintMapping\n" -" .type( Car.class )\n" -" .defaultGroupSequence( Car.class, CarChecks.class )\n" -" .type( RentalCar.class )\n" -" .defaultGroupSequenceProviderClass" -"( RentalCarGroupSequenceProvider.class );" -msgstr "" - -#. Tag: title -#: custom-options.xml:270 -#, no-c-format -msgid "Boolean composition of constraints" -msgstr "" - -#. Tag: para -#: custom-options.xml:272 -#, no-c-format -msgid "" -"Bean Validation specificies that the constraints of a composed constraint " -"(see ) are all combined " -"via a logical AND. This means all of the composing " -"constraints need to return true in order for an overall " -"successful validation." -msgstr "" - -#. Tag: para -#: custom-options.xml:278 -#, no-c-format -msgid "" -"Hibernate Validator offers an extension to this and allows you to compose " -"constraints via a logical OR or NOT. To do so you have to use the ConstraintComposition annotation and the enum CompositionType " -"with its values AND, OR and " -"ALL_FALSE." -msgstr "" - -#. Tag: para -#: custom-options.xml:286 -#, no-c-format -msgid "" -"shows how to build a composed constraint @PatternOrSize where only one of the composing constraints needs to be valid in " -"order to pass the validation. Either the validated string is all lower-cased " -"or it is between two and three characters long." -msgstr "" - -#. Tag: title -#: custom-options.xml:293 -#, no-c-format -msgid "OR composition of constraints" -msgstr "" - -#. Tag: programlisting -#: custom-options.xml:295 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter11." -"booleancomposition;\n" -"\n" -"@ConstraintComposition(OR)\n" -"@Pattern(regexp = \"[a-z]\")\n" -"@Size(min = 2, max = 3)\n" -"@ReportAsSingleViolation\n" -"@Target({ METHOD, FIELD })\n" -"@Retention(RUNTIME)\n" -"@Constraint(validatedBy = { })\n" -"public @interface PatternOrSize {\n" -" String message() default \"{org.hibernate.validator.referenceguide." -"chapter11.\" +\n" -" \"booleancomposition.PatternOrSize.message}\";\n" -"\n" -" Class<?>[] groups() default { };\n" -"\n" -" Class<? extends Payload>[] payload() default { };\n" -"}" -msgstr "" - -#. Tag: para -#: custom-options.xml:299 -#, no-c-format -msgid "" -"Using ALL_FALSE as composition type implicitly enforces " -"that only a single violation will get reported in case validation of the " -"constraint composition fails." -msgstr "" - -#. Tag: classname -#: custom-options.xml:306 -#, no-c-format -msgid "ResourceBundleLocator" -msgstr "" - -#. Tag: para -#: custom-options.xml:308 -#, no-c-format -msgid "" -"As described in , " -"Bean Validation allows to plug in custom message interpolator " -"implementations." -msgstr "" - -#. Tag: para -#: custom-options.xml:312 -#, no-c-format -msgid "" -"With ResourceBundleLocator, Hibernate Validator " -"provides an additional SPI which allows to retrieve error messages from " -"other resource bundles than ValidationMessages while " -"still using the actual interpolation algorithm as defined by the " -"specification. Refer to " -"to learn how to make use of that SPI." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/customconstraints.po b/documentation/src/main/docbook/zh-CN/modules/customconstraints.po deleted file mode 100644 index 6320ac117c..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/customconstraints.po +++ /dev/null @@ -1,1199 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2011-11-14 10:37+0000\n" -"PO-Revision-Date: 2010-08-21 02:16+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: customconstraints.xml:24 -#, no-c-format -msgid "Creating custom constraints" -msgstr "创建自己的约束规则" - -#. Tag: para -#: customconstraints.xml:26 -#, no-c-format -msgid "" -"Though the Bean Validation API defines a whole set of standard constraint " -"annotations one can easily think of situations in which these standard " -"annotations won't suffice. For these cases you are able to create custom " -"constraints tailored to your specific validation requirements in a simple " -"manner." -msgstr "" -"尽管Bean Validation API定义了一大堆标准的约束条件, 但是肯定还是有这些约束不能" -"满足我们需求的时候, 在这种情况下, 你可以根据你的特定的校验需求来创建自己的约" -"束条件." - -#. Tag: title -#: customconstraints.xml:33 -#, no-c-format -msgid "Creating a simple constraint" -msgstr "创建一个简单的约束条件" - -#. Tag: para -#: customconstraints.xml:35 -#, no-c-format -msgid "To create a custom constraint, the following three steps are required:" -msgstr "按照以下三个步骤来创建一个自定义的约束条件" - -#. Tag: para -#: customconstraints.xml:40 -#, no-c-format -msgid "Create a constraint annotation" -msgstr "创建约束标注" - -#. Tag: para -#: customconstraints.xml:44 -#, no-c-format -msgid "Implement a validator" -msgstr "实现一个验证器" - -#. Tag: para -#: customconstraints.xml:48 -#, no-c-format -msgid "Define a default error message" -msgstr "定义默认的验证错误信息" - -#. Tag: title -#: customconstraints.xml:53 -#, no-c-format -msgid "The constraint annotation" -msgstr "约束标注" - -#. Tag: para -#: customconstraints.xml:55 -#, no-c-format -msgid "" -"Let's write a constraint annotation, that can be used to express that a " -"given string shall either be upper case or lower case. We'll apply it later " -"on to the licensePlate field of the Car class from to " -"ensure, that the field is always an upper-case string." -msgstr "" -"让我们来创建一个新的用来判断一个给定字符串是否全是大写或者小写字符的约束标" -"注. 我们将稍后把它用在中的类" -"CarlicensePlate字段上来确保这个" -"字段的内容一直都是大写字母." - -#. Tag: para -#: customconstraints.xml:62 -#, no-c-format -msgid "" -"First we need a way to express the two case modes. We might use " -"String constants, but a better way to go is to use a " -"Java 5 enum for that purpose:" -msgstr "" -"首先,我们需要一种方法来表示这两种模式( 译注: 大写或小写), 我们可以使用" -"String常量, 但是在Java 5中, 枚举类型是个更好的选择:" - -#. Tag: title -#: customconstraints.xml:67 -#, no-c-format -msgid "Enum CaseMode to express upper vs. lower case" -msgstr "枚举类型CaseMode, 来表示大写或小写模式." - -#. Tag: programlisting -#: customconstraints.xml:70 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"public enum CaseMode {\n" -" UPPER, \n" -" LOWER;\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"public enum CaseMode {\n" -" UPPER, \n" -" LOWER;\n" -"}" - -#. Tag: para -#: customconstraints.xml:73 -#, no-c-format -msgid "" -"Now we can define the actual constraint annotation. If you've never designed " -"an annotation before, this may look a bit scary, but actually it's not that " -"hard:" -msgstr "" -"现在我们可以来定义真正的约束标注了. 如果你以前没有创建过标注(annotation)的话," -"那么这个可能看起来有点吓人, 可是其实没有那么难的 :)" - -#. Tag: title -#: customconstraints.xml:78 -#, no-c-format -msgid "Defining CheckCase constraint annotation" -msgstr "定义一个CheckCase的约束标注" - -#. Tag: programlisting -#: customconstraints.xml:80 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import static java.lang.annotation.ElementType.*;\n" -"import static java.lang.annotation.RetentionPolicy.*;\n" -"\n" -"import java.lang.annotation.Documented;\n" -"import java.lang.annotation.Retention;\n" -"import java.lang.annotation.Target;\n" -"\n" -"import javax.validation.Constraint;\n" -"import javax.validation.Payload;\n" -"\n" -"@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n" -"@Retention(RUNTIME)\n" -"@Constraint(validatedBy = CheckCaseValidator.class)\n" -"@Documented\n" -"public @interface CheckCase {\n" -"\n" -" String message() default \"{com.mycompany.constraints.checkcase}\";\n" -"\n" -" Class<?>[] groups() default {};\n" -"\n" -" Class<? extends Payload>[] payload() default {};\n" -" \n" -" CaseMode value();\n" -"\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import static java.lang.annotation.ElementType.*;\n" -"import static java.lang.annotation.RetentionPolicy.*;\n" -"\n" -"import java.lang.annotation.Documented;\n" -"import java.lang.annotation.Retention;\n" -"import java.lang.annotation.Target;\n" -"\n" -"import javax.validation.Constraint;\n" -"import javax.validation.Payload;\n" -"\n" -"@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n" -"@Retention(RUNTIME)\n" -"@Constraint(validatedBy = CheckCaseValidator.class)\n" -"@Documented\n" -"public @interface CheckCase {\n" -"\n" -" String message() default \"{com.mycompany.constraints.checkcase}\";\n" -"\n" -" Class<?>[] groups() default {};\n" -"\n" -" Class<? extends Payload>[] payload() default {};\n" -" \n" -" CaseMode value();\n" -"\n" -"}" - -#. Tag: para -#: customconstraints.xml:83 -#, no-c-format -msgid "" -"An annotation type is defined using the @interface keyword. All " -"attributes of an annotation type are declared in a method-like manner. The " -"specification of the Bean Validation API demands, that any constraint " -"annotation defines" -msgstr "" -"一个标注(annotation) 是通过@interface关键字来定义的. 这个标注中" -"的属性是声明成类似方法的样式的. 根据Bean Validation API 规范的要求" - -#. Tag: para -#: customconstraints.xml:90 -#, no-c-format -msgid "" -"an attribute message that returns the default key for " -"creating error messages in case the constraint is violated" -msgstr "" -"message属性, 这个属性被用来定义默认得消息模版, 当这个约" -"束条件被验证失败的时候,通过此属性来输出错误信息." - -#. Tag: para -#: customconstraints.xml:96 -#, no-c-format -msgid "" -"an attribute groups that allows the specification of " -"validation groups, to which this constraint belongs (see ). This must default to an " -"empty array of type Class<?>." -msgstr "" -"groups 属性, 用于指定这个约束条件属于哪(些)个校验组(请参" -"考). 这个的默认" -"值必须是Class<?>类型到空到数组." - -#. Tag: para -#: customconstraints.xml:104 -#, no-c-format -msgid "" -"an attribute payload that can be used by clients of " -"the Bean Validation API to assign custom payload objects to a constraint. " -"This attribute is not used by the API itself." -msgstr "" -"payload 属性, Bean Validation API 的使用者可以通过此属" -"性来给约束条件指定严重级别. 这个属性并不被API自身所使用." - -#. Tag: para -#: customconstraints.xml:108 -#, no-c-format -msgid "An example for a custom payload could be the definition of a severity." -msgstr "通过payload属性来指定默认错误严重级别的示例" - -#. Tag: programlisting -#: customconstraints.xml:111 -#, no-c-format -msgid "" -"public class Severity {\n" -" public static class Info extends Payload {};\n" -" public static class Error extends Payload {};\n" -"}\n" -"\n" -"public class ContactDetails {\n" -" @NotNull(message=\"Name is mandatory\", payload=Severity.Error.class)\n" -" private String name;\n" -"\n" -" @NotNull(message=\"Phone number not specified, but not mandatory\", " -"payload=Severity.Info.class)\n" -" private String phoneNumber;\n" -"\n" -" // ...\n" -"}" -msgstr "" -"public class Severity {\n" -" public static class Info extends Payload {};\n" -" public static class Error extends Payload {};\n" -"}\n" -"\n" -"public class ContactDetails {\n" -" @NotNull(message=\"Name is mandatory\", payload=Severity.Error.class)\n" -" private String name;\n" -"\n" -" @NotNull(message=\"Phone number not specified, but not mandatory\", " -"payload=Severity.Info.class)\n" -" private String phoneNumber;\n" -"\n" -" // ...\n" -"}" - -#. Tag: para -#: customconstraints.xml:113 -#, no-c-format -msgid "" -"Now a client can after the validation of a ContactDetails instance access the severity of a constraint using " -"ConstraintViolation.getConstraintDescriptor().getPayload() and adjust its behaviour depending on the severity." -msgstr "" -"这样, 在校验完一个ContactDetails 的示例之后, 你就可以" -"通过调用ConstraintViolation.getConstraintDescriptor().getPayload" -"()来得到之前指定到错误级别了,并且可以根据这个信息来决定接下来到" -"行为." - -#. Tag: para -#: customconstraints.xml:122 -#, no-c-format -msgid "" -"Besides those three mandatory attributes (message, " -"groups and payload) we add another " -"one allowing for the required case mode to be specified. The name " -"value is a special one, which can be omitted upon using " -"the annotation, if it is the only attribute specified, as e.g. in " -"@CheckCase(CaseMode.UPPER)." -msgstr "" -"除了这三个强制性要求的属性(message, groupspayload) 之外, 我们还添加了一个属性用来指定" -"所要求到字符串模式. 此属性的名称value在annotation的定义" -"中比较特殊, 如果只有这个属性被赋值了的话, 那么, 在使用此annotation到时候可以" -"忽略此属性名称, 即@CheckCase(CaseMode.UPPER)." - -#. Tag: para -#: customconstraints.xml:130 -#, no-c-format -msgid "" -"In addition we annotate the annotation type with a couple of so-called meta " -"annotations:" -msgstr "" -"另外, 我们还给这个annotation标注了一些(所谓的) 元标注( 译注: 或\"元模型信息" -"\"?, \"meta annotatioins\"): " - -#. Tag: para -#: customconstraints.xml:135 -#, no-c-format -msgid "" -"@Target({ METHOD, FIELD, ANNOTATION_TYPE }): Says, that " -"methods, fields and annotation declarations may be annotated with @CheckCase " -"(but not type declarations e.g.)" -msgstr "" -"@Target({ METHOD, FIELD, ANNOTATION_TYPE }): 表示@CheckCase 可以" -"被用在方法, 字段或者annotation声明上." - -#. Tag: para -#: customconstraints.xml:141 -#, no-c-format -msgid "" -"@Retention(RUNTIME): Specifies, that annotations of this type " -"will be available at runtime by the means of reflection" -msgstr "" -"@Retention(RUNTIME): 表示这个标注信息是在运行期通过反射被读取的." - -#. Tag: para -#: customconstraints.xml:147 -#, no-c-format -msgid "" -"@Constraint(validatedBy = CheckCaseValidator.class): Specifies " -"the validator to be used to validate elements annotated with @CheckCase" -msgstr "" -"@Constraint(validatedBy = CheckCaseValidator.class): 指明使用那" -"个校验器(类) 去校验使用了此标注的元素." - -#. Tag: para -#: customconstraints.xml:153 -#, no-c-format -msgid "" -"@Documented: Says, that the use of @CheckCase will " -"be contained in the JavaDoc of elements annotated with it" -msgstr "" -"@Documented: 表示在对使用了@CheckCase的类进行" -"javadoc操作到时候, 这个标注会被添加到javadoc当中." - -#. Tag: para -#: customconstraints.xml:160 -#, no-c-format -msgid "" -"Hibernate Validator provides support for the validation of method parameters " -"using constraint annotations (see )." -msgstr "" - -#. Tag: para -#: customconstraints.xml:164 -#, no-c-format -msgid "" -"In order to use a custom constraint for parameter validation the " -"ElementType.PARAMETER must be specified within the " -"@Target annotation. This is already the case for all " -"constraints defined by the Bean Validation API and also the custom " -"constraints provided by Hibernate Validator." -msgstr "" - -#. Tag: title -#: customconstraints.xml:173 -#, no-c-format -msgid "The constraint validator" -msgstr "约束校验器" - -#. Tag: para -#: customconstraints.xml:176 -#, fuzzy, no-c-format -msgid "" -"Next, we need to implement a constraint validator, that's able to validate " -"elements with a @CheckCase annotation. To do so, we " -"implement the interface ConstraintValidator as shown " -"below:" -msgstr "" -"接下来, 我们需要实现一个约束验证器, 它是被用来校验应用了" -"@CheckCase标注到元素到. 如下面例子所示, 这个验证器需要" -"实现ConstraintValidator接口." - -#. Tag: title -#: customconstraints.xml:182 -#, no-c-format -msgid "" -"Implementing a constraint validator for the constraint CheckCase" -msgstr "约束条件CheckCase的验证器" - -#. Tag: programlisting -#: customconstraints.xml:185 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.ConstraintValidator;\n" -"import javax.validation.ConstraintValidatorContext;\n" -"\n" -"public class CheckCaseValidator implements ConstraintValidator<CheckCase, " -"String> {\n" -"\n" -" private CaseMode caseMode;\n" -"\n" -" public void initialize(CheckCase constraintAnnotation) {\n" -" this.caseMode = constraintAnnotation.value();\n" -" }\n" -"\n" -" public boolean isValid(String object, ConstraintValidatorContext " -"constraintContext) {\n" -"\n" -" if (object == null)\n" -" return true;\n" -"\n" -" if (caseMode == CaseMode.UPPER)\n" -" return object.equals(object.toUpperCase());\n" -" else\n" -" return object.equals(object.toLowerCase());\n" -" }\n" -"\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.ConstraintValidator;\n" -"import javax.validation.ConstraintValidatorContext;\n" -"\n" -"public class CheckCaseValidator implements ConstraintValidator<CheckCase, " -"String> {\n" -"\n" -" private CaseMode caseMode;\n" -"\n" -" public void initialize(CheckCase constraintAnnotation) {\n" -" this.caseMode = constraintAnnotation.value();\n" -" }\n" -"\n" -" public boolean isValid(String object, ConstraintValidatorContext " -"constraintContext) {\n" -"\n" -" if (object == null)\n" -" return true;\n" -"\n" -" if (caseMode == CaseMode.UPPER)\n" -" return object.equals(object.toUpperCase());\n" -" else\n" -" return object.equals(object.toLowerCase());\n" -" }\n" -"\n" -"}" - -#. Tag: para -#: customconstraints.xml:188 -#, no-c-format -msgid "" -"The ConstraintValidator interface defines two type " -"parameters, which we set in our implementation. The first one specifies the " -"annotation type to be validated (in our example CheckCase), the second one the type of elements, which the validator can " -"handle (here String)." -msgstr "" -"ConstraintValidator定义了两个泛型参数, 第一个是这个校" -"验器所服务到标注类型(在我们的例子中即CheckCase), 第二" -"个这个校验器所支持到被校验元素到类型 (即String)." - -#. Tag: para -#: customconstraints.xml:195 -#, no-c-format -msgid "" -"In case a constraint annotation is allowed at elements of different types, a " -"ConstraintValidator for each allowed type has to be " -"implemented and registered at the constraint annotation as shown above." -msgstr "" -"如果一个约束标注支持多种类型到被校验元素的话, 那么需要为每个所支持的类型定义" -"一个ConstraintValidator,并且注册到约束标注中." - -#. Tag: para -#: customconstraints.xml:200 -#, no-c-format -msgid "" -"The implementation of the validator is straightforward. The " -"initialize() method gives us access to the " -"attribute values of the annotation to be validated. In the example we store " -"the CaseMode in a field of the validator for further " -"usage." -msgstr "" -"这个验证器的实现就很平常了, initialize() 方法传进来" -"一个所要验证的标注类型的实例, 在本例中, 我们通过此实例来获取其value属性的值," -"并将其保存为CaseMode类型的成员变量供下一步使用." - -#. Tag: para -#: customconstraints.xml:206 -#, no-c-format -msgid "" -"In the isValid() method we implement the logic, " -"that determines, whether a String is valid according " -"to a given @CheckCase annotation or not. This " -"decision depends on the case mode retrieved in initialize(). As the Bean Validation specification recommends, we consider " -"null values as being valid. If null is not a valid " -"value for an element, it should be annotated with @NotNull " -"explicitly." -msgstr "" -"isValid()是实现真正的校验逻辑的地方, 判断一个给定的" -"String对于@CheckCase这个约束条" -"件来说是否是合法的, 同时这还要取决于在initialize()中获" -"得的大小写模式. 根据Bean Validation中所推荐的做法, 我们认为null" -"是合法的值. 如果null对于这个元素来说是不合法的话,那么它应该使用" -"@NotNull来标注." - -#. Tag: title -#: customconstraints.xml:216 -#, no-c-format -msgid "The ConstraintValidatorContext" -msgstr "ConstraintValidatorContext" - -#. Tag: para -#: customconstraints.xml:218 -#, no-c-format -msgid "" -"relies on the default error message generation by just returning " -"true or false from the " -"isValid call. Using the passed " -"ConstraintValidatorContext object it is possible to " -"either add additional error messages or completely disable the default error " -"message generation and solely define custom error messages. The " -"ConstraintValidatorContext API is modeled as fluent " -"interface and is best demonstrated with an example:" -msgstr "" -"中的isValid使用了约束条件中定义的错误消息模板, 然后" -"返回一个true 或者 false. 通过使用传" -"入的ConstraintValidatorContext对象, 我们还可以给约束条" -"件中定义的错误信息模板来添加额外的信息或者完全创建一个新的错误信息模板. " - -#. Tag: title -#: customconstraints.xml:230 -#, no-c-format -msgid "Use of ConstraintValidatorContext to define custom error messages" -msgstr "使用ConstraintValidatorContext来自定义错误信息" - -#. Tag: programlisting -#: customconstraints.xml:233 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.ConstraintValidator;\n" -"import javax.validation.ConstraintValidatorContext;\n" -"\n" -"public class CheckCaseValidator implements ConstraintValidator<CheckCase, " -"String> {\n" -"\n" -" private CaseMode caseMode;\n" -"\n" -" public void initialize(CheckCase constraintAnnotation) {\n" -" this.caseMode = constraintAnnotation.value();\n" -" }\n" -"\n" -" public boolean isValid(String object, ConstraintValidatorContext " -"constraintContext) {\n" -"\n" -" if (object == null)\n" -" return true;\n" -" \n" -" boolean isValid;\n" -" if (caseMode == CaseMode.UPPER) {\n" -" isValid = object.equals(object.toUpperCase());\n" -" }\n" -" else {\n" -" isValid = object.equals(object.toLowerCase());\n" -" }\n" -" \n" -" if(!isValid) {\n" -" constraintContext.disableDefaultConstraintViolation();\n" -" constraintContext.buildConstraintViolationWithTemplate( \"{com." -"mycompany.constraints.CheckCase.message}\" ).addConstraintViolation();\n" -" }\n" -" return result;\n" -" }\n" -"\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.ConstraintValidator;\n" -"import javax.validation.ConstraintValidatorContext;\n" -"\n" -"public class CheckCaseValidator implements ConstraintValidator<CheckCase, " -"String> {\n" -"\n" -" private CaseMode caseMode;\n" -"\n" -" public void initialize(CheckCase constraintAnnotation) {\n" -" this.caseMode = constraintAnnotation.value();\n" -" }\n" -"\n" -" public boolean isValid(String object, ConstraintValidatorContext " -"constraintContext) {\n" -"\n" -" if (object == null)\n" -" return true;\n" -" \n" -" boolean isValid;\n" -" if (caseMode == CaseMode.UPPER) {\n" -" isValid = object.equals(object.toUpperCase());\n" -" }\n" -" else {\n" -" isValid = object.equals(object.toLowerCase());\n" -" }\n" -" \n" -" if(!isValid) {\n" -" constraintContext.disableDefaultConstraintViolation();\n" -" constraintContext.buildConstraintViolationWithTemplate( \"{com." -"mycompany.constraints.CheckCase.message}\" ).addConstraintViolation();\n" -" }\n" -" return result;\n" -" }\n" -"\n" -"}" - -#. Tag: para -#: customconstraints.xml:236 -#, no-c-format -msgid "" -"shows how you can disable the default error message generation and add a " -"custom error message using a specified message template. In this example the " -"use of the ConstraintValidatorContext results in the " -"same error message as the default error message generation." -msgstr "" -"演示了如果创建一个新的错误信息模板来替换掉约束条件中定义的默认的. 在本例中, " -"实际上通过调用ConstraintValidatorContext达到了一个使用" -"默认消息模板的效果." - -#. Tag: para -#: customconstraints.xml:242 -#, no-c-format -msgid "" -"It is important to end each new constraint violation with " -"addConstraintViolation. Only after that the new " -"constraint violation will be created." -msgstr "" -"在创建新的constraint violation的时候一定要记得调用" -"addConstraintViolation, 只有这样, 这个新的" -"constraint violation才会被真正的创建." - -#. Tag: para -#: customconstraints.xml:247 -#, no-c-format -msgid "" -"In case you are implementing a ConstraintValidator a " -"class level constraint it is also possible to adjust set the property path " -"for the created constraint violations. This is important for the case where " -"you validate multiple properties of the class or even traverse the object " -"graph. A custom property path creation could look like ." -msgstr "" - -#. Tag: title -#: customconstraints.xml:256 -#, no-c-format -msgid "" -"Adding new ConstraintViolation with custom property " -"path" -msgstr "" - -#. Tag: programlisting -#: customconstraints.xml:259 -#, no-c-format -msgid "" -"public boolean isValid(Group group, ConstraintValidatorContext " -"constraintValidatorContext) {\n" -" boolean isValid = false;\n" -" ...\n" -"\n" -" if(!isValid) {\n" -" constraintValidatorContext\n" -" .buildConstraintViolationWithTemplate( \"{my.custom." -"template}\" )\n" -" .addNode( \"myProperty\" ).addConstraintViolation();\n" -" }\n" -" return isValid;\n" -"}" -msgstr "" -"public boolean isValid(Group group, ConstraintValidatorContext " -"constraintValidatorContext) {\n" -" boolean isValid = false;\n" -" ...\n" -"\n" -" if(!isValid) {\n" -" constraintValidatorContext\n" -" .buildConstraintViolationWithTemplate( \"{my.custom." -"template}\" )\n" -" .addNode( \"myProperty\" ).addConstraintViolation();\n" -" }\n" -" return isValid;\n" -"}" - -#. Tag: title -#: customconstraints.xml:265 -#, no-c-format -msgid "The error message" -msgstr "校验错误信息" - -#. Tag: para -#: customconstraints.xml:267 -#, no-c-format -msgid "" -"Finally we need to specify the error message, that shall be used, in case a " -"@CheckCase constraint is violated. To do so, we add " -"the following to our custom ValidationMessages.properties (see also )" -msgstr "" -"最后, 我们还需要指定如果@CheckCase这个约束条件验证的时" -"候,没有通过的话的校验错误信息. 我们可以添加下面的内容到我们项目自定义的" -"ValidationMessages.properties (参考 )文件中." - -#. Tag: title -#: customconstraints.xml:274 -#, no-c-format -msgid "" -"Defining a custom error message for the CheckCase " -"constraint" -msgstr "为CheckCase约束定义一个错误信息" - -#. Tag: programlisting -#: customconstraints.xml:277 -#, no-c-format -msgid "com.mycompany.constraints.CheckCase.message=Case mode must be {value}." -msgstr "com.mycompany.constraints.CheckCase.message=Case mode must be {value}." - -#. Tag: para -#: customconstraints.xml:280 -#, no-c-format -msgid "" -"If a validation error occurs, the validation runtime will use the default " -"value, that we specified for the message attribute of the " -"@CheckCase annotation to look up the error message in " -"this file." -msgstr "" -"如果发现校验错误了的话, 你所使用的Bean Validation的实现会用我们定义在" -"@CheckCase中message属性上的值作为键到这个文件中去查找" -"对应的错误信息." - -#. Tag: title -#: customconstraints.xml:287 -#, no-c-format -msgid "Using the constraint" -msgstr "应用约束条件" - -#. Tag: para -#: customconstraints.xml:289 -#, no-c-format -msgid "" -"Now that our first custom constraint is completed, we can use it in the " -"Car class from the chapter to specify that the licensePlate field shall only contain upper-case strings:" -msgstr "" -"现在我们已经有了一个自定义的约束条件了, 我们可以把它用在中的Car类上, 来校验此类" -"的licensePlate属性的值是否全都是大写字母." - -#. Tag: title -#: customconstraints.xml:296 -#, no-c-format -msgid "Applying the CheckCase constraint" -msgstr "应用CheckCase约束条件" - -#. Tag: programlisting -#: customconstraints.xml:299 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.Min;\n" -"import javax.validation.constraints.NotNull;\n" -"import javax.validation.constraints.Size;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" @CheckCase(CaseMode.UPPER)\n" -" private String licensePlate;\n" -"\n" -" @Min(2)\n" -" private int seatCount;\n" -" \n" -" public Car(String manufacturer, String licencePlate, int seatCount) {\n" -"\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.Min;\n" -"import javax.validation.constraints.NotNull;\n" -"import javax.validation.constraints.Size;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" @CheckCase(CaseMode.UPPER)\n" -" private String licensePlate;\n" -"\n" -" @Min(2)\n" -" private int seatCount;\n" -" \n" -" public Car(String manufacturer, String licencePlate, int seatCount) {\n" -"\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"\n" -"}" - -#. Tag: para -#: customconstraints.xml:302 -#, no-c-format -msgid "" -"Finally let's demonstrate in a little test that the @CheckCase constraint is properly validated:" -msgstr "" -"最后,让我们用一个简单的测试来检测@CheckCase约束已经被" -"正确的校验了:" - -#. Tag: title -#: customconstraints.xml:307 -#, no-c-format -msgid "Testcase demonstrating the CheckCase validation" -msgstr "演示CheckCase的验证过程" - -#. Tag: programlisting -#: customconstraints.xml:310 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import static org.junit.Assert.*;\n" -"\n" -"import java.util.Set;\n" -"\n" -"import javax.validation.ConstraintViolation;\n" -"import javax.validation.Validation;\n" -"import javax.validation.Validator;\n" -"import javax.validation.ValidatorFactory;\n" -"\n" -"import org.junit.BeforeClass;\n" -"import org.junit.Test;\n" -"\n" -"public class CarTest {\n" -"\n" -" private static Validator validator;\n" -"\n" -" @BeforeClass\n" -" public static void setUp() {\n" -" ValidatorFactory factory = Validation.buildDefaultValidatorFactory" -"();\n" -" validator = factory.getValidator();\n" -" }\n" -"\n" -" @Test\n" -" public void testLicensePlateNotUpperCase() {\n" -"\n" -" Car car = new Car(\"Morris\", \"dd-ab-123\", 4);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -" assertEquals(1, constraintViolations.size());\n" -" assertEquals(\n" -" \"Case mode must be UPPER.\", \n" -" constraintViolations.iterator().next().getMessage());\n" -" }\n" -"\n" -" @Test\n" -" public void carIsValid() {\n" -"\n" -" Car car = new Car(\"Morris\", \"DD-AB-123\", 4);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -"\n" -" assertEquals(0, constraintViolations.size());\n" -" }\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import static org.junit.Assert.*;\n" -"\n" -"import java.util.Set;\n" -"\n" -"import javax.validation.ConstraintViolation;\n" -"import javax.validation.Validation;\n" -"import javax.validation.Validator;\n" -"import javax.validation.ValidatorFactory;\n" -"\n" -"import org.junit.BeforeClass;\n" -"import org.junit.Test;\n" -"\n" -"public class CarTest {\n" -"\n" -" private static Validator validator;\n" -"\n" -" @BeforeClass\n" -" public static void setUp() {\n" -" ValidatorFactory factory = Validation.buildDefaultValidatorFactory" -"();\n" -" validator = factory.getValidator();\n" -" }\n" -"\n" -" @Test\n" -" public void testLicensePlateNotUpperCase() {\n" -"\n" -" Car car = new Car(\"Morris\", \"dd-ab-123\", 4);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -" assertEquals(1, constraintViolations.size());\n" -" assertEquals(\n" -" \"Case mode must be UPPER.\", \n" -" constraintViolations.iterator().next().getMessage());\n" -" }\n" -"\n" -" @Test\n" -" public void carIsValid() {\n" -"\n" -" Car car = new Car(\"Morris\", \"DD-AB-123\", 4);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -"\n" -" assertEquals(0, constraintViolations.size());\n" -" }\n" -"}" - -#. Tag: title -#: customconstraints.xml:316 -#, no-c-format -msgid "Constraint composition" -msgstr "约束条件组合" - -#. Tag: para -#: customconstraints.xml:318 -#, no-c-format -msgid "" -"Looking at the licensePlate field of the " -"Car class in , we see three constraint annotations already. In complexer " -"scenarios, where even more constraints could be applied to one element, this " -"might become a bit confusing easily. Furthermore, if we had a " -"licensePlate field in another class, we would have to " -"copy all constraint declarations to the other class as well, violating the " -"DRY principle." -msgstr "" -"在中我们可以看到, 类" -"CarlicensePlate属性上定义了三个" -"约束条件. 在某些复杂的场景中, 可能还会有更多的约束条件被定义到同一个元素上" -"面, 这可能会让代码看起来有些复杂, 另外, 如果在另外的类里面还有一个" -"licensePlate属性, 我们可能还要把这些约束条件再拷贝到这个" -"属性上, 但是这样做又违反了 DRY 原则." - -#. Tag: para -#: customconstraints.xml:327 -#, no-c-format -msgid "" -"This problem can be tackled using compound constraints. In the following we " -"create a new constraint annotation @ValidLicensePlate, that comprises the constraints @NotNull, " -"@Size and @CheckCase:" -msgstr "" -"这个问题可以通过使用组合约束条件来解决. 接下来让我们来创建一个新的约束标注" -"@ValidLicensePlate, 它组合了@NotNull, @Size@CheckCase:" - -#. Tag: title -#: customconstraints.xml:334 -#, no-c-format -msgid "" -"Creating a composing constraint ValidLicensePlate" -msgstr "创建一个约束条件组合ValidLicensePlate" - -#. Tag: programlisting -#: customconstraints.xml:337 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import static java.lang.annotation.ElementType.*;\n" -"import static java.lang.annotation.RetentionPolicy.*;\n" -"\n" -"import java.lang.annotation.Documented;\n" -"import java.lang.annotation.Retention;\n" -"import java.lang.annotation.Target;\n" -"\n" -"import javax.validation.Constraint;\n" -"import javax.validation.Payload;\n" -"import javax.validation.constraints.NotNull;\n" -"import javax.validation.constraints.Size;\n" -"\n" -"@NotNull\n" -"@Size(min = 2, max = 14)\n" -"@CheckCase(CaseMode.UPPER)\n" -"@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n" -"@Retention(RUNTIME)\n" -"@Constraint(validatedBy = {})\n" -"@Documented\n" -"public @interface ValidLicensePlate {\n" -"\n" -" String message() default \"{com.mycompany.constraints." -"validlicenseplate}\";\n" -"\n" -" Class<?>[] groups() default {};\n" -"\n" -" Class<? extends Payload>[] payload() default {};\n" -"\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import static java.lang.annotation.ElementType.*;\n" -"import static java.lang.annotation.RetentionPolicy.*;\n" -"\n" -"import java.lang.annotation.Documented;\n" -"import java.lang.annotation.Retention;\n" -"import java.lang.annotation.Target;\n" -"\n" -"import javax.validation.Constraint;\n" -"import javax.validation.Payload;\n" -"import javax.validation.constraints.NotNull;\n" -"import javax.validation.constraints.Size;\n" -"\n" -"@NotNull\n" -"@Size(min = 2, max = 14)\n" -"@CheckCase(CaseMode.UPPER)\n" -"@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n" -"@Retention(RUNTIME)\n" -"@Constraint(validatedBy = {})\n" -"@Documented\n" -"public @interface ValidLicensePlate {\n" -"\n" -" String message() default \"{com.mycompany.constraints." -"validlicenseplate}\";\n" -"\n" -" Class<?>[] groups() default {};\n" -"\n" -" Class<? extends Payload>[] payload() default {};\n" -"\n" -"}" - -#. Tag: para -#: customconstraints.xml:340 -#, no-c-format -msgid "" -"To do so, we just have to annotate the constraint declaration with its " -"comprising constraints (btw. that's exactly why we allowed annotation types " -"as target for the @CheckCase annotation). As no " -"additional validation is required for the @ValidLicensePlate annotation itself, we don't declare a validator within the " -"@Constraint meta annotation." -msgstr "" -"我们只需要把要组合的约束标注在这个新的类型上加以声明 (注: 这正是我们为什么把" -"annotation types作为了@CheckCase的一个target). 因为这" -"个组合不需要额外的校验器, 所以不需要声明validator属性." - -#. Tag: para -#: customconstraints.xml:348 -#, no-c-format -msgid "" -"Using the new compound constraint at the licensePlate " -"field now is fully equivalent to the previous version, where we declared the " -"three constraints directly at the field itself:" -msgstr "" -"现在, 在licensePlate属性上使用这个新定义的\"约束条件" -"\" (其实是个组合) 和之前在其上声明那三个约束条件是一样的效果了." - -#. Tag: title -#: customconstraints.xml:354 -#, no-c-format -msgid "" -"Application of composing constraint ValidLicensePlate" -msgstr "使用ValidLicensePlate组合约束" - -#. Tag: programlisting -#: customconstraints.xml:357 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"public class Car {\n" -"\n" -" @ValidLicensePlate\n" -" private String licensePlate;\n" -"\n" -" //...\n" -"\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"public class Car {\n" -"\n" -" @ValidLicensePlate\n" -" private String licensePlate;\n" -"\n" -" //...\n" -"\n" -"}" - -#. Tag: para -#: customconstraints.xml:360 -#, no-c-format -msgid "" -"The set of ConstraintViolations retrieved when " -"validating a Car instance will contain an entry for " -"each violated composing constraint of the @ValidLicensePlate constraint. If you rather prefer a single " -"ConstraintViolation in case any of the composing " -"constraints is violated, the @ReportAsSingleViolation " -"meta constraint can be used as follows:" -msgstr "" - -#. Tag: title -#: customconstraints.xml:370 -#, no-c-format -msgid "Usage of @ReportAsSingleViolation" -msgstr "@ReportAsSingleViolation的用法" - -#. Tag: programlisting -#: customconstraints.xml:372 -#, no-c-format -msgid "" -"//...\n" -"@ReportAsSingleViolation\n" -"public @interface ValidLicensePlate {\n" -"\n" -" String message() default \"{com.mycompany.constraints." -"validlicenseplate}\";\n" -"\n" -" Class<?>[] groups() default {};\n" -"\n" -" Class<? extends Payload>[] payload() default {};\n" -"\n" -"}" -msgstr "" -"//...\n" -"@ReportAsSingleViolation\n" -"public @interface ValidLicensePlate {\n" -"\n" -" String message() default \"{com.mycompany.constraints." -"validlicenseplate}\";\n" -"\n" -" Class<?>[] groups() default {};\n" -"\n" -" Class<? extends Payload>[] payload() default {};\n" -"\n" -"}" diff --git a/documentation/src/main/docbook/zh-CN/modules/customoptions.po b/documentation/src/main/docbook/zh-CN/modules/customoptions.po deleted file mode 100644 index c68ce925ff..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/customoptions.po +++ /dev/null @@ -1,1111 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2011. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2012-05-09 09:42+0000\n" -"PO-Revision-Date: 2011-02-11 14:56+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"Language: zh-CN\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: customoptions.xml:24 -#, no-c-format -msgid "Hibernate Validator Specifics" -msgstr "" - -#. Tag: para -#: customoptions.xml:26 -#, no-c-format -msgid "" -"In the following sections we are having a closer look at some of the " -"Hibernate Validator specific features (features which are not part of the " -"Bean Validation specification). This includes the fail fast mode, the " -"programmatic constraint configuration API and boolean composition of " -"composing constraints." -msgstr "" - -#. Tag: para -#: customoptions.xml:33 -#, no-c-format -msgid "" -"The features described in the following sections are not portable between " -"Bean Validation providers/implementations." -msgstr "" - -#. Tag: title -#: customoptions.xml:38 -#, no-c-format -msgid "Public API" -msgstr "" - -#. Tag: para -#: customoptions.xml:40 -#, no-c-format -msgid "" -"Let's start, however, with a look at the public API of Hibernate Validator. " -" lists all packages belonging to " -"this API and describes their purpose." -msgstr "" - -#. Tag: para -#: customoptions.xml:44 -#, no-c-format -msgid "" -"Any packages not listed in that table are internal packages of Hibernate " -"Validator and are not intended to be accessed by clients. The contents of " -"these internal packages can change from release to release without notice, " -"thus possibly breaking any client code relying on it." -msgstr "" - -#. Tag: para -#: customoptions.xml:51 -#, no-c-format -msgid "" -"In the following table, when a package is public its not necessarily true " -"for its nested packages." -msgstr "" - -#. Tag: title -#: customoptions.xml:56 -#, no-c-format -msgid "Hibernate Validator public API" -msgstr "" - -#. Tag: entry -#: customoptions.xml:61 -#, no-c-format -msgid "Packages" -msgstr "" - -#. Tag: entry -#: customoptions.xml:63 -#, no-c-format -msgid "Description" -msgstr "" - -#. Tag: package -#: customoptions.xml:69 -#, no-c-format -msgid "org.hibernate.validator" -msgstr "" - -#. Tag: entry -#: customoptions.xml:71 -#, no-c-format -msgid "" -"This package contains the classes used by the Bean Validation bootstrap " -"mechanism (eg. validation provider, configuration class). For more details " -"see ." -msgstr "" - -#. Tag: entry -#: customoptions.xml:78 -#, no-c-format -msgid "" -"org.hibernate.validator.cfg, org.hibernate." -"validator.cfg.context, org.hibernate.validator.cfg.defs" -msgstr "" - -#. Tag: entry -#: customoptions.xml:82 -#, no-c-format -msgid "" -"With Hibernate Validator you can define constraints via a fluent API. These " -"packages contain all classes needed to use this feature. In the package " -"org.hibernate.validator.cfg you will find the " -"ConstraintMapping class and in package org." -"hibernate.validator.cfg.defs all constraint definitions. For more " -"details see ." -msgstr "" - -#. Tag: entry -#: customoptions.xml:93 -#, no-c-format -msgid "" -"org.hibernate.validator.constraints, org." -"hibernate.validator.constraints.br" -msgstr "" - -#. Tag: entry -#: customoptions.xml:96 -#, no-c-format -msgid "" -"In addition to Bean Validation constraints, Hibernate Validator provides " -"some useful custom constraints. These packages contain all custom annotation " -"classes. For more details see ." -msgstr "" - -#. Tag: entry -#: customoptions.xml:103 -#, no-c-format -msgid "" -"org.hibernate.validator.group, org.hibernate." -"validator.spi.group" -msgstr "" - -#. Tag: entry -#: customoptions.xml:106 -#, no-c-format -msgid "" -"With Hibernate Validator you can define dynamic default group sequences in " -"function of the validated object state. These packages contain all classes " -"needed to use this feature (GroupSequenceProvider " -"annotation and DefaultGroupSequenceProvider " -"contract). For more details see ." -msgstr "" - -#. Tag: entry -#: customoptions.xml:116 -#, no-c-format -msgid "" -"org.hibernate.validator.messageinterpolation, " -"org.hibernate.validator.resourceloading, org." -"hibernate.validator.spi.resourceloading" -msgstr "" - -#. Tag: entry -#: customoptions.xml:120 -#, no-c-format -msgid "" -"These packages contain the classes related to constraint message " -"interpolation. The first package contains two implementations of " -"MessageInterpolator. The first one, " -"ValueFormatterMessageInterpolator allows to " -"interpolate the validated value into the constraint message, see . The second implementation named " -"ResourceBundleMessageInterpolator is the " -"implementation used by default by Hibernate Validator. This implementation " -"relies on a ResourceBundleLocator, see . Hibernate Validator provides " -"different ResourceBundleLocator implementations " -"located in the package org.hibernate.validator.resourceloading." -msgstr "" - -#. Tag: entry -#: customoptions.xml:139 -#, no-c-format -msgid "" -"org.hibernate.validator.method, org.hibernate." -"validator.method.metadata" -msgstr "" - -#. Tag: entry -#: customoptions.xml:142 -#, no-c-format -msgid "" -"Hibernate Validator provides support for method-level constraints based on " -"appendix C of the Bean Validation specification. The first package contains " -"the MethodValidator interface allowing you to " -"validate method return values and parameters. The second package contains " -"meta data for constraints hosted on parameters and methods which can be " -"retrieved via the MethodValidator." -msgstr "" - -#. Tag: para -#: customoptions.xml:156 -#, no-c-format -msgid "" -"The public packages of Hibernate Validator fall into two categories: while " -"the actual API parts are intended to be invoked or " -"used by clients (e.g. the API for programmatic " -"constraint declaration or the custom constraints), the SPI (service provider " -"interface) packages contain interfaces which are intended to be " -"implemented by clients (e.g. " -"ResourceBundleLocator)." -msgstr "" - -#. Tag: title -#: customoptions.xml:167 -#, no-c-format -msgid "Fail fast mode" -msgstr "" - -#. Tag: para -#: customoptions.xml:169 -#, no-c-format -msgid "" -"First off, the fail fast mode. Hibernate Validator allows to return from the " -"current validation as soon as the first constraint violation occurs. This is " -"called the fail fast mode and can be useful for " -"validation of large object graphs where one is only interested whether there " -"is a constraint violation or not. , and show multiple ways to enable the fail fast " -"mode." -msgstr "" - -#. Tag: title -#: customoptions.xml:180 -#, no-c-format -msgid "Enabling via a property" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:182 -#, no-c-format -msgid "" -"HibernateValidatorConfiguration configuration = Validation.byProvider" -"( HibernateValidator.class ).configure();\n" -"ValidatorFactory factory = configuration.addProperty( \"hibernate.validator." -"fail_fast\", \"true\" ).buildValidatorFactory();\n" -"Validator validator = factory.getValidator();\n" -"\n" -"// do some actual fail fast validation\n" -"..." -msgstr "" - -#. Tag: title -#: customoptions.xml:186 -#, no-c-format -msgid "" -"Enabling at the Configuration level" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:189 -#, no-c-format -msgid "" -"HibernateValidatorConfiguration configuration = Validation.byProvider" -"( HibernateValidator.class ).configure();\n" -"ValidatorFactory factory = configuration.failFast( true )." -"buildValidatorFactory();\n" -"Validator validator = factory.getValidator();\n" -"\n" -"// do some actual fail fast validation\n" -"..." -msgstr "" - -#. Tag: title -#: customoptions.xml:193 -#, no-c-format -msgid "" -"Enabling at the ValidatorFactory level" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:196 -#, no-c-format -msgid "" -"HibernateValidatorConfiguration configuration = Validation.byProvider" -"( HibernateValidator.class ).configure();\n" -"ValidatorFactory factory = configuration.buildValidatorFactory();\n" -"\n" -"Validator validator = factory.getValidator();\n" -"\n" -"// do some non fail fast validation\n" -"...\n" -"\n" -"validator = factory.unwrap( HibernateValidatorFactory.class )\n" -" .usingContext()\n" -" .failFast( true )\n" -" .getValidator();\n" -"\n" -"// do fail fast validation\n" -"..." -msgstr "" - -#. Tag: title -#: customoptions.xml:201 -#, no-c-format -msgid "Method validation" -msgstr "" - -#. Tag: para -#: customoptions.xml:203 -#, no-c-format -msgid "" -"The Bean Validation API allows to specify constraints for fields, properties " -"and types. Hibernate Validator goes one step further and allows to place " -"contraint annotations also on method parameters and method return values, " -"thus enabling a programming style known as \"Programming by Contract\"." -msgstr "" - -#. Tag: para -#: customoptions.xml:209 -#, no-c-format -msgid "" -"More specifically this means that Bean Validation constraints can be used to " -"specify" -msgstr "" - -#. Tag: para -#: customoptions.xml:214 -#, no-c-format -msgid "" -"the preconditions that must be met before a method invocation (by annotating " -"method parameters with constraints) and" -msgstr "" - -#. Tag: para -#: customoptions.xml:219 -#, no-c-format -msgid "" -"the postconditions that are guaranteed after a method invocation (by " -"annotating methods)" -msgstr "" - -#. Tag: para -#: customoptions.xml:224 -#, no-c-format -msgid "" -"This approach has several advantages over traditional ways of parameter and " -"return value checking:" -msgstr "" - -#. Tag: para -#: customoptions.xml:229 -#, no-c-format -msgid "" -"The checks don't have to be performed manually (e.g. by throwing " -"IllegalArgumentExceptions or similar), resulting in " -"less code to write and maintain." -msgstr "" - -#. Tag: para -#: customoptions.xml:235 -#, no-c-format -msgid "" -"A method's pre- and postconditions don't have to be expressed again in the " -"method's JavaDoc, since the constraint annotations will automatically be " -"included in the generated JavaDoc. This avoids redundancy and reduces the " -"chance of inconsistencies between implementation and documentation." -msgstr "" - -#. Tag: para -#: customoptions.xml:244 -#, no-c-format -msgid "" -"Method validation was also considered to be included in the Bean Validation " -"API as defined by JSR 303, but it didn't become part of the 1.0 version. A " -"basic draft is outlined in appendix C of the specification, and the " -"implementation in Hibernate Validator is largely influenced by this draft. " -"The feature is considered again for inclusion in BV 1.1." -msgstr "" - -#. Tag: title -#: customoptions.xml:253 -#, no-c-format -msgid "Defining method-level constraints" -msgstr "" - -#. Tag: para -#: customoptions.xml:255 -#, no-c-format -msgid "demonstrates the definition of method-level constraints." -msgstr "" - -#. Tag: title -#: customoptions.xml:258 -#, no-c-format -msgid "Using method-level constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:260 -#, no-c-format -msgid "" -"public class RentalStation {\n" -"\n" -" @NotNull \n" -" public Car rentCar(@NotNull Customer customer, @NotNull @Future Date " -"startDate, @Min(1) int durationInDays) { \n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: customoptions.xml:263 -#, no-c-format -msgid "" -"Here the following pre- and postconditions for the rentCar() method are declared:" -msgstr "" - -#. Tag: para -#: customoptions.xml:268 -#, no-c-format -msgid "The renting customer may not be null" -msgstr "" - -#. Tag: para -#: customoptions.xml:272 -#, no-c-format -msgid "The rental's start date must not be null and must be in the future" -msgstr "" - -#. Tag: para -#: customoptions.xml:277 -#, no-c-format -msgid "The rental duration must be at least one day" -msgstr "" - -#. Tag: para -#: customoptions.xml:281 -#, no-c-format -msgid "The returned Car instance may not be null" -msgstr "" - -#. Tag: para -#: customoptions.xml:286 -#, no-c-format -msgid "" -"Using the @Valid annotation it's also possible to " -"define that a cascaded validation of parameter or return value objects shall " -"be performed. An example can be found in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:292 -#, no-c-format -msgid "Cascaded validation of method-level constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:294 -#, no-c-format -msgid "" -"public class RentalStation {\n" -"\n" -" @Valid\n" -" public Set<Rental> getRentalsByCustomer(@Valid Customer customer) " -"{ \n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: customoptions.xml:297 -#, no-c-format -msgid "" -"Here all the constraints declared at the Customer " -"type will be evaluated when validating the method parameter and all " -"constraints declared at the returned Rental objects " -"will be evaluated when validating the method's return value." -msgstr "" - -#. Tag: title -#: customoptions.xml:304 -#, no-c-format -msgid "Using method constraints in type hierarchies" -msgstr "" - -#. Tag: para -#: customoptions.xml:306 -#, no-c-format -msgid "" -"Special care must be taken when defining parameter constraints in " -"inheritance hierarchies." -msgstr "" - -#. Tag: para -#: customoptions.xml:309 -#, no-c-format -msgid "" -"When a method is overridden in sub-types method parameter constraints can " -"only be declared at the base type. The reason for this restriction is that " -"the preconditions to be fulfilled by a type's client must not be " -"strengthened in sub-types (which may not even be known to the base type's " -"client). Note that also if the base method doesn't declare any parameter " -"constraints at all, no parameter constraints may be added in overriding " -"methods." -msgstr "" - -#. Tag: para -#: customoptions.xml:317 -#, no-c-format -msgid "" -"The same restriction applies to interface methods: no parameter constraints " -"may be defined at the implementing method (or the same method declared in " -"sub-interfaces)." -msgstr "" - -#. Tag: para -#: customoptions.xml:321 -#, no-c-format -msgid "" -"If a violation of this rule is detected by the validation engine, a " -"javax.validation.ConstraintDeclarationException will " -"be thrown. In some examples for illegal parameter constraints declarations are shown." -msgstr "" - -#. Tag: title -#: customoptions.xml:329 -#, no-c-format -msgid "Illegal parameter constraint declarations" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:331 -#, no-c-format -msgid "" -"public class Car {\n" -"\n" -" public void drive(Person driver) { ... }\n" -"\n" -"}\n" -"\n" -"public class RentalCar extends Car {\n" -"\n" -" //not allowed, parameter constraint added in overriding method\n" -" public void drive(@NotNull Person driver) { ... }\n" -"\n" -"}\n" -"\n" -"public interface ICar {\n" -"\n" -" void drive(Person driver);\n" -"\n" -"}\n" -"\n" -"public class CarImpl implements ICar {\n" -"\n" -" //not allowed, parameter constraint added in implementation of interface " -"method\n" -" public void drive(@NotNull Person driver) { ... }\n" -"\n" -"}" -msgstr "" - -#. Tag: para -#: customoptions.xml:334 -#, no-c-format -msgid "" -"This rule only applies to parameter constraints, return value constraints " -"may be added in sub-types without any restrictions as it is alright to " -"strengthen the postconditions guaranteed to a type's client." -msgstr "" - -#. Tag: title -#: customoptions.xml:342 -#, no-c-format -msgid "Evaluating method-level constraints" -msgstr "" - -#. Tag: para -#: customoptions.xml:344 -#, no-c-format -msgid "" -"To validate method-level constraints Hibernate Validator provides the " -"interface org.hibernate.validator.method.MethodValidator." -msgstr "" - -#. Tag: para -#: customoptions.xml:348 -#, no-c-format -msgid "" -"As shown in this " -"interface defines methods for the evaluation of parameter as well as return " -"value constraints and for retrieving an extended type descriptor providing " -"method constraint related meta data." -msgstr "" - -#. Tag: title -#: customoptions.xml:354 -#, no-c-format -msgid "The MethodValidator interface" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:356 -#, no-c-format -msgid "" -"public interface MethodValidator {\n" -"\n" -" <T> Set<MethodConstraintViolation<T>> validateParameter" -"(T object, Method method, Object parameterValue, int parameterIndex, " -"Class<?>... groups);\n" -" \n" -" <T> Set<MethodConstraintViolation<T>> " -"validateAllParameters(T object, Method method, Object[] parameterValues, " -"Class<?>... groups);\n" -" \n" -" <T> Set<MethodConstraintViolation<T>> " -"validateReturnValue(T object, Method method, Object returnValue, Class<?" -">... groups);\n" -" \n" -" TypeDescriptor getConstraintsForType(Class<?> clazz);\n" -"}" -msgstr "" - -#. Tag: para -#: customoptions.xml:359 -#, no-c-format -msgid "" -"To retrieve a method validator get hold of an instance of HV's " -"javax.validation.Validator implementation and unwrap " -"it to MethodValidator as shown in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:365 -#, no-c-format -msgid "Retrieving a MethodValidator instance" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:368 -#, no-c-format -msgid "" -"MethodValidator methodValidator = Validation.byProvider( HibernateValidator." -"class )\n" -" .configure()\n" -" .buildValidatorFactory()\n" -" .getValidator()\n" -" .unwrap( MethodValidator.class );" -msgstr "" - -#. Tag: para -#: customoptions.xml:371 -#, no-c-format -msgid "" -"The validation methods defined on MethodValidator " -"each return a Set<MethodConstraintViolation>. " -"The type MethodConstraintViolation (see ) extends " -"javax.validation.ConstraintViolation and provides " -"additional method level validation specific information such as the method " -"and index of the parameter which caused the constraint violation." -msgstr "" - -#. Tag: title -#: customoptions.xml:382 -#, no-c-format -msgid "The MethodConstraintViolation type" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:385 -#, no-c-format -msgid "" -"public interface MethodConstraintViolation<T> extends " -"ConstraintViolation<T> {\n" -" \n" -" public static enum Kind { PARAMETER, RETURN_VALUE }\n" -"\n" -" Method getMethod();\n" -"\n" -" Integer getParameterIndex();\n" -"\n" -" String getParameterName();\n" -"\n" -" Kind getKind();\n" -"}" -msgstr "" - -#. Tag: para -#: customoptions.xml:389 -#, no-c-format -msgid "" -"The method getParameterName() currently returns " -"synthetic parameter identifiers such as \"arg0\", \"arg1\" etc. In a future " -"version of Hibernate Validator support for specifying parameter identifiers " -"might be added." -msgstr "" - -#. Tag: para -#: customoptions.xml:395 -#, no-c-format -msgid "" -"Typically the validation of method-level constraints is not invoked manually " -"but automatically upon method invocation by an integration layer using AOP " -"(aspect-oriented programming) or similar method interception facilities such " -"as the JDK's java.lang.reflect.Proxy API or CDI " -"(\"JSR 299: Contexts and Dependency Injection for the JavaTM EE platform\")." -msgstr "" - -#. Tag: para -#: customoptions.xml:403 -#, no-c-format -msgid "" -"If a parameter or return value constraint can't be validated sucessfully " -"such an integration layer typically will throw a " -"MethodConstraintViolationException which similar to " -"javax.validation.ConstraintViolationException " -"contains a set with the occurred constraint violations." -msgstr "" - -#. Tag: para -#: customoptions.xml:410 -#, no-c-format -msgid "" -"If you are using CDI you might be interested in the Seam Validation project. " -"This Seam module provides an interceptor which integrates the method " -"validation functionality with CDI." -msgstr "" - -#. Tag: title -#: customoptions.xml:418 -#, no-c-format -msgid "Retrieving method-level constraint meta data" -msgstr "" - -#. Tag: para -#: customoptions.xml:420 -#, no-c-format -msgid "" -"As outlined in the Bean " -"Validation API provides rich capabilities for retrieving constraint related " -"meta data. Hibernate Validator extends this API and allows to retrieve " -"constraint meta data also for method-level constraints." -msgstr "" - -#. Tag: para -#: customoptions.xml:426 -#, no-c-format -msgid "" -"shows how to use this extended API to retrieve constraint meta data for the " -"rentCar() method from the RentalStation type." -msgstr "" - -#. Tag: title -#: customoptions.xml:432 -#, no-c-format -msgid "Retrieving meta data for method-level constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:434 -#, no-c-format -msgid "" -"TypeDescriptor typeDescriptor = methodValidator.getConstraintsForType" -"(RentalStation.class)\n" -"\n" -"//retrieve a descriptor for the rentCar() method\n" -"MethodDescriptor rentCarMethod = typeDescriptor.getConstraintsForMethod" -"(\"rentCar\", Customer.class, Date.class, int.class);\n" -"assertEquals(rentCarMethod.getMethodName(), \"rentCar\");\n" -"assertTrue(rentCarMethod.hasConstraints());\n" -"assertFalse(rentCarMethod.isCascaded());\n" -"\n" -"//retrieve constraints from the return value\n" -"Set<ConstraintDescriptor<?>> returnValueConstraints = " -"rentCarMethod.findConstraints().getConstraintDescriptors();\n" -"assertEquals(returnValueConstraints.size(), 1);\n" -"assertEquals(returnValueConstraints.iterator().next().getAnnotation()." -"annotationType(), NotNull.class);\n" -"\n" -"List<ParameterDescriptor> allParameters = rentCarMethod." -"getParameterDescriptors();\n" -"assertEquals(allParameters.size(), 3);\n" -"\n" -"//retrieve a descriptor for the startDate parameter\n" -"ParameterDescriptor startDateParameter = allParameters.get(1);\n" -"assertEquals(startDateParameter.getIndex(), 1);\n" -"assertFalse(startDateParameter.isCascaded());\n" -"assertEquals(startDateParameter.findConstraints().getConstraintDescriptors()." -"size(), 2);" -msgstr "" - -#. Tag: para -#: customoptions.xml:437 -#, no-c-format -msgid "" -"Refer to the JavaDoc of the package org.hibernate.validator.method." -"metadata for more details on the extended meta data API." -msgstr "" - -#. Tag: title -#: customoptions.xml:446 customoptions.xml:462 -#, no-c-format -msgid "Programmatic constraint definition" -msgstr "" - -#. Tag: para -#: customoptions.xml:448 -#, no-c-format -msgid "" -"Another addition to the Bean Validation specification is the ability to " -"configure constraints via a fluent API. This API can be used exclusively or " -"in combination with annotations and xml. If used in combination programmatic " -"constraints are additive to constraints configured via the standard " -"configuration capabilities." -msgstr "" - -#. Tag: para -#: customoptions.xml:454 -#, no-c-format -msgid "" -"The API is centered around the ConstraintMapping " -"class which can be found in the package org.hibernate.validator." -"cfg. Starting with the instantiation of a new " -"ConstraintMapping, constraints can be defined in a " -"fluent manner as shown in ." -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:464 -#, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .property( \"manufacturer\", FIELD )\n" -" .constraint( new NotNullDef() )\n" -" .property( \"licensePlate\", FIELD )\n" -" .constraint( new NotNullDef() )\n" -" .constraint( new SizeDef().min( 2 ).max( 14 ) )\n" -" .property( \"seatCount\", FIELD )\n" -" .constraint( new MinDef()value ( 2 ) )\n" -".type( RentalCar.class )\n" -" .property( \"rentalStation\", METHOD )\n" -" .constraint( new NotNullDef() );" -msgstr "" - -#. Tag: para -#: customoptions.xml:467 -#, no-c-format -msgid "" -"As you can see constraints can be configured on multiple classes and " -"properties using method chaining. The constraint definition classes " -"NotNullDef, SizeDef and " -"MinDef are helper classes which allow to configure " -"constraint parameters in a type-safe fashion. Definition classes exist for " -"all built-in constraints in the org.hibernate.validator.cfg.defs package." -msgstr "" - -#. Tag: para -#: customoptions.xml:475 -#, no-c-format -msgid "" -"For custom constraints you can either create your own definition classes " -"extending ConstraintDef or you can use " -"GenericConstraintDef as seen in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:481 -#, no-c-format -msgid "" -"Programmatic constraint definition using createGeneric()" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:484 -#, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .property( \"licensePlate\", FIELD )\n" -" .constraint( new GenericConstraintDef<CheckCase.class>" -"( CheckCase.class ).param( \"value\", CaseMode.UPPER ) );" -msgstr "" - -#. Tag: para -#: customoptions.xml:487 -#, no-c-format -msgid "" -"Not only standard class- and property-level constraints but also method " -"constraints can be configured using the API. As shown in methods are identified by " -"their name and their parameters (if there are any). Having selected a " -"method, constraints can be placed on the method's parameters and/or return " -"value." -msgstr "" - -#. Tag: title -#: customoptions.xml:495 -#, no-c-format -msgid "Programmatic definition of method constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:497 -#, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .method( \"drive\", String.class, Integer.class )\n" -" .parameter( 0 )\n" -" .constraint( new NotNullDef() )\n" -" .constraint( new MinDef().value ( 1 ) )\n" -" .parameter( 1 )\n" -" .constraint( new NotNullDef() )\n" -" .returnValue()\n" -" .constraint( new NotNullDef() )\n" -" .method( \"check\" )\n" -" .returnValue()\n" -" .constraint( new NotNullDef() );" -msgstr "" - -#. Tag: para -#: customoptions.xml:500 -#, no-c-format -msgid "" -"Using the API it's also possible to mark properties, method parameters and " -"method return values as cascading (equivalent to annotating them with " -"@Valid). An example can be found in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:506 -#, no-c-format -msgid "Marking constraints for cascaded validation" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:508 -#, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .property( \"manufacturer\", FIELD )\n" -" .valid()\n" -" .property( \"licensePlate\", METHOD )\n" -" .valid()\n" -" .method( \"drive\", String.class, Integer.class )\n" -" .parameter( 0 )\n" -" .valid()\n" -" .parameter( 1 )\n" -" .valid()\n" -" .returnValue()\n" -" .valid()\n" -".type( RentalCar.class )\n" -" .property( \"rentalStation\", METHOD )\n" -" .valid();" -msgstr "" - -#. Tag: para -#: customoptions.xml:511 -#, no-c-format -msgid "" -"Last but not least you can configure the default group sequence or the " -"default group sequence provider of a type as shown in ." -msgstr "" - -#. Tag: title -#: customoptions.xml:514 -#, no-c-format -msgid "" -"Configuration of default group sequence and default group sequence provider" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:517 -#, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .defaultGroupSequence( Car.class, CarChecks.class )\n" -".type( RentalCar.class )\n" -" .defaultGroupSequenceProvider( RentalCarGroupSequenceProvider.class );" -msgstr "" - -#. Tag: para -#: customoptions.xml:520 -#, no-c-format -msgid "" -"Once a ConstraintMapping is set up it has to be " -"passed to the configuration. Since the programmatic API is not part of the " -"official Bean Validation specification you need to get hold of a " -"HibernateValidatorConfiguration instance as shown in " -"." -msgstr "" - -#. Tag: title -#: customoptions.xml:527 -#, no-c-format -msgid "Creating a Hibernate Validator specific configuration" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:529 -#, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"// configure mapping instance\n" -"\n" -"HibernateValidatorConfiguration config = Validation.byProvider" -"( HibernateValidator.class ).configure();\n" -"config.addMapping( mapping );\n" -"ValidatorFactory factory = config.buildValidatorFactory();\n" -"Validator validator = factory.getValidator();" -msgstr "" - -#. Tag: title -#: customoptions.xml:534 -#, no-c-format -msgid "Boolean composition for constraint composition" -msgstr "" - -#. Tag: para -#: customoptions.xml:536 -#, no-c-format -msgid "" -"As per Bean Validation specification the constraints of a composed " -"constraint (see ) are all " -"combined via a logical AND. This means all of the " -"composing constraints need to return true in order for " -"an overall successful validation. Hibernate Validator offers an extension to " -"this logical AND combination which allows you to " -"compose constraints via a logical OR or NOT. To do so you have to use the ConstraintComposition annotation and the enum CompositionType " -"with its values AND, OR and " -"ALL_FALSE. shows how to build a composing constraint where only one of " -"the constraints has to be successful in order to pass the validation. Either " -"the validated string is all lowercased or it is between two and three " -"characters long." -msgstr "" - -#. Tag: title -#: customoptions.xml:554 -#, no-c-format -msgid "OR composition of constraints" -msgstr "" - -#. Tag: programlisting -#: customoptions.xml:556 -#, no-c-format -msgid "" -"@ConstraintComposition(OR)\n" -"@Pattern(regexp = \"[a-z]\")\n" -"@Size(min = 2, max = 3)\n" -"@ReportAsSingleViolation\n" -"@Target({ METHOD, FIELD })\n" -"@Retention(RUNTIME)\n" -"@Constraint(validatedBy = { })\n" -"public @interface PatternOrSize {\n" -" public abstract String message() default \"{PatternOrSize.message}\";\n" -" public abstract Class<?>[] groups() default { };\n" -" public abstract Class<? extends Payload>[] payload() default { };\n" -"}" -msgstr "" - -#. Tag: para -#: customoptions.xml:560 -#, no-c-format -msgid "" -"Using ALL_FALSE as composition type implicitly enforces " -"that only a single violation will get reported in case validation of the " -"constraint composition fails." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/further-reading.po b/documentation/src/main/docbook/zh-CN/modules/further-reading.po deleted file mode 100644 index b319d393bb..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/further-reading.po +++ /dev/null @@ -1,61 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: further-reading.xml:24 -#, no-c-format -msgid "Further reading" -msgstr "" - -#. Tag: para -#: further-reading.xml:26 -#, no-c-format -msgid "Last but not least, a few pointers to further information." -msgstr "" - -#. Tag: para -#: further-reading.xml:28 -#, no-c-format -msgid "" -"A great source for examples is the Bean Validation TCK which is available " -"for anonymous access on GitHub. In particular the TCK's tests might be of interest. The JSR 349 specification itself is also a " -"great way to deepen your understanding of Bean Validation resp. Hibernate " -"Validator." -msgstr "" - -#. Tag: para -#: further-reading.xml:38 -#, no-c-format -msgid "" -"If you have any further questions to Hibernate Validator or want to share " -"some of your use cases have a look at the Hibernate Validator Wiki and the " -"Hibernate " -"Validator Forum." -msgstr "" - -#. Tag: para -#: further-reading.xml:45 -#, no-c-format -msgid "" -"In case you would like to report a bug use Hibernate's Jira " -"instance. Feedback is always welcome!" -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/furtherreading.po b/documentation/src/main/docbook/zh-CN/modules/furtherreading.po deleted file mode 100644 index 1e7a8443fb..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/furtherreading.po +++ /dev/null @@ -1,77 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-03 09:59+0000\n" -"PO-Revision-Date: 2010-08-14 14:25+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: furtherreading.xml:24 -#, no-c-format -msgid "Further reading" -msgstr "进一步阅读" - -#. Tag: para -#: furtherreading.xml:26 -#, no-c-format -msgid "Last but not least, a few pointers to further information." -msgstr "" - -#. Tag: para -#: furtherreading.xml:28 -#, fuzzy, no-c-format -msgid "" -"A great source for examples is the Bean Validation TCK which is available " -"for anonymous access on GitHub. In particular the TCK's tests might be of " -"interest. The JSR 303 specification itself is also a great way to deepen your understanding " -"of Bean Validation resp. Hibernate Validator." -msgstr "" -"最后,还有一些东东可供进一步参考. Bean Validation TCK 是一份非常好的示例,你可" -"以从Hibernate SVN repository匿名访问得到. 或者, 你也可以通过" -"Hibernate's " -"fisheye来查看我们的测试用例代码. 另外阅读The JSR 303规范也是很好的方法来加深你对Bean " -"Validation 和 Hibernate Validator的理解." - -#. Tag: para -#: furtherreading.xml:37 -#, no-c-format -msgid "" -"If you have any further questions to Hibernate Validator or want to share " -"some of your use cases have a look at the Hibernate Validator Wiki and the " -"Hibernate " -"Validator Forum." -msgstr "" -"如果你还有什么关于Hibernate Validator的问题或者想和我们分享你的使用经验,请使" -"用Hibernate " -"Validator Wiki或者去Hibernate Validator Forum发帖子(译注:但是不要灌" -"水:-D)." - -#. Tag: para -#: furtherreading.xml:44 -#, no-c-format -msgid "" -"In case you would like to report a bug use Hibernate's Jira " -"instance. Feedback is always welcome!" -msgstr "" -"如果你发现了Hibernate Validator的bug,请在Hibernate's Jira中报告, " -"我们非常欢迎您的反馈!" diff --git a/documentation/src/main/docbook/zh-CN/modules/getting-started.po b/documentation/src/main/docbook/zh-CN/modules/getting-started.po deleted file mode 100644 index c82da5cfea..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/getting-started.po +++ /dev/null @@ -1,482 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: getting-started.xml:24 -#, no-c-format -msgid "Getting started" -msgstr "" - -#. Tag: para -#: getting-started.xml:26 -#, no-c-format -msgid "" -"This chapter will show you how to get started with Hibernate Validator, the " -"reference implementation (RI) of Bean Validation. For the following " -"quickstart you need:" -msgstr "" - -#. Tag: para -#: getting-started.xml:32 -#, no-c-format -msgid "A JDK >= 6" -msgstr "" - -#. Tag: ulink -#: getting-started.xml:36 -#, no-c-format -msgid "Apache Maven" -msgstr "" - -#. Tag: para -#: getting-started.xml:40 -#, no-c-format -msgid "An Internet connection (Maven has to download all required libraries)" -msgstr "" - -#. Tag: title -#: getting-started.xml:46 -#, no-c-format -msgid "Project set up" -msgstr "" - -#. Tag: para -#: getting-started.xml:48 -#, no-c-format -msgid "" -"In order to use Hibernate Validator within a Maven project, simply add the " -"following dependency to your pom.xml:" -msgstr "" - -#. Tag: title -#: getting-started.xml:52 -#, no-c-format -msgid "Hibernate Validator Maven dependency" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:54 -#, no-c-format -msgid "" -"<dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator</artifactId>\n" -" <version>&version;</version>\n" -"</dependency>" -msgstr "" - -#. Tag: para -#: getting-started.xml:57 -#, no-c-format -msgid "" -"This transitively pulls in the dependency to the Bean Validation API " -"(javax.validation:validation-api:&bvVersion;)." -msgstr "" - -#. Tag: title -#: getting-started.xml:61 -#, no-c-format -msgid "Logging" -msgstr "" - -#. Tag: para -#: getting-started.xml:63 -#, no-c-format -msgid "" -"For the purposes of logging, Hibernate Validator uses the JBoss Logging API. " -"This is an abstraction layer which supports several known logging solutions " -"(e.g. log4j or the logging framework provided by the JDK) as implementation. " -"Just add your preferred logging library as dependency to your project and " -"all log requests from Hibernate Validator will automatically be delegated to " -"that logging provider." -msgstr "" - -#. Tag: para -#: getting-started.xml:70 -#, no-c-format -msgid "" -"If there are several logging implementations part of the classpath, you can " -"explicitely specify a provider using the system property org.jboss." -"logging.provider. Supported values currently are jboss, jdk, log4j and " -"slf4j." -msgstr "" - -#. Tag: title -#: getting-started.xml:78 -#, no-c-format -msgid "Unified EL" -msgstr "" - -#. Tag: para -#: getting-started.xml:80 -#, no-c-format -msgid "" -"Hibernate Validator requires an implementation of the Unified Expression " -"Language (JSR 341) for " -"evaluating dynamic expressions in constraint violation messages (see ). When your application runs in " -"a Java EE container such as JBoss AS, an EL implementation is already " -"provided by the container. In a Java SE environment, however, you have to " -"add an implementation as dependency to your POM file. For instance you can " -"add the following two dependencies to use the JSR 341 reference implementation:" -msgstr "" - -#. Tag: title -#: getting-started.xml:92 -#, no-c-format -msgid "Maven dependencies for Unified EL reference implementation" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:95 -#, no-c-format -msgid "" -"<dependency>\n" -" <groupId>javax.el</groupId>\n" -" <artifactId>javax.el-api</artifactId>\n" -" <version>2.2.4</version>\n" -"</dependency>\n" -"<dependency>\n" -" <groupId>org.glassfish.web</groupId>\n" -" <artifactId>javax.el</artifactId>\n" -" <version>2.2.4</version>\n" -"</dependency>" -msgstr "" - -#. Tag: title -#: getting-started.xml:100 -#, no-c-format -msgid "CDI" -msgstr "" - -#. Tag: para -#: getting-started.xml:102 -#, no-c-format -msgid "" -"Bean Validation defines integration points with CDI (Contexts and Dependency " -"Injection for JavaTM EE, JSR 346). If your application runs in an " -"environment which does not provide this integration out of the box, you may " -"use the Hibernate Validator CDI portable extension by adding the following " -"Maven dependency to your POM:" -msgstr "" - -#. Tag: title -#: getting-started.xml:111 -#, no-c-format -msgid "Hibernate Validator CDI portable extension Maven dependency" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:114 -#, no-c-format -msgid "" -"<dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator-cdi</artifactId>\n" -" <version>&version;</version>\n" -"</dependency>" -msgstr "" - -#. Tag: para -#: getting-started.xml:117 -#, no-c-format -msgid "" -"Note that adding this dependency is usually not required for applications " -"running on a Java EE application server. You can learn more about the " -"integration of Bean Validation and CDI in ." -msgstr "" - -#. Tag: title -#: getting-started.xml:125 -#, no-c-format -msgid "Applying constraints" -msgstr "" - -#. Tag: para -#: getting-started.xml:127 -#, no-c-format -msgid "Lets dive directly into an example to see how to apply constraints." -msgstr "" - -#. Tag: title -#: getting-started.xml:131 -#, no-c-format -msgid "Class Car annotated with constraints" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:133 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter01;\n" -"\n" -"import javax.validation.constraints.Min;\n" -"import javax.validation.constraints.NotNull;\n" -"import javax.validation.constraints.Size;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" private String licensePlate;\n" -"\n" -" @Min(2)\n" -" private int seatCount;\n" -"\n" -" public Car(String manufacturer, String licencePlate, int seatCount) " -"{\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" -msgstr "" - -#. Tag: para -#: getting-started.xml:136 -#, no-c-format -msgid "" -"The @NotNull, @Size and " -"@Min annotations are used to declare the constraints " -"which should be applied to the fields of a Car " -"instance:" -msgstr "" - -#. Tag: para -#: getting-started.xml:143 -#, no-c-format -msgid "manufacturer must never be null" -msgstr "" - -#. Tag: para -#: getting-started.xml:148 -#, no-c-format -msgid "" -"licensePlate must never be null and " -"must be between 2 and 14 characters long" -msgstr "" - -#. Tag: para -#: getting-started.xml:154 -#, no-c-format -msgid "seatCount must be at least 2" -msgstr "" - -#. Tag: title -#: getting-started.xml:160 -#, no-c-format -msgid "Validating constraints" -msgstr "" - -#. Tag: para -#: getting-started.xml:162 -#, no-c-format -msgid "" -"To perform a validation of these constraints, you use a " -"Validator instance. Let's have a look at a unit test " -"for Car:" -msgstr "" - -#. Tag: title -#: getting-started.xml:167 -#, no-c-format -msgid "Class CarTest showing validation examples" -msgstr "" - -#. Tag: programlisting -#: getting-started.xml:169 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter01;\n" -"\n" -"import java.util.Set;\n" -"import javax.validation.ConstraintViolation;\n" -"import javax.validation.Validation;\n" -"import javax.validation.Validator;\n" -"import javax.validation.ValidatorFactory;\n" -"\n" -"import org.junit.BeforeClass;\n" -"import org.junit.Test;\n" -"\n" -"import static org.junit.Assert.assertEquals;\n" -"\n" -"public class CarTest {\n" -"\n" -" private static Validator validator;\n" -"\n" -" @BeforeClass\n" -" public static void setUp() {\n" -" ValidatorFactory factory = Validation." -"buildDefaultValidatorFactory();\n" -" validator = factory.getValidator();\n" -" }\n" -"\n" -" @Test\n" -" public void manufacturerIsNull() {\n" -" Car car = new Car( null, \"DD-AB-123\", 4 );\n" -"\n" -" Set<ConstraintViolation<Car>> " -"constraintViolations =\n" -" validator.validate( car );\n" -"\n" -" assertEquals( 1, constraintViolations.size() );\n" -" assertEquals( \"may not be null\", constraintViolations." -"iterator().next().getMessage() );\n" -" }\n" -"\n" -" @Test\n" -" public void licensePlateTooShort() {\n" -" Car car = new Car( \"Morris\", \"D\", 4 );\n" -"\n" -" Set<ConstraintViolation<Car>> " -"constraintViolations =\n" -" validator.validate( car );\n" -"\n" -" assertEquals( 1, constraintViolations.size() );\n" -" assertEquals(\n" -" \"size must be between 2 and 14\",\n" -" constraintViolations.iterator().next()." -"getMessage()\n" -" );\n" -" }\n" -"\n" -" @Test\n" -" public void seatCountTooLow() {\n" -" Car car = new Car( \"Morris\", \"DD-AB-123\", 1 );\n" -"\n" -" Set<ConstraintViolation<Car>> " -"constraintViolations =\n" -" validator.validate( car );\n" -"\n" -" assertEquals( 1, constraintViolations.size() );\n" -" assertEquals(\n" -" \"must be greater than or equal to 2\",\n" -" constraintViolations.iterator().next()." -"getMessage()\n" -" );\n" -" }\n" -"\n" -" @Test\n" -" public void carIsValid() {\n" -" Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" -"\n" -" Set<ConstraintViolation<Car>> " -"constraintViolations =\n" -" validator.validate( car );\n" -"\n" -" assertEquals( 0, constraintViolations.size() );\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: getting-started.xml:172 -#, no-c-format -msgid "" -"In the setUp() method a Validator object is retrieved from the ValidatorFactory. A Validator instance is thread-safe and " -"may be reused multiple times. It thus can safely be stored in a static field " -"and be used in the test methods to validate the different Car instances." -msgstr "" - -#. Tag: para -#: getting-started.xml:180 -#, no-c-format -msgid "" -"The validate() method returns a set of " -"ConstraintViolation instances, which you can iterate " -"ovr in order to see which validation errors occurred. The first three test " -"methods show some expected constraint violations:" -msgstr "" - -#. Tag: para -#: getting-started.xml:187 -#, no-c-format -msgid "" -"The @NotNull constraint on manufacturer is violated " -"in manufacturerIsNull()" -msgstr "" - -#. Tag: para -#: getting-started.xml:192 -#, no-c-format -msgid "" -"The @Size constraint on licensePlate is violated in " -"licensePlateTooShort()" -msgstr "" - -#. Tag: para -#: getting-started.xml:197 -#, no-c-format -msgid "" -"The @Min constraint on seatCount is violated in " -"seatCountTooLow()" -msgstr "" - -#. Tag: para -#: getting-started.xml:202 -#, no-c-format -msgid "" -"If the object validates successfully, validate() " -"returns an empty set as you can see in carIsValid()." -msgstr "" - -#. Tag: para -#: getting-started.xml:206 -#, no-c-format -msgid "" -"Note that only use classes from the package javax.validation from the Bean Validation API are used. No classes from Hibernate " -"Validator are directly referenced, resulting in portable code." -msgstr "" - -#. Tag: title -#: getting-started.xml:213 -#, no-c-format -msgid "Where to go next?" -msgstr "" - -#. Tag: para -#: getting-started.xml:215 -#, no-c-format -msgid "" -"That concludes the 5 minute tour through the world of Hibernate Validator " -"and Bean Validaiton. Continue exploring the code examples or look at further " -"examples referenced in ." -msgstr "" - -#. Tag: para -#: getting-started.xml:220 -#, no-c-format -msgid "" -"To learn more about the validation of beans and properties, just continue " -"reading . If you are interested " -"in using Bean Validation for the validation of method pre- and postcondition " -"refer to . In case your " -"application has specific validation requirements have a look at ." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/gettingstarted.po b/documentation/src/main/docbook/zh-CN/modules/gettingstarted.po deleted file mode 100644 index 9f96dbb6d3..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/gettingstarted.po +++ /dev/null @@ -1,720 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-03 09:59+0000\n" -"PO-Revision-Date: 2010-07-07 03:33+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: gettingstarted.xml:24 -#, no-c-format -msgid "Getting started" -msgstr "开始入门" - -#. Tag: para -#: gettingstarted.xml:26 -#, no-c-format -msgid "" -"This chapter will show you how to get started with Hibernate Validator, the " -"reference implementation (RI) of Bean Validation. For the following " -"quickstart you need:" -msgstr "" -"本章将会告诉你如何使用Hibernate Validator, 在开始之前,你需要准备好下面的环境:" - -#. Tag: para -#: gettingstarted.xml:32 -#, fuzzy, no-c-format -msgid "A JDK >= 6" -msgstr "A JDK >= 5" - -#. Tag: ulink -#: gettingstarted.xml:36 -#, no-c-format -msgid "Apache Maven" -msgstr "Apache Maven" - -#. Tag: para -#: gettingstarted.xml:40 -#, no-c-format -msgid "An Internet connection (Maven has to download all required libraries)" -msgstr "网络连接 ( Maven需要通过互联网下载所需的类库)" - -#. Tag: title -#: gettingstarted.xml:46 -#, no-c-format -msgid "Project set up" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:48 -#, no-c-format -msgid "" -"In order to use Hibernate Validator within a Maven project, simply add the " -"following dependency to your pom.xml:" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:50 -#, no-c-format -msgid "Hibernate Validator Maven dependency" -msgstr "" - -#. Tag: programlisting -#: gettingstarted.xml:52 -#, no-c-format -msgid "" -"<dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator</artifactId>\n" -" <version>&version;</version>\n" -"</dependency>" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:55 -#, no-c-format -msgid "" -"This transitively pulls in the dependency to the Bean Validation API " -"(javax.validation:validation-api:&bvVersion;)." -msgstr "" - -#. Tag: para -#: gettingstarted.xml:59 -#, no-c-format -msgid "" -"For the purposes of logging, Hibernate Validator uses the JBoss Logging API. " -"This is an abstraction layer which supports several known logging solutions " -"(e.g. log4j or the logging framework provided by the JDK) as implementation. " -"Just add your preferred logging library to the classpath and all log " -"requests from Hibernate Validator will automatically be delegated to that " -"logging provider." -msgstr "" - -#. Tag: para -#: gettingstarted.xml:66 -#, no-c-format -msgid "" -"Alternatively, you can explicitely specify a provider using the system " -"property org.jboss.logging.provider. Supported values " -"currently are jboss, jdk, " -"log4j and slf4j." -msgstr "" - -#. Tag: title -#: gettingstarted.xml:73 -#, no-c-format -msgid "Unified EL" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:75 -#, no-c-format -msgid "" -"Hibernate Validator requires an implementation of the Unified Expression " -"Language (JSR 341) for " -"evaluating dynamic expressions in constraint violation messages (see ). When your application runs in " -"a Java EE container such as JBoss AS, an EL implementation is already " -"provided by the container. In a Java SE environment, however, you have to " -"add an implementation as dependency to your POM file. For instance you can " -"add the following two dependencies to use the JSR 341 reference implementation:" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:87 -#, no-c-format -msgid "Maven dependencies for Unified EL reference implementation" -msgstr "" - -#. Tag: programlisting -#: gettingstarted.xml:90 -#, no-c-format -msgid "" -"<dependency>\n" -" <groupId>javax.el</groupId>\n" -" <artifactId>javax.el-api</artifactId>\n" -" <version>2.2.4</version>\n" -"</dependency>\n" -"<dependency>\n" -" <groupId>org.glassfish.web</groupId>\n" -" <artifactId>javax.el</artifactId>\n" -" <version>2.2.4</version>\n" -"</dependency>" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:95 -#, no-c-format -msgid "CDI" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:97 -#, no-c-format -msgid "" -"Bean Validation defines integration points with CDI (Contexts and Dependency " -"Injection for JavaTM EE, JSR 346). If your application runs in an " -"environment which does not provide this integration out of the box, you may " -"use the Hibernate Validator CDI portable extension by adding the following " -"Maven dependency to your POM:" -msgstr "" - -#. Tag: title -#: gettingstarted.xml:106 -#, no-c-format -msgid "Hibernate Validator CDI portable extension Maven dependency" -msgstr "" - -#. Tag: programlisting -#: gettingstarted.xml:109 -#, no-c-format -msgid "" -"<dependency>\n" -" <groupId>org.hibernate</groupId>\n" -" <artifactId>hibernate-validator-cdi</artifactId>\n" -" <version>&version;</version>\n" -"</dependency>" -msgstr "" - -#. Tag: para -#: gettingstarted.xml:112 -#, no-c-format -msgid "" -"Note that adding this dependency is usually not required for applications " -"running on a Java EE application server. You can learn more about the " -"integration of Bean Validation and CDI in section TODO." -msgstr "" - -#. Tag: title -#: gettingstarted.xml:119 -#, no-c-format -msgid "Applying constraints" -msgstr "添加约束" - -#. Tag: para -#: gettingstarted.xml:121 -#, no-c-format -msgid "Lets dive directly into an example to see how to apply constraints." -msgstr "" - -#. Tag: title -#: gettingstarted.xml:125 -#, no-c-format -msgid "Class Car annotated with constraints" -msgstr "带约束性标注(annotated with constraints)的Car 类" - -#. Tag: programlisting -#: gettingstarted.xml:127 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.Min;\n" -"import javax.validation.constraints.NotNull;\n" -"import javax.validation.constraints.Size;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" private String licensePlate;\n" -"\n" -" @Min(2)\n" -" private int seatCount;\n" -" \n" -" public Car(String manufacturer, String licencePlate, int seatCount) {\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.Min;\n" -"import javax.validation.constraints.NotNull;\n" -"import javax.validation.constraints.Size;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" private String licensePlate;\n" -"\n" -" @Min(2)\n" -" private int seatCount;\n" -" \n" -" public Car(String manufacturer, String licencePlate, int seatCount) {\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" - -#. Tag: para -#: gettingstarted.xml:130 -#, no-c-format -msgid "" -"@NotNull, @Size and " -"@Min are so-called constraint annotations, that we " -"use to declare constraints, which shall be applied to the fields of a " -"Car instance:" -msgstr "" -"@NotNull, @Size and " -"@Min就是上面所属的约束性标注( constraint " -"annotations), 我们就是使用它们来声明约束, 例如在Car的" -"字段中我们可以看到:" - -#. Tag: para -#: gettingstarted.xml:137 -#, no-c-format -msgid "manufacturer shall never be null" -msgstr "manufacturer永远不能为null" - -#. Tag: para -#: gettingstarted.xml:141 -#, no-c-format -msgid "" -"licensePlate shall never be null and must be between 2 " -"and 14 characters long" -msgstr "" -"licensePlate永远不能为null,并且它的值字符串的长度要在2到" -"14之间" - -#. Tag: para -#: gettingstarted.xml:146 -#, no-c-format -msgid "seatCount shall be at least 2." -msgstr "seatCount的值要不能小于2" - -#. Tag: title -#: gettingstarted.xml:152 -#, no-c-format -msgid "Validating constraints" -msgstr "校验约束" - -#. Tag: para -#: gettingstarted.xml:154 -#, fuzzy, no-c-format -msgid "" -"To perform a validation of these constraints, we use a Validator instance. Let's have a look at a unit test for Car:" -msgstr "" -"我们需要使用Validator来对上面的那些约束进行校验. 让我" -"们来看看CarTest这个类:" - -#. Tag: title -#: gettingstarted.xml:159 -#, no-c-format -msgid "Class CarTest showing validation examples" -msgstr "在CarTest中使用校验" - -#. Tag: programlisting -#: gettingstarted.xml:161 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import static org.junit.Assert.*;\n" -"\n" -"import java.util.Set;\n" -"\n" -"import javax.validation.ConstraintViolation;\n" -"import javax.validation.Validation;\n" -"import javax.validation.Validator;\n" -"import javax.validation.ValidatorFactory;\n" -"\n" -"import org.junit.BeforeClass;\n" -"import org.junit.Test;\n" -"\n" -"public class CarTest {\n" -"\n" -" private static Validator validator;\n" -"\n" -" @BeforeClass\n" -" public static void setUp() {\n" -" ValidatorFactory factory = Validation.buildDefaultValidatorFactory" -"();\n" -" validator = factory.getValidator();\n" -" }\n" -"\n" -" @Test\n" -" public void manufacturerIsNull() {\n" -" Car car = new Car(null, \"DD-AB-123\", 4);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -"\n" -" assertEquals(1, constraintViolations.size());\n" -" assertEquals(\"may not be null\", constraintViolations.iterator()." -"next().getMessage());\n" -" }\n" -"\n" -" @Test\n" -" public void licensePlateTooShort() {\n" -" Car car = new Car(\"Morris\", \"D\", 4);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations = \n" -" validator.validate(car);\n" -"\n" -" assertEquals(1, constraintViolations.size());\n" -" assertEquals(\"size must be between 2 and 14\", constraintViolations." -"iterator().next().getMessage());\n" -" }\n" -" \n" -" @Test\n" -" public void seatCountTooLow() {\n" -" Car car = new Car(\"Morris\", \"DD-AB-123\", 1);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -"\n" -" assertEquals(1, constraintViolations.size());\n" -" assertEquals(\"must be greater than or equal to 2\", " -"constraintViolations.iterator().next().getMessage());\n" -" }\n" -"\n" -" @Test\n" -" public void carIsValid() {\n" -" Car car = new Car(\"Morris\", \"DD-AB-123\", 2);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -"\n" -" assertEquals(0, constraintViolations.size());\n" -" }\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import static org.junit.Assert.*;\n" -"\n" -"import java.util.Set;\n" -"\n" -"import javax.validation.ConstraintViolation;\n" -"import javax.validation.Validation;\n" -"import javax.validation.Validator;\n" -"import javax.validation.ValidatorFactory;\n" -"\n" -"import org.junit.BeforeClass;\n" -"import org.junit.Test;\n" -"\n" -"public class CarTest {\n" -"\n" -" private static Validator validator;\n" -"\n" -" @BeforeClass\n" -" public static void setUp() {\n" -" ValidatorFactory factory = Validation.buildDefaultValidatorFactory" -"();\n" -" validator = factory.getValidator();\n" -" }\n" -"\n" -" @Test\n" -" public void manufacturerIsNull() {\n" -" Car car = new Car(null, \"DD-AB-123\", 4);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -"\n" -" assertEquals(1, constraintViolations.size());\n" -" assertEquals(\"may not be null\", constraintViolations.iterator()." -"next().getMessage());\n" -" }\n" -"\n" -" @Test\n" -" public void licensePlateTooShort() {\n" -" Car car = new Car(\"Morris\", \"D\", 4);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations = \n" -" validator.validate(car);\n" -"\n" -" assertEquals(1, constraintViolations.size());\n" -" assertEquals(\"size must be between 2 and 14\", constraintViolations." -"iterator().next().getMessage());\n" -" }\n" -" \n" -" @Test\n" -" public void seatCountTooLow() {\n" -" Car car = new Car(\"Morris\", \"DD-AB-123\", 1);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -"\n" -" assertEquals(1, constraintViolations.size());\n" -" assertEquals(\"must be greater than or equal to 2\", " -"constraintViolations.iterator().next().getMessage());\n" -" }\n" -"\n" -" @Test\n" -" public void carIsValid() {\n" -" Car car = new Car(\"Morris\", \"DD-AB-123\", 2);\n" -"\n" -" Set<ConstraintViolation<Car>> constraintViolations =\n" -" validator.validate(car);\n" -"\n" -" assertEquals(0, constraintViolations.size());\n" -" }\n" -"}" - -#. Tag: para -#: gettingstarted.xml:164 -#, no-c-format -msgid "" -"In the setUp() method we get a " -"Validator instance from the " -"ValidatorFactory. A Validator " -"instance is thread-safe and may be reused multiple times. For this reason we " -"store it as field of our test class. We can use the Validator now to validate the different car instances in the test methods." -msgstr "" -"在setUp()方法中,我们通过" -"ValidatorFactory得到了一个Validator的实例. Validator是线程安全的,并且可以重复使" -"用, 所以我们把它保存成一个类变量. 现在我们可以在test方法中使用这个validator的" -"实例来校验不同的car实例了." - -#. Tag: para -#: gettingstarted.xml:172 -#, no-c-format -msgid "" -"The validate() method returns a set of " -"ConstraintViolation instances, which we can iterate " -"in order to see which validation errors occurred. The first three test " -"methods show some expected constraint violations:" -msgstr "" -"validate()方法会返回一个set的" -"ConstraintViolation的实例的集合, 我们可以通过遍历它来" -"查看有哪些验证错误. 前面三个测试用例显示了一些预期的校验约束:" - -#. Tag: para -#: gettingstarted.xml:179 -#, no-c-format -msgid "" -"The @NotNull constraint on manufacturer is violated " -"in manufacturerIsNull()" -msgstr "" -"在manufacturerIsNull()中可以看到manufacturer违反了" -"@NotNull约束" - -#. Tag: para -#: gettingstarted.xml:184 -#, no-c-format -msgid "" -"The @Size constraint on licensePlate is violated in " -"licensePlateTooShort()" -msgstr "" -"licensePlateTooShort()中的licensePlate违反了" -"@Size约束" - -#. Tag: para -#: gettingstarted.xml:189 -#, no-c-format -msgid "" -"The @Min constraint on seatCount is violated in " -"seatCountTooLow()" -msgstr "" -"而seatCountTooLow()中则导致seatCount违反了" -"@Min约束" - -#. Tag: para -#: gettingstarted.xml:194 -#, no-c-format -msgid "" -"If the object validates successfully, validate() " -"returns an empty set." -msgstr "" -" 如果一个对象没有校验出问题的话,那么validate() 会返" -"回一个空的set对象." - -#. Tag: para -#: gettingstarted.xml:197 -#, no-c-format -msgid "" -"Note that we only use classes from the package javax.validation from the Bean Validation API. As we don't reference any classes of " -"the RI directly, it would be no problem to switch to another implementation " -"of the API, should that need arise." -msgstr "" -"注意,我们只使用了Bean Validation API中的package javax.validation中的类, 并没有直接调用参考实现中的任何类,所以, 没有任何问题如果切换到" -"其他的实现." - -#. Tag: title -#: gettingstarted.xml:205 -#, no-c-format -msgid "Where to go next?" -msgstr "更进一步" - -#. Tag: para -#: gettingstarted.xml:207 -#, fuzzy, no-c-format -msgid "" -"That concludes our 5 minute tour through the world of Hibernate Validator. " -"Continue exploring the code examples or look at further examples referenced " -"in . To deepen your " -"understanding of Hibernate Validator just continue reading . In case your application has specific " -"validation requirements have a look at ." -msgstr "" -"在本章中, 您了解了一个基于Hibernate Validator的简单例子. 更多的示例请参考 " -". 如果想进一步了解Hibenate " -"Validator, 请继续阅读. 如果您的" -"应用程序有特殊的校验需求,请参考 ." - -#, fuzzy -#~ msgid "" -#~ "A properly configured remote repository. Add the following to your " -#~ "settings.xml: Configuring the JBoss Maven repository " -#~ "<repositories>\n" -#~ " <repository>\n" -#~ " <id>jboss-public-repository-group</id>\n" -#~ " <url>https://repository.jboss.org/nexus/content/groups/" -#~ "public-jboss</url>\n" -#~ " <releases>\n" -#~ " <enabled>true</enabled>\n" -#~ " </releases>\n" -#~ " <snapshots>\n" -#~ " <enabled>true</enabled>\n" -#~ " </snapshots>\n" -#~ " </repository>\n" -#~ "</repositories> More information " -#~ "about settings.xml can be found in the Maven " -#~ "Local Settings Model." -#~ msgstr "" -#~ "配置远端maven仓库. 添加下面的内容到你的settings.xml" -#~ "中: Configuring the JBoss Maven repository in " -#~ "<filename>settings.xml</filename> <" -#~ "repositories>\n" -#~ " <repository>\n" -#~ " <id>jboss</id>\n" -#~ " <url>http://repository.jboss.com/maven2</url>\n" -#~ " <releases>\n" -#~ " <enabled>true</enabled>\n" -#~ " </releases>\n" -#~ " <snapshots>\n" -#~ " <enabled>false</enabled>\n" -#~ " </snapshots>\n" -#~ " </repository>\n" -#~ "</repositories> 更多关于" -#~ "settings.xml 的信息请参考Maven Local Settings " -#~ "Model." - -#, fuzzy -#~ msgid "" -#~ "Alternatively, you can start by creating a sample project using Hibernate " -#~ "Validator's Quickstart Maven archetype as follows:" -#~ msgstr "使用Maven archetype插件来创建一个新的Maven 项目" - -#~ msgid "" -#~ "Using Maven's archetype plugin to create a sample project using Hibernate " -#~ "Validator" -#~ msgstr "" -#~ "使用Maven archetype 插件来创建一个简单的基于Hibernate Validator的项目" - -#, fuzzy -#~ msgid "" -#~ "mvn archetype:generate -DarchetypeGroupId=org.hibernate \\\n" -#~ " -DarchetypeArtifactId=hibernate-validator-" -#~ "quickstart-archetype \\\n" -#~ " -DarchetypeVersion=&version; \\\n" -#~ " -DarchetypeRepository=http://repository.jboss.org/" -#~ "nexus/content/groups/public-jboss/ \\\n" -#~ " -DgroupId=com.mycompany \\\n" -#~ " -DartifactId=hv-quickstart" -#~ msgstr "" -#~ "mvn archetype:create -DarchetypeGroupId=org.hibernate \\\n" -#~ " -DarchetypeArtifactId=hibernate-validator-quickstart-" -#~ "archetype \\\n" -#~ " -DarchetypeVersion=&version; \\\n" -#~ " -DgroupId=com.mycompany \n" -#~ " -DartifactId=hv-quickstart" - -#~ msgid "" -#~ "Maven will create your project in the directory hv-quickstart. Change " -#~ "into this directory and run:" -#~ msgstr "" -#~ "Maven 将会把你的项目创建在hv-quickstart目录中. 进入这个目录并且执行:" - -#~ msgid "mvn test" -#~ msgstr "mvn test" - -#, fuzzy -#~ msgid "" -#~ "Maven will compile the example code and run the implemented unit tests. " -#~ "Let's have a look at the actual code in the next section." -#~ msgstr "" -#~ "这样, Maven会编译示例代码并且运行单元测试, 接下来,让我们看看生成的代码." - -#~ msgid "" -#~ "Open the project in the IDE of your choice and have a look at the class " -#~ "Car:" -#~ msgstr "在你喜欢的IDE中打开这个项目中的Car类:" - -#, fuzzy -#~ msgid "" -#~ "Hibernate Validator uses JAXB for XML parsing. JAXB is part of the Java " -#~ "Class Library since Java 6 which means that if you run Hibernate " -#~ "Validator with Java 5 you will have to add additional JAXB dependencies. " -#~ "Using Maven you have to add the following dependencies:" -#~ "<dependency>\n" -#~ " <groupId>javax.xml.bind</groupId>\n" -#~ " <artifactId>jaxb-api</artifactId>\n" -#~ " <version>2.2</version>\n" -#~ "</dependency>\n" -#~ "<dependency>\n" -#~ " <groupId>com.sun.xml.bind</groupId>\n" -#~ " <artifactId>jaxb-impl</artifactId>\n" -#~ " <version>2.1.12</version>\n" -#~ "</dependency>\n" -#~ " if you are using the SourceForge package you find the " -#~ "necessary libraries in the lib/jdk5 directory. In " -#~ "case you are not using the XML configuration you can also disable it " -#~ "explicitly by calling Configuration.ignoreXmlConfiguration() during ValidationFactory creation. In " -#~ "this case the JAXB dependencies are not needed." -#~ msgstr "" -#~ "Hibernate Validator 使用JAXB 来解析XML. JAXB 已经被集成进Java 6了, 所以,如" -#~ "果你要在Java 5上使用Hibernate Validator的话, 那么,还需要添加额外的JAXB的依" -#~ "赖. 如果你使用Maven的话,你可以把下面的内容添加到pom当中:" -#~ "<dependency>\n" -#~ " <groupId>javax.xml.bind</groupId>\n" -#~ " <artifactId>jaxb-api</artifactId>\n" -#~ " <version>2.2</version>\n" -#~ "</dependency>\n" -#~ "<dependency>\n" -#~ " <groupId>com.sun.xml.bind</groupId>\n" -#~ " <artifactId>jaxb-impl</artifactId>\n" -#~ " <version>2.1.12</version>\n" -#~ "</dependency>\n" -#~ "" - -#~ msgid "Setting up a new Maven project" -#~ msgstr "第一个Maven项目" diff --git a/documentation/src/main/docbook/zh-CN/modules/groups.po b/documentation/src/main/docbook/zh-CN/modules/groups.po deleted file mode 100644 index f080e5e3c1..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/groups.po +++ /dev/null @@ -1,914 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-03 09:59+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"Language: zh-CN\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: groups.xml:24 -#, no-c-format -msgid "Grouping constraints" -msgstr "" - -#. Tag: para -#: groups.xml:26 -#, no-c-format -msgid "" -"All validation methods on Validator and " -"ExecutableValidator discussed in earlier chapters " -"also take a var-arg argument groups. So far we have " -"been ignoring this parameter, but it is time to have a closer look." -msgstr "" - -#. Tag: title -#: groups.xml:32 -#, no-c-format -msgid "Requesting groups" -msgstr "" - -#. Tag: para -#: groups.xml:34 -#, no-c-format -msgid "" -"Groups allow you to restrict the set of constraints applied during " -"validation. A possible use-case for groups are UI wizards where in each step " -"only a specified subset of constraints get validated. The groups targeted " -"are passed as var-arg parameters to the appropriate validate method. Let's " -"have a look at an extended Car with " -"Driver example. First we have the class " -"Person () which has " -"a @NotNull constraint on name. " -"Since no group is specified for this annotation the default group " -"javax.validation.groups.Default is assumed." -msgstr "" - -#. Tag: para -#: groups.xml:46 -#, no-c-format -msgid "" -"When more than one group is requested, the order in which the groups are " -"evaluated is not deterministic. If no group is specified the default group " -"javax.validation.groups.Default is assumed." -msgstr "" - -#. Tag: title -#: groups.xml:53 -#, no-c-format -msgid "Person" -msgstr "" - -#. Tag: programlisting -#: groups.xml:55 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups;\n" -"\n" -"public class Person {\n" -" @NotNull\n" -" private String name;\n" -"\n" -" public Person(String name) {\n" -" this.name = name;\n" -" }\n" -"\n" -" // getters and setters ...\n" -"}" -msgstr "" - -#. Tag: para -#: groups.xml:58 -#, no-c-format -msgid "" -"Next we have the class Driver () extending Person. Here we are " -"adding the properties age and " -"hasDrivingLicense. In order to drive you must be at " -"least 18 (@Min(18)) and you must have a driving " -"license (@AssertTrue). Both constraints defined on " -"these properties belong to the group DriverChecks. As " -"you can see in the group " -"DriverChecks is just a simple tagging interface. " -"Using interfaces makes the usage of groups type safe and allows for easy " -"refactoring. It also means that groups can inherit from each other via class " -"inheritance." -msgstr "" - -#. Tag: title -#: groups.xml:72 -#, no-c-format -msgid "Driver" -msgstr "" - -#. Tag: programlisting -#: groups.xml:74 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups;\n" -"\n" -"public class Driver extends Person {\n" -" @Min(\n" -" value = 18,\n" -" message = \"You have to be 18 to drive a car\",\n" -" groups = DriverChecks.class\n" -" )\n" -" public int age;\n" -"\n" -" @AssertTrue(\n" -" message = \"You first have to pass the driving test" -"\",\n" -" groups = DriverChecks.class\n" -" )\n" -" public boolean hasDrivingLicense;\n" -"\n" -" public Driver(String name) {\n" -" super( name );\n" -" }\n" -"\n" -" public void passedDrivingTest(boolean b) {\n" -" hasDrivingLicense = b;\n" -" }\n" -"\n" -" public int getAge() {\n" -" return age;\n" -" }\n" -"\n" -" public void setAge(int age) {\n" -" this.age = age;\n" -" }\n" -"}" -msgstr "" - -#. Tag: title -#: groups.xml:78 -#, no-c-format -msgid "Group interfaces" -msgstr "" - -#. Tag: programlisting -#: groups.xml:80 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups;\n" -"\n" -"public interface DriverChecks {\n" -"}" -msgstr "" - -#. Tag: programlisting -#: groups.xml:82 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups;\n" -"\n" -"public interface CarChecks {\n" -"}" -msgstr "" - -#. Tag: para -#: groups.xml:85 -#, no-c-format -msgid "" -"Last but not least we add the property passedVehicleInspection to the Car class () indicating whether a car passed the road worthy tests." -msgstr "" - -#. Tag: title -#: groups.xml:91 -#, no-c-format -msgid "Car" -msgstr "" - -#. Tag: programlisting -#: groups.xml:93 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups;\n" -"\n" -"public class Car {\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" private String licensePlate;\n" -"\n" -" @Min(2)\n" -" private int seatCount;\n" -"\n" -" @AssertTrue(\n" -" message = \"The car has to pass the vehicle " -"inspection first\",\n" -" groups = CarChecks.class\n" -" )\n" -" private boolean passedVehicleInspection;\n" -"\n" -" @Valid\n" -" private Driver driver;\n" -"\n" -" public Car(String manufacturer, String licencePlate, int seatCount) " -"{\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" public boolean isPassedVehicleInspection() {\n" -" return passedVehicleInspection;\n" -" }\n" -"\n" -" public void setPassedVehicleInspection(boolean " -"passedVehicleInspection) {\n" -" this.passedVehicleInspection = passedVehicleInspection;\n" -" }\n" -"\n" -" public Driver getDriver() {\n" -" return driver;\n" -" }\n" -"\n" -" public void setDriver(Driver driver) {\n" -" this.driver = driver;\n" -" }\n" -"\n" -" // getters and setters ...\n" -"}" -msgstr "" - -#. Tag: para -#: groups.xml:96 -#, no-c-format -msgid "" -"Overall three different groups are used in our example. Person." -"name, Car.manufacturer, Car." -"licensePlate and Car.seatCount all belong to " -"the Default group. Driver.age " -"and Driver.hasDrivingLicense belong to " -"DriverChecks and last but not least Car." -"passedVehicleInspection belongs to the group " -"CarChecks. " -"shows how passing different group combinations to the Validator." -"validate method result in different validation results." -msgstr "" - -#. Tag: title -#: groups.xml:110 -#, no-c-format -msgid "Drive away" -msgstr "" - -#. Tag: programlisting -#: groups.xml:112 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups;\n" -"\n" -"public class GroupTest {\n" -"\n" -" private static Validator validator;\n" -"\n" -" @BeforeClass\n" -" public static void setUp() {\n" -" ValidatorFactory factory = Validation." -"buildDefaultValidatorFactory();\n" -" validator = factory.getValidator();\n" -" }\n" -"\n" -" @Test\n" -" public void driveAway() {\n" -" // create a car and check that everything is ok with it.\n" -" Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" -" Set<ConstraintViolation<Car>> " -"constraintViolations = validator.validate( car );\n" -" assertEquals( 0, constraintViolations.size() );\n" -"\n" -" // but has it passed the vehicle inspection?\n" -" constraintViolations = validator.validate( car, CarChecks." -"class );\n" -" assertEquals( 1, constraintViolations.size() );\n" -" assertEquals(\n" -" \"The car has to pass the vehicle inspection " -"first\",\n" -" constraintViolations.iterator().next()." -"getMessage()\n" -" );\n" -"\n" -" // let's go to the vehicle inspection\n" -" car.setPassedVehicleInspection( true );\n" -" assertEquals( 0, validator.validate( car ).size() );\n" -"\n" -" // now let's add a driver. He is 18, but has not passed the " -"driving test yet\n" -" Driver john = new Driver( \"John Doe\" );\n" -" john.setAge( 18 );\n" -" car.setDriver( john );\n" -" constraintViolations = validator.validate( car, DriverChecks." -"class );\n" -" assertEquals( 1, constraintViolations.size() );\n" -" assertEquals(\n" -" \"You first have to pass the driving test" -"\",\n" -" constraintViolations.iterator().next()." -"getMessage()\n" -" );\n" -"\n" -" // ok, John passes the test\n" -" john.passedDrivingTest( true );\n" -" assertEquals( 0, validator.validate( car, DriverChecks." -"class ).size() );\n" -"\n" -" // just checking that everything is in order now\n" -" assertEquals(\n" -" 0, validator.validate(\n" -" car,\n" -" Default.class,\n" -" CarChecks.class,\n" -" DriverChecks.class\n" -" ).size()\n" -" );\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: groups.xml:115 -#, no-c-format -msgid "" -"In we first create a car and validate " -"it using no explicit group. There are no validation errors, even though the " -"property passedVehicleInspection is per default " -"false. However, the constraint defined on this property " -"does not belong to the default group. Next we just validate the " -"CarChecks group which will fail until we make sure " -"that the car passes the vehicle inspection. When we then add a driver to the " -"car and validate against DriverChecks we get again a " -"constraint violation due to the fact that the driver has not yet passed the " -"driving test. Only after setting passedDrivingTest to " -"true the validation against DriverChecks will pass. " -"Last but not least, we show that all constraints are passing by validating " -"against all defined groups." -msgstr "" - -#. Tag: title -#: groups.xml:132 -#, no-c-format -msgid "Defining group sequences" -msgstr "" - -#. Tag: para -#: groups.xml:134 -#, no-c-format -msgid "" -"By default, constraints are evaluated in no particular order, regardless of " -"which groups they belong to. In some situations, however, it is useful to " -"control the order constraints are evaluated. In our example from we could for example require that first all " -"default car constraints are passing before we check the road worthiness of " -"the car. Finally before we drive away we check the actual driver " -"constraints. In order to implement such an order one would define a new " -"interface and annotate it with @GroupSequence " -"defining the order in which the groups have to be validated." -msgstr "" - -#. Tag: para -#: groups.xml:146 -#, no-c-format -msgid "" -"If at least one constraint fails in a sequenced group none of the " -"constraints of the following groups in the sequence get validated." -msgstr "" - -#. Tag: title -#: groups.xml:152 -#, no-c-format -msgid "Interface with @GroupSequence" -msgstr "" - -#. Tag: programlisting -#: groups.xml:154 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups;\n" -"\n" -"@GroupSequence({ Default.class, CarChecks.class, DriverChecks.class })\n" -"public interface OrderedChecks {\n" -"}" -msgstr "" - -#. Tag: para -#: groups.xml:158 -#, no-c-format -msgid "" -"Groups defining a sequence and groups composing a sequence must not be " -"involved in a cyclic dependency either directly or indirectly, either " -"through cascaded sequence definition or group inheritance. If a group " -"containing such a circularity is evaluated, a " -"GroupDefinitionException is raised." -msgstr "" - -#. Tag: para -#: groups.xml:162 -#, no-c-format -msgid "" -"The usage of the new sequence could then look like in ." -msgstr "" - -#. Tag: title -#: groups.xml:167 -#, no-c-format -msgid "Usage of a group sequence" -msgstr "" - -#. Tag: programlisting -#: groups.xml:169 -#, no-c-format -msgid "" -"@Test\n" -"public void testOrderedChecks() {\n" -" Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" -" car.setPassedVehicleInspection( true );\n" -"\n" -" Driver john = new Driver( \"John Doe\" );\n" -" john.setAge( 18 );\n" -" john.passedDrivingTest( true );\n" -" car.setDriver( john );\n" -"\n" -" assertEquals( 0, validator.validate( car, OrderedChecks.class ).size" -"() );\n" -"}" -msgstr "" - -#. Tag: title -#: groups.xml:174 -#, no-c-format -msgid "Redefining the default group sequence" -msgstr "" - -#. Tag: title -#: groups.xml:177 -#, no-c-format -msgid "@GroupSequence" -msgstr "" - -#. Tag: para -#: groups.xml:179 -#, no-c-format -msgid "" -"The @GroupSequence annotation also fulfills a second " -"purpose. It allows you to redefine what the Default " -"group means for a given class. To redefine Default " -"for a given class, add a @GroupSequence annotation to " -"the class. The defined groups in the annotation express the sequence of " -"groups that substitute Default for this class. introduces a new class " -"RentalCar with a redefined default group. With this " -"definition you can evaluate the constraints belonging to " -"RentalChecks, CarChecks and " -"RentalCar by just requesting the Default group as seen in ." -msgstr "" - -#. Tag: title -#: groups.xml:195 -#, no-c-format -msgid "RentalCar with @GroupSequence" -msgstr "" - -#. Tag: programlisting -#: groups.xml:197 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups;\n" -"\n" -"@GroupSequence({ RentalChecks.class, CarChecks.class, RentalCar.class })\n" -"public class RentalCar extends Car {\n" -" @AssertFalse(message = \"The car is currently rented out\", groups = " -"RentalChecks.class)\n" -" private boolean rented;\n" -"\n" -" public RentalCar(String manufacturer, String licencePlate, int " -"seatCount) {\n" -" super( manufacturer, licencePlate, seatCount );\n" -" }\n" -"\n" -" public boolean isRented() {\n" -" return rented;\n" -" }\n" -"\n" -" public void setRented(boolean rented) {\n" -" this.rented = rented;\n" -" }\n" -"}" -msgstr "" - -#. Tag: title -#: groups.xml:201 -#, no-c-format -msgid "RentalCar with redefined default group" -msgstr "" - -#. Tag: programlisting -#: groups.xml:203 -#, no-c-format -msgid "" -"/**\n" -" * Validating the default group leads to validation on the default group " -"sequence of {@code RentalCar}.\n" -" */\n" -"@Test\n" -"public void carIsRented() {\n" -" RentalCar rentalCar = new RentalCar( \"Morris\", \"DD-AB-123\", " -"2 );\n" -" rentalCar.setPassedVehicleInspection( true );\n" -" rentalCar.setRented( true );\n" -"\n" -" Set<ConstraintViolation<RentalCar>> constraintViolations " -"= validator.validate( rentalCar );\n" -"\n" -" assertEquals( 1, constraintViolations.size() );\n" -" assertEquals(\n" -" \"Wrong message\",\n" -" \"The car is currently rented out\",\n" -" constraintViolations.iterator().next().getMessage()\n" -" );\n" -"\n" -" rentalCar.setRented( false );\n" -" constraintViolations = validator.validate( rentalCar );\n" -"\n" -" assertEquals( 0, constraintViolations.size() );\n" -"}" -msgstr "" - -#. Tag: para -#: groups.xml:207 -#, no-c-format -msgid "" -"Due to the fact that there cannot be a cyclic dependency in the group and " -"group sequence definitions one cannot just add Default to the sequence redefining Default for a " -"class. Instead the class itself has to be added!" -msgstr "" - -#. Tag: para -#: groups.xml:215 -#, no-c-format -msgid "" -"The Default group sequence overriding is local to the " -"class it is defined on and is not propagated to the associated objects. This " -"means in particular that adding DriverChecks to the " -"default group sequence of RentalCar would not have " -"any effects. Only the group Default will be " -"propagated to the driver association when validation a rental car instance." -msgstr "" - -#. Tag: title -#: groups.xml:226 -#, no-c-format -msgid "@GroupSequenceProvider" -msgstr "" - -#. Tag: para -#: groups.xml:228 -#, no-c-format -msgid "" -"The @javax.validation.GroupSequence annotation is a " -"standardized Bean Validation annotation. As seen in the previous section it " -"allows you to statically redefine the default group sequence for a class. " -"Hibernate Validator also offers a custom, non standardized annotation - " -"org.hibernate.validator.group.GroupSequenceProvider - " -"which allows for dynamic redefinition of the default group sequence. Using " -"the rental car scenario again, one could dynamically add the " -"CarChecks as seen in and ." -msgstr "" - -#. Tag: title -#: groups.xml:241 -#, no-c-format -msgid "RentalCar with @GroupSequenceProvider" -msgstr "" - -#. Tag: programlisting -#: groups.xml:243 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups." -"groupsequenceprovider;\n" -"\n" -"@GroupSequenceProvider(RentalCarGroupSequenceProvider.class)\n" -"public class RentalCar extends Car {\n" -" @AssertFalse(message = \"The car is currently rented out\", groups = " -"RentalChecks.class)\n" -" private boolean rented;\n" -"\n" -" public RentalCar(String manufacturer, String licencePlate, int " -"seatCount) {\n" -" super( manufacturer, licencePlate, seatCount );\n" -" }\n" -"\n" -" public boolean isRented() {\n" -" return rented;\n" -" }\n" -"\n" -" public void setRented(boolean rented) {\n" -" this.rented = rented;\n" -" }\n" -"}" -msgstr "" - -#. Tag: title -#: groups.xml:247 -#, no-c-format -msgid "DefaultGroupSequenceProvider implementation" -msgstr "" - -#. Tag: programlisting -#: groups.xml:249 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups." -"groupsequenceprovider;\n" -"\n" -"public class RentalCarGroupSequenceProvider implements " -"DefaultGroupSequenceProvider<RentalCar> {\n" -" public List<Class<?>> getValidationGroups(RentalCar car) " -"{\n" -" List<Class<?>> defaultGroupSequence = new " -"ArrayList<Class<?>>();\n" -" defaultGroupSequence.add( RentalCar.class );\n" -"\n" -" if ( car != null && !car.isRented() ) {\n" -" defaultGroupSequence.add( CarChecks.class );\n" -" }\n" -"\n" -" return defaultGroupSequence;\n" -" }\n" -"}" -msgstr "" - -#. Tag: title -#: groups.xml:255 -#, no-c-format -msgid "Group conversion" -msgstr "" - -#. Tag: para -#: groups.xml:257 -#, no-c-format -msgid "" -"What if you wanted to validate the car related checks together with the " -"driver checks. Of course you could pass the required groups to the validate " -"call explicitly, but what if you wanted to make these validations occur as " -"part of the Default group validation. Here " -"@ConvertGroup comes into play which allows you during " -"cascaded validation to use a different group than the originally requested " -"one." -msgstr "" - -#. Tag: para -#: groups.xml:265 -#, no-c-format -msgid "" -"Let's have a look at . Here @GroupSequence({ CarChecks.class, Car.class })" -" is used to combine the car related constraints under the " -"Default group (see ). There is also a @ConvertGroup(from = Default.class, " -"to = DriverChecks.class) which ensures the Default group gets converted to the DriverChecks " -"group during cascaded validation of the driver " -"association." -msgstr "" - -#. Tag: title -#: groups.xml:277 -#, no-c-format -msgid "@ConvertGroup usage" -msgstr "" - -#. Tag: programlisting -#: groups.xml:279 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups." -"groupconversion;\n" -"\n" -"@GroupSequence({ CarChecks.class, Car.class })\n" -"public class Car {\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" private String licensePlate;\n" -"\n" -" @Min(2)\n" -" private int seatCount;\n" -"\n" -" @AssertTrue(\n" -" message = \"The car has to pass the vehicle " -"inspection first\",\n" -" groups = CarChecks.class\n" -" )\n" -" private boolean passedVehicleInspection;\n" -"\n" -" @Valid\n" -" @ConvertGroup(from = Default.class, to = DriverChecks.class)\n" -" private Driver driver;\n" -"\n" -" public Car(String manufacturer, String licencePlate, int seatCount) " -"{\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" public boolean isPassedVehicleInspection() {\n" -" return passedVehicleInspection;\n" -" }\n" -"\n" -" public void setPassedVehicleInspection(boolean " -"passedVehicleInspection) {\n" -" this.passedVehicleInspection = passedVehicleInspection;\n" -" }\n" -"\n" -" public Driver getDriver() {\n" -" return driver;\n" -" }\n" -"\n" -" public void setDriver(Driver driver) {\n" -" this.driver = driver;\n" -" }\n" -"\n" -" // getters and setters ...\n" -"}" -msgstr "" - -#. Tag: programlisting -#: groups.xml:281 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups." -"groupconversion;\n" -"\n" -"public class Driver extends Person {\n" -" @Min(\n" -" value = 18,\n" -" message = \"You have to be 18 to drive a car\",\n" -" groups = DriverChecks.class\n" -" )\n" -" public int age;\n" -"\n" -" @AssertTrue(\n" -" message = \"You first have to pass the driving test" -"\",\n" -" groups = DriverChecks.class\n" -" )\n" -" public boolean hasDrivingLicense;\n" -"\n" -" public Driver(String name) {\n" -" super( name );\n" -" }\n" -"\n" -" public void passedDrivingTest(boolean b) {\n" -" hasDrivingLicense = b;\n" -" }\n" -"\n" -" public int getAge() {\n" -" return age;\n" -" }\n" -"\n" -" public void setAge(int age) {\n" -" this.age = age;\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: groups.xml:284 -#, no-c-format -msgid "" -"As a result the validateDriverChecksTogetherWithCarChecks test in will " -"pass even though the constraint on hasDrivingLicense " -"belongs to the DriverChecks group and only the " -"Default group is requested in the " -"validate call." -msgstr "" - -#. Tag: title -#: groups.xml:293 -#, no-c-format -msgid "Test case for @ConvertGroup" -msgstr "" - -#. Tag: programlisting -#: groups.xml:295 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter05.groups." -"groupconversion;\n" -"\n" -"public class GroupConversionTest {\n" -"\n" -" private static Validator validator;\n" -"\n" -" @BeforeClass\n" -" public static void setUp() {\n" -" ValidatorFactory factory = Validation." -"buildDefaultValidatorFactory();\n" -" validator = factory.getValidator();\n" -" }\n" -"\n" -" @Test\n" -" public void validateDriverChecksTogetherWithCarChecks() {\n" -" // create a car and validate. The Driver is still null and " -"does not get validated\n" -" Car car = new Car( \"VW\", \"USD-123\", 4 );\n" -" car.setPassedVehicleInspection( true );\n" -" Set<ConstraintViolation<Car>> " -"constraintViolations = validator.validate( car );\n" -" assertEquals( 0, constraintViolations.size() );\n" -"\n" -" // create a driver who has not passed the driving test\n" -" Driver john = new Driver( \"John Doe\" );\n" -" john.setAge( 18 );\n" -"\n" -" // now let's add a driver to the car\n" -" car.setDriver( john );\n" -" constraintViolations = validator.validate( car );\n" -" assertEquals( 1, constraintViolations.size() );\n" -" assertEquals(\n" -" \"The driver constraint should also be " -"validated as part of the default group\",\n" -" constraintViolations.iterator().next()." -"getMessage(),\n" -" \"You first have to pass the driving test\"\n" -" );\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: groups.xml:298 -#, no-c-format -msgid "" -"Group conversions can be used everywhere @Valid can " -"be used, namely associations, method and constructor parameters and return " -"values. In order to specify multiple conversions @ConvertGroup." -"List can be used." -msgstr "" - -#. Tag: para -#: groups.xml:303 -#, no-c-format -msgid "However, there are several restrictionsas well :" -msgstr "" - -#. Tag: para -#: groups.xml:305 -#, no-c-format -msgid "" -"@ConvertGroup must be used in combination with " -"@Valid. If used without a " -"ConstraintDeclarationException is thrown." -msgstr "" - -#. Tag: para -#: groups.xml:312 -#, no-c-format -msgid "" -"It is not legal to have multiple conversion rules on the same element with " -"the same from value. In this case, a " -"ConstraintDeclarationException is raised." -msgstr "" - -#. Tag: para -#: groups.xml:319 -#, no-c-format -msgid "" -"The from attribute cannot refer to a group sequence. " -"A ConstraintDeclarationException is raised in this " -"situation." -msgstr "" - -#. Tag: para -#: groups.xml:325 -#, no-c-format -msgid "" -"Rules are not executed recursively. The first matching conversion rule is " -"used and subsequent rules are ignored. For example if a set of " -"@ConvertGroup declarations chains group A to B and B " -"to C, the group A will be converted to B and not to C." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/integration.po b/documentation/src/main/docbook/zh-CN/modules/integration.po deleted file mode 100644 index c418dcf956..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/integration.po +++ /dev/null @@ -1,542 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2010-08-23 00:37+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: integration.xml:24 -#, fuzzy, no-c-format -msgid "Integrating with other frameworks" -msgstr "与其他框架集成" - -#. Tag: para -#: integration.xml:26 -#, no-c-format -msgid "" -"Hibernate Validator is intended to be used to implement multi-layered data " -"validation, where constraints are expressed in a single place (the annotated " -"domain model) and checked in various different layers of the application." -msgstr "" -"Hibernate Validator 的设计初衷是在一个分层的应用程序中, 约束信息只需要被定义" -"一次( 通过在领域模型上标注), 然后在不同的层中进行数据校验." - -#. Tag: title -#: integration.xml:32 -#, no-c-format -msgid "OSGi" -msgstr "OSGi" - -#. Tag: para -#: integration.xml:34 -#, fuzzy, no-c-format -msgid "" -"The Hibernate Validator jar file is conform to the OSGi specification and " -"can be used within any OSGi container. The following lists represent the " -"packages imported and exported by Hibernate Validator. The classes within " -"the exported packages are considered part of Hibernate Validator public API." -msgstr "" -"Hibernate Validator 的jar文件符合OSGi的规范,所以能够被用在任何OSGi的容器当" -"中. 以下的包是Hibernate Validator 暴露出来的API:org.hibernate." -"validator, org.hibernate.validator.constraints, " -"org.hibernate.validator.messageinterpolation and " -"org.hibernate.validator.resourceloading." - -#. Tag: para -#: integration.xml:41 -#, no-c-format -msgid "" -"The Java Service Provider mechanism used by Bean Validation to automatically " -"discover validation providers doesn't work in an OSGi environment. To solve " -"this, you have to provide a custom ValidationProviderResolver (see )." -msgstr "" - -#. Tag: title -#: integration.xml:49 -#, no-c-format -msgid "Exported packages" -msgstr "" - -#. Tag: package -#: integration.xml:52 -#, no-c-format -msgid "org.hibernate.validator" -msgstr "" - -#. Tag: package -#: integration.xml:56 -#, no-c-format -msgid "org.hibernate.validator.cfg.*" -msgstr "" - -#. Tag: package -#: integration.xml:60 -#, no-c-format -msgid "org.hibernate.validator.constraints.*" -msgstr "" - -#. Tag: package -#: integration.xml:64 -#, no-c-format -msgid "org.hibernate.validator.group" -msgstr "" - -#. Tag: package -#: integration.xml:68 -#, no-c-format -msgid "org.hibernate.validator.messageinterpolation" -msgstr "" - -#. Tag: package -#: integration.xml:72 -#, no-c-format -msgid "org.hibernate.validator.resourceloading" -msgstr "" - -#. Tag: package -#: integration.xml:76 -#, no-c-format -msgid "org.hibernate.validator.spi.*" -msgstr "" - -#. Tag: title -#: integration.xml:81 -#, no-c-format -msgid "Imported packages" -msgstr "" - -#. Tag: para -#: integration.xml:84 -#, no-c-format -msgid "javax.persistence.*, [2.0.0,3.0.0), optional" -msgstr "" - -#. Tag: para -#: integration.xml:89 -#, no-c-format -msgid "javax.validation.*, [1.0.0,2.0.0)" -msgstr "" - -#. Tag: package -#: integration.xml:93 -#, no-c-format -msgid "javax.xml.*" -msgstr "" - -#. Tag: para -#: integration.xml:97 -#, no-c-format -msgid "javax.el.*, [2.0.0,4.0.0)" -msgstr "" - -#. Tag: package -#: integration.xml:101 -#, no-c-format -msgid "org.xml.sax.*" -msgstr "" - -#. Tag: para -#: integration.xml:105 -#, no-c-format -msgid "org.jboss.logging.*, [3.1.0,4.0.0)" -msgstr "" - -#. Tag: para -#: integration.xml:109 -#, no-c-format -msgid "com.fasterxml.classmate.*, 0.8.0" -msgstr "" - -#. Tag: para -#: integration.xml:113 -#, no-c-format -msgid "org.joda.time.*, [1.6.0,2.0.0), optional" -msgstr "" - -#. Tag: para -#: integration.xml:118 -#, no-c-format -msgid "org.jsoup.*, [1.5.2,2.0.0), optional" -msgstr "" - -#. Tag: title -#: integration.xml:124 -#, no-c-format -msgid "Database schema-level validation" -msgstr "与数据库集成校验" - -#. Tag: para -#: integration.xml:126 -#, no-c-format -msgid "" -"Out of the box, Hibernate Annotations (as of Hibernate 3.5.x) will translate " -"the constraints you have defined for your entities into mapping metadata. " -"For example, if a property of your entity is annotated @NotNull, its columns will be declared as not null in the " -"DDL schema generated by Hibernate." -msgstr "" -"Hibernate Annotations (即 Hibernate 3.5.x) 会自动的把你定已在实体模型上的约束" -"信息添加到其映射信息中. 例如, 假设你的一个实体类的属性上有@NotNull的约束的话, 那么Hibernate在生成创建此实体对应的表的DDL的时候, 会自动" -"的给那个属性对应的字段添加上not null." - -#. Tag: para -#: integration.xml:132 -#, fuzzy, no-c-format -msgid "" -"If, for some reason, the feature needs to be disabled, set " -"hibernate.validator.apply_to_ddl to false. See also and ." -msgstr "" -"如果因为某种原因, 你不想使用这个特性, 那么可以将hibernate.validator." -"apply_to_ddl属性设置为false. 请参考." - -#. Tag: para -#: integration.xml:138 -#, no-c-format -msgid "" -"You can also limit the DDL constraint generation to a subset of the defined " -"constraints by setting the property org.hibernate.validator.group." -"ddl. The property specifies the comma-separated, fully specified " -"class names of the groups a constraint has to be part of in order to be " -"considered for DDL schema generation." -msgstr "" -"你也可以限制这个DDL约束自动生成的特性只应用到一部分实体类. 只需要设置" -"org.hibernate.validator.group.ddl属性, 这个属性的值是你" -"想要应用此特性的实体类的全路径名称, 每个以逗号分隔." - -#. Tag: title -#: integration.xml:147 -#, no-c-format -msgid "ORM integration" -msgstr "ORM集成" - -#. Tag: para -#: integration.xml:149 -#, no-c-format -msgid "" -"Hibernate Validator integrates with both Hibernate and all pure Java " -"Persistence providers." -msgstr "" -"Hibernate Validator不仅能够和Hibernate集成工作, 还能够和任何JPA的实现很好的一" -"起工作." - -#. Tag: para -#: integration.xml:153 -#, no-c-format -msgid "" -"When lazy loaded associations are supposed to be validated it is recommended " -"to place the constraint on the getter of the association. Hibernate replaces " -"lazy loaded associations with proxy instances which get initialized/loaded " -"when requested via the getter. If, in such a case, the constraint is placed " -"on field level the actual proxy instance is used which will lead to " -"validation errors." -msgstr "" - -#. Tag: title -#: integration.xml:162 -#, no-c-format -msgid "Hibernate event-based validation" -msgstr "基于Hibernate事件模型的校验" - -#. Tag: para -#: integration.xml:164 -#, no-c-format -msgid "" -"Hibernate Validator has a built-in Hibernate event listener - org.hibernate.cfg.beanvalidation.BeanValidationEventListener - which is part of Hibernate Annotations (as of Hibernate " -"3.5.x). Whenever a PreInsertEvent, " -"PreUpdateEvent or PreDeleteEvent " -"occurs, the listener will verify all constraints of the entity instance and " -"throw an exception if any constraint is violated. Per default objects will " -"be checked before any inserts or updates are made by Hibernate. Pre deletion " -"events will per default not trigger a validation. You can configure the " -"groups to be validated per event type using the properties javax." -"persistence.validation.group.pre-persist, javax." -"persistence.validation.group.pre-update and javax." -"persistence.validation.group.pre-remove. The values of these " -"properties are the comma-separated, fully specified class names of the " -"groups to validate. shows the default values for these properties. In this case they " -"could also be omitted." -msgstr "" -"Hibernate Annotations (即 Hibernate 3.5.x) 中包含了一个的Hibernate 事件监听器" -"(译注: 请阅读Hibernate Core文档了解Hibernate的事件模型) - org.hibernate.cfg.beanvalidation.BeanValidationEventListener - 来为Hibernate Validator服务. 当一个" -"PreInsertEvent, PreUpdateEvent 或 " -"PreDeleteEvent事件发生的时候, 这个监听器就可以对该事件" -"所涉及到的实体对象进行校验, 如果校验不通过的话, 则抛出异常. 默认情况下, " -"Hibernate在对每个对象进行保存或者修改操作的时候,都会对其进行校验, 而删除操作" -"则不会. 你可以通过javax.persistence.validation.group.pre-persist, javax.persistence.validation.group.pre-updatejavax.persistence.validation.group.pre-remove属性来定义对应事件发生的时候, 具体要校验哪(些)个校验组, 这个属性的值" -"是要应用的校验组类的全路径, 使用逗号分隔. 显示了这几个属性在Hibernate内部定义的默" -"认值, 所以, 你不需要在你的应用中再重复定义了." - -#. Tag: para -#: integration.xml:185 -#, no-c-format -msgid "" -"On constraint violation, the event will raise a runtime " -"ConstraintViolationException which contains a set of " -"ConstraintViolations describing each failure." -msgstr "" -"如果发生了违反约束条件的情况, 该监听器会抛出一个运行时的" -"ConstraintViolationException异常, 此异常包含了一系列的" -"ConstraintViolation对象用于描述每个违反了约束条件的情况." - -#. Tag: para -#: integration.xml:190 -#, no-c-format -msgid "" -"If Hibernate Validator is present in the classpath, Hibernate Annotations " -"(or Hibernate EntityManager) will use it transparently. To avoid validation " -"even though Hibernate Validator is in the classpath set javax." -"persistence.validation.mode to none." -msgstr "" -"如果类路径上有Hibernate Validator, 则Hibernate Annotations (或 Hibernate " -"EntityManager)会自动调用它, 如果你想避免这种情况, 可以设置javax." -"persistence.validation.mode属性为none." - -#. Tag: para -#: integration.xml:197 -#, no-c-format -msgid "" -"If the beans are not annotated with validation annotations, there is no " -"runtime performance cost." -msgstr "如果实体模型上没有定义约束条件, 则不会有任何性能损耗." - -#. Tag: para -#: integration.xml:201 -#, no-c-format -msgid "" -"In case you need to manually set the event listeners for Hibernate Core, use " -"the following configuration in hibernate.cfg.xml:" -msgstr "" -"如果你想在Hibernate Core中使用上面提到的事件监听器, 则可以在" -"hibernate.cfg.xml中定义如下的配置信息:" - -#. Tag: title -#: integration.xml:206 -#, no-c-format -msgid "" -"Manual configuration of BeanValidationEvenListener" -msgstr "自定义BeanValidationEvenListener" - -#. Tag: programlisting -#: integration.xml:209 -#, no-c-format -msgid "" -"<hibernate-configuration>\n" -" <session-factory>\n" -" ...\n" -" <property name=\"javax.persistence.validation.group.pre-persist" -"\">javax.validation.groups.Default</property>\n" -" <property name=\"javax.persistence.validation.group.pre-update" -"\">javax.validation.groups.Default</property>\n" -" <property name=\"javax.persistence.validation.group.pre-remove" -"\"></property>\n" -" ...\n" -" <event type=\"pre-update\">\n" -" <listener class=\"org.hibernate.cfg.beanvalidation." -"BeanValidationEventListener\"/>\n" -" </event>\n" -" <event type=\"pre-insert\">\n" -" <listener class=\"org.hibernate.cfg.beanvalidation." -"BeanValidationEventListener\"/>\n" -" </event>\n" -" <event type=\"pre-delete\">\n" -" <listener class=\"org.hibernate.cfg.beanvalidation." -"BeanValidationEventListener\"/>\n" -" </event>\n" -" </session-factory>\n" -"</hibernate-configuration>" -msgstr "" -"<hibernate-configuration>\n" -" <session-factory>\n" -" ...\n" -" <property name=\"javax.persistence.validation.group.pre-persist" -"\">javax.validation.groups.Default</property>\n" -" <property name=\"javax.persistence.validation.group.pre-update" -"\">javax.validation.groups.Default</property>\n" -" <property name=\"javax.persistence.validation.group.pre-remove" -"\"></property>\n" -" ...\n" -" <event type=\"pre-update\">\n" -" <listener class=\"org.hibernate.cfg.beanvalidation." -"BeanValidationEventListener\"/>\n" -" </event>\n" -" <event type=\"pre-insert\">\n" -" <listener class=\"org.hibernate.cfg.beanvalidation." -"BeanValidationEventListener\"/>\n" -" </event>\n" -" <event type=\"pre-delete\">\n" -" <listener class=\"org.hibernate.cfg.beanvalidation." -"BeanValidationEventListener\"/>\n" -" </event>\n" -" </session-factory>\n" -"</hibernate-configuration>" - -#. Tag: title -#: integration.xml:214 -#, no-c-format -msgid "JPA" -msgstr "JPA" - -#. Tag: para -#: integration.xml:216 -#, fuzzy, no-c-format -msgid "" -"If you are using JPA 2 and Hibernate Validator is in the classpath the JPA2 " -"specification requires that Bean Validation gets enabled. The properties " -"javax.persistence.validation.group.pre-persist, " -"javax.persistence.validation.group.pre-update and " -"javax.persistence.validation.group.pre-remove as " -"described in can in this case be configured in persistence.xml. " -"persistence.xml also defines a node validation-mode " -"which can be set to AUTO, CALLBACK, NONE. The default is AUTO." -msgstr "" -"如果你是把Hibernate Validator和JPA2一起使用, 那么中所说的javax.persistence." -"validation.group.pre-persist, javax.persistence." -"validation.group.pre-updatejavax.persistence." -"validation.group.pre-remove需要定义在persistence.xml中. 并且, persistence.xml中还包含了一个" -"validation-mode的节点可以被设置成AUTO, " -"CALLBACK, NONE, 默认值是" -"AUTO." - -#. Tag: para -#: integration.xml:230 -#, no-c-format -msgid "" -"In a JPA 1 you will have to create and register Hibernate Validator " -"yourself. In case you are using Hibernate EntityManager you can add a " -"customized version of the BeanValidationEventListener " -"described in to your project and register it manually." -msgstr "" -"对于JPA1来讲, 你需要自己创建和注册Hibernate Validator. 如果你是使用Hibernate " -"EntityManager, 那么你可以把中列出来的BeanValidationEventListener类添加到你的项目中, 然后再手工注册它." - -#. Tag: title -#: integration.xml:240 -#, no-c-format -msgid "Presentation layer validation" -msgstr "展示层校验" - -#. Tag: para -#: integration.xml:242 -#, no-c-format -msgid "" -"When working with JSF2 or JBoss Seam and " -"Hibernate Validator (Bean Validation) is present in the runtime environment " -"validation is triggered for every field in the application. shows an example of the f:validateBean tag in a JSF page. " -"For more information refer to the Seam documentation or the JSF 2 " -"specification." -msgstr "" -"如果你正在使用JSF2或者JBoss Seam,并且Hibernate " -"Validator (Bean Validation) 在类路径上的话, 那么界面上的字段可以被自动校验. " -"显示了一个在JSF页面上使用f:validateBean标签的" -"实例. 更多的信息请参考Seam的文档或者JSF2规范." - -#. Tag: title -#: integration.xml:250 -#, no-c-format -msgid "Usage of Bean Validation within JSF2" -msgstr "在JSF2中使用Bean Validation" - -#. Tag: programlisting -#: integration.xml:252 -#, no-c-format -msgid "" -"<h:form>\n" -" <f:validateBean>\n" -" <h:inputText value=”#{model.property}” />\n" -" <h:selectOneRadio value=”#{model.radioProperty}” > ... </h:" -"selectOneRadio>\n" -" <!-- other input components here -->\n" -" </f:validateBean>\n" -"</h:form>" -msgstr "" -"<h:form>\n" -" <f:validateBean>\n" -" <h:inputText value=”#{model.property}” />\n" -" <h:selectOneRadio value=”#{model.radioProperty}” > ... </h:" -"selectOneRadio>\n" -" <!-- other input components here -->\n" -" </f:validateBean>\n" -"</h:form>" - -#. Tag: para -#: integration.xml:256 -#, no-c-format -msgid "" -"The integration between JSF 2 and Bean Validation is described in the \"Bean " -"Validation Integration\" chapter of JSR-314. It is interesting to know that JSF 2 " -"implements a custom MessageInterpolator to ensure ensure proper " -"localization. To encourage the use of the Bean Validation message facility, " -"JSF 2 will per default only display the generated Bean Validation message. " -"This can, however, be configured via the application resource bundle by " -"providing the following configuration ({0} is " -"replaced with the Bean Validation message and {1} is " -"replaced with the JSF component label):" -msgstr "" - -#. Tag: programlisting -#: integration.xml:268 -#, no-c-format -msgid "javax.faces.validator.BeanValidator.MESSAGE={1}: {0}" -msgstr "" - -#. Tag: para -#: integration.xml:270 -#, no-c-format -msgid "The default is:" -msgstr "" - -#. Tag: programlisting -#: integration.xml:272 -#, no-c-format -msgid "javax.faces.validator.BeanValidator.MESSAGE={0}" -msgstr "" - -#. Tag: title -#: integration.xml:277 -#, fuzzy, no-c-format -msgid "CDI" -msgstr "JPA" - -#. Tag: para -#: integration.xml:279 -#, no-c-format -msgid "TODO" -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/message-interpolation.po b/documentation/src/main/docbook/zh-CN/modules/message-interpolation.po deleted file mode 100644 index 000fcee251..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/message-interpolation.po +++ /dev/null @@ -1,583 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: message-interpolation.xml:24 -#, no-c-format -msgid "Message interpolation" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:26 -#, no-c-format -msgid "" -"Message interpolation is the process of creating error messages for violated " -"Bean Validation constraints. In this chapter you will learn how such " -"messages are defined and resolved and how you can plug in custom message " -"interpolators in case the default algorithm is not sufficient for your " -"requirements." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:33 -#, no-c-format -msgid "Default message interpolation" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:35 -#, no-c-format -msgid "" -"Constraint violation messages are retrieved from so called message " -"descriptors. Each constraint defines its default message descriptor using " -"the message attribute. At declaration time, the " -"default descriptor can be overridden with a specific value as shown in ." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:42 -#, no-c-format -msgid "" -"Specifying a message descriptor using the message " -"attribute" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:45 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter04;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull(message = \"The manufacturer name must not be null\")\n" -" private String manufacturer;\n" -"\n" -" //constructor, getters and setters ...\n" -"}" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:48 -#, no-c-format -msgid "" -"If a constraint is violated, its descriptor will be interpolated by the " -"runtime using the currently configured MessageInterpolator. The interpolated error message can then be retrieved from the " -"resulting constraint violation by calling " -"ConstraintViolation#getMessage()." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:54 -#, no-c-format -msgid "" -"Message descriptors can contain message parameters as " -"well as message expressions which will be resolved " -"during interpolation. Message parameters are string literals enclosed in " -"{}, while message expressions are string literals " -"enclosed in ${}. The following algorithm is applied " -"during method interpolation:" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:63 -#, no-c-format -msgid "" -"Resolve any message parameters by using them as key for the resource bundle " -"ValidationMessages. If this bundle contains an entry " -"for a given message parameter, that parameter will be replaced in the " -"message with the corresponding value from the bundle. This step will be " -"executed recursively if the replaced value again contains message " -"parameters. The resource bundle is expected to be provided by the " -"application developer, e.g. by adding a file named " -"ValidationMessages.properties to the classpath. You can " -"also create localized error messages by providing locale specific variations " -"of this bundle, such as ValidationMessages_en_US.properties. By default, the JVM's default locale " -"(Locale#getDefault()) will be used when looking up " -"messages in the bundle." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:80 -#, no-c-format -msgid "" -"Resolve any message parameters by using them as key for a resource bundle " -"containing the standard error messages for the built-in constraints as " -"defined in Appendix B of the Bean Validation specification. In the case of " -"Hibernate Validator, this bundle is named org.hibernate.validator." -"ValidationMessages. If this step triggers a replacement, step 1 " -"is executed again, otherwise step 3 is applied." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:91 -#, no-c-format -msgid "" -"Resolve any message parameters by replacing them with the value of the " -"constraint annotation member of the same name. This allows to refer to " -"attribute values of the constraint (e.g. Size#min()) in the error message (e.g. \"must be at least ${min}\")." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:99 -#, no-c-format -msgid "" -"Resolve any message expressions by evaluating them as expressions of the " -"Unified Expression Language. See to learn more about the usage of Unified EL in error " -"messages." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:107 -#, no-c-format -msgid "" -"You can find the formal definition of the interpolation algorithm in section " -"5.3.1.1 of the Bean Validation specification." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:114 -#, no-c-format -msgid "Special characters" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:116 -#, no-c-format -msgid "" -"Since the characters {, } and " -"$ have a special meaning in message descriptors they need to be " -"escaped if you want to use them literally. The following rules apply:" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:121 -#, no-c-format -msgid "" -"\\{ is considered as the literal " -"{" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:126 -#, no-c-format -msgid "" -"\\} is considered as the literal }" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:131 -#, no-c-format -msgid "" -"\\$ is considered as the literal $" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:136 -#, no-c-format -msgid "" -"\\\\ is considered as the literal \\" -msgstr "" - -#. Tag: title -#: message-interpolation.xml:143 -#, no-c-format -msgid "Interpolation with message expressions" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:145 -#, no-c-format -msgid "" -"Since Bean Validation 1.1 / Hibernate Validator 5 it is possible to use the " -"Unified Expression Language (as defined by JSR 341) in constraint violation messages. This " -"allows to define error messages based on conditional logic and also enables " -"advanced formatting options. The validation engine makes the following " -"objects available in the EL context:" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:155 -#, no-c-format -msgid "the attribute values of the constraint mapped to the attribute names" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:160 -#, no-c-format -msgid "" -"the currently validated value (property, bean, method parameter etc.) under " -"the name validatedValue" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:166 -#, no-c-format -msgid "" -"a bean mapped to the name formatter exposing the var-arg " -"method format(String format, Object... args) which " -"behaves like java.util.Formatter.format(String format, Object... " -"args)." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:174 -#, no-c-format -msgid "" -"The following section provides several examples for using EL expressions in " -"error messages." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:179 -#, no-c-format -msgid "Examples" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:181 -#, no-c-format -msgid "" -"shows how to make use of the different options for specifying message " -"descriptors." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:185 -#, no-c-format -msgid "Specifying message descriptors" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:187 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter04.complete;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @Size(\n" -" min = 2,\n" -" max = 14,\n" -" message = \"The license plate must be between {min} " -"and {max} characters long\"\n" -" )\n" -" private String licensePlate;\n" -"\n" -" @Min(\n" -" value = 2,\n" -" message = \"There must be at least {value} seat" -"${value > 1 ? 's' : ''}\"\n" -" )\n" -" private int seatCount;\n" -"\n" -" @DecimalMax(\n" -" value = \"350\",\n" -" message = \"The top speed ${formatter.format" -"('%1$.2f', validatedValue)} is higher \" +\n" -" \"than {value}\"\n" -" )\n" -" private double topSpeed;\n" -"\n" -" @DecimalMax(value = \"100000\", message = \"Price must not be higher " -"than ${value}\")\n" -" private BigDecimal price;\n" -"\n" -" public Car(\n" -" String manufacturer,\n" -" String licensePlate,\n" -" int seatCount,\n" -" double topSpeed,\n" -" BigDecimal price) {\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licensePlate;\n" -" this.seatCount = seatCount;\n" -" this.topSpeed = topSpeed;\n" -" this.price = price;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:190 -#, no-c-format -msgid "" -"Validating an invalid Car instance yields constraint " -"violations with the messages shown by the assertions in :" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:196 -#, no-c-format -msgid "" -"the @NotNull constraint on the manufacturer field causes the error message \"may not be null\", as this is the " -"default message defined by the Bean Validation specification and no specific " -"descriptor is given in the message attribute" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:204 -#, no-c-format -msgid "" -"the @Size constraint on the licensePlate field shows the interpolation of message parameters ({min}" -", {max})" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:211 -#, no-c-format -msgid "" -"the @Min constraint on seatCount " -"demonstrates how use an EL expression with a ternery expression to " -"dynamically chose singular or plural form, depending on an attribute of the " -"constraint (\"There must be at least 1 seat\" vs. \"There must be at least 2 " -"seats\")" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:219 -#, no-c-format -msgid "" -"the message for the @DecimalMax constraint on " -"topSpeed shows how to refer to the validated object in " -"the error message and format it using the formatter object" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:226 -#, no-c-format -msgid "" -"finally, the @DecimalMax constraint on " -"price shows that parameter interpolation has precedence " -"over expression evaluation, causing the $ sign to show up " -"in front of the maximum price" -msgstr "" - -#. Tag: title -#: message-interpolation.xml:235 -#, no-c-format -msgid "Expected error messages" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:237 -#, no-c-format -msgid "" -"Car car = new Car( null, \"A\", 1, 400.123456, BigDecimal.valueOf" -"( 200000 ) );\n" -"\n" -"String message = validator.validateProperty( car, \"manufacturer\" )\n" -" .iterator()\n" -" .next()\n" -" .getMessage();\n" -"assertEquals( \"may not be null\", message );\n" -"\n" -"message = validator.validateProperty( car, \"licensePlate\" )\n" -" .iterator()\n" -" .next()\n" -" .getMessage();\n" -"assertEquals(\n" -" \"The license plate must be between 2 and 14 characters long" -"\",\n" -" message\n" -");\n" -"\n" -"message = validator.validateProperty( car, \"seatCount\" ).iterator().next()." -"getMessage();\n" -"assertEquals( \"There must be at least 2 seats\", message );\n" -"\n" -"message = validator.validateProperty( car, \"topSpeed\" ).iterator().next()." -"getMessage();\n" -"assertEquals( \"The top speed 400.12 is higher than 350\", message );\n" -"\n" -"message = validator.validateProperty( car, \"price\" ).iterator().next()." -"getMessage();\n" -"assertEquals( \"Price must not be higher than $100000\", message );" -msgstr "" - -#. Tag: title -#: message-interpolation.xml:243 -#, no-c-format -msgid "Custom message interpolation" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:245 -#, no-c-format -msgid "" -"If the default message interpolation algorithm does not fit your " -"requirements it is also possible to plug in a custom " -"MessageInterpolator implementation." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:249 -#, no-c-format -msgid "" -"Custom interpolators must implement the interface javax." -"validation.MessageInterpolator. Note that implementations must " -"be thread-safe. It is recommended that custom message interpolators delegate " -"final implementation to the runtime's default interpolator, which can be " -"obtained via Configuration#getDefaultMessageInterpolator()." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:256 -#, no-c-format -msgid "" -"In order to use a custom message interpolator it must be registered with the " -"validation runtime. You can do this by either configuring it in the Bean " -"Validation XML descriptor META-INF/validation.xml (see " -") or passing it when " -"bootstrapping a ValidatorFactory or " -"Validator (see and , respectively)." -msgstr "" - -#. Tag: classname -#: message-interpolation.xml:267 -#, no-c-format -msgid "ResourceBundleLocator" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:269 -#, no-c-format -msgid "" -"It is a common case that you want to use the message interpolation algorithm " -"as defined by the Bean Validation specification but retrieve error messages " -"from other resource bundles than ValidationMessages. In " -"this situation Hibernate Validator's ResourceBundleLocator SPI can help." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:276 -#, no-c-format -msgid "" -"The default message interpolator in Hibernate Validator, " -"ResourceBundleMessageInterpolator, delegates " -"retrieval of resource bundles to that SPI. Using an alternative bundle only " -"requires passing an instance of PlatformResourceBundleLocator with the bundle name when bootstrapping the " -"ValidatorFactory as shown in ." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:286 -#, no-c-format -msgid "Using a specific resource bundle" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:288 -#, no-c-format -msgid "" -"Validator validator = Validation.byDefaultProvider()\n" -" .configure()\n" -" .messageInterpolator(\n" -" new ResourceBundleMessageInterpolator(\n" -" new " -"PlatformResourceBundleLocator( \"MyMessages\" )\n" -" )\n" -" )\n" -" .buildValidatorFactory()\n" -" .getValidator();" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:291 -#, no-c-format -msgid "" -"Of course you also could implement a completely different " -"ResourceBundleLocator, which for instance returns " -"bundles backed by records in a database. In this case you can obtain the " -"default locator via " -"HibernateValidatorConfiguration#getDefaultResourceBundleLocator()" -", which you e.g. could use as fallback for your custom locator." -msgstr "" - -#. Tag: para -#: message-interpolation.xml:298 -#, no-c-format -msgid "" -"Besides PlatformResourceBundleLocator, Hibernate " -"Validator provides another resource bundle locator implementation out of the " -"box, namely AggregateResourceBundleLocator, which " -"allows to retrieve error messages from more than one resource bundle. You " -"could for instance use this implementation in a multi-module application " -"where you want to have one message bundle per module. shows how to use " -"AggregateResourceBundleLocator." -msgstr "" - -#. Tag: title -#: message-interpolation.xml:309 -#, no-c-format -msgid "Using AggregateResourceBundleLocator" -msgstr "" - -#. Tag: programlisting -#: message-interpolation.xml:312 -#, no-c-format -msgid "" -"Validator validator = Validation.byDefaultProvider()\n" -" .configure()\n" -" .messageInterpolator(\n" -" new ResourceBundleMessageInterpolator(\n" -" new " -"AggregateResourceBundleLocator(\n" -" Arrays.asList" -"(\n" -" \"MyMessages" -"\",\n" -" \"MyOtherMessages" -"\"\n" -" )\n" -" )\n" -" )\n" -" )\n" -" .buildValidatorFactory()\n" -" .getValidator();" -msgstr "" - -#. Tag: para -#: message-interpolation.xml:315 -#, no-c-format -msgid "" -"Note that the bundles are processed in the order as passed to the " -"constructor. That means if several bundles contain an entry for a given " -"message key, the value will be taken from the first bundle in the list " -"containing the key." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/metadata-api.po b/documentation/src/main/docbook/zh-CN/modules/metadata-api.po deleted file mode 100644 index b28571c7ef..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/metadata-api.po +++ /dev/null @@ -1,932 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: metadata-api.xml:24 -#, no-c-format -msgid "Metadata API" -msgstr "" - -#. Tag: para -#: metadata-api.xml:26 -#, no-c-format -msgid "" -"The Bean Validation specification provides not only a validation engine, but " -"also an API for retrieving constraint metadata in a uniform way, no matter " -"whether the constraints are declared using annotations or via XML mappings. " -"We'll have a closer look at this API and its possibilities in the following " -"sections. All the introduced API types can be found in the javax." -"validation.metadata package." -msgstr "" - -#. Tag: para -#: metadata-api.xml:33 -#, no-c-format -msgid "" -"The examples presented in this chapter are based on the classes and " -"constraint declarations shown in ." -msgstr "" - -#. Tag: title -#: metadata-api.xml:38 -#, no-c-format -msgid "Example classes" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:40 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter07;\n" -"\n" -"public class Person {\n" -"\n" -" public interface Basic {\n" -" }\n" -"\n" -" @NotNull\n" -" private String name;\n" -"\n" -" //getters and setters ...\n" -"}" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:42 -#, no-c-format -msgid "" -"public interface Vehicle {\n" -"\n" -" public interface Basic {\n" -" }\n" -"\n" -" @NotNull(groups = Vehicle.Basic.class)\n" -" String getManufacturer();\n" -"}" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:44 -#, no-c-format -msgid "" -"@ValidCar\n" -"public class Car implements Vehicle {\n" -"\n" -" public interface SeverityInfo extends Payload {\n" -" }\n" -"\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" private String licensePlate;\n" -"\n" -" private Person driver;\n" -"\n" -" private String modelName;\n" -"\n" -" public Car() {\n" -" }\n" -"\n" -" public Car(\n" -" @NotNull String manufacturer,\n" -" String licencePlate,\n" -" Person driver,\n" -" String modelName) {\n" -"\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.driver = driver;\n" -" this.modelName = modelName;\n" -" }\n" -"\n" -" public void driveAway(@Max(75) int speed) {\n" -" //...\n" -" }\n" -"\n" -" @LuggageCountMatchesPassengerCount(\n" -" piecesOfLuggagePerPassenger = 2,\n" -" validationAppliesTo = ConstraintTarget.PARAMETERS,\n" -" payload = SeverityInfo.class,\n" -" message = \"There must not be more than " -"{piecesOfLuggagePerPassenger} pieces of \" +\n" -" \"luggage per passenger.\"\n" -" )\n" -" public void load(List<Person> passengers, List<" -"PieceOfLuggage> luggage) {\n" -" //...\n" -" }\n" -"\n" -" @Override\n" -" @Size(min = 3)\n" -" public String getManufacturer() {\n" -" return manufacturer;\n" -" }\n" -"\n" -" public void setManufacturer(String manufacturer) {\n" -" this.manufacturer = manufacturer;\n" -" }\n" -"\n" -" @Valid\n" -" @ConvertGroup(from = Default.class, to = Person.Basic.class)\n" -" public Person getDriver() {\n" -" return driver;\n" -" }\n" -"\n" -" //further getters and setters...\n" -"}" -msgstr "" - -#. Tag: classname -#: metadata-api.xml:49 -#, no-c-format -msgid "BeanDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:51 -#, no-c-format -msgid "" -"The entry point into the metadata API is the method Validator." -"getConstraintsForClass(), which returns an instance of the BeanDescriptor interface. Using this descriptor, you can obtain metadata " -"for constraints declared directly on the bean itself (class- or property-" -"level), but also retrieve metadata descriptors representing single " -"properties, methods and constructors." -msgstr "" - -#. Tag: para -#: metadata-api.xml:60 -#, no-c-format -msgid "" -"demonstrates how to retrieve a BeanDescriptor for the " -"Car class and how to use this descriptor in form of " -"assertions." -msgstr "" - -#. Tag: para -#: metadata-api.xml:66 -#, no-c-format -msgid "" -"If a constraint declaration hosted by the requested class is invalid, a " -"ValidationException is thrown." -msgstr "" - -#. Tag: title -#: metadata-api.xml:72 -#, no-c-format -msgid "Using BeanDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:74 -#, no-c-format -msgid "" -"Validator validator = Validation.buildDefaultValidatorFactory().getValidator" -"();\n" -"\n" -"BeanDescriptor carDescriptor = validator.getConstraintsForClass( Car." -"class );\n" -"\n" -"assertTrue( carDescriptor.isBeanConstrained() );\n" -"\n" -"//one class-level constraint\n" -"assertEquals( 1, carDescriptor.getConstraintDescriptors().size() );\n" -"\n" -"//manufacturer, licensePlate, driver\n" -"assertEquals( 3, carDescriptor.getConstrainedProperties().size() );\n" -"\n" -"//property has constraint\n" -"assertNotNull( carDescriptor.getConstraintsForProperty( \"licensePlate" -"\" ) );\n" -"\n" -"//property is marked with @Valid\n" -"assertNotNull( carDescriptor.getConstraintsForProperty( \"driver\" ) );\n" -"\n" -"//constraints from getter method in interface and implementation class are " -"returned\n" -"assertEquals(\n" -" 2,\n" -" carDescriptor.getConstraintsForProperty( \"manufacturer\" )\n" -" .getConstraintDescriptors()\n" -" .size()\n" -");\n" -"\n" -"//property is not constrained\n" -"assertNull( carDescriptor.getConstraintsForProperty( \"modelName\" ) );\n" -"\n" -"//driveAway(int), load(List<Person>, List<PieceOfLuggage>)\n" -"assertEquals( 2, carDescriptor.getConstrainedMethods( MethodType." -"NON_GETTER ).size() );\n" -"\n" -"//driveAway(int), getManufacturer(), getDriver(), load(List<Person>, " -"List<PieceOfLuggage>)\n" -"assertEquals(\n" -" 4,\n" -" carDescriptor.getConstrainedMethods( MethodType.NON_GETTER, " -"MethodType.GETTER )\n" -" .size()\n" -");\n" -"\n" -"//driveAway(int)\n" -"assertNotNull( carDescriptor.getConstraintsForMethod( \"driveAway\", int." -"class ) );\n" -"\n" -"//getManufacturer()\n" -"assertNotNull( carDescriptor.getConstraintsForMethod( \"getManufacturer" -"\" ) );\n" -"\n" -"//setManufacturer() is not constrained\n" -"assertNull( carDescriptor.getConstraintsForMethod( \"setManufacturer\", " -"String.class ) );\n" -"\n" -"//Car(String, String, Person, String)\n" -"assertEquals( 1, carDescriptor.getConstrainedConstructors().size() );\n" -"\n" -"//Car(String, String, Person, String)\n" -"assertNotNull(\n" -" carDescriptor.getConstraintsForConstructor(\n" -" String.class,\n" -" String.class,\n" -" Person.class,\n" -" String.class\n" -" )\n" -");" -msgstr "" - -#. Tag: para -#: metadata-api.xml:77 -#, no-c-format -msgid "" -"You can determine whether the specified class hosts any class- or property-" -"level constraints via isBeanConstrained(). Method or " -"constructor constraints are not considered by isBeanConstrained()" -"." -msgstr "" - -#. Tag: para -#: metadata-api.xml:82 -#, no-c-format -msgid "" -"The method getConstraintDescriptors() is common to all " -"descriptors derived from ElementDescriptor (see ) and returns a set of " -"descriptors representing the constraints directly declared on the given " -"element. In case of BeanDescriptor, the bean's class-" -"level constraints are returned. More details on " -"ConstraintDescriptor can be found in ." -msgstr "" - -#. Tag: para -#: metadata-api.xml:91 -#, no-c-format -msgid "" -"Via getConstraintsForProperty(), " -"getConstraintsForMethod() and " -"getConstraintsForConstructor() you can obtain a " -"descriptor representing one given property or executable element, identified " -"by its name and, in case of methods and constructors, parameter types. The " -"different descriptor types returned by these methods are described in the " -"following sections." -msgstr "" - -#. Tag: para -#: metadata-api.xml:99 -#, no-c-format -msgid "" -"Note that these methods consider constraints declared at super-types " -"according to the rules for constraint inheritance as described in TODO. An " -"example is the descriptor for the manufacturer property, " -"which provides access to all constraints defined on " -"Vehicle#getManufacturer() and the implementing " -"method Car#getManufacturer(). null is returned in case the specified element does not exist or is not " -"constrained." -msgstr "" - -#. Tag: para -#: metadata-api.xml:108 -#, no-c-format -msgid "" -"The methods getConstrainedProperties(), " -"getConstrainedMethods() and " -"getConstrainedConstructors() return (potentially " -"empty) sets with all constrained properties, methods and constructors, " -"respectively. An element is considered constrained, if it has at least one " -"constraint or is marked for cascaded validation. When invoking " -"getConstrainedMethods(), you can specify the type " -"of the methods to be returned (getters, non-getters or both)." -msgstr "" - -#. Tag: classname -#: metadata-api.xml:119 -#, no-c-format -msgid "PropertyDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:121 -#, no-c-format -msgid "" -"The interface PropertyDescriptor represents one given " -"property of a class. It is transparent whether constraints are declared on a " -"field or a property getter, provided the JavaBeans naming conventions are " -"respected. " -"shows how to use the PropertyDescriptor interface." -msgstr "" - -#. Tag: title -#: metadata-api.xml:130 -#, no-c-format -msgid "Using PropertyDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:132 -#, no-c-format -msgid "" -"PropertyDescriptor licensePlateDescriptor = carDescriptor." -"getConstraintsForProperty(\n" -" \"licensePlate\"\n" -");\n" -"\n" -"//\"licensePlate\" has two constraints, is not marked with @Valid and " -"defines no group conversions\n" -"assertEquals( \"licensePlate\", licensePlateDescriptor.getPropertyName() );\n" -"assertEquals( 2, licensePlateDescriptor.getConstraintDescriptors().size" -"() );\n" -"assertTrue( licensePlateDescriptor.hasConstraints() );\n" -"assertFalse( licensePlateDescriptor.isCascaded() );\n" -"assertTrue( licensePlateDescriptor.getGroupConversions().isEmpty() );\n" -"\n" -"PropertyDescriptor driverDescriptor = carDescriptor.getConstraintsForProperty" -"( \"driver\" );\n" -"\n" -"//\"driver\" has no constraints, is marked with @Valid and defines one group " -"conversion\n" -"assertEquals( \"driver\", driverDescriptor.getPropertyName() );\n" -"assertTrue( driverDescriptor.getConstraintDescriptors().isEmpty() );\n" -"assertFalse( driverDescriptor.hasConstraints() );\n" -"assertTrue( driverDescriptor.isCascaded() );\n" -"assertEquals( 1, driverDescriptor.getGroupConversions().size() );" -msgstr "" - -#. Tag: para -#: metadata-api.xml:135 -#, no-c-format -msgid "" -"Using getConstrainedDescriptors(), you can retrieve " -"a set of ConstraintDescriptors providing more " -"information on the individual constraints of a given property. The method " -"isCascaded() returns true, if " -"the property is marked for cascaded validation (either using the " -"@Valid annotation or via XML), false otherwise. Any configured group conversions are returned by " -"getGroupConversions(). See for more details on " -"GroupConversionDescriptor." -msgstr "" - -#. Tag: title -#: metadata-api.xml:148 -#, no-c-format -msgid "MethodDescriptor and ConstructorDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:150 -#, no-c-format -msgid "" -"Constrained methods and constructors (together referred to as \"executables" -"\" in the following) are represented by the interfaces MethodDescriptor and ConstructorDescriptor, respectively. demonstrates how to work with these " -"descriptors." -msgstr "" - -#. Tag: title -#: metadata-api.xml:160 -#, no-c-format -msgid "" -"Using MethodDescriptor and " -"ConstructorDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:163 -#, no-c-format -msgid "" -"//driveAway(int) has a constrained parameter and an unconstrained return " -"value\n" -"MethodDescriptor driveAwayDescriptor = carDescriptor.getConstraintsForMethod" -"(\n" -" \"driveAway\",\n" -" int.class\n" -");\n" -"assertEquals( \"driveAway\", driveAwayDescriptor.getName() );\n" -"assertTrue( driveAwayDescriptor.hasConstrainedParameters() );\n" -"assertFalse( driveAwayDescriptor.hasConstrainedReturnValue() );\n" -"\n" -"//always returns an empty set; constraints are retrievable by navigating to\n" -"//one of the sub-descriptors, e.g. for the return value\n" -"assertTrue( driveAwayDescriptor.getConstraintDescriptors().isEmpty() );\n" -"\n" -"ParameterDescriptor speedDescriptor = driveAwayDescriptor." -"getParameterDescriptors()\n" -" .get( 0 );\n" -"\n" -"//The \"speed\" parameter is located at index 0, has one constraint and is " -"not cascaded\n" -"//nor does it define group conversions\n" -"assertEquals( \"arg0\", speedDescriptor.getName() );\n" -"assertEquals( 0, speedDescriptor.getIndex() );\n" -"assertEquals( 1, speedDescriptor.getConstraintDescriptors().size() );\n" -"assertFalse( speedDescriptor.isCascaded() );\n" -"assert speedDescriptor.getGroupConversions().isEmpty();\n" -"\n" -"//getDriver() has no constrained parameters but its return value is marked " -"for cascaded\n" -"//validation and declares one group conversion\n" -"MethodDescriptor getDriverDescriptor = carDescriptor.getConstraintsForMethod" -"(\n" -" \"getDriver\"\n" -");\n" -"assertFalse( getDriverDescriptor.hasConstrainedParameters() );\n" -"assertTrue( getDriverDescriptor.hasConstrainedReturnValue() );\n" -"\n" -"ReturnValueDescriptor returnValueDescriptor = getDriverDescriptor." -"getReturnValueDescriptor();\n" -"assertTrue( returnValueDescriptor.getConstraintDescriptors().isEmpty() );\n" -"assertTrue( returnValueDescriptor.isCascaded() );\n" -"assertEquals( 1, returnValueDescriptor.getGroupConversions().size() );\n" -"\n" -"//load(List<Person>, List<PieceOfLuggage>) has one cross-" -"parameter constraint\n" -"MethodDescriptor loadDescriptor = carDescriptor.getConstraintsForMethod(\n" -" \"load\",\n" -" List.class,\n" -" List.class\n" -");\n" -"assertTrue( loadDescriptor.hasConstrainedParameters() );\n" -"assertFalse( loadDescriptor.hasConstrainedReturnValue() );\n" -"assertEquals(\n" -" 1,\n" -" loadDescriptor.getCrossParameterDescriptor()." -"getConstraintDescriptors().size()\n" -");\n" -"\n" -"//Car(String, String, Person, String) has one constrained parameter\n" -"ConstructorDescriptor constructorDescriptor = carDescriptor." -"getConstraintsForConstructor(\n" -" String.class,\n" -" String.class,\n" -" Person.class,\n" -" String.class\n" -");\n" -"\n" -"assertEquals( \"Car\", constructorDescriptor.getName() );\n" -"assertFalse( constructorDescriptor.hasConstrainedReturnValue() );\n" -"assertTrue( constructorDescriptor.hasConstrainedParameters() );\n" -"assertEquals(\n" -" 1,\n" -" constructorDescriptor.getParameterDescriptors()\n" -" .get( 0 )\n" -" .getConstraintDescriptors()\n" -" .size()\n" -");" -msgstr "" - -#. Tag: para -#: metadata-api.xml:166 -#, no-c-format -msgid "" -"getName() returns the name of the given method or " -"constructor. The methods hasConstrainedParameters() " -"and hasConstrainedReturnValue() can be used to " -"perform a quick check whether an executable element has any parameter " -"constraints (either constraints on single parameters or cross-parameter " -"constraints) or return value constraints." -msgstr "" - -#. Tag: para -#: metadata-api.xml:174 -#, no-c-format -msgid "" -"Note that any constraints are not directly exposed on " -"MethodDescriptor and " -"ConstructorDescriptor, but rather on dedicated " -"descriptors representing an executable's parameters, its return value and " -"its cross-parameter constraints. To get hold of one of these descriptors, " -"invoke getParameterDescriptors(), " -"getReturnValueDescriptor() or " -"getCrossParameterDescriptor(), respectively." -msgstr "" - -#. Tag: para -#: metadata-api.xml:184 -#, no-c-format -msgid "" -"These descriptors provide access to the element's constraints " -"(getConstraintDescriptors()) and, in case of " -"parameters and return value, to its configuration for cascaded validation " -"(isValid() and getGroupConversions()). For parameters, you also can retrieve the index and the name, " -"as returned by the currently used parameter name provider (see TODO) via " -"getName() and getIndex()." -msgstr "" - -#. Tag: para -#: metadata-api.xml:194 -#, no-c-format -msgid "" -"Getter methods following the JavaBeans naming conventions are considered as " -"bean properties but also as constrained methods." -msgstr "" - -#. Tag: para -#: metadata-api.xml:197 -#, no-c-format -msgid "" -"That means you can retrieve the related metadata either by obtaining a " -"PropertyDescriptor (e.g. BeanDescriptor." -"getConstraintsForProperty(\"foo\")) or by examining the return " -"value descriptor of the getter's MethodDescriptor (e." -"g. BeanDescriptor.getConstraintsForMethod(\"getFoo\")." -"getReturnValueDescriptor())." -msgstr "" - -#. Tag: classname -#: metadata-api.xml:207 -#, no-c-format -msgid "ElementDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:209 -#, no-c-format -msgid "" -"The ElementDiscriptor interface is the common " -"base class for the individual descriptor types such as " -"BeanDescriptor, PropertyDescriptor etc. Besides getConstraintDescriptors() " -"it provides some more methods common to all descriptors." -msgstr "" - -#. Tag: para -#: metadata-api.xml:217 -#, no-c-format -msgid "" -"hasConstraints() allows for a quick check whether an element " -"has any direct constraints (e.g. class-level constraints in case of " -"BeanDescriptor). getElementClass() returns the Java type of the element represented by a given " -"descriptor. More specifically, the method returns" -msgstr "" - -#. Tag: para -#: metadata-api.xml:226 -#, no-c-format -msgid "the object type when invoked on BeanDescriptor," -msgstr "" - -#. Tag: para -#: metadata-api.xml:231 -#, no-c-format -msgid "" -"the type of a property or parameter when invoked on " -"PropertyDescriptor or ParameterDescriptor respectively," -msgstr "" - -#. Tag: para -#: metadata-api.xml:237 -#, no-c-format -msgid "" -"Object[].class when invoked on " -"CrossParameterDescriptor," -msgstr "" - -#. Tag: para -#: metadata-api.xml:242 -#, no-c-format -msgid "" -"the return type when invoked on ConstructorDescriptor, MethodDescriptor or " -"ReturnValueDescriptor. void.class will be returned for methods which don't have a return value." -msgstr "" - -#. Tag: para -#: metadata-api.xml:251 -#, no-c-format -msgid "shows how these methods are used." -msgstr "" - -#. Tag: title -#: metadata-api.xml:255 -#, no-c-format -msgid "Using ElementDescriptor methods" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:257 -#, no-c-format -msgid "" -"PropertyDescriptor manufacturerDescriptor = carDescriptor." -"getConstraintsForProperty(\n" -" \"manufacturer\"\n" -");\n" -"\n" -"assertTrue( manufacturerDescriptor.hasConstraints() );\n" -"assertEquals( String.class, manufacturerDescriptor.getElementClass() );\n" -"\n" -"CrossParameterDescriptor loadCrossParameterDescriptor = carDescriptor." -"getConstraintsForMethod(\n" -" \"load\",\n" -" List.class,\n" -" List.class\n" -").getCrossParameterDescriptor();\n" -"\n" -"assertTrue( loadCrossParameterDescriptor.hasConstraints() );\n" -"assertEquals( Object[].class, loadCrossParameterDescriptor.getElementClass" -"() );" -msgstr "" - -#. Tag: para -#: metadata-api.xml:260 -#, no-c-format -msgid "" -"Finally, ElementDescriptor offers access to the " -"ConstraintFinder API which allows you to query for " -"constraint metadata in a fine grained way. shows how to retrieve a ConstraintFinder instance via findConstraints() and use " -"the API to query for constraint metadata." -msgstr "" - -#. Tag: title -#: metadata-api.xml:269 -#, no-c-format -msgid "Usage of ConstraintFinder" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:271 -#, no-c-format -msgid "" -"PropertyDescriptor manufacturerDescriptor = carDescriptor." -"getConstraintsForProperty(\n" -" \"manufacturer\"\n" -");\n" -"\n" -"//\"manufacturer\" constraints are declared on the getter, not the field\n" -"assertTrue(\n" -" manufacturerDescriptor.findConstraints()\n" -" .declaredOn( ElementType.FIELD )\n" -" .getConstraintDescriptors()\n" -" .isEmpty()\n" -");\n" -"\n" -"//@NotNull on Vehicle#getManufacturer() is part of another group\n" -"assertEquals(\n" -" 1,\n" -" manufacturerDescriptor.findConstraints()\n" -" .unorderedAndMatchingGroups( Default." -"class )\n" -" .getConstraintDescriptors()\n" -" .size()\n" -");\n" -"\n" -"//@Size on Car#getManufacturer()\n" -"assertEquals(\n" -" 1,\n" -" manufacturerDescriptor.findConstraints()\n" -" .lookingAt( Scope.LOCAL_ELEMENT )\n" -" .getConstraintDescriptors()\n" -" .size()\n" -");\n" -"\n" -"//@Size on Car#getManufacturer() and @NotNull on Vehicle#getManufacturer()\n" -"assertEquals(\n" -" 2,\n" -" manufacturerDescriptor.findConstraints()\n" -" .lookingAt( Scope.HIERARCHY )\n" -" .getConstraintDescriptors()\n" -" .size()\n" -");\n" -"\n" -"//Combining several filter options\n" -"assertEquals(\n" -" 1,\n" -" manufacturerDescriptor.findConstraints()\n" -" .declaredOn( ElementType.METHOD )\n" -" .lookingAt( Scope.HIERARCHY )\n" -" .unorderedAndMatchingGroups( Vehicle.Basic." -"class )\n" -" .getConstraintDescriptors()\n" -" .size()\n" -");" -msgstr "" - -#. Tag: para -#: metadata-api.xml:274 -#, no-c-format -msgid "" -"Via declaredOn(), the API allows to return only " -"ConstraintDescriptors declared on certain element " -"types. This is useful to search for property constraints declared on either " -"fields or getter methods." -msgstr "" - -#. Tag: para -#: metadata-api.xml:279 -#, no-c-format -msgid "" -"unorderedAndMatchingGroups() restricts the " -"resulting constraints to those matching the given validation group(s)." -msgstr "" - -#. Tag: para -#: metadata-api.xml:283 -#, no-c-format -msgid "" -"lookingAt() allows to distinguish between " -"constraints directly specified on the element (Scope." -"LOCAL_ELEMENT) or constraints belonging to the element but hosted " -"anywhere in the class hierarchy (Scope.HIERARCHY)." -msgstr "" - -#. Tag: para -#: metadata-api.xml:289 -#, no-c-format -msgid "" -"The different options also can be combined as shown in the last example." -msgstr "" - -#. Tag: para -#: metadata-api.xml:293 -#, no-c-format -msgid "" -"Order is not respected by unorderedAndMatchingGroups(), but group inheritance and inheritance via sequence are." -msgstr "" - -#. Tag: classname -#: metadata-api.xml:300 -#, no-c-format -msgid "GroupConversionDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:302 -#, no-c-format -msgid "" -"All those descriptor types that represent elements which can be subject of " -"cascaded validation (i.e., PropertyDescriptor, " -"ParameterDescriptor and " -"ReturnValueDescriptor) provide access to the " -"element's group conversions via getGroupConversions(). The returned set contains a GroupConversionDescriptor for each configured conversion, allowing to retrieve " -"source and target groups of the conversion. shows an example." -msgstr "" - -#. Tag: title -#: metadata-api.xml:317 -#, no-c-format -msgid "Using GroupConversionDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:319 -#, no-c-format -msgid "" -"PropertyDescriptor driverDescriptor = carDescriptor.getConstraintsForProperty" -"( \"driver\" );\n" -"\n" -"Set<GroupConversionDescriptor> groupConversions = driverDescriptor." -"getGroupConversions();\n" -"assertEquals( 1, groupConversions.size() );\n" -"\n" -"GroupConversionDescriptor groupConversionDescriptor = groupConversions." -"iterator()\n" -" .next();\n" -"assertEquals( Default.class, groupConversionDescriptor.getFrom() );\n" -"assertEquals( Person.Basic.class, groupConversionDescriptor.getTo() );" -msgstr "" - -#. Tag: classname -#: metadata-api.xml:324 -#, no-c-format -msgid "ConstraintDescriptor" -msgstr "" - -#. Tag: para -#: metadata-api.xml:326 -#, no-c-format -msgid "" -"Last but not least, the ConstraintDescriptor interface describes a single constraint together with its composing " -"constraints. Via an instance of this interface you get access to the " -"constraint annotation and its parameters." -msgstr "" - -#. Tag: para -#: metadata-api.xml:332 -#, no-c-format -msgid "" -"shows how to retrieve default constraint attributes (such as message " -"template, groups etc.) as well as custom constraint attributes " -"(piecesOfLuggagePerPassenger) and other metadata such as " -"the constraint's annotation type and its validators from a " -"ConstraintDescriptor." -msgstr "" - -#. Tag: title -#: metadata-api.xml:340 -#, no-c-format -msgid "Using ConstraintDescriptor" -msgstr "" - -#. Tag: programlisting -#: metadata-api.xml:342 -#, no-c-format -msgid "" -"//descriptor for the @LuggageCountMatchesPassengerCount constraint on the\n" -"//load(List<Person>, List<PieceOfLuggage>) method\n" -"ConstraintDescriptor<?> constraintDescriptor = carDescriptor." -"getConstraintsForMethod(\n" -" \"load\",\n" -" List.class,\n" -" List.class\n" -").getCrossParameterDescriptor().getConstraintDescriptors().iterator().next" -"();\n" -"\n" -"//constraint type\n" -"assertEquals(\n" -" LuggageCountMatchesPassengerCount.class,\n" -" constraintDescriptor.getAnnotation().annotationType()\n" -");\n" -"\n" -"//standard constraint attributes\n" -"assertEquals( SeverityInfo.class, constraintDescriptor.getPayload().iterator" -"().next() );\n" -"assertEquals(\n" -" ConstraintTarget.PARAMETERS,\n" -" constraintDescriptor.getValidationAppliesTo()\n" -");\n" -"assertEquals( Default.class, constraintDescriptor.getGroups().iterator().next" -"() );\n" -"assertEquals(\n" -" \"There must not be more than {piecesOfLuggagePerPassenger} " -"pieces of luggage per passenger.\",\n" -" constraintDescriptor.getMessageTemplate()\n" -");\n" -"\n" -"//custom constraint attribute\n" -"assertEquals(\n" -" 2,\n" -" constraintDescriptor.getAttributes().get" -"( \"piecesOfLuggagePerPassenger\" )\n" -");\n" -"\n" -"//no composing constraints\n" -"assertTrue( constraintDescriptor.getComposingConstraints().isEmpty() );\n" -"\n" -"//validator class\n" -"assertEquals(\n" -" Arrays.<Class<?>>asList" -"( LuggageCountMatchesPassengerCount.Validator.class ),\n" -" constraintDescriptor.getConstraintValidatorClasses()\n" -");" -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/metadataapi.po b/documentation/src/main/docbook/zh-CN/modules/metadataapi.po deleted file mode 100644 index 2c25f7a34d..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/metadataapi.po +++ /dev/null @@ -1,194 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2011. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2011-11-14 10:37+0000\n" -"PO-Revision-Date: 2011-01-12 15:42+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"Language: zh-CN\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: metadataapi.xml:24 -#, no-c-format -msgid "Metadata API" -msgstr "" - -#. Tag: para -#: metadataapi.xml:26 -#, no-c-format -msgid "" -"The Bean Validation specification provides not only a validation engine, but " -"also a metadata repository for all defined constraints. The following " -"paragraphs are discussing this API. All the introduced classes can be found " -"in the javax.validation.metadata package." -msgstr "" - -#. Tag: classname -#: metadataapi.xml:33 -#, no-c-format -msgid "BeanDescriptor" -msgstr "" - -#. Tag: para -#: metadataapi.xml:35 -#, no-c-format -msgid "" -"The entry into the metadata API is via Validator." -"getConstraintsForClass which returns an instance of the BeanDescriptor " -"interface. Using this bean descriptor you can determine whether the " -"specified class hosts any constraints at all via beanDescriptor." -"isBeanConstrained." -msgstr "" - -#. Tag: para -#: metadataapi.xml:42 -#, no-c-format -msgid "" -"If a constraint declaration hosted by the requested class is invalid, a " -"ValidationException is thrown." -msgstr "" - -#. Tag: para -#: metadataapi.xml:47 -#, no-c-format -msgid "" -"You can then call beanDescriptor.getConstraintDescriptors to " -"get a set of ConstraintDescriptors representing all " -"class level constraints." -msgstr "" - -#. Tag: para -#: metadataapi.xml:52 -#, no-c-format -msgid "" -"If you are interested in property level constraints, you can call " -"beanDescriptor.getConstraintsForProperty or " -"beanDescriptor.getConstrainedProperties to get a single resp. " -"set of PropertyDescriptors (see )." -msgstr "" - -#. Tag: classname -#: metadataapi.xml:60 -#, no-c-format -msgid "PropertyDescriptor" -msgstr "" - -#. Tag: para -#: metadataapi.xml:62 -#, no-c-format -msgid "" -"The PropertyDescriptor interface extends the " -"ElementDescriptor interface and represents " -"constraints on properties of a class. The constraint can be declared on the " -"attribute itself or on the getter of the attribute - provided Java Bean " -"naming conventions are respected. A PropertyDescriptor adds isCascaded (returning true " -"if the property is marked with @Valid) and " -"getPropertyName to the ElementDescriptor " -"functionality." -msgstr "" - -#. Tag: classname -#: metadataapi.xml:75 -#, no-c-format -msgid "ElementDescriptor" -msgstr "" - -#. Tag: para -#: metadataapi.xml:77 -#, no-c-format -msgid "" -"The ElementDiscriptor interface is the common " -"base class for BeanDescriptor and " -"PropertyDescriptor. Next to the hasConstraints " -"and getConstraintDescriptors methods it also offers " -"access to the ConstraintFinder API which allows you " -"to query the metadata API in a more fine grained way. For example you can " -"restrict your search to constraints described on fields or on getters or a " -"given set of groups. Given an ElementDescriptor " -"instance you just call findConstraints to retrieve a " -"ConstraintFinder instance." -msgstr "" - -#. Tag: title -#: metadataapi.xml:92 -#, no-c-format -msgid "Usage of ConstraintFinder" -msgstr "" - -#. Tag: programlisting -#: metadataapi.xml:94 -#, no-c-format -msgid "" -"Validator validator = Validation.buildDefaultValidatorFactory().getValidator" -"();\n" -"BeanDescriptor beanDescriptor = validator.getConstraintsForClass(Person." -"class);\n" -"PropertyDescriptor propertyDescriptor = beanDescriptor." -"getConstraintsForProperty(\"name\");\n" -"Set<ConstraintDescriptor<?>> constraints = propertyDescriptor." -"findConstraints()\n" -" .declaredOn(ElementType.METHOD)\n" -" .unorderedAndMatchingGroups" -"(Default.class)\n" -" .lookingAt(Scope.LOCAL_ELEMENT)\n" -" .getConstraintDescriptors();" -msgstr "" - -#. Tag: para -#: metadataapi.xml:97 -#, no-c-format -msgid "" -"shows an example on how to use the ConstraintFinder " -"API. Interesting are especially the restrictions " -"unorderedAndMatchingGroups and lookingAt(Scope.LOCAL_ELEMENT). The former allows " -"to only return ConstraintDescriptors matching a " -"specified set of groups wheras the latter allows to distinguish between " -"constraint directly specified on the element (Scope.LOCAL_ELEMENT) or constraints belonging to the element but hosted anywhere in " -"the class hierarchy (Scope.HIERARCHY)." -msgstr "" - -#. Tag: para -#: metadataapi.xml:108 -#, no-c-format -msgid "" -"Order is not respected by unorderedAndMatchingGroups, but group inheritance " -"and inheritance via sequence are." -msgstr "" - -#. Tag: classname -#: metadataapi.xml:114 -#, no-c-format -msgid "ConstraintDescriptor" -msgstr "" - -#. Tag: para -#: metadataapi.xml:116 -#, no-c-format -msgid "" -"Last but not least, the ConstraintDescriptor interface describes a " -"single constraint together with its composing constraints. Via an instance " -"of this interface you get access to the constraint annotation and its " -"parameters, as well as the groups the constraint is supposed to be applied " -"on. It also also you to access the pass-through constraint payload (see " -")." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/method-constraints.po b/documentation/src/main/docbook/zh-CN/modules/method-constraints.po deleted file mode 100644 index 96d7554960..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/method-constraints.po +++ /dev/null @@ -1,1334 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: method-constraints.xml:24 -#, no-c-format -msgid "Declaring and validating method constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:26 -#, no-c-format -msgid "" -"As of Bean Validation 1.1, constraints can not only be applied to Java beans " -"and their properties, but also to the parameters and return values of the " -"methods and constructors of any Java type. That way Bean Validation " -"constraints can be used to specify" -msgstr "" - -#. Tag: para -#: method-constraints.xml:33 -#, no-c-format -msgid "" -"the preconditions that must be satisfied by the caller before a method or " -"constructor may be invoked (by applying constraints to the parameters of an " -"executable)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:39 -#, no-c-format -msgid "" -"the postconditions that are guaranteed to the caller after a method or " -"constructor invocation returns (by applying constraints to the return value " -"of an executable)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:46 -#, no-c-format -msgid "" -"For the purpose of this reference guide, the term method " -"constraint refers to both, method and constructor constraints, if " -"not stated otherwise. Ocassionally, the term executable " -"is used when referering to methods and constructors." -msgstr "" - -#. Tag: para -#: method-constraints.xml:53 -#, no-c-format -msgid "" -"This approach has several advantages over traditional ways of checking the " -"correctness of parameters and return values:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:58 -#, no-c-format -msgid "" -"the checks don't have to be performed manually (e.g. by throwing " -"IllegalArgumentExceptions or similar), resulting in " -"less code to write and maintain" -msgstr "" - -#. Tag: para -#: method-constraints.xml:64 -#, no-c-format -msgid "" -"an executable's pre- and postconditions don't have to be expressed again in " -"its documentation, since the constraint annotations will automatically be " -"included in the generated JavaDoc. This avoids redundancies and reduces the " -"chance of inconsistencies between implementation and documentation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:73 -#, no-c-format -msgid "" -"In order to make annotations show up in the JavaDoc of annoted elements, the " -"annotation types themselves must be annotated with the meta annotation " -"@Documented. This is the case for all built-in " -"constraints and is considered a best practice for any custom constraints." -msgstr "" - -#. Tag: para -#: method-constraints.xml:80 -#, no-c-format -msgid "" -"In the remainder of this chapter you will learn how to declare parameter and " -"return value constraints and how to validate the same using the " -"ExecutableValidator API." -msgstr "" - -#. Tag: title -#: method-constraints.xml:85 -#, no-c-format -msgid "Declaring method constraints" -msgstr "" - -#. Tag: title -#: method-constraints.xml:88 -#, no-c-format -msgid "Parameter constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:90 -#, no-c-format -msgid "" -"You specify the preconditions of a method or constructor by adding " -"constraint annotations to its parameters as demonstrated in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:95 -#, no-c-format -msgid "Declaring method and constructor parameter constraints" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:97 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.parameter;\n" -"\n" -"public class RentalStation {\n" -"\n" -" public RentalStation(@NotNull String name) {\n" -" //...\n" -" }\n" -"\n" -" public void rentCar(\n" -" @NotNull Customer customer,\n" -" @NotNull @Future Date startDate,\n" -" @Min(1) int durationInDays) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:100 -#, no-c-format -msgid "The following preconditions are declared here:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:104 -#, no-c-format -msgid "" -"The name passed to the RentalCar constructor must not " -"be null" -msgstr "" - -#. Tag: para -#: method-constraints.xml:109 -#, no-c-format -msgid "" -"When invoking the rentCar() method, the given " -"customer must not be null, the rental's start date must " -"not be null and must be in the future and the rental " -"duration must be at least one day" -msgstr "" - -#. Tag: para -#: method-constraints.xml:116 -#, no-c-format -msgid "" -"Note that declaring method or constructor constraints itself does not " -"automatically cause their validation upon invocation of the executable. " -"Instead, the ExecutableValidator API (see ) must be used to perform the validation, which is " -"often done using a method interception facility such as AOP, proxy objects " -"etc." -msgstr "" - -#. Tag: para -#: method-constraints.xml:123 -#, no-c-format -msgid "" -"Constraints may only be applied to instance methods, i.e. declaring " -"constraints on static methods is not supported. Depending on the " -"interception facility you use for triggering method validation, additional " -"restrictions may apply, e.g. with respect to the visibility of methods " -"supported as target of interception. Refer to the documentation of the " -"interception technology to find out whether any such limitations exist." -msgstr "" - -#. Tag: title -#: method-constraints.xml:132 -#, no-c-format -msgid "Cross-parameter constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:134 -#, no-c-format -msgid "" -"Sometimes validation does not only depend on a single parameter but on " -"several or even all parameters of a method or constructor. This kind of " -"requirement can be fulfilled with help of a cross-parameter constraint." -msgstr "" - -#. Tag: para -#: method-constraints.xml:139 -#, no-c-format -msgid "" -"Cross-parameter constraints can be considered as the method validation " -"equivalent to class-level constraints. Both can be used to implement " -"validation requirements which are based on several elements. While class-" -"level constraints apply to several properties of a bean, cross-parameter " -"constraints apply to several parameters of an executable." -msgstr "" - -#. Tag: para -#: method-constraints.xml:146 -#, no-c-format -msgid "" -"In contrast to single-parameter constraints, cross-parameter constraints are " -"declared on the method or constructor as you can see in . Here the cross-parameter " -"constraint @LuggageCountMatchesPassengerCount " -"declared on the load() method is used to ensure " -"that no passenger has more than two pieces of luggage." -msgstr "" - -#. Tag: title -#: method-constraints.xml:155 -#, no-c-format -msgid "Declaring a cross-parameter constraint" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:157 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.crossparameter;\n" -"\n" -"public class Car {\n" -"\n" -" @LuggageCountMatchesPassengerCount(piecesOfLuggagePerPassenger = 2)\n" -" public void load(List<Person> passengers, List<" -"PieceOfLuggage> luggage) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:160 -#, no-c-format -msgid "" -"As you will learn in the next section, return value constraints are also " -"declared on the method level. In order to distinguish cross-parameter " -"constraints from return value constraints, a constraint's target is " -"configured at its validator implementation(s). You can find out about the " -"details in which " -"shows how to implement your own cross-parameter constraints." -msgstr "" - -#. Tag: para -#: method-constraints.xml:168 -#, no-c-format -msgid "" -"In some cases a constraint can be applied to an executable's parameters (i." -"e. it is a cross-parameter constraint), but also to the return value. One " -"example for this are custom constraints which allow to specify validation " -"rules using expression or script languages." -msgstr "" - -#. Tag: para -#: method-constraints.xml:174 -#, no-c-format -msgid "" -"Such constraints must define a member validationAppliesTo() which can be used at declaration time to specify the constraint " -"target. As shown in " -"you apply the constraint to an executable's parameters by specifying " -"validationAppliesTo = ConstraintTarget.PARAMETERS, while " -"ConstraintTarget.RETURN_VALUE is used to apply the " -"constraint to the executable return value." -msgstr "" - -#. Tag: title -#: method-constraints.xml:184 -#, no-c-format -msgid "Specifying a constraint's target" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:186 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.crossparameter." -"constrainttarget;\n" -"\n" -"public class Garage {\n" -"\n" -" @ELAssert(expression = \"...\", validationAppliesTo = " -"ConstraintTarget.PARAMETERS)\n" -" public Car buildCar(List<Part> parts) {\n" -" //...\n" -" }\n" -"\n" -" @ELAssert(expression = \"...\", validationAppliesTo = " -"ConstraintTarget.RETURN_VALUE)\n" -" public Car paintCar(int color) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:189 -#, no-c-format -msgid "" -"Although such a constraint is applicable to the parameters and return value " -"of an executable, the target can often be inferred automatically. This is " -"the case, if the constraint is declared on" -msgstr "" - -#. Tag: para -#: method-constraints.xml:196 -#, no-c-format -msgid "" -"a void method with parameters (the constraint applies to the parameters)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:201 -#, no-c-format -msgid "" -"an executable with return value but no parameters (the constraint applies to " -"the return value)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:206 -#, no-c-format -msgid "" -"neither a method nor a constructor, but a field, parameter etc. (the " -"constraint applies to the annotated element)" -msgstr "" - -#. Tag: para -#: method-constraints.xml:211 -#, no-c-format -msgid "" -"In these situations you don't have to specify the constraint target. It is " -"still recommended to do so if it increases readability of the source code. " -"If the constraint target is not specified in situations where it can't be " -"determined automatically, a ConstraintDeclarationException is raised." -msgstr "" - -#. Tag: title -#: method-constraints.xml:221 -#, no-c-format -msgid "Return value constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:223 -#, no-c-format -msgid "" -"The postconditions of a method or constructor are declared by adding " -"constraint annotations to the executable as shown in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:228 -#, no-c-format -msgid "Declaring method and constructor return value constraints" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:231 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.returnvalue;\n" -"\n" -"public class RentalStation {\n" -"\n" -" @ValidRentalStation\n" -" public RentalStation() {\n" -" //...\n" -" }\n" -"\n" -" @NotNull\n" -" @Size(min = 1)\n" -" public List<Customer> getCustomers() {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:234 -#, no-c-format -msgid "" -"The following constraints apply to the executables of " -"RentalStation:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:239 -#, no-c-format -msgid "" -"Any newly created RentalStation object must satisfy " -"the @ValidRentalStation constraint" -msgstr "" - -#. Tag: para -#: method-constraints.xml:245 -#, no-c-format -msgid "" -"The customer list returned by getCustomers() must " -"not be null and must contain at least on element" -msgstr "" - -#. Tag: title -#: method-constraints.xml:253 -#, no-c-format -msgid "Cascaded validation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:256 -#, no-c-format -msgid "" -"Similar to the cascaded validation of JavaBeans properties (see ), the @Valid annotation can be used to mark executable parameters and return " -"values for cascaded validation. When validating a parameter or return value " -"annotated with @Valid, the constraints declared on " -"the parameter or return value object are validated as well." -msgstr "" - -#. Tag: para -#: method-constraints.xml:264 -#, no-c-format -msgid "" -"In , the " -"car parameter of the method Garage#checkCar()" -" as well as the return value of the Garage constructor are marked for cascaded validation." -msgstr "" - -#. Tag: title -#: method-constraints.xml:271 -#, no-c-format -msgid "Marking executable parameters and return values for cascaded validation" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:274 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.cascaded;\n" -"\n" -"public class Garage {\n" -"\n" -" @NotNull\n" -" private final String name;\n" -"\n" -" @Valid\n" -" public Garage(String name) {\n" -" this.name = name;\n" -" }\n" -"\n" -" public boolean checkCar(@Valid @NotNull Car car) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:276 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.cascaded;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private final String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" private final String licensePlate;\n" -"\n" -" public Car(String manufacturer, String licencePlate) {\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:279 -#, no-c-format -msgid "" -"When validating the arguments of the checkCar() " -"method, the constraints on the properties of the passed Car object are evaluated as well. Similarly, the @NotNull constraint on the name field of " -"Garage is checked when validating the return value of " -"the Garage constructor." -msgstr "" - -#. Tag: para -#: method-constraints.xml:287 -#, no-c-format -msgid "" -"Generally, the cascaded validation works for executables in exactly the same " -"way as it does for JavaBeans properties." -msgstr "" - -#. Tag: para -#: method-constraints.xml:290 -#, no-c-format -msgid "" -"In particular, null values are ignored during cascaded " -"validation (naturally this can't happen during constructor return value " -"validation) and cascaded validation is performed recursively, i.e. if a " -"parameter or return value object which is marked for cascaded validation " -"itself has properties marked with @Valid, the " -"constraints declared on the referenced elements will be validated as well." -msgstr "" - -#. Tag: para -#: method-constraints.xml:298 -#, no-c-format -msgid "" -"Cascaded validation can not only be applied to simple object references but " -"also to collection-typed parameters and return values. This means when " -"putting the @Valid annotation to a parameter or " -"return value which" -msgstr "" - -#. Tag: para -#: method-constraints.xml:305 -#, no-c-format -msgid "is an array" -msgstr "" - -#. Tag: para -#: method-constraints.xml:309 -#, no-c-format -msgid "implements java.lang.Iterable" -msgstr "" - -#. Tag: para -#: method-constraints.xml:313 -#, no-c-format -msgid "implements java.util.Map" -msgstr "" - -#. Tag: para -#: method-constraints.xml:317 -#, no-c-format -msgid "" -"then each contained element gets checked, when the parameter or return value " -"is validated. So when validating the arguments of the checkCars()" -" method in , each element instance of the passed list will be " -"validated and a ConstraintViolation created when any " -"of the contained Car objects is invalid." -msgstr "" - -#. Tag: title -#: method-constraints.xml:326 -#, no-c-format -msgid "List-typed method parameter marked for cascaded validation" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:329 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.cascaded." -"collection;\n" -"\n" -"public class Garage {\n" -"\n" -" public boolean checkCars(@Valid @NotNull List<Car> cars) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: title -#: method-constraints.xml:334 -#, no-c-format -msgid "Method constraints in inheritance hierarchies" -msgstr "" - -#. Tag: para -#: method-constraints.xml:337 -#, no-c-format -msgid "" -"When declaring method constraints in inheritance hierarchies, it's important " -"to be aware of the following rules:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:342 -#, no-c-format -msgid "" -"The preconditions to be satisified by the caller of a method may not be " -"strengthened in subtypes" -msgstr "" - -#. Tag: para -#: method-constraints.xml:347 -#, no-c-format -msgid "" -"The postconditions guaranteed to the caller of a method may not be weakened " -"in subtypes" -msgstr "" - -#. Tag: para -#: method-constraints.xml:352 -#, no-c-format -msgid "" -"These rules are motivated by the concept of behavioral subtyping which requires that wherever a type T is " -"used, also a subtype S of T " -"may be used without altering the program's behavior." -msgstr "" - -#. Tag: para -#: method-constraints.xml:358 -#, no-c-format -msgid "" -"As an example, consider a class invoking a method on an object with the " -"static type T. If the runtime type of that object was " -"S and S imposed additional " -"preconditions, the client class might fail to satisfy these preconditions as " -"is not aware of them. The rules of behavioral subtyping are also known as " -"the Liskov substitution principle." -msgstr "" - -#. Tag: para -#: method-constraints.xml:367 -#, no-c-format -msgid "" -"The Bean Validation specification implements the first rule by disallowing " -"parameter constraints on methods which override or implement a method " -"declared in a supertype (superclass or interface). shows a violation of this rule." -msgstr "" - -#. Tag: title -#: method-constraints.xml:374 -#, no-c-format -msgid "Illegal method parameter constraint in subtype" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:376 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.inheritance." -"parameter;\n" -"\n" -"public interface Vehicle {\n" -"\n" -" void drive(@Max(75) int speedInMph);\n" -"}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:378 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.inheritance." -"parameter;\n" -"\n" -"import javax.validation.constraints.Max;\n" -"\n" -"public class Car implements Vehicle {\n" -"\n" -" @Override\n" -" public void drive(@Max(55) int speedInMph) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:381 -#, no-c-format -msgid "" -"The @Max constraint on Car#drive() is illegal since this method implements the interface method " -"Vehicle#drive(). Note that parameter constraints on " -"overriding methods are also disallowed, if the supertype method itself " -"doesn't declare any parameter constraints." -msgstr "" - -#. Tag: para -#: method-constraints.xml:388 -#, no-c-format -msgid "" -"Furthermore, if a method overrides or implements a method declared in " -"several parallel supertypes (e.g. two interfaces not extending each other or " -"a class and an interface not implemented by that class), no parameter " -"constraints may be specified for the method in any of the involved types. " -"The types in demonstrate a violation of that rule. The method " -"RacingCar#drive() overrides " -"Vehicle#drive() as well as Car#drive(). Therefore the constraint on Vehicle#drive() is illegal." -msgstr "" - -#. Tag: title -#: method-constraints.xml:401 -#, no-c-format -msgid "Illegal method parameter constraint in parallel types of a hierarchy" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:404 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.inheritance." -"parallel;\n" -"\n" -"public interface Vehicle {\n" -"\n" -" void drive(@Max(75) int speedInMph);\n" -"}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:406 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.inheritance." -"parallel;\n" -"\n" -"public interface Car {\n" -"\n" -" public void drive(int speedInMph);\n" -"}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:408 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.inheritance." -"parallel;\n" -"\n" -"public class RacingCar implements Car, Vehicle {\n" -"\n" -" @Override\n" -" public void drive(int speedInMph) {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:411 -#, no-c-format -msgid "" -"The previously described restrictions only apply to parameter constraints. " -"In contrast, return value constraints may be added in methods overriding or " -"implementing any supertype methods." -msgstr "" - -#. Tag: para -#: method-constraints.xml:415 -#, no-c-format -msgid "" -"In this case, all the method's return value constraints apply for the " -"subtype method, i.e. the constraints declared on the subtype method itself " -"as well as any return value constraints on overridden/implemented supertype " -"methods. This is legal as putting additional return value constraints in " -"place may never represent a weakening of the postconditions guaranteed to " -"the caller of a method." -msgstr "" - -#. Tag: para -#: method-constraints.xml:422 -#, no-c-format -msgid "" -"So when validating the return value of the method " -"Car#getPassengers() shown in , the @Size constraint on the method itself as well as the " -"@NotNull constraint on the implemented interface " -"method Vehicle#getPassengers() apply." -msgstr "" - -#. Tag: title -#: method-constraints.xml:431 -#, no-c-format -msgid "Return value constraints on supertype and subtype method" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:434 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.inheritance." -"returnvalue;\n" -"\n" -"public interface Vehicle {\n" -"\n" -" @NotNull\n" -" List<Person> getPassengers();\n" -"}" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:436 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.inheritance." -"returnvalue;\n" -"\n" -"public class Car implements Vehicle {\n" -"\n" -" @Override\n" -" @Size(min = 1)\n" -" public List<Person> getPassengers() {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: para -#: method-constraints.xml:439 -#, no-c-format -msgid "" -"If the validation engine detects a violation of any of the aforementioned " -"rules, a ConstraintDeclarationException will be " -"raised." -msgstr "" - -#. Tag: para -#: method-constraints.xml:445 -#, no-c-format -msgid "" -"The rules described in this section only apply to methods but not " -"constructors. By definition, constructors never override supertype " -"constructors. Therefore, when validating the parameters or the return value " -"of a constructor invocation only the constraints declared on the constructor " -"itself apply, but never any constraints declared on supertype constructors." -msgstr "" - -#. Tag: title -#: method-constraints.xml:456 -#, no-c-format -msgid "Validating method constraints" -msgstr "" - -#. Tag: para -#: method-constraints.xml:458 -#, no-c-format -msgid "" -"The validation of method constraints is done using the " -"ExecutableValidator interface." -msgstr "" - -#. Tag: para -#: method-constraints.xml:461 -#, no-c-format -msgid "" -"In you'll learn " -"how to obtain an ExecutableValidator instance " -"while shows how to " -"use the different methods offered by this interface." -msgstr "" - -#. Tag: para -#: method-constraints.xml:466 -#, no-c-format -msgid "" -"Instead of calling the ExecutableValidator methods directly from within " -"application code, they are usually invoked via a method interception " -"technology such as AOP, proxy objects, etc. This causes executable " -"constraints to be validated automatically and transparently upon method or " -"constructor invocation. Typically a ConstraintViolationException is raised by the integration layer in case any of the constraints " -"is violated." -msgstr "" - -#. Tag: title -#: method-constraints.xml:475 -#, no-c-format -msgid "Obtaining an ExecutableValidator instance" -msgstr "" - -#. Tag: para -#: method-constraints.xml:478 -#, no-c-format -msgid "" -"You can retrieve an ExecutableValidator instance via " -"Validator#forExecutables() as shown in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:483 -#, no-c-format -msgid "Obtaining an ExecutableValidator" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:485 -#, no-c-format -msgid "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"executableValidator = factory.getValidator().forExecutables();" -msgstr "" - -#. Tag: para -#: method-constraints.xml:488 -#, no-c-format -msgid "" -"In the example the executable validator is retrieved from the default " -"validator factory, but if required you could also bootstrap a specifically " -"configured factory as described in , for instance in order to use a specific parameter name provider (see " -")." -msgstr "" - -#. Tag: title -#: method-constraints.xml:497 -#, no-c-format -msgid "ExecutableValidator methods" -msgstr "" - -#. Tag: para -#: method-constraints.xml:499 -#, no-c-format -msgid "" -"The ExecutableValidator interface offers altogether " -"four methods:" -msgstr "" - -#. Tag: para -#: method-constraints.xml:504 -#, no-c-format -msgid "" -"validateParameters() and " -"validateReturnValue() for method validation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:510 -#, no-c-format -msgid "" -"validateConstructorParameters() and " -"validateConstructorReturnValue() for constructor " -"validation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:516 -#, no-c-format -msgid "" -"Just as the methods on Validator, all these methods " -"return a Set<ConstraintViolation> which " -"contains a ConstraintViolation instance for each " -"violated constraint and which is empty if the validation succeeds. Also all " -"the methods have a var-args groups parameter by which you " -"can pass the validation groups to be considered for validation." -msgstr "" - -#. Tag: para -#: method-constraints.xml:524 -#, no-c-format -msgid "" -"The examples in the following sections are based on the methods on " -"constructors of the Car class shown in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:529 -#, no-c-format -msgid "" -"Class Car with constrained methods and constructors" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:532 -#, no-c-format -msgid "" -"package org.hibernate.validator.referenceguide.chapter03.validation;\n" -"\n" -"public class Car {\n" -"\n" -" public Car(@NotNull String manufacturer) {\n" -" //...\n" -" }\n" -"\n" -" @ValidRacingCar\n" -" public Car(String manufacturer, String team) {\n" -" //...\n" -" }\n" -"\n" -" public void drive(@Max(75) int speedInMph) {\n" -" //...\n" -" }\n" -"\n" -" @Size(min = 1)\n" -" public List<Passenger> getPassengers() {\n" -" //...\n" -" }\n" -"}" -msgstr "" - -#. Tag: methodname -#: method-constraints.xml:536 -#, no-c-format -msgid "validateParameters()" -msgstr "" - -#. Tag: para -#: method-constraints.xml:538 -#, no-c-format -msgid "" -"The method validateParameters() is used to validate " -"the arguments of a method invocation. shows an example. The validation results " -"in a violation of the @Max constraint on the " -"parameter of the drive() method." -msgstr "" - -#. Tag: title -#: method-constraints.xml:546 -#, no-c-format -msgid "Using ExecutableValidator#validateParameters()" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:549 -#, no-c-format -msgid "" -"Car object = new Car( \"Morris\" );\n" -"Method method = Car.class.getMethod( \"drive\", int.class );\n" -"Object[] parameterValues = { 80 };\n" -"Set<ConstraintViolation<Car>> violations = executableValidator." -"validateParameters(\n" -" object,\n" -" method,\n" -" parameterValues\n" -");\n" -"\n" -"assertEquals( 1, violations.size() );\n" -"Class<? extends Annotation> constraintType = violations.iterator()\n" -" .next()\n" -" .getConstraintDescriptor()\n" -" .getAnnotation()\n" -" .annotationType();\n" -"assertEquals( Max.class, constraintType );" -msgstr "" - -#. Tag: para -#: method-constraints.xml:552 -#, no-c-format -msgid "" -"Note that validateParameters() validates all the " -"parameter constraints of a method, i.e. constraints on individual parameters " -"as well as cross-parameter constraints." -msgstr "" - -#. Tag: methodname -#: method-constraints.xml:559 -#, no-c-format -msgid "validateReturnValue()" -msgstr "" - -#. Tag: para -#: method-constraints.xml:561 -#, no-c-format -msgid "" -"Using validateReturnValue() the return value of a " -"method can can be validated. The validation in yields one constraint " -"violation since the getPassengers() method is " -"expect to return at least one Passenger object." -msgstr "" - -#. Tag: title -#: method-constraints.xml:569 -#, no-c-format -msgid "" -"Using ExecutableValidator#validateReturnValue()" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:572 -#, no-c-format -msgid "" -"Car object = new Car( \"Morris\" );\n" -"Method method = Car.class.getMethod( \"getPassengers\" );\n" -"Object returnValue = Collections.<Passenger>emptyList();\n" -"Set<ConstraintViolation<Car>> violations = executableValidator." -"validateReturnValue(\n" -" object,\n" -" method,\n" -" returnValue\n" -");\n" -"\n" -"assertEquals( 1, violations.size() );\n" -"Class<? extends Annotation> constraintType = violations.iterator()\n" -" .next()\n" -" .getConstraintDescriptor()\n" -" .getAnnotation()\n" -" .annotationType();\n" -"assertEquals( Size.class, constraintType );" -msgstr "" - -#. Tag: methodname -#: method-constraints.xml:577 -#, no-c-format -msgid "validateConstructorParameters()" -msgstr "" - -#. Tag: para -#: method-constraints.xml:579 -#, no-c-format -msgid "" -"The arguments of constructor invocations can be validated with " -"validateConstructorParameters() as shown in method " -". Due to the @NotNull constraint on the " -"manufacturer parameter, the validation call returns one " -"constraint violation." -msgstr "" - -#. Tag: title -#: method-constraints.xml:588 -#, no-c-format -msgid "" -"Using ExecutableValidator#validateConstructorParameters()" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:591 -#, no-c-format -msgid "" -"Constructor<Car> constructor = Car.class.getConstructor( String." -"class );\n" -"Object[] parameterValues = { null };\n" -"Set<ConstraintViolation<Car>> violations = executableValidator." -"validateConstructorParameters(\n" -" constructor,\n" -" parameterValues\n" -");\n" -"\n" -"assertEquals( 1, violations.size() );\n" -"Class<? extends Annotation> constraintType = violations.iterator()\n" -" .next()\n" -" .getConstraintDescriptor()\n" -" .getAnnotation()\n" -" .annotationType();\n" -"assertEquals( NotNull.class, constraintType );" -msgstr "" - -#. Tag: methodname -#: method-constraints.xml:596 -#, no-c-format -msgid "validateConstructorReturnValue()" -msgstr "" - -#. Tag: para -#: method-constraints.xml:598 -#, no-c-format -msgid "" -"Finally, by using validateConstructorReturnValue() " -"you can valide a constructor's return value. In , " -"validateConstructorReturnValue() returns one " -"constraint violation, since the Car object returned " -"by the constructor doesn't satisfy the @ValidRacingCar constraint (not shown)." -msgstr "" - -#. Tag: title -#: method-constraints.xml:608 -#, no-c-format -msgid "" -"Using ExecutableValidator#validateConstructorReturnValue()" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:611 -#, no-c-format -msgid "" -"//constructor for creating racing cars\n" -"Constructor<Car> constructor = Car.class.getConstructor( String.class, " -"String.class );\n" -"Car createdObject = new Car( \"Morris\", null );\n" -"Set<ConstraintViolation<Car>> violations = executableValidator." -"validateConstructorReturnValue(\n" -" constructor,\n" -" createdObject\n" -");\n" -"\n" -"assertEquals( 1, violations.size() );\n" -"Class<? extends Annotation> constraintType = violations.iterator()\n" -" .next()\n" -" .getConstraintDescriptor()\n" -" .getAnnotation()\n" -" .annotationType();\n" -"assertEquals( ValidRacingCar.class, constraintType );" -msgstr "" - -#. Tag: title -#: method-constraints.xml:617 -#, no-c-format -msgid "" -"ConstraintViolation methods for method validation" -msgstr "" - -#. Tag: para -#: method-constraints.xml:620 -#, no-c-format -msgid "" -"In addition to the methods introduced in , ConstraintViolation provides " -"two more methods specific to the validation of executable parameters and " -"return values." -msgstr "" - -#. Tag: para -#: method-constraints.xml:626 -#, no-c-format -msgid "" -"ConstraintViolation#getExecutableParameters() " -"returns the validated parameter array in case of method or constructor " -"parameter validation, while " -"ConstraintViolation#getExecutableReturnValue() " -"provides access to the validated object in case of return value validation." -msgstr "" - -#. Tag: para -#: method-constraints.xml:633 -#, no-c-format -msgid "" -"All the other ConstraintViolation methods generally " -"work for method validation in the same way as for validation of beans. Refer " -"to the JavaDoc to learn more about the behavior of the individual methods and their " -"return values during bean and method validation." -msgstr "" - -#. Tag: para -#: method-constraints.xml:640 -#, no-c-format -msgid "" -"Note that getPropertyPath() can be very useful in " -"order to obtain detailed information about the validated parameter or return " -"value, e.g. for logging purposes. In particular, you can retrieve name and " -"argument types of the concerned method as well as the index of the concerned " -"parameter from the path nodes. How this can be done is shown in ." -msgstr "" - -#. Tag: title -#: method-constraints.xml:649 -#, no-c-format -msgid "Retrieving method and parameter information" -msgstr "" - -#. Tag: programlisting -#: method-constraints.xml:651 -#, no-c-format -msgid "" -"Car object = new Car( \"Morris\" );\n" -"Method method = Car.class.getMethod( \"drive\", int.class );\n" -"Object[] parameterValues = { 80 };\n" -"Set<ConstraintViolation<Car>> violations = executableValidator." -"validateParameters(\n" -" object,\n" -" method,\n" -" parameterValues\n" -");\n" -"\n" -"assertEquals( 1, violations.size() );\n" -"Iterator<Node> propertyPath = violations.iterator()\n" -" .next()\n" -" .getPropertyPath()\n" -" .iterator();\n" -"\n" -"MethodNode methodNode = propertyPath.next().as( MethodNode.class );\n" -"assertEquals( \"drive\", methodNode.getName() );\n" -"assertEquals( Arrays.<Class<?>>asList( int.class ), methodNode." -"getParameterTypes() );\n" -"\n" -"ParameterNode parameterNode = propertyPath.next().as( ParameterNode." -"class );\n" -"assertEquals( \"arg0\", parameterNode.getName() );\n" -"assertEquals( 0, parameterNode.getParameterIndex() );" -msgstr "" - -#. Tag: para -#: method-constraints.xml:654 -#, no-c-format -msgid "" -"The parameter name is determined using the current " -"ParameterNameProvider (see TODO) and defaults to " -"arg0, arg1 etc." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/preface.po b/documentation/src/main/docbook/zh-CN/modules/preface.po deleted file mode 100644 index d7dbbd1a96..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/preface.po +++ /dev/null @@ -1,69 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2010-07-06 23:46+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: preface.xml:24 -#, no-c-format -msgid "Preface" -msgstr "序言" - -#. Tag: para -#: preface.xml:26 -#, no-c-format -msgid "" -"Validating data is a common task that occurs throughout any application, " -"from the presentation layer to the persistence layer. Often the same " -"validation logic is implemented in each layer, proving time consuming and " -"error-prone. To avoid duplication of these validations in each layer, " -"developers often bundle validation logic directly into the domain model, " -"cluttering domain classes with validation code which is really metadata " -"about the class itself." -msgstr "" -"数据校验是任何一个应用程序都会用到的功能,无论是显示层还是持久层. 通常,相同的" -"校验逻辑会分散在各个层中, 这样,不仅浪费了时间还会导致错误的发生(译注: 重复代" -"码). 为了避免重复, 开发人员经常会把这些校验逻辑直接写在领域模型里面, 但是这样" -"又把领域模型代码和校验代码混杂在了一起, 而这些校验逻辑更应该是描述领域模型的" -"元数据." - -#. Tag: para -#: preface.xml:45 -#, fuzzy, no-c-format -msgid "" -"JSR 349 - Bean Validation 1.1 - defines a metadata model and API for entity " -"validation. The default metadata source is annotations, with the ability to " -"override and extend the meta-data through the use of XML. The API is not " -"tied to a specific application tier or programming model. It is specifically " -"not tied to either the web tier or the persistence tier, and is available " -"for both server-side application programming, as well as rich client Swing " -"application developers." -msgstr "" -"JSR 303 - Bean Validation - 为实体验证定义了元数据模型和API. 默认的元数据模型" -"是通过Annotations来描述的,但是也可以使用XML来重载或者扩展. Bean Validation " -"API 并不局限于应用程序的某一层或者哪种编程模型, 例如,如图所示, Bean " -"Validation 可以被用在任何一层, 或者是像类似Swing的富客户端程序中." - -#. Tag: para -#: preface.xml:64 -#, no-c-format -msgid "" -"Hibernate Validator is the reference implementation of this JSR. The " -"implementation itself as well as the Bean Validation API and TCK are all " -"provided and distributed under the Apache Software License 2.0." -msgstr "" - -#~ msgid "Hibernate Validator is the reference implementation of this JSR." -#~ msgstr "Hibernate Validator 是这个JSR的参考实现." diff --git a/documentation/src/main/docbook/zh-CN/modules/programmaticapi.po b/documentation/src/main/docbook/zh-CN/modules/programmaticapi.po deleted file mode 100644 index 44d5a80b9a..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/programmaticapi.po +++ /dev/null @@ -1,220 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2011-01-12 15:42+0000\n" -"PO-Revision-Date: 2010-08-23 23:32+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: programmaticapi.xml:24 programmaticapi.xml:47 -#, no-c-format -msgid "Programmatic constraint definition" -msgstr "编程方式应用约束条件" - -#. Tag: para -#: programmaticapi.xml:27 -#, no-c-format -msgid "" -"Use of the features described in the following sections is not portable " -"between Bean Validation providers/implementations." -msgstr "下面的特性是不可移植的." - -#. Tag: para -#: programmaticapi.xml:31 -#, no-c-format -msgid "" -"Hibernate Validator allows to configure constraints not only via annotations " -"and xml, but also via a programmatic API. This API can be used exclusively " -"or in combination with annotations and xml. If used in combination " -"programmatic constraints are additive to otherwise configured constraints." -msgstr "" -"Hibernate Validator不仅支持通过标注(annotation) 和xml的方式来给实体定义约束条" -"件, 你也可以通过编程的方式来实现. 这套API即可以覆盖另外两种方式定义的约束条" -"件, 也可以和它们结合在一起使用, 如果是后者的话, 那么它所定义的约束条件会被附" -"加到另外两种方式所定义的约束后面." - -#. Tag: para -#: programmaticapi.xml:37 -#, no-c-format -msgid "" -"The programmatic API is centered around the ConstraintMapping class which can be found together with its supporting classes in " -"the org.hibernate.validator.cfg package. " -"ConstraintMapping is the entry point to a fluent API " -"allowing the definition of constraints. shows how the API can be used." -msgstr "" -"这套API是以org.hibernate.validator.cfg下面的" -"ConstraintMapping为中心点, 此包中还包含一些关联的类. " -"ConstraintMapping是实现此功能的入口点. 介绍了如何使用此API." - -#. Tag: programlisting -#: programmaticapi.xml:49 -#, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .property( \"manufacturer\", FIELD )\n" -" .constraint( NotNullDef.class )\n" -" .property( \"licensePlate\", FIELD )\n" -" .constraint( NotNullDef.class )\n" -" .constraint( SizeDef.class )\n" -" .min( 2 )\n" -" .max( 14 )\n" -" .property( \"seatCount\", FIELD )\n" -" .constraint( MinDef.class )\n" -" .value ( 2 )\n" -".type( RentalCar.class )\n" -" .property( \"rentalStation\", METHOD)\n" -" .constraint( NotNullDef.class );" -msgstr "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .property( \"manufacturer\", FIELD )\n" -" .constraint( NotNullDef.class )\n" -" .property( \"licensePlate\", FIELD )\n" -" .constraint( NotNullDef.class )\n" -" .constraint( SizeDef.class )\n" -" .min( 2 )\n" -" .max( 14 )\n" -" .property( \"seatCount\", FIELD )\n" -" .constraint( MinDef.class )\n" -" .value ( 2 )\n" -".type( RentalCar.class )\n" -" .property( \"rentalStation\", METHOD)\n" -" .constraint( NotNullDef.class );" - -#. Tag: para -#: programmaticapi.xml:52 -#, fuzzy, no-c-format -msgid "" -"As you can see you can configure constraints on multiple classes and " -"properties using method chaining. The constraint definition classes " -"NotNullDef, SizeDef and " -"MinDef are helper classes which allow to configure " -"constraint parameters in a type-safe fashion. Definition classes exists for " -"all built-in constraints in the org.hibernate.validator.cfg.defs package. For a custom constraint you can either create your own " -"definition class extending ConstraintDef or you can " -"use the genericConstraint method as seen in ." -msgstr "" -"正如你所看到的, 通过链式API的设计, 你可以给多个实体和属性设置约束条件. 上面所" -"用到的NotNullDef, SizeDef 等 " -"MinDef 只是每个约束条件定义(annotation)所对应的约束定" -"义类, 这样的设计是为了类型安全. org.hibernate.validator.cfg.defs下包含有每个内置的约束条件对应的约束定义类. 对于自定义的约束条件来" -"说, 你可以通过继承ConstraintDef来创建你自己的约束定义" -"类, 或者你可以使用GenericConstraintDef, 请参考." - -#. Tag: title -#: programmaticapi.xml:65 -#, no-c-format -msgid "" -"Programmatic constraint definition using GenericConstraintDef" -msgstr "通过GenericConstraintDef实现约束定义类" - -#. Tag: programlisting -#: programmaticapi.xml:68 -#, fuzzy, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .property( \"licensePlate\", FIELD )\n" -" .genericConstraint( CheckCase.class )\n" -" .param( \"value\", CaseMode.UPPER );" -msgstr "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .property( \"licensePlate\", FIELD )\n" -" .constraint( GenericConstraintDef.class )\n" -" .constraintType( CheckCase.class )\n" -" .param( \"value\", CaseMode.UPPER );" - -#. Tag: para -#: programmaticapi.xml:71 -#, no-c-format -msgid "" -"Last but not least, you can also define cascading constraints as well as the " -"default group sequence of an entity." -msgstr "" -"最后, 你也可是通过API的方式来实现对一个实体重定义默认组序列和级联约束条件定" -"义." - -#. Tag: title -#: programmaticapi.xml:75 -#, no-c-format -msgid "Cascading constraints and group redefinition" -msgstr "级联约束和默认组序列定义" - -#. Tag: programlisting -#: programmaticapi.xml:77 -#, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .valid( \"driver\", FIELD )\n" -".type( RentalCar.class)\n" -" .defaultGroupSequence( RentalCar.class, CarChecks.class );" -msgstr "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"mapping.type( Car.class )\n" -" .valid( \"driver\", FIELD )\n" -".type( RentalCar.class)\n" -" .defaultGroupSequence( RentalCar.class, CarChecks.class );" - -#. Tag: para -#: programmaticapi.xml:80 -#, no-c-format -msgid "" -"Once you have your ConstraintMapping you will have to " -"pass it to the configuration. Since the programmatic configuration is not " -"part of the official Bean Validation specification you will have to get hold " -"of the Hibernate Validator specific configuration instance. See ." -msgstr "" -"一旦你创建(和配置)好了ConstraintMapping, 你需要把它传" -"递进configuration, 从而创建validator. 因为这个编程方式定义约束的特性不是Bean " -"Validation规范的一部分, 所以你只能通过获取内部的Hibernate Validator的" -"configuration对象来实现. 请参考." - -#. Tag: title -#: programmaticapi.xml:87 -#, no-c-format -msgid "Creating a Hibernate Validator specific configuration" -msgstr "创建Hibernate Validator特有的属性" - -#. Tag: programlisting -#: programmaticapi.xml:89 -#, no-c-format -msgid "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"// configure mapping instance\n" -"\n" -"HibernateValidatorConfiguration config = Validation.byProvider" -"( HibernateValidator.class ).configure();\n" -"config.addMapping( mapping );\n" -"ValidatorFactory factory = config.buildValidatorFactory();\n" -"Validator validator = factory.getValidator();" -msgstr "" -"ConstraintMapping mapping = new ConstraintMapping();\n" -"// configure mapping instance\n" -"\n" -"HibernateValidatorConfiguration config = Validation.byProvider" -"( HibernateValidator.class ).configure();\n" -"config.addMapping( mapping );\n" -"ValidatorFactory factory = config.buildValidatorFactory();\n" -"Validator validator = factory.getValidator();" diff --git a/documentation/src/main/docbook/zh-CN/modules/usingvalidator.po b/documentation/src/main/docbook/zh-CN/modules/usingvalidator.po deleted file mode 100644 index ad51ff043c..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/usingvalidator.po +++ /dev/null @@ -1,2839 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-03 09:59+0000\n" -"PO-Revision-Date: 2010-08-19 22:28+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: usingvalidator.xml:24 -#, fuzzy, no-c-format -msgid "Declaring and validating constraints" -msgstr "校验约束" - -#. Tag: para -#: usingvalidator.xml:26 -#, no-c-format -msgid "" -"In this chapter we will see in more detail how to use Hibernate Validator to " -"validate constraints for a given entity model. We will also learn which " -"default constraints the Bean Validation specification provides and which " -"additional constraints are only provided by Hibernate Validator. Let's start " -"with how to add constraints to an entity." -msgstr "" -"在本章中,我们会详细的介绍如何使用Hibernate Validator 来对一个给定的实体模型进" -"行验证. 还会介绍Bean Validation规范提供了哪些默认的约束条件和Hibernate " -"Validator提供了哪些额外的. 让我们先从如何给一个实体添加约束开始." - -#. Tag: title -#: usingvalidator.xml:33 -#, no-c-format -msgid "Defining constraints" -msgstr "定义约束" - -#. Tag: para -#: usingvalidator.xml:35 -#, fuzzy, no-c-format -msgid "" -"Constraints in Bean Validation are expressed via Java annotations. In this " -"section we show how to enhance an object model with these annotations. We " -"have to differentiate between several types of constraint annotations:" -msgstr "" -"Bean Validation 的约束是通过Java 注解(annotations)来标注的. 在本节中,我们会介" -"绍如何使用这些注解(annotations)来标注一个实体模型. 并且,我们会区分三种不通的" -"注解(annotations) 类型." - -#. Tag: para -#: usingvalidator.xml:42 -#, fuzzy, no-c-format -msgid "field constraints" -msgstr "字段级(field level) 约束" - -#. Tag: para -#: usingvalidator.xml:46 -#, fuzzy, no-c-format -msgid "property constraints" -msgstr "属性级别约束" - -#. Tag: para -#: usingvalidator.xml:50 -#, fuzzy, no-c-format -msgid "class constraints" -msgstr "类级别约束" - -#. Tag: para -#: usingvalidator.xml:54 -#, no-c-format -msgid "" -"method constraints (parameter, cross-parameter and return value constraints)" -msgstr "" - -#. Tag: para -#: usingvalidator.xml:60 -#, no-c-format -msgid "" -"Not all constraints can be placed on all of these levels. In fact, none of " -"the default constraints defined by Bean Validation can be placed at class " -"level. The java.lang.annotation.Target annotation in " -"the constraint annotation itself determines on which elements a constraint " -"can be placed. See for more " -"information." -msgstr "" -"不是所有的约束都能够被用在所有的类结构上. 事实上, 没有任何定义在Bean " -"Validation规范中的约束可以被用在class上. 约束定义中的java.lang." -"annotation.Target属性定义了这个约束能够被使用在哪个层次结构上. 详" -"细信息请参考." - -#. Tag: title -#: usingvalidator.xml:69 -#, no-c-format -msgid "Field-level constraints" -msgstr "字段级(field level) 约束" - -#. Tag: para -#: usingvalidator.xml:71 -#, no-c-format -msgid "" -"Constraints can be expressed by annotating a field of a class. shows a field level configuration example:" -msgstr "" -"约束条件能够被标注在类的字段上面, 请参考示例" - -#. Tag: title -#: usingvalidator.xml:76 -#, no-c-format -msgid "Field level constraint" -msgstr "字段级(field level) 约束" - -#. Tag: programlisting -#: usingvalidator.xml:78 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @AssertTrue\n" -" private boolean isRegistered;\n" -"\n" -" public Car(String manufacturer, boolean isRegistered) {\n" -" super();\n" -" this.manufacturer = manufacturer;\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @AssertTrue\n" -" private boolean isRegistered;\n" -"\n" -" public Car(String manufacturer, boolean isRegistered) {\n" -" super();\n" -" this.manufacturer = manufacturer;\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"}" - -#. Tag: para -#: usingvalidator.xml:81 -#, no-c-format -msgid "" -"When using field level constraints field access strategy is used to access " -"the value to be validated. This means the bean validation provider directly " -"accesses the instance variable and does not invoke the property accessor " -"method also if such a method exists." -msgstr "" -"当约束被定义在字段上的时候, 这个字段的值是通过字段访问策略来获取并验证的. 也" -"就是说Bean Validation的实现者会直接访问这个实例变量而不会调用属性的访问器" -"(getter) 即使这个方法存在." - -#. Tag: para -#: usingvalidator.xml:87 -#, no-c-format -msgid "The access type (private, protected or public) does not matter." -msgstr "这个字段的访问级别( private, protected 或者 public) 对此没有影响." - -#. Tag: para -#: usingvalidator.xml:92 -#, no-c-format -msgid "Static fields and properties cannot be validated." -msgstr "静态字段或者属性是不会被校验的." - -#. Tag: para -#: usingvalidator.xml:96 -#, no-c-format -msgid "" -"When validating byte code enhanced objects property level constraints should " -"be used, because the byte code enhancing library won't be able to determine " -"a field access via reflection." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:103 -#, no-c-format -msgid "Property-level constraints" -msgstr "属性级别约束" - -#. Tag: para -#: usingvalidator.xml:105 -#, no-c-format -msgid "" -"If your model class adheres to the JavaBeans " -"standard, it is also possible to annotate the properties of a bean class " -"instead of its fields. uses the " -"same entity as in , however, property " -"level constraints are used." -msgstr "" -"如果你的模型遵循JavaBeans规范的话, 你还可" -"以把约束标注在属性上. 的唯一不同就是它的约束是定义在属性级别上的." - -#. Tag: para -#: usingvalidator.xml:111 -#, no-c-format -msgid "The property's getter method has to be annotated, not its setter." -msgstr "" -"如果要定义约束在属性级别上的话,那么只能定义在访问器(getter)上面,不能定义在修" -"改器(setter)上." - -#. Tag: title -#: usingvalidator.xml:116 -#, no-c-format -msgid "Property level constraint" -msgstr "属性级约束" - -#. Tag: programlisting -#: usingvalidator.xml:118 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.AssertTrue;\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Car {\n" -"\n" -" private String manufacturer;\n" -"\n" -" private boolean isRegistered;\n" -" \n" -" public Car(String manufacturer, boolean isRegistered) {\n" -" super();\n" -" this.manufacturer = manufacturer;\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"\n" -" @NotNull\n" -" public String getManufacturer() {\n" -" return manufacturer;\n" -" }\n" -"\n" -" public void setManufacturer(String manufacturer) {\n" -" this.manufacturer = manufacturer;\n" -" }\n" -"\n" -" @AssertTrue\n" -" public boolean isRegistered() {\n" -" return isRegistered;\n" -" }\n" -"\n" -" public void setRegistered(boolean isRegistered) {\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.AssertTrue;\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Car {\n" -"\n" -" private String manufacturer;\n" -"\n" -" private boolean isRegistered;\n" -" \n" -" public Car(String manufacturer, boolean isRegistered) {\n" -" super();\n" -" this.manufacturer = manufacturer;\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"\n" -" @NotNull\n" -" public String getManufacturer() {\n" -" return manufacturer;\n" -" }\n" -"\n" -" public void setManufacturer(String manufacturer) {\n" -" this.manufacturer = manufacturer;\n" -" }\n" -"\n" -" @AssertTrue\n" -" public boolean isRegistered() {\n" -" return isRegistered;\n" -" }\n" -"\n" -" public void setRegistered(boolean isRegistered) {\n" -" this.isRegistered = isRegistered;\n" -" }\n" -"}" - -#. Tag: para -#: usingvalidator.xml:121 -#, fuzzy, no-c-format -msgid "" -"When using property level constraints property access strategy is used to " -"access the value to be validated. This means the bean validation provider " -"accesses the state via the property accessor method. One advantage of " -"annotating properties instead of fields is that the constraints become part " -"of the constrained type's API that way and users are aware of the existing " -"constraints without having to examine the type's implementation." -msgstr "" -"当约束被定义在属性上的时候, 这个属性的值是通过属性访问策略来获取并验证的. 也" -"就是说Bean Validation的实现者会通过该属性的访问器来获取该属性的值并验证." - -#. Tag: para -#: usingvalidator.xml:130 -#, fuzzy, no-c-format -msgid "" -"It is recommended to stick either to field or property " -"annotations within one class. It is not recommended to annotate a field " -"and the accompanying getter method as this would cause " -"the field to be validated twice." -msgstr "" -"我们不推荐在一个类里面混合使用字段级约束和属性级约束!因为这样会导致字段被校验" -"两次." - -#. Tag: title -#: usingvalidator.xml:139 -#, no-c-format -msgid "Class-level constraints" -msgstr "类级别约束" - -#. Tag: para -#: usingvalidator.xml:142 -#, fuzzy, no-c-format -msgid "" -"Last but not least, a constraint can also be placed on class level. When a " -"constraint annotation is placed on this level the class instance itself " -"passed to the ConstraintValidator. Class level " -"constraints are useful if it is necessary to inspect more than a single " -"property of the class to validate it or if a correlation between different " -"state variables has to be evaluated. In we add the property passengers to the class " -"Car. We also add the constraint " -"PassengerCount on the class level. We will later see " -"how we can actually create this custom constraint (see ). For now it is enough to know that " -"PassengerCount will ensure that there cannot be more " -"passengers in a car than there are seats." -msgstr "" -"最后, 一个约束也能够被放在类级别上. 当一个约束被标注在一个类上的时候,这个类的" -"实例对象被传递给ConstraintValidator. 当需要同时校验多" -"个属性来验证一个对象或者一个属性在验证的时候需要另外的属性的信息的时候, 类级" -"别的约束会很有用. 在中, 我们给类" -"Car添加了一个passengers的属性. 并" -"且我们还标注了一个PassengerCount约束在类级别上. 稍后会" -"看到我们是如何创建这个自定义的约束的(). 现在,我们可以知道,PassengerCount会保证这个车里乘客的数量不会超过它的座位数." - -#. Tag: title -#: usingvalidator.xml:158 -#, no-c-format -msgid "Class level constraint" -msgstr "类级别约束" - -#. Tag: programlisting -#: usingvalidator.xml:160 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.Min;\n" -"import javax.validation.constraints.NotNull;\n" -"import javax.validation.constraints.Size;\n" -"\n" -"@PassengerCount\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" private String licensePlate;\n" -"\n" -" @Min(2)\n" -" private int seatCount;\n" -" \n" -" private List<Person> passengers;\n" -" \n" -" public Car(String manufacturer, String licencePlate, int seatCount) {\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.Min;\n" -"import javax.validation.constraints.NotNull;\n" -"import javax.validation.constraints.Size;\n" -"\n" -"@PassengerCount\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" private String manufacturer;\n" -"\n" -" @NotNull\n" -" @Size(min = 2, max = 14)\n" -" private String licensePlate;\n" -"\n" -" @Min(2)\n" -" private int seatCount;\n" -" \n" -" private List<Person> passengers;\n" -" \n" -" public Car(String manufacturer, String licencePlate, int seatCount) {\n" -" this.manufacturer = manufacturer;\n" -" this.licensePlate = licencePlate;\n" -" this.seatCount = seatCount;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" - -#. Tag: title -#: usingvalidator.xml:165 -#, no-c-format -msgid "Constraint inheritance" -msgstr "约束继承" - -#. Tag: para -#: usingvalidator.xml:167 -#, no-c-format -msgid "" -"When validating an object that implements an interface or extends another " -"class, all constraint annotations on the implemented interface and parent " -"class apply in the same manner as the constraints specified on the validated " -"object itself. To make things clearer let's have a look at the following " -"example:" -msgstr "" -"如果要验证的对象继承于某个父类或者实现了某个接口,那么定义在父类或者接口中的约" -"束会在验证这个对象的时候被自动加载,如同这些约束定义在这个对象所在的类中一样. " -"让我们来看看下面的示例:" - -#. Tag: title -#: usingvalidator.xml:174 -#, no-c-format -msgid "Constraint inheritance using RentalCar" -msgstr "约束继承" - -#. Tag: programlisting -#: usingvalidator.xml:176 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class RentalCar extends Car {\n" -"\n" -" private String rentalStation;\n" -" \n" -" public RentalCar(String manufacturer, String rentalStation) {\n" -" super(manufacturer);\n" -" this.rentalStation = rentalStation;\n" -" }\n" -" \n" -" @NotNull\n" -" public String getRentalStation() {\n" -" return rentalStation;\n" -" }\n" -"\n" -" public void setRentalStation(String rentalStation) {\n" -" this.rentalStation = rentalStation;\n" -" }\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class RentalCar extends Car {\n" -"\n" -" private String rentalStation;\n" -" \n" -" public RentalCar(String manufacturer, String rentalStation) {\n" -" super(manufacturer);\n" -" this.rentalStation = rentalStation;\n" -" }\n" -" \n" -" @NotNull\n" -" public String getRentalStation() {\n" -" return rentalStation;\n" -" }\n" -"\n" -" public void setRentalStation(String rentalStation) {\n" -" this.rentalStation = rentalStation;\n" -" }\n" -"}" - -#. Tag: para -#: usingvalidator.xml:179 -#, no-c-format -msgid "" -"Our well-known class Car is now extended by " -"RentalCar with the additional property " -"rentalStation. If an instance of RentalCar is validated, not only the @NotNull " -"constraint on rentalStation is validated, but also the " -"constraint on manufacturer from the parent class." -msgstr "" -"我们有了一个新的RentalCar类继承自前面我们已经见到的" -"Car, 这个子类中增加了一个rentalStation属性. 如果校验一个RentalCar的实例对象, 那么不" -"仅会验证属性rentalStation上的 @NotNull约束是否合法,还会校验父类中的manufacturer属性." - -#. Tag: para -#: usingvalidator.xml:187 -#, no-c-format -msgid "" -"The same would hold true, if Car were an interface " -"implemented by RentalCar." -msgstr "如果类Car是一个接口类型的话也是一样的效果." - -#. Tag: para -#: usingvalidator.xml:190 -#, no-c-format -msgid "" -"Constraint annotations are aggregated if methods are overridden. If " -"RentalCar would override the " -"getManufacturer() method from Car any constraints annotated at the overriding method would be " -"evaluated in addition to the @NotNull constraint from " -"the super-class." -msgstr "" -"如果类RentalCar 重写了父类Car的" -"getManufacturer()方法, 那么定义在父类的这个方法上的" -"约束和子类这个方法上定义的约束都会被校验." - -#. Tag: title -#: usingvalidator.xml:199 -#, no-c-format -msgid "Object graphs" -msgstr "对象图" - -#. Tag: para -#: usingvalidator.xml:201 -#, no-c-format -msgid "" -"The Bean Validation API does not only allow to validate single class " -"instances but also complete object graphs. To do so, just annotate a field " -"or property representing a reference to another object with " -"@Valid. If the parent object is validated, all " -"referenced objects annotated with @Valid will be " -"validated as well (as will be their children etc.). See ." -msgstr "" -"Bean Validation API不仅能够用来校验单个的实例对象,还能够用来校验完整的对象图." -"要使用这个功能,只需要在一个有关联关系的字段或者属性上标注@Valid. 这样,如果一个对象被校验,那么它的所有的标注了@Valid的关联对象都会被校验. 请看." - -#. Tag: title -#: usingvalidator.xml:210 -#, no-c-format -msgid "Class Person" -msgstr "Class Person" - -#. Tag: programlisting -#: usingvalidator.xml:212 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Person {\n" -"\n" -" @NotNull\n" -" private String name;\n" -" \n" -" public Person(String name) {\n" -" super();\n" -" this.name = name;\n" -" }\n" -"\n" -" public String getName() {\n" -" return name;\n" -" }\n" -"\n" -" public void setName(String name) {\n" -" this.name = name;\n" -" }\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Person {\n" -"\n" -" @NotNull\n" -" private String name;\n" -" \n" -" public Person(String name) {\n" -" super();\n" -" this.name = name;\n" -" }\n" -"\n" -" public String getName() {\n" -" return name;\n" -" }\n" -"\n" -" public void setName(String name) {\n" -" this.name = name;\n" -" }\n" -"}" - -#. Tag: title -#: usingvalidator.xml:216 -#, no-c-format -msgid "Adding a driver to the car" -msgstr "Adding a driver to the car" - -#. Tag: programlisting -#: usingvalidator.xml:218 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import javax.validation.Valid;\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" @Valid\n" -" private Person driver;\n" -" \n" -" public Car(Person driver) {\n" -" this.driver = driver;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import javax.validation.Valid;\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" @Valid\n" -" private Person driver;\n" -" \n" -" public Car(Person driver) {\n" -" this.driver = driver;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" - -#. Tag: para -#: usingvalidator.xml:221 -#, no-c-format -msgid "" -"If an instance of Car is validated, the referenced " -"Person object will be validated as well, as the " -"driver field is annotated with @Valid. Therefore the validation of a Car will " -"fail if the name field of the referenced " -"Person instance is null." -msgstr "" -"如果校验Car的实例对象的话,因为它的driver属性标注了@Valid, 那么关联的" -"Person也会被校验. 所以,如果对象Personname属性如果是null的话,那么校验" -"会失败." - -#. Tag: para -#: usingvalidator.xml:229 -#, no-c-format -msgid "" -"Object graph validation also works for collection-typed fields. That means " -"any attributes that" -msgstr "关联校验也适用于集合类型的字段, 也就是说,任何下列的类型:" - -#. Tag: para -#: usingvalidator.xml:234 -#, no-c-format -msgid "are arrays" -msgstr "数组" - -#. Tag: para -#: usingvalidator.xml:238 -#, no-c-format -msgid "" -"implement java.lang.Iterable (especially " -"Collection, List and " -"Set)" -msgstr "" -"实现了java.lang.Iterable接口( 例如" -"Collection, List 和 " -"Set)" - -#. Tag: para -#: usingvalidator.xml:244 -#, no-c-format -msgid "implement java.util.Map" -msgstr "实现了java.util.Map接口" - -#. Tag: para -#: usingvalidator.xml:248 -#, no-c-format -msgid "" -"can be annotated with @Valid, which will cause each " -"contained element to be validated, when the parent object is validated." -msgstr "" -"如果标注了@Valid, 那么当主对象被校验的时候,这些集合对" -"象中的元素都会被校验." - -#. Tag: title -#: usingvalidator.xml:253 -#, no-c-format -msgid "Car with a list of passengers" -msgstr "Car with a list of passengers" - -#. Tag: programlisting -#: usingvalidator.xml:255 -#, no-c-format -msgid "" -"package com.mycompany;\n" -"\n" -"import java.util.ArrayList;\n" -"import java.util.List;\n" -"\n" -"import javax.validation.Valid;\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" @Valid\n" -" private List<Person> passengers = new ArrayList<Person>();\n" -"\n" -" public Car(List<Person> passengers) {\n" -" this.passengers = passengers;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" -msgstr "" -"package com.mycompany;\n" -"\n" -"import java.util.ArrayList;\n" -"import java.util.List;\n" -"\n" -"import javax.validation.Valid;\n" -"import javax.validation.constraints.NotNull;\n" -"\n" -"public class Car {\n" -"\n" -" @NotNull\n" -" @Valid\n" -" private List<Person> passengers = new ArrayList<Person>();\n" -"\n" -" public Car(List<Person> passengers) {\n" -" this.passengers = passengers;\n" -" }\n" -"\n" -" //getters and setters ...\n" -"}" - -#. Tag: para -#: usingvalidator.xml:258 -#, no-c-format -msgid "" -"If a Car instance is validated, a " -"ConstraintValidation will be created, if any of the " -"Person objects contained in the passengers list has a null name." -msgstr "" -"当校验一个Car的实例的时候,如果passengers list中包含的任何一个Person对象没有名字的话," -"都会导致校验失败(a ConstraintValidation will be " -"created)." - -#. Tag: para -#: usingvalidator.xml:262 -#, no-c-format -msgid "" -"null values are getting ignored when validating " -"object graphs." -msgstr "对象图校验的时候是会被忽略null值的." - -#. Tag: title -#: usingvalidator.xml:269 -#, no-c-format -msgid "Validating constraints" -msgstr "校验约束" - -#. Tag: para -#: usingvalidator.xml:271 -#, no-c-format -msgid "" -"The Validator interface is the main entry point to " -"Bean Validation. In we will " -"first show how to obtain an Validator instance. " -"Afterwards we will learn how to use the different methods of the " -"Validator interface." -msgstr "" -"Validator 是Bean Validation中最主要的接口, 我们会在" -"中详细介绍如何获取一个" -"Validator的实例, 现在先让我们来看看如何使用" -"Validator接口中的各个方法. " - -#. Tag: title -#: usingvalidator.xml:278 -#, no-c-format -msgid "Obtaining a Validator instance" -msgstr "获取一个Validator的实例" - -#. Tag: para -#: usingvalidator.xml:280 -#, no-c-format -msgid "" -"The first step towards validating an entity instance is to get hold of a " -"Validator instance. The road to this instance leads " -"via the Validation class and a " -"ValidatorFactory. The easiest way is to use the " -"static Validation.buildDefaultValidatorFactory() " -"method:" -msgstr "" -"对一个实体对象验证之前首先需要有个Validator对象, 而这" -"个对象是需要通过Validation 类和 " -"ValidatorFactory来创建的. 最简单的方法是调用" -"Validation.buildDefaultValidatorFactory() 这个静态方" -"法. " - -#. Tag: title -#: usingvalidator.xml:289 -#, no-c-format -msgid "Validation.buildDefaultValidatorFactory()" -msgstr "Validation.buildDefaultValidatorFactory()" - -#. Tag: programlisting -#: usingvalidator.xml:291 -#, no-c-format -msgid "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"Validator validator = factory.getValidator();" -msgstr "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"Validator validator = factory.getValidator();" - -#. Tag: para -#: usingvalidator.xml:294 -#, no-c-format -msgid "" -"For other ways of obtaining a Validator instance see . For now we just want to see how we can use " -"the Validator instance to validate entity instances." -msgstr "" -"介绍了其他的获取Validator实例的方" -"法. 现在我们的目标是学习如何使用Validator 来校验实体对" -"象." - -#. Tag: title -#: usingvalidator.xml:301 -#, no-c-format -msgid "Validator methods" -msgstr "Validator中的方法" - -#. Tag: para -#: usingvalidator.xml:303 -#, no-c-format -msgid "" -"The Validator interface contains three methods that " -"can be used to either validate entire entities or just a single properties " -"of the entity." -msgstr "" -"Validator中有三个方法能够被用来校验整个实体对象或者实" -"体对象中的属性." - -#. Tag: para -#: usingvalidator.xml:307 -#, no-c-format -msgid "" -"All three methods return a Set<ConstraintViolation>. The set is empty, if the validation succeeds. Otherwise a " -"ConstraintViolation instance is added for each " -"violated constraint." -msgstr "" -"这三个方法都会返回一个Set<ConstraintViolation>对" -"象, 如果整个验证过程没有发现问题的话,那么这个set是空的, 否则, 每个违反约束的" -"地方都会被包装成一个ConstraintViolation的实例然后添加" -"到set当中. " - -#. Tag: para -#: usingvalidator.xml:313 -#, fuzzy, no-c-format -msgid "" -"All the validation methods have a var-args parameter which can be used to " -"specify, which validation groups shall be considered when performing the " -"validation. If the parameter is not specified the default validation group " -"(javax.validation.groups.Default) will be used. We " -"will go into more detail on the topic of validation groups in " -msgstr "" -"所有的校验方法都接收零个或多个用来定义此次校验是基于哪个校验组的参数. 如果没" -"有给出这个参数的话, 那么此次校验将会基于默认的校验组 (javax." -"validation.groups.Default). " - -#. Tag: methodname -#: usingvalidator.xml:322 -#, no-c-format -msgid "validate" -msgstr "validate" - -#. Tag: para -#: usingvalidator.xml:324 -#, no-c-format -msgid "" -"Use the validate() method to perform validation of " -"all constraints of a given entity instance (see )." -msgstr "" -"使用validate()方法对一个给定的实体对象中定义的所有约" -"束条件进行校验 ( )." - -#. Tag: title -#: usingvalidator.xml:329 -#, no-c-format -msgid "Usage of Validator.validate()" -msgstr "Validator.validate() 使用方法" - -#. Tag: programlisting -#: usingvalidator.xml:332 -#, no-c-format -msgid "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"Validator validator = factory.getValidator();\n" -"\n" -"Car car = new Car(null);\n" -"\n" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validate(car);\n" -"\n" -"assertEquals(1, constraintViolations.size());\n" -"assertEquals(\"may not be null\", constraintViolations.iterator().next()." -"getMessage());" -msgstr "" -"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n" -"Validator validator = factory.getValidator();\n" -"\n" -"Car car = new Car(null);\n" -"\n" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validate(car);\n" -"\n" -"assertEquals(1, constraintViolations.size());\n" -"assertEquals(\"may not be null\", constraintViolations.iterator().next()." -"getMessage());" - -#. Tag: methodname -#: usingvalidator.xml:337 -#, no-c-format -msgid "validateProperty" -msgstr "validateProperty" - -#. Tag: para -#: usingvalidator.xml:339 -#, no-c-format -msgid "" -"With help of the validateProperty() a single named " -"property of a given object can be validated. The property name is the " -"JavaBeans property name." -msgstr "" -"通过validateProperty()可以对一个给定实体对象的单个属" -"性进行校验. 其中属性名称需要符合JavaBean规范中定义的属性名称." - -#. Tag: title -#: usingvalidator.xml:344 -#, no-c-format -msgid "Usage of Validator.validateProperty()" -msgstr "Validator.validateProperty()使用方法" - -#. Tag: programlisting -#: usingvalidator.xml:347 -#, no-c-format -msgid "" -"Validator validator = Validation.buildDefaultValidatorFactory().getValidator" -"();\n" -"\n" -"Car car = new Car(null);\n" -"\n" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validateProperty(car, \"manufacturer\");\n" -"\n" -"assertEquals(1, constraintViolations.size());\n" -"assertEquals(\"may not be null\", constraintViolations.iterator().next()." -"getMessage());" -msgstr "" -"Validator validator = Validation.buildDefaultValidatorFactory().getValidator" -"();\n" -"\n" -"Car car = new Car(null);\n" -"\n" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validateProperty(car, \"manufacturer\");\n" -"\n" -"assertEquals(1, constraintViolations.size());\n" -"assertEquals(\"may not be null\", constraintViolations.iterator().next()." -"getMessage());" - -#. Tag: para -#: usingvalidator.xml:350 -#, no-c-format -msgid "" -"Validator.validateProperty is for example used in " -"the integration of Bean Validation into JSF 2 (see )." -msgstr "" -"例如, Validator.validateProperty可以被用在把Bean " -"Validation集成进JSF 2中的时候使用 (请参考 )." - -#. Tag: methodname -#: usingvalidator.xml:356 -#, no-c-format -msgid "validateValue" -msgstr "validateValue" - -#. Tag: para -#: usingvalidator.xml:358 -#, no-c-format -msgid "" -"Using the validateValue() method you can check, " -"whether a single property of a given class can be validated successfully, if " -"the property had the specified value:" -msgstr "" -"通过validateValue() 方法,你能够校验如果把一个特定的" -"值赋给一个类的某一个属性的话,是否会违反此类中定义的约束条件." - -#. Tag: title -#: usingvalidator.xml:363 -#, no-c-format -msgid "Usage of Validator.validateValue()" -msgstr "Validator.validateValue() 使用方法" - -#. Tag: programlisting -#: usingvalidator.xml:366 -#, no-c-format -msgid "" -"Validator validator = Validation.buildDefaultValidatorFactory().getValidator" -"();\n" -"\n" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validateValue(Car.class, \"manufacturer\", null);\n" -"\n" -"assertEquals(1, constraintViolations.size());\n" -"assertEquals(\"may not be null\", constraintViolations.iterator().next()." -"getMessage());" -msgstr "" -"Validator validator = Validation.buildDefaultValidatorFactory().getValidator" -"();\n" -"\n" -"Set<ConstraintViolation<Car>> constraintViolations = validator." -"validateValue(Car.class, \"manufacturer\", null);\n" -"\n" -"assertEquals(1, constraintViolations.size());\n" -"assertEquals(\"may not be null\", constraintViolations.iterator().next()." -"getMessage());" - -#. Tag: para -#: usingvalidator.xml:370 -#, no-c-format -msgid "" -"@Valid is not honored by validateProperty" -"() or validateValue()." -msgstr "" -"validateProperty()validateValue() 会忽略被验证属性上定义的@Valid." - -#. Tag: title -#: usingvalidator.xml:378 -#, no-c-format -msgid "ConstraintViolation methods" -msgstr "ConstraintViolation 中的方法" - -#. Tag: para -#: usingvalidator.xml:380 -#, no-c-format -msgid "" -"Now it is time to have a closer look at what a " -"ConstraintViolation. Using the different methods of " -"ConstraintViolation a lot of useful information about " -"the cause of the validation failure can be determined. gives an overview of these methods:" -msgstr "" -"现在是时候看看究竟ConstraintViolation是什么了. " -"ConstraintViolation中包含了很多方法能够帮你快速定位究" -"竟是什么导致了校验失败. 列出了" -"这些方法:" - -#. Tag: title -#: usingvalidator.xml:388 -#, no-c-format -msgid "The various ConstraintViolation methods" -msgstr "ConstraintViolation 中的方法" - -#. Tag: entry -#: usingvalidator.xml:394 -#, no-c-format -msgid "Method" -msgstr "方法名" - -#. Tag: entry -#: usingvalidator.xml:396 -#, no-c-format -msgid "Usage" -msgstr "作用" - -#. Tag: entry -#: usingvalidator.xml:398 -#, no-c-format -msgid "Example (referring to )" -msgstr "示例 (请参考)" - -#. Tag: methodname -#: usingvalidator.xml:405 -#, no-c-format -msgid "getMessage()" -msgstr "getMessage()" - -#. Tag: entry -#: usingvalidator.xml:407 -#, no-c-format -msgid "The interpolated error message." -msgstr "获取(经过翻译的)校验错误信息" - -#. Tag: entry -#: usingvalidator.xml:409 -#, no-c-format -msgid "may not be null" -msgstr "may not be null" - -#. Tag: methodname -#: usingvalidator.xml:413 -#, no-c-format -msgid "getMessageTemplate()" -msgstr "getMessageTemplate()" - -#. Tag: entry -#: usingvalidator.xml:415 -#, no-c-format -msgid "The non-interpolated error message." -msgstr "获取错误信息模版" - -#. Tag: entry -#: usingvalidator.xml:417 -#, no-c-format -msgid "{javax.validation.constraints.NotNull.message}" -msgstr "{javax.validation.constraints.NotNull.message}" - -#. Tag: methodname -#: usingvalidator.xml:421 -#, no-c-format -msgid "getRootBean()" -msgstr "getRootBean()" - -#. Tag: entry -#: usingvalidator.xml:423 -#, no-c-format -msgid "The root bean being validated." -msgstr "获取被校验的根实体对象" - -#. Tag: entry -#: usingvalidator.xml:425 usingvalidator.xml:443 -#, no-c-format -msgid "car" -msgstr "car" - -#. Tag: methodname -#: usingvalidator.xml:429 -#, no-c-format -msgid "getRootBeanClass()" -msgstr "getRootBeanClass()" - -#. Tag: entry -#: usingvalidator.xml:431 -#, no-c-format -msgid "The class of the root bean being validated." -msgstr "获取被校验的根实体类." - -#. Tag: entry -#: usingvalidator.xml:433 -#, no-c-format -msgid "Car.class" -msgstr "Car.class" - -#. Tag: methodname -#: usingvalidator.xml:437 -#, no-c-format -msgid "getLeafBean()" -msgstr "getLeafBean()" - -#. Tag: entry -#: usingvalidator.xml:439 -#, no-c-format -msgid "" -"If a bean constraint, the bean instance the constraint is applied on. If a " -"property constraint, the bean instance hosting the property the constraint " -"is applied on." -msgstr "" -"如果约束是添加在一个bean(实体对象)上的,那么则返回这个bean的实例, 如果是约束是" -"定义在一个属性上的, 则返回这个属性所属的bean的实例对象. " - -#. Tag: methodname -#: usingvalidator.xml:447 -#, no-c-format -msgid "getPropertyPath()" -msgstr "getPropertyPath()" - -#. Tag: entry -#: usingvalidator.xml:449 -#, no-c-format -msgid "The property path to the value from root bean." -msgstr "从被验证的根对象到被验证的属性的路径." - -#. Tag: methodname -#: usingvalidator.xml:455 -#, no-c-format -msgid "getInvalidValue()" -msgstr "getInvalidValue()" - -#. Tag: entry -#: usingvalidator.xml:457 -#, no-c-format -msgid "The value failing to pass the constraint." -msgstr "倒是校验失败的值." - -#. Tag: entry -#: usingvalidator.xml:459 -#, no-c-format -msgid "passengers" -msgstr "passengers" - -#. Tag: methodname -#: usingvalidator.xml:463 -#, no-c-format -msgid "getConstraintDescriptor()" -msgstr "getConstraintDescriptor()" - -#. Tag: entry -#: usingvalidator.xml:465 -#, no-c-format -msgid "Constraint metadata reported to fail." -msgstr "导致校验失败的约束定义." - -#. Tag: title -#: usingvalidator.xml:475 -#, no-c-format -msgid "Message interpolation" -msgstr "验证失败提示信息解析" - -#. Tag: para -#: usingvalidator.xml:477 -#, no-c-format -msgid "" -"As we will see in each " -"constraint definition must define a default message descriptor. This message " -"can be overridden at declaration time using the message attribute of the constraint. You can see this in . This message descriptors get interpolated when a " -"constraint validation fails using the configured " -"MessageInterpolator. The interpolator will try to " -"resolve any message parameters, meaning string literals enclosed in braces. " -"In order to resolve these parameters Hibernate Validator's default " -"MessageInterpolator first recursively resolves " -"parameters against a custom ResourceBundle called " -"ValidationMessages.properties at the root of the " -"classpath (It is up to you to create this file). If no further replacements " -"are possible against the custom bundle the default " -"ResourceBundle under /org/hibernate/" -"validator/ValidationMessages.properties gets evaluated. If a " -"replacement occurs against the default bundle the algorithm looks again at " -"the custom bundle (and so on). Once no further replacements against these " -"two resource bundles are possible remaining parameters are getting resolved " -"against the attributes of the constraint to be validated." -msgstr "" -"在中,我们会看到,每个约束定义中" -"都包含有一个用于提示验证结果的消息模版, 并且在声明一个约束条件的时候,你可以通" -"过这个约束中的message属性来重写默认的消息模版, 可以" -"参考. 如果在校验的时候,这个约束条件没有通" -"过,那么你配置的MessageInterpolator会被用来当成解析器来" -"解析这个约束中定义的消息模版, 从而得到最终的验证失败提示信息. 这个解析器会尝" -"试解析模版中的占位符( 大括号括起来的字符串 ). 其中, Hibernate Validator中默认" -"的解析器 (MessageInterpolator) 会先在类路径下找名称为" -"ValidationMessages.properties的" -"ResourceBundle, 然后将占位符和这个文件中定义的resource" -"进行匹配,如果匹配不成功的话,那么它会继续匹配Hibernate Validator自带的位于" -"/org/hibernate/validator/ValidationMessages.properties的" -"ResourceBundle, 依次类推,递归的匹配所有的占位符." - -#. Tag: para -#: usingvalidator.xml:500 -#, no-c-format -msgid "" -"Since the braces { and } have special meaning in the messages they need to " -"be escaped if they are used literally. The following The following rules " -"apply:" -msgstr "" -"因为大括号{ 在这里是特殊字符,所以,你可以通过使用反斜线来对其进行转义, 例如:" - -#. Tag: para -#: usingvalidator.xml:504 -#, no-c-format -msgid "\\{ is considered as the literal {" -msgstr "\\{ 被转义成 {" - -#. Tag: para -#: usingvalidator.xml:508 -#, no-c-format -msgid "\\} is considered as the literal }" -msgstr "\\} 被转义成 }" - -#. Tag: para -#: usingvalidator.xml:512 -#, no-c-format -msgid "\\\\ is considered as the literal \\" -msgstr "\\\\ 被转义成 \\" - -#. Tag: para -#: usingvalidator.xml:516 -#, no-c-format -msgid "" -"If the default message interpolator does not fit your requirements it is " -"possible to plug a custom MessageInterpolator when " -"the ValidatorFactory gets created. This can be seen " -"in ." -msgstr "" -"如果默认的消息解析器不能够满足你的需求,那么你也可以在创建" -"ValidatorFactory的时候, 将其替换为一个你自定义的" -"MessageInterpolator, 具体请参考 ." - -#. Tag: title -#: usingvalidator.xml:525 -#, no-c-format -msgid "Built-in constraints" -msgstr "内置的约束条件" - -#. Tag: para -#: usingvalidator.xml:527 -#, no-c-format -msgid "" -"Hibernate Validator comprises a basic set of commonly used constraints. " -"These are foremost the constraints defined by the Bean Validation " -"specification (see ). " -"Additionally, Hibernate Validator provides useful custom constraints (see " -" and )." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:535 usingvalidator.xml:554 -#, fuzzy, no-c-format -msgid "Bean Validation constraints" -msgstr "校验约束" - -#. Tag: para -#: usingvalidator.xml:537 -#, no-c-format -msgid "" -"shows purpose and supported data types of all constraints specified in the " -"Bean Validation API. All these constraints apply to the field/property " -"level, there are no class-level constraints defined in the Bean Validation " -"specification. If you are using the Hibernate object-relational mapper, some " -"of the constraints are taken into account when creating the DDL for your " -"model (see column \"Hibernate metadata impact\")." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:546 -#, no-c-format -msgid "" -"Hibernate Validator allows some constraints to be applied to more data types " -"than required by the Bean Validation specification (e.g. @Max can be applied " -"to Strings). Relying on this feature can impact " -"portability of your application between Bean Validation providers." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:567 usingvalidator.xml:827 usingvalidator.xml:1025 -#, no-c-format -msgid "Annotation" -msgstr "Annotation" - -#. Tag: entry -#: usingvalidator.xml:569 usingvalidator.xml:829 usingvalidator.xml:1027 -#, no-c-format -msgid "Supported data types" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:571 usingvalidator.xml:831 usingvalidator.xml:1029 -#, no-c-format -msgid "Use" -msgstr "作用" - -#. Tag: entry -#: usingvalidator.xml:573 usingvalidator.xml:833 usingvalidator.xml:1033 -#, fuzzy, no-c-format -msgid "Hibernate metadata impact" -msgstr "对Hibernate Core中的元数据的影响" - -#. Tag: entry -#: usingvalidator.xml:579 -#, no-c-format -msgid "@AssertFalse" -msgstr "@AssertFalse" - -#. Tag: entry -#: usingvalidator.xml:581 usingvalidator.xml:593 -#, no-c-format -msgid "Boolean, boolean" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:584 -#, fuzzy, no-c-format -msgid "Checks that the annotated element is false." -msgstr "检查被标注的值是否为false." - -#. Tag: entry -#: usingvalidator.xml:587 usingvalidator.xml:599 usingvalidator.xml:619 -#: usingvalidator.xml:639 usingvalidator.xml:675 usingvalidator.xml:733 -#: usingvalidator.xml:749 usingvalidator.xml:762 usingvalidator.xml:789 -#: usingvalidator.xml:849 usingvalidator.xml:863 usingvalidator.xml:900 -#: usingvalidator.xml:913 usingvalidator.xml:926 usingvalidator.xml:942 -#: usingvalidator.xml:959 usingvalidator.xml:976 usingvalidator.xml:994 -#: usingvalidator.xml:1049 usingvalidator.xml:1063 usingvalidator.xml:1078 -#, no-c-format -msgid "none" -msgstr "没有" - -#. Tag: entry -#: usingvalidator.xml:591 -#, no-c-format -msgid "@AssertTrue" -msgstr "@AssertTrue" - -#. Tag: entry -#: usingvalidator.xml:596 -#, fuzzy, no-c-format -msgid "Checks that the annotated element is true." -msgstr "检查被标注的值是否为true." - -#. Tag: entry -#: usingvalidator.xml:603 -#, no-c-format -msgid "@DecimalMax" -msgstr "@DecimalMax" - -#. Tag: entry -#: usingvalidator.xml:605 usingvalidator.xml:645 -#, fuzzy, no-c-format -msgid "" -"BigDecimal, BigInteger, " -"String, byte, " -"short, int, long and the respective wrappers of the primitive types. Additionally " -"supported by HV: any sub-type of Number and " -"CharSequence." -msgstr "" -"字段或属性. 支持类型包括BigDecimal, " -"BigInteger, String, " -"byte, short, int, long和其各自对应的包装器类型." - -#. Tag: entry -#: usingvalidator.xml:614 -#, no-c-format -msgid "" -"The annotated element must be a number whose value must be lower or equal to " -"the specified maximum. The parameter value is the string representation of " -"the max value according to the BigDecimal string " -"representation." -msgstr "" -"被标注的值必须不大于约束中指定的最大值. 这个约束的参数是一个通过" -"BigDecimal定义的最大值的字符串表示." - -#. Tag: entry -#: usingvalidator.xml:623 -#, no-c-format -msgid "@DecimalMin" -msgstr "@DecimalMin" - -#. Tag: entry -#: usingvalidator.xml:625 -#, fuzzy, no-c-format -msgid "" -"BigDecimal, BigInteger, " -"String, byte, " -"short, int, long and the respective wrappers of the primitive types. Additionally " -"supported by HV: any sub-type of Number and " -"CharSequence." -msgstr "" -"字段或属性. 支持类型包括BigDecimal, " -"BigInteger, String, " -"byte, short, int, long和其各自对应的包装器类型." - -#. Tag: entry -#: usingvalidator.xml:634 -#, no-c-format -msgid "" -"The annotated element must be a number whose value must be higher or equal " -"to the specified minimum. The parameter value is the string representation " -"of the min value according to the BigDecimal string " -"representation." -msgstr "" -"被标注的值必须不小于约束中指定的最小值. 这个约束的参数是一个通过" -"BigDecimal定义的最小值的字符串表示." - -#. Tag: entry -#: usingvalidator.xml:643 -#, no-c-format -msgid "@Digits(integer=, fraction=)" -msgstr "@Digits(integer=, fraction=)" - -#. Tag: entry -#: usingvalidator.xml:654 -#, fuzzy, no-c-format -msgid "" -"Checks whether the annoted value is a number having up to integer digits and fraction fractional digits." -msgstr "" -"检查此值是否是一个数字,并且这个数字的整数部分不超过integer" -"定义的位数, 和小数部分不超过fraction 定义的位数." - -#. Tag: entry -#: usingvalidator.xml:658 -#, no-c-format -msgid "Define column precision and scale." -msgstr "对应的数据库表字段会被设置精度(precision)和准度(scale)." - -#. Tag: entry -#: usingvalidator.xml:662 -#, no-c-format -msgid "@Future" -msgstr "@Future" - -#. Tag: entry -#: usingvalidator.xml:664 usingvalidator.xml:739 -#, no-c-format -msgid "" -"java.util.Date, java.util.Calendar; Additionally supported by HV, if the Joda Time date/time API is on the class " -"path: any implementations of ReadablePartial and " -"ReadableInstant." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:672 -#, no-c-format -msgid "Checks whether the annotated date is in the future." -msgstr "检查给定的日期是否比现在晚." - -#. Tag: entry -#: usingvalidator.xml:679 -#, no-c-format -msgid "@Max" -msgstr "@Max" - -#. Tag: entry -#: usingvalidator.xml:681 -#, fuzzy, no-c-format -msgid "" -"BigDecimal, BigInteger, " -"byte, short, int, long and the respective wrappers of the " -"primitive types. Additionally supported by HV: any sub-type " -"ofCharSequence (the numeric value represented by the " -"character sequence is evaluated), any sub-type of Number." -msgstr "" -"字段或属性. 支持类型包括BigDecimal, " -"BigInteger, String, " -"byte, short, int, long和其各自对应的包装器类型." - -#. Tag: entry -#: usingvalidator.xml:690 -#, no-c-format -msgid "" -"Checks whether the annotated value is less than or equal to the specified " -"maximum." -msgstr "检查该值是否小于或等于约束条件中指定的最大值." - -#. Tag: entry -#: usingvalidator.xml:693 usingvalidator.xml:711 -#, no-c-format -msgid "Add a check constraint on the column." -msgstr "会给对应的数据库表字段添加一个check的约束条件." - -#. Tag: entry -#: usingvalidator.xml:697 -#, no-c-format -msgid "@Min" -msgstr "@Min" - -#. Tag: entry -#: usingvalidator.xml:699 -#, fuzzy, no-c-format -msgid "" -"BigDecimal, BigInteger, " -"byte, short, int, long and the respective wrappers of the " -"primitive types. Additionally supported by HV: any sub-type of " -"CharSequence (the numeric value represented by the " -"char sequence is evaluated), any sub-type of Number." -msgstr "" -"字段或属性. 支持类型包括BigDecimal, " -"BigInteger, String, " -"byte, short, int, long和其各自对应的包装器类型." - -#. Tag: entry -#: usingvalidator.xml:708 -#, no-c-format -msgid "" -"Checks whether the annotated value is higher than or equal to the specified " -"minimum." -msgstr "检查该值是否大于或等于约束条件中规定的最小值." - -#. Tag: entry -#: usingvalidator.xml:715 -#, no-c-format -msgid "@NotNull" -msgstr "@NotNull" - -#. Tag: entry -#: usingvalidator.xml:717 usingvalidator.xml:728 usingvalidator.xml:965 -#, fuzzy, no-c-format -msgid "Any type" -msgstr "类" - -#. Tag: entry -#: usingvalidator.xml:719 -#, fuzzy, no-c-format -msgid "Checks that the annotated value is not null." -msgstr "检查该值不为null.." - -#. Tag: entry -#: usingvalidator.xml:722 -#, no-c-format -msgid "Column(s) are not null." -msgstr "对应的表字段不允许为null." - -#. Tag: entry -#: usingvalidator.xml:726 -#, no-c-format -msgid "@Null" -msgstr "@Null" - -#. Tag: entry -#: usingvalidator.xml:730 -#, fuzzy, no-c-format -msgid "Checks that the annotated value is null." -msgstr "检查该值应该为null." - -#. Tag: entry -#: usingvalidator.xml:737 -#, no-c-format -msgid "@Past" -msgstr "@Past" - -#. Tag: entry -#: usingvalidator.xml:747 -#, no-c-format -msgid "Checks whether the annotated date is in the past." -msgstr "检查标注对象中的值表示的日期比当前早." - -#. Tag: entry -#: usingvalidator.xml:753 -#, no-c-format -msgid "@Pattern(regex=, flag=)" -msgstr "@Pattern(regex=, flag=)" - -#. Tag: entry -#: usingvalidator.xml:755 -#, no-c-format -msgid "" -"String. Additionally supported by HV: any sub-type of " -"CharSequence." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:758 -#, no-c-format -msgid "" -"Checks if the annotated string matches the regular expression " -"regex considering the given flag match." -msgstr "" -"检查该字符串是否能够在match指定的情况下被" -"regex定义的正则表达式匹配." - -#. Tag: entry -#: usingvalidator.xml:766 -#, no-c-format -msgid "@Size(min=, max=)" -msgstr "@Size(min=, max=)" - -#. Tag: entry -#: usingvalidator.xml:768 -#, fuzzy, no-c-format -msgid "" -"String, Collection, " -"Map and arrays. Additionally " -"supported by HV: any sub-type of CharSequence." -msgstr "字段或属性. 支持的类型包括String, Collection, Map 和数组." - -#. Tag: entry -#: usingvalidator.xml:773 -#, fuzzy, no-c-format -msgid "" -"Checks if the annotated element's size is between min and max (inclusive)." -msgstr "检查该值的size是否在[min, max)之间." - -#. Tag: entry -#: usingvalidator.xml:776 usingvalidator.xml:875 -#, no-c-format -msgid "Column length will be set to max." -msgstr "对应的数据库表字段的长度会被设置成约束中定义的最大值." - -#. Tag: entry -#: usingvalidator.xml:780 -#, no-c-format -msgid "@Valid" -msgstr "@Valid" - -#. Tag: entry -#: usingvalidator.xml:782 -#, no-c-format -msgid "Any non-primitive type" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:784 -#, no-c-format -msgid "" -"Performs validation recursively on the associated object. If the object is a " -"collection or an array, the elements are validated recursively. If the " -"object is a map, the value elements are validated recursively." -msgstr "" -"递归的对关联对象进行校验, 如果关联对象是个集合或者数组, 那么对其中的元素进行" -"递归校验,如果是一个map,则对其中的值部分进行校验." - -#. Tag: para -#: usingvalidator.xml:796 -#, fuzzy, no-c-format -msgid "" -"On top of the parameters indicated in each constraint supports the parameters message, " -"groups and payload. This is a " -"requirement of the Bean Validation specification." -msgstr "" -"除了中列出的各个约束包含的参数" -"外,所有的约束条件还都有message, groupspayload三个参数, 这个是Bean Validation " -"规范规定的." - -#. Tag: title -#: usingvalidator.xml:805 -#, fuzzy, no-c-format -msgid "Additional constraints" -msgstr "内置的约束条件" - -#. Tag: para -#: usingvalidator.xml:807 -#, no-c-format -msgid "" -"In addition to the constraints defined by the Bean Validation API Hibernate " -"Validator provides several useful custom constraints which are listed in " -". With one exception also these " -"constraints apply to the field/property level, only @ScriptAssert is a class-" -"level constraint." -msgstr "" - -#. Tag: title -#: usingvalidator.xml:814 -#, fuzzy, no-c-format -msgid "Custom constraints" -msgstr "内置的约束条件" - -#. Tag: entry -#: usingvalidator.xml:839 -#, no-c-format -msgid "@CreditCardNumber" -msgstr "@CreditCardNumber" - -#. Tag: classname -#: usingvalidator.xml:841 usingvalidator.xml:855 usingvalidator.xml:869 -#: usingvalidator.xml:882 usingvalidator.xml:906 usingvalidator.xml:948 -#: usingvalidator.xml:982 usingvalidator.xml:1041 usingvalidator.xml:1055 -#: usingvalidator.xml:1069 -#, fuzzy, no-c-format -msgid "CharSequence" -msgstr "校验组序列" - -#. Tag: entry -#: usingvalidator.xml:843 -#, fuzzy, no-c-format -msgid "" -"Checks that the annotated character sequence passes the Luhn checksum test. " -"Note, this validation aims to check for user mistakes, not credit card " -"validity! See also Anatomy of Credit Card Numbers." -msgstr "" -"检查被标注的字符串能否通过Luhn Checksum test. 注意, 这个约束条件是为了防止用" -"户手误, 并不对信用卡有效性进行检测. 请参考Anatomy of Credit Card Numbers." - -#. Tag: entry -#: usingvalidator.xml:853 -#, no-c-format -msgid "@Email" -msgstr "@Email" - -#. Tag: entry -#: usingvalidator.xml:857 -#, fuzzy, no-c-format -msgid "" -"Checks whether the specified character sequence is a valid email address. " -"The optional parameters regexp and flags allow to specify an additional regular expression (including " -"regular expression flags) which the email must match." -msgstr "" -"判断该值是否是一个有效的URL, 如果给出了约束中的protocol, hostport 参数的" -"话,那个被校验的值需要和其匹配." - -#. Tag: entry -#: usingvalidator.xml:867 -#, no-c-format -msgid "@Length(min=, max=)" -msgstr "@Length(min=, max=)" - -#. Tag: entry -#: usingvalidator.xml:871 -#, fuzzy, no-c-format -msgid "" -"Validates that the annotated character sequence is between min and max included." -msgstr "" -"检查该字符串的长度是否在minmax规定的范围内." - -#. Tag: entry -#: usingvalidator.xml:879 -#, no-c-format -msgid "" -"@ModCheck(modType=, multiplier=, startIndex=, endIndex=, " -"checkDigitPosition=, ignoreNonDigitCharacters=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:884 -#, no-c-format -msgid "" -"Checks that the digits within the annotated character sequence pass the mod " -"10 or mod 11 checksum algorithm. modType is used to " -"select the modulo type and the multiplier determines " -"the algorithm specific multiplier (see also Luhn algorithm). startIndex and endIndex allow to only run the modulo " -"algorithm on the specified sub-string. checkDigitPosition allows to use an arbitrary digit within the character sequence to " -"be the check digit. If not specified it is assumed that the check digit is " -"part of the specified range. Last but not least, " -"ignoreNonDigitCharacters allows to ignore non digit " -"characters." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:904 -#, no-c-format -msgid "@NotBlank" -msgstr "@NotBlank" - -#. Tag: entry -#: usingvalidator.xml:908 -#, fuzzy, no-c-format -msgid "" -"Checks that the annotated character sequence is not null and the trimmed " -"length is greater than 0. The difference to @NotEmpty is that this " -"constraint can only be applied on strings and that trailing whitespaces are " -"ignored." -msgstr "" -"检查该字符串不为null,并且不是空字符串. 本约束和下面的@NotEmpty的不同之处在于," -"本约束只能被用在字符串类型上,并且会忽略字符串尾部的空白字符." - -#. Tag: entry -#: usingvalidator.xml:917 -#, no-c-format -msgid "@NotEmpty" -msgstr "@NotEmpty" - -#. Tag: entry -#: usingvalidator.xml:919 -#, fuzzy, no-c-format -msgid "" -"CharSequence, Collection, " -"Map and arrays" -msgstr "字段或属性. 支持的类型包括String, Collection, Map 和数组." - -#. Tag: entry -#: usingvalidator.xml:923 -#, fuzzy, no-c-format -msgid "" -"Checks whether the annotated element is not null nor " -"empty." -msgstr "检查该值不为null同时也不为空." - -#. Tag: entry -#: usingvalidator.xml:930 -#, no-c-format -msgid "@Range(min=, max=)" -msgstr "@Range(min=, max=)" - -#. Tag: entry -#: usingvalidator.xml:932 -#, fuzzy, no-c-format -msgid "" -"BigDecimal, BigInteger, " -"CharSequence, byte, " -"short, int, long and the respective wrappers of the primitive types" -msgstr "" -"字段或属性. 支持类型包括BigDecimal, " -"BigInteger, String, " -"byte, short, int, long和其各自对应的包装器类型." - -#. Tag: entry -#: usingvalidator.xml:939 -#, fuzzy, no-c-format -msgid "" -"Checks whether the annotated value lies between (inclusive) the specified " -"minimum and maximum." -msgstr "检查该值是否在[min, max)之间" - -#. Tag: entry -#: usingvalidator.xml:946 -#, no-c-format -msgid "@SafeHtml(whitelistType=, additionalTags=)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:950 -#, no-c-format -msgid "" -"Checks whether the annotated value contains potentially malicious fragments " -"such as <script/>. In order to use this constraint, the " -"jsoup library must be part of the " -"class path. With the whitelistType attribute " -"predefined whitelist types can be chosen. You can also specify additional " -"html tags for the whitelist with the additionalTags " -"attribute." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:963 -#, no-c-format -msgid "@ScriptAssert(lang=, script=, alias=)" -msgstr "@ScriptAssert(lang=, script=, alias=)" - -#. Tag: entry -#: usingvalidator.xml:967 -#, fuzzy, no-c-format -msgid "" -"Checks whether the given script can successfully be evaluated against the " -"annotated element. In order to use this constraint, an implementation of the " -"Java Scripting API as defined by JSR 223 (\"Scripting for the " -"JavaTM Platform\") must part of the class path. " -"The expressions to be evaluated can be written in any scripting or " -"expression language, for which a JSR 223 compatible engine can be found in " -"the class path." -msgstr "" -"要使用这个约束条件,必须先要保证Java Scripting API 即JSR 223 (\"Scripting for " -"the JavaTM Platform\")的实现在类路径当中. 如果使用" -"的时Java 6的话,则不是问题, 如果是老版本的话, 那么需要把 JSR 223的实现添加进类" -"路径. 这个约束条件中的表达式可以使用任何兼容JSR 223的脚本来编写. (更多信息请" -"参考javadoc)" - -#. Tag: entry -#: usingvalidator.xml:980 -#, fuzzy, no-c-format -msgid "@URL(protocol=, host=, port=, regexp=, flags=)" -msgstr "@URL(protocol=, host=, port=)" - -#. Tag: entry -#: usingvalidator.xml:984 -#, fuzzy, no-c-format -msgid "" -"Checks if the annotated character sequence is a valid URL according to " -"RFC2396. If any of the optional parameters protocol, " -"host or port are specified, " -"the corresponding URL fragments must match the specified values. The " -"optional parameters regexp and flags allow to specify an additional regular expression (including " -"regular expression flags) which the URL must match." -msgstr "" -"判断该值是否是一个有效的URL, 如果给出了约束中的protocol, hostport 参数的" -"话,那个被校验的值需要和其匹配." - -#. Tag: title -#: usingvalidator.xml:1001 -#, fuzzy, no-c-format -msgid "Country specific constraints" -msgstr "定义约束" - -#. Tag: para -#: usingvalidator.xml:1003 -#, no-c-format -msgid "" -"Hibernate Validator offers also some country specific constraints, e.g. for " -"the validation of social security numbers." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:1005 -#, no-c-format -msgid "" -"If you have to implement a country specific constraint, consider making it a " -"contribution to Hibernate Validator!" -msgstr "" - -#. Tag: title -#: usingvalidator.xml:1010 -#, no-c-format -msgid "Custom country specific constraints" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1031 -#, no-c-format -msgid "Country" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1039 -#, no-c-format -msgid "@CNPJ" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1043 -#, no-c-format -msgid "" -"Checks that the annotated character sequence represents a Brazilian " -"corporate tax payer registry number (Cadastro de Pessoa Juríeddica)" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1047 usingvalidator.xml:1061 usingvalidator.xml:1076 -#, no-c-format -msgid "Brazil" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1053 -#, no-c-format -msgid "@CPF" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1057 -#, no-c-format -msgid "" -"Checks that the annotated character sequence represents a Brazilian " -"individual taxpayer registry number (Cadastro de Pessoa Fídsica)." -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1067 -#, no-c-format -msgid "@TituloEleitoral" -msgstr "" - -#. Tag: entry -#: usingvalidator.xml:1071 -#, no-c-format -msgid "" -"Checks that the annotated character sequence represents a Brazilian voter ID " -"card number (Título " -"Eleitoral)." -msgstr "" - -#. Tag: para -#: usingvalidator.xml:1085 -#, fuzzy, no-c-format -msgid "" -"In some cases neither the Bean Validation constraints nor the custom " -"constraints provided by Hibernate Validator will fulfill your requirements. " -"In this case you can easily write your own constraint. We will discuss this " -"in ." -msgstr "" -"如果这些内置的约束不能满足你的需求的话, 那么你可以创建你自己的约束条件, 我们" -"接下来会详细介绍, 请继续阅读" - -#~ msgid "Validation step by step" -#~ msgstr "Validation step by step" - -#~ msgid "Validating groups" -#~ msgstr "校验组" - -#~ msgid "" -#~ "Groups allow you to restrict the set of constraints applied during " -#~ "validation. This makes for example wizard like validation possible where " -#~ "in each step only a specified subset of constraints get validated. The " -#~ "groups targeted are passed as var-args parameters to " -#~ "validate, validateProperty and validateValue. Let's have a look " -#~ "at an extended Car with Driver example. First we have the class Person " -#~ "() which has a @NotNull constraint on name. Since no group is " -#~ "specified for this annotation its default group is javax." -#~ "validation.groups.Default." -#~ msgstr "" -#~ "校验组能够让你在验证的时候选择应用哪些约束条件. 这样在某些情况下( 例如向" -#~ "导 ) 就可以对每一步进行校验的时候, 选取对应这步的那些约束条件进行验证了. " -#~ "校验组是通过可变参数传递给validate, " -#~ "validatePropertyvalidateValue的. 让我们来看个例子, 这个实例扩展了上面的Car类,又为其添加了一个新的Driver. 首先, 类" -#~ "Person () 的" -#~ "name属性上定义了一个@NotNull " -#~ "的约束条件. 因为没有明确指定这个约束条件属于哪个组,所以它被归类到默认组 " -#~ "(javax.validation.groups.Default)." - -#~ msgid "" -#~ "When more than one group is requested, the order in which the groups are " -#~ "evaluated is not deterministic. If no group is specified the default " -#~ "group javax.validation.groups.Default is assumed." -#~ msgstr "" -#~ "如果某个约束条件属于多个组,那么各个组在校验时候的顺序是不可预知的. 如果一" -#~ "个约束条件没有被指明属于哪个组,那么它就会被归类到默认组(javax." -#~ "validation.groups.Default)." - -#~ msgid "Person" -#~ msgstr "Person" - -#~ msgid "" -#~ "public class Person {\n" -#~ " @NotNull\n" -#~ " private String name;\n" -#~ "\n" -#~ " public Person(String name) {\n" -#~ " this.name = name;\n" -#~ " }\n" -#~ " // getters and setters ...\n" -#~ "}" -#~ msgstr "" -#~ "public class Person {\n" -#~ " @NotNull\n" -#~ " private String name;\n" -#~ "\n" -#~ " public Person(String name) {\n" -#~ " this.name = name;\n" -#~ " }\n" -#~ " // getters and setters ...\n" -#~ "}" - -#~ msgid "" -#~ "Next we have the class Driver () extending Person. Here we " -#~ "are adding the properties age and " -#~ "hasDrivingLicense. In order to drive you must be at " -#~ "least 18 (@Min(18)) and you must have a driving " -#~ "license (@AssertTrue). Both constraints defined on " -#~ "these properties belong to the group DriverChecks. " -#~ "As you can see in the group " -#~ "DriverChecks is just a simple tagging interface. " -#~ "Using interfaces makes the usage of groups type safe and allows for easy " -#~ "refactoring. It also means that groups can inherit from each other via " -#~ "class inheritance." -#~ msgstr "" -#~ "接下来, 我们让类Driver () 继承自类Person. 然后添加两个属性,分别是" -#~ "agehasDrivingLicense. 对于一" -#~ "个司机来说, 要开车的话, 必须满足两个条件, 年满18周岁 (@Min(18)" -#~ ") 和你的有驾照(@AssertTrue). 这两个约束" -#~ "条件分别定义在那两个属性上, 并且把他们都归于DriverChecks组. 通过, 你可以看" -#~ "到, \"DriverChecks组\" 就是一个简单的标记接口. 使用" -#~ "接口( 而不是字符串) 可以做到类型安全,并且接口比字符串更加对重构友好, 另" -#~ "外, 接口还意味着一个组可以继承别的组." - -#~ msgid "Driver" -#~ msgstr "Driver" - -#~ msgid "" -#~ "public class Driver extends Person {\n" -#~ " @Min(value = 18, message = \"You have to be 18 to drive a car\", " -#~ "groups = DriverChecks.class)\n" -#~ " public int age;\n" -#~ "\n" -#~ " @AssertTrue(message = \"You first have to pass the driving test\", " -#~ "groups = DriverChecks.class)\n" -#~ " public boolean hasDrivingLicense;\n" -#~ "\n" -#~ " public Driver(String name) {\n" -#~ " super( name );\n" -#~ " }\n" -#~ "\n" -#~ " public void passedDrivingTest(boolean b) {\n" -#~ " hasDrivingLicense = b;\n" -#~ " }\n" -#~ "\n" -#~ " public int getAge() {\n" -#~ " return age;\n" -#~ " }\n" -#~ "\n" -#~ " public void setAge(int age) {\n" -#~ " this.age = age;\n" -#~ " }\n" -#~ "}" -#~ msgstr "" -#~ "public class Driver extends Person {\n" -#~ " @Min(value = 18, message = \"You have to be 18 to drive a car\", " -#~ "groups = DriverChecks.class)\n" -#~ " public int age;\n" -#~ "\n" -#~ " @AssertTrue(message = \"You first have to pass the driving test\", " -#~ "groups = DriverChecks.class)\n" -#~ " public boolean hasDrivingLicense;\n" -#~ "\n" -#~ " public Driver(String name) {\n" -#~ " super( name );\n" -#~ " }\n" -#~ "\n" -#~ " public void passedDrivingTest(boolean b) {\n" -#~ " hasDrivingLicense = b;\n" -#~ " }\n" -#~ "\n" -#~ " public int getAge() {\n" -#~ " return age;\n" -#~ " }\n" -#~ "\n" -#~ " public void setAge(int age) {\n" -#~ " this.age = age;\n" -#~ " }\n" -#~ "}" - -#~ msgid "Group interfaces" -#~ msgstr "Group interfaces" - -#~ msgid "" -#~ "public interface DriverChecks {\n" -#~ "}\n" -#~ "\n" -#~ "public interface CarChecks {\n" -#~ "}" -#~ msgstr "" -#~ "public interface DriverChecks {\n" -#~ "}\n" -#~ "\n" -#~ "public interface CarChecks {\n" -#~ "}" - -#~ msgid "" -#~ "Last but not least we add the property passedVehicleInspection to the Car class () indicating whether a car passed the road worthy tests." -#~ msgstr "" -#~ "最后, 我们给Car class () 添加一个passedVehicleInspection的属性,来表示这" -#~ "个车是否通过了上路检查." - -#~ msgid "Car" -#~ msgstr "Car" - -#~ msgid "" -#~ "public class Car {\n" -#~ " @NotNull\n" -#~ " private String manufacturer;\n" -#~ "\n" -#~ " @NotNull\n" -#~ " @Size(min = 2, max = 14)\n" -#~ " private String licensePlate;\n" -#~ "\n" -#~ " @Min(2)\n" -#~ " private int seatCount;\n" -#~ "\n" -#~ " @AssertTrue(message = \"The car has to pass the vehicle inspection " -#~ "first\", groups = CarChecks.class)\n" -#~ " private boolean passedVehicleInspection;\n" -#~ "\n" -#~ " @Valid\n" -#~ " private Driver driver;\n" -#~ "\n" -#~ " public Car(String manufacturer, String licencePlate, int seatCount) " -#~ "{\n" -#~ " this.manufacturer = manufacturer;\n" -#~ " this.licensePlate = licencePlate;\n" -#~ " this.seatCount = seatCount;\n" -#~ " }\n" -#~ "}" -#~ msgstr "" -#~ "public class Car {\n" -#~ " @NotNull\n" -#~ " private String manufacturer;\n" -#~ "\n" -#~ " @NotNull\n" -#~ " @Size(min = 2, max = 14)\n" -#~ " private String licensePlate;\n" -#~ "\n" -#~ " @Min(2)\n" -#~ " private int seatCount;\n" -#~ "\n" -#~ " @AssertTrue(message = \"The car has to pass the vehicle inspection " -#~ "first\", groups = CarChecks.class)\n" -#~ " private boolean passedVehicleInspection;\n" -#~ "\n" -#~ " @Valid\n" -#~ " private Driver driver;\n" -#~ "\n" -#~ " public Car(String manufacturer, String licencePlate, int seatCount) " -#~ "{\n" -#~ " this.manufacturer = manufacturer;\n" -#~ " this.licensePlate = licencePlate;\n" -#~ " this.seatCount = seatCount;\n" -#~ " }\n" -#~ "}" - -#~ msgid "" -#~ "Overall three different groups are used in our example. Person." -#~ "name, Car.manufacturer, Car." -#~ "licensePlate and Car.seatCount all belong " -#~ "to the Default group. Driver.age and Driver.hasDrivingLicense belong to " -#~ "DriverChecks and last but not least Car." -#~ "passedVehicleInspection belongs to the group " -#~ "CarChecks. " -#~ "shows how passing different group combinations to the " -#~ "Validator.validate method result in different " -#~ "validation results." -#~ msgstr "" -#~ "现在, 在我们的例子中有三个不同的校验组, Person.name, " -#~ "Car.manufacturer, Car.licensePlateCar.seatCount都属于默认" -#~ "(Default) 组, Driver.age 和 " -#~ "Driver.hasDrivingLicense 从属于 " -#~ "DriverChecks组, 而Car." -#~ "passedVehicleInspectionCarChecks组" -#~ "中. 演示了如何让" -#~ "Validator.validate验证不同的组来得到不同的校验结" -#~ "果." - -#~ msgid "Drive away" -#~ msgstr "Drive away" - -#~ msgid "" -#~ "public class GroupTest {\n" -#~ "\n" -#~ " private static Validator validator;\n" -#~ "\n" -#~ " @BeforeClass\n" -#~ " public static void setUp() {\n" -#~ " ValidatorFactory factory = Validation.buildDefaultValidatorFactory" -#~ "();\n" -#~ " validator = factory.getValidator();\n" -#~ " }\n" -#~ "\n" -#~ " @Test\n" -#~ " public void driveAway() {\n" -#~ " // create a car and check that everything is ok with it.\n" -#~ " Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" -#~ " Set<ConstraintViolation<Car>> constraintViolations = " -#~ "validator.validate( car );\n" -#~ " assertEquals( 0, constraintViolations.size() );\n" -#~ "\n" -#~ " // but has it passed the vehicle inspection?\n" -#~ " constraintViolations = validator.validate( car, CarChecks." -#~ "class );\n" -#~ " assertEquals( 1, constraintViolations.size() );\n" -#~ " assertEquals(\"The car has to pass the vehicle inspection first" -#~ "\", constraintViolations.iterator().next().getMessage());\n" -#~ "\n" -#~ " // let's go to the vehicle inspection\n" -#~ " car.setPassedVehicleInspection( true );\n" -#~ " assertEquals( 0, validator.validate( car ).size() );\n" -#~ "\n" -#~ " // now let's add a driver. He is 18, but has not passed the " -#~ "driving test yet\n" -#~ " Driver john = new Driver( \"John Doe\" );\n" -#~ " john.setAge( 18 );\n" -#~ " car.setDriver( john );\n" -#~ " constraintViolations = validator.validate( car, DriverChecks." -#~ "class );\n" -#~ " assertEquals( 1, constraintViolations.size() );\n" -#~ " assertEquals( \"You first have to pass the driving test\", " -#~ "constraintViolations.iterator().next().getMessage() );\n" -#~ "\n" -#~ " // ok, John passes the test\n" -#~ " john.passedDrivingTest( true );\n" -#~ " assertEquals( 0, validator.validate( car, DriverChecks.class )." -#~ "size() );\n" -#~ "\n" -#~ " // just checking that everything is in order now\n" -#~ " assertEquals( 0, validator.validate( car, Default.class, " -#~ "CarChecks.class, DriverChecks.class ).size() );\n" -#~ " }\n" -#~ "}" -#~ msgstr "" -#~ "public class GroupTest {\n" -#~ "\n" -#~ " private static Validator validator;\n" -#~ "\n" -#~ " @BeforeClass\n" -#~ " public static void setUp() {\n" -#~ " ValidatorFactory factory = Validation.buildDefaultValidatorFactory" -#~ "();\n" -#~ " validator = factory.getValidator();\n" -#~ " }\n" -#~ "\n" -#~ " @Test\n" -#~ " public void driveAway() {\n" -#~ " // create a car and check that everything is ok with it.\n" -#~ " Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" -#~ " Set<ConstraintViolation<Car>> constraintViolations = " -#~ "validator.validate( car );\n" -#~ " assertEquals( 0, constraintViolations.size() );\n" -#~ "\n" -#~ " // but has it passed the vehicle inspection?\n" -#~ " constraintViolations = validator.validate( car, CarChecks." -#~ "class );\n" -#~ " assertEquals( 1, constraintViolations.size() );\n" -#~ " assertEquals(\"The car has to pass the vehicle inspection first" -#~ "\", constraintViolations.iterator().next().getMessage());\n" -#~ "\n" -#~ " // let's go to the vehicle inspection\n" -#~ " car.setPassedVehicleInspection( true );\n" -#~ " assertEquals( 0, validator.validate( car ).size() );\n" -#~ "\n" -#~ " // now let's add a driver. He is 18, but has not passed the " -#~ "driving test yet\n" -#~ " Driver john = new Driver( \"John Doe\" );\n" -#~ " john.setAge( 18 );\n" -#~ " car.setDriver( john );\n" -#~ " constraintViolations = validator.validate( car, DriverChecks." -#~ "class );\n" -#~ " assertEquals( 1, constraintViolations.size() );\n" -#~ " assertEquals( \"You first have to pass the driving test\", " -#~ "constraintViolations.iterator().next().getMessage() );\n" -#~ "\n" -#~ " // ok, John passes the test\n" -#~ " john.passedDrivingTest( true );\n" -#~ " assertEquals( 0, validator.validate( car, DriverChecks.class )." -#~ "size() );\n" -#~ "\n" -#~ " // just checking that everything is in order now\n" -#~ " assertEquals( 0, validator.validate( car, Default.class, " -#~ "CarChecks.class, DriverChecks.class ).size() );\n" -#~ " }\n" -#~ "}" - -#~ msgid "" -#~ "First we create a car and validate it using no explicit group. There are " -#~ "no validation errors, even though the property " -#~ "passedVehicleInspection is per default " -#~ "false. However, the constraint defined on this " -#~ "property does not belong to the default group. Next we just validate the " -#~ "CarChecks group which will fail until we make sure " -#~ "that the car passes the vehicle inspection. When we then add a driver to " -#~ "the car and validate against DriverChecks we get " -#~ "again a constraint violation due to the fact that the driver has not yet " -#~ "passed the driving test. Only after setting passedDrivingTest to true the validation against DriverChecks will pass." -#~ msgstr "" -#~ "首先我们创建一辆汽车然后在没有明确指定使用哪个校验组的情况下校验它, 可以看" -#~ "到即使passedVehicleInspection的默认值是" -#~ "false也不会校验出错误来. 因为定义在这个属性上的约束条" -#~ "件并不属于默认的校验组, 接下来,我们来校验CarChecks" -#~ "这个组, 这样就会发现car违反了约束条件, 必须让这个车先通过检测. 接下来,我们" -#~ "给这个车增加一个司机, 然后在基于DriverChecks来校" -#~ "验, 会发现因为这个司机因为还没有通过驾照考试, 所以又一次得到了校验错误, 如" -#~ "果我们设置passedDrivingTest属性为true之后, DriverChecks组的校验就通过了." - -#~ msgid "" -#~ "Last but not least, we show that all constraints are passing by " -#~ "validating against all defined groups." -#~ msgstr "" -#~ "最后, 让我们再来校验所有的组中定义的约束条件,可以看到所有的约束条件都通过" -#~ "了验证." - -#~ msgid "Group sequences" -#~ msgstr "校验组序列" - -#, fuzzy -#~ msgid "" -#~ "By default, constraints are evaluated in no particular order, regardless " -#~ "of which groups they belong to. In some situations, however, it is useful " -#~ "to control the order constraints are evaluated. In our example from we could for " -#~ "example require that first all default car constraints are passing before " -#~ "we check the road worthiness of the car. Finally before we drive away we " -#~ "check the actual driver constraints. In order to implement such an order " -#~ "one would define a new interface and annotate it with " -#~ "@GroupSequence defining the order in which the " -#~ "groups have to be validated." -#~ msgstr "" -#~ "默认情况下, 如果一个实体类(或者属性)上定义了多个约束条件,那么在验证过程中," -#~ "这些约束条件无序被校验的, 不管它们属于那个验证组. 但是在某些情况下, 控制这" -#~ "个顺序又是有必要的. 在中, 我们可以要求汽车先要通过检测, 没有问题了之后在进行" -#~ "上路测试, 最后, 在我们把车开走之前,还要让司机通过测试. 为了达到这个效果, " -#~ "我们可以创建一个新的接口, 然后用@GroupSequence标注" -#~ "它, 在这个标注里面去定义要应用的验证组的顺序. " - -#, fuzzy -#~ msgid "" -#~ "If at least one constraint fails in a sequenced group none of the " -#~ "constraints of the following groups in the sequence get validated." -#~ msgstr "" -#~ "如果这个校验组序列中有一个约束条件没有通过验证的话, 那么此约束条件后面的都" -#~ "不会再继续被校验了. " - -#~ msgid "Interface with @GroupSequence" -#~ msgstr "标注了@GroupSequence的接口" - -#~ msgid "" -#~ "@GroupSequence({Default.class, CarChecks.class, DriverChecks.class})\n" -#~ "public interface OrderedChecks {\n" -#~ "}" -#~ msgstr "" -#~ "@GroupSequence({Default.class, CarChecks.class, DriverChecks.class})\n" -#~ "public interface OrderedChecks {\n" -#~ "}" - -#~ msgid "" -#~ "Groups defining a sequence and groups composing a sequence must not be " -#~ "involved in a cyclic dependency either directly or indirectly, either " -#~ "through cascaded sequence definition or group inheritance. If a group " -#~ "containing such a circularity is evaluated, a " -#~ "GroupDefinitionException is raised." -#~ msgstr "" -#~ "一个校验组序列中包含的校验组和这个校验组序列不能造成直接或者间接的循环引" -#~ "用. 包括校验组继承. 如果造成了循环引用的话, 会导致" -#~ "GroupDefinitionException异常." - -#~ msgid "" -#~ "The usage of the new sequence could then look like in ." -#~ msgstr "展示了校验组序列的用法." - -#~ msgid "Usage of a group sequence" -#~ msgstr "校验组序列的用法" - -#~ msgid "" -#~ "@Test\n" -#~ "public void testOrderedChecks() {\n" -#~ " Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" -#~ " car.setPassedVehicleInspection( true );\n" -#~ "\n" -#~ " Driver john = new Driver( \"John Doe\" );\n" -#~ " john.setAge( 18 );\n" -#~ " john.passedDrivingTest( true );\n" -#~ " car.setDriver( john );\n" -#~ "\n" -#~ " assertEquals( 0, validator.validate( car, OrderedChecks.class ).size" -#~ "() );\n" -#~ "}" -#~ msgstr "" -#~ "@Test\n" -#~ "public void testOrderedChecks() {\n" -#~ " Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n" -#~ " car.setPassedVehicleInspection( true );\n" -#~ "\n" -#~ " Driver john = new Driver( \"John Doe\" );\n" -#~ " john.setAge( 18 );\n" -#~ " john.passedDrivingTest( true );\n" -#~ " car.setDriver( john );\n" -#~ "\n" -#~ " assertEquals( 0, validator.validate( car, OrderedChecks.class ).size" -#~ "() );\n" -#~ "}" - -#~ msgid "Redefining the default group sequence of a class" -#~ msgstr "对一个类重定义其默认校验组" - -#, fuzzy -#~ msgid "@GroupSequence" -#~ msgstr "校验组序列" - -#, fuzzy -#~ msgid "" -#~ "The @GroupSequence annotation also fulfills a " -#~ "second purpose. It allows you to redefine what the Default group means for a given class. To redefine Default for a given class, add a @GroupSequence " -#~ "annotation to the class. The defined groups in the annotation express the " -#~ "sequence of groups that substitute Default for " -#~ "this class. introduces a new class " -#~ "RentalCar with a redefined default group. With " -#~ "this definition you can evaluate the constraints belonging to " -#~ "RentalChecks, CarChecks and " -#~ "RentalCar by just requesting the " -#~ "Default group as seen in ." -#~ msgstr "" -#~ "@GroupSequence annotation还有第二个用处, 通过把" -#~ "@GroupSequence标注于一个类, 你可以给这个类定义它的" -#~ "默认校验组(Default). 这样,定义在其中的校验组就表示" -#~ "对这个类进行默认组校验的时候要被应用的约束条件(和顺序). 中引入了一个新的类RentalCar, 它就被重定义了默认" -#~ "组. 这样, 在中, RentalCar被校验的时候,实际上是被应用了三个校验组的约束条件." - -#, fuzzy -#~ msgid "RentalCar with @GroupSequence" -#~ msgstr "标注了@GroupSequence的接口" - -#, fuzzy -#~ msgid "" -#~ "@GroupSequence({ RentalChecks.class, CarChecks.class, RentalCar.class })\n" -#~ "public class RentalCar extends Car {\n" -#~ " @AssertFalse(message = \"The car is currently rented out\", groups = " -#~ "RentalChecks.class)\n" -#~ " private boolean rented;\n" -#~ "\n" -#~ " public RentalCar(String manufacturer, String licencePlate, int " -#~ "seatCount) {\n" -#~ " super( manufacturer, licencePlate, seatCount );\n" -#~ " }\n" -#~ "\n" -#~ " public boolean isRented() {\n" -#~ " return rented;\n" -#~ " }\n" -#~ "\n" -#~ " public void setRented(boolean rented) {\n" -#~ " this.rented = rented;\n" -#~ " }\n" -#~ "}" -#~ msgstr "" -#~ "@GroupSequence({ RentalCar.class, CarChecks.class })\n" -#~ "public class RentalCar extends Car {\n" -#~ " public RentalCar(String manufacturer, String licencePlate, int " -#~ "seatCount) {\n" -#~ " super( manufacturer, licencePlate, seatCount );\n" -#~ " }\n" -#~ "}" - -#, fuzzy -#~ msgid "RentalCar with redefined default group" -#~ msgstr "标注了@GroupSequence的接口" - -#, fuzzy -#~ msgid "" -#~ "Due to the fact that there cannot be a cyclic dependency in the group and " -#~ "group sequence definitions one cannot just add Default to the sequence redefining Default for " -#~ "a class. Instead the class itself has to be added!" -#~ msgstr "" -#~ "因为不能在校验组和校验组序列中有循环依赖关系, 所以, 如果你想重定义一个类的" -#~ "默认组, 并且还想把Default组加入到这个重定义的序列当" -#~ "中的话, 则不能简单的加入Default, 而是需要把被重定义" -#~ "的类加入到其中." - -#, fuzzy -#~ msgid "@GroupSequenceProvider" -#~ msgstr "校验组序列" - -#, fuzzy -#~ msgid "RentalCar with @GroupSequenceProvider" -#~ msgstr "标注了@GroupSequence的接口" - -#, fuzzy -#~ msgid "" -#~ "@GroupSequenceProvider(RentalCarGroupSequenceProvider.class)\n" -#~ "public class RentalCar extends Car {\n" -#~ " @AssertFalse(message = \"The car is currently rented out\", groups = " -#~ "RentalChecks.class)\n" -#~ " private boolean rented;\n" -#~ "\n" -#~ " public RentalCar(String manufacturer, String licencePlate, int " -#~ "seatCount) {\n" -#~ " super( manufacturer, licencePlate, seatCount );\n" -#~ " }\n" -#~ "\n" -#~ " public boolean isRented() {\n" -#~ " return rented;\n" -#~ " }\n" -#~ "\n" -#~ " public void setRented(boolean rented) {\n" -#~ " this.rented = rented;\n" -#~ " }\n" -#~ "}" -#~ msgstr "" -#~ "package com.mycompany;\n" -#~ "\n" -#~ "import javax.validation.constraints.NotNull;\n" -#~ "\n" -#~ "public class RentalCar extends Car {\n" -#~ "\n" -#~ " private String rentalStation;\n" -#~ " \n" -#~ " public RentalCar(String manufacturer, String rentalStation) {\n" -#~ " super(manufacturer);\n" -#~ " this.rentalStation = rentalStation;\n" -#~ " }\n" -#~ " \n" -#~ " @NotNull\n" -#~ " public String getRentalStation() {\n" -#~ " return rentalStation;\n" -#~ " }\n" -#~ "\n" -#~ " public void setRentalStation(String rentalStation) {\n" -#~ " this.rentalStation = rentalStation;\n" -#~ " }\n" -#~ "}" - -#~ msgid "testOrderedChecksWithRedefinedDefault" -#~ msgstr "testOrderedChecksWithRedefinedDefault" - -#, fuzzy -#~ msgid "" -#~ "@Test\n" -#~ "public void testOrderedChecksWithRedefinedDefault() {\n" -#~ " RentalCar rentalCar = new RentalCar( \"Morris\", \"DD-AB-123\", 2 );\n" -#~ " rentalCar.setPassedVehicleInspection( true );\n" -#~ "\n" -#~ " Driver john = new Driver( \"John Doe\" );\n" -#~ " john.setAge( 18 );\n" -#~ " john.passedDrivingTest( true );\n" -#~ " rentalCar.setDriver( john );\n" -#~ "\n" -#~ " assertEquals( 0, validator.validate( rentalCar, Default.class ).size" -#~ "() );\n" -#~ "}" -#~ msgstr "" -#~ "@Test\n" -#~ "public void testOrderedChecksWithRedefinedDefault() {\n" -#~ " RentalCar rentalCar = new RentalCar( \"Morris\", \"DD-AB-123\", 2 );\n" -#~ " rentalCar.setPassedVehicleInspection( true );\n" -#~ "\n" -#~ " Driver john = new Driver( \"John Doe\" );\n" -#~ " john.setAge( 18 );\n" -#~ " john.passedDrivingTest( true );\n" -#~ " rentalCar.setDriver( john );\n" -#~ "\n" -#~ " assertEquals( 0, validator.validate( rentalCar, Default.class, " -#~ "DriverChecks.class ).size() );\n" -#~ "}" - -#, fuzzy -#~ msgid "Checks whether the specified string is a valid email address." -#~ msgstr "检查所给的字符串是否符合email地址的格式." - -#~ msgid "" -#~ "The Bean Validation specification does not enforce that groups have to be " -#~ "interfaces. Non interface classes could be used as well, but we recommend " -#~ "to stick to interfaces." -#~ msgstr "" -#~ "Bean Validation并没有规定组必须是用接口来定义, 所以非接口的类也是被接收的," -#~ "但是我们推荐使用接口." - -#~ msgid "" -#~ "Hibernate Validator implements all of the default constraints specified " -#~ "in Bean Validation as well as some custom ones. list all constraints available in Hibernate " -#~ "Validator." -#~ msgstr "" -#~ "Hibernate Validator不仅实现了Bean Validation中规定的所有的默认约束条件, 还" -#~ "有附加有一些自定义的. 列出了" -#~ "Hibernate Validator中已经提供的约束条件." - -#~ msgid "Part of Bean Validation Specification" -#~ msgstr "属于Bean Validation 规范" - -#~ msgid "Apply on" -#~ msgstr "应用位置" - -#~ msgid "yes" -#~ msgstr "yes" - -#~ msgid "field/property" -#~ msgstr "field/property" - -#~ msgid "no" -#~ msgstr "no" - -#~ msgid "field/property. The supported type is String." -#~ msgstr "字段或属性, 要求其类型为String." - -#~ msgid "field/property. Needs to be a string." -#~ msgstr "字段或属性, 需要是String类型的." - -#~ msgid "" -#~ "field/property. Supported types are String, Collection, Map and arrays." -#~ msgstr "字段或属性. 支持的类型包括String, Collection, Map 和数组." - -#~ msgid "field/property. Any non-primitive types are supported." -#~ msgstr "字段或属性. 支持所有的非原始类型." - -#~ msgid "RentalCar" -#~ msgstr "RentalCar" - -#~ msgid "" -#~ "field/property. Supported types are java.util.Date " -#~ "and java.util.Calendar." -#~ msgstr "" -#~ "字段或属性, 支持类型是java.util.Date 和 " -#~ "java.util.Calendar." diff --git a/documentation/src/main/docbook/zh-CN/modules/xml-configuration.po b/documentation/src/main/docbook/zh-CN/modules/xml-configuration.po deleted file mode 100644 index d45d042f82..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/xml-configuration.po +++ /dev/null @@ -1,344 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2013. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-29 13:14+0000\n" -"PO-Revision-Date: 2013-04-29 13:14+0000\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: zh-CN\n" - -#. Tag: title -#: xml-configuration.xml:24 -#, no-c-format -msgid "Configuring via XML" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:26 -#, no-c-format -msgid "" -"So far we have used the default configuration source for Bean Validation, " -"namely annotations. However, there also exist two kinds of XML descriptors " -"allowing configuration via XML. The first descriptor describes general Bean " -"Validation behaviour and is provided as META-INF/validation.xml. The second one describes constraint declarations and closely " -"matches the constraint declaration approach via annotations. Let's have a " -"look at these two document types." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:34 -#, no-c-format -msgid "" -"The xsd files are available via http://www.jboss.org/xml/ns/javax/" -"validation/configuration and http://www.jboss.org/xml/ns/javax/validation/" -"mapping." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:41 -#, no-c-format -msgid "Configuring ValidationFactory in validation.xml" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:44 -#, no-c-format -msgid "" -"The key to enable XML configuration for Hibernate Validator is the file " -"META-INF/validation.xml. If this file exists on the " -"classpath its configuration will be applied when the " -"ValidationFactory gets created. shows a model view of the XML schema to which " -"validation.xml has to adhere." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:51 -#, no-c-format -msgid "validation-configuration-1.1.xsd" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:67 -#, no-c-format -msgid "" -"shows the several configuration options of validation.xml. All settings are optional and the same configuration options are " -"also available programmatically through javax.validation." -"Configuration. In fact the XML configuration will be overridden " -"by values explicitly specified via the programmatic API. It is even possible " -"to ignore the XML configuration completely via Configuration." -"ignoreXmlConfiguration(). See also ." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:79 -#, no-c-format -msgid "validation.xml" -msgstr "" - -#. Tag: programlisting -#: xml-configuration.xml:81 -#, no-c-format -msgid "" -"<validation-config\n" -" xmlns=\"http://jboss.org/xml/ns/javax/validation/configuration\"\n" -" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" -" xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/" -"configuration\">\n" -"\n" -" <default-provider>com.acme.ValidationProvider</default-" -"provider>\n" -"\n" -" <message-interpolator>com.acme.MessageInterpolator</message-" -"interpolator>\n" -" <traversable-resolver>com.acme.TraversableResolver</traversable-" -"resolver>\n" -" <constraint-validator-factory>\n" -" com.acme.ConstraintValidatorFactory\n" -" </constraint-validator-factory>\n" -" <parameter-name-provider>com.acme.ParameterNameProvider</" -"parameter-name-provider>\n" -"\n" -" <executable-validation enabled=\"true\">\n" -" <default-validated-executable-types>\n" -" <executable-type>CONSTRUCTORS</executable-type>\n" -" <executable-type>NON_GETTER_METHODS</executable-" -"type>\n" -" <executable-type>GETTER_METHODS</executable-type>\n" -" </default-validated-executable-types>\n" -" </executable-validation>\n" -"\n" -" <constraint-mapping>META-INF/validation/constraints-car.xml</" -"constraint-mapping>\n" -"\n" -" <property name=\"hibernate.validator.fail_fast\">false</" -"property>\n" -"</validation-config>" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:85 -#, no-c-format -msgid "" -"There must only be one file named META-INF/validation.xml on the classpath. If more than one is found an exception is thrown." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:90 -#, no-c-format -msgid "" -"The node default-provider allows to choose the Bean " -"Validation provider. This is useful if there is more than one provider on " -"the classpath. message-interpolator, " -"traversable-resolver, constraint-validator-" -"factory and parameter-name-provider allow to " -"customize the used implementations for the interfaces " -"MessageInterpolator, TraversableResolver, ConstraintValidatorFactory and " -"ParameterNameProvider defined in the javax." -"validation package. See the sub-sections of for more information about these " -"interfaces." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:105 -#, no-c-format -msgid "" -"executable-validation and its subnodes define defaults " -"for method validation. The Bean Validation specification defines constructor " -"and non getter methods as defaults. The enabled " -"attribute acts as global switch to turn method validation on and off (see " -"also )." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:112 -#, no-c-format -msgid "" -"Via the constraint-mapping element you can list an " -"arbitrary number of additional XML files containing the actual constraint " -"configuration. Mapping file names must be specified using their fully-" -"qualified name on the classpath. Details on writing mapping files can be " -"found in the next section." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:118 -#, no-c-format -msgid "" -"Last but not least, you can specify provider specific properties via the " -"property nodes. In the example we are using the " -"Hibernate Validator specific hibernate.validator.fail_fast property (see )." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:126 -#, no-c-format -msgid "Mapping constraints via constraint-mappings" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:129 -#, no-c-format -msgid "" -"Expressing constraints in XML is possible via files adhering to the schema " -"seen in . Note that these " -"mapping files are only processed if listed via constraint-mapping in validation.xml." -msgstr "" - -#. Tag: title -#: xml-configuration.xml:136 -#, no-c-format -msgid "validation-mapping-1.1.xsd" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:151 -#, no-c-format -msgid "" -"shows how our classes Car and RentalCar from resp. could be mapped in XML. Example x shows how method " -"validation from example y can be expressed in xml. (TODO create example)" -msgstr "" - -#. Tag: title -#: xml-configuration.xml:158 -#, no-c-format -msgid "constraints.xml" -msgstr "" - -#. Tag: programlisting -#: xml-configuration.xml:160 -#, no-c-format -msgid "" -"<constraint-mappings\n" -" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" -" xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/mapping " -"validation-mapping-1.1.xsd\"\n" -" xmlns=\"http://jboss.org/xml/ns/javax/validation/mapping\" version=" -"\"1.1\">\n" -"\n" -" <default-package>org.hibernate.validator.quickstart</default-" -"package>\n" -" <bean class=\"Car\" ignore-annotations=\"true\">\n" -" <field name=\"manufacturer\">\n" -" <constraint annotation=\"javax.validation.constraints.NotNull" -"\"/>\n" -" </field>\n" -" <field name=\"licensePlate\">\n" -" <constraint annotation=\"javax.validation.constraints.NotNull" -"\"/>\n" -" </field>\n" -" <field name=\"seatCount\">\n" -" <constraint annotation=\"javax.validation.constraints.Min" -"\">\n" -" <element name=\"value\">2</element>\n" -" </constraint>\n" -" </field>\n" -" <field name=\"driver\">\n" -" <valid/>\n" -" </field>\n" -" <getter name=\"passedVehicleInspection\" ignore-annotations=\"true" -"\">\n" -" <constraint annotation=\"javax.validation.constraints." -"AssertTrue\">\n" -" <message>The car has to pass the vehicle inspection " -"first</message>\n" -" <groups>\n" -" <value>CarChecks</value>\n" -" </groups>\n" -" <element name=\"max\">10</element>\n" -" </constraint>\n" -" </getter>\n" -" </bean>\n" -" <bean class=\"RentalCar\" ignore-annotations=\"true\">\n" -" <class ignore-annotations=\"true\">\n" -" <group-sequence>\n" -" <value>RentalCar</value>\n" -" <value>CarChecks</value>\n" -" </group-sequence>\n" -" </class>\n" -" </bean>\n" -" <constraint-definition annotation=\"org.mycompany.CheckCase\">\n" -" <validated-by include-existing-validators=\"false\">\n" -" <value>org.mycompany.CheckCaseValidator</value>\n" -" </validated-by>\n" -" </constraint-definition>\n" -"</constraint-mappings>" -msgstr "" - -#. Tag: para -#: xml-configuration.xml:163 -#, no-c-format -msgid "" -"The XML configuration is closely mirroring the programmatic API. For this " -"reason it should suffice to just add some comments. default-" -"package is used for all fields where a class name is expected. If " -"the specified class is not fully qualified the configured default package " -"will be used. Every mapping file can then have several bean nodes, each describing the constraints on the entity with the " -"specified class name. A given entity can only be configured " -"once across all configuration files. The same applies for constraint " -"definitions for a given constraint annotation. It can only occur in one " -"mapping file. If these rules are violated a ValidationException is thrown. Setting ignore-annotations to true means that constraint annotations " -"placed on the configured bean are ignored. The default for this value is " -"true. ignore-annotations is also available for the " -"nodes class, fields and " -"getter. If not explicitly specified on these levels the " -"configured bean value applies. Otherwise do the nodes " -"class, fields and " -"getter determine on which level the constraints are " -"placed (see ). The " -"constraint node is then used to add a constraint on the " -"corresponding level. Each constraint definition must define the class via " -"the annotation attribute. The constraint attributes " -"required by the Bean Validation specification (message, " -"groups and payload) have dedicated " -"nodes. All other constraint specific attributes are configured using the " -"element node." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:194 -#, no-c-format -msgid "" -"The class node also allows to reconfigure the default group sequence (see " -") via the group-" -"sequence node." -msgstr "" - -#. Tag: para -#: xml-configuration.xml:198 -#, no-c-format -msgid "" -"Last but not least, the list of ConstraintValidators " -"associated to a given constraint can be altered via the constraint-" -"definition node. The annotation attribute " -"represents the constraint annotation being altered. The validated-" -"by elements represent the (ordered) list of " -"ConstraintValidator implementations associated to the " -"constraint. If include-existing-validator is set to " -"false, validators defined on the constraint annotation " -"are ignored. If set to true, the list of constraint " -"validators described in XML is concatenated to the list of validators " -"specified on the annotation." -msgstr "" diff --git a/documentation/src/main/docbook/zh-CN/modules/xmlconfiguration.po b/documentation/src/main/docbook/zh-CN/modules/xmlconfiguration.po deleted file mode 100644 index 6f312e335a..0000000000 --- a/documentation/src/main/docbook/zh-CN/modules/xmlconfiguration.po +++ /dev/null @@ -1,426 +0,0 @@ -# Language zh-CN translations for PACKAGE package. -# Automatically generated, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: http://bugs.kde.org\n" -"POT-Creation-Date: 2013-04-03 09:59+0000\n" -"PO-Revision-Date: 2010-08-22 23:44+0830\n" -"Last-Translator: Strong Liu \n" -"Language-Team: none\n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#. Tag: title -#: xmlconfiguration.xml:24 -#, no-c-format -msgid "XML configuration" -msgstr "XML configuration" - -#. Tag: filename -#: xmlconfiguration.xml:27 -#, no-c-format -msgid "validation.xml" -msgstr "validation.xml" - -#. Tag: para -#: xmlconfiguration.xml:29 -#, fuzzy, no-c-format -msgid "" -"The key to enable XML configuration for Hibernate Validator is the file " -"META-INF/validation.xml. If this file exists on the " -"classpath its configuration will be applied when the " -"ValidationFactory gets created. shows a model view of the XML schema to which " -"validation.xml has to adhere." -msgstr "" -"我们可以使用validation.xml来对Hibernate Validator进行配" -"置. ValidationFactory在初始化的时候会在类路径下寻找此" -"文件,如果找到的话,就会应用其中定义的配置信息. 显示了valiation.xml的xsd模" -"型." - -#. Tag: title -#: xmlconfiguration.xml:36 -#, no-c-format -msgid "validation-configuration-1.0.xsd" -msgstr "validation-configuration-1.0.xsd" - -#. Tag: para -#: xmlconfiguration.xml:51 -#, no-c-format -msgid "" -"shows the several configuration options of validation.xml." -msgstr "列出了validation.xml中的一些常用的配置项." - -#. Tag: title -#: xmlconfiguration.xml:55 -#, no-c-format -msgid "validation.xml" -msgstr "validation.xml" - -#. Tag: programlisting -#: xmlconfiguration.xml:57 -#, fuzzy, no-c-format -msgid "" -"<validation-config\n" -" xmlns=\"http://jboss.org/xml/ns/javax/validation/configuration\"\n" -" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" -" xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/" -"configuration\">\n" -"\n" -" <default-provider>org.hibernate.validator.HibernateValidator</" -"default-provider>\n" -" <message-interpolator>org.hibernate.validator.messageinterpolation." -"ResourceBundleMessageInterpolator</message-interpolator>\n" -" <traversable-resolver>org.hibernate.validator.engine.resolver." -"DefaultTraversableResolver</traversable-resolver>\n" -" <constraint-validator-factory>org.hibernate.validator.engine." -"ConstraintValidatorFactoryImpl</constraint-validator-factory>\n" -" <constraint-mapping>META-INF/validation/constraints-car.xml</" -"constraint-mapping>\n" -" <property name=\"prop1\">value1</property>\n" -" <property name=\"prop2\">value2</property>\n" -"</validation-config>" -msgstr "" -"<validation-config xmlns=\"http://jboss.org/xml/ns/javax/validation/" -"configuration\"\n" -" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" -" xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/configuration" -"\">\n" -" <default-provider>org.hibernate.validator.HibernateValidator</" -"default-provider>\n" -" <message-interpolator>org.hibernate.validator.engine." -"ResourceBundleMessageInterpolator</message-interpolator>\n" -" <traversable-resolver>org.hibernate.validator.engine.resolver." -"DefaultTraversableResolver</traversable-resolver>\n" -" <constraint-validator-factory>org.hibernate.validator.engine." -"ConstraintValidatorFactoryImpl</constraint-validator-factory>\n" -" <constraint-mapping>/constraints-car.xml</constraint-" -"mapping>\n" -" <property name=\"prop1\">value1</property>\n" -" <property name=\"prop2\">value2</property>\n" -"</validation-config>" - -#. Tag: para -#: xmlconfiguration.xml:61 -#, fuzzy, no-c-format -msgid "" -"There must only be one file named META-INF/validation.xml on the classpath. If more than one is found an exception is thrown." -msgstr "" -"类路径下面只能有一个validation.xml, 如果超过一个的话,会" -"抛出异常." - -#. Tag: para -#: xmlconfiguration.xml:66 -#, fuzzy, no-c-format -msgid "" -"The node default-provider allows to choose the Bean " -"Validation provider. This is useful if there is more than one provider on " -"the classpath. message-interpolator, " -"traversable-resolver and constraint-validator-" -"factory allow to customize the used implementations for " -"javax.validation.MessageInterpolator, " -"javax.validation.TraversableResolver resp. " -"javax.validation.ConstraintValidatorFactory." -msgstr "" -"validation.xml中所有的配置信息都是可选的, 中就是列出了Hibernate Validator中的默认值. 如果类" -"路径当中存在有多个Bean Validation的实现的话, 那么可以通过default-" -"provider节点指定使用那个Bean Validation的实现. message-" -"interpolator, traversable-resolver 和 " -"constraint-validator-factory可以用来指定自定义的" -"javax.validation.MessageInterpolator, " -"javax.validation.TraversableResolver和" -"javax.validation.ConstraintValidatorFactory. 同样的, " -"这些配置信息也可以通过编程的方式调用javax.validation." -"Configuration来实现. 另外, 你可以通过API的方式来重写xml中的配置信" -"息, 也可以通过调用 Configuration.ignoreXmlConfiguration()来完全的忽略掉xml的配置信息. 请参考." - -#. Tag: para -#: xmlconfiguration.xml:76 -#, no-c-format -msgid "" -"All these settings are optional. " -"shows the defaults used within Hibernate Validator. The same configuration " -"options are also available programmatically through javax." -"validation.Configuration. In fact XML configuration will be " -"overridden by values explicitly specified via the API. It is even possible " -"to ignore the XML configuration completely via Configuration." -"ignoreXmlConfiguration(). See also ." -msgstr "" - -#. Tag: para -#: xmlconfiguration.xml:86 -#, fuzzy, no-c-format -msgid "" -"Via the constraint-mapping element you can list an " -"arbitrary number of additional XML files containing the actual constraint " -"configuration. Mapping file names must be specified using their fully-" -"qualified name on the classpath. Details on writing mapping files can be " -"found in the next section." -msgstr "" -"你可以增加若干个constraint-mapping节点,在每个里面列出一" -"个额外的xml文件用来定义约束规则, 具体请参考." - -#. Tag: para -#: xmlconfiguration.xml:92 -#, fuzzy, no-c-format -msgid "" -"Last but not least, you can specify provider specific properties via the " -"property nodes." -msgstr "" -"最后, 你可以通过property来定义各个Bean Validation 实现专" -"属的属性. Hibernate Validator当前并没有使用任何特定的属性." - -#. Tag: title -#: xmlconfiguration.xml:97 -#, no-c-format -msgid "Mapping constraints" -msgstr "映射约束" - -#. Tag: para -#: xmlconfiguration.xml:99 -#, fuzzy, no-c-format -msgid "" -"Expressing constraints in XML is possible via files adhering to the schema " -"seen in . Note that these " -"mapping files are only processed if listed via constraint-mapping in your validation.xml." -msgstr "" -"我们也可以通过xml来定义约束条件, 只需要这个xml符合中所定义的规范. 需要注意的是, 你必须把xml定义的约束" -"列在validation.xmlconstraint-mapping节点中才能得到处理." - -#. Tag: title -#: xmlconfiguration.xml:106 -#, no-c-format -msgid "validation-mapping-1.0.xsd" -msgstr "validation-mapping-1.0.xsd" - -#. Tag: para -#: xmlconfiguration.xml:121 -#, fuzzy, no-c-format -msgid "" -"shows how our classes Car and RentalCar from resp. could be mapped in XML." -msgstr "" -"显示了如何通过xml定义的方式来给中的类Car 以及" -" 中的RentalCar定义约束条件." - -#. Tag: title -#: xmlconfiguration.xml:127 -#, no-c-format -msgid "constraints-car.xml" -msgstr "constraints-car.xml" - -#. Tag: programlisting -#: xmlconfiguration.xml:129 -#, fuzzy, no-c-format -msgid "" -"<constraint-mappings\n" -" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" -" xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/mapping " -"validation-mapping-1.0.xsd\"\n" -" xmlns=\"http://jboss.org/xml/ns/javax/validation/mapping\">\n" -"\n" -" <default-package>org.hibernate.validator.quickstart</default-" -"package>\n" -" <bean class=\"Car\" ignore-annotations=\"true\">\n" -" <field name=\"manufacturer\">\n" -" <constraint annotation=\"javax.validation.constraints.NotNull" -"\"/>\n" -" </field>\n" -" <field name=\"licensePlate\">\n" -" <constraint annotation=\"javax.validation.constraints.NotNull" -"\"/>\n" -" </field>\n" -" <field name=\"seatCount\">\n" -" <constraint annotation=\"javax.validation.constraints.Min" -"\">\n" -" <element name=\"value\">2</element>\n" -" </constraint>\n" -" </field>\n" -" <field name=\"driver\">\n" -" <valid/>\n" -" </field>\n" -" <getter name=\"passedVehicleInspection\" ignore-annotations=\"true" -"\">\n" -" <constraint annotation=\"javax.validation.constraints." -"AssertTrue\">\n" -" <message>The car has to pass the vehicle inspection " -"first</message>\n" -" <groups>\n" -" <value>CarChecks</value>\n" -" </groups>\n" -" <element name=\"max\">10</element>\n" -" </constraint>\n" -" </getter>\n" -" </bean>\n" -" <bean class=\"RentalCar\" ignore-annotations=\"true\">\n" -" <class ignore-annotations=\"true\">\n" -" <group-sequence>\n" -" <value>RentalCar</value>\n" -" <value>CarChecks</value>\n" -" </group-sequence>\n" -" </class>\n" -" </bean>\n" -" <constraint-definition annotation=\"org.mycompany.CheckCase\">\n" -" <validated-by include-existing-validators=\"false\">\n" -" <value>org.mycompany.CheckCaseValidator</value>\n" -" </validated-by>\n" -" </constraint-definition>\n" -"</constraint-mappings>" -msgstr "" -"<constraint-mappings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance" -"\"\n" -" xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/" -"validation/mapping validation-mapping-1.0.xsd\"\n" -" xmlns=\"http://jboss.org/xml/ns/javax/validation/mapping" -"\">\n" -" <default-package>org.hibernate.validator.quickstart</default-" -"package>\n" -" <bean class=\"Car\" ignore-annotations=\"true\">\n" -" <field name=\"manufacturer\">\n" -" <constraint annotation=\"javax.validation.constraints.NotNull" -"\"/>\n" -" </field>\n" -" <field name=\"licensePlate\">\n" -" <constraint annotation=\"javax.validation.constraints.NotNull" -"\"/>\n" -" </field>\n" -" <field name=\"seatCount\">\n" -" <constraint annotation=\"javax.validation.constraints.Min" -"\">\n" -" <element name=\"value\">2</element>\n" -" </constraint>\n" -" </field>\n" -" <field name=\"driver\">\n" -" <valid/>\n" -" </field>\n" -" <getter name=\"passedVehicleInspection\" ignore-annotations=\"true" -"\">\n" -" <constraint annotation=\"javax.validation.constraints." -"AssertTrue\">\n" -" <message>The car has to pass the vehicle inspection " -"first</message>\n" -" <groups>\n" -" <value>CarChecks</value>\n" -" </groups>\n" -" <element name=\"max\">10</element>\n" -" </constraint>\n" -" </getter>\n" -" </bean>\n" -" <bean class=\"RentalCar\" ignore-annotations=\"true\">\n" -" <class ignore-annotations=\"true\">\n" -" <group-sequence>\n" -" <value>RentalCar</value>\n" -" <value>CarChecks</value>\n" -" </group-sequence>\n" -" </class>\n" -" </bean>\n" -" <constraint-definition annotation=\"org.mycompany.CheckCase\" include-" -"existing-validator=\"false\">\n" -" <validated-by include-existing-validators=\"false\">\n" -" <value>org.mycompany.CheckCaseValidator</value>\n" -" </validated-by>\n" -" </constraint-definition>\n" -"</constraint-mappings>" - -#. Tag: para -#: xmlconfiguration.xml:132 -#, fuzzy, no-c-format -msgid "" -"The XML configuration is closely mirroring the programmatic API. For this " -"reason it should suffice to just add some comments. default-" -"package is used for all fields where a class name is expected. If " -"the specified class is not fully qualified the configured default package " -"will be used. Every mapping file can then have several bean nodes, each describing the constraints on the entity with the " -"specified class name. A given entity can only be configured " -"once across all configuration files. If the same class is configured more " -"than once an exception is thrown. Setting ignore-" -"annotations to true means that constraint " -"annotations placed on the configured bean are ignored. The default for this " -"value is true. ignore-annotations is also available for " -"the nodes class, fields and " -"getter. If not explicitly specified on these levels the " -"configured bean value applies. Otherwise do the nodes " -"class, fields and " -"getter determine on which level the constraints are " -"placed (see ). The " -"constraint node is then used to add a constraint on the " -"corresponding level. Each constraint definition must define the class via " -"the annotation attribute. The constraint attributes " -"required by the Bean Validation specification (message, " -"groups and payload) have dedicated " -"nodes. All other constraint specific attributes are configured using the " -"element node." -msgstr "" -"这个xml的定义基本上和通过编程方式差不多, 所以只需要简单的解释. 其中" -"default-package属性用来定义一个默认的包路径, 如果下面指" -"定的class不是全限定名称的话,会自动加上这个默认的包路径. 每个xml文件都可以包含" -"任意多个bean节点, 每个对应一个要添加约束条件的实体类." -" 每个实体类只能在所有的xml映射文件中被定义一次, 否则会抛出异" -"常. 通过添加ignore-annotations 属性并" -"将其设置为true可以忽略在对应bean上" -"添加的约束标注信息, 这个属性的默认值就是true. " -"ignore-annotations 属性还可以定义在class, fieldsgetter属性上, " -"如果没有明确指定的话, 那么默认级别是bean (可参考 ). constraint 节点用于添加一个约束条件到其父节点对应的元素上, 并且它需要通过" -"annotation属性来指定需要使用哪个约束条件. 对于每个约束条" -"件中所需要的属性, 其中, 由Bean Validation 规范规定的属性(message, groupspayload) 可以" -"通过同名的子节点来定义, 而每个约束条件中自定义的属性, 则需要使用" -"element节点来定义." - -#. Tag: para -#: xmlconfiguration.xml:161 -#, no-c-format -msgid "" -"The class node also allows to reconfigure the default group sequence (see " -") via the group-" -"sequence node." -msgstr "" -"class节点同样支持通过group-sequence" -"节点来对一个类的默认校验组进行重定义(请参考 ) ." - -#. Tag: para -#: xmlconfiguration.xml:165 -#, fuzzy, no-c-format -msgid "" -"Last but not least, the list of ConstraintValidators " -"associated to a given constraint can be altered via the constraint-" -"definition node. The annotation attribute " -"represents the constraint annotation being altered. The validated-" -"by elements represent the (ordered) list of " -"ConstraintValidator implementations associated to the " -"constraint. If include-existing-validator is set to " -"false, validators defined on the constraint annotation " -"are ignored. If set to true, the list of constraint " -"validators described in XML is concatenated to the list of validators " -"specified on the annotation." -msgstr "" -"最后, 你还可以通过constraint-definition节点来对一个指定" -"的约束条件上绑定的校验器(ConstraintValidator)进行修" -"改. 此节点上的annotation对应要修改的约束条件, 而" -"validated-by子节点中(按顺序)列出要关联到此约束条件上的校" -"验器( ConstraintValidator的实现类), 而" -"include-existing-validator属性如果是false的话,那么默认定义在此约束条件上的校验器将被忽略, 如果为" -"true, 那么在xml中定义的校验器会被添加在约束条件上默认定" -"义的校验器的后面." diff --git a/documentation/zanata.sh b/documentation/zanata.sh deleted file mode 100755 index 85909f4ad8..0000000000 --- a/documentation/zanata.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/sh - -# zanata.sh -# -# Script for pushing and pulling translation files to and from Zanata server - -set -eu - -push ( ) -{ - PUSH_PO_FILES=0 - while getopts "a" option - do - case $option in - a ) PUSH_PO_FILES=1;; - * ) usage;; - esac - done - - # update pot files before importing to zanata - echo "Updating POT files" - mvn jdocbook:update-pot - if [ $PUSH_PO_FILES -gt 0 ]; then - echo "Updating PO files" - mvn jdocbook:update-po - fi - - # push updated pot files to zanata for translation - echo "Pushing updated POT files to Zanata for translation" - PUSH_OPTION="" - if [ $PUSH_PO_FILES -gt 0 ]; then - PUSH_OPTION="-Dzanata.importPo" - fi - mvn zanata:publican-push $PUSH_OPTION -e - - echo "Finished! You may want to check pot into version control to track the updated POT files" -} - -pull ( ) -{ - echo "Pulling latest translations from Zanata server" - mvn zanata:publican-pull -e -Dzanata.dstDir=src/main/docbook - echo "Finished! Don't forget to check locale dirs into version control to record the updated PO files" -} - -draft ( ) -{ - DRAFT_DIR="target/draft" - while getopts "d:" option - do - case $option in - d ) DRAFT_DIR=$OPTARG;; - * ) usage;; - esac - done - - # PO files are saved to a directory outside the locale dirs - # to avoid overwriting versioned files. - - mkdir -p $DRAFT_DIR - - echo "Pulling latest translations from Zanata server" - # write PO files to a different directory under target - mvn zanata:publican-pull -e -Dzanata.dstDir=$DRAFT_DIR - - # draft build the translated documents - - # copy en-US source to draft dir for use by jDocBook - cp -a ./src/main/docbook/en-US $DRAFT_DIR/en-US - - echo "Building translated documentation with jDocBook" - - # pick up PO files from the different directory above - mvn jdocbook:resources jdocbook:translate jdocbook:generate -DjdocbookSourceDirectory=$DRAFT_DIR - - echo "Finished!" -} - -usage ( ) -{ - echo "Usage: `basename $0` []" - echo "where is one of:" - echo " push : Import updated source content from git to Zanata." - echo " [-a] Update and push translations as well" - echo " pull : Export translations from Zanata to git" - echo " draft : Build DocBook document using latest translations" - echo " [-d draftdir] Directory in which to build the draft documentation" - exit $E_OPTERROR -} - -NO_ARGS=0 -E_OPTERROR=85 - -if [ $# -eq "$NO_ARGS" ] # Script invoked with no command-line args? -then - usage -fi - -command=$1 -shift - -case $command in - "push" ) if [ $# -eq "$NO_ARGS" ] - then - push - else - push "${@}" - fi;; - "pull" ) pull;; - "draft" ) if [ $# -eq "$NO_ARGS" ] - then - draft - else - draft "${@}" - fi;; - * ) usage;; -esac diff --git a/documentation/zanata.xml b/documentation/zanata.xml deleted file mode 100644 index ec147e801e..0000000000 --- a/documentation/zanata.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - https://translate.jboss.org/ - hibernate_validator - 5.0.0 - - de - es - fr - it - ja - ko - pt-BR - zh-Hans - zh-Hant - -