You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/08/11 01:07:25 UTC
incubator-tamaya git commit: Implemented validation model extension.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 7011d5de0 -> bc58374b3
Implemented validation model extension.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/bc58374b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/bc58374b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/bc58374b
Branch: refs/heads/master
Commit: bc58374b38d3d9154d2bee9d7aa2cfb8d87a949c
Parents: 7011d5d
Author: anatole <an...@apache.org>
Authored: Tue Aug 11 01:06:50 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Aug 11 01:06:50 2015 +0200
----------------------------------------------------------------------
sandbox/model/pom.xml | 4 +
.../org/apache/tamaya/model/ConfigModel.java | 37 ----
.../apache/tamaya/model/ConfigParameter.java | 40 ----
.../org/apache/tamaya/model/ConfigSection.java | 87 ---------
.../tamaya/model/ConfigValidationResult.java | 117 ------------
.../apache/tamaya/model/ConfigValidator.java | 58 +++++-
.../java/org/apache/tamaya/model/Validated.java | 63 -------
.../org/apache/tamaya/model/Validation.java | 66 +++++++
.../apache/tamaya/model/ValidationResult.java | 170 +++++++++++++++--
.../apache/tamaya/model/ValidationState.java | 59 ++++++
.../ConfiguredValidationProviderSpi.java | 188 +++++++++++++++++++
.../tamaya/model/spi/AbstractValidation.java | 48 +++++
.../apache/tamaya/model/spi/AreaValidation.java | 138 ++++++++++++++
.../tamaya/model/spi/ParameterValidation.java | 153 +++++++++++++++
.../tamaya/model/spi/ValidationGroup.java | 97 ++++++++++
.../tamaya/model/spi/ValidationProviderSpi.java | 39 ++++
...pache.tamaya.model.spi.ValidationProviderSpi | 19 ++
.../model/TestConfigValidationProvider.java | 49 +++++
.../apache/tamaya/model/ValidationTests.java | 24 +++
.../META-INF/configmodel/configmodel.properties | 96 ++++++++++
.../META-INF/javaconfiguration.properties | 22 +++
...pache.tamaya.model.spi.ValidationProviderSpi | 19 ++
.../src/test/resources/examples/configmodel.ini | 2 +-
.../resources/examples/configmodel.properties | 93 +++++++++
.../src/test/resources/examples/configmodel.xml | 2 +-
.../test/resources/examples/configmodel.yaml | 4 +-
26 files changed, 1321 insertions(+), 373 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/model/pom.xml b/sandbox/model/pom.xml
index dc63da1..29484d9 100644
--- a/sandbox/model/pom.xml
+++ b/sandbox/model/pom.xml
@@ -47,6 +47,10 @@ under the License.
<version>0.1-incubating-SNAPSHOT</version>
<scope>Test</scope>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigModel.java b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
deleted file mode 100644
index b5d96d6..0000000
--- a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
+++ /dev/null
@@ -1,37 +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.tamaya.model;
-
-import java.util.Collection;
-
-/**
- * Model of a configuration state. A model can be a full model, or a partial model, validating only
- * a configuration subset. This allows better user feedback because big configurations can be grouped
- * and validated by multiple (partial) models.
- */
-public interface ConfigModel extends Validated {
-
- /**
- * Get the sections defined.
- *
- * @return the sections defined, never null.
- */
- Collection<ConfigSection> getSections();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigParameter.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigParameter.java b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigParameter.java
deleted file mode 100644
index e54af21..0000000
--- a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigParameter.java
+++ /dev/null
@@ -1,40 +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.tamaya.model;
-
-
-/**
- * Interface describing a configuration parameter.
- */
-public interface ConfigParameter extends Validated {
-
- /**
- * Flag if the item is required.
- *
- * @return true, if the item is required.
- */
- boolean isRequired();
-
- /**
- * Get the containing parent section.
- *
- * @return the parent secion, or null, if there is no parent.
- */
- ConfigSection getParent();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigSection.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigSection.java b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigSection.java
deleted file mode 100644
index fd36c59..0000000
--- a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigSection.java
+++ /dev/null
@@ -1,87 +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.tamaya.model;
-
-import java.util.Collection;
-
-/**
- * Interface describing a configuration section.
- */
-public interface ConfigSection extends Validated {
- /**
- * Get all parameters contained in the given section.
- *
- * @return the parameters, not null.
- */
- Collection<ConfigParameter> getParameters();
-
- /**
- * Get all parameters contained in the given section.
- *
- * @param recursive if true, traverse down the subtree and collect all parameters found.
- * @return the parameters, not null.
- */
- Collection<ConfigParameter> getParameters(boolean recursive);
-
- /**
- * Get a parameter by name.
- *
- * @param name the parameter name.
- * @return the parameter found, or null.
- */
- ConfigParameter getParameter(String name);
-
- /**
- * Get all child section (non recursive).
- *
- * @return all child sections, never null.
- */
- Collection<ConfigSection> getChildSections();
-
- /**
- * Get a child section by name (non recursive).
- *
- * @param name the section's name.
- * @return the section found, or null.
- */
- ConfigSection getSection(String name);
-
- /**
- * Get a section by name/path. The section path can be relative (first lookup)
- * or absolute.
- *
- * @param name the section's name/path.
- * @return the section found, or null.
- */
- ConfigSection lookupSection(String name);
-
- /**
- * Flag if the item is required.
- *
- * @return true, if the item is required.
- */
- boolean isRequired();
-
- /**
- * Get the containing parent section.
- *
- * @return the parent secion, or null, if there is no parent.
- */
- ConfigSection getParent();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigValidationResult.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigValidationResult.java b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigValidationResult.java
deleted file mode 100644
index f642740..0000000
--- a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigValidationResult.java
+++ /dev/null
@@ -1,117 +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.tamaya.model;
-
-import java.util.Objects;
-
-/**
- * Models a partial configuration validation result.
- */
-public class ConfigValidationResult {
- /**
- * the config section.
- */
- private ConfigSection section;
- /**
- * the config parameter (may be null).
- */
- private ConfigParameter parameter;
- /**
- * The validation result.
- */
- private ValidationResult result;
- /**
- * The validation message.
- */
- private String message;
-
- /**
- * Constructor.
- *
- * @param section the section, not null.
- * @param parameter the corresponding parameter, or null.
- * @param result the validation result, not null.
- * @param message the detail message.
- */
- public ConfigValidationResult(ConfigSection section, ConfigParameter parameter, ValidationResult result, String message) {
- this.message = message;
- this.parameter = parameter;
- this.section = Objects.requireNonNull(section);
- this.result = Objects.requireNonNull(result);
- }
-
- /**
- * Constructor.
- *
- * @param section the section, not null.
- * @param result the validation result, not null.
- * @param message the detail message.
- */
- public ConfigValidationResult(ConfigSection section, ValidationResult result, String message) {
- this.message = message;
- this.section = Objects.requireNonNull(section);
- this.result = Objects.requireNonNull(result);
- }
-
- /**
- * Get the validated section.
- *
- * @return the section, never null.
- */
- public ConfigSection getSection() {
- return section;
- }
-
- /**
- * Get the validated parameter.
- *
- * @return the parameter, or null.
- */
- public ConfigParameter getParameter() {
- return parameter;
- }
-
- /**
- * Get the validation result.
- *
- * @return the result, never null.
- */
- public ValidationResult getResult() {
- return result;
- }
-
- /**
- * Get the detail message.
- *
- * @return the detail message, or null.
- */
- public String getMessage() {
- return message;
- }
-
- @Override
- public String toString() {
- return "ConfigValidationResult{" +
- "section=" + section +
- ", parameter=" + parameter +
- ", result=" + result +
- ", message='" + message + '\'' +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigValidator.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigValidator.java b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigValidator.java
index 621675b..c2f029d 100644
--- a/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigValidator.java
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/ConfigValidator.java
@@ -20,11 +20,14 @@ package org.apache.tamaya.model;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.model.spi.ValidationProviderSpi;
import org.apache.tamaya.spi.ServiceContextManager;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* Validator accessor to validate the current configuration.
@@ -38,12 +41,44 @@ public final class ConfigValidator {
}
/**
+ * Get the sections defined.
+ *
+ * @return the sections defined, never null.
+ */
+ public static Collection<Validation> getValidations() {
+ List<Validation> result = new ArrayList<>();
+ for (ValidationProviderSpi model : ServiceContextManager.getServiceContext().getServices(ValidationProviderSpi.class)) {
+ result.addAll(model.getValidations());
+ }
+ return result;
+ }
+
+ /**
+ * Validates the current configuration.
+ *
+ * @return the validation results, never null.
+ */
+ public static Collection<ValidationResult> validate() {
+ return validate(false);
+ }
+
+ /**
* Validates the current configuration.
+ * @param showUndefined show any unknown parameters.
+ * @return the validation results, never null.
+ */
+ public static Collection<ValidationResult> validate(boolean showUndefined) {
+ return validate(ConfigurationProvider.getConfiguration(), showUndefined);
+ }
+
+ /**
+ * Validates the given configuration.
*
+ * @param config the configuration to be validated against, not null.
* @return the validation results, never null.
*/
- public static Collection<ConfigValidationResult> validate() {
- return validate(ConfigurationProvider.getConfiguration());
+ public static Collection<ValidationResult> validate(Configuration config) {
+ return validate(config, false);
}
/**
@@ -52,10 +87,21 @@ public final class ConfigValidator {
* @param config the configuration to be validated against, not null.
* @return the validation results, never null.
*/
- public static Collection<ConfigValidationResult> validate(Configuration config) {
- List<ConfigValidationResult> result = new ArrayList<>();
- for (ConfigModel model : ServiceContextManager.getServiceContext().getServices(ConfigModel.class)) {
- result.addAll(model.validate(config));
+ public static Collection<ValidationResult> validate(Configuration config, boolean showUndefined) {
+ List<ValidationResult> result = new ArrayList<>();
+ for (Validation defConf : getValidations()) {
+ result.addAll(defConf.validate(config));
+ }
+ if(showUndefined){
+ Map<String,String> map = new HashMap<>(config.getProperties());
+ for (Validation defConf : getValidations()) {
+ if("Parameter".equals(defConf.getType())){
+ map.remove(defConf.getName());
+ }
+ }
+ for(Map.Entry<String,String> entry:map.entrySet()){
+ result.add(ValidationResult.ofUndefined(entry.getKey()));
+ }
}
return result;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/Validated.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/Validated.java b/sandbox/model/src/main/java/org/apache/tamaya/model/Validated.java
deleted file mode 100644
index 6afac71..0000000
--- a/sandbox/model/src/main/java/org/apache/tamaya/model/Validated.java
+++ /dev/null
@@ -1,63 +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.tamaya.model;
-
-import org.apache.tamaya.Configuration;
-
-import java.util.Collection;
-
-/**
- * Basis structure describing a validated item, by default a parameter or a section.
- */
-public interface Validated {
- /**
- * Get the item's type.
- *
- * @return the type, never null.
- */
- String getType();
-
- /**
- * Get the item's fully qualified name. This name is - in combination with the {@link getType()} - unique.
- */
- String getName();
-
- /**
- * Get an optional description of the item, using the default locale.
- *
- * @return the description required, or null.
- */
- String getDescription();
-
- /**
- * Validates the item and all its children against the current configuration.
- *
- * @return the validation results, never null.
- */
- Collection<ConfigValidationResult> validate();
-
- /**
- * Validates the item and all its children against the given configuration.
- *
- * @param config the configuration to be validated against, not null.
- * @return the validation results, never null.
- */
- Collection<ConfigValidationResult> validate(Configuration config);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/Validation.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/Validation.java b/sandbox/model/src/main/java/org/apache/tamaya/model/Validation.java
new file mode 100644
index 0000000..a262070
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/Validation.java
@@ -0,0 +1,66 @@
+/*
+ * 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.tamaya.model;
+
+import org.apache.tamaya.Configuration;
+
+import java.util.Collection;
+
+/**
+ * Basis structure describing a validated item, by default a parameter or a section.
+ */
+public interface Validation {
+
+
+ /**
+ * Get the type of item that is validated by a validation.
+ * @return the validted type, never null.
+ */
+ String getType();
+
+ /**
+ * Get the item's name, it should minimally describe the validation. Examples are:
+ * <pre>
+ * Area: a.b.c
+ * Params: a.b.c:paramName
+ * Filter: a.b.c.FilterImplClass
+ * Dependency: mydep
+ * CombinationPolicy: a.b.c.MyCombinationPolicyClass
+ * </pre>
+ */
+ String getName();
+
+ /**
+ * Get an description of the item, using the default locale. The description is basically optional
+ * though it is higly recommended to provide a description, so the validation issues is well
+ * resolvable.
+ *
+ * @return the description required, or null.
+ */
+ String getDescription();
+
+ /**
+ * Validates the item and all its children against the given configuration.
+ *
+ * @param config the configuration to be validated against, not null.
+ * @return the validation results, never null.
+ */
+ Collection<ValidationResult> validate(Configuration config);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/ValidationResult.java b/sandbox/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
index 44baf4e..1970512 100644
--- a/sandbox/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
@@ -18,42 +18,174 @@
*/
package org.apache.tamaya.model;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.model.spi.AbstractValidation;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+
/**
- * Enum type describing the different validation results supported.
+ * Models a partial configuration validation result.
*/
-public enum ValidationResult {
+public final class ValidationResult {
+ /**
+ * the config section.
+ */
+ private Validation validation;
+ /**
+ * The validation result.
+ */
+ private ValidationState result;
+ /**
+ * The validation message.
+ */
+ private String message;
+
+ /**
+ * Creates a new ValidationResult.
+ *
+ * @param validation the validation item, not null.
+ */
+ public static ValidationResult ofValid(Validation validation) {
+ return new ValidationResult(validation, ValidationState.VALID, null);
+ }
+
/**
- * The validated item is valid
+ * Creates a new ValidationResult.
+ *
+ * @param validation the validation item, not null.
*/
- VALID,
+ public static ValidationResult ofMissing(Validation validation) {
+ return new ValidationResult(validation, ValidationState.MISSING, null);
+ }
+
+
/**
- * The validated item is deprecated.
+ * Creates a new ValidationResult.
+ *
+ * @param validation the validation item, not null.
+ * @param message Additional message to be shown (optional).
*/
- DEPRECATED,
+ public static ValidationResult ofMissing(Validation validation, String message) {
+ return new ValidationResult(validation, ValidationState.MISSING, message);
+ }
+
/**
- * The validated item is correct, but the value is worth a warning.
+ * Creates a new ValidationResult.
+ *
+ * @param validation the validation item, not null.
*/
- WARNING,
+ public static ValidationResult ofError(Validation validation, String error) {
+ return new ValidationResult(validation, ValidationState.ERROR, error);
+ }
+
/**
- * The given section or parameter is not a defined/validated item. It may be still valid, but typically,
- * when validation is fully implemented, such a parametr or section should be removed.
+ * Creates a new ValidationResult.
+ *
+ * @param validation the validation item, not null.
*/
- UNDEFIEND,
+ public static ValidationResult ofWarning(Validation validation, String warning) {
+ return new ValidationResult(validation, ValidationState.WARNING, warning);
+ }
+
/**
- * A required parameter or section is missing.
+ * Creates a new ValidationResult.
+ *
+ * @param validation the validation item, not null.
*/
- MISSING,
+ public static ValidationResult ofDeprecated(Validation validation, String alternateUsage) {
+ return new ValidationResult(validation, ValidationState.DEPRECATED, alternateUsage != null ? "Use instead: " + alternateUsage : null);
+ }
+
/**
- * The validated item has an invalid value.
+ * Creates a new ValidationResult.
+ *
+ * @param validation the validation item, not null.
*/
- ERROR;
+ public static ValidationResult ofDeprecated(Validation validation) {
+ return new ValidationResult(validation, ValidationState.DEPRECATED, null);
+ }
/**
- * Method to quickly evaluate if the current state is an error state.
+ * Creates a new ValidationResult.
*
- * @return true, if the state is not ERROR or MISSING.
+ * @param key the name/key
+ * @return a corresponding validation item
*/
- boolean isError() {
- return this.ordinal() == MISSING.ordinal() || this.ordinal() == ERROR.ordinal();
+ public static ValidationResult ofUndefined(final String key) {
+ return new ValidationResult(new AbstractValidation(key, "Undefined key: " + key) {
+
+ @Override
+ public String getType() {
+ return "<undefined>";
+ }
+
+ @Override
+ public Collection<ValidationResult> validate(Configuration config) {
+ return Collections.emptySet();
+ }
+ }, ValidationState.UNDEFINED, null);
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param validation the validation item, not null.
+ * @param result the validation result, not null.
+ * @param message the detail message.
+ */
+ public static ValidationResult of(Validation validation, ValidationState result, String message) {
+ return new ValidationResult(validation, result, message);
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param validation the validation item, not null.
+ * @param result the validation result, not null.
+ * @param message the detail message.
+ */
+ private ValidationResult(Validation validation, ValidationState result, String message) {
+ this.message = message;
+ this.validation = Objects.requireNonNull(validation);
+ this.result = Objects.requireNonNull(result);
+ }
+
+ /**
+ * Get the validation section.
+ *
+ * @return the section, never null.
+ */
+ public Validation getValidation() {
+ return validation;
+ }
+
+ /**
+ * Get the validation result.
+ *
+ * @return the result, never null.
+ */
+ public ValidationState getResult() {
+ return result;
+ }
+
+ /**
+ * Get the detail message.
+ *
+ * @return the detail message, or null.
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ @Override
+ public String toString() {
+ if (message != null) {
+ return result + ": " + validation.getName() + " (" + validation.getType() + ") -> " + message + '\n';
+ }
+ return result + ": " + validation.getName() + " (" + validation.getType() + ")";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/ValidationState.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/ValidationState.java b/sandbox/model/src/main/java/org/apache/tamaya/model/ValidationState.java
new file mode 100644
index 0000000..0170085
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/ValidationState.java
@@ -0,0 +1,59 @@
+/*
+ * 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.tamaya.model;
+
+/**
+ * Enum type describing the different validation results supported.
+ */
+public enum ValidationState {
+ /**
+ * The validated item is valid
+ */
+ VALID,
+ /**
+ * The validated item is deprecated.
+ */
+ DEPRECATED,
+ /**
+ * The validated item is correct, but the value is worth a warning.
+ */
+ WARNING,
+ /**
+ * The given section or parameter is not a defined/validated item. It may be still valid, but typically,
+ * when validation is fully implemented, such a parametr or section should be removed.
+ */
+ UNDEFINED,
+ /**
+ * A required parameter or section is missing.
+ */
+ MISSING,
+ /**
+ * The validated item has an invalid value.
+ */
+ ERROR;
+
+ /**
+ * Method to quickly evaluate if the current state is an error state.
+ *
+ * @return true, if the state is not ERROR or MISSING.
+ */
+ boolean isError() {
+ return this.ordinal() == MISSING.ordinal() || this.ordinal() == ERROR.ordinal();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredValidationProviderSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredValidationProviderSpi.java b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredValidationProviderSpi.java
new file mode 100644
index 0000000..a3f77b8
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredValidationProviderSpi.java
@@ -0,0 +1,188 @@
+package org.apache.tamaya.model.internal;
+
+import org.apache.tamaya.model.Validation;
+import org.apache.tamaya.model.spi.AreaValidation;
+import org.apache.tamaya.model.spi.ParameterValidation;
+import org.apache.tamaya.model.spi.ValidationProviderSpi;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Validation provider that reads model metadata from property files with the following format:
+ * <pre>
+ * ###################################################################################
+ * # Example of a configuration metamodel expressed via properties.
+ * ####################################################################################
+ *
+ * # Metamodel information
+ * [model].provider=ConfigModel Extension
+ *
+ * # reusable parameter definition, referenceable as MyNumber
+ * [MyNumber].class=Parameter
+ * [MyNumber].type=Integer
+ * [MyNumber].description=a (reusable) number type parameter (optional)
+ *
+ * ####################################################################################
+ * # Description of Configuration Sections (minimal, can be extended by other modules).
+ * # By default its interpreted as a section !
+ * ####################################################################################
+ *
+ * # a (section)
+ * a.class=Section
+ * a.params2.class=Parameter
+ * a.params2.type=String
+ * a.params2.required=true
+ * a.params2.description=a required parameter
+ *
+ * a.paramInt.class=Parameter
+ * a.paramInt.ref=MyNumber
+ * a.paramInt.description=an optional parameter (default)
+ *
+ * a._number.class=Parameter
+ * a._number.type=Integer
+ * a._number.deprecated=true
+ * a._number.mappedTo=a.paramInt
+ *
+ * # a.b.c (section)
+ * a.b.c.class=Section
+ * a.b.c.description=Just a test section
+ *
+ * # a.b.c.aRequiredSection (section)
+ * a.b.c.aRequiredSection.class=Section
+ * a.b.c.aRequiredSection.required=true
+ * a.b.c.aRequiredSection.description=A section containing required parameters is called a required section.\
+ * Sections can also explicitly be defined to be required, but without\
+ * specifying the paramteres to be contained.,
+ *
+ * # a.b.c.aRequiredSection.subsection (section)
+ * a.b.c.aRequiredSection.subsection.class=Section
+ *
+ * a.b.c.aRequiredSection.subsection.param0.class=Parameter
+ * a.b.c.aRequiredSection.subsection.param0.type=String
+ * a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
+ * # A minmal String parameter
+ * a.b.c.aRequiredSection.subsection.param00.class=Parameter
+ * a.b.c.aRequiredSection.subsection.param00.type=String
+ *
+ * # a.b.c.aRequiredSection.subsection (section)
+ * a.b.c.aRequiredSection.subsection.param1.class=Parameter
+ * a.b.c.aRequiredSection.subsection.param1.type = String
+ * a.b.c.aRequiredSection.subsection.param1.required = true
+ * a.b.c.aRequiredSection.subsection.intParam.class=Parameter
+ * a.b.c.aRequiredSection.subsection.intParam.type = Integer
+ * a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
+ *
+ * # a.b.c.aRequiredSection.nonempty-subsection (section)
+ * a.b.c.aRequiredSection.nonempty-subsection.class=Section
+ * a.b.c.aRequiredSection.nonempty-subsection.required=true
+ *
+ * # a.b.c.aRequiredSection.optional-subsection (section)
+ * a.b.c.aRequiredSection.optional-subsection.class=Section
+ *
+ * # a.b.c.aValidatedSection (section)
+ * a.b.c.aValidatedSection.class=Section
+ * a.b.c.aValidatedSection.description=A validated section.
+ * a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator
+ * </pre>
+ */
+public class ConfiguredValidationProviderSpi implements ValidationProviderSpi {
+
+ private List<Validation> validations = new ArrayList<>();
+
+ public ConfiguredValidationProviderSpi() {
+ try {
+ Enumeration<URL> configs = getClass().getClassLoader().getResources("META-INF/configmodel/configmodel.properties");
+ while (configs.hasMoreElements()) {
+ URL config = configs.nextElement();
+ try (InputStream is = config.openStream()) {
+ Properties props = new Properties();
+ props.load(is);
+ loadValidations(props, config.toString());
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE,
+ "Error loading config metadata from " + config, e);
+ }
+ }
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE,
+ "Error loading config metadata from META-INF/configmodel/configmodel.properties", e);
+ }
+ validations = Collections.unmodifiableList(validations);
+ }
+
+ private void loadValidations(Properties props, String resource) {
+ String provider = props.getProperty("[model].provider");
+ if (provider == null) {
+ provider = resource;
+ }
+ Set<String> itemKeys = new HashSet<>();
+ for (Object key : props.keySet()) {
+ if (key.toString().endsWith(".class")) {
+ itemKeys.add(key.toString().substring(0, key.toString().length() - ".class".length()));
+ }
+ }
+ for (String baseKey : itemKeys) {
+ String clazz = props.getProperty(baseKey + ".class");
+ String type = props.getProperty(baseKey + ".type");
+ if(type==null){
+ type = String.class.getName();
+ }
+ String description = props.getProperty(baseKey + ".description");
+ String regEx = props.getProperty(baseKey + ".expression");
+ String validations = props.getProperty(baseKey + ".validations");
+ String requiredVal = props.getProperty(baseKey + ".required");
+ if ("Parameter".equalsIgnoreCase(clazz)) {
+ initParameter(baseKey, description, type, requiredVal, regEx, validations);
+ } else if ("Section".equalsIgnoreCase(clazz)) {
+ initSection(baseKey, description, requiredVal, validations);
+ }
+ }
+ }
+
+ private void initParameter(String name, String desc, String type, String reqVal, String regEx, String validations) {
+ boolean required = "true".equalsIgnoreCase(reqVal);
+ ParameterValidation.Builder builder = ParameterValidation.builder(name).setRequired(required)
+ .setDescription(desc).setExpression(regEx).setType(type);
+ if (validations != null) {
+ try {
+ // TODO defined validator API
+// builder.addValidations(validations);
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to load validations for " + name, e);
+ }
+ }
+ this.validations.add(builder.build());
+ }
+
+ private void initSection(String name, String desc, String reqVal, String validations) {
+ boolean required = "true".equalsIgnoreCase(reqVal);
+ AreaValidation.Builder builder = AreaValidation.builder(name).setRequired(required)
+ .setDescription(desc);
+ if (validations != null) {
+ try {
+ // TODO defined validator API
+// builder.addValidations(validations);
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to load validations for " + name, e);
+ }
+ }
+ this.validations.add(builder.build());
+ }
+
+
+ @Override
+ public Collection<Validation> getValidations() {
+ return validations;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/AbstractValidation.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/spi/AbstractValidation.java b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/AbstractValidation.java
new file mode 100644
index 0000000..4bc159a
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/AbstractValidation.java
@@ -0,0 +1,48 @@
+/*
+ * 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.tamaya.model.spi;
+
+import org.apache.tamaya.model.Validation;
+
+import java.util.Objects;
+
+/**
+ * Default configuration Model for a configuration area.
+ */
+public abstract class AbstractValidation implements Validation {
+
+ private String name;
+ private String description;
+
+ protected AbstractValidation(String name, String description) {
+ this.name = Objects.requireNonNull(name);
+ this.description = description;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/AreaValidation.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/spi/AreaValidation.java b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/AreaValidation.java
new file mode 100644
index 0000000..239178c
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/AreaValidation.java
@@ -0,0 +1,138 @@
+/*
+ * 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.tamaya.model.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.model.ValidationResult;
+import org.apache.tamaya.model.Validation;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Default configuration Model for a configuration area.
+ */
+public class AreaValidation extends ValidationGroup {
+
+ private boolean required = false;
+
+ public static Builder builder(String name){
+ return new Builder(name);
+ }
+
+ public static Validation of(String name, boolean required){
+ return new Builder(name).setRequired(required).build();
+ }
+
+ public static Validation of(String name, boolean required, Validation... validations){
+ return new Builder(name).setRequired(required).addValidations(validations).build();
+ }
+
+ protected AreaValidation(Builder builder) {
+ super(builder.name, builder.childValidations);
+ this.required = builder.required;
+ }
+
+ @Override
+ public String getType(){
+ return "Area";
+ }
+
+ @Override
+ public Collection<ValidationResult> validate(Configuration config) {
+ Map<String,String> map = config.getProperties();
+ String lookupKey = getName() + '.';
+ boolean present = false;
+ for(String key:map.keySet()){
+ if(key.startsWith(lookupKey)){
+ present = true;
+ break;
+ }
+ }
+ List<ValidationResult> result = new ArrayList<>(1);
+ if(required && !present) {
+ result.add(ValidationResult.ofMissing(this));
+ }
+ result.addAll(super.validate(config));
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder b = new StringBuilder();
+ b.append(getType()).append(": " + getName());
+ if(required) {
+ b.append(", required: " + required);
+ }
+ for(Validation val:getValidations()){
+ b.append(", ").append(val.toString());
+ }
+ return b.toString();
+ }
+
+
+ public static class Builder{
+ private String name;
+ private String description;
+ private boolean required;
+ private List<Validation> childValidations = new ArrayList<>();
+
+ public Builder(String areaName){
+ this.name = Objects.requireNonNull(areaName);
+ }
+
+ public Builder addValidations(Validation... validations){
+ this.childValidations.addAll(Arrays.asList(validations));
+ return this;
+ }
+
+ public Builder addValidations(Collection<Validation> validations){
+ this.childValidations.addAll(validations);
+ return this;
+ }
+
+ public Builder addParameter(ParameterValidation parameterConfig){
+ this.childValidations.add(parameterConfig);
+ return this;
+ }
+
+ public Builder setRequired(boolean required){
+ this.required = required;
+ return this;
+ }
+
+ public Builder setDescription(String description){
+ this.description = description;
+ return this;
+ }
+
+ public Builder setName(String name){
+ this.name = Objects.requireNonNull(name);
+ return this;
+ }
+
+ public Validation build(){
+ return new AreaValidation(this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ParameterValidation.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ParameterValidation.java b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ParameterValidation.java
new file mode 100644
index 0000000..72175b8
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ParameterValidation.java
@@ -0,0 +1,153 @@
+/*
+ * 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.tamaya.model.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.model.Validation;
+import org.apache.tamaya.model.ValidationResult;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default configuration Model for a configuration parameter.
+ */
+public class ParameterValidation extends AbstractValidation {
+
+ private boolean required = false;
+ private String regEx;
+ private Class type;
+
+
+ protected ParameterValidation(Builder builder) {
+ super(builder.name, builder.description);
+ this.required = builder.required;
+ this.regEx = builder.regEx;
+ this.type = builder.type;
+ }
+
+ @Override
+ public String getType() {
+ return "Parameter";
+ }
+
+ public Class getParameterType() {
+ return type;
+ }
+
+ @Override
+ public Collection<ValidationResult> validate(Configuration config) {
+ List<ValidationResult> result = new ArrayList<>(1);
+ String configValue = config.get(getName());
+ if (configValue == null && required) {
+ result.add(ValidationResult.ofMissing(this));
+ }
+ if (configValue != null && regEx != null) {
+ if (!configValue.matches(regEx)) {
+ result.add(ValidationResult.ofError(this, "Config value not matching expression: " + regEx + ", was " +
+ configValue));
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder b = new StringBuilder();
+ b.append(getType()).append(": ").append(getName());
+ if (required) {
+ b.append(", required: " + required);
+ }
+ if (regEx != null) {
+ b.append(", expression: " + regEx);
+ }
+ return b.toString();
+ }
+
+ public static Builder builder(String name) {
+ return new Builder(name);
+ }
+
+ public static Validation of(String name, boolean required, String expression) {
+ return new Builder(name).setRequired(required).setExpression(expression).build();
+ }
+
+
+ public static Validation of(String name, boolean required) {
+ return new Builder(name).setRequired(required).build();
+ }
+
+ public static Validation of(String name) {
+ return new Builder(name).setRequired(false).build();
+ }
+
+
+ public static class Builder {
+ private Class type;
+ private String name;
+ private String regEx;
+ private String description;
+ private boolean required;
+
+ public Builder(String name) {
+ this.name = Objects.requireNonNull(name);
+ }
+
+ public Builder setType(String type) {
+ try {
+ this.type = Class.forName(type);
+ } catch (ClassNotFoundException e) {
+ try {
+ this.type = Class.forName("java.lang."+type);
+ } catch (ClassNotFoundException e2) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to load parameter type: " + type, e2);
+ }
+ }
+ return this;
+ }
+
+ public Builder setRequired(boolean required) {
+ this.required = required;
+ return this;
+ }
+
+ public Builder setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public Builder setExpression(String regEx) {
+ this.regEx = regEx;
+ return this;
+ }
+
+ public Builder setName(String name) {
+ this.name = Objects.requireNonNull(name);
+ return this;
+ }
+
+ public Validation build() {
+ return new ParameterValidation(this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ValidationGroup.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ValidationGroup.java b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ValidationGroup.java
new file mode 100644
index 0000000..5c6ddca
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ValidationGroup.java
@@ -0,0 +1,97 @@
+/*
+ * 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.tamaya.model.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.model.Validation;
+import org.apache.tamaya.model.ValidationResult;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Default configuration Model for a configuration area.
+ */
+public class ValidationGroup implements Validation {
+
+ private String name;
+ private List<Validation> childValidations = new ArrayList<>();
+
+ public ValidationGroup(String name, Validation... validations){
+ this(name, Arrays.asList(validations));
+ }
+
+ public ValidationGroup(Collection<Validation> validations){
+ this("", validations);
+ }
+
+ public ValidationGroup(Validation... validations){
+ this("", Arrays.asList(validations));
+ }
+
+ protected ValidationGroup(String name, Collection<Validation> validations) {
+ this.name = Objects.requireNonNull(name);
+ this.childValidations.addAll(validations);
+ this.childValidations = Collections.unmodifiableList(childValidations);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getType() {
+ return "Group";
+ }
+
+ @Override
+ public String getDescription() {
+ StringBuilder b = new StringBuilder();
+ for(Validation val:childValidations){
+ b.append(" >> " + val);
+ }
+ return b.toString();
+ }
+
+ public Collection<Validation> getValidations(){
+ return childValidations;
+ }
+
+ @Override
+ public Collection<ValidationResult> validate(Configuration config) {
+ List<ValidationResult> result = new ArrayList<>(1);
+ for(Validation child: childValidations){
+ result.addAll(child.validate(config));
+ }
+ return result;
+ }
+
+ @Override
+ public String toString(){
+ StringBuilder b = new StringBuilder();
+ b.append(getType()).append(", size: ").append(childValidations.size()).append(": ").append(getDescription());
+ return b.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ValidationProviderSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ValidationProviderSpi.java b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ValidationProviderSpi.java
new file mode 100644
index 0000000..edb795c
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ValidationProviderSpi.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.tamaya.model.spi;
+
+import org.apache.tamaya.model.Validation;
+
+import java.util.Collection;
+
+/**
+ * Model of a configuration state. A model can be a full model, or a partial model, validating only
+ * a configuration subset. This allows better user feedback because big configurations can be grouped
+ * and validated by multiple (partial) models.
+ */
+public interface ValidationProviderSpi {
+
+ /**
+ * Get the validation defined.
+ *
+ * @return the sections defined, never null.
+ */
+ Collection<Validation> getValidations();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi b/sandbox/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
new file mode 100644
index 0000000..e2ba992
--- /dev/null
+++ b/sandbox/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.apache.tamaya.model.internal.ConfiguredValidationProviderSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/test/java/org/apache/tamaya/model/TestConfigValidationProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/java/org/apache/tamaya/model/TestConfigValidationProvider.java b/sandbox/model/src/test/java/org/apache/tamaya/model/TestConfigValidationProvider.java
new file mode 100644
index 0000000..f0d24f6
--- /dev/null
+++ b/sandbox/model/src/test/java/org/apache/tamaya/model/TestConfigValidationProvider.java
@@ -0,0 +1,49 @@
+package org.apache.tamaya.model;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.model.spi.AreaValidation;
+import org.apache.tamaya.model.spi.ParameterValidation;
+import org.apache.tamaya.model.spi.ValidationGroup;
+import org.apache.tamaya.model.spi.ValidationProviderSpi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Created by Anatole on 09.08.2015.
+ */
+public class TestConfigValidationProvider implements ValidationProviderSpi{
+
+ private List<Validation> validations = new ArrayList<>(1);
+
+ public TestConfigValidationProvider(){
+ validations.add(new TestConfigValidation());
+ validations = Collections.unmodifiableList(validations);
+ }
+
+ @Override
+ public Collection<Validation> getValidations() {
+ return validations;
+ }
+
+ private static final class TestConfigValidation extends ValidationGroup{
+
+ public TestConfigValidation(){
+ super("TestConfig", new AreaValidation.Builder("a.test.existing").setRequired(true).build(),
+ ParameterValidation.of("a.test.existing.aParam", true),
+ ParameterValidation.of("a.test.existing.optionalParam"),
+ ParameterValidation.of("a.test.existing.aABCParam", false, "[ABC].*"),
+ new AreaValidation.Builder("a.test.notexisting").setRequired(true).build(),
+ ParameterValidation.of("a.test.notexisting.aParam", true),
+ ParameterValidation.of("a.test.notexisting.optionalParam"),
+ ParameterValidation.of("a.test.existing.aABCParam2", false, "[ABC].*"));
+ }
+ @Override
+ public String getName() {
+ return "TestConfigValidation";
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/test/java/org/apache/tamaya/model/ValidationTests.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/java/org/apache/tamaya/model/ValidationTests.java b/sandbox/model/src/test/java/org/apache/tamaya/model/ValidationTests.java
new file mode 100644
index 0000000..29c8328
--- /dev/null
+++ b/sandbox/model/src/test/java/org/apache/tamaya/model/ValidationTests.java
@@ -0,0 +1,24 @@
+package org.apache.tamaya.model;
+
+import org.junit.Test;
+
+/**
+ * Created by Anatole on 10.08.2015.
+ */
+public class ValidationTests {
+
+ @Test
+ public void testDefaults(){
+ System.err.println(ConfigValidator.validate());
+ }
+
+ @Test
+ public void testAllValidations(){
+ System.err.println(ConfigValidator.getValidations());
+ }
+
+ @Test
+ public void testAllValidationsInclUndefined(){
+ System.err.println("Inclusing UNDEFINED: \n" + ConfigValidator.validate(true));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/test/resources/META-INF/configmodel/configmodel.properties
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/META-INF/configmodel/configmodel.properties b/sandbox/model/src/test/resources/META-INF/configmodel/configmodel.properties
new file mode 100644
index 0000000..472abc3
--- /dev/null
+++ b/sandbox/model/src/test/resources/META-INF/configmodel/configmodel.properties
@@ -0,0 +1,96 @@
+#
+# 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 current 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.
+#
+
+###################################################################################
+# Example of a configuration metamodel expressed via properties.
+####################################################################################
+
+# Metamodel information
+[model].provider=ConfigModel Extension
+
+# reusable parameter definition, referenceable as MyNumber
+[MyNumber].class=Parameter
+[MyNumber].type=Integer
+[MyNumber].description=a (reusable) number type parameter (optional)
+
+####################################################################################
+# Description of Configuration Sections (minimal, can be extended by other modules).
+# By default its interpreted as a section !
+####################################################################################
+
+# a (section)
+a.class=Section
+a.params2.class=Parameter
+a.params2.type=String
+a.params2.required=true
+a.params2.description=a required parameter
+
+a.paramInt.class=Parameter
+a.paramInt.ref=MyNumber
+a.paramInt.description=an optional parameter (default)
+
+a._number.class=Parameter
+a._number.type=Integer
+a._number.deprecated=true
+a._number.mappedTo=a.paramInt
+
+# a.b.c (section)
+a.b.c.class=Section
+a.b.c.description=Just a test section
+
+# a.b.c.aRequiredSection (section)
+a.b.c.aRequiredSection.class=Section
+a.b.c.aRequiredSection.required=true
+a.b.c.aRequiredSection.description=A section containing required parameters is called a required section.\
+ Sections can also explicitly be defined to be required, but without\
+ specifying the paramteres to be contained.,
+
+# a.b.c.aRequiredSection.subsection (section)
+a.b.c.aRequiredSection.subsection.class=Section
+
+a.b.c.aRequiredSection.subsection.param0.class=Parameter
+a.b.c.aRequiredSection.subsection.param0.type=String
+a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
+# A minmal String parameter
+a.b.c.aRequiredSection.subsection.param00.class=Parameter
+a.b.c.aRequiredSection.subsection.param00.type=String
+
+# a.b.c.aRequiredSection.subsection (section)
+a.b.c.aRequiredSection.subsection.param1.class=Parameter
+a.b.c.aRequiredSection.subsection.param1.type = String
+a.b.c.aRequiredSection.subsection.param1.required = true
+a.b.c.aRequiredSection.subsection.intParam.class=Parameter
+a.b.c.aRequiredSection.subsection.intParam.type = Integer
+a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
+
+# a.b.c.aRequiredSection.nonempty-subsection (section)
+a.b.c.aRequiredSection.nonempty-subsection.class=Section
+a.b.c.aRequiredSection.nonempty-subsection.required=true
+
+# a.b.c.aRequiredSection.optional-subsection (section)
+a.b.c.aRequiredSection.optional-subsection.class=Section
+
+# a.b.c.aValidatedSection (section)
+a.b.c.aValidatedSection.class=Section
+a.b.c.aValidatedSection.description=A validated section.
+a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator
+
+
+
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/META-INF/javaconfiguration.properties b/sandbox/model/src/test/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..b0b8c22
--- /dev/null
+++ b/sandbox/model/src/test/resources/META-INF/javaconfiguration.properties
@@ -0,0 +1,22 @@
+#
+# 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 current 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.
+#
+a.test.existing.aParam=existingValue
+a.test.existing.optionalParam=optionalValue
+a.test.existing.aABCParam=ABCparam
+a.test.existing.aABCParam2=MMM
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi b/sandbox/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
new file mode 100644
index 0000000..45c1b86
--- /dev/null
+++ b/sandbox/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.apache.tamaya.model.TestConfigValidationProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/test/resources/examples/configmodel.ini
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/examples/configmodel.ini b/sandbox/model/src/test/resources/examples/configmodel.ini
index 8f34e18..e5f3c70 100644
--- a/sandbox/model/src/test/resources/examples/configmodel.ini
+++ b/sandbox/model/src/test/resources/examples/configmodel.ini
@@ -91,7 +91,7 @@ class = Section
[a.b.c.aValidatedSection]
class = Section
-description = "A validated section."
+description = "A validation section."
validations = org.apache.tamaya.model.TestValidator?max=3
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/test/resources/examples/configmodel.properties
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/examples/configmodel.properties b/sandbox/model/src/test/resources/examples/configmodel.properties
new file mode 100644
index 0000000..7609511
--- /dev/null
+++ b/sandbox/model/src/test/resources/examples/configmodel.properties
@@ -0,0 +1,93 @@
+#
+# 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 current 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.
+#
+
+###################################################################################
+# Example of a configuration metamodel expressed via properties.
+####################################################################################
+
+# Metamodel information
+[model].class=Meta-model
+[model].name=testmodel
+[model].provider=ConfigModel Extension
+[model].version=1.0
+[model].release-date=2001-01-23
+[model].author=Anatole Tresch
+# [model].format=alternate format reader type
+[model].comments=Late afternoon is best. Backup contact is Nancy.
+
+# reusable parameter definition, referenceable as MyNumber
+[MyNumber].class=Parameter
+[MyNumber].type=Integer
+[MyNumber].description=a (reusable) number type parameter (optional)
+
+####################################################################################
+# Description of Configuration Sections (minimal, can be extended by other modules).
+# By default its interpreted as a section !
+####################################################################################
+
+# a (section)
+a.class=Section
+a.params2.type=String
+a.params2.required=true
+a.params2.description=a required parameter
+a.paramInt.ref=MyNumber
+a.paramInt.description=an optional parameter (default)
+a._number.type=Integer
+a._number.deprecated=true
+a._number.mappedTo=a.paramInt
+
+# a.b.c (section)
+a.b.c.class=Section
+a.b.c.description=Just a test section
+
+# a.b.c.aRequiredSection (section)
+a.b.c.aRequiredSection.class=Section
+a.b.c.aRequiredSection.required=true
+a.b.c.aRequiredSection.description=A section containing required parameters is called a required section.\
+ Sections can also explicitly be defined to be required, but without\
+ specifying the paramteres to be contained.,
+
+# a.b.c.aRequiredSection.subsection (section)
+a.b.c.aRequiredSection.subsection.class=Section
+a.b.c.aRequiredSection.subsection.param0.type=String
+a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
+# A minmal String parameter
+a.b.c.aRequiredSection.subsection.param00.type = String
+
+# a.b.c.aRequiredSection.subsection (section)
+a.b.c.aRequiredSection.subsection.param1.type = String
+a.b.c.aRequiredSection.subsection.param1.required = true
+a.b.c.aRequiredSection.subsection.intParam.type = Integer
+a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
+
+# a.b.c.aRequiredSection.nonempty-subsection (section)
+a.b.c.aRequiredSection.nonempty-subsection.class=Section
+a.b.c.aRequiredSection.nonempty-subsection.required=true
+
+# a.b.c.aRequiredSection.optional-subsection (section)
+a.b.c.aRequiredSection.optional-subsection.class=Section
+
+# a.b.c.aValidatedSection (section)
+a.b.c.aValidatedSection.class=Section
+a.b.c.aValidatedSection.description=A validated section.
+a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator?max=3
+
+
+
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/test/resources/examples/configmodel.xml
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/examples/configmodel.xml b/sandbox/model/src/test/resources/examples/configmodel.xml
index 13a6de2..bf35f79 100644
--- a/sandbox/model/src/test/resources/examples/configmodel.xml
+++ b/sandbox/model/src/test/resources/examples/configmodel.xml
@@ -94,6 +94,6 @@ under the License.
<a.b.c.aRequiredSection.optional-subsection class="Section"/>
<a.b.c.aRequiredSection.aValidatedSection>
<validations>org.apache.tamaya.model.validation.MaxItemValidator?max=3"</validations>
- <description>A validated section.</description>
+ <description>A validation section.</description>
</a.b.c.aRequiredSection.aValidatedSection>
</model>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc58374b/sandbox/model/src/test/resources/examples/configmodel.yaml
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/examples/configmodel.yaml b/sandbox/model/src/test/resources/examples/configmodel.yaml
index c0fca57..4c9cf12 100644
--- a/sandbox/model/src/test/resources/examples/configmodel.yaml
+++ b/sandbox/model/src/test/resources/examples/configmodel.yaml
@@ -32,7 +32,7 @@ tbd (adapt to others...)
model: {
class : "Metamodel",
name : 'testmodel',
- provider : 'ConfigModel Extension',
+ provider : 'ValidationProviderSpi Extension',
version : '1.0',
release-date : 2001-01-23,
author : 'Anatole Tresch',
@@ -85,7 +85,7 @@ a.b.c.aRequiredSection.optional-subsection: {}
---
a.b.c.aRequiredSection.aValidatedSection: {
- __desc: 'A validated section.',
+ __desc: 'A validation section.',
__validations: 'org.apache.tamaya.model.validation.MaxItemValidator?max=3'
}