-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-1363 Updated ValidationExtension to use new property filtering
- introduced new helper in cdi module to deal with new PropertyFilter spi.
- Loading branch information
1 parent
9a70c78
commit d5fe970
Showing
4 changed files
with
81 additions
and
47 deletions.
There are no files selected for viewing
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
75 changes: 75 additions & 0 deletions
75
cdi/src/main/java/org/hibernate/validator/cdi/internal/util/GetterPropertyMatcherHelper.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,75 @@ | ||
/* | ||
* 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.cdi.internal.util; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Type; | ||
|
||
import javax.validation.ValidatorFactory; | ||
|
||
import org.hibernate.validator.HibernateValidatorFactory; | ||
import org.hibernate.validator.internal.properties.DefaultGetterPropertyMatcher; | ||
import org.hibernate.validator.spi.properties.ConstrainableExecutable; | ||
import org.hibernate.validator.spi.properties.GetterPropertyMatcher; | ||
|
||
/** | ||
* A wrapper around {@link GetterPropertyMatcher}. | ||
* | ||
* @author Marko Bekhta | ||
*/ | ||
public class GetterPropertyMatcherHelper { | ||
|
||
private final GetterPropertyMatcher getterPropertyMatcher; | ||
|
||
private GetterPropertyMatcherHelper(GetterPropertyMatcher getterPropertyMatcher) { | ||
this.getterPropertyMatcher = getterPropertyMatcher; | ||
} | ||
|
||
public boolean isProperty(Method method) { | ||
return getterPropertyMatcher.isProperty( new ConstrainableMethod( method ) ); | ||
} | ||
|
||
public String getPropertyName(Method method) { | ||
return getterPropertyMatcher.getPropertyName( new ConstrainableMethod( method ) ); | ||
} | ||
|
||
public static GetterPropertyMatcherHelper forValidationFactory(ValidatorFactory factory) { | ||
GetterPropertyMatcher getterPropertyMatcher; | ||
if ( factory instanceof HibernateValidatorFactory ) { | ||
getterPropertyMatcher = factory.unwrap( HibernateValidatorFactory.class ).getGetterPropertyMatcher(); | ||
} | ||
else { | ||
getterPropertyMatcher = new DefaultGetterPropertyMatcher(); | ||
} | ||
return new GetterPropertyMatcherHelper( getterPropertyMatcher ); | ||
} | ||
|
||
private static class ConstrainableMethod implements ConstrainableExecutable { | ||
|
||
private final Method method; | ||
|
||
private ConstrainableMethod(Method method) { | ||
this.method = method; | ||
} | ||
|
||
@Override public Class<?> getReturnType() { | ||
return method.getReturnType(); | ||
} | ||
|
||
@Override public String getName() { | ||
return method.getName(); | ||
} | ||
|
||
@Override public Type[] getParameterTypes() { | ||
return method.getParameterTypes(); | ||
} | ||
|
||
public Method getMethod() { | ||
return method; | ||
} | ||
} | ||
} |
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