Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-371: First draft for method-level meta data API
- Loading branch information
1 parent
290e7a7
commit 3458757
Showing
6 changed files
with
241 additions
and
1 deletion.
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
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
65 changes: 65 additions & 0 deletions
65
...ate-validator/src/main/java/org/hibernate/validator/method/metadata/MethodDescriptor.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,65 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, 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.validator.method.metadata; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
import javax.validation.Valid; | ||
import javax.validation.metadata.ElementDescriptor; | ||
|
||
/** | ||
* Describes a constrained method and the constraints associated with it. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public interface MethodDescriptor extends ElementDescriptor { | ||
|
||
/** | ||
* Returns the method represented by this descriptor. | ||
* | ||
* @return The method represented by this descriptor. | ||
*/ | ||
Method getMethod(); | ||
|
||
/** | ||
* <p> | ||
* Returns a list with descriptors for this method's parameters. | ||
* </p> | ||
* <p> | ||
* The size of this list corresponds with the number of this method's | ||
* parameters. If there are no constraints defined for a given parameter | ||
* (neither locally nor in the inheritance hierarchy) and this parameter is | ||
* also not annotated with {@link Valid} (neither locally nor in the | ||
* inheritance hierarchy), the returned list will contain <code>null</code> | ||
* at the position representing that parameter. | ||
* </p> | ||
* | ||
* @return A list with descriptors for this method's parameters. An empty | ||
* list will be returned if this method has no parameters. | ||
*/ | ||
List<ParameterDescriptor> getParameterConstraints(); | ||
|
||
/** | ||
* Whether a cascaded validation for this method's return value shall be | ||
* performed or not. This is the case if this method is annotated with the | ||
* {@link Valid} annotation either locally or in the inheritance hierarchy. | ||
* | ||
* @return <code>True</code>, if this method's return value shall be | ||
* validated recursively, <code>false</code> otherwise. | ||
*/ | ||
boolean isCascaded(); | ||
} |
47 changes: 47 additions & 0 deletions
47
...-validator/src/main/java/org/hibernate/validator/method/metadata/ParameterDescriptor.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,47 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, 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.validator.method.metadata; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.metadata.ElementDescriptor; | ||
|
||
/** | ||
* Describes a constrained parameter and the constraints associated with it. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public interface ParameterDescriptor extends ElementDescriptor { | ||
|
||
/** | ||
* Whether cascaded validation for this parameter shall be | ||
* performed or not. This is the case if this parameter is annotated with the | ||
* {@link Valid} annotation either locally or in the inheritance hierarchy. | ||
* | ||
* @return <code>True</code>, if this parameter shall be | ||
* validated recursively, <code>false</code> otherwise. | ||
*/ | ||
boolean isCascaded(); | ||
|
||
/** | ||
* Returns this parameter's index within the parameter array of the | ||
* method holding it. | ||
* | ||
* @return This parameter's index. | ||
*/ | ||
int getIndex(); | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
...rnate-validator/src/main/java/org/hibernate/validator/method/metadata/TypeDescriptor.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 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, 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.validator.method.metadata; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Set; | ||
import javax.validation.Valid; | ||
import javax.validation.metadata.BeanDescriptor; | ||
import javax.validation.metadata.ElementDescriptor; | ||
import javax.validation.metadata.PropertyDescriptor; | ||
|
||
/** | ||
* Describes a constrained Java type and the constraints associated to it. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public interface TypeDescriptor extends ElementDescriptor { | ||
|
||
/** | ||
* Whether this type has any class-, property- or method-level constraints | ||
* or not. This is <code>true</code>, if | ||
* {@link BeanDescriptor#isBeanConstrained()} would return true for the same | ||
* type. Furthermore this will be true, if | ||
* <ul> | ||
* <li>a constraint is hosted on any of this type's method's parameters</li> | ||
* <li>any of this type's method's parameters is marked for cascaded | ||
* validation with the {@link Valid} annotation</li> | ||
* <li>a constraint is hosted on the return value of any of this type's | ||
* methods</li> | ||
* <li>the return value of any of this type's methods is marked for cascaded | ||
* validation with the {@link Valid} annotation</li> | ||
* </ul> | ||
* | ||
* @return <code>True</code>, if this type has any constraints, | ||
* <code>false</code> | ||
*/ | ||
boolean isTypeConstrained(); | ||
|
||
/** | ||
* @see BeanDescriptor#getConstrainedProperties() | ||
*/ | ||
Set<PropertyDescriptor> getConstrainedProperties(); | ||
|
||
/** | ||
* @see BeanDescriptor#getConstraintsForProperty(String) | ||
*/ | ||
PropertyDescriptor getConstraintsForProperty(String propertyName); | ||
|
||
/** | ||
* Returns a set with the constrained methods of this type. | ||
* | ||
* @return A set with the constrained methods of this type, will be empty if | ||
* none of this type's methods are constrained. | ||
*/ | ||
Set<MethodDescriptor> getConstrainedMethods(); | ||
|
||
/** | ||
* Returns a descriptor for the specified method. | ||
* | ||
* @param method The method of interest. | ||
* | ||
* @return A descriptor for the specified method. Will never be null. | ||
* | ||
* @throws IllegalArgumentException if method is null or is not a method of the type represented | ||
* by this descriptor. | ||
*/ | ||
MethodDescriptor getConstraintsForMethod(Method method); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
hibernate-validator/src/main/java/org/hibernate/validator/method/metadata/package.html
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 @@ | ||
<!-- | ||
~ | ||
~ JBoss, Home of Professional Open Source | ||
~ Copyright 2011, Red Hat, Inc. and/or its affiliates, 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. | ||
--> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<p>This package provides a meta model related to method-level | ||
constraints and as such is an addition to the package <code>javax.validation.metadata</code> | ||
provided by the Bean Validation API. This meta model is read-only, all | ||
of its types are immutable. This package is part of the public Hibernate | ||
Validator API.</p> | ||
</body> | ||
</html> |