-
Notifications
You must be signed in to change notification settings - Fork 579
HV-1363 support for non-standard Java beans #938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b26462
HV-1363 Build abstraction over reflection in ConstraintLocation and r…
marko-bekhta dd51f80
fixup! HV-1363 Build abstraction over reflection in ConstraintLocatio…
gsmet e34276b
HV-1363 Moved getter detection logic to separate class
marko-bekhta c63b86e
HV-1363 Reworked the property filtering logic
marko-bekhta 4cb8d13
HV-1363 Added ability to configure property filter for ValidatorFactory
marko-bekhta 1b55886
HV-1363 Updated ValidationExtension to use new property filtering
marko-bekhta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised we don't also have an abstraction on
ElementType
. I think it's going to be in the way.It's pretty obvious from the way we have to special case things whereas the
ElementType
could be returned by theProperty
object or theCallable
in the case of a method/constructor.Maybe we could call it
ConstraintLocationType
.AFAICS, it's only exposed in BV in the
TraversableResolver
(and considering it only applies to Java Bean properties (either fields or getters), we could check that theConstraintLocationType
is valid and translate it then call agetElementType()
method which would be present onJavaBeanField
andJavaBeanGetter
) and inConstraintFinder
(we probably could have a translation layer there too).Did you think about it?