/
bootstrapping.po
819 lines (768 loc) · 32.9 KB
/
bootstrapping.po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
# 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 21:26+0830\n"
"Last-Translator: Strong Liu <stliu@hibernate.org>\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
#, no-c-format
msgid ""
"We already seen in <xref linkend=\"section-validator-instance\"/> the "
"easiest way to create a <classname>Validator</classname> instance - "
"<methodname>Validation.buildDefaultValidatorFactory</methodname>. In this "
"chapter we have a look at the other methods in <classname>javax.validation."
"Validation</classname> and how they allow to configure several aspects of "
"Bean Validation at bootstrapping time."
msgstr ""
"在<xref linkend=\"section-validator-instance\"/>中我们说道过, 最简单的创建一"
"个<classname>Validator</classname>实例的方法是通过<methodname>Validation."
"buildDefaultValidatorFactory</methodname>. 在本章中我们会继续介绍"
"<classname>javax.validation.Validation</classname>中的其他方法, 以及如何通过"
"这些方法在Bean Validation初始化的时候对其进行配置的."
#. Tag: para
#: bootstrapping.xml:33
#, no-c-format
msgid ""
"The different bootstrapping options allow, amongst other things, to "
"bootstrap any Bean Validation implementation on the classpath. Generally, an "
"available provider is discovered by the <ulink url=\"http://java.sun.com/"
"j2se/1.3/docs/guide/jar/jar.html#Service%20Provider\">Java Service Provider</"
"ulink> mechanism. A Bean Validation implementation includes the file "
"<filename>javax.validation.spi.ValidationProvider</filename> in "
"<filename>META-INF/services</filename>. This file contains the fully "
"qualified classname of the <classname>ValidationProvider</classname> of the "
"implementation. In the case of Hibernate Validator this is <classname>org."
"hibernate.validator.HibernateValidator</classname>."
msgstr ""
"The different bootstrapping options allow, amongst other things, to "
"bootstrap any Bean Validation implementation on the classpath. 通常, 一个服务"
"的提供者是能够被<ulink url=\"http://java.sun.com/j2se/1.3/docs/guide/jar/jar."
"html#Service%20Provider\">Java Service Provider</ulink>发现的. 对于Bean "
"Validation的实现(服务提供者)来说, 他们的<filename>META-INF/services</"
"filename>目录下需要包含一个名为<filename>javax.validation.spi."
"ValidationProvider</filename>的文件. 此文件中包含了一个"
"<classname>ValidationProvider</classname>接口的实现类的全路径名称, 具体到"
"Hibernate Validator来说, 就是<classname>org.hibernate.validator."
"HibernateValidator</classname>."
#. Tag: para
#: bootstrapping.xml:46
#, no-c-format
msgid ""
"If there are more than one Bean Validation implementation providers in the "
"classpath and <methodname>Validation.buildDefaultValidatorFactory()</"
"methodname> is used, there is no guarantee which provider will be chosen. To "
"enforce the provider <methodname>Validation.byProvider()</methodname> should "
"be used."
msgstr ""
"如果当前类路径下存在多个Bean Validation的实现, 那么<methodname>Validation."
"buildDefaultValidatorFactory()</methodname>并不能保证具体那个实现会被使用. 如"
"果想指定某一个的话, 请使用<methodname>Validation.byProvider()</methodname>."
#. Tag: title
#: bootstrapping.xml:55
#, no-c-format
msgid ""
"<classname>Configuration</classname> and <classname>ValidatorFactory</"
"classname>"
msgstr ""
"<classname>Configuration</classname> 和 <classname>ValidatorFactory</"
"classname>"
#. Tag: para
#: bootstrapping.xml:58
#, no-c-format
msgid ""
"There are three different methods in the Validation class to create a "
"Validator instance. The easiest in shown in <xref linkend=\"example-build-"
"default-validator-factory\"/>."
msgstr ""
"Validation类提供了三种方法来创建一个Validator的实例, <xref linkend=\"example-"
"build-default-validator-factory\"/>中显示的是最简单的方法."
#. Tag: title
#: bootstrapping.xml:63
#, no-c-format
msgid "Validation.buildDefaultValidatorFactory()"
msgstr "Validation.buildDefaultValidatorFactory()"
#. Tag: programlisting
#: bootstrapping.xml:65
#, 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:68
#, no-c-format
msgid ""
"You can also use the method <methodname>Validation.byDefaultProvider()</"
"methodname> which will allow you to configure several aspects of the created "
"Validator instance:"
msgstr ""
"你也可以通过<methodname>Validation.byDefaultProvider()</methodname>现获取一个"
"Configuration对象, 这样可以对要创建的Validator进行配置."
#. Tag: title
#: bootstrapping.xml:73
#, no-c-format
msgid "Validation.byDefaultProvider()"
msgstr "Validation.byDefaultProvider()"
#. Tag: programlisting
#: bootstrapping.xml:75
#, no-c-format
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();"
#. Tag: para
#: bootstrapping.xml:78
#, no-c-format
msgid ""
"We will learn more about <classname>MessageInterpolator</classname>, "
"<classname>TraversableResolver</classname> and "
"<classname>ConstraintValidatorFactory</classname> in the following sections."
msgstr ""
"<classname>MessageInterpolator</classname>, <classname>TraversableResolver</"
"classname> 和 <classname>ConstraintValidatorFactory</classname>会在后面详细介"
"绍."
#. Tag: para
#: bootstrapping.xml:83
#, no-c-format
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 <classname>Validator</classname> creation looks like:"
msgstr ""
"最后, 你可以指定使用哪个Bean Validation的实现. 如果类路径下存在多个Bean "
"Validation的实现的话,这样就很有必要了. 例如, 如果你想使用Hibernate Validator"
"来作为内部实现来创建<classname>Validator</classname>的话:"
#. Tag: title
#: bootstrapping.xml:91
#, no-c-format
msgid "Validation.byProvider( HibernateValidator.class )"
msgstr "Validation.byProvider( HibernateValidator.class )"
#. Tag: programlisting
#: bootstrapping.xml:93
#, no-c-format
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();"
#. Tag: para
#: bootstrapping.xml:97
#, no-c-format
msgid ""
"The generated <classname>Validator</classname> instance is thread safe and "
"can be cached."
msgstr ""
"创建出来的<classname>Validator</classname>实例是线程安全的, 所以你可以把它缓"
"存起来."
#. Tag: classname
#: bootstrapping.xml:103
#, no-c-format
msgid "ValidationProviderResolver"
msgstr "ValidationProviderResolver"
#. Tag: para
#: bootstrapping.xml:105
#, no-c-format
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 <classname>ValidationProviderResolver</classname>. An example in an "
"OSGi environment you could plug your custom provider resolver like seen in "
"<xref linkend=\"example-provider-resolver\"/>."
msgstr ""
"如果 Java Service Provider机制在你的环境中不能够正常工作, 或者你有特别的"
"classloader设置的话, 你也可以提供一个自定义的"
"<classname>ValidationProviderResolver</classname>.<xref linkend=\"example-"
"provider-resolver\"/>显示了如何在OSGi环境中插入自定义的provider resolver."
#. Tag: title
#: bootstrapping.xml:112
#, no-c-format
msgid "Providing a custom ValidationProviderResolver"
msgstr "使用自定义的ValidationProviderResolver"
#. Tag: programlisting
#: bootstrapping.xml:114
#, no-c-format
msgid ""
"Configuration<?> config = Validation.byDefaultProvider()\n"
" .providerResolver( new OSGiServiceDiscoverer() )\n"
" .configure();\n"
"\n"
"ValidatorFactory factory = config.buildValidatorFactory();\n"
"Validator validator = factory.getValidator();"
msgstr ""
"Configuration<?> config = Validation.byDefaultProvider()\n"
" .providerResolver( new OSGiServiceDiscoverer() )\n"
" .configure();\n"
"\n"
"ValidatorFactory factory = config.buildValidatorFactory();\n"
"Validator validator = factory.getValidator();"
#. Tag: para
#: bootstrapping.xml:117
#, no-c-format
msgid ""
"Your <classname>OSGiServiceDiscoverer</classname> must in this case "
"implement the interface <classname>ValidationProviderResolver</classname>:"
msgstr ""
"在这种情况下, 你的<classname>OSGiServiceDiscoverer</classname>类需要实现"
"<classname>ValidationProviderResolver</classname>接口:"
#. Tag: title
#: bootstrapping.xml:122
#, no-c-format
msgid "ValidationProviderResolver interface"
msgstr "ValidationProviderResolver接口"
#. Tag: programlisting
#: bootstrapping.xml:124
#, no-c-format
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"
"}"
#. Tag: classname
#: bootstrapping.xml:129
#, no-c-format
msgid "MessageInterpolator"
msgstr "MessageInterpolator"
#. Tag: para
#: bootstrapping.xml:131
#, fuzzy, no-c-format
msgid ""
"already discussed the default message interpolation algorithm. If you have "
"special requirements for your message interpolation you can provide a custom "
"interpolator using <methodname>Configuration.messageInterpolator()</"
"methodname>. This message interpolator will be shared by all validators "
"generated by the <classname>ValidatorFactory</classname> created from this "
"<classname>Configuration</classname>. <xref linkend=\"example-message-"
"interpolator\"/> 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 ""
"已经讨轮过默认的错误消息解析机制. 如果这个默认的实现不能满足你的需求的话, 你"
"还可以通过<methodname>Configuration.messageInterpolator()</methodname>方法来"
"提供你自定义的消息解析器. 这样, 所有通过<classname>Configuration</classname>"
"创建出来的<classname>ValidatorFactory</classname>生成的校验器都会使用此消息解"
"析器(请参考 <xref linkend=\"example-message-interpolator\"/>)."
#. Tag: para
#: bootstrapping.xml:144
#, no-c-format
msgid ""
"${validatedValue}: this will call <methodname>String.valueOf </methodname>on "
"the validated value."
msgstr ""
#. Tag: para
#: bootstrapping.xml:149
#, no-c-format
msgid ""
"${validatedValue:<format>}: provide your own format string which will "
"be passed to <code>String.format</code> together with the validated value. "
"Refer to the javadoc of <code>String.format</code> for more information "
"about the format options."
msgstr ""
#. Tag: title
#: bootstrapping.xml:158
#, no-c-format
msgid "Providing a custom MessageInterpolator"
msgstr "自定义的MessageInterpolator"
#. Tag: programlisting
#: bootstrapping.xml:160
#, fuzzy, no-c-format
msgid ""
"Configuration<?> configuration = Validation.byDefaultProvider()."
"configure();\n"
"ValidatorFactory factory = configuration\n"
" .messageInterpolator(new ValueFormatterMessageInterpolator(configuration."
"getDefaultMessageInterpolator()))\n"
" .buildValidatorFactory();\n"
"\n"
"Validator validator = factory.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: para
#: bootstrapping.xml:164
#, no-c-format
msgid ""
"It is recommended that <classname>MessageInterpolator</classname> "
"implementations delegate final interpolation to the Bean Validation default "
"<classname>MessageInterpolator</classname> to ensure standard Bean "
"Validation interpolation rules are followed. The default implementation is "
"accessible through <methodname>Configuration.getDefaultMessageInterpolator()"
"</methodname>."
msgstr ""
"It is recommended that <classname>MessageInterpolator</classname> "
"implementations delegate final interpolation to the Bean Validation default "
"<classname>MessageInterpolator</classname> to ensure standard Bean "
"Validation interpolation rules are followed. The default implementation is "
"accessible through <methodname>Configuration.getDefaultMessageInterpolator()"
"</methodname>."
#. Tag: title
#: bootstrapping.xml:173
#, no-c-format
msgid "ResourceBundleLocator"
msgstr "ResourceBundleLocator"
#. Tag: para
#: bootstrapping.xml:175
#, no-c-format
msgid ""
"A common use case is the ability to specify your own resource bundles for "
"message interpolation. The default <classname>MessageInterpolator</"
"classname> implementation in Hibernate Validator is called "
"<classname>ResourceBundleMessageInterpolator</classname> and per default "
"loads resource bundles via <methodname>ResourceBundle.getBundle</"
"methodname>. However, <classname>ResourceBundleMessageInterpolator</"
"classname> also allows you to specify a custom implementation of "
"<classname>ResourceBundleLocator</classname> allowing you to provide your "
"own resource bundles. <xref linkend=\"example-resource-bundle-locator\"/> "
"shows an example. In the example<methodname> HibernateValidatorConfiguration."
"getDefaultResourceBundleLocator</methodname> is used to retrieve the default "
"<classname>ResourceBundleLocator</classname> which then can be passed to the "
"custom implementation in order implement delegation."
msgstr ""
"一个普遍的需求是你可能需要为错误消息解析指定你自己的resource bundles. "
"<classname>ResourceBundleMessageInterpolator</classname>是Hibernate Validator"
"中默认的<classname>MessageInterpolator</classname>的实现, 它默认情况下是通过"
"<methodname>ResourceBundle.getBundle</methodname>来获取resource bundle的. 不"
"过, <classname>ResourceBundleMessageInterpolator</classname>也支持你指定一个"
"自定义的<classname>ResourceBundleLocator</classname>实现来提供你自己的"
"resource bundle. <xref linkend=\"example-resource-bundle-locator\"/>提供了一"
"个示例. 在这个例子中, 先通过<methodname> HibernateValidatorConfiguration."
"getDefaultResourceBundleLocator</methodname>获取默认的"
"<classname>ResourceBundleLocator</classname>实现, 然后再用你自定义的实现把默"
"认的包装起来, 代理模式."
#. Tag: title
#: bootstrapping.xml:194
#, no-c-format
msgid "Providing a custom ResourceBundleLocator"
msgstr "自定义的ResourceBundleLocator"
#. Tag: programlisting
#: bootstrapping.xml:196
#, no-c-format
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));"
#. Tag: para
#: bootstrapping.xml:199
#, no-c-format
msgid ""
"Hibernate Validator provides the following implementation of "
"<classname>ResourceBundleLocator</classname> - "
"<classname>PlatformResourceBundleLocator</classname> (the default) and "
"<classname>AggregateResourceBundleLocator</classname>. 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提供了两个<classname>ResourceBundleLocator</classname>的实"
"现 - <classname>PlatformResourceBundleLocator</classname> (默认) 和 "
"<classname>AggregateResourceBundleLocator</classname>. 后者可以定义一系列的"
"resource bundle, 然后它会读取这些文件, 并且把它们组合成一个. 更多信息请参考此"
"类的javadoc 文档."
#. Tag: classname
#: bootstrapping.xml:210
#, no-c-format
msgid "TraversableResolver"
msgstr "TraversableResolver"
#. Tag: para
#: bootstrapping.xml:212
#, no-c-format
msgid ""
"The usage of the <classname>TraversableResolver</classname> 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 <classname>TraversableResolver</"
"classname> interface (see <xref linkend=\"example-traversable-resolver\"/>). "
"In the example HibernateValidatorConfiguration."
msgstr ""
"到目前位置我们还没有讨论过<classname>TraversableResolver</classname>接口, 它"
"的设计目的是在某些情况下, 我们可能不应该去获取一个属性的状态. 最典型的情况就"
"是一个延迟加载的属性或者与JPA中涉及到关联关系的时候. 当验证这两种情况的属性的"
"时候, 很可能会触发一次对数据库的查询.Bean Validation正是通过"
"<classname>TraversableResolver</classname>接口来控制能否访问某一个属性的 "
"(<xref linkend=\"example-traversable-resolver\"/>)."
#. Tag: title
#: bootstrapping.xml:224
#, no-c-format
msgid "TraversableResolver interface"
msgstr "TraversableResolver接口"
#. Tag: programlisting
#: bootstrapping.xml:226
#, no-c-format
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"
"}"
#. Tag: para
#: bootstrapping.xml:229
#, fuzzy, no-c-format
msgid ""
"Hibernate Validator provides two <classname>TraversableResolver</classname>s "
"out of the box which will be enabled automatically depending on your "
"environment. The first is the <classname>DefaultTraversableResolver</"
"classname> which will always return true for <methodname>isReachable()</"
"methodname> and <methodname>isTraversable()</methodname>. The second is the "
"<classname>JPATraversableResolver</classname> which gets enabled when "
"Hibernate Validator gets used in combination with JPA 2. In case you have to "
"provide your own resolver you can do so again using the "
"<classname>Configuration</classname> object as seen in <xref linkend="
"\"example-traversable-resolver-config\"/>."
msgstr ""
"Hibernate Validator包含了两个<classname>TraversableResolver</classname>接口的"
"实现, 并且会根据你的环境来决定自动判断使用哪个实现. 首先是"
"<classname>DefaultTraversableResolver</classname>, 它的"
"<methodname>isReachable()</methodname>和<methodname>isTraversable()</"
"methodname>总是返回true. 而另外一个, <classname>JPATraversableResolver</"
"classname>, 会在把Hibernate Validator 和JPA2一起使用的时候被启用. 如果你想提"
"供自己的实现, 可以参照<xref linkend=\"example-traversable-resolver-config\"/"
">."
#. Tag: title
#: bootstrapping.xml:242
#, no-c-format
msgid "Providing a custom TraversableResolver"
msgstr "自定义的TraversableResolver"
#. Tag: programlisting
#: bootstrapping.xml:244
#, no-c-format
msgid ""
"Configuration<?> configuration = Validation.byDefaultProvider()."
"configure();\n"
"ValidatorFactory factory = configuration\n"
" .traversableResolver(new MyTraversableResolver())\n"
" .buildValidatorFactory();\n"
"\n"
"Validator validator = factory.getValidator();"
msgstr ""
"Configuration<?> configuration = Validation.byDefaultProvider()."
"configure();\n"
"ValidatorFactory factory = configuration\n"
" .traversableResolver(new MyTraversableResolver())\n"
" .buildValidatorFactory();\n"
"\n"
"Validator validator = factory.getValidator();"
#. Tag: classname
#: bootstrapping.xml:249
#, no-c-format
msgid "ConstraintValidatorFactory"
msgstr "ConstraintValidatorFactory"
#. Tag: para
#: bootstrapping.xml:251
#, no-c-format
msgid ""
"Last but not least, there is one more configuration option to discuss, the "
"<classname>ConstraintValidatorFactory</classname>. The default "
"<classname>ConstraintValidatorFactory</classname> provided by Hibernate "
"Validator requires a public no-arg constructor to instantiate "
"<classname>ConstraintValidator</classname> instances (see <xref linkend="
"\"section-constraint-validator\"/>). Using a custom "
"<classname>ConstraintValidatorFactory</classname> offers for example the "
"possibility to use dependency injection in constraint implementations. The "
"configuration of the custom factory is once more via the "
"<classname>Configuration</classname> (<xref linkend=\"example-constraint-"
"validator-factory\"/>)."
msgstr ""
"最后, 还有个配置项得提一下, 那就是<classname>ConstraintValidatorFactory</"
"classname>类. Hibernate Validator中默认的"
"<classname>ConstraintValidatorFactory</classname>需要一个无参的构造方法来初始"
"化<classname>ConstraintValidator</classname>的实例(参考<xref linkend="
"\"section-constraint-validator\"/>). 对于自定义的"
"<classname>ConstraintValidatorFactory</classname>实现来说, 例如, 你可以让其支"
"持对约束条件的依赖注入等功能. 配置使用这个自定义的"
"<classname>ConstraintValidatorFactory</classname>的方法还是老样子(<xref "
"linkend=\"example-constraint-validator-factory\"/>)."
#. Tag: title
#: bootstrapping.xml:264
#, no-c-format
msgid "Providing a custom ConstraintValidatorFactory"
msgstr "自定义的ConstraintValidatorFactory"
#. Tag: programlisting
#: bootstrapping.xml:266
#, no-c-format
msgid ""
"Configuration<?> configuration = Validation.byDefaultProvider()."
"configure();\n"
"ValidatorFactory factory = configuration\n"
" .constraintValidatorFactory(new IOCConstraintValidatorFactory())\n"
" .buildValidatorFactory();\n"
"\n"
"Validator validator = factory.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:269
#, no-c-format
msgid "The interface you have to implement is:"
msgstr "你需要实现此接口:"
#. Tag: title
#: bootstrapping.xml:272
#, no-c-format
msgid "ConstraintValidatorFactory interface"
msgstr "ConstraintValidatorFactory接口"
#. Tag: programlisting
#: bootstrapping.xml:274
#, no-c-format
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"
"}"
#. Tag: para
#: bootstrapping.xml:278
#, no-c-format
msgid ""
"Any constraint implementation relying on "
"<classname>ConstraintValidatorFactory</classname> behaviors specific to an "
"implementation (dependency injection, no no-arg constructor and so on) are "
"not considered portable."
msgstr ""
"如果一个约束条件的实现需要依赖<classname>ConstraintValidatorFactory</"
"classname>的某个特定的行为(例如依赖注入或者没有无参的构造方法等) 都可能导致不"
"可移植."
#. Tag: para
#: bootstrapping.xml:285
#, no-c-format
msgid ""
"ConstraintValidatorFactory should not cache instances as the state of each "
"instance can be altered in the initialize method."
msgstr ""
"ConstraintValidatorFactory不应该缓存其创建的实例, 因为每个实例都可能在其的初"
"始化方法中被修改."