/
bootstrapping.pot
438 lines (386 loc) · 19.4 KB
/
bootstrapping.pot
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
# SOME DESCRIPTIVE TITLE.
# FIRST AUTHOR <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <kde-i18n-doc@kde.org>\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 "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 ""
#. 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 ""
#. 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 ""
#. Tag: title
#: bootstrapping.xml:55
#, no-c-format
msgid "<classname>Configuration</classname> and <classname>ValidatorFactory</classname>"
msgstr ""
#. 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 ""
#. Tag: title
#: bootstrapping.xml:63
#, no-c-format
msgid "Validation.buildDefaultValidatorFactory()"
msgstr ""
#. Tag: programlisting
#: bootstrapping.xml:65
#, no-c-format
msgid ""
"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
"Validator validator = factory.getValidator();"
msgstr ""
#. 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 ""
#. Tag: title
#: bootstrapping.xml:73
#, no-c-format
msgid "Validation.byDefaultProvider()"
msgstr ""
#. 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 ""
#. 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 ""
#. 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 ""
#. Tag: title
#: bootstrapping.xml:91
#, no-c-format
msgid "Validation.byProvider( HibernateValidator.class )"
msgstr ""
#. 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 ""
#. Tag: para
#: bootstrapping.xml:97
#, no-c-format
msgid "The generated <classname>Validator</classname> instance is thread safe and can be cached."
msgstr ""
#. Tag: classname
#: bootstrapping.xml:103
#, no-c-format
msgid "ValidationProviderResolver"
msgstr ""
#. 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 ""
#. Tag: title
#: bootstrapping.xml:112
#, no-c-format
msgid "Providing a custom ValidationProviderResolver"
msgstr ""
#. 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 ""
#. Tag: para
#: bootstrapping.xml:117
#, no-c-format
msgid "Your <classname>OSGiServiceDiscoverer</classname> must in this case implement the interface <classname>ValidationProviderResolver</classname>:"
msgstr ""
#. Tag: title
#: bootstrapping.xml:122
#, no-c-format
msgid "ValidationProviderResolver interface"
msgstr ""
#. 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 ""
#. Tag: classname
#: bootstrapping.xml:129
#, no-c-format
msgid "MessageInterpolator"
msgstr ""
#. Tag: para
#: bootstrapping.xml:131
#, 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 ""
#. 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 ""
#. Tag: programlisting
#: bootstrapping.xml:160
#, 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 ""
#. 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 ""
#. Tag: title
#: bootstrapping.xml:173
#, no-c-format
msgid "ResourceBundleLocator"
msgstr ""
#. 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 ""
#. Tag: title
#: bootstrapping.xml:194
#, no-c-format
msgid "Providing a custom ResourceBundleLocator"
msgstr ""
#. 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 ""
#. 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 ""
#. Tag: classname
#: bootstrapping.xml:210
#, no-c-format
msgid "TraversableResolver"
msgstr ""
#. 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 ""
#. Tag: title
#: bootstrapping.xml:224
#, no-c-format
msgid "TraversableResolver interface"
msgstr ""
#. 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 ""
#. Tag: para
#: bootstrapping.xml:229
#, 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 ""
#. Tag: title
#: bootstrapping.xml:242
#, no-c-format
msgid "Providing a custom TraversableResolver"
msgstr ""
#. 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 ""
#. Tag: classname
#: bootstrapping.xml:249
#, no-c-format
msgid "ConstraintValidatorFactory"
msgstr ""
#. 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 ""
#. Tag: title
#: bootstrapping.xml:264
#, no-c-format
msgid "Providing a custom ConstraintValidatorFactory"
msgstr ""
#. 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 ""
#. 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 ""
#. 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 ""
#. 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 ""
#. 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 ""