-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[value-context-changes] Introduce HibernateConstrainedType, that wrap…
…s class `HibernateConstrainedType` wraps a class and is used as a key for metadata manager. It can also wrap strings or any other objects/data for metadata of property holders and other kinds of objects.
- Loading branch information
1 parent
686a788
commit abd5bf5
Showing
41 changed files
with
660 additions
and
301 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
engine/src/main/java/org/hibernate/validator/engine/HibernateConstrainedType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.engine; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* An interface that represents a type/class of a bean that will be validated. | ||
* Based on this type set of constraints will be determined, and applied to the | ||
* validated object. | ||
* | ||
* @author Marko Bekhta | ||
* @since 6.1 | ||
*/ | ||
public interface HibernateConstrainedType<T> { | ||
|
||
/** | ||
* @return a class of an object that will be validated. | ||
*/ | ||
Class<T> getActuallClass(); | ||
|
||
List<HibernateConstrainedType<? super T>> getHierarchy(); | ||
|
||
boolean isInterface(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 96 additions & 64 deletions
160
engine/src/main/java/org/hibernate/validator/internal/engine/ValidatorImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
...java/org/hibernate/validator/internal/engine/constrainedtype/JavaBeanConstrainedType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.internal.engine.constrainedtype; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hibernate.validator.engine.HibernateConstrainedType; | ||
import org.hibernate.validator.internal.util.classhierarchy.ClassHierarchyHelper; | ||
import org.hibernate.validator.metadata.BeanMetaDataClassNormalizer; | ||
|
||
/** | ||
* An implementation of {@link HibernateConstrainedType} for regular JavaBeans. | ||
* Wrapps a {@link Class} object to adapt it to the needs of HV usages. | ||
* | ||
* @author Marko Bekhta | ||
*/ | ||
public class JavaBeanConstrainedType<T> implements HibernateConstrainedType<T> { | ||
|
||
private final Class<T> clazz; | ||
|
||
public JavaBeanConstrainedType(Class<T> clazz) { | ||
this.clazz = clazz; | ||
} | ||
|
||
@Override | ||
public Class<T> getActuallClass() { | ||
return clazz; | ||
} | ||
|
||
@Override | ||
public List<HibernateConstrainedType<? super T>> getHierarchy() { | ||
List<Class<? super T>> hierarchy = ClassHierarchyHelper.getHierarchy( clazz ); | ||
List<HibernateConstrainedType<? super T>> result = new ArrayList<>( hierarchy.size() ); | ||
for ( Class<? super T> clazzz : hierarchy ) { | ||
result.add( new JavaBeanConstrainedType<>( clazzz ) ); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean isInterface() { | ||
return clazz.isInterface(); | ||
} | ||
|
||
public HibernateConstrainedType<T> normalize(BeanMetaDataClassNormalizer normalizer) { | ||
return new NormalizedJavaBeanConstrainedType<>( normalizer, clazz ); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if ( this == o ) { | ||
return true; | ||
} | ||
if ( o == null || !( o instanceof JavaBeanConstrainedType ) ) { | ||
return false; | ||
} | ||
|
||
JavaBeanConstrainedType<?> that = (JavaBeanConstrainedType<?>) o; | ||
|
||
if ( !clazz.equals( that.clazz ) ) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return clazz.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JavaBeanConstrainedType{" + | ||
"clazz=" + clazz + | ||
'}'; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ibernate/validator/internal/engine/constrainedtype/NormalizedJavaBeanConstrainedType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.internal.engine.constrainedtype; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hibernate.validator.engine.HibernateConstrainedType; | ||
import org.hibernate.validator.internal.util.classhierarchy.ClassHierarchyHelper; | ||
import org.hibernate.validator.metadata.BeanMetaDataClassNormalizer; | ||
|
||
/** | ||
* Uses {@link org.hibernate.validator.metadata.BeanMetaDataClassNormalizer} before | ||
* creating a {@link HibernateConstrainedType}. | ||
* | ||
* @author Marko Bekhta | ||
*/ | ||
public class NormalizedJavaBeanConstrainedType<T> extends JavaBeanConstrainedType<T> { | ||
private final BeanMetaDataClassNormalizer normalizer; | ||
|
||
public NormalizedJavaBeanConstrainedType(BeanMetaDataClassNormalizer normalizer, Class<T> clazz) { | ||
super( (Class<T>) normalizer.normalize( clazz ) ); | ||
this.normalizer = normalizer; | ||
} | ||
|
||
@Override | ||
public List<HibernateConstrainedType<? super T>> getHierarchy() { | ||
List<Class<? super T>> hierarchy = ClassHierarchyHelper.getHierarchy( getActuallClass() ); | ||
List<HibernateConstrainedType<? super T>> result = new ArrayList<>( hierarchy.size() ); | ||
//TODO : question - do we actually need to normalize anything here. Wouldn't it be enough to normalize only when | ||
// the metadata is retrieved ? | ||
for ( Class<? super T> clazzz : hierarchy ) { | ||
result.add( (NormalizedJavaBeanConstrainedType<? super T>) new NormalizedJavaBeanConstrainedType<>( normalizer, normalizer.normalize( clazzz ) ) ); | ||
} | ||
return result; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...e/src/main/java/org/hibernate/validator/internal/engine/constrainedtype/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
|
||
/** | ||
* Classes implementing {@link org.hibernate.validator.engine.HibernateConstrainedType}. | ||
*/ | ||
package org.hibernate.validator.internal.engine.constrainedtype; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.