Hibernate SVN: r16754 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-10 17:48:21 -0400 (Wed, 10 Jun 2009)
New Revision: 16754
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ValidatorFactory.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
Log:
BVAL-161 Add unwrap methods to ValidatorFactory and Validator
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-06-10 20:48:54 UTC (rev 16753)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-06-10 21:48:21 UTC (rev 16754)
@@ -100,4 +100,16 @@
* constraints are invalid.
*/
BeanDescriptor getConstraintsForClass(Class<?> clazz);
+
+ /**
+ * Return an object of the specified type to allow access to the
+ * provider-specific API. If the Bean Validation provider
+ * implementation does not support the specified class, the
+ * ValidationException is thrown.
+ * @param type the class of the object to be returned.
+ * @return an instance of the specified class
+ * @throws ValidationException if the provider does not
+ * support the call.
+ */
+ public <T> T unwrap(Class<T> type);
}
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ValidatorFactory.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ValidatorFactory.java 2009-06-10 20:48:54 UTC (rev 16753)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ValidatorFactory.java 2009-06-10 21:48:21 UTC (rev 16754)
@@ -50,4 +50,16 @@
* @return MessageInterpolator instance.
*/
MessageInterpolator getMessageInterpolator();
+
+ /**
+ * Return an object of the specified type to allow access to the
+ * provider-specific API. If the Bean Validation provider
+ * implementation does not support the specified class, the
+ * ValidationException is thrown.
+ * @param type the class of the object to be returned.
+ * @return an instance of the specified class
+ * @throws ValidationException if the provider does not
+ * support the call.
+ */
+ public <T> T unwrap(Class<T> type);
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java 2009-06-10 20:48:54 UTC (rev 16753)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java 2009-06-10 21:48:21 UTC (rev 16754)
@@ -27,6 +27,7 @@
import javax.validation.Validator;
import javax.validation.ValidatorContext;
import javax.validation.ValidatorFactory;
+import javax.validation.ValidationException;
import javax.validation.spi.ConfigurationState;
import org.hibernate.validation.engine.xml.AnnotationIgnores;
@@ -70,6 +71,10 @@
return messageInterpolator;
}
+ public <T> T unwrap(Class<T> type) {
+ throw new ValidationException( "Type " + type + " not supported");
+ }
+
/**
* {@inheritDoc}
*/
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-10 20:48:54 UTC (rev 16753)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-10 21:48:21 UTC (rev 16754)
@@ -34,6 +34,7 @@
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
import javax.validation.Validator;
+import javax.validation.ValidationException;
import javax.validation.groups.Default;
import com.googlecode.jtype.TypeUtils;
@@ -150,6 +151,10 @@
return getBeanMetaData( clazz ).getBeanDescriptor();
}
+ public <T> T unwrap(Class<T> type) {
+ throw new ValidationException( "Type " + type + " not supported");
+ }
+
private void sanityCheckPropertyPath(String propertyName) {
if ( propertyName == null || propertyName.length() == 0 ) {
throw new IllegalArgumentException( "Invalid property path." );
15 years, 5 months
Hibernate SVN: r16753 - core/trunk/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-10 16:48:54 -0400 (Wed, 10 Jun 2009)
New Revision: 16753
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/component_mapping.xml
Log:
fixed issue with xml syntax
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/component_mapping.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/component_mapping.xml 2009-06-10 18:46:26 UTC (rev 16752)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/component_mapping.xml 2009-06-10 20:48:54 UTC (rev 16753)
@@ -132,9 +132,9 @@
</para>
<para>
- The properties of a component can be of any Hibernate type (collections, many-to-one
- associations, other components, etc). Nested components should <emphasis>not</emphasis>
- be considered an exotic usage. Hibernate is intended to support a fine-grained
+ The properties of a component can be of any Hibernate type (collections, many-to-one
+ associations, other components, etc). Nested components should <emphasis>not</emphasis>
+ be considered an exotic usage. Hibernate is intended to support a fine-grained
object model.
</para>
@@ -179,28 +179,28 @@
</set>]]></programlisting>
<important>
- <para>
- If you define a <literal>Set</literal> of composite elements, it is
- important to implement <literal>equals()</literal> and
+ <para>
+ If you define a <literal>Set</literal> of composite elements, it is
+ important to implement <literal>equals()</literal> and
<literal>hashCode()</literal> correctly.
- </important>
- </para>
+ </para>
+ </important>
<para>
Composite elements can contain components but not collections. If your
- composite element contains
- components, use the <literal><nested-composite-element></literal>
- tag. This case is a collection of components which
- themselves have components. You may want to consider if
- a one-to-many association is more appropriate. Remodel the
- composite element as an entity, but be aware that even though the Java model
- is the same, the relational model and persistence semantics are still
+ composite element contains
+ components, use the <literal><nested-composite-element></literal>
+ tag. This case is a collection of components which
+ themselves have components. You may want to consider if
+ a one-to-many association is more appropriate. Remodel the
+ composite element as an entity, but be aware that even though the Java model
+ is the same, the relational model and persistence semantics are still
slightly different.
</para>
<para>
A composite element mapping does not support null-able properties
- if you are using a <literal><set></literal>. There is no separate primary key column
+ if you are using a <literal><set></literal>. There is no separate primary key column
in the composite element table. Hibernate
uses each column's value to identify a record when deleting objects,
which is not possible with null values. You have to either use only
@@ -214,7 +214,7 @@
<literal><many-to-one></literal> element. This mapping allows
you to map extra columns of a many-to-many association table to the
composite element class. The following is a many-to-many association
- from <literal>Order</literal> to <literal>Item</literal>, where
+ from <literal>Order</literal> to <literal>Item</literal>, where
<literal>purchaseDate</literal>, <literal>price</literal> and
<literal>quantity</literal> are properties of the association:
</para>
@@ -288,12 +288,12 @@
<listitem>
<para>
It must re-implement <literal>equals()</literal> and
- <literal>hashCode()</literal> consistently with the database's
+ <literal>hashCode()</literal> consistently with the database's
notion of composite key equality.
</para>
</listitem>
</itemizedlist>
-
+
<note>
<title>Note</title>
<para>
@@ -301,42 +301,42 @@
requirement of Hibernate, it is recommended.
</para>
</note>
-
+
<para>
You cannot use an <literal>IdentifierGenerator</literal> to generate composite keys.
Instead the application must assign its own identifiers.
</para>
<para>
- Use the <literal><composite-id></literal> tag, with nested
- <literal><key-property></literal> elements, in place of the usual
+ Use the <literal><composite-id></literal> tag, with nested
+ <literal><key-property></literal> elements, in place of the usual
<literal><id></literal> declaration. For example, the
<literal>OrderLine</literal> class has a primary key that depends upon
the (composite) primary key of <literal>Order</literal>.
</para>
<programlisting><![CDATA[<class name="OrderLine">
-
+
<composite-id name="id" class="OrderLineId">
<key-property name="lineId"/>
<key-property name="orderId"/>
<key-property name="customerId"/>
</composite-id>
-
+
<property name="name"/>
-
+
<many-to-one name="order" class="Order"
insert="false" update="false">
<column name="orderId"/>
<column name="customerId"/>
</many-to-one>
....
-
+
</class>]]></programlisting>
<para>
- Any foreign keys referencing the <literal>OrderLine</literal> table are now
- composite. Declare this in your mappings for other classes. An association
+ Any foreign keys referencing the <literal>OrderLine</literal> table are now
+ composite. Declare this in your mappings for other classes. An association
to <literal>OrderLine</literal> is mapped like this:
</para>
@@ -347,21 +347,21 @@
<column name="customerId"/>
</many-to-one>]]></programlisting>
- <note>
- </title>
- Note
- </title>
- <para>
- The <literal><column></literal> tag is an alternative to the
- <literal>column</literal> attribute everywhere.
- </para>
- </note>
-
-<para>
+ <tip>
+ <para>
+ The <literal>column</literal> element is an alternative to the
+ <literal>column</literal> attribute everywhere. Using the
+ <literal>column</literal> element just gives more declaration
+ options, which are mostly useful when utilizing
+ <literal>hbm2ddl</literal>
+ </para>
+ </tip>
+
+ <para>
A <literal>many-to-many</literal> association to <literal>OrderLine</literal> also
uses the composite foreign key:
</para>
-
+
<programlisting><![CDATA[<set name="undeliveredOrderLines">
<key column name="warehouseId"/>
<many-to-many class="OrderLine">
@@ -372,7 +372,7 @@
</set>]]></programlisting>
<para>
- The collection of <literal>OrderLine</literal>s in <literal>Order</literal> would
+ The collection of <literal>OrderLine</literal>s in <literal>Order</literal> would
use:
</para>
@@ -387,9 +387,9 @@
<para>
The <literal><one-to-many></literal> element declares no columns.
</para>
-
+
<para>
- If <literal>OrderLine</literal> itself owns a collection, it also has a composite
+ If <literal>OrderLine</literal> itself owns a collection, it also has a composite
foreign key.
</para>
@@ -426,9 +426,9 @@
<para>
The semantics of a <literal><dynamic-component></literal> mapping are identical
- to <literal><component></literal>. The advantage of this kind of mapping is
+ to <literal><component></literal>. The advantage of this kind of mapping is
the ability to determine the actual properties of the bean at deployment time just
- by editing the mapping document. Runtime manipulation of the mapping document is
+ by editing the mapping document. Runtime manipulation of the mapping document is
also possible, using a DOM parser. You can also access, and change, Hibernate's
configuration-time metamodel via the <literal>Configuration</literal> object.
</para>
15 years, 5 months
Hibernate SVN: r16752 - core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-10 14:46:26 -0400 (Wed, 10 Jun 2009)
New Revision: 16752
Added:
core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/portability.xml
Log:
minor changes; added biblio references for JPwH
Added: core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/portability.xml
===================================================================
--- core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/portability.xml (rev 0)
+++ core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/portability.xml 2009-06-10 18:46:26 UTC (rev 16752)
@@ -0,0 +1,204 @@
+<?xml version='1.0' encoding="UTF-8"?>
+<!--
+ ~ Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+
+<chapter id="portability">
+ <title>Database Portability Considerations</title>
+
+ <sect1 id="portability-basics">
+ <title>Portability Basics</title>
+
+ <para>
+ One of the selling points of Hibernate (and really Object/Relational Mapping as a whole) is
+ the notion of database portability. This could mean an internal IT user migrating from one
+ database vendor to another, or it could mean a framework or deployable application consuming
+ Hibernate to simultaneously target multiple database products by their users. Regardless of
+ the exact scenario, the basic idea is that you want Hibernate to help you run against any number
+ of databases without changes to your code, and ideally without any changes to the mapping metadata.
+ </para>
+ </sect1>
+
+ <sect1 id="portability-dialect">
+ <title>Dialect</title>
+
+ <para>
+ The first line of portability for Hibernate is the dialect, which is a specialization of the
+ <classname>org.hibernate.dialect.Dialect</classname> contract. A dialect encapsulates all
+ the differences in how Hibernate must communicate with a particular database to accomplish some
+ task like getting a sequence value or structuring a SELECT query. Hibernate bundles a wide range
+ of dialects for many of the most popular databases. If you find that your particular database is
+ not among them, it is not terribly difficult to write your own.
+ </para>
+ </sect1>
+
+ <sect1 id="portability-dialectresolver">
+ <title>Dialect resolution</title>
+
+ <para>
+ Originally, Hibernate would always require that users specify which dialect to use. In the case
+ of users looking to simultaneously target multiple databases with their build that was problematic.
+ Generally this required their users to configure the Hibernate dialect or defining their own method
+ of setting that value.
+ </para>
+
+ <para>
+ Starting with version 3.2, Hibernate introduced the notion of automatically detecting the dialect
+ to use based on the <interfacename>java.sql.DatabaseMetaData</interfacename> obtained from a
+ <interfacename>java.sql.Connection</interfacename> to that database. This was much better, expect
+ that this resolution was limited to databases Hibernate know about ahead of time and was in no way
+ configurable or overrideable.
+ </para>
+
+ <para>
+ Starting with version 3.3, Hibernate has a fare more powerful way to automatically determine
+ which dialect to should be used by relying on a series of delegates which implement the
+ <interfacename>org.hibernate.dialect.resolver.DialectResolver</interfacename> which defines only a
+ single method:<programlisting><![CDATA[public Dialect resolveDialect(DatabaseMetaData metaData) throws JDBCConnectionException]]></programlisting>.
+ The basic contract here is that if the resolver 'understands' the given database metadata then
+ it returns the corresponding Dialect; if not it returns null and the process continues to the next
+ resolver. The signature also identifies <exceptionname>org.hibernate.exception.JDBCConnectionException</exceptionname>
+ as possibly being thrown. A JDBCConnectionException here is interpreted to imply a "non transient"
+ (aka non-recoverable) connection problem and is used to indicate an immediate stop to resolution
+ attempts. All other exceptions result in a warning and continuing on to the next resolver.
+ </para>
+
+ <para>
+ The cool part about these resolvers is that users can also register their own custom resolvers
+ which will be processed ahead of the built-in Hibernate ones. This might be useful in a number of
+ different situations: it allows easy integration for auto-detection of dialects beyond those
+ shipped with HIbernate itself; it allows you to specify to use a custom dialect when a particular
+ database is recognized; etc. To register one or more resolvers, simply specify them (seperated by
+ commas, tabs or spaces) using the 'hibernate.dialect_resolvers' configuration setting (see the
+ <constant>DIALECT_RESOLVERS</constant> constant on
+ <ooclass><package>org.hibernate.cfg</package><classname>Environment</classname></ooclass>).
+ </para>
+ </sect1>
+
+ <sect1 id="portability-idgen">
+ <title>Identifier generation</title>
+
+ <para>
+ When considering portability between databases, another important decision is selecting the
+ identifier generation stratagy you want to use. Originally Hibernate provided the
+ <emphasis>native</emphasis> generator for this purpose, which was intended to select between
+ a <emphasis>sequence</emphasis>, <emphasis>identity</emphasis>, or <emphasis>table</emphasis>
+ strategy depending on the capability of the underlying database. However, an insidious implication
+ of this approach comes about when targtetting some databases which support <emphasis>identity</emphasis>
+ generation and some which do not. <emphasis>identity</emphasis> generation relies on the SQL
+ definition of an IDENTITY (or auto-increment) column to manage the identifier value; it is what is
+ known as a post-insert generation strategy becauase the insert must actually happen before we can
+ know the identifier value. Because Hibernate relies on this identifier value to uniquely reference
+ entities within a persistence context it must then issue the insert
+ immediately when the users requests the entitiy be associated with the session (like via
+ save() e.g.) regardless of current transactional semantics.
+
+ <note>
+ <para>
+ Hibernate was changed slightly once the implication of this was better understood so that
+ the insert is delayed in cases where that is feasible.
+ </para>
+ </note>
+
+ The underlying issue is that the actual semanctics of the application itself changes in these cases.
+ </para>
+
+ <para>
+ Starting with version 3.2.3, Hibernate comes with a set of
+ <ulink url="http://in.relation.to/2082.lace">enhanced</ulink> identifier generators targetting
+ portability in a much different way.
+ <note>
+ <para>
+ There are specifically 2 bundled <emphasis>enhanced</emphasis>generators:
+ <itemizedlist>
+ <listitem>
+ <para>
+ <classname>org.hibernate.id.enhanced.SequenceStyleGenerator</classname>
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <classname>org.hibernate.id.enhanced.TableGenerator</classname>
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ </note>
+ The idea behind these generators is to port the actual semantics of the identifer value
+ generation to the different databases. For example, the
+ <classname>org.hibernate.id.enhanced.SequenceStyleGenerator</classname> mimics the behavior of
+ a sequence on databases which do not support sequences by using a table.
+ </para>
+ </sect1>
+
+ <sect1 id="portability-functions">
+ <title>Database functions</title>
+
+ <warning>
+ <para>
+ This is an area in Hibernate in need of improvement. In terms of portability concerns,
+ this function handling currently works pretty well from HQL; however, it is quite lacking
+ in all other aspects.
+ </para>
+ </warning>
+
+ <para>
+ SQL functions can be referenced in many ways by users. However, not all databases
+ support the same set of functions. Hibernate, provides a means of mapping a
+ <emphasis>logical</emphasis> function name to a a delegate which knows how to render
+ that particular function, perhaps even using a totally different physical function call.
+ <important>
+ <para>
+ Technically this function registration is handled through the
+ <classname>org.hibernate.dialect.function.SQLFunctionRegistry</classname> class
+ which is intended to allow users to provide custom function definitions without
+ having to provide a custom dialect. This specific behavior is not fully completed
+ as of yet.
+ </para>
+ <para>
+ It is sort of implemented such that users can programatically register functions
+ with the <classname>org.hibernate.cfg.Configuration</classname> and those functions
+ will be recognized for HQL.
+ </para>
+ </important>
+ </para>
+ </sect1>
+
+ <sect1 id="portability-types">
+ <title>Type mappings</title>
+
+ <para>
+ This section scheduled for completion at a later date...
+ </para>
+
+ <!--
+ todo :
+ <sect2 id="portability-types-lobs">
+ <title>BLOB/CLOB mappings</title>
+ </sect2>
+
+ <sect2 id="portability-types-bool">
+ <title>Boolean mappings</title>
+ </sect2>
+ -->
+ </sect1>
+</chapter>
\ No newline at end of file
15 years, 5 months
Hibernate SVN: r16751 - in core/trunk/documentation/manual/src/main/docbook/en-US: content and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-10 14:46:15 -0400 (Wed, 10 Jun 2009)
New Revision: 16751
Added:
core/trunk/documentation/manual/src/main/docbook/en-US/content/portability.xml
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml
Log:
HHH-3944 - Document known database portability strategies
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml 2009-06-10 18:44:15 UTC (rev 16750)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml 2009-06-10 18:46:15 UTC (rev 16751)
@@ -91,6 +91,8 @@
<xi:include href="content/best_practices.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="content/portability.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
<xi:include href="content/bibliography.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</book>
Added: core/trunk/documentation/manual/src/main/docbook/en-US/content/portability.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/portability.xml (rev 0)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/portability.xml 2009-06-10 18:46:15 UTC (rev 16751)
@@ -0,0 +1,204 @@
+<?xml version='1.0' encoding="UTF-8"?>
+<!--
+ ~ Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+
+<chapter id="portability">
+ <title>Database Portability Considerations</title>
+
+ <sect1 id="portability-basics">
+ <title>Portability Basics</title>
+
+ <para>
+ One of the selling points of Hibernate (and really Object/Relational Mapping as a whole) is
+ the notion of database portability. This could mean an internal IT user migrating from one
+ database vendor to another, or it could mean a framework or deployable application consuming
+ Hibernate to simultaneously target multiple database products by their users. Regardless of
+ the exact scenario, the basic idea is that you want Hibernate to help you run against any number
+ of databases without changes to your code, and ideally without any changes to the mapping metadata.
+ </para>
+ </sect1>
+
+ <sect1 id="portability-dialect">
+ <title>Dialect</title>
+
+ <para>
+ The first line of portability for Hibernate is the dialect, which is a specialization of the
+ <classname>org.hibernate.dialect.Dialect</classname> contract. A dialect encapsulates all
+ the differences in how Hibernate must communicate with a particular database to accomplish some
+ task like getting a sequence value or structuring a SELECT query. Hibernate bundles a wide range
+ of dialects for many of the most popular databases. If you find that your particular database is
+ not among them, it is not terribly difficult to write your own.
+ </para>
+ </sect1>
+
+ <sect1 id="portability-dialectresolver">
+ <title>Dialect resolution</title>
+
+ <para>
+ Originally, Hibernate would always require that users specify which dialect to use. In the case
+ of users looking to simultaneously target multiple databases with their build that was problematic.
+ Generally this required their users to configure the Hibernate dialect or defining their own method
+ of setting that value.
+ </para>
+
+ <para>
+ Starting with version 3.2, Hibernate introduced the notion of automatically detecting the dialect
+ to use based on the <interfacename>java.sql.DatabaseMetaData</interfacename> obtained from a
+ <interfacename>java.sql.Connection</interfacename> to that database. This was much better, expect
+ that this resolution was limited to databases Hibernate know about ahead of time and was in no way
+ configurable or overrideable.
+ </para>
+
+ <para>
+ Starting with version 3.3, Hibernate has a fare more powerful way to automatically determine
+ which dialect to should be used by relying on a series of delegates which implement the
+ <interfacename>org.hibernate.dialect.resolver.DialectResolver</interfacename> which defines only a
+ single method:<programlisting><![CDATA[public Dialect resolveDialect(DatabaseMetaData metaData) throws JDBCConnectionException]]></programlisting>.
+ The basic contract here is that if the resolver 'understands' the given database metadata then
+ it returns the corresponding Dialect; if not it returns null and the process continues to the next
+ resolver. The signature also identifies <exceptionname>org.hibernate.exception.JDBCConnectionException</exceptionname>
+ as possibly being thrown. A JDBCConnectionException here is interpreted to imply a "non transient"
+ (aka non-recoverable) connection problem and is used to indicate an immediate stop to resolution
+ attempts. All other exceptions result in a warning and continuing on to the next resolver.
+ </para>
+
+ <para>
+ The cool part about these resolvers is that users can also register their own custom resolvers
+ which will be processed ahead of the built-in Hibernate ones. This might be useful in a number of
+ different situations: it allows easy integration for auto-detection of dialects beyond those
+ shipped with HIbernate itself; it allows you to specify to use a custom dialect when a particular
+ database is recognized; etc. To register one or more resolvers, simply specify them (seperated by
+ commas, tabs or spaces) using the 'hibernate.dialect_resolvers' configuration setting (see the
+ <constant>DIALECT_RESOLVERS</constant> constant on
+ <ooclass><package>org.hibernate.cfg</package><classname>Environment</classname></ooclass>).
+ </para>
+ </sect1>
+
+ <sect1 id="portability-idgen">
+ <title>Identifier generation</title>
+
+ <para>
+ When considering portability between databases, another important decision is selecting the
+ identifier generation stratagy you want to use. Originally Hibernate provided the
+ <emphasis>native</emphasis> generator for this purpose, which was intended to select between
+ a <emphasis>sequence</emphasis>, <emphasis>identity</emphasis>, or <emphasis>table</emphasis>
+ strategy depending on the capability of the underlying database. However, an insidious implication
+ of this approach comes about when targtetting some databases which support <emphasis>identity</emphasis>
+ generation and some which do not. <emphasis>identity</emphasis> generation relies on the SQL
+ definition of an IDENTITY (or auto-increment) column to manage the identifier value; it is what is
+ known as a post-insert generation strategy becauase the insert must actually happen before we can
+ know the identifier value. Because Hibernate relies on this identifier value to uniquely reference
+ entities within a persistence context it must then issue the insert
+ immediately when the users requests the entitiy be associated with the session (like via
+ save() e.g.) regardless of current transactional semantics.
+
+ <note>
+ <para>
+ Hibernate was changed slightly once the implication of this was better understood so that
+ the insert is delayed in cases where that is feasible.
+ </para>
+ </note>
+
+ The underlying issue is that the actual semanctics of the application itself changes in these cases.
+ </para>
+
+ <para>
+ Starting with version 3.2.3, Hibernate comes with a set of
+ <ulink url="http://in.relation.to/2082.lace">enhanced</ulink> identifier generators targetting
+ portability in a much different way.
+ <note>
+ <para>
+ There are specifically 2 bundled <emphasis>enhanced</emphasis>generators:
+ <itemizedlist>
+ <listitem>
+ <para>
+ <classname>org.hibernate.id.enhanced.SequenceStyleGenerator</classname>
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <classname>org.hibernate.id.enhanced.TableGenerator</classname>
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ </note>
+ The idea behind these generators is to port the actual semantics of the identifer value
+ generation to the different databases. For example, the
+ <classname>org.hibernate.id.enhanced.SequenceStyleGenerator</classname> mimics the behavior of
+ a sequence on databases which do not support sequences by using a table.
+ </para>
+ </sect1>
+
+ <sect1 id="portability-functions">
+ <title>Database functions</title>
+
+ <warning>
+ <para>
+ This is an area in Hibernate in need of improvement. In terms of portability concerns,
+ this function handling currently works pretty well from HQL; however, it is quite lacking
+ in all other aspects.
+ </para>
+ </warning>
+
+ <para>
+ SQL functions can be referenced in many ways by users. However, not all databases
+ support the same set of functions. Hibernate, provides a means of mapping a
+ <emphasis>logical</emphasis> function name to a a delegate which knows how to render
+ that particular function, perhaps even using a totally different physical function call.
+ <important>
+ <para>
+ Technically this function registration is handled through the
+ <classname>org.hibernate.dialect.function.SQLFunctionRegistry</classname> class
+ which is intended to allow users to provide custom function definitions without
+ having to provide a custom dialect. This specific behavior is not fully completed
+ as of yet.
+ </para>
+ <para>
+ It is sort of implemented such that users can programatically register functions
+ with the <classname>org.hibernate.cfg.Configuration</classname> and those functions
+ will be recognized for HQL.
+ </para>
+ </important>
+ </para>
+ </sect1>
+
+ <sect1 id="portability-types">
+ <title>Type mappings</title>
+
+ <para>
+ This section scheduled for completion at a later date...
+ </para>
+
+ <!--
+ todo :
+ <sect2 id="portability-types-lobs">
+ <title>BLOB/CLOB mappings</title>
+ </sect2>
+
+ <sect2 id="portability-types-bool">
+ <title>Boolean mappings</title>
+ </sect2>
+ -->
+ </sect1>
+</chapter>
\ No newline at end of file
15 years, 5 months
Hibernate SVN: r16750 - in core/trunk/documentation/manual/src/main/docbook/en-US: content and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-10 14:44:15 -0400 (Wed, 10 Jun 2009)
New Revision: 16750
Added:
core/trunk/documentation/manual/src/main/docbook/en-US/content/bibliography.xml
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml
core/trunk/documentation/manual/src/main/docbook/en-US/content/preface.xml
Log:
minor changes; added biblio references for JPwH
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml 2009-06-10 18:43:08 UTC (rev 16749)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml 2009-06-10 18:44:15 UTC (rev 16750)
@@ -91,5 +91,7 @@
<xi:include href="content/best_practices.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="content/bibliography.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
</book>
Added: core/trunk/documentation/manual/src/main/docbook/en-US/content/bibliography.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/bibliography.xml (rev 0)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/bibliography.xml 2009-06-10 18:44:15 UTC (rev 16750)
@@ -0,0 +1,75 @@
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE bibliography PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+
+<bibliography>
+ <title>References</title>
+
+ <biblioentry id="biblio-PoEAA">
+ <abbrev>PoEAA</abbrev>
+ <title>Patterns of Enterprise Application Architecture</title>
+ <isbn>0-321-12742-0</isbn>
+ <authorgroup>
+ <author>
+ <firstname>Martin</firstname>
+ <surname>Fowler</surname>
+ </author>
+ </authorgroup>
+ <copyright>
+ <year>2003</year>
+ <holder>Pearson Education, Inc.</holder>
+ </copyright>
+ <publisher>
+ <publishername>Addison-Wesley Publishing Company</publishername>
+ </publisher>
+ </biblioentry>
+
+ <biblioentry id="biblio-JPwH">
+ <abbrev>JPwH</abbrev>
+ <title>Java Persistence with Hibernate</title>
+ <subtitle>Second Edition of Hibernate in Action</subtitle>
+ <isbn>1-932394-88-5</isbn>
+ <bibliomisc>
+ <ulink url="http://www.manning.com/bauer2"/>
+ </bibliomisc>
+ <authorgroup>
+ <author>
+ <firstname>Christian</firstname>
+ <surname>Bauer</surname>
+ </author>
+ <author>
+ <firstname>Gavin</firstname>
+ <surname>King</surname>
+ </author>
+ </authorgroup>
+ <copyright>
+ <year>2007</year>
+ <holder>Manning Publications Co.</holder>
+ </copyright>
+ <publisher>
+ <publishername>Manning Publications Co.</publishername>
+ </publisher>
+ </biblioentry>
+
+</bibliography>
\ No newline at end of file
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/preface.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/preface.xml 2009-06-10 18:43:08 UTC (rev 16749)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/preface.xml 2009-06-10 18:44:15 UTC (rev 16750)
@@ -30,8 +30,8 @@
<para>
Working with object-oriented software and a relational database can be cumbersome
- and time consuming in today's enterprise environments. Hibernate is an object/relational
- mapping tool for Java environments. The term object/relational mapping (ORM) refers to
+ and time consuming in today's enterprise environments. Hibernate is an Object/Relational
+ Mapping tool for Java environments. The term Object/Relational Mapping (ORM) refers to
the technique of mapping a data representation from an object model to a relational
data model with a SQL-based schema.
</para>
@@ -86,12 +86,12 @@
</listitem>
<listitem>
<para>
- Use this reference documentation as your primary source of information.
- Consider reading <emphasis>Java Persistence with Hibernate</emphasis>
- (http://www.manning.com/bauer2) if you need more help with application
- design, or if you prefer a step-by-step tutorial. Also visit
- http://caveatemptor.hibernate.org and download the example application
- for Java Persistence with Hibernate.
+ Use this reference documentation as your primary source of
+ information. Consider reading <biblioref linkend="biblio-JPwH"/>
+ if you need more help with application design, or if you prefer
+ a step-by-step tutorial. Also visit
+ <ulink url="http://caveatemptor.hibernate.org"/> and download
+ the example application from <biblioref linkend="biblio-JPwH"/>.
</para>
</listitem>
<listitem>
@@ -101,8 +101,8 @@
</listitem>
<listitem>
<para>
- Third party demos, examples, and tutorials are linked on the Hibernate
- website.
+ Links to third party demos, examples, and tutorials are maintained
+ on the Hibernate website.
</para>
</listitem>
<listitem>
15 years, 5 months
Hibernate SVN: r16749 - core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-10 14:43:08 -0400 (Wed, 10 Jun 2009)
New Revision: 16749
Modified:
core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml
Log:
minor changes; added biblio references for JPwH
Modified: core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml
===================================================================
--- core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml 2009-06-10 18:41:22 UTC (rev 16748)
+++ core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/Hibernate_Reference.xml 2009-06-10 18:43:08 UTC (rev 16749)
@@ -91,5 +91,8 @@
<xi:include href="content/best_practices.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="content/portability.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="content/bibliography.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</book>
15 years, 5 months
Hibernate SVN: r16748 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validation/constraints/impl and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-10 14:41:22 -0400 (Wed, 10 Jun 2009)
New Revision: 16748
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertFalseValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertTrueValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForCalendar.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForDate.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/LengthValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotEmptyValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotNullValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NullValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForCalendar.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForDate.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PatternValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArray.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfBoolean.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfByte.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfChar.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfDouble.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfFloat.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfInt.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfLong.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfPrimitives.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfShort.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForCollection.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForMap.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/package.html
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNullValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForCalendar.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForDate.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArray.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForCollection.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForMap.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForString.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Length.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmpty.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/package.html
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ConstraintDescriptorTest.java
Log:
HV-166 Move constraints validator impl into org.hibernate.validation.constraints.impl
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,42 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.AssertFalse;
-
-/**
- * Validates that the value passed is false
- *
- * @author Alaa Nassef
- */
-public class AssertFalseValidator implements ConstraintValidator<AssertFalse, Boolean> {
-
- public void initialize(AssertFalse constraintAnnotation) {
- }
-
- public boolean isValid(Boolean bool, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( bool == null ) {
- return true;
- }
- return !bool;
- }
-
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,42 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.AssertTrue;
-
-/**
- * Validates that the value passed is true
- *
- * @author Alaa Nassef
- */
-public class AssertTrueValidator implements ConstraintValidator<AssertTrue, Boolean> {
-
- public void initialize(AssertTrue constraintAnnotation) {
- }
-
- public boolean isValid(Boolean bool, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( bool == null ) {
- return true;
- }
- return bool;
- }
-
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForNumber.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForNumber.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForNumber.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,72 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.math.BigDecimal;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-import javax.validation.constraints.Digits;
-
-/**
- * Validates that the <code>Number</code> being validates matches the pattern
- * defined in the constraint.
- *
- * @author Alaa Nassef
- * @author Hardy Ferentschik
- */
-public class DigitsValidatorForNumber implements ConstraintValidator<Digits, Number> {
-
- private int maxIntegerLength;
- private int maxFractionLength;
-
- public void initialize(Digits constraintAnnotation) {
- this.maxIntegerLength = constraintAnnotation.integer();
- this.maxFractionLength = constraintAnnotation.fraction();
- validateParameters();
- }
-
- public boolean isValid(Number num, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( num == null ) {
- return true;
- }
-
- BigDecimal bigNum;
- if ( num instanceof BigDecimal ) {
- bigNum = ( BigDecimal ) num;
- }
- else {
- bigNum = new BigDecimal( num.toString() );
- }
-
- int integerPartLength = bigNum.precision() - bigNum.scale();
- int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();
-
- return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
- }
-
- private void validateParameters() {
- if ( maxIntegerLength < 0 ) {
- throw new ValidationException( "The length of the interger part cannot be negative." );
- }
- if ( maxFractionLength < 0 ) {
- throw new ValidationException( "The length of the fraction part cannot be negative." );
- }
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForString.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForString.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForString.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,80 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.math.BigDecimal;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-import javax.validation.constraints.Digits;
-
-/**
- * Validates that the <code>String</code> being validated consists of digits,
- * and matches the pattern defined in the constraint.
- *
- * @author Alaa Nassef
- * @author Hardy Ferentschik
- */
-public class DigitsValidatorForString implements ConstraintValidator<Digits, String> {
-
- private int maxIntegerLength;
- private int maxFractionLength;
-
- public void initialize(Digits constraintAnnotation) {
- this.maxIntegerLength = constraintAnnotation.integer();
- this.maxFractionLength = constraintAnnotation.fraction();
- validateParameters();
- }
-
- public boolean isValid(String str, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( str == null ) {
- return true;
- }
-
- BigDecimal bigNum = getBigDecimalValue( str );
- if ( bigNum == null ) {
- return false;
- }
-
- int integerPartLength = bigNum.precision() - bigNum.scale();
- int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();
-
- return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
- }
-
- private BigDecimal getBigDecimalValue(String str) {
- BigDecimal bd;
- try {
- bd = new BigDecimal( str );
- }
- catch ( NumberFormatException nfe ) {
- return null;
- }
- return bd;
- }
-
- private void validateParameters() {
- if ( maxIntegerLength < 0 ) {
- throw new ValidationException( "The length of the interger part cannot be negative." );
- }
- if ( maxFractionLength < 0 ) {
- throw new ValidationException( "The length of the fraction part cannot be negative." );
- }
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,43 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.util.Calendar;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Future;
-
-/**
- * Check that the <code>java.util.Calendar</code> passed to be validated is in
- * the future.
- *
- * @author Alaa Nassef
- */
-public class FutureValidatorForCalendar implements ConstraintValidator<Future, Calendar> {
-
- public void initialize(Future constraintAnnotation) {
- }
-
- public boolean isValid(Calendar cal, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( cal == null ) {
- return true;
- }
- return cal.after( Calendar.getInstance() );
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,43 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.util.Date;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Future;
-
-/**
- * Check that the <code>java.util.Date</code> passed to be validated is in the
- * future.
- *
- * @author Alaa Nassef
- */
-public class FutureValidatorForDate implements ConstraintValidator<Future, Date> {
-
- public void initialize(Future constraintAnnotation) {
- }
-
- public boolean isValid(Date date, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( date == null ) {
- return true;
- }
- return date.after( new Date() );
- }
-}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Length.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Length.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Length.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -26,6 +26,8 @@
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import org.hibernate.validation.constraints.impl.LengthValidator;
+
/**
* Validate that the string is between min and max included
*
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,59 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-
-/**
- * Check that a string's length is between min and max.
- *
- * @author Emmanuel Bernard
- * @author Gavin King
- */
-public class LengthValidator implements ConstraintValidator<Length, String> {
- private int min;
- private int max;
-
- public void initialize(Length parameters) {
- min = parameters.min();
- max = parameters.max();
- validateParameters();
- }
-
- public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
- if ( value == null ) {
- return true;
- }
- int length = value.length();
- return length >= min && length <= max;
- }
-
- private void validateParameters() {
- if ( min < 0 ) {
- throw new ValidationException( "The min parameter cannot be negative." );
- }
- if ( max < 0 ) {
- throw new ValidationException( "The max paramter cannot be negative." );
- }
- if ( max < min ) {
- throw new ValidationException( "The length cannot be negative." );
- }
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,56 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Max;
-
-/**
- * Check that the number being validated is less than or equal to the maximum
- * value specified.
- *
- * @author Alaa Nassef
- */
-public class MaxValidatorForNumber implements ConstraintValidator<Max, Number> {
-
- private long maxValue;
-
- public void initialize(Max maxValue) {
- this.maxValue = maxValue.value();
- }
-
- public boolean isValid(Number value, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( value == null ) {
- return true;
- }
- if ( value instanceof BigDecimal ) {
- return ( ( BigDecimal ) value ).compareTo( BigDecimal.valueOf( maxValue ) ) != 1;
- }
- else if ( value instanceof BigInteger ) {
- return ( ( BigInteger ) value ).compareTo( BigInteger.valueOf( maxValue ) ) != 1;
- }
- else {
- double doubleValue = value.doubleValue();
- return doubleValue <= maxValue;
- }
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,51 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.math.BigDecimal;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Max;
-
-/**
- * Check that the String being validated represents a number, and has a value
- * less than or equal to the maximum value specified.
- *
- * @author Alaa Nassef
- */
-public class MaxValidatorForString implements ConstraintValidator<Max, String> {
-
- private long maxValue;
-
- public void initialize(Max maxValue) {
- this.maxValue = maxValue.value();
- }
-
- public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( value == null ) {
- return true;
- }
- try {
- return new BigDecimal( value ).compareTo( BigDecimal.valueOf( maxValue ) ) != 1;
- }
- catch ( NumberFormatException nfe ) {
- return false;
- }
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,57 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Min;
-
-/**
- * Check that the number being validated is greater than or equal to the minimum
- * value specified.
- *
- * @author Alaa Nassef
- */
-public class MinValidatorForNumber implements ConstraintValidator<Min, Number> {
-
- private long minValue;
-
- public void initialize(Min minValue) {
- this.minValue = minValue.value();
- }
-
- public boolean isValid(Number value, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( value == null ) {
- return true;
- }
- if ( value instanceof BigDecimal ) {
- return ( ( BigDecimal ) value ).compareTo( BigDecimal.valueOf( minValue ) ) != -1;
- }
- else if ( value instanceof BigInteger ) {
- return ( ( BigInteger ) value ).compareTo( BigInteger.valueOf( minValue ) ) != -1;
- }
- else {
- double doubleValue = value.doubleValue();
- return doubleValue >= minValue;
- }
-
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,51 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.math.BigDecimal;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Min;
-
-/**
- * Check that the String being validated represents a number, and has a value
- * more than or equal to the minimum value specified.
- *
- * @author Alaa Nassef
- */
-public class MinValidatorForString implements ConstraintValidator<Min, String> {
-
- private long minValue;
-
- public void initialize(Min minValue) {
- this.minValue = minValue.value();
- }
-
- public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( value == null ) {
- return true;
- }
- try {
- return new BigDecimal( ( String ) value ).compareTo( BigDecimal.valueOf( minValue ) ) != -1;
- }
- catch ( NumberFormatException nfe ) {
- return false;
- }
- }
-}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmpty.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmpty.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmpty.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -25,6 +25,8 @@
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import org.hibernate.validation.constraints.impl.NotEmptyValidator;
+
/**
* @author Emmanuel Bernard
*/
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,39 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
- * @todo Extend to not only support strings, but also collections and maps. Needs to be specified first though.
- */
-public class NotEmptyValidator implements ConstraintValidator<NotEmpty, String> {
-
- public void initialize(NotEmpty parameters) {
- }
-
- public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
- if ( object == null ) {
- return true;
- }
- int length = object.length();
- return length > 0;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNullValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNullValidator.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNullValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,37 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.NotNull;
-
-/**
- * Validate that the object is not <code>null</code>.
- *
- * @author Emmanuel Bernard
- */
-public class NotNullValidator implements ConstraintValidator<NotNull, Object> {
-
- public void initialize(NotNull parameters) {
- }
-
- public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
- return object != null;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullValidator.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,38 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Null;
-
-/**
- * Validate that the object is <code>null</code>
- *
- * @author Alaa Nassef
- */
-public class NullValidator implements ConstraintValidator<Null, Object> {
-
- public void initialize(Null constraintAnnotation) {
- }
-
- public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
- return object == null;
- }
-
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForCalendar.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForCalendar.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForCalendar.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,43 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.util.Calendar;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Past;
-
-/**
- * Check that the <code>java.util.Calendar</code> passed to be validated is in the
- * past.
- *
- * @author Alaa Nassef
- */
-public class PastValidatorForCalendar implements ConstraintValidator<Past, Calendar> {
-
- public void initialize(Past constraintAnnotation) {
- }
-
- public boolean isValid(Calendar cal, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( cal == null ) {
- return true;
- }
- return cal.before( Calendar.getInstance() );
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForDate.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForDate.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForDate.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,43 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.util.Date;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Past;
-
-/**
- * Check that the <code>java.util.Date</code> passed to be validated is in the
- * past.
- *
- * @author Alaa Nassef
- */
-public class PastValidatorForDate implements ConstraintValidator<Past, Date> {
-
- public void initialize(Past constraintAnnotation) {
- }
-
- public boolean isValid(Date date, ConstraintValidatorContext constraintValidatorContext) {
- //null values are valid
- if ( date == null ) {
- return true;
- }
- return date.before( new Date() );
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,56 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.util.regex.Matcher;
-import java.util.regex.PatternSyntaxException;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-import javax.validation.constraints.Pattern;
-
-/**
- * @author Hardy Ferentschik
- */
-public class PatternValidator implements ConstraintValidator<Pattern, String> {
-
- private java.util.regex.Pattern pattern;
-
- public void initialize(Pattern parameters) {
- Pattern.Flag flags[] = parameters.flags();
- int intFlag = 0;
- for ( Pattern.Flag flag : flags ) {
- intFlag = intFlag | flag.getValue();
- }
-
- try {
- pattern = java.util.regex.Pattern.compile( parameters.regexp(), intFlag );
- }
- catch ( PatternSyntaxException e ) {
- throw new ValidationException( "Invalid regular expression.", e );
- }
- }
-
- public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
- if ( value == null ) {
- return true;
- }
- Matcher m = pattern.matcher( value );
- return m.matches();
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArray.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArray.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArray.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,70 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-import javax.validation.constraints.Size;
-
-/**
- * Check that the length of an array is betweeb <i>min</i> and <i>max</i>
- *
- * @author Hardy Ferentschik
- */
-public class SizeValidatorForArray implements ConstraintValidator<Size, Object[]> {
- private int min;
- private int max;
-
- public void initialize(Size parameters) {
- min = parameters.min();
- max = parameters.max();
- validateParameters();
- }
-
- /**
- * Checks the number of entries in an array.
- *
- * @param array The array to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
- * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(Object[] array, ConstraintValidatorContext constraintValidatorContext) {
- if ( array == null ) {
- return true;
- }
- int length = Array.getLength( array );
- return length >= min && length <= max;
- }
-
- private void validateParameters() {
- if ( min < 0 ) {
- throw new ValidationException( "The min parameter cannot be negative." );
- }
- if ( max < 0 ) {
- throw new ValidationException( "The max paramter cannot be negative." );
- }
- if ( max < min ) {
- throw new ValidationException( "The length cannot be negative." );
- }
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,48 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.constraints.Size;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
-*/
-public class SizeValidatorForArraysOfBoolean extends SizeValidatorForArraysOfPrimitives
- implements ConstraintValidator<Size, boolean[]> {
-
- /**
- * Checks the number of entries in an array.
- *
- * @param array The array to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
- * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(boolean[] array, ConstraintValidatorContext constraintValidatorContext) {
- if ( array == null ) {
- return true;
- }
- int length = Array.getLength( array );
- return length >= min && length <= max;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,48 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-
-/**
- * @author Hardy Ferentschik
- */
-public class SizeValidatorForArraysOfByte extends SizeValidatorForArraysOfPrimitives
- implements ConstraintValidator<Size, byte[]> {
-
- /**
- * Checks the number of entries in an array.
- *
- * @param array The array to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
- * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(byte[] array, ConstraintValidatorContext constraintValidatorContext) {
- if ( array == null ) {
- return true;
- }
- int length = Array.getLength( array );
- return length >= min && length <= max;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,48 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.Size;
-
-/**
- * @author Hardy Ferentschik
- */
-public class SizeValidatorForArraysOfChar extends SizeValidatorForArraysOfPrimitives
- implements ConstraintValidator<Size, char[]> {
-
- /**
- * Checks the number of entries in an array.
- *
- * @param array The array to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
- * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(char[] array, ConstraintValidatorContext constraintValidatorContext) {
- if ( array == null ) {
- return true;
- }
- int length = Array.getLength( array );
- return length >= min && length <= max;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,48 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.constraints.Size;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
-*/
-public class SizeValidatorForArraysOfDouble extends SizeValidatorForArraysOfPrimitives
- implements ConstraintValidator<Size, double[]> {
-
- /**
- * Checks the number of entries in an array.
- *
- * @param array The array to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
- * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(double[] array, ConstraintValidatorContext constraintValidatorContext) {
- if ( array == null ) {
- return true;
- }
- int length = Array.getLength( array );
- return length >= min && length <= max;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,48 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.constraints.Size;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
-*/
-public class SizeValidatorForArraysOfFloat extends SizeValidatorForArraysOfPrimitives
- implements ConstraintValidator<Size, float[]> {
-
- /**
- * Checks the number of entries in an array.
- *
- * @param array The array to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
- * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(float[] array, ConstraintValidatorContext constraintValidatorContext) {
- if ( array == null ) {
- return true;
- }
- int length = Array.getLength( array );
- return length >= min && length <= max;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,48 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.constraints.Size;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
-*/
-public class SizeValidatorForArraysOfInt extends SizeValidatorForArraysOfPrimitives
- implements ConstraintValidator<Size, int[]> {
-
- /**
- * Checks the number of entries in an array.
- *
- * @param array The array to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
- * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(int[] array, ConstraintValidatorContext constraintValidatorContext) {
- if ( array == null ) {
- return true;
- }
- int length = Array.getLength( array );
- return length >= min && length <= max;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,48 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.constraints.Size;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
-*/
-public class SizeValidatorForArraysOfLong extends SizeValidatorForArraysOfPrimitives
- implements ConstraintValidator<Size, long[]> {
-
- /**
- * Checks the number of entries in an array.
- *
- * @param array The array to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
- * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(long[] array, ConstraintValidatorContext constraintValidatorContext) {
- if ( array == null ) {
- return true;
- }
- int length = Array.getLength( array );
- return length >= min && length <= max;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,52 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-import javax.validation.constraints.Size;
-
-/**
- * Check that the length of an array is betweeb <i>min</i> and <i>max</i>
- *
- * @author Hardy Ferentschik
- */
-public class SizeValidatorForArraysOfPrimitives {
- protected int min;
- protected int max;
-
- public void initialize(Size parameters) {
- min = parameters.min();
- max = parameters.max();
- validateParameters();
- }
-
- private void validateParameters() {
- if ( min < 0 ) {
- throw new ValidationException( "The min parameter cannot be negative." );
- }
- if ( max < 0 ) {
- throw new ValidationException( "The max paramter cannot be negative." );
- }
- if ( max < min ) {
- throw new ValidationException( "The length cannot be negative." );
- }
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,48 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.lang.reflect.Array;
-import javax.validation.constraints.Size;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
-*/
-public class SizeValidatorForArraysOfShort extends SizeValidatorForArraysOfPrimitives
- implements ConstraintValidator<Size, short[]> {
-
- /**
- * Checks the number of entries in an array.
- *
- * @param array The array to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
- * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(short[] array, ConstraintValidatorContext constraintValidatorContext) {
- if ( array == null ) {
- return true;
- }
- int length = Array.getLength( array );
- return length >= min && length <= max;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForCollection.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForCollection.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForCollection.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,70 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.util.Collection;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-import javax.validation.constraints.Size;
-
-/**
- * Check that a string's length is between min and max.
- *
- * @author Hardy Ferentschik
- */
-public class SizeValidatorForCollection implements ConstraintValidator<Size, Collection> {
- private int min;
- private int max;
-
- public void initialize(Size parameters) {
- min = parameters.min();
- max = parameters.max();
- validateParameters();
- }
-
- /**
- * Checks the number of entries in a map.
- *
- * @param collection The collection to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the collection is <code>null</code> or the number of entries in
- * <code>collection</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(Collection collection, ConstraintValidatorContext constraintValidatorContext) {
- if ( collection == null ) {
- return true;
- }
- int length = collection.size();
- return length >= min && length <= max;
- }
-
- private void validateParameters() {
- if ( min < 0 ) {
- throw new ValidationException( "The min parameter cannot be negative." );
- }
- if ( max < 0 ) {
- throw new ValidationException( "The max paramter cannot be negative." );
- }
- if ( max < min ) {
- throw new ValidationException( "The length cannot be negative." );
- }
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForMap.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForMap.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForMap.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,70 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import java.util.Map;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-import javax.validation.constraints.Size;
-
-/**
- * Check that a string's length is between min and max.
- *
- * @author Hardy Ferentschik
- */
-public class SizeValidatorForMap implements ConstraintValidator<Size, Map> {
- private int min;
- private int max;
-
- public void initialize(Size parameters) {
- min = parameters.min();
- max = parameters.max();
- validateParameters();
- }
-
- /**
- * Checks the number of entries in a map.
- *
- * @param map The map to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the map is <code>null</code> or the number of entries in <code>map</code>
- * is between the specified <code>min</code> and <code>max</code> values (inclusive),
- * <code>false</code> otherwise.
- */
- public boolean isValid(Map map, ConstraintValidatorContext constraintValidatorContext) {
- if ( map == null ) {
- return true;
- }
- int size = map.size();
- return size >= min && size <= max;
- }
-
- private void validateParameters() {
- if ( min < 0 ) {
- throw new ValidationException( "The min parameter cannot be negative." );
- }
- if ( max < 0 ) {
- throw new ValidationException( "The max paramter cannot be negative." );
- }
- if ( max < min ) {
- throw new ValidationException( "The length cannot be negative." );
- }
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForString.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForString.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForString.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -1,70 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.constraints;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-import javax.validation.constraints.Size;
-
-/**
- * Check that a string's length is between min and max.
- *
- * @author Emmanuel Bernard
- * @author Gavin King
- * @author Hardy Ferentschik
- */
-public class SizeValidatorForString implements ConstraintValidator<Size, String> {
- private int min;
- private int max;
-
- public void initialize(Size parameters) {
- min = parameters.min();
- max = parameters.max();
- validateParameters();
- }
-
- /**
- * Checks the length of the specified string.
- *
- * @param s The string to validate.
- * @param constraintValidatorContext context in which the constraint is evaluated.
- *
- * @return Returns <code>true</code> if the string is <code>null</code> or the length of <code>s</code> between the specified
- * <code>min</code> and <code>max</code> values (inclusive), <code>false</code> otherwise.
- */
- public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
- if ( s == null ) {
- return true;
- }
- int length = s.length();
- return length >= min && length <= max;
- }
-
- private void validateParameters() {
- if ( min < 0 ) {
- throw new ValidationException( "The min parameter cannot be negative." );
- }
- if ( max < 0 ) {
- throw new ValidationException( "The max paramter cannot be negative." );
- }
- if ( max < min ) {
- throw new ValidationException( "The length cannot be negative." );
- }
- }
-}
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertFalseValidator.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertFalseValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertFalseValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.AssertFalse;
+
+/**
+ * Validates that the value passed is false
+ *
+ * @author Alaa Nassef
+ */
+public class AssertFalseValidator implements ConstraintValidator<AssertFalse, Boolean> {
+
+ public void initialize(AssertFalse constraintAnnotation) {
+ }
+
+ public boolean isValid(Boolean bool, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ return bool == null || !bool;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertFalseValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertTrueValidator.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertTrueValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertTrueValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.AssertTrue;
+
+/**
+ * Validates that the value passed is true
+ *
+ * @author Alaa Nassef
+ */
+public class AssertTrueValidator implements ConstraintValidator<AssertTrue, Boolean> {
+
+ public void initialize(AssertTrue constraintAnnotation) {
+ }
+
+ public boolean isValid(Boolean bool, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ return bool == null || bool;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/AssertTrueValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForNumber.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForNumber.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForNumber.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForNumber.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,72 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.math.BigDecimal;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Digits;
+
+/**
+ * Validates that the <code>Number</code> being validates matches the pattern
+ * defined in the constraint.
+ *
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class DigitsValidatorForNumber implements ConstraintValidator<Digits, Number> {
+
+ private int maxIntegerLength;
+ private int maxFractionLength;
+
+ public void initialize(Digits constraintAnnotation) {
+ this.maxIntegerLength = constraintAnnotation.integer();
+ this.maxFractionLength = constraintAnnotation.fraction();
+ validateParameters();
+ }
+
+ public boolean isValid(Number num, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( num == null ) {
+ return true;
+ }
+
+ BigDecimal bigNum;
+ if ( num instanceof BigDecimal ) {
+ bigNum = ( BigDecimal ) num;
+ }
+ else {
+ bigNum = new BigDecimal( num.toString() );
+ }
+
+ int integerPartLength = bigNum.precision() - bigNum.scale();
+ int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();
+
+ return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
+ }
+
+ private void validateParameters() {
+ if ( maxIntegerLength < 0 ) {
+ throw new ValidationException( "The length of the interger part cannot be negative." );
+ }
+ if ( maxFractionLength < 0 ) {
+ throw new ValidationException( "The length of the fraction part cannot be negative." );
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForNumber.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForString.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/DigitsValidatorForString.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForString.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForString.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,80 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.math.BigDecimal;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Digits;
+
+/**
+ * Validates that the <code>String</code> being validated consists of digits,
+ * and matches the pattern defined in the constraint.
+ *
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class DigitsValidatorForString implements ConstraintValidator<Digits, String> {
+
+ private int maxIntegerLength;
+ private int maxFractionLength;
+
+ public void initialize(Digits constraintAnnotation) {
+ this.maxIntegerLength = constraintAnnotation.integer();
+ this.maxFractionLength = constraintAnnotation.fraction();
+ validateParameters();
+ }
+
+ public boolean isValid(String str, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( str == null ) {
+ return true;
+ }
+
+ BigDecimal bigNum = getBigDecimalValue( str );
+ if ( bigNum == null ) {
+ return false;
+ }
+
+ int integerPartLength = bigNum.precision() - bigNum.scale();
+ int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();
+
+ return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
+ }
+
+ private BigDecimal getBigDecimalValue(String str) {
+ BigDecimal bd;
+ try {
+ bd = new BigDecimal( str );
+ }
+ catch ( NumberFormatException nfe ) {
+ return null;
+ }
+ return bd;
+ }
+
+ private void validateParameters() {
+ if ( maxIntegerLength < 0 ) {
+ throw new ValidationException( "The length of the interger part cannot be negative." );
+ }
+ if ( maxFractionLength < 0 ) {
+ throw new ValidationException( "The length of the fraction part cannot be negative." );
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/DigitsValidatorForString.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForCalendar.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForCalendar.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForCalendar.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,43 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.util.Calendar;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Future;
+
+/**
+ * Check that the <code>java.util.Calendar</code> passed to be validated is in
+ * the future.
+ *
+ * @author Alaa Nassef
+ */
+public class FutureValidatorForCalendar implements ConstraintValidator<Future, Calendar> {
+
+ public void initialize(Future constraintAnnotation) {
+ }
+
+ public boolean isValid(Calendar cal, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( cal == null ) {
+ return true;
+ }
+ return cal.after( Calendar.getInstance() );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForCalendar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForDate.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForDate.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForDate.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,43 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.util.Date;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Future;
+
+/**
+ * Check that the <code>java.util.Date</code> passed to be validated is in the
+ * future.
+ *
+ * @author Alaa Nassef
+ */
+public class FutureValidatorForDate implements ConstraintValidator<Future, Date> {
+
+ public void initialize(Future constraintAnnotation) {
+ }
+
+ public boolean isValid(Date date, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( date == null ) {
+ return true;
+ }
+ return date.after( new Date() );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/FutureValidatorForDate.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/LengthValidator.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/LengthValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/LengthValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,61 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+
+import org.hibernate.validation.constraints.Length;
+
+/**
+ * Check that a string's length is between min and max.
+ *
+ * @author Emmanuel Bernard
+ * @author Gavin King
+ */
+public class LengthValidator implements ConstraintValidator<Length, String> {
+ private int min;
+ private int max;
+
+ public void initialize(Length parameters) {
+ min = parameters.min();
+ max = parameters.max();
+ validateParameters();
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ if ( value == null ) {
+ return true;
+ }
+ int length = value.length();
+ return length >= min && length <= max;
+ }
+
+ private void validateParameters() {
+ if ( min < 0 ) {
+ throw new ValidationException( "The min parameter cannot be negative." );
+ }
+ if ( max < 0 ) {
+ throw new ValidationException( "The max paramter cannot be negative." );
+ }
+ if ( max < min ) {
+ throw new ValidationException( "The length cannot be negative." );
+ }
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/LengthValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForNumber.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForNumber.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForNumber.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,56 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Max;
+
+/**
+ * Check that the number being validated is less than or equal to the maximum
+ * value specified.
+ *
+ * @author Alaa Nassef
+ */
+public class MaxValidatorForNumber implements ConstraintValidator<Max, Number> {
+
+ private long maxValue;
+
+ public void initialize(Max maxValue) {
+ this.maxValue = maxValue.value();
+ }
+
+ public boolean isValid(Number value, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( value == null ) {
+ return true;
+ }
+ if ( value instanceof BigDecimal ) {
+ return ( ( BigDecimal ) value ).compareTo( BigDecimal.valueOf( maxValue ) ) != 1;
+ }
+ else if ( value instanceof BigInteger ) {
+ return ( ( BigInteger ) value ).compareTo( BigInteger.valueOf( maxValue ) ) != 1;
+ }
+ else {
+ double doubleValue = value.doubleValue();
+ return doubleValue <= maxValue;
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForNumber.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForString.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForString.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForString.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,51 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.math.BigDecimal;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Max;
+
+/**
+ * Check that the String being validated represents a number, and has a value
+ * less than or equal to the maximum value specified.
+ *
+ * @author Alaa Nassef
+ */
+public class MaxValidatorForString implements ConstraintValidator<Max, String> {
+
+ private long maxValue;
+
+ public void initialize(Max maxValue) {
+ this.maxValue = maxValue.value();
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( value == null ) {
+ return true;
+ }
+ try {
+ return new BigDecimal( value ).compareTo( BigDecimal.valueOf( maxValue ) ) != 1;
+ }
+ catch ( NumberFormatException nfe ) {
+ return false;
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MaxValidatorForString.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForNumber.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForNumber.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForNumber.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,57 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Min;
+
+/**
+ * Check that the number being validated is greater than or equal to the minimum
+ * value specified.
+ *
+ * @author Alaa Nassef
+ */
+public class MinValidatorForNumber implements ConstraintValidator<Min, Number> {
+
+ private long minValue;
+
+ public void initialize(Min minValue) {
+ this.minValue = minValue.value();
+ }
+
+ public boolean isValid(Number value, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( value == null ) {
+ return true;
+ }
+ if ( value instanceof BigDecimal ) {
+ return ( ( BigDecimal ) value ).compareTo( BigDecimal.valueOf( minValue ) ) != -1;
+ }
+ else if ( value instanceof BigInteger ) {
+ return ( ( BigInteger ) value ).compareTo( BigInteger.valueOf( minValue ) ) != -1;
+ }
+ else {
+ double doubleValue = value.doubleValue();
+ return doubleValue >= minValue;
+ }
+
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForNumber.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForString.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForString.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForString.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,51 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.math.BigDecimal;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Min;
+
+/**
+ * Check that the String being validated represents a number, and has a value
+ * more than or equal to the minimum value specified.
+ *
+ * @author Alaa Nassef
+ */
+public class MinValidatorForString implements ConstraintValidator<Min, String> {
+
+ private long minValue;
+
+ public void initialize(Min minValue) {
+ this.minValue = minValue.value();
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( value == null ) {
+ return true;
+ }
+ try {
+ return new BigDecimal( ( String ) value ).compareTo( BigDecimal.valueOf( minValue ) ) != -1;
+ }
+ catch ( NumberFormatException nfe ) {
+ return false;
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/MinValidatorForString.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotEmptyValidator.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotEmptyValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotEmptyValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,41 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+import org.hibernate.validation.constraints.NotEmpty;
+
+/**
+ * @author Hardy Ferentschik
+ * @todo Extend to not only support strings, but also collections and maps. Needs to be specified first though.
+ */
+public class NotEmptyValidator implements ConstraintValidator<NotEmpty, String> {
+
+ public void initialize(NotEmpty parameters) {
+ }
+
+ public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
+ if ( object == null ) {
+ return true;
+ }
+ int length = object.length();
+ return length > 0;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotEmptyValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotNullValidator.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNullValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotNullValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotNullValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,37 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.NotNull;
+
+/**
+ * Validate that the object is not <code>null</code>.
+ *
+ * @author Emmanuel Bernard
+ */
+public class NotNullValidator implements ConstraintValidator<NotNull, Object> {
+
+ public void initialize(NotNull parameters) {
+ }
+
+ public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
+ return object != null;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NotNullValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NullValidator.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NullValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NullValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,38 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Null;
+
+/**
+ * Validate that the object is <code>null</code>
+ *
+ * @author Alaa Nassef
+ */
+public class NullValidator implements ConstraintValidator<Null, Object> {
+
+ public void initialize(Null constraintAnnotation) {
+ }
+
+ public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
+ return object == null;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/NullValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForCalendar.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForCalendar.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForCalendar.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForCalendar.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,43 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.util.Calendar;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Past;
+
+/**
+ * Check that the <code>java.util.Calendar</code> passed to be validated is in the
+ * past.
+ *
+ * @author Alaa Nassef
+ */
+public class PastValidatorForCalendar implements ConstraintValidator<Past, Calendar> {
+
+ public void initialize(Past constraintAnnotation) {
+ }
+
+ public boolean isValid(Calendar cal, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( cal == null ) {
+ return true;
+ }
+ return cal.before( Calendar.getInstance() );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForCalendar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForDate.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastValidatorForDate.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForDate.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForDate.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,43 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.util.Date;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Past;
+
+/**
+ * Check that the <code>java.util.Date</code> passed to be validated is in the
+ * past.
+ *
+ * @author Alaa Nassef
+ */
+public class PastValidatorForDate implements ConstraintValidator<Past, Date> {
+
+ public void initialize(Past constraintAnnotation) {
+ }
+
+ public boolean isValid(Date date, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( date == null ) {
+ return true;
+ }
+ return date.before( new Date() );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PastValidatorForDate.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PatternValidator.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PatternValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PatternValidator.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,56 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.util.regex.Matcher;
+import java.util.regex.PatternSyntaxException;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Pattern;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class PatternValidator implements ConstraintValidator<Pattern, String> {
+
+ private java.util.regex.Pattern pattern;
+
+ public void initialize(Pattern parameters) {
+ Pattern.Flag flags[] = parameters.flags();
+ int intFlag = 0;
+ for ( Pattern.Flag flag : flags ) {
+ intFlag = intFlag | flag.getValue();
+ }
+
+ try {
+ pattern = java.util.regex.Pattern.compile( parameters.regexp(), intFlag );
+ }
+ catch ( PatternSyntaxException e ) {
+ throw new ValidationException( "Invalid regular expression.", e );
+ }
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ if ( value == null ) {
+ return true;
+ }
+ Matcher m = pattern.matcher( value );
+ return m.matches();
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/PatternValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArray.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArray.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArray.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArray.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,70 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Size;
+
+/**
+ * Check that the length of an array is betweeb <i>min</i> and <i>max</i>
+ *
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForArray implements ConstraintValidator<Size, Object[]> {
+ private int min;
+ private int max;
+
+ public void initialize(Size parameters) {
+ min = parameters.min();
+ max = parameters.max();
+ validateParameters();
+ }
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(Object[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+
+ private void validateParameters() {
+ if ( min < 0 ) {
+ throw new ValidationException( "The min parameter cannot be negative." );
+ }
+ if ( max < 0 ) {
+ throw new ValidationException( "The max paramter cannot be negative." );
+ }
+ if ( max < min ) {
+ throw new ValidationException( "The length cannot be negative." );
+ }
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArray.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfBoolean.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfBoolean.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfBoolean.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfBoolean extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, boolean[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(boolean[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfBoolean.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfByte.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfByte.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfByte.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForArraysOfByte extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, byte[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(byte[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfByte.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfChar.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfChar.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfChar.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForArraysOfChar extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, char[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(char[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfChar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfDouble.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfDouble.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfDouble.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfDouble extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, double[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(double[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfDouble.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfFloat.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfFloat.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfFloat.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfFloat extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, float[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(float[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfFloat.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfInt.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfInt.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfInt.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfInt extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, int[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(int[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfInt.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfLong.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfLong.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfLong.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfLong extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, long[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(long[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfLong.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfPrimitives.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfPrimitives.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfPrimitives.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,52 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Size;
+
+/**
+ * Check that the length of an array is betweeb <i>min</i> and <i>max</i>
+ *
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForArraysOfPrimitives {
+ protected int min;
+ protected int max;
+
+ public void initialize(Size parameters) {
+ min = parameters.min();
+ max = parameters.max();
+ validateParameters();
+ }
+
+ private void validateParameters() {
+ if ( min < 0 ) {
+ throw new ValidationException( "The min parameter cannot be negative." );
+ }
+ if ( max < 0 ) {
+ throw new ValidationException( "The max paramter cannot be negative." );
+ }
+ if ( max < min ) {
+ throw new ValidationException( "The length cannot be negative." );
+ }
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfPrimitives.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfShort.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfShort.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfShort.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfShort extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, short[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(short[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForArraysOfShort.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForCollection.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForCollection.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForCollection.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForCollection.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,70 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.util.Collection;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Size;
+
+/**
+ * Check that a string's length is between min and max.
+ *
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForCollection implements ConstraintValidator<Size, Collection> {
+ private int min;
+ private int max;
+
+ public void initialize(Size parameters) {
+ min = parameters.min();
+ max = parameters.max();
+ validateParameters();
+ }
+
+ /**
+ * Checks the number of entries in a map.
+ *
+ * @param collection The collection to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the collection is <code>null</code> or the number of entries in
+ * <code>collection</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(Collection collection, ConstraintValidatorContext constraintValidatorContext) {
+ if ( collection == null ) {
+ return true;
+ }
+ int length = collection.size();
+ return length >= min && length <= max;
+ }
+
+ private void validateParameters() {
+ if ( min < 0 ) {
+ throw new ValidationException( "The min parameter cannot be negative." );
+ }
+ if ( max < 0 ) {
+ throw new ValidationException( "The max paramter cannot be negative." );
+ }
+ if ( max < min ) {
+ throw new ValidationException( "The length cannot be negative." );
+ }
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForCollection.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForMap.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForMap.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForMap.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForMap.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,70 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import java.util.Map;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Size;
+
+/**
+ * Check that a string's length is between min and max.
+ *
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForMap implements ConstraintValidator<Size, Map> {
+ private int min;
+ private int max;
+
+ public void initialize(Size parameters) {
+ min = parameters.min();
+ max = parameters.max();
+ validateParameters();
+ }
+
+ /**
+ * Checks the number of entries in a map.
+ *
+ * @param map The map to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the map is <code>null</code> or the number of entries in <code>map</code>
+ * is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(Map map, ConstraintValidatorContext constraintValidatorContext) {
+ if ( map == null ) {
+ return true;
+ }
+ int size = map.size();
+ return size >= min && size <= max;
+ }
+
+ private void validateParameters() {
+ if ( min < 0 ) {
+ throw new ValidationException( "The min parameter cannot be negative." );
+ }
+ if ( max < 0 ) {
+ throw new ValidationException( "The max paramter cannot be negative." );
+ }
+ if ( max < min ) {
+ throw new ValidationException( "The length cannot be negative." );
+ }
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForMap.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForString.java (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForString.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForString.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForString.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,70 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints.impl;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Size;
+
+/**
+ * Check that a string's length is between min and max.
+ *
+ * @author Emmanuel Bernard
+ * @author Gavin King
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForString implements ConstraintValidator<Size, String> {
+ private int min;
+ private int max;
+
+ public void initialize(Size parameters) {
+ min = parameters.min();
+ max = parameters.max();
+ validateParameters();
+ }
+
+ /**
+ * Checks the length of the specified string.
+ *
+ * @param s The string to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the string is <code>null</code> or the length of <code>s</code> between the specified
+ * <code>min</code> and <code>max</code> values (inclusive), <code>false</code> otherwise.
+ */
+ public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
+ if ( s == null ) {
+ return true;
+ }
+ int length = s.length();
+ return length >= min && length <= max;
+ }
+
+ private void validateParameters() {
+ if ( min < 0 ) {
+ throw new ValidationException( "The min parameter cannot be negative." );
+ }
+ if ( max < 0 ) {
+ throw new ValidationException( "The max paramter cannot be negative." );
+ }
+ if ( max < min ) {
+ throw new ValidationException( "The length cannot be negative." );
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/SizeValidatorForString.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/package.html (from rev 16742, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/package.html)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/package.html (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/impl/package.html 2009-06-10 18:41:22 UTC (rev 16748)
@@ -0,0 +1,27 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<!--
+
+ JBoss, Home of Professional Open Source
+ Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ by the @authors tag. See the copyright.txt in the distribution for a
+ full listing of individual contributors.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+</head>
+<body>
+This package contains the implementations of the builtin constraints as well as Hibernate Validator specific
+constraint implementations.
+</body>
+</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/package.html 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/package.html 2009-06-10 18:41:22 UTC (rev 16748)
@@ -21,7 +21,6 @@
-->
</head>
<body>
-This package contains the implementations of the builtin constraints as well as Hibernate Validator specific
-constraints and their implementations.
+This package contains the Hibernate Validator specific constraints.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -40,32 +40,32 @@
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
-import org.hibernate.validation.constraints.AssertFalseValidator;
-import org.hibernate.validation.constraints.AssertTrueValidator;
-import org.hibernate.validation.constraints.DigitsValidatorForNumber;
-import org.hibernate.validation.constraints.DigitsValidatorForString;
-import org.hibernate.validation.constraints.FutureValidatorForCalendar;
-import org.hibernate.validation.constraints.FutureValidatorForDate;
-import org.hibernate.validation.constraints.MaxValidatorForNumber;
-import org.hibernate.validation.constraints.MaxValidatorForString;
-import org.hibernate.validation.constraints.MinValidatorForNumber;
-import org.hibernate.validation.constraints.MinValidatorForString;
-import org.hibernate.validation.constraints.NotNullValidator;
-import org.hibernate.validation.constraints.NullValidator;
-import org.hibernate.validation.constraints.PastValidatorForCalendar;
-import org.hibernate.validation.constraints.PastValidatorForDate;
-import org.hibernate.validation.constraints.PatternValidator;
-import org.hibernate.validation.constraints.SizeValidatorForArray;
-import org.hibernate.validation.constraints.SizeValidatorForArraysOfBoolean;
-import org.hibernate.validation.constraints.SizeValidatorForArraysOfByte;
-import org.hibernate.validation.constraints.SizeValidatorForArraysOfChar;
-import org.hibernate.validation.constraints.SizeValidatorForArraysOfDouble;
-import org.hibernate.validation.constraints.SizeValidatorForArraysOfFloat;
-import org.hibernate.validation.constraints.SizeValidatorForArraysOfInt;
-import org.hibernate.validation.constraints.SizeValidatorForArraysOfLong;
-import org.hibernate.validation.constraints.SizeValidatorForCollection;
-import org.hibernate.validation.constraints.SizeValidatorForMap;
-import org.hibernate.validation.constraints.SizeValidatorForString;
+import org.hibernate.validation.constraints.impl.AssertFalseValidator;
+import org.hibernate.validation.constraints.impl.AssertTrueValidator;
+import org.hibernate.validation.constraints.impl.DigitsValidatorForNumber;
+import org.hibernate.validation.constraints.impl.DigitsValidatorForString;
+import org.hibernate.validation.constraints.impl.FutureValidatorForCalendar;
+import org.hibernate.validation.constraints.impl.FutureValidatorForDate;
+import org.hibernate.validation.constraints.impl.MaxValidatorForNumber;
+import org.hibernate.validation.constraints.impl.MaxValidatorForString;
+import org.hibernate.validation.constraints.impl.MinValidatorForNumber;
+import org.hibernate.validation.constraints.impl.MinValidatorForString;
+import org.hibernate.validation.constraints.impl.NotNullValidator;
+import org.hibernate.validation.constraints.impl.NullValidator;
+import org.hibernate.validation.constraints.impl.PastValidatorForCalendar;
+import org.hibernate.validation.constraints.impl.PastValidatorForDate;
+import org.hibernate.validation.constraints.impl.PatternValidator;
+import org.hibernate.validation.constraints.impl.SizeValidatorForArray;
+import org.hibernate.validation.constraints.impl.SizeValidatorForArraysOfBoolean;
+import org.hibernate.validation.constraints.impl.SizeValidatorForArraysOfByte;
+import org.hibernate.validation.constraints.impl.SizeValidatorForArraysOfChar;
+import org.hibernate.validation.constraints.impl.SizeValidatorForArraysOfDouble;
+import org.hibernate.validation.constraints.impl.SizeValidatorForArraysOfFloat;
+import org.hibernate.validation.constraints.impl.SizeValidatorForArraysOfInt;
+import org.hibernate.validation.constraints.impl.SizeValidatorForArraysOfLong;
+import org.hibernate.validation.constraints.impl.SizeValidatorForCollection;
+import org.hibernate.validation.constraints.impl.SizeValidatorForMap;
+import org.hibernate.validation.constraints.impl.SizeValidatorForString;
import org.hibernate.validation.util.ReflectionHelper;
/**
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -32,7 +32,7 @@
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
-import org.hibernate.validation.constraints.NotNullValidator;
+import org.hibernate.validation.constraints.impl.NotNullValidator;
import org.hibernate.validation.engine.ConfigurationImpl;
import org.hibernate.validation.engine.ConstraintValidatorFactoryImpl;
import org.hibernate.validation.engine.HibernateValidatorConfiguration;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -22,6 +22,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.hibernate.validation.constraints.impl.AssertFalseValidator;
+
/**
* @author Alaa Nassef
*/
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -22,6 +22,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.hibernate.validation.constraints.impl.AssertTrueValidator;
+
/**
* @author Alaa Nassef
*/
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForNumberTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForNumberTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForNumberTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -27,6 +27,7 @@
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+import org.hibernate.validation.constraints.impl.DigitsValidatorForNumber;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForStringTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForStringTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForStringTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -27,6 +27,7 @@
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+import org.hibernate.validation.constraints.impl.DigitsValidatorForString;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -24,6 +24,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.hibernate.validation.constraints.impl.FutureValidatorForCalendar;
+
/**
* @author Alaa Nassef
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -24,6 +24,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.hibernate.validation.constraints.impl.FutureValidatorForDate;
+
public class FutureValidatorForDateTest {
private static FutureValidatorForDate constraint;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -25,6 +25,7 @@
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+import org.hibernate.validation.constraints.impl.LengthValidator;
/**
* Tests the <code>LengthConstraint</code>.
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -28,6 +28,7 @@
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+import org.hibernate.validation.constraints.impl.MaxValidatorForNumber;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -26,6 +26,7 @@
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+import org.hibernate.validation.constraints.impl.MaxValidatorForString;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -28,6 +28,7 @@
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+import org.hibernate.validation.constraints.impl.MinValidatorForNumber;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -26,6 +26,7 @@
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+import org.hibernate.validation.constraints.impl.MinValidatorForString;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -22,6 +22,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.hibernate.validation.constraints.impl.NotEmptyValidator;
+
/**
* @author Hardy Ferentschik
*/
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -21,6 +21,8 @@
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
+import org.hibernate.validation.constraints.impl.NotNullValidator;
+
/**
* @author Hardy Ferentschik
*/
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -22,6 +22,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.hibernate.validation.constraints.impl.NullValidator;
+
/**
* @author Alaa Nassef
*/
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -24,6 +24,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.hibernate.validation.constraints.impl.PastValidatorForCalendar;
+
/**
* @author Alaa Nassef
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -24,6 +24,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import org.hibernate.validation.constraints.impl.PastValidatorForDate;
+
public class PastValidatorForDateTest {
private static PastValidatorForDate constraint;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -26,6 +26,7 @@
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+import org.hibernate.validation.constraints.impl.PatternValidator;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ConstraintDescriptorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ConstraintDescriptorTest.java 2009-06-10 18:38:26 UTC (rev 16747)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ConstraintDescriptorTest.java 2009-06-10 18:41:22 UTC (rev 16748)
@@ -32,7 +32,7 @@
import static org.testng.Assert.fail;
import org.testng.annotations.Test;
-import org.hibernate.validation.constraints.NotNullValidator;
+import org.hibernate.validation.constraints.impl.NotNullValidator;
import org.hibernate.validation.engine.Order;
import org.hibernate.validation.engine.constraintcomposition.GermanAddress;
import org.hibernate.validation.util.LoggerFactory;
15 years, 5 months
Hibernate SVN: r16747 - core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-10 14:38:26 -0400 (Wed, 10 Jun 2009)
New Revision: 16747
Added:
core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/bibliography.xml
Log:
minor changes; added biblio references for JPwH
Added: core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/bibliography.xml
===================================================================
--- core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/bibliography.xml (rev 0)
+++ core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/bibliography.xml 2009-06-10 18:38:26 UTC (rev 16747)
@@ -0,0 +1,75 @@
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE bibliography PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+
+<bibliography>
+ <title>References</title>
+
+ <biblioentry id="biblio-PoEAA">
+ <abbrev>PoEAA</abbrev>
+ <title>Patterns of Enterprise Application Architecture</title>
+ <isbn>0-321-12742-0</isbn>
+ <authorgroup>
+ <author>
+ <firstname>Martin</firstname>
+ <surname>Fowler</surname>
+ </author>
+ </authorgroup>
+ <copyright>
+ <year>2003</year>
+ <holder>Pearson Education, Inc.</holder>
+ </copyright>
+ <publisher>
+ <publishername>Addison-Wesley Publishing Company</publishername>
+ </publisher>
+ </biblioentry>
+
+ <biblioentry id="biblio-JPwH">
+ <abbrev>JPwH</abbrev>
+ <title>Java Persistence with Hibernate</title>
+ <subtitle>Second Edition of Hibernate in Action</subtitle>
+ <isbn>1-932394-88-5</isbn>
+ <bibliomisc>
+ <ulink url="http://www.manning.com/bauer2"/>
+ </bibliomisc>
+ <authorgroup>
+ <author>
+ <firstname>Christian</firstname>
+ <surname>Bauer</surname>
+ </author>
+ <author>
+ <firstname>Gavin</firstname>
+ <surname>King</surname>
+ </author>
+ </authorgroup>
+ <copyright>
+ <year>2007</year>
+ <holder>Manning Publications Co.</holder>
+ </copyright>
+ <publisher>
+ <publishername>Manning Publications Co.</publishername>
+ </publisher>
+ </biblioentry>
+
+</bibliography>
\ No newline at end of file
15 years, 5 months
Hibernate SVN: r16746 - core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-10 14:38:12 -0400 (Wed, 10 Jun 2009)
New Revision: 16746
Modified:
core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/preface.xml
Log:
minor changes; added biblio references for JPwH
Modified: core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/preface.xml
===================================================================
--- core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/preface.xml 2009-06-10 18:33:59 UTC (rev 16745)
+++ core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/preface.xml 2009-06-10 18:38:12 UTC (rev 16746)
@@ -30,8 +30,8 @@
<para>
Working with object-oriented software and a relational database can be cumbersome
- and time consuming in today's enterprise environments. Hibernate is an object/relational
- mapping tool for Java environments. The term object/relational mapping (ORM) refers to
+ and time consuming in today's enterprise environments. Hibernate is an Object/Relational
+ Mapping tool for Java environments. The term Object/Relational Mapping (ORM) refers to
the technique of mapping a data representation from an object model to a relational
data model with a SQL-based schema.
</para>
@@ -86,12 +86,12 @@
</listitem>
<listitem>
<para>
- Use this reference documentation as your primary source of information.
- Consider reading <emphasis>Java Persistence with Hibernate</emphasis>
- (http://www.manning.com/bauer2) if you need more help with application
- design, or if you prefer a step-by-step tutorial. Also visit
- http://caveatemptor.hibernate.org and download the example application
- for Java Persistence with Hibernate.
+ Use this reference documentation as your primary source of
+ information. Consider reading <biblioref linkend="biblio-JPwH"/>
+ if you need more help with application design, or if you prefer
+ a step-by-step tutorial. Also visit
+ <ulink url="http://caveatemptor.hibernate.org"/> and download
+ the example application from <biblioref linkend="biblio-JPwH"/>.
</para>
</listitem>
<listitem>
@@ -101,8 +101,8 @@
</listitem>
<listitem>
<para>
- Third party demos, examples, and tutorials are linked on the Hibernate
- website.
+ Links to third party demos, examples, and tutorials are maintained
+ on the Hibernate website.
</para>
</listitem>
<listitem>
15 years, 5 months
Hibernate SVN: r16745 - core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-10 14:33:59 -0400 (Wed, 10 Jun 2009)
New Revision: 16745
Modified:
core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/transactions.xml
Log:
added a definition of UoW
Modified: core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/transactions.xml
===================================================================
--- core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/transactions.xml 2009-06-10 18:33:44 UTC (rev 16744)
+++ core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/transactions.xml 2009-06-10 18:33:59 UTC (rev 16745)
@@ -92,6 +92,23 @@
<title>Unit of work</title>
<para>
+ First, let's define a unit of work. A unit of work is a
+ design pattern described by Martin Fowler as
+ <quote>
+ [maintaining] a list of objects affected by a business
+ transaction and coordinates the writing out of changes
+ and the resolution of concurrency problems.
+ </quote><citation>PoEAA</citation>
+ In other words, its a series of operations we wish to carry out
+ against the database together. Basically, it is a transaction,
+ though fulfilling a unit of work will often span multiple
+ physical database transactions (see <xref linkend="transactions-basics-apptx"/>).
+ So really we are talking about a more abstract notion of a
+ transaction. The term "business transaction" is also sometimes
+ used in lieu of unit of work.
+ </para>
+
+ <para>
Do not use the <emphasis>session-per-operation</emphasis> antipattern:
do not open and close a <literal>Session</literal> for every simple database call in
a single thread. The same is true for database transactions. Database calls
15 years, 5 months