Skip to content

Commit

Permalink
HV-372: Fixing typos, improving wording/formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling committed Jun 18, 2011
1 parent 24d1b61 commit 6cf11f8
Showing 1 changed file with 70 additions and 61 deletions.
131 changes: 70 additions & 61 deletions hibernate-validator/src/main/docbook/en-US/modules/customoptions.xml
Expand Up @@ -210,23 +210,23 @@ validator = factory.unwrap( HibernateValidatorFactory.class )
values, thus enabling a programming style known as "Programming by
Contract".</para>

<para>More specifically this means that any Bean Validation constraints
can be used to specify</para>
<para>More specifically this means that Bean Validation constraints can be
used to specify</para>

<itemizedlist>
<listitem>
<para>any preconditions that must be met before a method invocation
(by annotating method parameters with constraints)</para>
<para>the preconditions that must be met before a method invocation
(by annotating method parameters with constraints) and</para>
</listitem>

<listitem>
<para>and any postconditions that are guaranteed after a method
invocation (by annotating methods)</para>
<para>the postconditions that are guaranteed after a method invocation
(by annotating methods)</para>
</listitem>
</itemizedlist>

<para>This approach has several advantages over traditional ways of
parameter or return value checking:</para>
parameter and return value checking:</para>

<itemizedlist>
<listitem>
Expand All @@ -237,7 +237,7 @@ validator = factory.unwrap( HibernateValidatorFactory.class )

<listitem>
<para>A method's pre- and postconditions don't have to be expressed
again in the method's JavaDoc, since the annotations will
again in the method's JavaDoc, since the constraint annotations will
automatically be included in the generated JavaDoc. This avoids
redundancy and reduces the chance of inconsistencies between
implementation and documentation.</para>
Expand All @@ -248,16 +248,16 @@ validator = factory.unwrap( HibernateValidatorFactory.class )
<para>Method validation was also considered to be included in the Bean
Validation API as defined by JSR 303, but it didn't become part of the
1.0 version. A basic draft is outlined in appendix C of the
specifcation, and the implementation in Hibernate Validator is largely
specification, and the implementation in Hibernate Validator is largely
influenced by this draft. The feature is considered again for inclusion
in BV 1.1</para>
in BV 1.1.</para>
</note>

<section>
<title>Defining method-level constraints</title>

<para>Listing <xref lang="" linkend="example-method-constraints" />
demonstrates the definition of method level constraints.<example
demonstrates the definition of method-level constraints.<example
id="example-method-constraints">
<title>Using method-level constraints</title>

Expand Down Expand Up @@ -288,7 +288,8 @@ validator = factory.unwrap( HibernateValidatorFactory.class )
</listitem>

<listitem>
<para>The returned Car instance may not be null</para>
<para>The returned <classname>Car</classname> instance may not be
null</para>
</listitem>
</itemizedlist>

Expand All @@ -315,59 +316,64 @@ validator = factory.unwrap( HibernateValidatorFactory.class )
<classname>Rental</classname> objects will be evaluated when validating
the method's return value.</para>

<para>Special care must be taken when defining parameter constraints in
inheritance hierarchies. When a method is overridden in sub-types only
at the base method parameter constraints may be declared. The reason for
this restriction is that the preconditions to be fulfilled by a type's
client must not be strengthened in sub-types (which maybe are not even
known to the base type's client).</para>
<section>
<title>Using method constraints in type hierarchies</title>

<para>Note that also if the base method doesn't declare any parameter
constraints at all, no parameter constraints may be added in overriding
methods. The same applies to interface methods: no parameter constraints
may be defined at the implementing method (or the same method declared
in sub-interfaces).</para>
<para>Special care must be taken when defining parameter constraints
in inheritance hierarchies. When a method is overridden in sub-types
only at the base method parameter constraints may be declared. The
reason for this restriction is that the preconditions to be fulfilled
by a type's client must not be strengthened in sub-types (which maybe
are not even known to the base type's client).</para>

<para>If a violation of this rule is detected by the validation engine a
<classname>javax.validation.ConstraintDeclarationException</classname>
will be thrown. In <xref lang=""
linkend="example-illegal-method-constraints" /> some examples for
illegal parameter constraints declarations are shown.</para>
<para>Note that also if the base method doesn't declare any parameter
constraints at all, no parameter constraints may be added in
overriding methods. The same applies to interface methods: no
parameter constraints may be defined at the implementing method (or
the same method declared in sub-interfaces).</para>

<example id="example-illegal-method-constraints">
<title>Illegal parameter constraint declarations</title>
<para>If a violation of this rule is detected by the validation engine
a
<classname>javax.validation.ConstraintDeclarationException</classname>
will be thrown. In <xref lang=""
linkend="example-illegal-method-constraints" /> some examples for
illegal parameter constraints declarations are shown.</para>

<programlisting>public class Car {
<example id="example-illegal-method-constraints">
<title>Illegal parameter constraint declarations</title>

void drive(Person driver) { ... }
<programlisting>public class Car {

public void drive(Person driver) { ... }

}

public class RentalCar {
public class RentalCar extends Car {

//not allowed, parameter constraint added in overriding method
void drive(@NotNull Person driver) { ... }
public void drive(@NotNull Person driver) { ... }

}

public interface Car {
public interface ICar {

void drive(Person driver);

}

public class CarImpl {
public class CarImpl implements ICar {

//not allowed, parameter constraint added in implementation of interface method
void drive(@NotNull Person driver) { ... }
public void drive(@NotNull Person driver) { ... }

}</programlisting>
</example>
</example>

<para>This rule only applies to parameter constraints, return value
constraints may be added in sub-types without any restrictions as it is
alright to strengthen the postconditions guaranteed to a type's
client.</para>
<para>This rule only applies to parameter constraints, return value
constraints may be added in sub-types without any restrictions as it
is alright to strengthen the postconditions guaranteed to a type's
client.</para>
</section>
</section>

<section>
Expand All @@ -376,10 +382,12 @@ public class CarImpl {
<para>To validate method-level constraints Hibernate Validator provides
the interface
<classname>org.hibernate.validator.method.MethodValidator</classname>.
As shown in <xref lang="" linkend="example-methodvalidator" /> this
interface defines methods for the evaluation of parameter as well as
return value constraints and for retrieving an extended type descriptor
providing method constraint related meta-data.</para>
</para>

<para>As shown in <xref lang="" linkend="example-methodvalidator" />
this interface defines methods for the evaluation of parameter as well
as return value constraints and for retrieving an extended type
descriptor providing method constraint related meta-data.</para>

<example id="example-methodvalidator">
<title>The <classname>MethodValidator</classname> interface</title>
Expand Down Expand Up @@ -418,8 +426,8 @@ public class CarImpl {
linkend="example-methodconstraintviolation" />) extends
<classname>javax.validation.ConstraintViolation</classname> and provides
additional method level validation specific information such as the
method and index of the parameter which caused the constraint violation.
</para>
method and index of the parameter which caused the constraint
violation.</para>

<example id="example-methodconstraintviolation">
<title>The <classname>MethodConstraintViolation</classname>
Expand Down Expand Up @@ -452,37 +460,38 @@ public class CarImpl {
method interception facilities such as the JDK's
<classname>java.lang.reflect.Proxy</classname> API or CDI ( "JSR 299:
Contexts and Dependency Injection for the
Java<superscript>TM</superscript> EE platform" ). If a parameter or
return value constraint can't be validated sucessfully such an
integration layer typically will throw a
Java<superscript>TM</superscript> EE platform" ). </para>

<para>If a parameter or return value constraint can't be validated
sucessfully such an integration layer typically will throw a
<classname>MethodConstraintViolationException</classname> which similar
to <classname>javax.validation.ConstraintViolationException</classname>
wraps the occurred constraint violations.</para>
contains a set with the occurred constraint violations.</para>

<tip>
<para>If you are using CDI you might be interested in the <ulink
url="http://seamframework.org/Seam3/ValidationModule">Seam
Validation</ulink> project. This Seam module provides an interceptor
which integrates Hibernate Validator's method validation functionality
with CDI.</para>
which integrates the method validation functionality with CDI.</para>
</tip>
</section>

<section>
<title>Retrieving meta-data for method-level constraints</title>
<title>Retrieving method-level constraint meta data</title>

<para>The Bean Validation API provides rich capabilities for retrieving
<para>As outlined in <xref lang="" linkend="validator-metadata-api" />
the Bean Validation API provides rich capabilities for retrieving
constraint related meta data. Hibernate Validator extends this API and
allows to retrieve constraint meta-data also for method-level
constraints. </para>
allows to retrieve constraint meta data also for method-level
constraints.</para>

<para><xref lang="" linkend="example-method-level-meta-data" /> shows
how to use this extended PI to retrieve constraint meta-data for the
how to use this extended API to retrieve constraint meta data for the
<methodname>rentCar()</methodname> method from the
<classname>RentalStation</classname> type.</para>

<example id="example-method-level-meta-data">
<title>Retrieving meta-data for method-level constraints</title>
<title>Retrieving meta data for method-level constraints</title>

<programlisting language="" role="">TypeDescriptor typeDescriptor = methodValidator.getConstraintsForType(RentalStation.class)

Expand Down Expand Up @@ -511,7 +520,7 @@ assertEquals(startDateParameter.findConstraints().getConstraintDescriptors().siz
url="http://docs.jboss.org/hibernate/validator/4.2/api/index.html?org/hibernate/validator/method/metadata/package-summary.html">JavaDoc</ulink>
of the package
<classname>org.hibernate.validator.method.metadata</classname> for more
details on the extended meta-data API.</para>
details on the extended meta data API.</para>
</section>
</section>

Expand Down

0 comments on commit 6cf11f8

Please sign in to comment.