Hibernate SVN: r15386 - in search/trunk/src: java/org/hibernate/search/impl and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-10-24 10:22:27 -0400 (Fri, 24 Oct 2008)
New Revision: 15386
Modified:
search/trunk/src/java/org/hibernate/search/FullTextSession.java
search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
Log:
HSEARCH-262
purging an entity also purges also subclasses from the index
Modified: search/trunk/src/java/org/hibernate/search/FullTextSession.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/FullTextSession.java 2008-10-24 14:00:30 UTC (rev 15385)
+++ search/trunk/src/java/org/hibernate/search/FullTextSession.java 2008-10-24 14:22:27 UTC (rev 15386)
@@ -34,20 +34,22 @@
SearchFactory getSearchFactory();
/**
- * Remove a particular entity from a particular class of an index.
+ * Remove the entity with the type <code>entityType</code> and the identifier <code>id</code> from the index.
+ * If <code>id == null</code> all indexed entities of this type and its indexed subclasses are deleted. In this
+ * case this method behaves like {@link #purgeAll(Class<?>)}.
*
- * @param entityType
- * @param id
+ * @param entityType The type of the entity to delete.
+ * @param id The id of the entity to delete.
*
- * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
+ * @throws IllegalArgumentException if entityType is <code>null</codE> or not an @Indexed entity type.
*/
public void purge(Class<?> entityType, Serializable id);
/**
- * Remove all entities from a particular class of an index.
+ * Remove all entities from of particular class and all its subclasses from the index.
*
- * @param entityType
- * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
+ * @param entityType The class of the entities to remove.
+ * @throws IllegalArgumentException if entityType is <code>null</code> or not an @Indexed entity type.
*/
public void purgeAll(Class<?> entityType);
Modified: search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2008-10-24 14:00:30 UTC (rev 15385)
+++ search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2008-10-24 14:22:27 UTC (rev 15386)
@@ -7,6 +7,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.hibernate.CacheMode;
import org.hibernate.Criteria;
@@ -43,9 +44,9 @@
import org.hibernate.search.FullTextQuery;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.SearchFactory;
+import org.hibernate.search.backend.TransactionContext;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkType;
-import org.hibernate.search.backend.TransactionContext;
import org.hibernate.search.backend.impl.EventSourceTransactionContext;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.engine.SearchFactoryImplementor;
@@ -62,6 +63,7 @@
* @author Hardy Ferentschik
*/
public class FullTextSessionImpl implements FullTextSession, SessionImplementor {
+
private final Session session;
private final SessionImplementor sessionImplementor;
private transient SearchFactoryImplementor searchFactory;
@@ -69,9 +71,9 @@
public FullTextSessionImpl(org.hibernate.Session session) {
- this.session = (Session) session;
- this.transactionContext = new EventSourceTransactionContext( (EventSource) session );
- this.sessionImplementor = (SessionImplementor) session;
+ this.session = ( Session ) session;
+ this.transactionContext = new EventSourceTransactionContext( ( EventSource ) session );
+ this.sessionImplementor = ( SessionImplementor ) session;
}
/**
@@ -85,10 +87,7 @@
}
/**
- * Remove all entities from a particular class of an index.
- *
- * @param entityType
- * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
+ * {@inheritDoc}
*/
public void purgeAll(Class entityType) {
purge( entityType, null );
@@ -100,32 +99,39 @@
}
/**
- * Remove a particular entity from a particular class of an index.
- *
- * @param entityType
- * @param id
- * @throws IllegalArgumentException if entityType is null or not an @Indexed entity type
+ * {@inheritDoc}
*/
public void purge(Class<?> entityType, Serializable id) {
- if ( entityType == null ) return;
+ if ( entityType == null ) {
+ return;
+ }
+
+ // accessing the document builders is not strictly necessary but a small optimization plus let's make sure the
+ // client didn't mess something up.
SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
- // not strictly necessary but a small optimization plus let's make sure the
- // client didn't mess something up.
+ DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilder( entityType );
+ if ( builder == null ) {
+ String msg = "Entity to index is not an @Indexed entity: " + entityType.getName();
+ throw new IllegalArgumentException( msg );
+ }
- if ( searchFactoryImplementor.getDocumentBuilder( entityType ) == null
- && searchFactoryImplementor.getContainedInOnlyBuilder( entityType ) == null ) {
- throw new IllegalArgumentException( "Entity to index is not an @Indexed entity nor @ContainedIn another entity: "
- + entityType.getName() );
- }
- WorkType type;
+ Work work;
if ( id == null ) {
- type = WorkType.PURGE_ALL;
+ // purge the main entity
+ work = new Work( entityType, id, WorkType.PURGE_ALL );
+ searchFactoryImplementor.getWorker().performWork( work, transactionContext );
+
+ // purge the subclasses
+ Set<Class<?>> subClasses = builder.getMappedSubclasses();
+ for ( Class clazz : subClasses ) {
+ work = new Work( clazz, id, WorkType.PURGE_ALL );
+ searchFactoryImplementor.getWorker().performWork( work, transactionContext );
+ }
}
else {
- type = WorkType.PURGE;
+ work = new Work( entityType, id, WorkType.PURGE );
+ searchFactoryImplementor.getWorker().performWork( work, transactionContext );
}
- Work work = new Work( entityType, id, type );
- searchFactoryImplementor.getWorker().performWork( work, transactionContext );
}
/**
@@ -134,19 +140,21 @@
* The entity must be associated with the session
*
* @param entity The entity to index - must not be <code>null</code>.
+ *
* @throws IllegalArgumentException if entity is null or not an @Indexed entity
*/
public void index(Object entity) {
- if ( entity == null ) throw new IllegalArgumentException( "Entity to index should not be null" );
+ if ( entity == null ) {
+ throw new IllegalArgumentException( "Entity to index should not be null" );
+ }
Class<?> clazz = Hibernate.getClass( entity );
//TODO cache that at the FTSession level
SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
//not strictly necessary but a small optimization
- if ( searchFactoryImplementor.getDocumentBuilder( clazz ) == null
- && searchFactoryImplementor.getContainedInOnlyBuilder( clazz ) == null ) {
- throw new IllegalArgumentException( "Entity to index is not an @Indexed entity nor @ContainedIn another entity: "
- + entity.getClass().getName() );
+ if ( searchFactoryImplementor.getDocumentBuilder( clazz ) == null ) {
+ String msg = "Entity to index is not an @Indexed entity: " + entity.getClass().getName();
+ throw new IllegalArgumentException( msg );
}
Serializable id = session.getIdentifier( entity );
Work work = new Work( entity, id, WorkType.INDEX );
@@ -203,7 +211,8 @@
return session.filter( collection, filter, value, type );
}
- public Collection filter(Object collection, String filter, Object[] values, Type[] types) throws HibernateException {
+ public Collection filter(Object collection, String filter, Object[] values, Type[] types)
+ throws HibernateException {
return session.filter( collection, filter, values, types );
}
Modified: search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java 2008-10-24 14:00:30 UTC (rev 15385)
+++ search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java 2008-10-24 14:22:27 UTC (rev 15386)
@@ -36,7 +36,6 @@
}
protected void setUp() throws Exception {
-// super.setUp(); //we need a fresh session factory each time for index set up
buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
}
Modified: search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2008-10-24 14:00:30 UTC (rev 15385)
+++ search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2008-10-24 14:22:27 UTC (rev 15386)
@@ -1,77 +1,124 @@
//$Id$
package org.hibernate.search.test.inheritance;
-import org.hibernate.search.test.SearchTestCase;
-import org.hibernate.search.FullTextSession;
-import org.hibernate.search.Search;
-import org.hibernate.Transaction;
+import java.util.List;
+
+import org.apache.lucene.analysis.StopAnalyzer;
+import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RangeQuery;
-import org.apache.lucene.index.Term;
-import java.util.List;
+import org.hibernate.Transaction;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.test.SearchTestCase;
/**
* @author Emmanuel Bernard
*/
public class InheritanceTest extends SearchTestCase {
+ protected void setUp() throws Exception {
+ super.setUp();
+ ensureIndexesAreEmpty();
+ }
+
public void testInheritance() throws Exception {
+ createTestData();
FullTextSession s = Search.getFullTextSession( openSession() );
Transaction tx = s.beginTransaction();
- Animal a = new Animal();
- a.setName("Shark Jr");
- s.save( a );
- Mammal m = new Mammal();
- m.setMammalNbr(2);
- m.setName("Elephant Jr");
- m.setWeight( 400 );
- s.save(m);
- tx.commit();//post commit events for lucene
- s.clear();
- tx = s.beginTransaction();
- QueryParser parser = new QueryParser("name", new StopAnalyzer() );
+ QueryParser parser = new QueryParser( "name", new StopAnalyzer() );
Query query;
org.hibernate.Query hibQuery;
- query = parser.parse( "Elephant" );
+ query = parser.parse( "Elephant" );
hibQuery = s.createFullTextQuery( query, Mammal.class );
List result = hibQuery.list();
assertNotNull( result );
assertEquals( "Query subclass by superclass attribute", 1, result.size() );
- query = parser.parse( "mammalNbr:[2 TO 2]" );
+ query = parser.parse( "mammalNbr:[2 TO 2]" );
hibQuery = s.createFullTextQuery( query, Animal.class, Mammal.class );
result = hibQuery.list();
assertNotNull( result );
assertEquals( "Query subclass by subclass attribute", 1, result.size() );
- query = parser.parse( "Jr" );
+ query = parser.parse( "Jr" );
hibQuery = s.createFullTextQuery( query, Animal.class );
result = hibQuery.list();
assertNotNull( result );
assertEquals( "Query filtering on superclass return mapped subclasses", 2, result.size() );
- query = new RangeQuery( new Term( "weight", "00200" ), null, true);
+ query = new RangeQuery( new Term( "weight", "00200" ), null, true );
hibQuery = s.createFullTextQuery( query, Animal.class );
result = hibQuery.list();
assertNotNull( result );
assertEquals( "Query on non @Indexed superclass property", 1, result.size() );
- for (Object managedEntity : result) {
- s.delete(managedEntity);
- }
- tx.commit();
+ tx.commit();
s.close();
}
+ /**
+ * Tests that purging the index of a class also purges the index of the subclasses. See also HSEARCH-262.
+ *
+ * @throws Exception in case the test fails.
+ */
+ public void testPurgeIndex() throws Exception {
+ createTestData();
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ QueryParser parser = new QueryParser( "name", new StopAnalyzer() );
+
+ Query query = parser.parse( "Jr" );
+ List result = s.createFullTextQuery( query, Animal.class ).list();
+ assertNotNull( result );
+ assertEquals( "Wrong number of hits. There should be one elephant and one shark.", 2, result.size() );
+
+ s.purgeAll( Animal.class );
+ tx.commit();
+ tx = s.beginTransaction();
+ result = s.createFullTextQuery( query, Animal.class ).list();
+ assertNotNull( result );
+ assertEquals(
+ "Wrong number of hits. Purging the Animal class should also purge the Mammals", 0, result.size()
+ );
+
+ tx.commit();
+
+ s.close();
+ }
+
+ private void createTestData() {
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ Animal a = new Animal();
+ a.setName( "Shark Jr" );
+ s.save( a );
+ Mammal m = new Mammal();
+ m.setMammalNbr( 2 );
+ m.setName( "Elephant Jr" );
+ m.setWeight( 400 );
+ s.save( m );
+ tx.commit();//post commit events for lucene
+ s.clear();
+ }
+
+ private void ensureIndexesAreEmpty() {
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ Transaction tx;
+ tx = s.beginTransaction();
+ s.purgeAll( Animal.class );
+ s.purgeAll( Mammal.class );
+ tx.commit();
+ }
+
protected Class[] getMappings() {
return new Class[] {
- Animal.class,
- Mammal.class
- };
+ Animal.class,
+ Mammal.class
+ };
}
}
17 years, 6 months
Hibernate SVN: r15385 - search/trunk/src/test/org/hibernate/search/test/query.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-10-24 10:00:30 -0400 (Fri, 24 Oct 2008)
New Revision: 15385
Modified:
search/trunk/src/test/org/hibernate/search/test/query/QueryUnindexedEntityTest.java
Log:
HSEARCH-162 make test fail
Modified: search/trunk/src/test/org/hibernate/search/test/query/QueryUnindexedEntityTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/QueryUnindexedEntityTest.java 2008-10-24 10:25:33 UTC (rev 15384)
+++ search/trunk/src/test/org/hibernate/search/test/query/QueryUnindexedEntityTest.java 2008-10-24 14:00:30 UTC (rev 15385)
@@ -19,7 +19,7 @@
*/
public class QueryUnindexedEntityTest extends SearchTestCase {
- public void testResultTransformToDelimString() throws Exception {
+ public void testQueryOnAllEntities() throws Exception {
FullTextSession s = Search.getFullTextSession( openSession() );
@@ -32,7 +32,7 @@
tx = s.beginTransaction();
QueryParser parser = new QueryParser( "name", new StandardAnalyzer() );
Query query = parser.parse( "name:foo" );
- FullTextQuery hibQuery = s.createFullTextQuery( query, Person.class );
+ FullTextQuery hibQuery = s.createFullTextQuery( query );
try {
hibQuery.list();
fail();
17 years, 6 months
Hibernate SVN: r15384 - in search/trunk: doc/reference/en and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-10-24 06:25:33 -0400 (Fri, 24 Oct 2008)
New Revision: 15384
Added:
search/trunk/src/filters/derby.filter
Modified:
search/trunk/doc/reference/en/master.xml
search/trunk/doc/reference/en/modules/getting-started.xml
search/trunk/doc/reference/en/modules/mapping.xml
search/trunk/ivy.xml
search/trunk/readme.txt
Log:
changed beta1 to beta2. Fixed some spelling mistakes. Added derby jdbc driver
Modified: search/trunk/doc/reference/en/master.xml
===================================================================
--- search/trunk/doc/reference/en/master.xml 2008-10-23 15:48:18 UTC (rev 15383)
+++ search/trunk/doc/reference/en/master.xml 2008-10-24 10:25:33 UTC (rev 15384)
@@ -24,7 +24,7 @@
~ Boston, MA 02110-1301 USA
-->
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
- <!ENTITY versionNumber "3.1.0.Beta1">
+ <!ENTITY versionNumber "3.1.0.Beta2">
<!ENTITY copyrightYear "2004">
<!ENTITY copyrightHolder "Red Hat Middleware, LLC.">
]>
Modified: search/trunk/doc/reference/en/modules/getting-started.xml
===================================================================
--- search/trunk/doc/reference/en/modules/getting-started.xml 2008-10-23 15:48:18 UTC (rev 15383)
+++ search/trunk/doc/reference/en/modules/getting-started.xml 2008-10-24 10:25:33 UTC (rev 15384)
@@ -298,7 +298,7 @@
details see <xref linkend="search-mapping-bridge" />.</para>
<para>This leaves us with <literal>@IndexedEmbedded. </literal>This
- annotation is used to indexed associated entities
+ annotation is used to index associated entities
(<literal>@ManyToMany</literal>, <literal>@*ToOne</literal> and
<literal>@Embedded</literal>) as part of the owning entity. This is needed
since a Lucene index document is a flat data structure which does not know
Modified: search/trunk/doc/reference/en/modules/mapping.xml
===================================================================
--- search/trunk/doc/reference/en/modules/mapping.xml 2008-10-23 15:48:18 UTC (rev 15383)
+++ search/trunk/doc/reference/en/modules/mapping.xml 2008-10-24 10:25:33 UTC (rev 15384)
@@ -446,21 +446,21 @@
feature richness.</para>
<para><note>
- <para>An associated object can itself be (but don't have to)
+ <para>An associated object can itself (but does not have to) be
<literal>@Indexed</literal></para>
</note></para>
<para>When @IndexedEmbedded points to an entity, the association has to
be directional and the other side has to be annotated
- <literal>@ContainedIn</literal> (as see in the previous example). If
+ <literal>@ContainedIn</literal> (as seen in the previous example). If
not, Hibernate Search has no way to update the root index when the
- associated entity is updated (in ou example, a <literal>Place</literal>
+ associated entity is updated (in our example, a <literal>Place</literal>
index document has to be updated when the associated
- <classname>Address</classname> instance is updated.</para>
+ <classname>Address</classname> instance is updated).</para>
<para>Sometimes, the object type annotated by
<classname>@IndexedEmbedded</classname> is not the object type targeted
- by Hibernate and Hibernate Search especially when interface are used in
+ by Hibernate and Hibernate Search especially when interfaces are used in
lieu of their implementation. You can override the object type targeted
by Hibernate Search using the <methodname>targetElement</methodname>
parameter.</para>
@@ -491,8 +491,8 @@
<section>
<title>Boost factor</title>
- <para>Lucene has the notion of <emphasis>boost factor</emphasis> . It's
- a way to give more weigth to a field or to an indexed element over an
+ <para>Lucene has the notion of <emphasis>boost factor</emphasis>. It's a
+ way to give more weigth to a field or to an indexed element over an
other during the indexation process. You can use
<literal>@Boost</literal> at the field or the class level.</para>
Modified: search/trunk/ivy.xml
===================================================================
--- search/trunk/ivy.xml 2008-10-23 15:48:18 UTC (rev 15383)
+++ search/trunk/ivy.xml 2008-10-24 10:25:33 UTC (rev 15384)
@@ -44,6 +44,7 @@
<dependency org="hsqldb" name="hsqldb" rev="1.8.0.2" conf="test->default"/>
<dependency org="postgresql" name="postgresql" rev="8.3-603.jdbc3" conf="test->default"/>
<dependency org="mysql" name="mysql-connector-java" rev="5.1.6" conf="test->default"/>
+ <dependency org="org.apache.derby" name="derby" rev="10.2.1.6" conf="test->default"/>
</dependencies>
</ivy-module>
\ No newline at end of file
Modified: search/trunk/readme.txt
===================================================================
--- search/trunk/readme.txt 2008-10-23 15:48:18 UTC (rev 15383)
+++ search/trunk/readme.txt 2008-10-24 10:25:33 UTC (rev 15384)
@@ -1,6 +1,6 @@
Hibernate Search
==================================================
-Version: 3.1.0.Beta1, 17.07.2008
+Version: 3.1.0.Beta2, 27.10.2008
Description
-----------
Copied: search/trunk/src/filters/derby.filter (from rev 15383, search/trunk/src/filters/mysql.filter)
===================================================================
--- search/trunk/src/filters/derby.filter (rev 0)
+++ search/trunk/src/filters/derby.filter 2008-10-24 10:25:33 UTC (rev 15384)
@@ -0,0 +1,7 @@
+## Derby
+
+hibernate.dialect org.hibernate.dialect.DerbyDialect
+hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver
+hibernate.connection.url jdbc:derby:hibernate;create=true
+hibernate.connection.username hibernate
+hibernate.connection.password hibernate
Property changes on: search/trunk/src/filters/derby.filter
___________________________________________________________________
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
17 years, 6 months
Hibernate SVN: r15383 - in validator/trunk: hibernate-validator/src/main/java/org/hibernate/validation/engine and 7 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-10-23 11:48:18 -0400 (Thu, 23 Oct 2008)
New Revision: 15383
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNull.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNullConstraint.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintFactoryImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Address.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Animal.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Author.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Book.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Boy.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Dictonary.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Order.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Person.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageResolverTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java
validator/trunk/validation-api/src/main/java/javax/validation/ConstraintFactory.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java
validator/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java
Log:
* Started to implement BVAL-31
* Removed org.hibernate.validator.constraint.NotNull
* Javadoc changes
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNull.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNull.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNull.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -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 java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Target;
-import javax.validation.ConstraintValidator;
-
-/**
- * @author Emmanuel Bernard
- */
-@Documented
-(a)ConstraintValidator(NotNullConstraint.class)
-@Target({ METHOD, FIELD })
-@Retention(RUNTIME)
-public @interface NotNull {
- public abstract String message() default "{validator.notNull}";
-
- public abstract String[] groups() default { };
-}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNullConstraint.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNullConstraint.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotNullConstraint.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -19,6 +19,7 @@
import javax.validation.Constraint;
import javax.validation.Context;
+import javax.validation.constraints.NotNull;
/**
* Validate that the object is not <code>null</code>.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -247,20 +247,31 @@
constraintCandidates.addAll( Arrays.asList( annotations ) );
for ( Annotation constraintCandiate : constraintCandidates ) {
- ConstraintValidator constraintValidator = constraintCandiate.annotationType()
- .getAnnotation( ConstraintValidator.class );
- if ( constraintValidator != null ) {
- final ConstraintDescriptorImpl constraintDescriptor = buildConstraintDescriptor( constraintCandiate );
+
+ if ( ReflectionHelper.isBuiltInConstraintAnnotation( constraintCandiate ) ) {
+ Class constraintClass = ReflectionHelper.getBuiltInConstraint( constraintCandiate );
+ final ConstraintDescriptorImpl constraintDescriptor = buildConstraintDescriptor(
+ constraintCandiate, constraintClass
+ );
constraintDescriptors.add( constraintDescriptor );
+ continue;
}
+
+ if ( ReflectionHelper.isConstraintAnnotation( constraintCandiate ) ) {
+ ConstraintValidator constraintValidator = constraintCandiate.annotationType()
+ .getAnnotation( ConstraintValidator.class );
+ final ConstraintDescriptorImpl constraintDescriptor = buildConstraintDescriptor(
+ constraintCandiate, constraintValidator.value()
+ );
+ constraintDescriptors.add( constraintDescriptor );
+ }
}
return constraintDescriptors;
}
@SuppressWarnings("unchecked")
- private <A extends Annotation> ConstraintDescriptorImpl buildConstraintDescriptor(A annotation) {
- getMessage( annotation ); // called to make sure there is a message
- String[] groups = getGroups( annotation );
+ private <A extends Annotation> ConstraintDescriptorImpl buildConstraintDescriptor(A annotation, Class constraintClass) {
+ String[] groups = ReflectionHelper.getAnnotationParameter( annotation, "groups", String[].class );
for ( String groupName : groups ) {
if ( groupSequences.containsKey( groupName ) ) {
throw new ValidationException( groupName + " is illegally used as group and sequence name." );
@@ -268,52 +279,24 @@
}
Constraint<A> constraint;
- ConstraintValidator constraintValidator = annotation.annotationType()
- .getAnnotation( ConstraintValidator.class );
try {
//unchecked
- constraint = constraintFactory.getInstance( constraintValidator.value() );
+ constraint = constraintFactory.getInstance( constraintClass );
}
catch ( RuntimeException e ) {
- throw new ValidationException( "Unable to instantiate " + constraintValidator.value(), e );
+ throw new ValidationException( "Unable to instantiate " + constraintClass, e );
}
try {
constraint.initialize( annotation );
}
catch ( RuntimeException e ) {
- throw new ValidationException( "Unable to intialize " + constraintValidator.value(), e );
+ throw new ValidationException( "Unable to intialize " + constraint.getClass().getName(), e );
}
- return new ConstraintDescriptorImpl( annotation, groups, constraint, constraintValidator.value() );
+ return new ConstraintDescriptorImpl( annotation, groups, constraint, constraintClass );
}
- private <A extends Annotation> String getMessage(A annotation) {
- try {
- Method m = annotation.getClass().getMethod( "message" );
- return ( String ) m.invoke( annotation );
- }
- catch ( NoSuchMethodException e ) {
- throw new ValidationException( "Constraint annotation has to define message element." );
- }
- catch ( Exception e ) {
- throw new ValidationException( "Unable to get message from " + annotation.getClass().getName() );
- }
- }
-
- private <A extends Annotation> String[] getGroups(A annotation) {
- try {
- Method m = annotation.getClass().getMethod( "groups" );
- return ( String[] ) m.invoke( annotation );
- }
- catch ( NoSuchMethodException e ) {
- throw new ValidationException( "Constraint annotation has to define groups element." );
- }
- catch ( Exception e ) {
- throw new ValidationException( "Unable to get groups from " + annotation.getClass().getName() );
- }
- }
-
/**
* Checks whether the given annotation has a value parameter which returns an array of annotations.
*
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintFactoryImpl.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintFactoryImpl.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -27,6 +27,10 @@
* @author Emmanuel Bernard
*/
public class ConstraintFactoryImpl implements ConstraintFactory {
+
+ /**
+ * {@inheritDoc}
+ */
public <T extends Constraint> T getInstance(Class<T> key) {
try {
return key.newInstance();
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -18,6 +18,7 @@
package org.hibernate.validation.util;
import java.beans.Introspector;
+import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
@@ -28,13 +29,17 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
+import java.util.Arrays;
import java.util.Collection;
-import java.util.Map;
import java.util.Iterator;
-import java.util.Arrays;
import java.util.List;
+import java.util.Map;
+import javax.validation.ConstraintValidator;
import javax.validation.ValidationException;
+import javax.validation.constraints.NotNull;
+import org.hibernate.validation.constraints.NotNullConstraint;
+
/**
* Some reflection utility methods.
*
@@ -42,10 +47,91 @@
*/
public class ReflectionHelper {
+ /**
+ * Private constructor in order to avoid instantiation.
+ */
private ReflectionHelper() {
}
+
/**
+ * @todo Maybe move into another class
+ * @todo Read mappings for example from a resource file
+ */
+ public static Class getBuiltInConstraint(Annotation annotation) {
+ if ( annotation instanceof NotNull ) {
+ return NotNullConstraint.class;
+ }
+ else {
+ return null;
+ }
+ }
+
+ public static boolean isBuiltInConstraintAnnotation(Annotation annotation) {
+ boolean isBuiltInConstraintAnnotation = false;
+
+ String packageName = annotation.annotationType().getPackage().getName();
+ if ( "javax.validation.constraints".equals( packageName ) ) {
+ isBuiltInConstraintAnnotation = true;
+ }
+ return isBuiltInConstraintAnnotation;
+ }
+
+ public static boolean isConstraintAnnotation(Annotation annotation) {
+ boolean isConstraintAnnotation = true;
+
+ ConstraintValidator constraintValidator = annotation.annotationType()
+ .getAnnotation( ConstraintValidator.class );
+ if ( constraintValidator == null ) {
+ isConstraintAnnotation = false;
+ return isConstraintAnnotation;
+ }
+
+ try {
+ getAnnotationParameter( annotation, "message", String.class );
+ } catch ( Exception e ) {
+ throw new ValidationException( "Constraint annotation has to define message element." );
+ }
+
+ try {
+ getAnnotationParameter( annotation, "groups", String[].class );
+ }
+ catch ( Exception e ) {
+ throw new ValidationException( "Constraint annotation has to define groups element." );
+ }
+
+ return isConstraintAnnotation;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public static <T> T getAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) {
+ try {
+ Method m = annotation.getClass().getMethod( parameterName );
+ Object o = m.invoke( annotation );
+ if ( o.getClass().getName().equals( type.getName() ) ) {
+ return ( T ) o;
+ }
+ else {
+ String msg = "Wrong parameter type. Expected: " + type.getName() + " Actual: " + o.getClass().getName();
+ throw new ValidationException( msg );
+ }
+ }
+ catch ( NoSuchMethodException e ) {
+ String msg = "The specified annotation defines no parameter '" + parameterName + "'.";
+ throw new ValidationException( msg, e );
+ }
+ catch ( IllegalAccessException e ) {
+ String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName();
+ throw new ValidationException( msg, e );
+ }
+ catch ( InvocationTargetException e ) {
+ String msg = "Unable to get '" + parameterName + "' from " + annotation.getClass().getName();
+ throw new ValidationException( msg, e );
+ }
+ }
+
+ /**
* Process bean properties getter by applying the JavaBean naming conventions.
*
* @param member the member for which to get the property name.
@@ -233,20 +319,20 @@
* @return <code>true</code> is <code>clazz</code> is instance of a collection class, <code>false</code> otherwise.
*/
private static boolean isCollectionClass(Class<?> clazz) {
- Class[] interfaces = clazz.getInterfaces();
+ Class[] interfaces = clazz.getInterfaces();
- for ( Class interfaceClass : interfaces) {
- if (interfaceClass == Collection.class
- || interfaceClass == java.util.List.class
- || interfaceClass == java.util.Set.class
- || interfaceClass == java.util.Map.class
- || interfaceClass == java.util.SortedSet.class // extension to the specs
- || interfaceClass == java.util.SortedMap.class) { // extension to the specs)
- return true;
- }
- }
+ for ( Class interfaceClass : interfaces ) {
+ if ( interfaceClass == Collection.class
+ || interfaceClass == java.util.List.class
+ || interfaceClass == java.util.Set.class
+ || interfaceClass == java.util.Map.class
+ || interfaceClass == java.util.SortedSet.class // extension to the specs
+ || interfaceClass == java.util.SortedMap.class ) { // extension to the specs)
+ return true;
+ }
+ }
- return false;
+ return false;
}
/**
@@ -256,8 +342,9 @@
* either a collection or array.
* @param index The index. The index does not have to be numerical. <code>value</code> could also be a map in which
* case the index could also be a string key.
+ *
* @return The indexed value or <code>null</code> if <code>value</code> is <code>null</code> or not a collection or array.
- * <code>null</code> is also returned in case the index does not exist.
+ * <code>null</code> is also returned in case the index does not exist.
*/
public static Object getIndexedValue(Object value, String index) {
if ( value == null ) {
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Address.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Address.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Address.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -17,8 +17,9 @@
*/
package org.hibernate.validation.eg;
+import javax.validation.constraints.NotNull;
+
import org.hibernate.validation.constraints.Length;
-import org.hibernate.validation.constraints.NotNull;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Animal.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Animal.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Animal.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -17,8 +17,9 @@
*/
package org.hibernate.validation.eg;
+import javax.validation.constraints.NotNull;
+
import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.constraints.NotNull;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Author.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Author.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Author.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -17,9 +17,10 @@
*/
package org.hibernate.validation.eg;
+import javax.validation.constraints.NotNull;
+
import org.hibernate.validation.constraints.Length;
import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.constraints.NotNull;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Book.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Book.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Book.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -19,10 +19,10 @@
import javax.validation.GroupSequence;
import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
import org.hibernate.validation.constraints.Length;
import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.constraints.NotNull;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Boy.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Boy.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Boy.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -17,8 +17,9 @@
*/
package org.hibernate.validation.eg;
-import org.hibernate.validation.constraints.NotNull;
+import javax.validation.constraints.NotNull;
+
/**
* @author Hardy Ferentschik
*/
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Dictonary.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Dictonary.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Dictonary.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -19,9 +19,9 @@
import javax.validation.GroupSequence;
import javax.validation.GroupSequences;
+import javax.validation.constraints.NotNull;
import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.constraints.NotNull;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Order.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Order.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Order.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -17,7 +17,7 @@
*/
package org.hibernate.validation.eg;
-import org.hibernate.validation.constraints.NotNull;
+import javax.validation.constraints.NotNull;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Person.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Person.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Person.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -17,8 +17,9 @@
*/
package org.hibernate.validation.eg;
+import javax.validation.constraints.NotNull;
+
import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.constraints.NotNull;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageResolverTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageResolverTest.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageResolverTest.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -24,16 +24,14 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.ResourceBundle;
+import javax.validation.constraints.NotNull;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
-import org.slf4j.Logger;
import org.hibernate.validation.constraints.Length;
-import org.hibernate.validation.constraints.NotNull;
import org.hibernate.validation.constraints.NotNullConstraint;
-import org.hibernate.validation.util.LoggerFactory;
/**
* Tests for message resolution.
@@ -41,7 +39,6 @@
* @author Hardy Ferentschik
*/
public class ResourceBundleMessageResolverTest {
- private static final Logger log = LoggerFactory.make();
private ResourceBundleMessageResolver resolver;
private NotNull notNull;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -17,16 +17,24 @@
*/
package org.hibernate.validation.util;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
+import javax.validation.ValidationException;
+import javax.validation.constraints.NotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.junit.Test;
/**
+ * Tests for the <code>ReflectionHelper</code>.
+ *
* @author Hardy Ferentschik
*/
public class ReflectionHelperTest {
@@ -41,14 +49,14 @@
assertEquals( "We should be able to retrieve the indexed object", testObject, value );
// try to get to the value by integer index
- value = ReflectionHelper.getIndexedValue( map, "0" );
+ value = ReflectionHelper.getIndexedValue( map, "0" );
assertEquals( "We should be able to retrieve the indexed object", testObject, value );
value = ReflectionHelper.getIndexedValue( map, "foo" );
- assertNull("A non existent index should return the null value", value);
+ assertNull( "A non existent index should return the null value", value );
value = ReflectionHelper.getIndexedValue( map, "2" );
- assertNull("A non existent index should return the null value", value);
+ assertNull( "A non existent index should return the null value", value );
}
@Test
@@ -61,7 +69,7 @@
assertEquals( "We should be able to retrieve the indexed object", testObject, value );
value = ReflectionHelper.getIndexedValue( list, "2" );
- assertNull("A non existent index should return the null value", value);
+ assertNull( "A non existent index should return the null value", value );
}
@Test
@@ -69,4 +77,42 @@
Object value = ReflectionHelper.getIndexedValue( null, "0" );
assertNull( value );
}
+
+ @Test
+ public void testGetMessageParamter() {
+ NotNull testAnnotation = new NotNull() {
+ public String message() {
+ return "test";
+ }
+
+ public String[] groups() {
+ return new String[] { "default" };
+ }
+
+ public Class<? extends Annotation> annotationType() {
+ return this.getClass();
+ }
+ };
+ String message = ReflectionHelper.getAnnotationParameter( testAnnotation, "message", String.class );
+ assertEquals( "Wrong message", "test", message );
+
+ String[] group = ReflectionHelper.getAnnotationParameter( testAnnotation, "groups", String[].class );
+ assertEquals( "Wrong message", "default", group[0] );
+
+ try {
+ ReflectionHelper.getAnnotationParameter( testAnnotation, "message", Integer.class );
+ fail();
+ }
+ catch ( ValidationException e ) {
+ assertTrue( "Wrong exception message", e.getMessage().startsWith( "Wrong parameter type." ) );
+ }
+
+ try {
+ ReflectionHelper.getAnnotationParameter( testAnnotation, "foo", Integer.class );
+ fail();
+ }
+ catch ( ValidationException e ) {
+ assertTrue( "Wrong exception message", e.getMessage().startsWith( "The specified annotation defines no parameter" ) );
+ }
+ }
}
Modified: validator/trunk/validation-api/src/main/java/javax/validation/ConstraintFactory.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/ConstraintFactory.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/ConstraintFactory.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -18,8 +18,8 @@
package javax.validation;
/**
- * Instantiate a Constraint from it's class.
- * The ConstraintFactory is <b>not</b> responsible for calling Constraint#initialize
+ * Instantiate a <code>Constraint</code> instance from its class.
+ * The <code>ConstraintFactory</code> is <b>not</b> responsible for calling {@link Constraint#initialize(java.lang.annotation.Annotation)}.
*
* @author Dhanji R. Prasanna
* @author Emmanuel Bernard
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,25 +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 javax.validation.constraints;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
/**
* The annotated element must be false.
* Supported types are <code>boolean</code> and <code>Boolean</code>
+ * <p/>
+ * <code>null</code> elements are considered valid.
*
- * Null elements are considered valid
- *
* @author Emmanuel Bernard
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
public @interface AssertFalse {
- String message() default "{constraint.assertFalse}";
- String[] groups() default {};
+ String message() default "{validator.assertFalse}";
+
+ String[] groups() default { };
}
\ No newline at end of file
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,25 +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 javax.validation.constraints;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
/**
* The annotated element must be true.
- * Supported types are <code>boolean</code> and <code>Boolean</code>
+ * Supported types are <code>boolean</code> and <code>Boolean</code>
+ * <p/>
+ * <code>null</code> elements are considered valid.
*
- * Null elements are considered valid
- *
* @author Emmanuel Bernard
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
public @interface AssertTrue {
- String message() default "{constraint.assertTrue}";
- String[] groups() default {};
+ String message() default "{validator.assertTrue}";
+
+ String[] groups() default { };
}
\ No newline at end of file
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,34 +1,55 @@
+// $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 javax.validation.constraints;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
/**
* The annotated element must be a number within accepted range
* Supported types are:
- * - <code>BigDecimal</code>
- * - <code>BigInteger</code>
- * - <code>Number</code>
- * - <code>String</code> (TODO should we keep it?)
- * - <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, <code>double</code>
- * TODO <code>byte</code>
+ * <ul>
+ * <li><code>BigDecimal</code></li>
+ * <li><code>BigInteger</code></li>
+ * <li><code>Number</code></li>
+ * <li><code>String</code></li>
+ * <li><code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, <code>double</code></li>
+ * </ul>
+ * <p/>
+ * <code>null</code> elements are considered valid
*
- * Null elements are considered valid
- *
* @author Emmanuel Bernard
+ * @todo support byte ?!
+ * @todo Is string supported or not?
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
public @interface Digits {
- String message() default "{constraint.digits}";
- String[] groups() default {};
+ String message() default "{validator.digits}";
+ String[] groups() default { };
+
/**
* @return maximum number of integral digits accepted for this number
*/
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,34 +1,54 @@
+// $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 javax.validation.constraints;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
/**
* The annotated element must be a date in the future.
* Now is defined as the current time according to the virtual machine
* The calendar used if the compared type is of type <code>Calendar</code>
* is the calendar based on the current timezone and the current locale.
- *
+ * <p/>
* TODO what are the implications
- *
+ * <p/>
* Supported types are:
- * - <code>java.util.Date</code>
- * - <code>java.util.Calendar</code>
- * - TODO new date/time JSR types?
+ * <ul>
+ * <li><code>java.util.Date</code></li>
+ * <li><code>java.util.Calendar</code></li>
+ * </ul>
+ * - TODO new date/time JSR types?
+ * <p/>
+ * <code>null</code> elements are considered valid.
*
- * Null elements are considered valid
- *
* @author Emmanuel Bernard
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
public @interface Future {
- String message() default "{constraint.future}";
- String[] groups() default {};
+ String message() default "{validator.future}";
+
+ String[] groups() default { };
}
\ No newline at end of file
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,36 +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 javax.validation.constraints;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
/**
* The annotated element must be a number whose value must be lower or
* equal than the specificed maximum.
- *
+ * <p/>
* Supported types are:
- * - <code>BigDecimal</code>
- * - <code>BigInteger</code>
- * - <code>Number</code>
- * - <code>String</code> (TODO should we keep it?)
- * - <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, <code>double</code>
- * TODO <code>byte</code>
+ * <ul>
+ * <li><code>BigDecimal</code></li>
+ * <li><code>BigInteger</code></li>
+ * <li><code>Number</code></li>
+ * <li><code>String</code></li>
+ * <li><code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, <code>double</code></li>
+ * </ul>
+ * <p/>
+ * <code>null</code> elements are considered valid
*
- * Null elements are considered valid
- *
* @author Emmanuel Bernard
+ * @todo support byte ?!
+ * @todo Is string supported or not?
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
public @interface Max {
- String message() default "{constraint.max}";
- String[] groups() default {};
+ String message() default "{validator.max}";
+ String[] groups() default { };
+
/**
* @return Value the element must be lower or equal to
*/
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,36 +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 javax.validation.constraints;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
/**
* The annotated element must be a number whose value must be greater or
* equal than the specificed minimum
- *
+ * <p/>
* Supported types are:
- * - <code>BigDecimal</code>
- * - <code>BigInteger</code>
- * - <code>Number</code>
- * - <code>String</code> (TODO should we keep it?)
- * - <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, <code>double</code>
- * TODO <code>byte</code>
+ * <ul>
+ * <li><code>BigDecimal</code></li>
+ * <li><code>BigInteger</code></li>
+ * <li><code>Number</code></li>
+ * <li><code>String</code></li>
+ * <li><code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, <code>double</code></li>
+ * </ul>
+ * <p/>
+ * <code>null</code> elements are considered valid
*
- * Null elements are considered valid
- *
* @author Emmanuel Bernard
+ * @todo support byte ?!
+ * @todo Is string supported or not?
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
public @interface Min {
- String message() default "{constraint.min}";
- String[] groups() default {};
+ String message() default "{validator.min}";
+ String[] groups() default { };
+
/**
* @return Value the element must be higher or equal to
*/
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,15 +1,32 @@
+// $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 javax.validation.constraints;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
/**
- * The annotated element must not be null.
+ * The annotated element must not be <code>null</code>.
* Accepts any type.
*
* @author Emmanuel Bernard
@@ -18,6 +35,7 @@
@Retention(RUNTIME)
@Documented
public @interface NotNull {
- String message() default "{constraint.notNull}";
- String[] groups() default {};
+ String message() default "{validator.notNull}";
+
+ String[] groups() default { };
}
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,16 +1,33 @@
+// $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 javax.validation.constraints;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
/**
* The annotated element must be null.
- * Accepts any type.
+ * Accepts any type.
*
* @author Emmanuel Bernard
*/
@@ -18,7 +35,8 @@
@Retention(RUNTIME)
@Documented
public @interface Null {
- String message() default "{constraint.null}";
- String[] groups() default {};
+ String message() default "{validator.null}";
+
+ String[] groups() default { };
}
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,34 +1,54 @@
+// $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 javax.validation.constraints;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
/**
* The annotated element must be a date in the past.
* Now is defined as the current time according to the virtual machine
* The calendar used if the compared type is of type <code>Calendar</code>
* is the calendar based on the current timezone and the current locale.
- *
+ * <p/>
* TODO what are the implications
- *
+ * <p/>
* Supported types are:
- * - <code>java.util.Date</code>
- * - <code>java.util.Calendar</code>
- * - TODO new date/time JSR types?
+ * <ul>
+ * <li><code>java.util.Date</code></li>
+ * <li><code>java.util.Calendar</code></li>
+ * </ul>
+ * - TODO new date/time JSR types?
+ * <p/>
+ * <code>null</code> elements are considered valid.
*
- * Null elements are considered valid
- *
* @author Emmanuel Bernard
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
public @interface Past {
- String message() default "{constraint.past}";
- String[] groups() default {};
+ String message() default "{validator.past}";
+
+ String[] groups() default { };
}
\ No newline at end of file
Modified: validator/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java 2008-10-23 14:42:43 UTC (rev 15382)
+++ validator/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java 2008-10-23 15:48:18 UTC (rev 15383)
@@ -1,3 +1,20 @@
+// $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 javax.validation.constraints;
import java.lang.annotation.Target;
@@ -12,11 +29,12 @@
* The annotated element size must be between the specified boundaries (included).
*
* Supported types are:
- * - <code>String</code> (string length is evaludated)
- * - <code>Collection</code> (collection size is evaluated)
- * - Array (array length is evaludated)
+ * <ul>
+ * <li><code>String</code> (string length is evaludated)</li>
+ * <li><code>Collection</code> (collection size is evaluated)</li>
+ * <li>Array (array length is evaludated)</li>
*
- * Null elements are considered valid
+ * <code>null</code> elements are considered valid.
*
* @author Emmanuel Bernard
*/
@@ -24,7 +42,7 @@
@Retention(RUNTIME)
@Documented
public @interface Size {
- String message() default "{constraint.min}";
+ String message() default "{validator.min}";
String[] groups() default {};
/**
17 years, 6 months
Hibernate SVN: r15382 - in search/trunk: src/java/org/hibernate/search/reader and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2008-10-23 10:42:43 -0400 (Thu, 23 Oct 2008)
New Revision: 15382
Modified:
search/trunk/doc/reference/en/modules/architecture.xml
search/trunk/doc/reference/en/modules/configuration.xml
search/trunk/src/java/org/hibernate/search/reader/ReaderProviderFactory.java
search/trunk/src/java/org/hibernate/search/reader/SharedReaderProvider.java
search/trunk/src/java/org/hibernate/search/reader/SharingBufferReaderProvider.java
search/trunk/src/test/org/hibernate/search/test/reader/SharedBufferedReaderPerfTest.java
search/trunk/src/test/org/hibernate/search/test/reader/SharedReaderPerfTest.java
Log:
HSEARCH-279 : deprecate SharedReaderProvider replaced by SharingBufferReaderProvider as default ReaderProvider
Modified: search/trunk/doc/reference/en/modules/architecture.xml
===================================================================
--- search/trunk/doc/reference/en/modules/architecture.xml 2008-10-23 10:55:33 UTC (rev 15381)
+++ search/trunk/doc/reference/en/modules/architecture.xml 2008-10-23 14:42:43 UTC (rev 15382)
@@ -228,22 +228,14 @@
multiple queries and threads provided that the
<classname>IndexReader</classname> is still up-to-date. If the
<classname>IndexReader</classname> is not up-to-date, a new one is
- opened and provided. Generally speaking, </para>
- </section>
-
- <section>
- <title>Shared Segments</title>
-
- <para>This strategies goes a step further the shared strategy and tries
- to minimize reopening even when the underlying index has changed. Each
+ opened and provided. Each
<classname>IndexReader</classname> is made of several
<classname>SegmentReader</classname>s. This strategy only reopens
- segments that have been modified or created and shared the already
- loaded segments. This strategy will become the default strategy in the
- near future.</para>
-
- <para>The name of this strategy is
- <literal>shared-segments</literal>.</para>
+ segments that have been modified or created after last opening and
+ shares the already loaded segments from the previous instance.
+ This strategy is the default.</para>
+
+ <para>The name of this strategy is <literal>shared</literal>.</para>
</section>
<section>
Modified: search/trunk/doc/reference/en/modules/configuration.xml
===================================================================
--- search/trunk/doc/reference/en/modules/configuration.xml 2008-10-23 10:55:33 UTC (rev 15381)
+++ search/trunk/doc/reference/en/modules/configuration.xml 2008-10-23 14:42:43 UTC (rev 15382)
@@ -471,16 +471,10 @@
<itemizedlist>
<listitem>
<para><literal>shared</literal>: share index readers across several
- queries</para>
+ queries. This strategy is the most efficient.</para>
</listitem>
<listitem>
- <para><literal>shared-segments</literal>: index readers are shared
- across several queries and when reopening is needed, the inchanged
- state is shared. This strategy is the most efficient.</para>
- </listitem>
-
- <listitem>
<para><literal>not-shared</literal>: create an index reader for each
individual query</para>
</listitem>
@@ -491,7 +485,7 @@
<programlisting>hibernate.search.reader.strategy = not-shared</programlisting>
- <para>Adding this property switch to the <literal>not-shared</literal>
+ <para>Adding this property switches to the <literal>not-shared</literal>
strategy.</para>
<para>Or if you have a custom reader strategy:</para>
Modified: search/trunk/src/java/org/hibernate/search/reader/ReaderProviderFactory.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/reader/ReaderProviderFactory.java 2008-10-23 10:55:33 UTC (rev 15381)
+++ search/trunk/src/java/org/hibernate/search/reader/ReaderProviderFactory.java 2008-10-23 14:42:43 UTC (rev 15382)
@@ -34,14 +34,15 @@
ReaderProvider readerProvider;
if ( StringHelper.isEmpty( impl ) ) {
//put another one
- readerProvider = new SharedReaderProvider();
+ readerProvider = new SharingBufferReaderProvider();
}
else if ( "not-shared".equalsIgnoreCase( impl ) ) {
readerProvider = new NotSharedReaderProvider();
}
else if ( "shared".equalsIgnoreCase( impl ) ) {
- readerProvider = new SharedReaderProvider();
+ readerProvider = new SharingBufferReaderProvider();
}
+ //will remove next "else":
else if ( "shared-segments".equalsIgnoreCase( impl ) ) {
readerProvider = new SharingBufferReaderProvider();
}
Modified: search/trunk/src/java/org/hibernate/search/reader/SharedReaderProvider.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/reader/SharedReaderProvider.java 2008-10-23 10:55:33 UTC (rev 15381)
+++ search/trunk/src/java/org/hibernate/search/reader/SharedReaderProvider.java 2008-10-23 14:42:43 UTC (rev 15382)
@@ -24,9 +24,10 @@
/**
* Share readers per SearchFactory, reusing them iff they are still valid.
- *
+ * @Deprecated replaced by SharingBufferReaderProvider
* @author Emmanuel Bernard
*/
+@Deprecated
public class SharedReaderProvider implements ReaderProvider {
private static final Logger log = LoggerFactory.make();
Modified: search/trunk/src/java/org/hibernate/search/reader/SharingBufferReaderProvider.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/reader/SharingBufferReaderProvider.java 2008-10-23 10:55:33 UTC (rev 15381)
+++ search/trunk/src/java/org/hibernate/search/reader/SharingBufferReaderProvider.java 2008-10-23 14:42:43 UTC (rev 15382)
@@ -23,11 +23,10 @@
import org.hibernate.search.util.LoggerFactory;
/**
- * As does SharedReaderProvider this also shares IndexReaders as long as they are "current";
+ * This ReaderProvider shares IndexReaders as long as they are "current";
* main difference with SharedReaderProvider is the way to update the Readers when needed:
* this uses IndexReader.reopen() which should improve performance on larger indexes
* as it shares buffers with previous IndexReader generation for the segments which didn't change.
- * Current drawbacks are: need of Lucene > 2.3.0 and less mature (experimental).
*
* @author Sanne Grinovero
*/
Modified: search/trunk/src/test/org/hibernate/search/test/reader/SharedBufferedReaderPerfTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/reader/SharedBufferedReaderPerfTest.java 2008-10-23 10:55:33 UTC (rev 15381)
+++ search/trunk/src/test/org/hibernate/search/test/reader/SharedBufferedReaderPerfTest.java 2008-10-23 14:42:43 UTC (rev 15382)
@@ -3,6 +3,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.search.Environment;
+import org.hibernate.search.reader.SharingBufferReaderProvider;
/**
* @author Emmanuel Bernard
@@ -10,6 +11,6 @@
public class SharedBufferedReaderPerfTest extends ReaderPerfTestCase {
protected void configure(Configuration cfg) {
super.configure( cfg );
- cfg.setProperty( Environment.READER_STRATEGY, "shared-segments" );
+ cfg.setProperty( Environment.READER_STRATEGY, SharingBufferReaderProvider.class.getCanonicalName() );
}
}
\ No newline at end of file
Modified: search/trunk/src/test/org/hibernate/search/test/reader/SharedReaderPerfTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/reader/SharedReaderPerfTest.java 2008-10-23 10:55:33 UTC (rev 15381)
+++ search/trunk/src/test/org/hibernate/search/test/reader/SharedReaderPerfTest.java 2008-10-23 14:42:43 UTC (rev 15382)
@@ -3,13 +3,15 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.search.Environment;
+import org.hibernate.search.reader.SharedReaderProvider;
/**
* @author Emmanuel Bernard
*/
+@SuppressWarnings("deprecation")
public class SharedReaderPerfTest extends ReaderPerfTestCase {
protected void configure(Configuration cfg) {
super.configure( cfg );
- cfg.setProperty( Environment.READER_STRATEGY, "shared" );
+ cfg.setProperty( Environment.READER_STRATEGY, SharedReaderProvider.class.getCanonicalName() );
}
}
17 years, 6 months
Hibernate SVN: r15381 - search/trunk/src/java/org/hibernate/search/backend/impl/lucene.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2008-10-23 06:55:33 -0400 (Thu, 23 Oct 2008)
New Revision: 15381
Modified:
search/trunk/src/java/org/hibernate/search/backend/impl/lucene/IndexInteractionType.java
search/trunk/src/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
Log:
make sure HSEARCH-222 is solved, even in case new LuceneWorkDelegates are created (removed dangerous constant "NEED_INDEXREADER").
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/lucene/IndexInteractionType.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/lucene/IndexInteractionType.java 2008-10-23 09:33:14 UTC (rev 15380)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/lucene/IndexInteractionType.java 2008-10-23 10:55:33 UTC (rev 15381)
@@ -1,25 +1,29 @@
package org.hibernate.search.backend.impl.lucene;
/**
+ * Constants to make the LuceneWorkDelegates advertise the type
+ * of resource they are going to need to perform the work.
+ *
+ * NEEDS_INDEXREADER is missing to make sure there always is an optimal
+ * solution, as some operations can be done both through an IndexReader
+ * and an IndexWriter, but as of Lucene 2.4 there are no operations which
+ * can't be done using an IndexWriter.
+ *
* @author Sanne Grinovero
*/
public enum IndexInteractionType {
/**
- * means the workType needs an IndexWriter.
+ * The workType needs an IndexWriter.
*/
NEEDS_INDEXWRITER,
/**
- * means the workType needs an IndexReader.
- */
- NEEDS_INDEXREADER,
- /**
- * means an IndexWriter should work best but it's possible
+ * An IndexWriter should work best but it's possible
* to use an IndexReader instead.
*/
PREFER_INDEXWRITER,
/**
- * means an IndexReader should work best but it's possible
+ * An IndexReader should work best but it's possible
* to use an IndexWriter instead.
*/
PREFER_INDEXREADER
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2008-10-23 09:33:14 UTC (rev 15380)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2008-10-23 10:55:33 UTC (rev 15381)
@@ -26,7 +26,6 @@
// if any work passed to addWork needs one, set corresponding flag to true:
private boolean batchmode = false;
- private boolean needsReader = false;
private boolean needsWriter = false;
private boolean preferReader = false;
@@ -42,9 +41,6 @@
}
IndexInteractionType type = work.getWorkDelegate( worker ).getIndexInteractionType();
switch ( type ) {
- case NEEDS_INDEXREADER :
- needsReader = true;
- //fall through:
case PREFER_INDEXREADER :
preferReader = true;
workOnReader.add( work );
@@ -64,7 +60,7 @@
// skip "resource optimization mode" when in batch to have all tasks use preferred (optimal) mode.
if ( ! batchmode ) {
// see if we can skip using some resource
- if ( ! needsReader && ! needsWriter ) { // no specific need:
+ if ( ! needsWriter ) { // no specific need:
if ( preferReader ) {
useReaderOnly();
}
@@ -72,12 +68,13 @@
useWriterOnly();
}
}
- else if ( needsReader && !needsWriter ) {
- useReaderOnly();
- }
- else if ( !needsReader && needsWriter ) {
+ else {
useWriterOnly();
}
+ if ( ! (workOnWriter.isEmpty() || workOnReader.isEmpty() ) ) {
+ throw new AssertionFailure(
+ "During non-batch mode performWorks tries to use both IndexWriter and IndexReader." );
+ }
}
// apply changes to index:
log.trace( "Locking Workspace (or waiting to...)" );
@@ -116,7 +113,6 @@
finally {
workspace.closeIndexWriter();
}
-
}
/**
17 years, 6 months
Hibernate SVN: r15380 - annotations/trunk/src/test/org/hibernate/test/annotations/generics.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2008-10-23 05:33:14 -0400 (Thu, 23 Oct 2008)
New Revision: 15380
Modified:
annotations/trunk/src/test/org/hibernate/test/annotations/generics/EmbeddedGenericsTest.java
Log:
ANN-778 - changed the test case to use parent's session/exception handling
Modified: annotations/trunk/src/test/org/hibernate/test/annotations/generics/EmbeddedGenericsTest.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/generics/EmbeddedGenericsTest.java 2008-10-23 08:54:17 UTC (rev 15379)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/generics/EmbeddedGenericsTest.java 2008-10-23 09:33:14 UTC (rev 15380)
@@ -28,17 +28,12 @@
public void setUp() throws Exception {
super.setUp();
- session = getSessions().openSession();
+ session = openSession();
session.getTransaction().begin();
edition = new Edition<String>();
edition.name = "Second";
}
- public void tearDown() throws Exception {
- session.close();
- super.tearDown();
- }
-
public void testWorksWithGenericEmbedded() {
Book b = new Book();
b.edition = edition;
@@ -48,6 +43,7 @@
assertEquals( "Second", retrieved.edition.name );
clean( Book.class, b.id );
+ session.close();
}
public void testWorksWithGenericCollectionOfElements() {
@@ -59,6 +55,7 @@
assertEquals( "Second", retrieved.editions.iterator().next().name );
clean( PopularBook.class, b.id );
+ session.close();
}
protected Class[] getMappings() {
17 years, 6 months
Hibernate SVN: r15379 - annotations/trunk.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-10-23 04:54:17 -0400 (Thu, 23 Oct 2008)
New Revision: 15379
Modified:
annotations/trunk/ivy.xml
Log:
added mysql and postgres driver to test dependencies
Modified: annotations/trunk/ivy.xml
===================================================================
--- annotations/trunk/ivy.xml 2008-10-23 07:58:53 UTC (rev 15378)
+++ annotations/trunk/ivy.xml 2008-10-23 08:54:17 UTC (rev 15379)
@@ -32,5 +32,8 @@
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.4.2" conf="test->default"/>
<dependency org="log4j" name="log4j" rev="1.2.14" conf="test->default"/>
<dependency org="junit" name="junit" rev="3.8.1" conf="test->default"/>
+ <dependency org="hsqldb" name="hsqldb" rev="1.8.0.2" conf="test->default"/>
+ <dependency org="postgresql" name="postgresql" rev="8.3-603.jdbc3" conf="test->default"/>
+ <dependency org="mysql" name="mysql-connector-java" rev="5.1.6" conf="test->default"/>
</dependencies>
</ivy-module>
\ No newline at end of file
17 years, 6 months
Hibernate SVN: r15378 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-10-23 03:58:53 -0400 (Thu, 23 Oct 2008)
New Revision: 15378
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorMetaData.java
Log:
renamed to MetaConstraint
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorMetaData.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorMetaData.java 2008-10-23 07:57:41 UTC (rev 15377)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorMetaData.java 2008-10-23 07:58:53 UTC (rev 15378)
@@ -1,188 +0,0 @@
-// $Id$// $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.engine;
-
-import java.lang.annotation.ElementType;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import javax.validation.ValidationException;
-
-import org.hibernate.validation.impl.ConstraintDescriptorImpl;
-import org.hibernate.validation.util.ReflectionHelper;
-
-/**
- * Instances of this class abstract the constraint type (class, method or field constraint). This allows
- * a unified handling of constraints in the validator imlpementation.
- *
- * @author Hardy Ferentschik
- */
-public class ValidatorMetaData {
-
- /**
- * The constraint specific meta data.
- */
- private final ConstraintDescriptorImpl descriptor;
-
- /**
- * The type (class) the constraint was defined on. <code>null</code> if the constraint was specified on method or
- * field level.
- */
- private final Type type;
-
- /**
- * The method the constraint was defined on. <code>null</code> if the constraint was specified on class or
- * field level.
- */
- private final Method method;
-
- /**
- * The field the constraint was defined on. <code>null</code> if the constraint was specified on class or
- * method level.
- */
- private final Field field;
-
- /**
- * The JavaBeans name for this constraint.
- */
- private final String propertyName;
-
- /**
- * Describes on which level (<code>TYPE</code>, <code>METHOD</code>, <code>FIELD</code>) the constraint was
- * defined on.
- */
- private final ElementType elementType;
-
- public ValidatorMetaData(Type t, ConstraintDescriptorImpl constraintDescriptor) {
- this.type = t;
- this.method = null;
- this.field = null;
- this.descriptor = constraintDescriptor;
- this.elementType = ElementType.TYPE;
- this.propertyName = "";
- }
-
- public ValidatorMetaData(Method m, ConstraintDescriptorImpl constraintDescriptor) {
- this.method = m;
- this.type = null;
- this.field = null;
- this.descriptor = constraintDescriptor;
- this.elementType = ElementType.METHOD;
- this.propertyName = ReflectionHelper.getPropertyName( m );
- }
-
- public ValidatorMetaData(Field f, ConstraintDescriptorImpl constraintDescriptor) {
- this.field = f;
- this.method = null;
- this.type = null;
- this.descriptor = constraintDescriptor;
- this.elementType = ElementType.FIELD;
- this.propertyName = f.getName();
- }
-
- /**
- * @param o the object from which to retrieve the value.
- *
- * @return Returns the value for this constraint from the specified object. Depending on the type either the value itself
- * is returned of method or field access is used to access the value.
- */
- public Object getValue(Object o) {
- switch ( elementType ) {
- case TYPE: {
- return o;
- }
- case METHOD: {
- return ReflectionHelper.getValue( method, o );
- }
- case FIELD: {
- return ReflectionHelper.getValue( field, o );
- }
- default: {
- throw new ValidationException(
- "Invalid state of ValidatorMetaData. Parameter elementType has unexpected value - " + elementType
- );
- }
- }
- }
-
- /**
- * @return Returns <code>true</code> in case the constraint is defined on a collection, <code>false</code>
- * otherwise.
- */
- public boolean isCollection() {
- Type t = typeOfAnnoatedElement();
- return ReflectionHelper.isCollection( t );
- }
-
- /**
- * @return Returns <code>true</code> in case the constraint is defined on an array, <code>false</code>
- * otherwise.
- */
- public boolean isArray() {
- Type t = typeOfAnnoatedElement();
- return ReflectionHelper.isArray( t );
- }
-
- public ConstraintDescriptorImpl getDescriptor() {
- return descriptor;
- }
-
- public Method getMethod() {
- return method;
- }
-
- public Field getField() {
- return field;
- }
-
- public Type getType() {
- return type;
- }
-
- public String getPropertyName() {
- return propertyName;
- }
-
- public ElementType getElementType() {
- return elementType;
- }
-
- private Type typeOfAnnoatedElement() {
- Type t;
- switch ( elementType ) {
- case TYPE: {
- t = type;
- break;
- }
- case METHOD: {
- t = ReflectionHelper.typeOf( method );
- break;
- }
- case FIELD: {
- t = ReflectionHelper.typeOf( field );
- break;
- }
- default: {
- throw new ValidationException(
- "Invalid state of ValidatorMetaData. Parameter elementType has unexpected value - " + elementType
- );
- }
- }
- return t;
- }
-}
17 years, 6 months
Hibernate SVN: r15377 - in validator/trunk: hibernate-validator/src/main/java/org/hibernate/validation/impl and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-10-23 03:57:41 -0400 (Thu, 23 Oct 2008)
New Revision: 15377
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProvider.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintDescriptorImpl.java
validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
validator/trunk/validation-api/src/main/java/javax/validation/ConstraintFactory.java
Log:
Some javadoc cleanups and refactories
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java (from rev 15369, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorMetaData.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2008-10-23 07:57:41 UTC (rev 15377)
@@ -0,0 +1,188 @@
+// $Id$// $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.engine;
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import javax.validation.ValidationException;
+
+import org.hibernate.validation.impl.ConstraintDescriptorImpl;
+import org.hibernate.validation.util.ReflectionHelper;
+
+/**
+ * Instances of this class abstract the constraint type (class, method or field constraint) and gives access to
+ * meta data about the constraint. This allows a unified handling of constraints in the validator imlpementation.
+ *
+ * @author Hardy Ferentschik
+ */
+public class MetaConstraint {
+
+ /**
+ * The constraint specific meta data.
+ */
+ private final ConstraintDescriptorImpl descriptor;
+
+ /**
+ * The type (class) the constraint was defined on. <code>null</code> if the constraint was specified on method or
+ * field level.
+ */
+ private final Type type;
+
+ /**
+ * The method the constraint was defined on. <code>null</code> if the constraint was specified on class or
+ * field level.
+ */
+ private final Method method;
+
+ /**
+ * The field the constraint was defined on. <code>null</code> if the constraint was specified on class or
+ * method level.
+ */
+ private final Field field;
+
+ /**
+ * The JavaBeans name for this constraint.
+ */
+ private final String propertyName;
+
+ /**
+ * Describes on which level (<code>TYPE</code>, <code>METHOD</code>, <code>FIELD</code>) the constraint was
+ * defined on.
+ */
+ private final ElementType elementType;
+
+ public MetaConstraint(Type t, ConstraintDescriptorImpl constraintDescriptor) {
+ this.type = t;
+ this.method = null;
+ this.field = null;
+ this.descriptor = constraintDescriptor;
+ this.elementType = ElementType.TYPE;
+ this.propertyName = "";
+ }
+
+ public MetaConstraint(Method m, ConstraintDescriptorImpl constraintDescriptor) {
+ this.method = m;
+ this.type = null;
+ this.field = null;
+ this.descriptor = constraintDescriptor;
+ this.elementType = ElementType.METHOD;
+ this.propertyName = ReflectionHelper.getPropertyName( m );
+ }
+
+ public MetaConstraint(Field f, ConstraintDescriptorImpl constraintDescriptor) {
+ this.field = f;
+ this.method = null;
+ this.type = null;
+ this.descriptor = constraintDescriptor;
+ this.elementType = ElementType.FIELD;
+ this.propertyName = f.getName();
+ }
+
+ /**
+ * @param o the object from which to retrieve the value.
+ *
+ * @return Returns the value for this constraint from the specified object. Depending on the type either the value itself
+ * is returned of method or field access is used to access the value.
+ */
+ public Object getValue(Object o) {
+ switch ( elementType ) {
+ case TYPE: {
+ return o;
+ }
+ case METHOD: {
+ return ReflectionHelper.getValue( method, o );
+ }
+ case FIELD: {
+ return ReflectionHelper.getValue( field, o );
+ }
+ default: {
+ throw new ValidationException(
+ "Invalid state of MetaConstraint. Parameter elementType has unexpected value - " + elementType
+ );
+ }
+ }
+ }
+
+ /**
+ * @return Returns <code>true</code> in case the constraint is defined on a collection, <code>false</code>
+ * otherwise.
+ */
+ public boolean isCollection() {
+ Type t = typeOfAnnoatedElement();
+ return ReflectionHelper.isCollection( t );
+ }
+
+ /**
+ * @return Returns <code>true</code> in case the constraint is defined on an array, <code>false</code>
+ * otherwise.
+ */
+ public boolean isArray() {
+ Type t = typeOfAnnoatedElement();
+ return ReflectionHelper.isArray( t );
+ }
+
+ public ConstraintDescriptorImpl getDescriptor() {
+ return descriptor;
+ }
+
+ public Method getMethod() {
+ return method;
+ }
+
+ public Field getField() {
+ return field;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public ElementType getElementType() {
+ return elementType;
+ }
+
+ private Type typeOfAnnoatedElement() {
+ Type t;
+ switch ( elementType ) {
+ case TYPE: {
+ t = type;
+ break;
+ }
+ case METHOD: {
+ t = ReflectionHelper.typeOf( method );
+ break;
+ }
+ case FIELD: {
+ t = ReflectionHelper.typeOf( field );
+ break;
+ }
+ default: {
+ throw new ValidationException(
+ "Invalid state of MetaConstraint. Parameter elementType has unexpected value - " + elementType
+ );
+ }
+ }
+ return t;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProvider.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProvider.java 2008-10-23 02:15:50 UTC (rev 15376)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProvider.java 2008-10-23 07:57:41 UTC (rev 15377)
@@ -65,7 +65,7 @@
* @return A list of <code>ValidatorMetaData</code> instances encapsulating the information of all the constraints
* defined on the bean.
*/
- List<ValidatorMetaData> getConstraintMetaDataList();
+ List<MetaConstraint> getConstraintMetaDataList();
/**
* @return A map keying the property name of a constraint to its <code>ElementDescriptor</code>.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java 2008-10-23 02:15:50 UTC (rev 15376)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java 2008-10-23 07:57:41 UTC (rev 15377)
@@ -18,7 +18,6 @@
package org.hibernate.validation.engine;
import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
@@ -69,7 +68,7 @@
/**
* List of constraints.
*/
- private List<ValidatorMetaData> constraintMetaDataList = new ArrayList<ValidatorMetaData>();
+ private List<MetaConstraint> metaConstraintList = new ArrayList<MetaConstraint>();
/**
* List of cascaded fields.
@@ -119,7 +118,7 @@
/**
* Get all superclasses and interfaces recursively.
*
- * @param clazz The class to start the seatch with.
+ * @param clazz The class to start the search with.
* @param classes List of classes to which to add all found super classes and interfaces.
*/
private void computeClassHierarchy(Class clazz, List<Class> classes) {
@@ -195,11 +194,11 @@
private void initFieldConstraints(Class clazz) {
for ( Field field : clazz.getDeclaredFields() ) {
- List<ConstraintDescriptorImpl> fieldMetadata = getFieldLevelMetadata( field );
+ List<ConstraintDescriptorImpl> fieldMetadata = findFieldLevelConstraints( field );
for ( ConstraintDescriptorImpl constraintDescription : fieldMetadata ) {
ReflectionHelper.setAccessibility( field );
- ValidatorMetaData metaData = new ValidatorMetaData( field, constraintDescription );
- constraintMetaDataList.add( metaData );
+ MetaConstraint metaConstraint = new MetaConstraint( field, constraintDescription );
+ metaConstraintList.add( metaConstraint );
}
if ( field.isAnnotationPresent( Valid.class ) ) {
cascadedFields.add( field );
@@ -209,11 +208,11 @@
private void initMethodConstraints(Class clazz) {
for ( Method method : clazz.getDeclaredMethods() ) {
- List<ConstraintDescriptorImpl> methodMetadata = getMethodLevelMetadata( method );
+ List<ConstraintDescriptorImpl> methodMetadata = findMethodLevelConstraints( method );
for ( ConstraintDescriptorImpl constraintDescription : methodMetadata ) {
ReflectionHelper.setAccessibility( method );
- ValidatorMetaData metaData = new ValidatorMetaData( method, constraintDescription );
- constraintMetaDataList.add( metaData );
+ MetaConstraint metaConstraint = new MetaConstraint( method, constraintDescription );
+ metaConstraintList.add( metaConstraint );
}
if ( method.isAnnotationPresent( Valid.class ) ) {
cascadedMethods.add( method );
@@ -222,10 +221,10 @@
}
private void initClassConstraints(Class clazz) {
- List<ConstraintDescriptorImpl> classMetadata = getClassLevelMetadata( clazz );
+ List<ConstraintDescriptorImpl> classMetadata = findClassLevelConstraints( clazz );
for ( ConstraintDescriptorImpl constraintDescription : classMetadata ) {
- ValidatorMetaData metaData = new ValidatorMetaData( clazz, constraintDescription );
- constraintMetaDataList.add( metaData );
+ MetaConstraint metaConstraint = new MetaConstraint( clazz, constraintDescription );
+ metaConstraintList.add( metaConstraint );
}
}
@@ -350,7 +349,7 @@
*
* @todo inject XML data here, probably externalizing the process
*/
- private List<ConstraintDescriptorImpl> getClassLevelMetadata(Class beanClass) {
+ private List<ConstraintDescriptorImpl> findClassLevelConstraints(Class beanClass) {
List<ConstraintDescriptorImpl> metadata = new ArrayList<ConstraintDescriptorImpl>();
for ( Annotation annotation : beanClass.getAnnotations() ) {
metadata.addAll( findConstraintAnnotations( annotation ) );
@@ -371,7 +370,7 @@
*
* @todo inject XML data here, probably externalizing the process
*/
- private List<ConstraintDescriptorImpl> getMethodLevelMetadata(Method method) {
+ private List<ConstraintDescriptorImpl> findMethodLevelConstraints(Method method) {
List<ConstraintDescriptorImpl> metadata = new ArrayList<ConstraintDescriptorImpl>();
for ( Annotation annotation : method.getAnnotations() ) {
metadata.addAll( findConstraintAnnotations( annotation ) );
@@ -408,7 +407,7 @@
*
* @todo inject XML data here, probably externalizing the process
*/
- private List<ConstraintDescriptorImpl> getFieldLevelMetadata(Field field) {
+ private List<ConstraintDescriptorImpl> findFieldLevelConstraints(Field field) {
List<ConstraintDescriptorImpl> metadata = new ArrayList<ConstraintDescriptorImpl>();
for ( Annotation annotation : field.getAnnotations() ) {
metadata.addAll( findConstraintAnnotations( annotation ) );
@@ -457,8 +456,8 @@
return groupSequences;
}
- public List<ValidatorMetaData> getConstraintMetaDataList() {
- return constraintMetaDataList;
+ public List<MetaConstraint> getConstraintMetaDataList() {
+ return metaConstraintList;
}
public Map<String, ElementDescriptor> getPropertyDescriptors() {
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 2008-10-23 02:15:50 UTC (rev 15376)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2008-10-23 07:57:41 UTC (rev 15377)
@@ -158,9 +158,9 @@
* @param context The current validation context.
*/
private void validateConstraints(ValidationContext<T> context) {
- for ( ValidatorMetaData metaData : metaDataProvider.getConstraintMetaDataList() ) {
- ConstraintDescriptorImpl constraintDescriptor = metaData.getDescriptor();
- context.pushProperty( metaData.getPropertyName() );
+ for ( MetaConstraint metaConstraint : metaDataProvider.getConstraintMetaDataList() ) {
+ ConstraintDescriptorImpl constraintDescriptor = metaConstraint.getDescriptor();
+ context.pushProperty( metaConstraint.getPropertyName() );
if ( !context.needsValidation( constraintDescriptor.getGroups() ) ) {
context.popProperty();
@@ -168,7 +168,7 @@
}
final Object leafBeanInstance = context.peekValidatedObject();
- Object value = metaData.getValue( leafBeanInstance );
+ Object value = metaConstraint.getValue( leafBeanInstance );
ContextImpl contextImpl = new ContextImpl(constraintDescriptor);
if ( !constraintDescriptor.getConstraintImplementation().isValid( value, contextImpl ) ) {
@@ -414,10 +414,10 @@
propertyIter.split();
if ( !propertyIter.hasNext() ) {
- List<ValidatorMetaData> metaDataList = validator.getMetaDataProvider().getConstraintMetaDataList();
- for ( ValidatorMetaData metaData : metaDataList ) {
- ConstraintDescriptor constraintDescriptor = metaData.getDescriptor();
- if ( metaData.getPropertyName().equals( propertyIter.getHead() ) ) {
+ List<MetaConstraint> metaConstraintList = validator.getMetaDataProvider().getConstraintMetaDataList();
+ for ( MetaConstraint metaConstraint : metaConstraintList ) {
+ ConstraintDescriptor constraintDescriptor = metaConstraint.getDescriptor();
+ if ( metaConstraint.getPropertyName().equals( propertyIter.getHead() ) ) {
matchingConstraintDescriptor = ( ConstraintDescriptorImpl ) constraintDescriptor;
}
}
@@ -453,12 +453,12 @@
// bottom out - there is only one token left
if ( !propertyIter.hasNext() ) {
- List<ValidatorMetaData> metaDataList = validator.getMetaDataProvider().getConstraintMetaDataList();
- for ( ValidatorMetaData metaData : metaDataList ) {
- ConstraintDescriptor constraintDescriptor = metaData.getDescriptor();
- if ( metaData.getPropertyName().equals( propertyIter.getHead() ) ) {
+ List<MetaConstraint> metaConstraintList = validator.getMetaDataProvider().getConstraintMetaDataList();
+ for ( MetaConstraint metaConstraint : metaConstraintList ) {
+ ConstraintDescriptor constraintDescriptor = metaConstraint.getDescriptor();
+ if ( metaConstraint.getPropertyName().equals( propertyIter.getHead() ) ) {
return new DesrciptorValueWrapper(
- ( ConstraintDescriptorImpl ) constraintDescriptor, metaData.getValue( value )
+ ( ConstraintDescriptorImpl ) constraintDescriptor, metaConstraint.getValue( value )
);
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintDescriptorImpl.java 2008-10-23 02:15:50 UTC (rev 15376)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ConstraintDescriptorImpl.java 2008-10-23 07:57:41 UTC (rev 15377)
@@ -28,29 +28,30 @@
import java.util.Set;
import javax.validation.Constraint;
import javax.validation.ConstraintDescriptor;
+import javax.validation.ReportAsSingleInvalidConstraint;
import javax.validation.ValidationException;
-import javax.validation.ReportAsSingleInvalidConstraint;
/**
* Describe a single constraint.
*
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class ConstraintDescriptorImpl implements ConstraintDescriptor {
private final Annotation annotation;
private final Constraint constraintImplementation;
private final Class<? extends Constraint> constraintClass;
- private final Set<String> contexts;
+ private final Set<String> groups;
private final Map<String, Object> parameters;
private final boolean isReportAsSingleInvalidConstraint;
- public ConstraintDescriptorImpl(Annotation annotation, String[] contexts, Constraint validator, Class<? extends Constraint> constraintClass) {
+ public ConstraintDescriptorImpl(Annotation annotation, String[] groups, Constraint validator, Class<? extends Constraint> constraintClass) {
this.annotation = annotation;
- if ( contexts.length == 0 ) {
- contexts = new String[] { "default" };
+ if ( groups.length == 0 ) {
+ groups = new String[] { "default" };
}
- this.contexts = new HashSet<String>();
- this.contexts.addAll( Arrays.asList( contexts ) );
+ this.groups = new HashSet<String>();
+ this.groups.addAll( Arrays.asList( groups ) );
this.constraintImplementation = validator;
this.parameters = getAnnotationParameters( annotation );
this.isReportAsSingleInvalidConstraint = annotation.annotationType().isAnnotationPresent(
@@ -59,45 +60,60 @@
this.constraintClass = constraintClass;
}
+
/**
- * Constraint declaration annotation
+ * {@inheritDoc}
*/
public Annotation getAnnotation() {
return annotation;
}
/**
- * What are the contexts the constraint is applied on
+ * {@inheritDoc}
*/
public Set<String> getGroups() {
- return contexts;
+ return groups;
}
+ /**
+ * {@inheritDoc}
+ */
public Class<? extends Constraint> getContstraintClass() {
return constraintClass;
}
public boolean isInGroups(String group) {
- return contexts.contains( group );
+ return groups.contains( group );
}
/**
- * Return the constraint implementation routine
- * //FIXME should we get rid of that and call the ConstraintFactory each time??
+ * @return the constraint's implementation.
+ *
+ * @todo should we get rid of that and call the ConstraintFactory each time??
*/
public Constraint getConstraintImplementation() {
return constraintImplementation;
}
+ /**
+ * {@inheritDoc}
+ */
public Map<String, Object> getParameters() {
return parameters;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @todo Implement
+ */
public Set<ConstraintDescriptor> getComposingConstraints() {
- //FIXME implement
return Collections.emptySet();
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isReportAsSingleInvalidConstraint() {
return isReportAsSingleInvalidConstraint;
}
Modified: validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2008-10-23 02:15:50 UTC (rev 15376)
+++ validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2008-10-23 07:57:41 UTC (rev 15377)
@@ -22,7 +22,7 @@
import java.util.Set;
/**
- * Describes a single constraint.
+ * Describes a single constraint and its composing constraints.
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
@@ -48,10 +48,10 @@
Class<? extends Constraint> getContstraintClass();
/**
- * Returns a map containing the annotation paramter names as keys and the annotation parameter values
+ * Returns a map containing the annotation parameter names as keys and the annotation parameter values
* as value.
- * If a composing constraint, parameter values are reflecting
- * the overridden parameters form the main constraint
+ * If this constraint is used as part of a composed constraint, parameter values are reflecting
+ * the overridden parameters form the main constraint.
*
* @return Returns a map containing the annotation paramter names as keys and the annotation parameter values
* as value.
@@ -59,11 +59,11 @@
Map<String, Object> getParameters();
/**
- * Return a set of ConstraintDescriptors. Each ConstraintDescriptor describes a composing
- * constraint. ConstraintDescriptor instances of composing constraints reflect overridden
- * parameter values in #getParameters() and #getAnnotation()
+ * Return a set of composing <code>ConstraintDescriptor</code>s where each descriptor describes a composing
+ * constraint. <code>ConstraintDescriptor</code> instances of composing constraints reflect overridden
+ * parameter values in {@link #getParameters()} and {@link #getAnnotation()}.
*
- * @return a set of ConstraintDescriptor object or an empty set
+ * @return a set of <code>ConstraintDescriptor<code> objects or an empty set in case there are no composing constraints.
*/
Set<ConstraintDescriptor> getComposingConstraints();
Modified: validator/trunk/validation-api/src/main/java/javax/validation/ConstraintFactory.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/ConstraintFactory.java 2008-10-23 02:15:50 UTC (rev 15376)
+++ validator/trunk/validation-api/src/main/java/javax/validation/ConstraintFactory.java 2008-10-23 07:57:41 UTC (rev 15377)
@@ -26,5 +26,11 @@
* @author Hardy Ferentschik
*/
public interface ConstraintFactory {
+
+ /**
+ * @param key The class of the constraint to instantiate.
+ *
+ * @return An constraint instance of the specified class.
+ */
<T extends Constraint> T getInstance(Class<T> key);
}
17 years, 6 months