Author: stliu
Date: 2010-08-22 11:49:15 -0400 (Sun, 22 Aug 2010)
New Revision: 20218
Modified:
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/customconstraints.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/xmlconfiguration.po
Log:
HV-351 translation
Modified:
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/customconstraints.po
===================================================================
---
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/customconstraints.po 2010-08-22
10:28:50 UTC (rev 20217)
+++
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/customconstraints.po 2010-08-22
15:49:15 UTC (rev 20218)
@@ -6,7 +6,7 @@
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To:
http://bugs.kde.org\n"
"POT-Creation-Date: 2010-07-06 14:46+0000\n"
-"PO-Revision-Date: 2010-08-20 00:04+0830\n"
+"PO-Revision-Date: 2010-08-21 02:16+0830\n"
"Last-Translator: Strong Liu <stliu(a)hibernate.org>\n"
"Language-Team: none\n"
"MIME-Version: 1.0\n"
@@ -101,13 +101,13 @@
#: customconstraints.xml:74
#, 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 ""
+msgstr "现在我们可以来定义真正的约束标注了. 如果你以前没有创建过标注(annotation)的话,那么这个可能看起来有点吓人, 可是其实没有那么难的
:)"
#. Tag: title
#: customconstraints.xml:79
#, no-c-format
msgid "Defining CheckCase constraint annotation"
-msgstr ""
+msgstr "定义一个CheckCase的约束标注"
#. Tag: programlisting
#: customconstraints.xml:81
@@ -141,36 +141,63 @@
"\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:84
#, no-c-format
msgid "An annotation type is defined using the <code>@interface</code>
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 ""
+msgstr "一个标注(annotation) 是通过<code>@interface</code>关键字来定义的.
这个标注中的属性是声明成类似方法的样式的. 根据Bean Validation API 规范的要求"
#. Tag: para
#: customconstraints.xml:91
#, no-c-format
msgid "an attribute <property>message</property> that returns the
default key for creating error messages in case the constraint is violated"
-msgstr ""
+msgstr "<property>message</property>属性, 这个属性被用来定义默认得消息模版,
当这个约束条件被验证失败的时候,通过此属性来输出错误信息."
#. Tag: para
#: customconstraints.xml:97
#, no-c-format
msgid "an attribute <property>groups</property> that allows the
specification of validation groups, to which this constraint belongs (see <xref
linkend=\"validator-usingvalidator-validationgroups\"/>). This must default
to an empty array of type
<classname>Class<?></classname>."
-msgstr ""
+msgstr "<property>groups</property> 属性, 用于指定这个约束条件属于哪(些)个校验组(请参考<xref
linkend=\"validator-usingvalidator-validationgroups\"/>).
这个的默认值必须是<classname>Class<?></classname>类型到空到数组."
#. Tag: para
#: customconstraints.xml:105
#, no-c-format
msgid "an attribute <classname>payload</classname> 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 ""
+msgstr "<classname>payload</classname> 属性, Bean Validation API
的使用者可以通过此属性来给约束条件指定严重级别. 这个属性并不被API自身所使用."
#. Tag: para
#: customconstraints.xml:109
#, no-c-format
msgid "An example for a custom payload could be the definition of a severity."
-msgstr ""
+msgstr "通过payload属性来指定默认错误严重级别的示例"
#. Tag: programlisting
#: customconstraints.xml:112
@@ -191,66 +218,80 @@
" // ...\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:114
#, no-c-format
msgid "Now a client can after the validation of a
<classname>ContactDetails</classname> instance access the severity of a
constraint using
<methodname>ConstraintViolation.getConstraintDescriptor().getPayload()</methodname>
and adjust its behaviour depending on the severity."
-msgstr ""
+msgstr "这样, 在校验完一个<classname>ContactDetails</classname> 的示例之后,
你就可以通过调用<methodname>ConstraintViolation.getConstraintDescriptor().getPayload()</methodname>来得到之前指定到错误级别了,并且可以根据这个信息来决定接下来到行为."
#. Tag: para
#: customconstraints.xml:123
#, no-c-format
msgid "Besides those three mandatory attributes
(<property>message</property>, <property>groups</property> and
<property>payload</property>) we add another one allowing for the required
case mode to be specified. The name <property>value</property> is a special
one, which can be omitted upon using the annotation, if it is the only attribute
specified, as e.g. in <code>(a)CheckCase(CaseMode.UPPER)</code>."
-msgstr ""
+msgstr "除了这三个强制性要求的属性(<property>message</property>,
<property>groups</property> 和 <property>payload</property>) 之外,
我们还添加了一个属性用来指定所要求到字符串模式. 此属性的名称<property>value</property>在annotation的定义中比较特殊,
如果只有这个属性被赋值了的话, 那么, 在使用此annotation到时候可以忽略此属性名称,
即<code>(a)CheckCase(CaseMode.UPPER)</code>."
#. Tag: para
#: customconstraints.xml:131
#, no-c-format
msgid "In addition we annotate the annotation type with a couple of so-called meta
annotations:"
-msgstr ""
+msgstr "另外, 我们还给这个annotation标注了一些(所谓的) 元标注( 译注: 或\"元模型信息\"?, \"meta
annotatioins\"): "
#. Tag: para
#: customconstraints.xml:136
#, no-c-format
msgid "<code>@Target({ METHOD, FIELD, ANNOTATION_TYPE })</code>: Says,
that methods, fields and annotation declarations may be annotated with @CheckCase (but not
type declarations e.g.)"
-msgstr ""
+msgstr "<code>@Target({ METHOD, FIELD, ANNOTATION_TYPE })</code>:
表示@CheckCase 可以被用在方法, 字段或者annotation声明上."
#. Tag: para
#: customconstraints.xml:142
#, no-c-format
msgid "<code>@Retention(RUNTIME)</code>: Specifies, that annotations of
this type will be available at runtime by the means of reflection"
-msgstr ""
+msgstr "<code>@Retention(RUNTIME)</code>: 表示这个标注信息是在运行期通过反射被读取的."
#. Tag: para
#: customconstraints.xml:148
#, no-c-format
msgid "<code>@Constraint(validatedBy = CheckCaseValidator.class)</code>:
Specifies the validator to be used to validate elements annotated with @CheckCase"
-msgstr ""
+msgstr "<code>@Constraint(validatedBy =
CheckCaseValidator.class)</code>: 指明使用那个校验器(类) 去校验使用了此标注的元素."
#. Tag: para
#: customconstraints.xml:154
#, no-c-format
msgid "<code>@Documented</code>: Says, that the use of
<code>@CheckCase</code> will be contained in the JavaDoc of elements annotated
with it"
-msgstr ""
+msgstr "<code>@Documented</code>:
表示在对使用了<code>@CheckCase</code>的类进行javadoc操作到时候, 这个标注会被添加到javadoc当中."
#. Tag: title
#: customconstraints.xml:162
#, no-c-format
msgid "The constraint validator"
-msgstr ""
+msgstr "约束校验器"
#. Tag: para
#: customconstraints.xml:165
#, no-c-format
msgid "Next, we need to implement a constraint validator, that's able to
validate elements with a <classname>@CheckCase</classname> annotation. To do
so, we implement the interface ConstraintValidator as shown below:"
-msgstr ""
+msgstr "接下来, 我们需要实现一个约束验证器,
它是被用来校验应用了<classname>@CheckCase</classname>标注到元素到. 如下面例子所示,
这个验证器需要实现ConstraintValidator接口."
#. Tag: title
#: customconstraints.xml:171
#, no-c-format
msgid "Implementing a constraint validator for the constraint
<classname>CheckCase</classname>"
-msgstr ""
+msgstr "约束条件<classname>CheckCase</classname>的验证器"
#. Tag: programlisting
#: customconstraints.xml:174
@@ -282,48 +323,73 @@
"\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:177
#, no-c-format
msgid "The <classname>ConstraintValidator</classname> interface defines
two type parameters, which we set in our implementation. The first one specifies the
annotation type to be validated (in our example
<classname>CheckCase</classname>), the second one the type of elements, which
the validator can handle (here <classname>String</classname>)."
-msgstr ""
+msgstr "<classname>ConstraintValidator</classname>定义了两个泛型参数,
第一个是这个校验器所服务到标注类型(在我们的例子中即<classname>CheckCase</classname>),
第二个这个校验器所支持到被校验元素到类型 (即<classname>String</classname>)."
#. Tag: para
#: customconstraints.xml:184
#, no-c-format
msgid "In case a constraint annotation is allowed at elements of different types, a
<classname>ConstraintValidator</classname> for each allowed type has to be
implemented and registered at the constraint annotation as shown above."
-msgstr ""
+msgstr "如果一个约束标注支持多种类型到被校验元素的话,
那么需要为每个所支持的类型定义一个<classname>ConstraintValidator</classname>,并且注册到约束标注中."
#. Tag: para
#: customconstraints.xml:189
#, no-c-format
msgid "The implementation of the validator is straightforward. The
<methodname>initialize()</methodname> method gives us access to the attribute
values of the annotation to be validated. In the example we store the
<classname>CaseMode</classname> in a field of the validator for further
usage."
-msgstr ""
+msgstr "这个验证器的实现就很平常了, <methodname>initialize()</methodname>
方法传进来一个所要验证的标注类型的实例, 在本例中,
我们通过此实例来获取其value属性的值,并将其保存为<classname>CaseMode</classname>类型的成员变量供下一步使用."
#. Tag: para
#: customconstraints.xml:195
#, no-c-format
msgid "In the <methodname>isValid()</methodname> method we implement the
logic, that determines, whether a <classname>String</classname> is valid
according to a given <classname>@CheckCase</classname> annotation or not. This
decision depends on the case mode retrieved in
<classname>initialize()</classname>. As the Bean Validation specification
recommends, we consider <code>null</code> values as being valid. If
<code>null</code> is not a valid value for an element, it should be annotated
with <code>@NotNull</code> explicitly."
-msgstr ""
+msgstr "<methodname>isValid()</methodname>是实现真正的校验逻辑的地方,
判断一个给定的<classname>String</classname>对于<classname>@CheckCase</classname>这个约束条件来说是否是合法的,
同时这还要取决于在<classname>initialize()</classname>中获得的大小写模式. 根据Bean
Validation中所推荐的做法, 我们认为<code>null</code>是合法的值.
如果<code>null</code>对于这个元素来说是不合法的话,那么它应该使用<code>(a)xn--notnull</code>-gu56b3xg1u4b."
#. Tag: title
#: customconstraints.xml:205
#, no-c-format
msgid "The ConstraintValidatorContext"
-msgstr ""
+msgstr "ConstraintValidatorContext"
#. Tag: para
#: customconstraints.xml:207
#, no-c-format
msgid "relies on the default error message generation by just returning
<constant>true</constant> or <constant>false</constant> from the
<methodname>isValid</methodname> call. Using the passed
<classname>ConstraintValidatorContext</classname> 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
<classname>ConstraintValidatorContext</classname> API is modeled as fluent
interface and is best demonstrated with an example:"
-msgstr ""
+msgstr "中的<methodname>isValid</methodname>使用了约束条件中定义的错误消息模板,
然后返回一个<constant>true</constant> 或者 <constant>false</constant>.
通过使用传入的<classname>ConstraintValidatorContext</classname>对象,
我们还可以给约束条件中定义的错误信息模板来添加额外的信息或者完全创建一个新的错误信息模板. "
#. Tag: title
#: customconstraints.xml:219
#, no-c-format
msgid "Use of ConstraintValidatorContext to define custom error messages"
-msgstr ""
+msgstr "使用ConstraintValidatorContext来自定义错误信息"
#. Tag: programlisting
#: customconstraints.xml:222
@@ -364,18 +430,52 @@
"\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:225
#, 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
<classname>ConstraintValidatorContext</classname> results in the same error
message as the default error message generation."
-msgstr ""
+msgstr "演示了如果创建一个新的错误信息模板来替换掉约束条件中定义的默认的. 在本例中,
实际上通过调用<classname>ConstraintValidatorContext</classname>达到了一个使用默认消息模板的效果."
#. Tag: para
#: customconstraints.xml:231
#, no-c-format
msgid "It is important to end each new constraint violation with
<methodname>addConstraintViolation</methodname>. Only after that the new
constraint violation will be created."
-msgstr ""
+msgstr "在创建新的constraint
violation的时候一定要记得调用<methodname>addConstraintViolation</methodname>, 只有这样,
这个新的constraint violation才会被真正的创建."
#. Tag: para
#: customconstraints.xml:236
@@ -405,54 +505,65 @@
" 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:254
#, no-c-format
msgid "The error message"
-msgstr ""
+msgstr "校验错误信息"
#. Tag: para
#: customconstraints.xml:256
#, no-c-format
msgid "Finally we need to specify the error message, that shall be used, in case a
<classname>@CheckCase</classname> constraint is violated. To do so, we add the
following to our custom <filename>ValidationMessages.properties</filename>
(see also <xref linkend=\"section-message-interpolation\"/>)"
-msgstr ""
+msgstr "最后,
我们还需要指定如果<classname>@CheckCase</classname>这个约束条件验证的时候,没有通过的话的校验错误信息.
我们可以添加下面的内容到我们项目自定义的<filename>ValidationMessages.properties</filename> (参考
<xref linkend=\"section-message-interpolation\"/>)文件中."
#. Tag: title
#: customconstraints.xml:263
#, no-c-format
msgid "Defining a custom error message for the
<classname>CheckCase</classname> constraint"
-msgstr ""
+msgstr "为<classname>CheckCase</classname>约束定义一个错误信息"
#. Tag: programlisting
#: customconstraints.xml:266
#, no-c-format
msgid "com.mycompany.constraints.CheckCase.message=Case mode must be {value}."
-msgstr ""
+msgstr "com.mycompany.constraints.CheckCase.message=Case mode must be
{value}."
#. Tag: para
#: customconstraints.xml:269
#, 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
<classname>@CheckCase</classname> annotation to look up the error message in
this file."
-msgstr ""
+msgstr "如果发现校验错误了的话, 你所使用的Bean
Validation的实现会用我们定义在<classname>@CheckCase</classname>中message属性上的值作为键到这个文件中去查找对应的错误信息."
#. Tag: title
#: customconstraints.xml:276
#, no-c-format
msgid "Using the constraint"
-msgstr ""
+msgstr "应用约束条件"
#. Tag: para
#: customconstraints.xml:278
#, no-c-format
msgid "Now that our first custom constraint is completed, we can use it in the
<classname>Car</classname> class from the <xref
linkend=\"validator-gettingstarted\"/> chapter to specify that the
<property>licensePlate</property> field shall only contain upper-case
strings:"
-msgstr ""
+msgstr "现在我们已经有了一个自定义的约束条件了, 我们可以把它用在<xref
linkend=\"validator-gettingstarted\"/>中的<classname>Car</classname>类上,
来校验此类的<property>licensePlate</property>属性的值是否全都是大写字母."
#. Tag: title
#: customconstraints.xml:285
#, no-c-format
msgid "Applying the <classname>CheckCase</classname> constraint"
-msgstr ""
+msgstr "应用<classname>CheckCase</classname>约束条件"
#. Tag: programlisting
#: customconstraints.xml:288
@@ -488,18 +599,47 @@
"\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:291
#, no-c-format
msgid "Finally let's demonstrate in a little test that the
<classname>@CheckCase</classname> constraint is properly validated:"
-msgstr ""
+msgstr
"最后,让我们用一个简单的测试来检测<classname>@CheckCase</classname>约束已经被正确的校验了:"
#. Tag: title
#: customconstraints.xml:296
#, no-c-format
msgid "Testcase demonstrating the <classname>CheckCase</classname>
validation"
-msgstr ""
+msgstr "演示<classname>CheckCase</classname>的验证过程"
#. Tag: programlisting
#: customconstraints.xml:299
@@ -554,30 +694,78 @@
" }\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:305
#, no-c-format
msgid "Constraint composition"
-msgstr ""
+msgstr "约束条件组合"
#. Tag: para
#: customconstraints.xml:307
#, no-c-format
msgid "Looking at the <property>licensePlate</property> field of the
<classname>Car</classname> class in <xref
linkend=\"example-car-with-checkcase\"/>, 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
<property>licensePlate</property> field in another class, we would have to
copy all constraint declarations to the other class as well, violating the DRY
principle."
-msgstr ""
+msgstr "在<xref linkend=\"example-car-with-checkcase\"/>中我们可以看到,
类<classname>Car</classname>的<property>licensePlate</property>属性上定义了三个约束条件.
在某些复杂的场景中, 可能还会有更多的约束条件被定义到同一个元素上面, 这可能会让代码看起来有些复杂, 另外,
如果在另外的类里面还有一个<property>licensePlate</property>属性, 我们可能还要把这些约束条件再拷贝到这个属性上,
但是这样做又违反了 DRY 原则."
#. Tag: para
#: customconstraints.xml:316
#, no-c-format
msgid "This problem can be tackled using compound constraints. In the following we
create a new constraint annotation <classname>@ValidLicensePlate</classname>,
that comprises the constraints <classname>@NotNull</classname>,
<classname>@Size</classname> and
<classname>@CheckCase</classname>:"
-msgstr ""
+msgstr "这个问题可以通过使用组合约束条件来解决.
接下来让我们来创建一个新的约束标注<classname>@ValidLicensePlate</classname>,
它组合了<classname>@NotNull</classname>, <classname>@Size</classname>
和 <classname>@CheckCase</classname>:"
#. Tag: title
#: customconstraints.xml:323
#, no-c-format
msgid "Creating a composing constraint
<classname>ValidLicensePlate</classname>"
-msgstr ""
+msgstr "创建一个约束条件组合<classname>ValidLicensePlate</classname>"
#. Tag: programlisting
#: customconstraints.xml:326
@@ -614,24 +802,54 @@
"\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"
+"(a)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:329
#, 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 <classname>@CheckCase</classname> annotation). As no additional
validation is required for the <classname>@ValidLicensePlate</classname>
annotation itself, we don't declare a validator within the
<classname>@Constraint </classname>meta annotation."
-msgstr ""
+msgstr "我们只需要把要组合的约束标注在这个新的类型上加以声明 (注: 这正是我们为什么把annotation
types作为了<classname>@CheckCase</classname>的一个target). 因为这个组合不需要额外的校验器,
所以不需要声明validator属性."
#. Tag: para
#: customconstraints.xml:337
#, no-c-format
msgid "Using the new compound constraint at the
<property>licensePlate</property> field now is fully equivalent to the
previous version, where we declared the three constraints directly at the field
itself:"
-msgstr ""
+msgstr "现在,
在<property>licensePlate</property>属性上使用这个新定义的\"约束条件\" (其实是个组合)
和之前在其上声明那三个约束条件是一样的效果了."
#. Tag: title
#: customconstraints.xml:343
#, no-c-format
msgid "Application of composing constraint
<classname>ValidLicensePlate</classname>"
-msgstr ""
+msgstr "使用<classname>ValidLicensePlate</classname>组合约束"
#. Tag: programlisting
#: customconstraints.xml:346
@@ -648,6 +866,16 @@
"\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:349
@@ -659,7 +887,7 @@
#: customconstraints.xml:359
#, no-c-format
msgid "Usage of <classname>@ReportAsSingleViolation</classname>"
-msgstr ""
+msgstr "<classname>@ReportAsSingleViolation</classname>的用法"
#. Tag: programlisting
#: customconstraints.xml:361
@@ -677,4 +905,15 @@
"\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"
+"}"
Modified:
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/xmlconfiguration.po
===================================================================
---
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/xmlconfiguration.po 2010-08-22
10:28:50 UTC (rev 20217)
+++
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/xmlconfiguration.po 2010-08-22
15:49:15 UTC (rev 20218)
@@ -6,8 +6,8 @@
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To:
http://bugs.kde.org\n"
"POT-Creation-Date: 2010-07-06 14:46+0000\n"
-"PO-Revision-Date: 2010-07-06 14:46+0000\n"
-"Last-Translator: Automatically generated\n"
+"PO-Revision-Date: 2010-08-22 23:44+0830\n"
+"Last-Translator: Strong Liu <stliu(a)hibernate.org>\n"
"Language-Team: none\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -17,190 +17,146 @@
#: xmlconfiguration.xml:25
#, no-c-format
msgid "XML configuration"
-msgstr ""
+msgstr "XML configuration"
#. Tag: filename
#: xmlconfiguration.xml:28
#, no-c-format
msgid "<filename>validation.xml</filename>"
-msgstr ""
+msgstr "<filename>validation.xml</filename>"
#. Tag: para
#: xmlconfiguration.xml:30
#, no-c-format
-msgid ""
-"The key to enable XML configuration for Hibernate Validator is the file "
-"<filename>validation.xml</filename>. If this file exists in the
classpath "
-"its configuration will be applied when the
<classname>ValidationFactory</"
-"classname> gets created. <xref
linkend=\"image-validation-configuration\"/> "
-"shows a model view of the xsd <filename>valiation.xml</filename> has to
"
-"adhere to."
-msgstr ""
+msgid "The key to enable XML configuration for Hibernate Validator is the file
<filename>validation.xml</filename>. If this file exists in the classpath its
configuration will be applied when the
<classname>ValidationFactory</classname> gets created. <xref
linkend=\"image-validation-configuration\"/> shows a model view of the xsd
<filename>valiation.xml</filename> has to adhere to."
+msgstr "我们可以使用<filename>validation.xml</filename>来对Hibernate
Validator进行配置.
<classname>ValidationFactory</classname>在初始化的时候会在类路径下寻找此文件,如果找到的话,就会应用其中定义的配置信息.
<xref
linkend=\"image-validation-configuration\"/>显示了<filename>valiation.xml</filename>的xsd模型."
#. Tag: title
#: xmlconfiguration.xml:37
#, no-c-format
msgid "validation-configuration-1.0.xsd"
-msgstr ""
+msgstr "validation-configuration-1.0.xsd"
#. Tag: para
#: xmlconfiguration.xml:52
#, no-c-format
-msgid ""
-"shows the several configuration options of
<filename>validation.xml</"
-"filename>."
-msgstr ""
+msgid "shows the several configuration options of
<filename>validation.xml</filename>."
+msgstr "列出了<filename>validation.xml</filename>中的一些常用的配置项."
#. Tag: title
#: xmlconfiguration.xml:56
#, no-c-format
msgid "<title>validation.xml</title>"
-msgstr ""
+msgstr "<title>validation.xml</title>"
#. Tag: programlisting
#: xmlconfiguration.xml:58
#, no-c-format
msgid ""
-"<validation-config
xmlns=\"http://jboss.org/xml/ns/javax/validation/"
-"configuration\"\n"
+"<validation-config
xmlns=\"http://jboss.org/xml/ns/javax/validation/configuration\"...
"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
-"
xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/config...
-"\">\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"
+"
xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/config...
+"
<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>"
msgstr ""
+"<validation-config
xmlns=\"http://jboss.org/xml/ns/javax/validation/configuration\"...
+"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+"
xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/config...
+"
<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:62
#, no-c-format
-msgid ""
-"There can only be one <filename>validation.xml</filename> in the
classpath. "
-"If more than one is found an exception is thrown."
-msgstr ""
+msgid "There can only be one <filename>validation.xml</filename> in the
classpath. If more than one is found an exception is thrown."
+msgstr "类路径下面只能有一个<filename>validation.xml</filename>,
如果超过一个的话,会抛出异常."
#. Tag: para
#: xmlconfiguration.xml:66
#, no-c-format
-msgid ""
-"All settings shown in the <filename>validation.xml</filename> are
optional "
-"and in the case of <xref linkend=\"example-validation-xml\"/> show
the "
-"defaults used within Hibernate Validator. The node <property>default-"
-"provider</property> allows to choose the Bean Validation provider. This is
"
-"useful if there is more than one provider in the classpath. "
-"<property>message-interpolator</property>,
<property>traversable-resolver</"
-"property> and <property>constraint-validator-factory</property>
allow to "
-"customize the
<classname>javax.validation.MessageInterpolator</classname>, "
-"<classname>javax.validation.TraversableResolver</classname> resp.
"
-"<classname>javax.validation.ConstraintValidatorFactory</classname>. The
same "
-"configuration options are also available programmatically through the "
-"<classname>javax.validation.Configuration</classname>. 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 "
-"<methodname> Configuration.ignoreXmlConfiguration()</methodname>. See
also "
-"<xref linkend=\"validator-bootstrapping\"/>."
-msgstr ""
+msgid "All settings shown in the <filename>validation.xml</filename> are
optional and in the case of <xref linkend=\"example-validation-xml\"/>
show the defaults used within Hibernate Validator. The node
<property>default-provider</property> allows to choose the Bean Validation
provider. This is useful if there is more than one provider in the classpath.
<property>message-interpolator</property>,
<property>traversable-resolver</property> and
<property>constraint-validator-factory</property> allow to customize the
<classname>javax.validation.MessageInterpolator</classname>,
<classname>javax.validation.TraversableResolver</classname> resp.
<classname>javax.validation.ConstraintValidatorFactory</classname>. The same
configuration options are also available programmatically through the
<classname>javax.validation.Configuration</classname>. 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 <methodname>
Configuration.ignoreXmlConfiguration()</methodname>. See also <xref
linkend=\"validator-bootstrapping\"/>."
+msgstr "<filename>validation.xml</filename>中所有的配置信息都是可选的, <xref
linkend=\"example-validation-xml\"/>中就是列出了Hibernate Validator中的默认值.
如果类路径当中存在有多个Bean Validation的实现的话,
那么可以通过<property>default-provider</property>节点指定使用那个Bean Validation的实现.
<property>message-interpolator</property>,
<property>traversable-resolver</property> 和
<property>constraint-validator-factory</property>可以用来指定自定义的<classname>javax.validation.MessageInterpolator</classname>,
<classname>javax.validation.TraversableResolver</classname>和<classname>javax.validation.ConstraintValidatorFactory</classname>.
同样的,
这些配置信息也可以通过编程的方式调用<classname>javax.validation.Configuration</classname>来实现.
另外, 你可以通过API的方式来重写xml中的配置信息, 也可以通过调用<methodname>
Configuration.ignoreXmlConfiguration()</method!
name>来完全的忽略掉xml的配置信息. 请参考<xref
linkend=\"validator-bootstrapping\"/>."
#. Tag: para
#: xmlconfiguration.xml:84
#, no-c-format
-msgid ""
-"Via the <property>constraint-mapping</property> you can list an
arbitrary "
-"number of additional XML files containing the actual constraint "
-"configuration. See <xref
linkend=\"section-mapping-constraints\"/>."
-msgstr ""
+msgid "Via the <property>constraint-mapping</property> you can list an
arbitrary number of additional XML files containing the actual constraint configuration.
See <xref linkend=\"section-mapping-constraints\"/>."
+msgstr
"你可以增加若干个<property>constraint-mapping</property>节点,在每个里面列出一个额外的xml文件用来定义约束规则,
具体请参考<xref linkend=\"section-mapping-constraints\"/>."
#. Tag: para
#: xmlconfiguration.xml:88
#, no-c-format
-msgid ""
-"Last but not least, you can specify provider specific properties via the "
-"<property>property</property> nodes. Hibernate Validator does currently
not "
-"make use of any custom properties."
-msgstr ""
+msgid "Last but not least, you can specify provider specific properties via the
<property>property</property> nodes. Hibernate Validator does currently not
make use of any custom properties."
+msgstr "最后, 你可以通过<property>property</property>来定义各个Bean Validation
实现专属的属性. Hibernate Validator当前并没有使用任何特定的属性."
#. Tag: title
#: xmlconfiguration.xml:94
#, no-c-format
msgid "Mapping constraints"
-msgstr ""
+msgstr "映射约束"
#. Tag: para
#: xmlconfiguration.xml:96
#, no-c-format
-msgid ""
-"Expressing constraints in XML is possible via files adhering to the xsd seen
"
-"in <xref linkend=\"image-mapping-configuration\"/>. Note that these
mapping "
-"files are only processed if listed via
<property>constraint-mapping</"
-"property> in your <filename>validation.xml</filename>."
-msgstr ""
+msgid "Expressing constraints in XML is possible via files adhering to the xsd seen
in <xref linkend=\"image-mapping-configuration\"/>. Note that these
mapping files are only processed if listed via
<property>constraint-mapping</property> in your
<filename>validation.xml</filename>."
+msgstr "我们也可以通过xml来定义约束条件, 只需要这个xml符合<xref
linkend=\"image-mapping-configuration\"/>中所定义的规范. 需要注意的是,
你必须把xml定义的约束列在<filename>validation.xml</filename>的<property>constraint-mapping</property>节点中才能得到处理."
#. Tag: title
#: xmlconfiguration.xml:103
#, no-c-format
msgid "validation-mapping-1.0.xsd"
-msgstr ""
+msgstr "validation-mapping-1.0.xsd"
#. Tag: para
#: xmlconfiguration.xml:118
#, no-c-format
-msgid ""
-"shows how our classes Car and RentalCar from <xref
linkend=\"example-car\"/> "
-"resp. <xref linkend=\"example-rental-car\"/> could be mapped in
XML."
-msgstr ""
+msgid "shows how our classes Car and RentalCar from <xref
linkend=\"example-car\"/> resp. <xref
linkend=\"example-rental-car\"/> could be mapped in XML."
+msgstr "显示了如何通过xml定义的方式来给<xref linkend=\"example-car\"/>中的类Car
以及<xref linkend=\"example-rental-car\"/> 中的RentalCar定义约束条件."
#. Tag: title
#: xmlconfiguration.xml:123
#, no-c-format
msgid "constraints-car.xml"
-msgstr ""
+msgstr "constraints-car.xml"
#. Tag: programlisting
#: xmlconfiguration.xml:125
#, no-c-format
msgid ""
-"<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"
+"<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\"&...
+"
<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"
+" <constraint
annotation=\"javax.validation.constraints.NotNull\"/>\n"
" </field>\n"
" <field name=\"licensePlate\">\n"
-" <constraint
annotation=\"javax.validation.constraints.NotNull"
-"\"/>\n"
+" <constraint
annotation=\"javax.validation.constraints.NotNull\"/>\n"
" </field>\n"
" <field name=\"seatCount\">\n"
-" <constraint
annotation=\"javax.validation.constraints.Min"
-"\">\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"
+" <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"
@@ -216,68 +172,72 @@
" </group-sequence>\n"
" </class>\n"
" </bean>\n"
-" <constraint-definition annotation=\"org.mycompany.CheckCase\"
include-"
-"existing-validator=\"false\">\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>"
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\"&...
+"
<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:128
#, no-c-format
-msgid ""
-"The XML configuration is closely mirroring the programmatic API. For this "
-"reason it should suffice to just add some comments. <property>default-"
-"package</property> is used for all fields where a classname is expected. If
"
-"the specified class is not fully qualified the configured default package "
-"will be used. Every mapping file can then have several
<property>bean</"
-"property> nodes, each describing the constraints on the entity with the "
-"specified class name.<warning> <para>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.</para> </warning>Settings
<property>ignore-"
-"annotations</property> to true means that constraint annotations placed on
"
-"the configured bean are ignored. The default for this value is "
-"<constant>true</constant>. ignore-annotations is also available for the
"
-"nodes <property>class</property>,
<property>fields</property> and "
-"<property>getter</property>. If not explicitly specified on these
levels the "
-"configured <property>bean</property> value applies. Otherwise do the
nodes "
-"<property>class</property>, <property>fields</property> and
"
-"<property>getter</property> determine on which level the constraints
are "
-"placed (see <xref linkend=\"validator-usingvalidator-annotate\"/>).
The "
-"<property>constraint</property> 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 (<property>message</property>,
<property>groups</"
-"property> and <property>payload</property>) have dedicated nodes.
All other "
-"constraint specific attributes are configured using the the "
-"<property>element</property> node."
-msgstr ""
+msgid "The XML configuration is closely mirroring the programmatic API. For this
reason it should suffice to just add some comments.
<property>default-package</property> is used for all fields where a classname
is expected. If the specified class is not fully qualified the configured default package
will be used. Every mapping file can then have several
<property>bean</property> nodes, each describing the constraints on the entity
with the specified class name.<warning> <para>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.</para> </warning>Settings
<property>ignore-annotations</property> to true means that constraint
annotations placed on the configured bean are ignored. The default for this value is
<constant>true</constant>. ignore-annotations is also available for the nodes
<property>class</property>, <property>fields</property> and
<property>getter</property>. If not explic!
itly specified on these levels the configured <property>bean</property> value
applies. Otherwise do the nodes <property>class</property>,
<property>fields</property> and <property>getter</property>
determine on which level the constraints are placed (see <xref
linkend=\"validator-usingvalidator-annotate\"/>). The
<property>constraint</property> 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
(<property>message</property>, <property>groups</property> and
<property>payload</property>) have dedicated nodes. All other constraint
specific attributes are configured using the the <property>element</property>
node."
+msgstr "这个xml的定义基本上和通过编程方式差不多, 所以只需要简单的解释.
其中<property>default-package</property>属性用来定义一个默认的包路径,
如果下面指定的class不是全限定名称的话,会自动加上这个默认的包路径.
每个xml文件都可以包含任意多个<property>bean</property>节点, 每个对应一个要添加约束条件的实体类.<warning>
<para>每个实体类只能在所有的xml映射文件中被定义一次, 否则会抛出异常.</para> </warning>
通过添加<property>ignore-annotations</property>
属性并将其设置为<constant>true</constant>可以忽略在对应<property>bean</property>上添加的约束标注信息,
这个属性的默认值就是<constant>true</constant>.
<property>ignore-annotations</property>
属性还可以定义在<property>class</property>, <property>fields</property> 和
<property>getter</property>属性上, 如果没有明确指定的话, 那么默认级别是<prop!
erty>bean</property> (可参考 <xref
linkend=\"validator-usingvalidator-annotate\"/>).
<property>constraint</property> 节点用于添加一个约束条件到其父节点对应的元素上,
并且它需要通过<property>annotation</property>属性来指定需要使用哪个约束条件. 对于每个约束条件中所需要的属性, 其中,
由Bean Validation 规范规定的属性(<property>message</property>,
<property>groups</property> 和 <property>payload</property>)
可以通过同名的子节点来定义, 而每个约束条件中自定义的属性, 则需要使用<property>element</property>节点来定义."
#. Tag: para
#: xmlconfiguration.xml:156
#, no-c-format
-msgid ""
-"The class node also allows to reconfigure the default group sequence (see "
-"<xref linkend=\"section-default-group-class\"/>) via the
<property>group-"
-"sequence</property> node."
-msgstr ""
+msgid "The class node also allows to reconfigure the default group sequence (see
<xref linkend=\"section-default-group-class\"/>) via the
<property>group-sequence</property> node."
+msgstr
"<property>class</property>节点同样支持通过<property>group-sequence</property>节点来对一个类的默认校验组进行重定义(请参考
<xref linkend=\"section-default-group-class\"/>) ."
#. Tag: para
#: xmlconfiguration.xml:160
#, no-c-format
-msgid ""
-"Last but not least, the list of
<classname>ConstraintValidator</classname>s "
-"associated to a given constraint can be altered via the
<property>constraint-"
-"definition</property> node. The <property>annotation</property>
attribute "
-"represents the constraint annotation being altered. The
<property>validated-"
-"by</property> elements represent the (ordered) list of "
-"<classname>ConstraintValidator</classname> implementations associated
to the "
-"constraint. If <property>include-existing-validator</property> is set
to "
-"<constant>false</constant>, validators defined on the constraint
annotation "
-"are ignored. If set to <constant>true</constant>, the list of "
-"ConstraintValidators described in XML are concatenated to the list of "
-"validators described on the annotation."
-msgstr ""
+msgid "Last but not least, the list of
<classname>ConstraintValidator</classname>s associated to a given constraint
can be altered via the <property>constraint-definition</property> node. The
<property>annotation</property> attribute represents the constraint annotation
being altered. The <property>validated-by</property> elements represent the
(ordered) list of <classname>ConstraintValidator</classname> implementations
associated to the constraint. If
<property>include-existing-validator</property> is set to
<constant>false</constant>, validators defined on the constraint annotation
are ignored. If set to <constant>true</constant>, the list of
ConstraintValidators described in XML are concatenated to the list of validators described
on the annotation."
+msgstr "最后,
你还可以通过<property>constraint-definition</property>节点来对一个指定的约束条件上绑定的校验器(<classname>ConstraintValidator</classname>)进行修改.
此节点上的<property>annotation</property>对应要修改的约束条件,
而<property>validated-by</property>子节点中(按顺序)列出要关联到此约束条件上的校验器(
<classname>ConstraintValidator</classname>的实现类),
而<property>include-existing-validator</property>属性如果是<constant>false</constant>的话,那么默认定义在此约束条件上的校验器将被忽略,
如果为<constant>true</constant>, 那么在xml中定义的校验器会被添加在约束条件上默认定义的校验器的后面."
+