-
Notifications
You must be signed in to change notification settings - Fork 38.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract classes from ~.validation.beanvalidation without a direct dependency on beanvalidation. See gh-30644
- Loading branch information
1 parent
0da2241
commit 592ab0f
Showing
27 changed files
with
220 additions
and
120 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
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
80 changes: 80 additions & 0 deletions
80
...xt/src/main/java/org/springframework/validation/method/DefaultMethodValidationResult.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,80 @@ | ||
/* | ||
* Copyright 2002-2023 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.springframework.validation.method; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
|
||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* Default {@link MethodValidationResult} implementation as a simple container. | ||
* | ||
* @author Rossen Stoyanchev | ||
* @since 6.1 | ||
*/ | ||
final class DefaultMethodValidationResult implements MethodValidationResult { | ||
|
||
private final Object target; | ||
|
||
private final Method method; | ||
|
||
private final List<ParameterValidationResult> allValidationResults; | ||
|
||
private final boolean forReturnValue; | ||
|
||
|
||
DefaultMethodValidationResult(Object target, Method method, List<ParameterValidationResult> results) { | ||
Assert.notEmpty(results, "'results' is required and must not be empty"); | ||
Assert.notNull(target, "'target' is required"); | ||
Assert.notNull(method, "Method is required"); | ||
this.target = target; | ||
this.method = method; | ||
this.allValidationResults = results; | ||
this.forReturnValue = (results.get(0).getMethodParameter().getParameterIndex() == -1); | ||
} | ||
|
||
|
||
@Override | ||
public Object getTarget() { | ||
return this.target; | ||
} | ||
|
||
@Override | ||
public Method getMethod() { | ||
return this.method; | ||
} | ||
|
||
@Override | ||
public boolean isForReturnValue() { | ||
return this.forReturnValue; | ||
} | ||
|
||
@Override | ||
public List<ParameterValidationResult> getAllValidationResults() { | ||
return this.allValidationResults; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return getAllErrors().size() + " validation errors " + | ||
"for " + (isForReturnValue() ? "return value" : "arguments") + " of " + | ||
this.method.toGenericString(); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...text/src/main/java/org/springframework/validation/method/EmptyMethodValidationResult.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,56 @@ | ||
/* | ||
* Copyright 2002-2023 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.springframework.validation.method; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* {@link MethodValidationResult} with an empty list of results. | ||
* | ||
* @author Rossen Stoyanchev | ||
* @since 6.1 | ||
*/ | ||
final class EmptyMethodValidationResult implements MethodValidationResult { | ||
|
||
@Override | ||
public Object getTarget() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Method getMethod() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public boolean isForReturnValue() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public List<ParameterValidationResult> getAllValidationResults() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "0 validation errors"; | ||
} | ||
|
||
} |
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
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
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.