Repository: camel Updated Branches: refs/heads/master 2f866b82b -> 3e4e7d6e9
CAMEL-11037: Ping Check API - Add javadoc Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3e4e7d6e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3e4e7d6e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3e4e7d6e Branch: refs/heads/master Commit: 3e4e7d6e9b8a98610581a70a65b3651d1853c895 Parents: 2f866b8 Author: lburgazzoli <lburgazz...@gmail.com> Authored: Tue Mar 21 09:52:56 2017 +0100 Committer: lburgazzoli <lburgazz...@gmail.com> Committed: Tue Mar 21 14:14:59 2017 +0100 ---------------------------------------------------------------------- .../org/apache/camel/ComponentVerifier.java | 48 +++++++++++++++++--- .../impl/verifier/DefaultComponentVerifier.java | 10 ++-- .../camel/impl/verifier/ResultErrorHelper.java | 6 +++ 3 files changed, 53 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/3e4e7d6e/camel-core/src/main/java/org/apache/camel/ComponentVerifier.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/ComponentVerifier.java b/camel-core/src/main/java/org/apache/camel/ComponentVerifier.java index 488a0ba..ce8cae8 100644 --- a/camel-core/src/main/java/org/apache/camel/ComponentVerifier.java +++ b/camel-core/src/main/java/org/apache/camel/ComponentVerifier.java @@ -21,8 +21,10 @@ import java.util.List; import java.util.Map; import java.util.Set; +/** + * Defines the interface used to validate component/endpoint parameters. + */ public interface ComponentVerifier { - // Todo: should be an enum ? String CODE_EXCEPTION = "exception"; String CODE_INTERNAL = "internal"; String CODE_MISSING_OPTION = "missing-option"; @@ -56,14 +58,29 @@ public interface ComponentVerifier { * Represent an error */ interface Error extends Serializable { + /** + * @return the error code + */ String getCode(); + + /** + * @return the error description (if available) + */ String getDescription(); + + /** + * @return the parameters in error + */ Set<String> getParameters(); + + /** + * @return a number of key/value pair with additional information related to the validation. + */ Map<String, Object> getAttributes(); } /** - * Represent a Result + * Represent a validation Result. */ interface Result extends Serializable { enum Status { @@ -72,16 +89,35 @@ public interface ComponentVerifier { UNSUPPORTED } + /** + * @return the scope against which the parameters have been validated. + */ Scope getScope(); + + /** + * @return the status + */ Status getStatus(); + + /** + * @return a list of errors + */ List<Error> getErrors(); } /** - * TODO: document - * @param parameters - * @param scope - * @return + * Validate the given parameters against the provided scope. + * + * <p> + * The supported scopes are: + * <ul> + * <li>PARAMETERS: to validate that all the mandatory options are provided and syntactically correct. + * <li>CONNECTIVITY: to validate that the given options (i.e. credentials, addresses) are correct. + * </ul> + * + * @param scope the scope of the validation + * @param parameters the parameters to validate + * @return the validation result */ Result verify(Scope scope, Map<String, Object> parameters); } http://git-wip-us.apache.org/repos/asf/camel/blob/3e4e7d6e/camel-core/src/main/java/org/apache/camel/impl/verifier/DefaultComponentVerifier.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/verifier/DefaultComponentVerifier.java b/camel-core/src/main/java/org/apache/camel/impl/verifier/DefaultComponentVerifier.java index 48de776..f102c6a 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/verifier/DefaultComponentVerifier.java +++ b/camel-core/src/main/java/org/apache/camel/impl/verifier/DefaultComponentVerifier.java @@ -55,14 +55,14 @@ public class DefaultComponentVerifier implements ComponentVerifier { .build(); } - switch (scope) { - case PARAMETERS: + if (scope == Scope.PARAMETERS) { return verifyParameters(parameters); - case CONNECTIVITY: + } + if (scope == Scope.CONNECTIVITY) { return verifyConnectivity(parameters); - default: - throw new IllegalArgumentException("Unsupported Verifier scope: " + scope); } + + throw new IllegalArgumentException("Unsupported Verifier scope: " + scope); } protected Result verifyConnectivity(Map<String, Object> parameters) { http://git-wip-us.apache.org/repos/asf/camel/blob/3e4e7d6e/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorHelper.java b/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorHelper.java index 4603ce4..d42b8cb 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorHelper.java +++ b/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorHelper.java @@ -38,6 +38,12 @@ public final class ResultErrorHelper { // Helpers // ********************************** + /** + * + * @param parameterName the required option + * @param parameters the + * @return + */ public static Optional<ComponentVerifier.Error> requiresOption(String parameterName, Map<String, Object> parameters) { if (ObjectHelper.isEmpty(parameters.get(parameterName))) { return Optional.of(