[maven-release-plugin] copy for tag org.apache.sling.validation.api-1.0.0
git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.validation.api-1.0.0@1790247 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/validation/ValidationService.java b/src/main/java/org/apache/sling/validation/ValidationService.java
index 6779c5a..4bb8242 100644
--- a/src/main/java/org/apache/sling/validation/ValidationService.java
+++ b/src/main/java/org/apache/sling/validation/ValidationService.java
@@ -68,8 +68,9 @@
* @param model the model with which to perform the validation
* @return a {@link ValidationResult} that provides the necessary information
* @throws SlingValidationException if one validator was called with invalid arguments
+ * @throws IllegalStateException if a validator id referenced in the given model could not be resolved
*/
- @Nonnull ValidationResult validate(@Nonnull Resource resource, @Nonnull ValidationModel model) throws SlingValidationException;
+ @Nonnull ValidationResult validate(@Nonnull Resource resource, @Nonnull ValidationModel model) throws SlingValidationException, IllegalStateException;
/**
* Validates a {@link ValueMap} or any object adaptable to a {@code ValueMap} using a specific {@link ValidationModel}. Since the
diff --git a/src/main/java/org/apache/sling/validation/model/ResourceProperty.java b/src/main/java/org/apache/sling/validation/model/ResourceProperty.java
index 2dbb70c..f5c4b58 100644
--- a/src/main/java/org/apache/sling/validation/model/ResourceProperty.java
+++ b/src/main/java/org/apache/sling/validation/model/ResourceProperty.java
@@ -48,9 +48,8 @@
@CheckForNull Pattern getNamePattern();
/**
- * Returns {@code true} if this property is expected to be a multiple property (e.g. array of values).
*
- * @return {@code true} if the property is multiple, {@code false} otherwise
+ * @return {@code true} if the property is expected to contain multiple values, {@code false} otherwise
*/
boolean isMultiple();
@@ -62,9 +61,9 @@
boolean isRequired();
/**
- * Returns a list of {@link ParameterizedValidator}s which should be applied on this property.
+ * Returns a list of {@link ValidatorInvocation}s which should be applied on this property.
*
- * @return the list of validators
+ * @return the {@link List} of {@link ValidatorInvocation}s
*/
- @Nonnull List<ParameterizedValidator> getValidators();
+ @Nonnull List<ValidatorInvocation> getValidatorInvocations();
}
diff --git a/src/main/java/org/apache/sling/validation/model/ValidationModel.java b/src/main/java/org/apache/sling/validation/model/ValidationModel.java
index 4167755..f7b8ab7 100644
--- a/src/main/java/org/apache/sling/validation/model/ValidationModel.java
+++ b/src/main/java/org/apache/sling/validation/model/ValidationModel.java
@@ -41,9 +41,9 @@
/**
* Returns the type of resource this model validates.
*
- * @return the validated resource type, never {@code null}
+ * @return the resource type to be validated, never {@code null}
*/
- @Nonnull String getValidatedResourceType();
+ @Nonnull String getValidatingResourceType();
/**
* Returns the paths under which resources will be validated by this model.
diff --git a/src/main/java/org/apache/sling/validation/model/ValidatorAndSeverity.java b/src/main/java/org/apache/sling/validation/model/ValidatorAndSeverity.java
deleted file mode 100644
index 0daede0..0000000
--- a/src/main/java/org/apache/sling/validation/model/ValidatorAndSeverity.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.sling.validation.model;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-
-import org.apache.sling.validation.spi.Validator;
-
-/**
- * This encapsulates a {@link Validator} as well as its default severity.
- *
- * @param <T> the type param of the encapsulated {@link Validator}
- */
-public final class ValidatorAndSeverity<T> {
- private final @Nonnull Validator<T> validator;
- private final Integer severity;
-
- public ValidatorAndSeverity(@Nonnull Validator<T> validator, Integer severity) {
- this.validator = validator;
- this.severity = severity;
- }
-
- public @CheckForNull Integer getSeverity() {
- return severity;
- }
-
- public @Nonnull Validator<T> getValidator() {
- return validator;
- }
-
- @Override
- public String toString() {
- return "ValidatorWithSeverity [validator=" + validator + ", severity=" + severity + "]";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((severity == null) ? 0 : severity.hashCode());
- result = prime * result + ((validator == null) ? 0 : validator.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ValidatorAndSeverity<?> other = (ValidatorAndSeverity<?>) obj;
- if (severity == null) {
- if (other.severity != null)
- return false;
- } else if (!severity.equals(other.severity))
- return false;
- if (!validator.equals(other.validator))
- return false;
- return true;
- }
-
-}
diff --git a/src/main/java/org/apache/sling/validation/model/ParameterizedValidator.java b/src/main/java/org/apache/sling/validation/model/ValidatorInvocation.java
similarity index 63%
rename from src/main/java/org/apache/sling/validation/model/ParameterizedValidator.java
rename to src/main/java/org/apache/sling/validation/model/ValidatorInvocation.java
index b42d246..1544415 100644
--- a/src/main/java/org/apache/sling/validation/model/ParameterizedValidator.java
+++ b/src/main/java/org/apache/sling/validation/model/ValidatorInvocation.java
@@ -27,35 +27,26 @@
/**
- * Defines a validator instance with information about the type and the parameterization of the validator.
- *
+ * Defines a specific validator invocation for a given property (without actually exposing a reference to the underlying {@link Validator}).
*/
@ProviderType
-public interface ParameterizedValidator {
+public interface ValidatorInvocation {
/**
*
- * @return the validator. Never {@code null}.
+ * @return the validator id of the {@link Validator} which is supposed to be called.
*/
- @Nonnull Validator<?> getValidator();
+ @Nonnull String getValidatorId();
/**
*
- * @return the parameterization of the validator (never {@code null}, but might be empty map)
+ * @return the parameterization of the {@link Validator#validate(Object, org.apache.sling.validation.spi.ValidatorContext, ValueMap)} call (never {@code null}, but might be empty map)
*/
@Nonnull ValueMap getParameters();
/**
- *
- * @return the type of the validator (i.e. the type of the data it can handle)
- */
- @Nonnull Class<?> getType();
-
- /**
- *
- * @return the severity of validation failures emitted by this validator.
- * Was either set on the model or on the {@link Validator} itself.
- * May be {@code null} in case it was set on none of them.
+ * @return the severity of validation failures emitted for this usage of the validator (as being set in the model).
+ * May be {@code null} in case it was not set on the model.
*/
@CheckForNull Integer getSeverity();
diff --git a/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java b/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java
index 29ba615..86e849e 100644
--- a/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java
+++ b/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java
@@ -19,13 +19,11 @@
package org.apache.sling.validation.model.spi;
import java.util.List;
-import java.util.Map;
import javax.annotation.Nonnull;
import org.apache.sling.validation.ValidationService;
import org.apache.sling.validation.model.ValidationModel;
-import org.apache.sling.validation.model.ValidatorAndSeverity;
import org.osgi.annotation.versioning.ProviderType;
@@ -42,16 +40,12 @@
* Retrieves the models responsible for validating the given resourceType.
*
* @param relativeResourceType the relative resource (relative to one of the resource resolver's search paths)
- * @param validatorsMap
- * all known validators in a map (key=id of validator). Only one of those should be used in the
- * returned validation models.
* @return a List of {@link ValidationModel}s. Never {@code null}, but might be empty collection in case no
* model for the given resource type could be found. The order which model gets active is mostly determined by {@link ValidationModel#getApplicablePaths()} (longest path match wins)
* but in case there are multiple models having the same applicable path, the order being returned here is considered (i.e. the first one is taken).
* @throws IllegalStateException
* in case a validation model was found but it is invalid
*/
- @Nonnull List<ValidationModel> getModels(@Nonnull String relativeResourceType,
- @Nonnull Map<String, ValidatorAndSeverity<?>> validatorsMap) throws IllegalStateException;
+ @Nonnull List<ValidationModel> getValidationModels(@Nonnull String relativeResourceType) throws IllegalStateException;
}
diff --git a/src/main/java/org/apache/sling/validation/model/spi/ValidationModelRetriever.java b/src/main/java/org/apache/sling/validation/model/spi/ValidationModelRetriever.java
new file mode 100644
index 0000000..c75822d
--- /dev/null
+++ b/src/main/java/org/apache/sling/validation/model/spi/ValidationModelRetriever.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.sling.validation.model.spi;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.sling.validation.model.ValidationModel;
+import org.osgi.annotation.versioning.ProviderType;
+
+/** Retrieves the validation model. */
+@ProviderType
+public interface ValidationModelRetriever {
+ /**
+ * A validation model for the given resourceType at the given resourcePath
+ * @param resourceType the resource type for which to retrieve the model
+ * @param resourcePath may be {@code null} or empty
+ * @param considerResourceSuperTypeModels {@code true} if a merged validation model considering even the models of the super resource types should be returned, otherwise {@code false}
+ * @return a validation model which should be used for validation or {@code null}, if no validation model could be found
+ * @throws IllegalStateException in case some error occurred during looking up models
+ */
+ public @CheckForNull ValidationModel getValidationModel(@Nonnull String resourceType, String resourcePath, boolean considerResourceSuperTypeModels);
+}
diff --git a/src/main/java/org/apache/sling/validation/spi/Validator.java b/src/main/java/org/apache/sling/validation/spi/Validator.java
index e54cebc..08491f9 100644
--- a/src/main/java/org/apache/sling/validation/spi/Validator.java
+++ b/src/main/java/org/apache/sling/validation/spi/Validator.java
@@ -73,7 +73,7 @@
* @return the validation result (encapsulates the validation status as well as messages).
* @throws SlingValidationException if some expected arguments are missing from the arguments map
*/
- @Nonnull ValidationResult validate(@Nonnull T data, @Nonnull ValidationContext context, @Nonnull ValueMap arguments) throws SlingValidationException;
+ @Nonnull ValidationResult validate(@Nonnull T data, @Nonnull ValidatorContext context, @Nonnull ValueMap arguments) throws SlingValidationException;
/**
* Each {@link Validator} must have a service property with name {@code validator.id} of type {@link String}. The validators are only addressable via the value of this property
@@ -83,7 +83,7 @@
String PROPERTY_VALIDATOR_ID = "validator.id";
/***
- * Each {@link Validator} may have a service property with name {@code validator.severity} of type {@link String}. This is taken as the severity of all
+ * Each {@link Validator} may have a service property with name {@code validator.severity} of type {@link Integer}. This is taken as the severity of all
* {@link ValidationFailure}s constructed by this {@link Validator} in case the model has not overwritten the severity.
* If this property is not set the default severity is being used.
*/
diff --git a/src/main/java/org/apache/sling/validation/spi/ValidationContext.java b/src/main/java/org/apache/sling/validation/spi/ValidatorContext.java
similarity index 94%
rename from src/main/java/org/apache/sling/validation/spi/ValidationContext.java
rename to src/main/java/org/apache/sling/validation/spi/ValidatorContext.java
index 73d4fd2..f7ddb7f 100644
--- a/src/main/java/org/apache/sling/validation/spi/ValidationContext.java
+++ b/src/main/java/org/apache/sling/validation/spi/ValidatorContext.java
@@ -30,14 +30,14 @@
/**
- * Used as parameter for each call of {@link Validator#validate(Object, ValidationContext, ValueMap)}
+ * Used as parameter for each call of {@link Validator#validate(Object, ValidatorContext, ValueMap)}
* Exposes additional information about the context in which the validation was called.
*/
@ProviderType
-public interface ValidationContext {
+public interface ValidatorContext {
/**
- * @return the relative location of the property which should be checked by the validator. Refers to the 'data' parameter of {@link Validator#validate(Object, ValidationContext, ValueMap)}
+ * @return the relative location of the property which should be checked by the validator. Refers to the 'data' parameter of {@link Validator#validate(Object, ValidatorContext, ValueMap)}
*/
@Nonnull String getLocation();
diff --git a/src/main/java/org/apache/sling/validation/spi/DefaultValidationFailure.java b/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationFailure.java
similarity index 95%
rename from src/main/java/org/apache/sling/validation/spi/DefaultValidationFailure.java
rename to src/main/java/org/apache/sling/validation/spi/support/DefaultValidationFailure.java
index e916e3c..2c1b887 100644
--- a/src/main/java/org/apache/sling/validation/spi/DefaultValidationFailure.java
+++ b/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationFailure.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.validation.spi;
+package org.apache.sling.validation.spi.support;
import java.io.Serializable;
import java.text.MessageFormat;
@@ -26,6 +26,7 @@
import javax.annotation.Nonnull;
import org.apache.sling.validation.ValidationFailure;
+import org.apache.sling.validation.spi.ValidatorContext;
import org.osgi.annotation.versioning.ProviderType;
/**
@@ -51,7 +52,7 @@
* @param messageKey the key to look up in the resource bundle
* @param messageArguments the arguments to be used with the looked up value from the resource bundle (given in {@link #getMessage(ResourceBundle)}
*/
- public DefaultValidationFailure(@Nonnull ValidationContext validationContext, @Nonnull String messageKey, Object... messageArguments) {
+ public DefaultValidationFailure(@Nonnull ValidatorContext validationContext, @Nonnull String messageKey, Object... messageArguments) {
this.location = validationContext.getLocation();
this.severity = validationContext.getSeverity();
this.defaultResourceBundle = validationContext.getDefaultResourceBundle();
diff --git a/src/main/java/org/apache/sling/validation/spi/DefaultValidationResult.java b/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationResult.java
similarity index 94%
rename from src/main/java/org/apache/sling/validation/spi/DefaultValidationResult.java
rename to src/main/java/org/apache/sling/validation/spi/support/DefaultValidationResult.java
index e9053e7..9d5f24e 100644
--- a/src/main/java/org/apache/sling/validation/spi/DefaultValidationResult.java
+++ b/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationResult.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.validation.spi;
+package org.apache.sling.validation.spi.support;
import java.io.Serializable;
import java.text.MessageFormat;
@@ -29,6 +29,7 @@
import org.apache.sling.validation.ValidationFailure;
import org.apache.sling.validation.ValidationResult;
+import org.apache.sling.validation.spi.ValidatorContext;
import org.osgi.annotation.versioning.ProviderType;
/**
@@ -57,7 +58,7 @@
* @param messageKey the message key used for looking up a value in the resource bundle given in {@link ValidationFailure#getMessage(java.util.ResourceBundle)}
* @param messageArguments optional number of arguments being used in {@link MessageFormat#format(String, Object...)}
*/
- public DefaultValidationResult(@Nonnull ValidationContext validationContext, @Nonnull String messageKey, Object... messageArguments) {
+ public DefaultValidationResult(@Nonnull ValidatorContext validationContext, @Nonnull String messageKey, Object... messageArguments) {
this.isValid = false;
this.failures = Collections.<ValidationFailure>singletonList(new DefaultValidationFailure(validationContext, messageKey, messageArguments));
}
diff --git a/src/main/java/org/apache/sling/validation/spi/support/package-info.java b/src/main/java/org/apache/sling/validation/spi/support/package-info.java
new file mode 100644
index 0000000..08e543f
--- /dev/null
+++ b/src/main/java/org/apache/sling/validation/spi/support/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+@Version("1.0.0")
+package org.apache.sling.validation.spi.support;
+
+import org.osgi.annotation.versioning.Version;