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 2018/12/17 19:54:46 UTC
[incubator-tamaya-sandbox] 03/09: Simplified validation module,
leveraging documentation module.
This is an automated email from the ASF dual-hosted git repository.
anatole pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tamaya-sandbox.git
commit ed8701d4d3d95202fe41158e1c2cb462ce12720c
Author: Anatole Tresch <at...@gmail.com>
AuthorDate: Tue Dec 4 18:48:15 2018 +0100
Simplified validation module, leveraging documentation module.
---
.../apache/tamaya/validation/ValidationCheck.java | 194 --------------
validation/pom.xml | 19 +-
.../org/apache/tamaya/validation/ConfigModel.java | 78 ------
.../tamaya/validation/ConfigModelManager.java | 285 ---------------------
.../apache/tamaya/validation/ConfigValidation.java | 122 +++++++++
.../org/apache/tamaya/validation/ModelTarget.java | 37 ---
.../org/apache/tamaya/validation/Validation.java | 203 ---------------
.../apache/tamaya/validation/ValidationCheck.java | 203 +++++++++++++++
.../apache/tamaya/validation/ValidationResult.java | 86 +++++--
.../internal/ConfigDocumentationBean.java | 196 --------------
.../ConfigValidationDocumentationReader.java | 98 +++++++
.../internal/ConfiguredInlineModelProviderSpi.java | 83 ------
.../ConfiguredPropertiesModelProviderSpi.java | 154 -----------
.../ConfiguredResourcesModelProviderSpi.java | 186 --------------
.../ConfiguredTypeEventsModelPopulator.java | 124 ---------
.../ConfiguredTypeEventsModelProvider.java | 51 ----
.../tamaya/validation/spi/AbstractConfigModel.java | 88 -------
.../tamaya/validation/spi/AbstractValidator.java | 107 ++++++++
.../{ParameterModel.java => AreaValidator.java} | 178 ++++++++-----
.../validation/spi/ConfigDocumentationMBean.java | 53 ----
.../tamaya/validation/spi/ConfigModelReader.java | 142 ----------
.../tamaya/validation/spi}/ConfigValidator.java | 15 +-
.../apache/tamaya/validation/spi/GroupModel.java | 110 --------
.../tamaya/validation/spi/ModelProviderSpi.java | 39 ---
...{ParameterModel.java => PropertyValidator.java} | 121 ++++-----
.../validation/spi/RegexPropertyValidator.java | 105 ++++++++
.../apache/tamaya/validation/spi/SectionModel.java | 202 ---------------
.../tamaya/validation/ConfigModelProviderTest.java | 68 -----
.../apache/tamaya/validation/ValidationTests.java | 53 ----
.../internal/ConfigDocumentationBeanTest.java | 108 --------
.../test/java/test/model/TestConfigAccessor.java | 45 ----
31 files changed, 874 insertions(+), 2679 deletions(-)
diff --git a/documentation/src/main/java/org/apache/tamaya/validation/ValidationCheck.java b/documentation/src/main/java/org/apache/tamaya/validation/ValidationCheck.java
deleted file mode 100644
index 2fb40a8..0000000
--- a/documentation/src/main/java/org/apache/tamaya/validation/ValidationCheck.java
+++ /dev/null
@@ -1,194 +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 createObject 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.validation;
-
-import org.apache.tamaya.doc.annot.ConfigAreaSpec;
-import org.apache.tamaya.doc.annot.ConfigPropertySpec;
-
-import java.lang.annotation.Annotation;
-import java.util.Objects;
-
-/**
- * Models a partial configuration configModel result.
- */
-public final class ValidationCheck {
- /**
- * The configModel result.
- */
- private final Finding result;
- /**
- * The configModel message.
- */
- private final String message;
-
- private final Annotation spec;
-
- /**
- * Get the checks annotation.
- * @return the annotation.
- */
- public Class getSpecType(){
- return spec.getClass();
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param spec the specification item, not null.
- * @return a new validation result containing valid parts createObject the given model.
- */
- public static ValidationCheck createValid(Annotation spec) {
- return new ValidationCheck(spec, Finding.VALID, null);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param spec the validated specification, not null.
- * @return a new validation result containing missing parts createObject the given model.
- */
- public static ValidationCheck createMissing(Annotation spec) {
- return new ValidationCheck(spec, Finding.MISSING, null);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param spec the validated specification, not null.
- * @param message Additional message to be shown (optional).
- * @return a new validation result containing missing parts createObject the given model with a message.
- */
- public static ValidationCheck createMissing(Annotation spec, String message) {
- return new ValidationCheck(spec, Finding.MISSING, message);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param spec the validated specification, not null.
- * @param error error message to addNode.
- * @return a new validation result containing erroneous parts createObject the given model with the given error message.
- */
- public static ValidationCheck createError(Annotation spec, String error) {
- return new ValidationCheck(spec, Finding.ERROR, error);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param spec the validated specification, not null.
- * @param warning warning message to addNode.
- * @return a new validation result containing warning parts createObject the given model with the given warning message.
- */
- public static ValidationCheck createWarning(Annotation spec, String warning) {
- return new ValidationCheck(spec, Finding.WARNING, warning);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param spec the validated specification, not null.
- * @param alternativeUsage allows setting a message to indicate non-deprecated replacement, maybe null.
- * @return a new validation result containing deprecated parts createObject the given model with an optional message.
- */
- public static ValidationCheck createDeprecated(Annotation spec, String alternativeUsage) {
- return new ValidationCheck(spec, Finding.DEPRECATED, alternativeUsage != null ? "Use instead: " + alternativeUsage : null);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param spec the validated specification, not null.
- * @return a new validation result containing deprecated parts createObject the given model.
- */
- public static ValidationCheck createDeprecated(Annotation spec) {
- return new ValidationCheck(spec, Finding.DEPRECATED, null);
- }
-
-
- /**
- * Constructor.
- *
- * @param spec the validated specification, not null.
- * @param result the configModel result, not null.
- * @param message the detail message.
- * @return new validation result.
- */
- public static ValidationCheck create(Annotation spec, Finding result, String message) {
- return new ValidationCheck(spec, result, message);
- }
-
-
- /**
- * Constructor.
- *
- * @param spec the validated specification, not null.
- * @param result the configModel result, not null.
- * @param message the detail message.
- */
- private ValidationCheck(Annotation spec, Finding result, String message) {
- this.message = message;
- this.spec = Objects.requireNonNull(spec);
- this.result = Objects.requireNonNull(result);
- }
-
- /**
- * Get the configModel section.
- *
- * @return the section, never null.
- */
- public Annotation getSpec() {
- return spec;
- }
-
- /**
- * Get the configModel result.
- *
- * @return the result, never null.
- */
- public Finding getResult() {
- return result;
- }
-
- /**
- * Get the detail message.
- *
- * @return the detail message, or null.
- */
- public String getMessage() {
- return message;
- }
-
- @Override
- public String toString() {
- String finalMessage = "";
- if (message != null) {
- finalMessage = " -> " + message;
- }
- if(spec instanceof ConfigPropertySpec){
- ConfigPropertySpec pspec = (ConfigPropertySpec)spec;
- return result + ": " + pspec.name() + " (property)"+finalMessage + '\n';
- }
- else if(spec instanceof ConfigAreaSpec){
- ConfigAreaSpec gspec = (ConfigAreaSpec)spec;
- return result + ": " + gspec.path() + " (group)"+finalMessage + '\n';
- }
- return result + ": " + spec + ")"+finalMessage + '\n';
- }
-}
diff --git a/validation/pom.xml b/validation/pom.xml
index c3ef7cf..e97dd66 100644
--- a/validation/pom.xml
+++ b/validation/pom.xml
@@ -51,28 +51,13 @@
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-events</artifactId>
+ <artifactId>tamaya-functions</artifactId>
<version>${project.parent.version}</version>
- <scope>provided</scope>
- <optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-json</artifactId>
+ <artifactId>tamaya-doc_alpha</artifactId>
<version>${project.parent.version}</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.apache.johnzon</groupId>
- <artifactId>johnzon-core</artifactId>
- <version>${johnzon.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-json_1.0_spec</artifactId>
- <version>1.0-alpha-1</version>
- <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
diff --git a/validation/src/main/java/org/apache/tamaya/validation/ConfigModel.java b/validation/src/main/java/org/apache/tamaya/validation/ConfigModel.java
deleted file mode 100644
index 259ff99..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/ConfigModel.java
+++ /dev/null
@@ -1,78 +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 createObject 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.validation;
-
-import org.apache.tamaya.Configuration;
-
-import java.util.Collection;
-
-/**
- * Base structure describing a validated item, by default a parameter or a section.
- */
-public interface ConfigModel {
-
- /**
- * Access the owner.
- * @return the owner createObject this model, never null.
- */
- String getOwner();
-
- /**
- * Get the type createObject item that is modelled.
- * @return the modelled type, never null.
- */
- ModelTarget getType();
-
- /**
- * Get the item's name, it should minimally describe the validation. Examples are:
- * <pre>
- * Sections: a.b.c
- * Params: a.b.c.paramName
- * Filter: a.b.c.FilterImplClass
- * Dependency: mydepClassname
- * CombinationPolicy: a.b.c.MyCombinationPolicyClass
- * </pre>
- * @return the item's name.
- */
- String getName();
-
- /**
- * Check if this validation is a required one.
- * @return true, if this validation is required.
- */
- boolean isRequired();
-
- /**
- * Get an description createObject 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 getList against the given configuration.
- *
- * @param config the configuration to be validated against, not null.
- * @return the validation result, or null, if not applicable.
- */
- Collection<Validation> validate(Configuration config);
-
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/ConfigModelManager.java b/validation/src/main/java/org/apache/tamaya/validation/ConfigModelManager.java
deleted file mode 100644
index ed6a545..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/ConfigModelManager.java
+++ /dev/null
@@ -1,285 +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 createObject 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.validation;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.validation.spi.ConfigDocumentationMBean;
-import org.apache.tamaya.validation.spi.ModelProviderSpi;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import java.lang.management.ManagementFactory;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Validator accessor to validate the current configuration.
- */
-public final class ConfigModelManager {
-
- /** The logger used. */
- private static final Logger LOG = Logger.getLogger(ConfigModelManager.class.getName());
-
- /**
- * Singleton constructor.
- */
- private ConfigModelManager() {
- }
-
- /**
- * Access the usage statistics for the recorded uses createObject configuration.
- * @param inModels the target models, not null.
- * @return usage statistics
- */
- public static String getConfigModelDescription(Collection<ConfigModel> inModels){
- StringBuilder b = new StringBuilder();
- List<ConfigModel> models = new ArrayList<>(inModels);
- Collections.sort(models, (k1, k2) -> {
- return k2.getName().compareTo(k2.getName());
- });
- b.append("TYPE OWNER NAME MANDATORY DESCRIPTION\n");
- b.append("-----------------------------------------------------------------------------------------------------\n");
- for(ConfigModel model:models){
- switch(model.getType()){
- case Parameter:
- b.append("PARAM ");
- break;
- case Section:
- b.append("SECTION ");
- break;
- case Group:
- b.append("GROUP ");
- break;
- default:
- break;
- }
- b.append(formatWithFixedLength(model.getOwner(), 10)).append(' ');
- b.append(formatWithFixedLength(model.getName(), 50));
- if(model.isRequired()){
- b.append(formatWithFixedLength("yes", 12));
- }else{
- b.append(formatWithFixedLength("no", 12));
- }
- if(model.getDescription()!=null){
- b.append(model.getDescription().replace("\n", "\\\n").replace("\"", "'")).append("\"");
- }
- b.append("\n");
- }
- return b.toString();
- }
-
- /**
- * Get the validations defined, using the default classloader.
- *
- * @return the sections defined, never null.
- * @see ServiceContextManager#getDefaultClassLoader()
- */
- public static Collection<ConfigModel> getModels() {
- return getModels(ServiceContextManager.getDefaultClassLoader());
- }
-
- /**
- * Get the validations defined.
- *
- * @param classLoader the target classloader, not null.
- * @return the sections defined, never null.
- */
- public static Collection<ConfigModel> getModels(ClassLoader classLoader) {
- List<ConfigModel> result = new ArrayList<>();
- for (ModelProviderSpi model : ServiceContextManager.getServiceContext(classLoader).getServices(ModelProviderSpi.class)) {
- result.addAll(model.getConfigModels());
- }
- return result;
- }
-
-
- /**
- * Find the validations by checking the validation's name using the given regular expression and
- * the default classloader.
- *
- * @param namePattern the regular expression to use, not null.
- * @param targets the target types only to be returned (optional).
- * @return the sections defined, never null.
- * @see ServiceContextManager#getDefaultClassLoader()
- */
- public static Collection<ConfigModel> findModels(String namePattern, ModelTarget... targets) {
- return findModels(namePattern, ServiceContextManager.getDefaultClassLoader(), targets);
- }
-
- /**
- * Find the validations by checking the validation's name using the given regular expression.
- *
- * @param classLoader the target classloader, not null.
- * @param namePattern the regular expression to use, not null.
- * @param targets the target types only to be returned (optional).
- * @return the sections defined, never null.
- */
- public static Collection<ConfigModel> findModels(String namePattern, ClassLoader classLoader, ModelTarget... targets) {
- List<ConfigModel> result = new ArrayList<>();
- for (ModelProviderSpi model : ServiceContextManager.getServiceContext(classLoader).getServices(ModelProviderSpi.class)) {
- for(ConfigModel configModel : model.getConfigModels()) {
- if(configModel.getName().matches(namePattern)) {
- if(targets.length>0){
- for(ModelTarget tgt:targets){
- if(configModel.getType().equals(tgt)){
- result.add(configModel);
- break;
- }
- }
- }else {
- result.add(configModel);
- }
- }
- }
- }
- return result;
- }
-
- /**
- * Validates the given configuration.
- *
- * @param config the configuration to be validated against, not null.
- * @return the validation results, never null.
- */
- public static Collection<Validation> validate(Configuration config) {
- return validate(config, false);
- }
-
- /**
- * Validates the given configuration.
- *
- * @param config the configuration to be validated against, not null.
- * @param showUndefined allows filtering for undefined configuration elements.
- * @return the validation results, never null.
- */
- public static Collection<Validation> validate(Configuration config, boolean showUndefined) {
- List<Validation> result = new ArrayList<>();
- for (ConfigModel defConf : getModels(config.getContext().getServiceContext().getClassLoader())) {
- result.addAll(defConf.validate(config));
- }
- if(showUndefined){
- Map<String,String> map = new HashMap<>(config.getProperties());
- Set<String> areas = extractTransitiveAreas(map.keySet());
- for (ConfigModel defConf : getModels()) {
- if(ModelTarget.Section.equals(defConf.getType())){
- for (Iterator<String> iter = areas.iterator();iter.hasNext();){
- String area = iter.next();
- if(area.matches(defConf.getName())){
- iter.remove();
- }
- }
- }
- if(ModelTarget.Parameter.equals(defConf.getType())){
- map.remove(defConf.getName());
- }
- }
- outer:for(Map.Entry<String,String> entry:map.entrySet()){
- for (ConfigModel defConf : getModels()) {
- if(ModelTarget.Section.equals(defConf.getType())){
- if(defConf.getName().endsWith(".*") && entry.getKey().matches(defConf.getName())){
- // Ignore parameters that are part createObject transitive section.
- continue outer;
- }
- }
- }
- result.add(Validation.createUndefined("<auto>", entry.getKey(), ModelTarget.Parameter));
- }
- for(String area:areas){
- result.add(Validation.createUndefined("<auto>", area, ModelTarget.Section));
- }
- }
- return result;
- }
-
- /**
- * Registers the {@link ConfigDocumentationMBean} mbean for accessing config documentation into the local platform
- * mbean server.
- */
- public static void registerMBean() {
- registerMBean(null);
- }
-
- /**
- * Registers the {@link ConfigDocumentationMBean} mbean for accessing config documentation into the local platform
- * mbean server.
- *
- * @param context allows to specify an additional MBean context, maybe {@code null}.
- */
- public static void registerMBean(String context) {
- try{
- ConfigDocumentationMBean configMbean = ServiceContextManager.getServiceContext()
- .getService(ConfigDocumentationMBean.class);
- MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- ObjectName on = context==null?new ObjectName("org.apache.tamaya.model:type=ConfigDocumentationMBean"):
- new ObjectName("org.apache.tamaya.model:type=ConfigDocumentationMBean,context="+context);
- try{
- mbs.getMBeanInfo(on);
- LOG.warning("Cannot register mbean " + on + ": already existing.");
- } catch(InstanceNotFoundException e) {
- LOG.info("Registering mbean " + on + "...");
- mbs.registerMBean(configMbean, on);
- }
- } catch(Exception e){
- LOG.log(Level.WARNING,
- "Failed to register ConfigDocumentationMBean.", e);
- }
- }
-
- private static String formatWithFixedLength(String name, int targetLength) {
- targetLength = targetLength-1;
- StringBuilder b = new StringBuilder();
- if(name.length() > targetLength){
- name = name.substring(0, targetLength);
- }
- b.append(name);
- for(int i=0;i<(targetLength-name.length());i++){
- b.append(' ');
- }
- b.append(' ');
- return b.toString();
- }
-
-
-
- private static java.util.Set<java.lang.String> extractTransitiveAreas(Set<String> keys) {
- Set<String> transitiveClosure = new HashSet<>();
- for(String key:keys){
- int index = key.lastIndexOf('.');
- while(index>0){
- String areaKey = key.substring(0,index);
- transitiveClosure.add(areaKey);
- index = areaKey.lastIndexOf('.');
- }
- }
- return transitiveClosure;
- }
-
-
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/ConfigValidation.java b/validation/src/main/java/org/apache/tamaya/validation/ConfigValidation.java
new file mode 100644
index 0000000..b934b52
--- /dev/null
+++ b/validation/src/main/java/org/apache/tamaya/validation/ConfigValidation.java
@@ -0,0 +1,122 @@
+/*
+ * 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 createObject 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.validation;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationSnapshot;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.validation.spi.ConfigValidator;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * Validator manager to validate a configuration.
+ */
+public final class ConfigValidation {
+
+ /** The logger used. */
+ private static final Logger LOG = Logger.getLogger(ConfigValidation.class.getName());
+ /** The validators used. */
+ private List<org.apache.tamaya.validation.spi.ConfigValidator> validators = new ArrayList<>();
+
+ /**
+ * Private constructor.
+ */
+ private ConfigValidation(){}
+
+ /**
+ * Access a singleton using the default classloader.
+ */
+ public static ConfigValidation getInstance() {
+ return ServiceContextManager.getServiceContext(
+ ServiceContextManager.getDefaultClassLoader()
+ ).getService(ConfigValidation.class, ConfigValidation::new);
+ }
+
+ /**
+ * Access a singleton using the given target classloader.
+ * @param classLoader the classloader, not null.
+ */
+ public static ConfigValidation getInstance(ClassLoader classLoader){
+ return ServiceContextManager.getServiceContext(classLoader).getService(ConfigValidation.class, ConfigValidation::new);
+ }
+
+ /**
+ * Add a validator.
+ * @param validator the new validator, not null.
+ */
+ public void addValidator(ConfigValidator validator){
+ if(!validators.contains(validator)) {
+ this.validators.add(validator);
+ }
+ }
+
+ /**
+ * Removes a vlidator.
+ * @param validator the validator, not null.
+ */
+ public void removeValidator(ConfigValidator validator){
+ this.validators.remove(validator);
+ }
+
+ /**
+ * Get the validations defined, using the default classloader.
+ *
+ * @return the sections defined, never null.
+ * @see ServiceContextManager#getDefaultClassLoader()
+ */
+ public Collection<org.apache.tamaya.validation.spi.ConfigValidator> getValidators() {
+ return getValidators(ServiceContextManager.getDefaultClassLoader());
+ }
+
+ /**
+ * Get the validations defined.
+ *
+ * @param classLoader the target classloader, not null.
+ * @return the sections defined, never null.
+ */
+ public Collection<org.apache.tamaya.validation.spi.ConfigValidator> getValidators(ClassLoader classLoader) {
+ return validators;
+ }
+
+ /**
+ * Validates the given configuration.
+ *
+ * @param config the configuration to be validated against, not null.
+ * @return the validation results, never null.
+ */
+ public ValidationResult validate(Configuration config) {
+ ConfigurationSnapshot snapshot = config.getSnapshot();
+ List<ValidationCheck> result = new ArrayList<>();
+ for (org.apache.tamaya.validation.spi.ConfigValidator validator : this.validators) {
+ result.addAll(validator.validate(config));
+ }
+ return new ValidationResult(snapshot, result);
+ }
+
+ @Override
+ public String toString() {
+ return "ConfigValidation{" +
+ "validators=" + validators +
+ '}';
+ }
+}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/ModelTarget.java b/validation/src/main/java/org/apache/tamaya/validation/ModelTarget.java
deleted file mode 100644
index 3af63ae..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/ModelTarget.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 createObject 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.validation;
-
-/**
- * This enumeration defines the types createObject supported validations.
- */
-public enum ModelTarget {
- /**
- * A configuration section.
- */
- Section,
- /**
- * A configuration paramter.
- */
- Parameter,
- /**
- * ConfigModel that is a container createObject other validations.
- */
- Group,
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/Validation.java b/validation/src/main/java/org/apache/tamaya/validation/Validation.java
deleted file mode 100644
index 128efee..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/Validation.java
+++ /dev/null
@@ -1,203 +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 createObject 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.validation;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.validation.spi.AbstractConfigModel;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Objects;
-
-/**
- * Models a partial configuration configModel result.
- */
-public final class Validation {
- /**
- * the config section.
- */
- private final ConfigModel configModel;
- /**
- * The configModel result.
- */
- private final ValidationResult result;
- /**
- * The configModel message.
- */
- private final String message;
-
- /**
- * Creates a new ValidationResult.
- *
- * @param configModel the configModel item, not null.
- * @return a new validation result containing valid parts createObject the given model.
- */
- public static Validation createValid(ConfigModel configModel) {
- return new Validation(configModel, ValidationResult.VALID, null);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param configModel the configModel item, not null.
- * @return a new validation result containing missing parts createObject the given model.
- */
- public static Validation createMissing(ConfigModel configModel) {
- return new Validation(configModel, ValidationResult.MISSING, null);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param configModel the configModel item, not null.
- * @param message Additional message to be shown (optional).
- * @return a new validation result containing missing parts createObject the given model with a message.
- */
- public static Validation createMissing(ConfigModel configModel, String message) {
- return new Validation(configModel, ValidationResult.MISSING, message);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param configModel the configModel item, not null.
- * @param error error message to addNode.
- * @return a new validation result containing erroneous parts createObject the given model with the given error message.
- */
- public static Validation createError(ConfigModel configModel, String error) {
- return new Validation(configModel, ValidationResult.ERROR, error);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param configModel the configModel item, not null.
- * @param warning warning message to addNode.
- * @return a new validation result containing warning parts createObject the given model with the given warning message.
- */
- public static Validation createWarning(ConfigModel configModel, String warning) {
- return new Validation(configModel, ValidationResult.WARNING, warning);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param configModel the configModel item, not null.
- * @param alternativeUsage allows setting a message to indicate non-deprecated replacement, maybe null.
- * @return a new validation result containing deprecated parts createObject the given model with an optional message.
- */
- public static Validation createDeprecated(ConfigModel configModel, String alternativeUsage) {
- return new Validation(configModel, ValidationResult.DEPRECATED, alternativeUsage != null ? "Use instead: " + alternativeUsage : null);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param configModel the configModel item, not null.
- * @return a new validation result containing deprecated parts createObject the given model.
- */
- public static Validation createDeprecated(ConfigModel configModel) {
- return new Validation(configModel, ValidationResult.DEPRECATED, null);
- }
-
- /**
- * Creates a new ValidationResult.
- *
- * @param owner owner
- * @param key the name/model key
- * @param type model type
- * @return a corresponding configModel item
- */
- public static Validation createUndefined(final String owner, final String key, final ModelTarget type) {
- return new Validation(new AbstractConfigModel(owner, key, false, "Undefined key: " + key) {
-
- @Override
- public ModelTarget getType() {
- return type;
- }
-
- @Override
- public Collection<Validation> validate(Configuration config) {
- return Collections.emptyList();
- }
- }, ValidationResult.UNDEFINED, null);
- }
-
-
- /**
- * Constructor.
- *
- * @param configModel the configModel item, not null.
- * @param result the configModel result, not null.
- * @param message the detail message.
- * @return new validation result.
- */
- public static Validation create(ConfigModel configModel, ValidationResult result, String message) {
- return new Validation(configModel, result, message);
- }
-
-
- /**
- * Constructor.
- *
- * @param configModel the configModel item, not null.
- * @param result the configModel result, not null.
- * @param message the detail message.
- */
- private Validation(ConfigModel configModel, ValidationResult result, String message) {
- this.message = message;
- this.configModel = Objects.requireNonNull(configModel);
- this.result = Objects.requireNonNull(result);
- }
-
- /**
- * Get the configModel section.
- *
- * @return the section, never null.
- */
- public ConfigModel getConfigModel() {
- return configModel;
- }
-
- /**
- * Get the configModel 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() {
- if (message != null) {
- return result + ": " + configModel.getName() + " (" + configModel.getType() + ") -> " + message + '\n';
- }
- return result + ": " + configModel.getName() + " (" + configModel.getType() + ")";
- }
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/ValidationCheck.java b/validation/src/main/java/org/apache/tamaya/validation/ValidationCheck.java
new file mode 100644
index 0000000..d4ad293
--- /dev/null
+++ b/validation/src/main/java/org/apache/tamaya/validation/ValidationCheck.java
@@ -0,0 +1,203 @@
+/*
+ * 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 createObject 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.validation;
+
+import org.apache.tamaya.doc.annot.ConfigAreaSpec;
+import org.apache.tamaya.doc.annot.ConfigPropertySpec;
+
+import java.util.Objects;
+
+/**
+ * Models a partial configuration validation result.
+ */
+public final class ValidationCheck {
+
+ /**
+ * Enum type describing the different validation results supported.
+ */
+ public enum Finding {
+ /**
+ * The validated item is valid
+ */
+ VALID,
+ /**
+ * The validated item is deprecated.
+ */
+ DEPRECATED,
+ /**
+ * The validated item is correct, but the createValue is worth a warning.
+ */
+ WARNING,
+ /**
+ * A required parameter or section is missing.
+ */
+ MISSING,
+ /**
+ * The validated item has an invalid createValue.
+ */
+ 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();
+ }
+ }
+
+ /**
+ * The finding level.
+ */
+ private final Finding result;
+
+ /**
+ * The message.
+ */
+ private final String message;
+
+ /**
+ * The validation source.
+ */
+ private final Object source;
+
+
+ /**
+ * Creates a new ValidationResult.
+ *
+ * @param source the source item, not null.
+ * @param message the message, not null.
+ * @return a new validation check containing valid parts createObject the given model.
+ */
+ public static ValidationCheck createValid(Object source, String message) {
+ return new ValidationCheck(source, Finding.VALID, null);
+ }
+
+ /**
+ * Creates a new ValidationResult.
+ *
+ * @param source the validated source, not null.
+ * @param message the message, not null.
+ * @return a new validation check containing missing parts createObject the given model.
+ */
+ public static ValidationCheck createMissing(Object source, String message) {
+ return new ValidationCheck(source, Finding.MISSING, message);
+ }
+
+ /**
+ * Creates a new ValidationResult.
+ *
+ * @param source the validated source, not null.
+ * @param message error message, not null.
+ * @return a new validation check containing erroneous parts createObject the given model with the given error message.
+ */
+ public static ValidationCheck createError(Object source, String message) {
+ return new ValidationCheck(source, Finding.ERROR, message);
+ }
+
+ /**
+ * Creates a new ValidationResult.
+ *
+ * @param source the validated source, not null.
+ * @param message warning message to, not null.
+ * @return a new validation check containing warning parts createObject the given model with the given warning message.
+ */
+ public static ValidationCheck createWarning(Object source, String message) {
+ return new ValidationCheck(source, Finding.WARNING, message);
+ }
+
+ /**
+ * Creates a new ValidationResult.
+ *
+ * @param source the validated source, not null.
+ * @param message allows the message, not null.
+ * @return a new validation check containing deprecated parts createObject the given model with an optional message.
+ */
+ public static ValidationCheck createDeprecated(Object source, String message) {
+ return new ValidationCheck(source, Finding.DEPRECATED, message);
+ }
+
+ /**
+ * Creates a new ValidationResult.
+ *
+ * @param source the validated source, not null.
+ * @return a new validation result containing deprecated parts createObject the given model.
+ */
+ public static ValidationCheck createDeprecated(Object source) {
+ return new ValidationCheck(source, Finding.DEPRECATED, "Deprecated: " + source);
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param source the validated specification, not null.
+ * @param result the configModel result, not null.
+ * @param message the detail message.
+ */
+ private ValidationCheck(Object source, Finding result, String message) {
+ this.message = Objects.requireNonNull(message);
+ this.source = Objects.requireNonNull(source);
+ this.result = Objects.requireNonNull(result);
+ }
+
+ /**
+ * Get the validation result.
+ *
+ * @return the result, never null.
+ */
+ public Finding getResult() {
+ return result;
+ }
+
+ /**
+ * Get the validation message.
+ *
+ * @return the detail message, or null.
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Get the checks source.
+ * @return the source, not null.
+ */
+ public Object getSource(){
+ return source;
+ }
+
+ @Override
+ public String toString() {
+ String finalMessage = "";
+ if (message != null) {
+ finalMessage = " -> " + message;
+ }
+ if(source instanceof ConfigPropertySpec){
+ ConfigPropertySpec pspec = (ConfigPropertySpec) source;
+ return result + ": " + pspec.name() + " (property)"+finalMessage + '\n';
+ }
+ else if(source instanceof ConfigAreaSpec){
+ ConfigAreaSpec gspec = (ConfigAreaSpec) source;
+ return result + ": " + gspec.path() + " (group)"+finalMessage + '\n';
+ }
+ return result + ": " + source + ")"+finalMessage + '\n';
+ }
+}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/ValidationResult.java b/validation/src/main/java/org/apache/tamaya/validation/ValidationResult.java
index 942a755..3c1dad0 100644
--- a/validation/src/main/java/org/apache/tamaya/validation/ValidationResult.java
+++ b/validation/src/main/java/org/apache/tamaya/validation/ValidationResult.java
@@ -18,42 +18,80 @@
*/
package org.apache.tamaya.validation;
+import org.apache.tamaya.ConfigurationSnapshot;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
/**
- * Enum type describing the different validation results supported.
+ * Result of a validation performed on a configuration.
*/
-public enum ValidationResult {
- /**
- * The validated item is valid
- */
- VALID,
- /**
- * The validated item is deprecated.
- */
- DEPRECATED,
+public final class ValidationResult {
+ private ConfigurationSnapshot snapshot;
+ private List<ValidationCheck> result;
+
/**
- * The validated item is correct, but the createValue is worth a warning.
+ * Creates a new validation result.
+ * @param snapshot the snapshpt config, not null.
+ * @param result the result, not null.
*/
- WARNING,
+ public ValidationResult(ConfigurationSnapshot snapshot, List<ValidationCheck> result) {
+ this.snapshot = Objects.requireNonNull(snapshot);
+ this.result = Objects.requireNonNull(result);
+ }
+
/**
- * 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 parameter or section should be removed.
+ * Access the validated snapshot.
+ * @return the snapshot, not null.
*/
- UNDEFINED,
+ public ConfigurationSnapshot getSnapshot() {
+ return snapshot;
+ }
+
/**
- * A required parameter or section is missing.
+ * Access the validation findings.
+ * @return the findings, not null.
*/
- MISSING,
+ public List<ValidationCheck> getResult() {
+ return result;
+ }
+
/**
- * The validated item has an invalid createValue.
+ * Checks if the validation does not include errors.
+ * @return true if no errors were identified.
*/
- ERROR;
+ public boolean isSuccessfull(){
+ for(ValidationCheck check:this.result){
+ if(check.getResult().isError()){
+ return false;
+ }
+ }
+ return true;
+ }
/**
- * Method to quickly evaluate if the current state is an error state.
- *
- * @return true, if the state is not ERROR or MISSING.
+ * Get the the findings filtered by Finding types given.
+ * @param findingTypes the findingTypes.
+ * @return the filterered list.
*/
- boolean isError() {
- return this.ordinal() == MISSING.ordinal() || this.ordinal() == ERROR.ordinal();
+ public List<ValidationCheck> getResultByFindings(ValidationCheck.Finding... findingTypes){
+ List<ValidationCheck.Finding> findings = Arrays.asList(findingTypes);
+ if(findings.isEmpty()){
+ return result;
+ }else{
+ return result.stream()
+ .filter(f -> findings.contains(f))
+ .collect(Collectors.toList());
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "ValidationResult{" +
+ "snapshot=" + snapshot +
+ ", result=" + result +
+ '}';
}
}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigDocumentationBean.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigDocumentationBean.java
deleted file mode 100644
index 14d4d02..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigDocumentationBean.java
+++ /dev/null
@@ -1,196 +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 createObject 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.validation.internal;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.ConfigModelManager;
-import org.apache.tamaya.validation.ModelTarget;
-import org.apache.tamaya.validation.Validation;
-import org.apache.tamaya.validation.spi.ConfigDocumentationMBean;
-
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonArrayBuilder;
-import javax.json.JsonObject;
-import javax.json.JsonObjectBuilder;
-import javax.json.JsonWriter;
-import javax.json.JsonWriterFactory;
-import javax.json.stream.JsonGenerator;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * MBean implementation createObject {@link ConfigDocumentationMBean}.
- */
-public class ConfigDocumentationBean implements ConfigDocumentationMBean{
-
- private final JsonWriterFactory writerFactory;
-
- private static final Comparator<Validation> COMPARATOR = new Comparator<Validation>() {
- @Override
- public int compare(Validation v1, Validation v2) {
- int compare = VAL_COMPARATOR.compare(v1.getConfigModel(), v2.getConfigModel());
- if(compare==0){
- compare = v1.getResult().compareTo(v2.getResult());
- }
- if(compare==0){
- return v1.getMessage().compareTo(v2.getMessage());
- }
- return compare;
- }
- };
- private static final Comparator<ConfigModel> VAL_COMPARATOR = new Comparator<ConfigModel>() {
- @Override
- public int compare(ConfigModel v1, ConfigModel v2) {
- int compare = v1.getType().compareTo(v2.getType());
- if(compare==0){
- compare = v1.getName().compareTo(v2.getName());
- }
- return compare;
- }
- };
-
- private Configuration config;
-
- /**
- * Default constructor, using the current configuration being available.
- */
- public ConfigDocumentationBean(){
- this(null);
- }
-
-
- /**
- * Creates an mbean bound to the given configuration. This is useful, when multiple mbeans for each
- * context should be used, e.g. one mbean per ear, app deployment.
- * @param config the configuration to be used.
- */
- public ConfigDocumentationBean(Configuration config){
- this.config = config;
- Map<String, Object> writerProperties = new HashMap<>(1);
- writerProperties.put(JsonGenerator.PRETTY_PRINTING, true);
- writerFactory = Json.createWriterFactory(writerProperties);
- }
-
- /**
- * Access the configuration.
- * @return either the configuration bound to this bean, or the current configuration.
- */
- private Configuration getConfig(){
- return config!=null?config: Configuration.current();
- }
-
- @Override
- public String validate(boolean showUndefined) {
- List<Validation> validations = new ArrayList<>(ConfigModelManager.validate(getConfig(), showUndefined));
- Collections.sort(validations, COMPARATOR);
- JsonArrayBuilder builder = Json.createArrayBuilder();
- for(Validation val:validations){
- builder.add(toJsonObject(val));
- }
- return formatJson(builder.build());
- }
-
-
-
- @Override
- public String getConfigurationModel() {
- List<ConfigModel> configModels = new ArrayList<>(ConfigModelManager.getModels());
- Collections.sort(configModels, VAL_COMPARATOR);
- JsonArrayBuilder result = Json.createArrayBuilder();
- for(ConfigModel val: configModels){
- result.add(toJsonObject(val));
- }
- return formatJson(result.build());
- }
-
- @Override
- public String getConfigurationModel(ModelTarget type) {
- return findValidationModels(".*", type);
- }
-
- @Override
- public String findConfigurationModels(String namePattern) {
- List<ConfigModel> configModels = new ArrayList<>(ConfigModelManager.findModels(namePattern));
- Collections.sort(configModels, VAL_COMPARATOR);
- JsonArrayBuilder result = Json.createArrayBuilder();
- for(ConfigModel val: configModels){
- result.add(toJsonObject(val));
- }
- return formatJson(result.build());
- }
-
- @Override
- public String findValidationModels(String namePattern, ModelTarget... type) {
- List<ConfigModel> configModels = new ArrayList<>(ConfigModelManager.findModels(namePattern, type));
- Collections.sort(configModels, VAL_COMPARATOR);
- JsonArrayBuilder result = Json.createArrayBuilder();
- for(ConfigModel val: configModels){
- result.add(toJsonObject(val));
- }
- return formatJson(result.build());
- }
-
- @Override
- public String toString(){
- return "ConfigDocumentationBean, config: " + (this.config!=null?this.config.toString():"<current>");
- }
-
-
- private JsonObject toJsonObject(ConfigModel val) {
- JsonObjectBuilder valJson = Json.createObjectBuilder().add("target", val.getType().toString())
- .add("name", val.getName());
- if(val.getDescription()!=null) {
- valJson.add("description", val.getDescription());
- }
- if(val.isRequired()){
- valJson.add("required",true);
- }
- return valJson.build();
- }
-
- private JsonObject toJsonObject(Validation val) {
- JsonObjectBuilder valJson = Json.createObjectBuilder().add("target", val.getConfigModel().getType().toString())
- .add("name", val.getConfigModel().getName());
- if(val.getConfigModel().isRequired()){
- valJson.add("required",true);
- }
- if(val.getConfigModel().getDescription() != null){
- valJson.add("description", val.getConfigModel().getDescription());
- }
- valJson.add("result", val.getResult().toString());
- if( val.getMessage() != null) {
- valJson.add("message", val.getMessage());
- }
- return valJson.build();
- }
-
- private String formatJson(JsonArray data) {
- StringWriter writer = new StringWriter();
- JsonWriter gen = writerFactory.createWriter(writer);
- gen.writeArray(data);
- return writer.toString();
- }
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigValidationDocumentationReader.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigValidationDocumentationReader.java
new file mode 100644
index 0000000..67b2979
--- /dev/null
+++ b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfigValidationDocumentationReader.java
@@ -0,0 +1,98 @@
+/*
+ * 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 createObject 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.validation.internal;
+
+import java.util.*;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.doc.ConfigDocumenter;
+import org.apache.tamaya.doc.DocumentedArea;
+import org.apache.tamaya.doc.DocumentedConfiguration;
+import org.apache.tamaya.doc.DocumentedProperty;
+import org.apache.tamaya.spi.ClassloaderAware;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.validation.spi.ConfigValidator;
+import org.apache.tamaya.validation.ValidationCheck;
+import org.apache.tamaya.validation.spi.AreaValidator;
+import org.apache.tamaya.validation.spi.PropertyValidator;
+
+/**
+ * Utility class to read metamodel information from properties. Hereby these properties can be part createObject a
+ * configuration (containing other entriees as well) or be dedicated model definition properties read
+ * from any kind createObject source.
+ */
+public class ConfigValidationDocumentationReader implements ClassloaderAware {
+
+ private ClassLoader classLoader;
+
+ public static ConfigValidationDocumentationReader getInstance(){
+ return ServiceContextManager.getServiceContext()
+ .getService(ConfigValidationDocumentationReader.class, ConfigValidationDocumentationReader::new);
+ }
+
+ public static ConfigValidationDocumentationReader getInstance(ClassLoader classLoader){
+ return ServiceContextManager.getServiceContext(classLoader)
+ .getService(ConfigValidationDocumentationReader.class, ConfigValidationDocumentationReader::new);
+ }
+
+
+ /**
+ * Loads validations as configured in the given properties.
+ * @param classLoader the target classLoader, not null.
+ * @return a collection createObject config validations.
+ */
+ public List<ConfigValidator> loadValidations(ClassLoader classLoader) {
+ List<ConfigValidator> result = new ArrayList<>();
+ DocumentedConfiguration configDoc = ConfigDocumenter.getInstance(classLoader).getDocumentation();
+ for(DocumentedArea docArea: configDoc.getAllAreasSorted()){
+ loadValidations(docArea, result);
+ }
+ for(DocumentedProperty docProp: configDoc.getAllPropertiesSorted()){
+ result.add(new PropertyValidator(docProp));
+ }
+ return result;
+ }
+
+ private void loadValidations(DocumentedArea docArea, List<ConfigValidator> result) {
+ result.add(new AreaValidator(docArea));
+ for(DocumentedProperty propDoc:docArea.getPropertiesSorted()){
+ result.add(new PropertyValidator(propDoc));
+ }
+ for(DocumentedArea area:docArea.getAreasSorted()){
+ loadValidations(area, result);
+ }
+ }
+
+ @Override
+ public void init(ClassLoader classLoader) {
+ this.classLoader = Objects.requireNonNull(classLoader);
+ }
+
+ @Override
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public List<ValidationCheck> validateConfiguration(Configuration config){
+ List<ValidationCheck> result = new ArrayList<>();
+
+ return result;
+ }
+
+}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredInlineModelProviderSpi.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredInlineModelProviderSpi.java
deleted file mode 100644
index 685271e..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredInlineModelProviderSpi.java
+++ /dev/null
@@ -1,83 +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 createObject 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.validation.internal;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.ClassloaderAware;
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.spi.ConfigModelReader;
-import org.apache.tamaya.validation.spi.ModelProviderSpi;
-
-import java.util.*;
-import java.util.logging.Logger;
-
-/**
- * ConfigModel provider that reads model metadata from the current {@link org.apache.tamaya.Configuration}.
- */
-public class ConfiguredInlineModelProviderSpi implements ModelProviderSpi, ClassloaderAware {
-
- /** The logger. */
- private static final Logger LOG = Logger.getLogger(ConfiguredInlineModelProviderSpi.class.getName());
- /** parameter to disable this provider. By default the provider is active. */
- private static final String MODEL_EANABLED_PARAM = "org.apache.tamaya.model.integrated.enabled";
-
- /** The configModels read. */
- private List<ConfigModel> configModels = new ArrayList<>();
- /** The target classloader used. */
- private ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-
- /**
- * Constructor, typically called by the {@link java.util.ServiceLoader}.
- */
- public ConfiguredInlineModelProviderSpi() {
- load();
- }
-
- /**
- * Loads the models from the underlying service provider.
- */
- public void load(){
- String enabledVal = Configuration.current(classLoader).get(MODEL_EANABLED_PARAM);
- boolean enabled = enabledVal == null || "true".equalsIgnoreCase(enabledVal);
- if (enabled) {
- LOG.info("Reading model configuration from config...");
- Map<String,String> config = Configuration.current().getProperties();
- String owner = config.get("_model.provider");
- if(owner==null){
- owner = config.toString();
- }
- configModels.addAll(ConfigModelReader.loadValidations(owner, config));
- }
- configModels = Collections.unmodifiableList(configModels);
- }
-
- public Collection<ConfigModel> getConfigModels() {
- return configModels;
- }
-
- @Override
- public void init(ClassLoader classLoader) {
- this.classLoader = Objects.requireNonNull(classLoader);
- }
-
- @Override
- public ClassLoader getClassLoader() {
- return classLoader;
- }
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredPropertiesModelProviderSpi.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredPropertiesModelProviderSpi.java
deleted file mode 100644
index 623e0e9..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredPropertiesModelProviderSpi.java
+++ /dev/null
@@ -1,154 +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 createObject 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.validation.internal;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.spi.ConfigModelReader;
-import org.apache.tamaya.validation.spi.ModelProviderSpi;
-import org.apache.tamaya.spisupport.propertysource.MapPropertySource;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * ConfigModel provider that reads model metadata from property files from
- * {@code classpath*:META-INF/configmodel.properties} in the following format:
- * <pre>
- * ###################################################################################
- * # Example createObject a configuration metamodel expressed via properties.
- * ####################################################################################
- *
- * # Metamodel information
- * [model].provider=ConfigModel Extension
- *
- * ####################################################################################
- * # Description createObject Configuration Sections (minimal, can be extended by other modules).
- * # By default its interpreted as a section !
- * ####################################################################################
- *
- * # a (section)
- * {model}a.class=Section
- * {model}a.params2.class=Parameter
- * {model}a.params2.type=String
- * {model}a.params2.required=true
- * {model}a.params2.description=a required parameter
- *
- * {model}a.paramInt.class=Parameter
- * {model}a.paramInt.ref=MyNumber
- * {model}a.paramInt.description=an optional parameter (default)
- *
- * {model}a._number.class=Parameter
- * {model}a._number.type=Integer
- * {model}a._number.deprecated=true
- * {model}a._number.mappedTo=a.paramInt
- *
- * # a.b.c (section)
- * {model}a.b.c.class=Section
- * {model}a.b.c.description=Just a test section
- *
- * # a.b.c.aRequiredSection (section)
- * {model}a.b.c.aRequiredSection.class=Section
- * {model}a.b.c.aRequiredSection.required=true
- * {model}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)
- * {model}a.b.c.aRequiredSection.subsection.class=Section
- *
- * {model}a.b.c.aRequiredSection.subsection.param0.class=Parameter
- * {model}a.b.c.aRequiredSection.subsection.param0.type=String
- * {model}a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
- * # A minmal String parameter
- * {model}a.b.c.aRequiredSection.subsection.param00.class=Parameter
- * {model}a.b.c.aRequiredSection.subsection.param00.type=String
- *
- * # a.b.c.aRequiredSection.subsection (section)
- * {model}a.b.c.aRequiredSection.subsection.param1.class=Parameter
- * {model}a.b.c.aRequiredSection.subsection.param1.type = String
- * {model}a.b.c.aRequiredSection.subsection.param1.required = true
- * {model}a.b.c.aRequiredSection.subsection.intParam.class=Parameter
- * {model}a.b.c.aRequiredSection.subsection.intParam.type = Integer
- * {model}a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
- *
- * # a.b.c.aRequiredSection.nonempty-subsection (section)
- * {model}a.b.c.aRequiredSection.nonempty-subsection.class=Section
- * {model}a.b.c.aRequiredSection.nonempty-subsection.required=true
- *
- * # a.b.c.aRequiredSection.optional-subsection (section)
- * {model}a.b.c.aRequiredSection.optional-subsection.class=Section
- *
- * # a.b.c.aValidatedSection (section)
- * {model}a.b.c.aValidatedSection.class=Section
- * {model}a.b.c.aValidatedSection.description=A validated section.
- * {model}a.b.c.aValidatedSection.configModels=org.apache.tamaya.model.TestValidator
- * </pre>
- */
-public class ConfiguredPropertiesModelProviderSpi implements ModelProviderSpi {
-
- /** The logger. */
- private static final Logger LOG = Logger.getLogger(ConfiguredPropertiesModelProviderSpi.class.getName());
- /** parameter to disable this provider. By default the provider is active. */
- private static final String MODEL_EANABLED_PARAM = "org.apache.tamaya.model.default.enabled";
- /** The configModels read. */
- private List<ConfigModel> configModels = new ArrayList<>();
-
- public ConfiguredPropertiesModelProviderSpi() {
- String enabledVal = Configuration.current().get(MODEL_EANABLED_PARAM);
- boolean enabled = enabledVal == null || "true".equalsIgnoreCase(enabledVal);
- if(!enabled){
- LOG.info("Reading model data from META-INF/configmodel.properties has been disabled.");
- return;
- }
- try {
- LOG.info("Reading model data from META-INF/configmodel.properties...");
- Enumeration<URL> configs = getClass().getClassLoader().getResources("META-INF/configmodel.properties");
- while (configs.hasMoreElements()) {
- URL config = configs.nextElement();
- try (InputStream is = config.openStream()) {
- Properties props = new Properties();
- props.load(is);
- Map<String,String> data = MapPropertySource.getMap(props);
- String owner = data.get("_model.owner");
- if(owner==null){
- owner = config.toString();
- }
- configModels.addAll(ConfigModelReader.loadValidations(owner,
- data));
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.SEVERE,
- "Error loading config metadata from " + config, e);
- }
- }
- } catch (Exception e) {
- LOG.log(Level.SEVERE,
- "Error loading config metadata from META-INF/configmodel.properties", e);
- }
- configModels = Collections.unmodifiableList(configModels);
- }
-
-
- public Collection<ConfigModel> getConfigModels() {
- return configModels;
- }
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java
deleted file mode 100644
index 6edb411..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java
+++ /dev/null
@@ -1,186 +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 createObject 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.validation.internal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.ConfigurationFormats;
-import org.apache.tamaya.resource.ResourceResolver;
-import org.apache.tamaya.spi.ClassloaderAware;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.spi.ConfigModelReader;
-import org.apache.tamaya.validation.spi.ModelProviderSpi;
-
-/**
- * ConfigModel provider that reads model metadata from property files from
- * {@code classpath*:META-INF/configmodel.json} in the following format:
- * <pre>
- * Example createObject a configuration metamodel expressed via YAML.
- * Structure is shown through indentation (one or more spaces).
- * Sequence items are denoted by a dash,
- * key createValue pairs within a map are separated by a colon.
- * </pre>
- */
-public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi, ClassloaderAware {
-
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(ConfiguredResourcesModelProviderSpi.class.getName());
- /**
- * The parameter that can be used to configure the location createObject the configuration model resources.
- */
- private static final String MODEL_RESOURCE_PARAM = "org.apache.tamaya.model.resources";
- /**
- * The resource class to checked for testing the availability createObject the resources extension module.
- */
- private static final String CONFIG_RESOURCE_CLASS = "org.apache.tamaya.resource.ConfigResource";
- /**
- * The resource class to checked for testing the availability createObject the formats extension module.
- */
- private static final String CONFIGURATION_FORMATS_CLASS = "org.apache.tamaya.format.ConfigurationFormats";
- /**
- * Initializes the flag showing if the formats module is present (required).
- */
- private static final boolean AVAILABLE = checkAvailabilityFormats();
- /**
- * Initializes the flag showing if the resources module is present (optional).
- */
- private static final boolean RESOURCES_EXTENSION_AVAILABLE = checkAvailabilityResources();
-
- /**
- * The configModels read.
- */
- private List<ConfigModel> configModels = new ArrayList<>();
-
- /** The target classloader. */
- private ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-
-
- /**
- * Initializes the flag showing if the formats module is present (required).
- */
- private static boolean checkAvailabilityFormats() {
- try {
- Class.forName(CONFIGURATION_FORMATS_CLASS);
- return true;
- } catch (final Exception e) {
- return false;
- }
- }
-
- /**
- * Initializes the flag showing if the resources module is present (optional).
- */
- private static boolean checkAvailabilityResources() {
- try {
- Class.forName(CONFIG_RESOURCE_CLASS);
- return true;
- } catch (final Exception e) {
- return false;
- }
- }
-
- /**
- * Constructor, mostly called from {@link java.util.ServiceLoader}
- */
- public ConfiguredResourcesModelProviderSpi() {
- if (!AVAILABLE) {
- LOG.info("tamaya-format extension is required to read model configuration, No extended model support AVAILABLE.");
- } else {
- reload();
- }
- }
-
- /**
- * Reloads the provider using resources from the current classloader.
- */
- public void reload(){
- final String resources = Configuration.current().get(MODEL_RESOURCE_PARAM);
- if (resources == null || resources.trim().isEmpty()) {
- LOG.info("Mo model resources location configured in " + MODEL_RESOURCE_PARAM + ".");
- return;
- }
- Collection<URL> urls;
- if (RESOURCES_EXTENSION_AVAILABLE) {
- LOG.info("Using tamaya-resources extension to read model configuration from " + resources);
- urls = ResourceResolver.getInstance(classLoader).getResources(resources.split(","));
- } else {
- LOG.info("Using default classloader resource location to read model configuration from " + resources);
- urls = new ArrayList<>();
- for (final String resource : resources.split(",")) {
- if (!resource.trim().isEmpty()) {
- Enumeration<URL> configs;
- try {
- configs = getClass().getClassLoader().getResources(resource);
- while (configs.hasMoreElements()) {
- urls.add(configs.nextElement());
- }
- } catch (final IOException e) {
- Logger.getLogger(getClass().getName()).log(Level.SEVERE,
- "Error evaluating config model locations from " + resource, e);
- }
- }
- }
- }
- // Reading configs
- for (final URL config : urls) {
- try (InputStream is = config.openStream()) {
- final ConfigurationData data = ConfigurationFormats.getInstance()
- .readConfigurationData(config);
- Map<String,String> props = new HashMap<>();
- for(PropertyValue val:data.getData()){
- props.putAll(val.toMap());
- }
- String owner = props.get("_model.provider");
- if(owner==null){
- owner = config.toString();
- }
- configModels.addAll(ConfigModelReader.loadValidations(owner, props));
- } catch (final Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.SEVERE,
- "Error loading config model data from " + config, e);
- }
- }
- configModels = Collections.unmodifiableList(configModels);
- }
-
- @Override
- public Collection<ConfigModel> getConfigModels() {
- return configModels;
- }
-
- @Override
- public void init(ClassLoader classLoader) {
- this.classLoader = Objects.requireNonNull(classLoader);
- }
-
- @Override
- public ClassLoader getClassLoader() {
- return classLoader;
- }
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredTypeEventsModelPopulator.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredTypeEventsModelPopulator.java
deleted file mode 100644
index 7436a81..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredTypeEventsModelPopulator.java
+++ /dev/null
@@ -1,124 +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 createObject 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.validation.internal;
-
-import org.apache.tamaya.events.ConfigEvent;
-import org.apache.tamaya.events.ConfigEventListener;
-import org.apache.tamaya.inject.spi.ConfiguredField;
-import org.apache.tamaya.inject.spi.ConfiguredMethod;
-import org.apache.tamaya.inject.spi.ConfiguredType;
-import org.apache.tamaya.spi.ClassloaderAware;
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.ConfigModelManager;
-import org.apache.tamaya.validation.spi.ModelProviderSpi;
-import org.apache.tamaya.validation.spi.ParameterModel;
-
-import java.util.Collection;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Internal facade that registers all kind createObject injected fields as {@link org.apache.tamaya.validation.ConfigModel} entries,
- * so all configured injection points are visible as documented configuration hooks.
- */
-public final class ConfiguredTypeEventsModelPopulator implements ConfigEventListener, ClassloaderAware {
-
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(ConfiguredTypeEventsModelPopulator.class.getName());
-
- /** System property to be setCurrent to deactivate auto documentation createObject configured classes published thorugh
- * ConfiguredType events.
- */
- private static final String ENABLE_EVENT_DOC = "org.apache.tamaya.model.autoModelEvents";
- private ClassLoader classLoader = ServiceContextManager.getDefaultClassLoader();
-
- @Override
- public void onConfigEvent(ConfigEvent event) {
- if(event.getResourceType()!=ConfiguredType.class){
- return;
- }
- String value = System.getProperty(ENABLE_EVENT_DOC);
- if(value == null || Boolean.parseBoolean(value)) {
- ConfiguredType confType = (ConfiguredType)event.getResource();
- for (ConfiguredField field : confType.getConfiguredFields()) {
- Collection<String> keys = field.getConfiguredKeys();
- for (String key : keys) {
- ParameterModel val = getModel(key, ParameterModel.class, classLoader);
- if (val == null) {
- ConfiguredTypeEventsModelProvider.addConfigModel(
- new ParameterModel.Builder(confType.getName(), key)
- .setType(field.getType().getName())
- .setDescription("Injected field: " +
- field.getAnnotatedField().getDeclaringClass().getName() + '.' + field.toString() +
- ", \nconfigured with keys: " + keys)
- .build());
- }
- }
- }
- for (ConfiguredMethod method : confType.getConfiguredMethods()) {
- Collection<String> keys = method.getConfiguredKeys();
- for (String key : keys) {
- ParameterModel val = getModel(key, ParameterModel.class, classLoader);
- if (val == null) {
- ConfiguredTypeEventsModelProvider.addConfigModel(
- new ParameterModel.Builder(confType.getName(), key)
- .setType(method.getParameterTypes()[0].getName())
- .setDescription("Injected field: " +
- method.getAnnotatedMethod().getDeclaringClass().getName() + '.' + method.toString() +
- ", \nconfigured with keys: " + keys)
- .build());
- }
- }
- }
- }
- }
-
- /**
- * Find the validations by matching the validation's name against the given model type.
- *
- * @param classLoader the target classloader, not null.
- * @param name the name to use, not null.
- * @param modelType classname createObject the target model type.
- * @param <T> type createObject the model to filter for.
- * @return the sections defined, never null.
- */
- private static <T extends ConfigModel> T getModel(String name, Class<T> modelType, ClassLoader classLoader) {
- for (ModelProviderSpi model : ServiceContextManager.getServiceContext(classLoader).getServices(ModelProviderSpi.class)) {
- for(ConfigModel configModel : model.getConfigModels()) {
- if(configModel.getName().equals(name) && configModel.getClass().equals(modelType)) {
- return modelType.cast(configModel);
- }
- }
- }
- return null;
- }
-
- @Override
- public void init(ClassLoader classLoader) {
- this.classLoader = Objects.requireNonNull(classLoader);
- }
-
- @Override
- public ClassLoader getClassLoader() {
- return classLoader;
- }
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredTypeEventsModelProvider.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredTypeEventsModelProvider.java
deleted file mode 100644
index e1708eb..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredTypeEventsModelProvider.java
+++ /dev/null
@@ -1,51 +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 createObject 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.validation.internal;
-
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.spi.ModelProviderSpi;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Model provider that adds model definitions for the items published as
- * {@link org.apache.tamaya.inject.spi.ConfiguredType} events.
- */
-public class ConfiguredTypeEventsModelProvider implements ModelProviderSpi {
- /** The collected models. */
- private static Collection<ConfigModel> configModels = new ArrayList<>();
-
- /**
- * Adds a model, called from the registered listener class.
- * @param configModel adds the config model.
- */
- static void addConfigModel(ConfigModel configModel){
- List<ConfigModel> newList = new ArrayList<>(configModels);
- newList.add(configModel);
- ConfiguredTypeEventsModelProvider.configModels = newList;
- }
-
- @Override
- public Collection<ConfigModel> getConfigModels() {
- return Collections.unmodifiableCollection(configModels);
- }
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/AbstractConfigModel.java b/validation/src/main/java/org/apache/tamaya/validation/spi/AbstractConfigModel.java
deleted file mode 100644
index 37fbfe1..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/spi/AbstractConfigModel.java
+++ /dev/null
@@ -1,88 +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 createObject 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.validation.spi;
-
-import org.apache.tamaya.validation.ConfigModel;
-
-import java.util.Objects;
-
-/**
- * Default configuration Model for a configuration area.
- */
-public abstract class AbstractConfigModel implements ConfigModel, Comparable<ConfigModel> {
- private final String owner;
- private final String name;
- private final String description;
- private boolean required = false;
-
-
- protected AbstractConfigModel(String owner, String name, boolean required, String description) {
- this.name = Objects.requireNonNull(name);
- this.owner = Objects.requireNonNull(owner);
- this.description = description;
- this.required = required;
- }
-
- @Override
- public String getOwner() {
- return owner;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public boolean isRequired() {
- return required;
- }
-
- @Override
- public int compareTo(ConfigModel configModel) {
- int compare = getType().compareTo(configModel.getType());
- if (compare != 0) {
- return compare;
- }
- return getName().compareTo(configModel.getName());
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- AbstractConfigModel that = (AbstractConfigModel) o;
- return getType().equals(that.getType()) && name.equals(that.name);
-
- }
-
- @Override
- public int hashCode() {
- return getType().hashCode() + name.hashCode();
- }
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/AbstractValidator.java b/validation/src/main/java/org/apache/tamaya/validation/spi/AbstractValidator.java
new file mode 100644
index 0000000..15de27a
--- /dev/null
+++ b/validation/src/main/java/org/apache/tamaya/validation/spi/AbstractValidator.java
@@ -0,0 +1,107 @@
+/*
+ * 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 createObject 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.validation.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.validation.ValidationCheck;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Base class for a validator.
+ */
+public abstract class AbstractValidator implements ConfigValidator {
+
+ /** The target key to validate. */
+ private String key;
+ /** The optional description. */
+ private String description;
+ /** The required flag. */
+ private boolean required;
+
+ /**
+ * Internal constructor.
+ * @param key the target configuration key, not null.
+ * @param required true, if the value/validation must be successful.
+ * @param description the description, not null.
+ */
+ protected AbstractValidator(String key, boolean required, String description) {
+ this.required = required;
+ this.description = description;
+ }
+
+ /**
+ * Get the area or paramter key.
+ * @return
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * Get the description of the validation.
+ * @return the description.
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Checks if the validation will declare an error if not met.
+ * @return true, if the validation must not fail.
+ */
+ public boolean isRequired() {
+ return required;
+ }
+
+ @Override
+ public List<ValidationCheck> validate(Configuration config) {
+ List<ValidationCheck> result = new ArrayList<>(1);
+ List<PropertyValue> configValues = config.get(key, new TypeLiteral<List<PropertyValue>>());
+ if (configValues.isEmpty() && required) {
+ result.add(ValidationCheck.createMissing(this, "Key " + key +" must be present"));
+ }else{
+ validateValues(configValues, result);
+ }
+ return result;
+ }
+
+ /**
+ * Internal method to override.
+ * @param configValues the config values read in order of precedence.
+ * @param result the result list, where the validation checks done should be added.
+ */
+ protected abstract void validateValues(List<PropertyValue> configValues, List<ValidationCheck> result);
+
+ @Override
+ public String toString() {
+ StringBuilder b = new StringBuilder();
+ b.append(getClass().getSimpleName()).append("{\n");
+ if (isRequired()) {
+ b.append(" required: ").append(isRequired()).append('\n');
+ }
+ b.append(" key: ").append(key).append('\n');
+ b.append(" description: ").append(description).append("\n}\n");
+ return b.toString();
+ }
+
+}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java b/validation/src/main/java/org/apache/tamaya/validation/spi/AreaValidator.java
similarity index 52%
copy from validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java
copy to validation/src/main/java/org/apache/tamaya/validation/spi/AreaValidator.java
index cf5372f..79e5e27 100644
--- a/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java
+++ b/validation/src/main/java/org/apache/tamaya/validation/spi/AreaValidator.java
@@ -19,12 +19,11 @@
package org.apache.tamaya.validation.spi;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.ModelTarget;
-import org.apache.tamaya.validation.Validation;
+import org.apache.tamaya.doc.DocumentedArea;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.apache.tamaya.validation.ValidationCheck;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
@@ -33,48 +32,64 @@ import java.util.logging.Logger;
/**
* Default configuration Model for a configuration parameter.
*/
-public class ParameterModel extends AbstractConfigModel {
- /** Optional regular expression for validating the createValue. */
- private final String regEx;
- /** The target type into which the createValue must be convertible. */
- private final Class<?> type;
+public class AreaValidator implements ConfigValidator {
+
+ /** The fully qualified parameter name. */
+ private String name;
+ /** The optional description. */
+ private String description;
+ /** The min cardinality. */
+ private int minCardinality;
+ /** The max cardinality. */
+ private int maxCardinality;
+ /** The owner instance, not null. */
+ private Object owner;
+ /** The parameter's target type. */
+ private Class<?> type;
/**
- * Internal constructor.
- * @param builder the builder, not null.
+ * Create a new property validator.
+ * @param documentedArea the property docs, not null.
*/
- protected ParameterModel(Builder builder) {
- super(builder.owner, builder.name, builder.required, builder.description);
- this.regEx = builder.regEx;
- this.type = builder.type;
- }
-
- @Override
- public ModelTarget getType() {
- return ModelTarget.Parameter;
+ public AreaValidator(DocumentedArea documentedArea) {
+ this.name = Objects.requireNonNull(documentedArea.getPath());
+ this.description = documentedArea.getDescription();
+ this.minCardinality = documentedArea.getMinCardinality();
+ this.maxCardinality = documentedArea.getMaxCardinality();
+ this.owner = documentedArea;
+ this.type = documentedArea.getValueType();
}
/**
- * Get the required parameter type.
- *
- * @return the type.
+ * Create a new property validator.
+ * @param builder the builder, not null.
*/
- public Class<?> getParameterType() {
- return type;
+ private AreaValidator(Builder builder) {
+ this.name = Objects.requireNonNull(builder.name);
+ this.description = builder.description;
+ this.minCardinality = builder.minCardinality;
+ this.maxCardinality = builder.maxCardinality;
+ this.owner = builder.owner;
+ this.type = builder.type;
}
+
@Override
- public Collection<Validation> validate(Configuration config) {
- List<Validation> result = new ArrayList<>(1);
- String configValue = config.get(getName());
- if (configValue == null && isRequired()) {
- result.add(Validation.createMissing(this));
+ public List<ValidationCheck> validate(Configuration config) {
+ List<ValidationCheck> result = new ArrayList<>(1);
+ Configuration section = config.map(ConfigurationFunctions.section(name));
+ int size = section.getProperties().size();
+ String baseText = description;
+ if(baseText==null){
+ baseText = "Validation failure for area '" + name + "': ";
+ }else{
+ baseText = baseText + " Validation failure: ";
}
- if (configValue != null && regEx != null) {
- if (!configValue.matches(regEx)) {
- result.add(Validation.createError(this, "Config createValue not matching expression: " + regEx + ", was " +
- configValue));
- }
+ if(minCardinality!=0 && minCardinality>size){
+ result.add(ValidationCheck.createError(this, baseText + "Min cardinality required: " + minCardinality +", was: " + size));
+ }
+ if(maxCardinality!=0 && maxCardinality<size){
+ result.add(ValidationCheck.createError(this, baseText + "Max cardinality exceeded: " + maxCardinality +", was: " + size));
}
return result;
}
@@ -82,12 +97,12 @@ public class ParameterModel extends AbstractConfigModel {
@Override
public String toString() {
StringBuilder b = new StringBuilder();
- b.append(getType()).append(": ").append(getName());
- if (isRequired()) {
- b.append(", required: ").append(isRequired());
+ b.append(type).append(": ").append(name);
+ if (minCardinality>0) {
+ b.append(", min: ").append(minCardinality);
}
- if (regEx != null) {
- b.append(", expression: ").append(regEx);
+ if (maxCardinality>0) {
+ b.append(", max: ").append(maxCardinality);
}
return b.toString();
}
@@ -107,11 +122,10 @@ public class ParameterModel extends AbstractConfigModel {
* @param owner the owner name, not null.
* @param name the fully qualified parameter name.
* @param required the required flag.
- * @param expression an optional regular expression to validate a createValue.
* @return the new ConfigModel instance.
*/
- public static ConfigModel of(String owner, String name, boolean required, String expression) {
- return new Builder(owner, name).setRequired(required).setExpression(expression).build();
+ public static AreaValidator of(Object owner, String name, boolean required) {
+ return new Builder(name, owner).setRequired().build();
}
/**
@@ -121,8 +135,20 @@ public class ParameterModel extends AbstractConfigModel {
* @param required the required flag.
* @return the new ConfigModel instance.
*/
- public static ConfigModel of(String owner, String name, boolean required) {
- return new Builder(owner, name).setRequired(required).build();
+ public static AreaValidator of(String owner, String name, boolean required) {
+ return new Builder(owner, name).setRequired().build();
+ }
+
+ /**
+ * Creates a new ConfigModel
+ * @param owner the owner name, not null.
+ * @param name the fully qualified parameter name.
+ * @param min the minimal cardinality.
+ * @param max the maximal cardinality.
+ * @return the new ConfigModel instance.
+ */
+ public static AreaValidator of(String owner, String name, int min, int max) {
+ return new Builder(owner, name).setMinCardinality(min).setMaxCardinality(max).build();
}
/**
@@ -131,8 +157,8 @@ public class ParameterModel extends AbstractConfigModel {
* @param name the fully qualified parameter name.
* @return the new ConfigModel instance.
*/
- public static ConfigModel of(String owner, String name) {
- return new Builder(owner, name).setRequired(false).build();
+ public static AreaValidator of(String owner, String name) {
+ return new Builder(owner, name).build();
}
@@ -142,25 +168,24 @@ public class ParameterModel extends AbstractConfigModel {
public static class Builder {
/** The parameter's target type. */
private Class<?> type;
- /** The owner. */
- private String owner;
/** The fully qualified parameter name. */
private String name;
- /** The optional validation expression. */
- private String regEx;
/** The optional description. */
private String description;
- /** The required flag. */
- private boolean required;
+ /** The min cardinality. */
+ private int minCardinality;
+ /** The max cardinality. */
+ private int maxCardinality;
+ /** The validation owner. */
+ private Object owner;
/**
* Creates a new Builder.
- * @param owner owner, not null.
* @param name the fully qualified parameter name, not null.
*/
- public Builder(String owner, String name) {
- this.owner = Objects.requireNonNull(owner);
+ public Builder(String name, Object owner) {
this.name = Objects.requireNonNull(name);
+ this.owner = Objects.requireNonNull(owner);
}
/**
@@ -182,32 +207,43 @@ public class ParameterModel extends AbstractConfigModel {
}
/**
- * Sets the required flag.
- * @param required the required flag.
+ * Sets the minimum cardinality required.
+ * @param minCardinality the minimum cardinality.
* @return the Builder for chaining
*/
- public Builder setRequired(boolean required) {
- this.required = required;
+ public Builder setMinCardinality(int minCardinality) {
+ this.minCardinality = minCardinality;
return this;
}
/**
- * Sets the optional description
- * @param description the description
+ * Sets the maximum cardinality required.
+ * @param maxCardinality the maximum cardinality.
* @return the Builder for chaining
*/
- public Builder setDescription(String description) {
- this.description = description;
+ public Builder setMaxCardinality(int maxCardinality) {
+ this.maxCardinality = maxCardinality;
+ return this;
+ }
+
+ /**
+ * Sets the minimum cardinality required to {@code 1}.
+ * @return the Builder for chaining
+ */
+ public Builder setRequired() {
+ this.minCardinality = 1;
+ this.maxCardinality = 0;
return this;
}
+
/**
- * Sets the optional validation expression
- * @param expression the validation expression
+ * Sets the optional description
+ * @param description the description
* @return the Builder for chaining
*/
- public Builder setExpression(String expression) {
- this.regEx = expression;
+ public Builder setDescription(String description) {
+ this.description = description;
return this;
}
@@ -216,7 +252,7 @@ public class ParameterModel extends AbstractConfigModel {
* @param owner the owner name, not null.
* @return the Builder for chaining
*/
- public Builder setOwner(String owner) {
+ public Builder setOwner(Object owner) {
this.owner = Objects.requireNonNull(owner);
return this;
}
@@ -235,8 +271,8 @@ public class ParameterModel extends AbstractConfigModel {
* Creates a new ConfigModel with the given parameters.
* @return a new ConfigModel , never null.
*/
- public ConfigModel build() {
- return new ParameterModel(this);
+ public AreaValidator build() {
+ return new AreaValidator(this);
}
}
}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigDocumentationMBean.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigDocumentationMBean.java
deleted file mode 100644
index 21e5ea1..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigDocumentationMBean.java
+++ /dev/null
@@ -1,53 +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 createObject 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.validation.spi;
-
-import org.apache.tamaya.validation.ModelTarget;
-
-/**
- * JMX Management bean for accessing current configuration information
- */
-public interface ConfigDocumentationMBean {
- /**
- * Validates the configuration for the given context.
- *
- * @param showUndefined allows filtering for undefined configuration elements.
- * @return the validation results, never null.
- */
- String validate(boolean showUndefined);
-
- String getConfigurationModel();
-
- String getConfigurationModel(ModelTarget type);
-
- /**
- * Find the validations by checking the validation's name using the given regular expression.
- * @param namePattern the regular expression to use, not null.
- * @return the sections defined, never null.
- */
- String findConfigurationModels(String namePattern);
-
- /**
- * Find the validations by checking the validation's name using the given regular expression.
- * @param type the target ModelTypes (optional), not null.
- * @param namePattern the regular expression to use, not null.
- * @return the sections defined, never null.
- */
- String findValidationModels(String namePattern, ModelTarget... type);
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigModelReader.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigModelReader.java
deleted file mode 100644
index 5b806af..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigModelReader.java
+++ /dev/null
@@ -1,142 +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 createObject 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.validation.spi;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.tamaya.validation.ConfigModel;
-
-/**
- * Utility class to read metamodel information from properties. Hereby these properties can be part createObject a
- * configuration (containing other entriees as well) or be dedicated model definition properties read
- * from any kind createObject source.
- */
-public final class ConfigModelReader {
-
- /** The default model entries selector. */
- private static final String DEFAULT_META_INFO_SELECTOR = ".model";
-
- /**
- * Utility class only.
- */
- private ConfigModelReader(){}
-
-
- /**
- * Loads validations as configured in the given properties.
- * @param owner owner, not null.
- * @param props the properties to be read
- * @return a collection createObject config validations.
- */
- public static Collection<ConfigModel> loadValidations(String owner, Map<String,String> props) {
- List<ConfigModel> result = new ArrayList<>();
- Set<String> itemKeys = new HashSet<>();
- for (Object key : props.keySet()) {
- if (key.toString().startsWith("_") &&
- key.toString().endsWith(DEFAULT_META_INFO_SELECTOR + ".target")) {
- itemKeys.add(key.toString().substring(0, key.toString().length() - ".model.target".length()));
- }
- }
- for (String baseKey : itemKeys) {
- String target = props.get(baseKey + ".model.target");
- String type = props.get(baseKey + ".model.type");
- if (type == null) {
- type = String.class.getName();
- }
- String value = props.get(baseKey + ".model.transitive");
- boolean transitive = false;
- if(value!=null) {
- transitive = Boolean.parseBoolean(value);
- }
- String description = props.get(baseKey + ".model.description");
- String regEx = props.get(baseKey + ".model.expression");
- String validations = props.get(baseKey + ".model.validations");
- String requiredVal = props.get(baseKey + ".model.required");
- String targetKey = baseKey.substring(1);
- if ("Parameter".equalsIgnoreCase(target)) {
- result.add(createParameterValidation(owner, targetKey,
- description, type, requiredVal, regEx, validations));
- } else if ("Section".equalsIgnoreCase(target)) {
- if(transitive){
- result.add(createSectionValidation(owner, targetKey+".*",
- description, requiredVal, validations));
- } else {
- result.add(createSectionValidation(owner, targetKey,
- description, requiredVal, validations));
- }
- }
- }
- return result;
- }
-
- /**
- * Creates a parameter validation.
- * @param paramName the param name, not null.
- * @param description the optional description
- * @param type the param type, default is String.
- * @param reqVal the required createValue, default is 'false'.
- * @param regEx an optional regular expression to be checked for this param
- * @param validations the optional custom validations to be performed.
- * @return the new validation for this parameter.
- */
- private static ConfigModel createParameterValidation(String owner, String paramName, String description, String type, String reqVal,
- String regEx, String validations) {
- boolean required = "true".equalsIgnoreCase(reqVal);
- ParameterModel.Builder builder = ParameterModel.builder(owner, paramName).setRequired(required)
- .setDescription(description).setExpression(regEx).setType(type);
-// if (validations != null) {
-// try {
-// // TODO define validator API
-//// builder.addValidations(loadValidations(validations));
-// } catch (Exception e) {
-// LOGGER.log(Level.WARNING, "Failed to load validations for " + paramName, e);
-// }
-// }
- return builder.build();
- }
-
- /**
- * Creates a section validation.
- * @param sectionName the section's name, not null.
- * @param description the optional description
- * @param reqVal the required createValue, default is 'false'.
- * @param validations the optional custom validations to be performed.
- * @return the new validation for this section.
- */
- private static ConfigModel createSectionValidation(String owner, String sectionName, String description, String reqVal,
- String validations) {
- boolean required = "true".equalsIgnoreCase(reqVal);
- SectionModel.Builder builder = SectionModel.builder(owner, sectionName).setRequired(required)
- .setDescription(description);
-// if (validations != null) {
-// try {
-// // TODO define validator API
-//// builder.addValidations(loadValidations(valiadtions));
-// } catch (Exception e) {
-// LOGGER.log(Level.WARNING, "Failed to load validations for " + sectionName, e);
-// }
-// }
- return builder.build();
- }
-}
diff --git a/documentation/src/main/java/org/apache/tamaya/validation/ConfigValidator.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidator.java
similarity index 70%
rename from documentation/src/main/java/org/apache/tamaya/validation/ConfigValidator.java
rename to validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidator.java
index 9a6b548..50be637 100644
--- a/documentation/src/main/java/org/apache/tamaya/validation/ConfigValidator.java
+++ b/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidator.java
@@ -16,11 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tamaya.validation;
+package org.apache.tamaya.validation.spi;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.validation.ValidationCheck;
+import java.util.List;
import java.util.function.Function;
-public interface ConfigValidator extends Function<Configuration, ValidationResult> {
+@FunctionalInterface
+public interface ConfigValidator {
+
+ /**
+ * Validaters the configuration.
+ * @param config the configuration to validate, not null.
+ * @return the findings evaluated.
+ */
+ List<ValidationCheck> validate(Configuration config);
+
}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/GroupModel.java b/validation/src/main/java/org/apache/tamaya/validation/spi/GroupModel.java
deleted file mode 100644
index 2957576..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/spi/GroupModel.java
+++ /dev/null
@@ -1,110 +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 createObject 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.validation.spi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.ModelTarget;
-import org.apache.tamaya.validation.Validation;
-
-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 GroupModel implements ConfigModel {
-
- private final String owner;
- private final String name;
- private boolean required;
- private List<ConfigModel> childModels = new ArrayList<>();
-
- public GroupModel(String owner, String name, ConfigModel... configModels){
- this(owner, name, Arrays.asList(configModels));
- }
-
- public GroupModel(String owner, String name, Collection<ConfigModel> configModels){
- this.owner = Objects.requireNonNull(owner);
- this.name = Objects.requireNonNull(name);
- this.childModels.addAll(configModels);
- this.childModels = Collections.unmodifiableList(childModels);
- for(ConfigModel val: configModels) {
- if(val.isRequired()){
- this.required = true;
- break;
- }
- }
- }
-
- @Override
- public String getOwner() {
- return owner;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public boolean isRequired() {
- return required;
- }
-
- @Override
- public ModelTarget getType() {
- return ModelTarget.Group;
- }
-
- @Override
- public String getDescription() {
- if(childModels.isEmpty()){
- return null;
- }
- StringBuilder b = new StringBuilder();
- for(ConfigModel val: childModels){
- b.append(" >> ").append(val);
- }
- return b.toString();
- }
-
- public Collection<ConfigModel> getValidations(){
- return childModels;
- }
-
- @Override
- public Collection<Validation> validate(Configuration config) {
- List<Validation> result = new ArrayList<>(1);
- for(ConfigModel child: childModels){
- result.addAll(child.validate(config));
- }
- return result;
- }
-
- @Override
- public String toString(){
- return String.valueOf(getType()) + ", getNumChilds: " + childModels.size() + ": " + getDescription();
- }
-
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ModelProviderSpi.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ModelProviderSpi.java
deleted file mode 100644
index 74bccd1..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/spi/ModelProviderSpi.java
+++ /dev/null
@@ -1,39 +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 createObject 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.validation.spi;
-
-import org.apache.tamaya.validation.ConfigModel;
-
-import java.util.Collection;
-
-/**
- * Model createObject 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 ModelProviderSpi {
-
- /**
- * Get the validation defined.
- *
- * @return the sections defined, never null.
- */
- Collection<ConfigModel> getConfigModels();
-
-}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java b/validation/src/main/java/org/apache/tamaya/validation/spi/PropertyValidator.java
similarity index 65%
rename from validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java
rename to validation/src/main/java/org/apache/tamaya/validation/spi/PropertyValidator.java
index cf5372f..afce656 100644
--- a/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java
+++ b/validation/src/main/java/org/apache/tamaya/validation/spi/PropertyValidator.java
@@ -19,12 +19,10 @@
package org.apache.tamaya.validation.spi;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.ModelTarget;
-import org.apache.tamaya.validation.Validation;
+import org.apache.tamaya.doc.DocumentedProperty;
+import org.apache.tamaya.validation.ValidationCheck;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
@@ -33,48 +31,56 @@ import java.util.logging.Logger;
/**
* Default configuration Model for a configuration parameter.
*/
-public class ParameterModel extends AbstractConfigModel {
- /** Optional regular expression for validating the createValue. */
- private final String regEx;
- /** The target type into which the createValue must be convertible. */
- private final Class<?> type;
+public class PropertyValidator implements ConfigValidator {
+
+ /** The parameter's target type. */
+ private Class<?> type;
+ /** The fully qualified parameter name. */
+ private String name;
+ /** The optional description. */
+ private String description;
+ /** The required flag. */
+ private boolean required;
+ /** The owner instance, not null. */
+ private Object owner;
/**
- * Internal constructor.
- * @param builder the builder, not null.
+ * Create a new property validator.
+ * @param documentedProperty the property docs, not null.
*/
- protected ParameterModel(Builder builder) {
- super(builder.owner, builder.name, builder.required, builder.description);
- this.regEx = builder.regEx;
- this.type = builder.type;
- }
-
- @Override
- public ModelTarget getType() {
- return ModelTarget.Parameter;
+ public PropertyValidator(DocumentedProperty documentedProperty) {
+ this.name = Objects.requireNonNull(documentedProperty.getName());
+ this.description = documentedProperty.getDescription();
+ this.required = documentedProperty.isRequired();
+ this.owner = documentedProperty;
+ this.type = documentedProperty.getValueType();
}
/**
- * Get the required parameter type.
- *
- * @return the type.
+ * Create a new property validator.
+ * @param builder the builder, not null.
*/
- public Class<?> getParameterType() {
- return type;
+ private PropertyValidator(Builder builder) {
+ this.name = Objects.requireNonNull(builder.name);
+ this.description = builder.description;
+ this.required = builder.required;
+ this.owner = builder.owner;
+ this.type = builder.type;
}
+
@Override
- public Collection<Validation> validate(Configuration config) {
- List<Validation> result = new ArrayList<>(1);
- String configValue = config.get(getName());
- if (configValue == null && isRequired()) {
- result.add(Validation.createMissing(this));
+ public List<ValidationCheck> validate(Configuration config) {
+ List<ValidationCheck> result = new ArrayList<>(1);
+ String configValue = config.getOrDefault(name, null);
+ String baseText = description;
+ if(baseText==null){
+ baseText = "Validation failure for property '" + name + "': ";
+ }else{
+ baseText = baseText + " Validation failure: ";
}
- if (configValue != null && regEx != null) {
- if (!configValue.matches(regEx)) {
- result.add(Validation.createError(this, "Config createValue not matching expression: " + regEx + ", was " +
- configValue));
- }
+ if (configValue == null && required) {
+ result.add(ValidationCheck.createMissing(this, baseText + " Missing."));
}
return result;
}
@@ -82,12 +88,9 @@ public class ParameterModel extends AbstractConfigModel {
@Override
public String toString() {
StringBuilder b = new StringBuilder();
- b.append(getType()).append(": ").append(getName());
- if (isRequired()) {
- b.append(", required: ").append(isRequired());
- }
- if (regEx != null) {
- b.append(", expression: ").append(regEx);
+ b.append(type).append(": ").append(name);
+ if (required) {
+ b.append(", required: ").append(required);
}
return b.toString();
}
@@ -107,11 +110,10 @@ public class ParameterModel extends AbstractConfigModel {
* @param owner the owner name, not null.
* @param name the fully qualified parameter name.
* @param required the required flag.
- * @param expression an optional regular expression to validate a createValue.
* @return the new ConfigModel instance.
*/
- public static ConfigModel of(String owner, String name, boolean required, String expression) {
- return new Builder(owner, name).setRequired(required).setExpression(expression).build();
+ public static PropertyValidator of(Object owner, String name, boolean required) {
+ return new Builder(name, owner).setRequired(required).build();
}
/**
@@ -121,7 +123,7 @@ public class ParameterModel extends AbstractConfigModel {
* @param required the required flag.
* @return the new ConfigModel instance.
*/
- public static ConfigModel of(String owner, String name, boolean required) {
+ public static PropertyValidator of(String owner, String name, boolean required) {
return new Builder(owner, name).setRequired(required).build();
}
@@ -131,7 +133,7 @@ public class ParameterModel extends AbstractConfigModel {
* @param name the fully qualified parameter name.
* @return the new ConfigModel instance.
*/
- public static ConfigModel of(String owner, String name) {
+ public static PropertyValidator of(String owner, String name) {
return new Builder(owner, name).setRequired(false).build();
}
@@ -142,25 +144,22 @@ public class ParameterModel extends AbstractConfigModel {
public static class Builder {
/** The parameter's target type. */
private Class<?> type;
- /** The owner. */
- private String owner;
/** The fully qualified parameter name. */
private String name;
- /** The optional validation expression. */
- private String regEx;
/** The optional description. */
private String description;
/** The required flag. */
private boolean required;
+ /** The validation owner. */
+ private Object owner;
/**
* Creates a new Builder.
- * @param owner owner, not null.
* @param name the fully qualified parameter name, not null.
*/
- public Builder(String owner, String name) {
- this.owner = Objects.requireNonNull(owner);
+ public Builder(String name, Object owner) {
this.name = Objects.requireNonNull(name);
+ this.owner = Objects.requireNonNull(owner);
}
/**
@@ -202,21 +201,11 @@ public class ParameterModel extends AbstractConfigModel {
}
/**
- * Sets the optional validation expression
- * @param expression the validation expression
- * @return the Builder for chaining
- */
- public Builder setExpression(String expression) {
- this.regEx = expression;
- return this;
- }
-
- /**
* Sets the owner name.
* @param owner the owner name, not null.
* @return the Builder for chaining
*/
- public Builder setOwner(String owner) {
+ public Builder setOwner(Object owner) {
this.owner = Objects.requireNonNull(owner);
return this;
}
@@ -235,8 +224,8 @@ public class ParameterModel extends AbstractConfigModel {
* Creates a new ConfigModel with the given parameters.
* @return a new ConfigModel , never null.
*/
- public ConfigModel build() {
- return new ParameterModel(this);
+ public PropertyValidator build() {
+ return new PropertyValidator(this);
}
}
}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/RegexPropertyValidator.java b/validation/src/main/java/org/apache/tamaya/validation/spi/RegexPropertyValidator.java
new file mode 100644
index 0000000..a630cf2
--- /dev/null
+++ b/validation/src/main/java/org/apache/tamaya/validation/spi/RegexPropertyValidator.java
@@ -0,0 +1,105 @@
+/*
+ * 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 createObject 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.validation.spi;
+
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.validation.ValidationCheck;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Default configuration Model for a configuration parameter.
+ */
+public class RegexPropertyValidator extends AbstractValidator {
+
+ /** Regular expression for validating the value. */
+ private final String regEx;
+
+ private boolean warningOnly;
+
+ private boolean validateAll;
+
+ /**
+ * Creates a new validator.
+ * @param regEx the regular expression to check.
+ * @param validateAll true, if all property values provided should be validated.
+ * @param warningOnly if activated only warning will be generated.
+ * @param key the property key
+ * @param description a description of the check.
+ */
+ public RegexPropertyValidator(String key, String regEx, boolean validateAll, boolean warningOnly, String description) {
+ super(key, false, description);
+ this.regEx = Objects.requireNonNull(regEx);
+ this.validateAll = validateAll;
+ this.warningOnly = warningOnly;
+ }
+
+ /**
+ * Creates a new validator.
+ * @param regEx the regular expression to check.
+ * @param key the property key
+ * @param description a description of the check.
+ */
+ public RegexPropertyValidator(String key, String regEx, String description) {
+ super(key, false, description);
+ this.regEx = Objects.requireNonNull(regEx);
+ }
+
+
+ @Override
+ protected void validateValues(List<PropertyValue> configValues, List<ValidationCheck> result) {
+ if (configValues.isEmpty() && isRequired()) {
+ result.add(ValidationCheck.createMissing(this, "Missing key: " + getKey()));
+ }
+ String baseText = getDescription();
+ if(baseText==null){
+ baseText = "Validation failure for property '" + getKey() + "': ";
+ }else{
+ baseText = baseText + " Validation failure: ";
+ }
+ if (regEx != null) {
+ for(PropertyValue value:configValues) {
+ if (!value.getValue().matches(regEx)) {
+ if(warningOnly){
+ result.add(ValidationCheck.createWarning(this, baseText + " Value not matching expression: " + regEx + ", was " +
+ configValues.get(0).getValue()));
+ }else {
+ result.add(ValidationCheck.createError(this, baseText + " Value not matching expression: " + regEx + ", was " +
+ configValues.get(0).getValue()));
+ }
+ }
+ if(!validateAll){
+ break;
+ }
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder b = new StringBuilder();
+ b.append(getClass().getSimpleName()).append("{\n");
+ b.append(" key : ").append(getKey()).append('\n');
+ b.append(" required : ").append(isRequired()).append('\n');
+ b.append(" expression: ").append(regEx).append("\n}\n");
+ return b.toString();
+ }
+
+}
diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/SectionModel.java b/validation/src/main/java/org/apache/tamaya/validation/spi/SectionModel.java
deleted file mode 100644
index 79ee50e..0000000
--- a/validation/src/main/java/org/apache/tamaya/validation/spi/SectionModel.java
+++ /dev/null
@@ -1,202 +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 createObject 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.validation.spi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.validation.ConfigModel;
-import org.apache.tamaya.validation.ModelTarget;
-import org.apache.tamaya.validation.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 section.
- */
-public class SectionModel extends GroupModel {
-
- /**
- * Creates a new builder.
- * @param owner owner, not null.
- * @param name the section name.
- * @return a new builder instance.
- */
- public static Builder builder(String owner, String name){
- return new Builder(owner, name);
- }
-
- /**
- * Creates a section validation for the given section.
- * @param owner owner, not null.
- * @param name the fully qualified section name
- * @param required flag, if the section is required to be present.
- * @return the ConfigModel instance
- */
- public static ConfigModel of(String owner, String name, boolean required){
- return new Builder(owner, name).setRequired(required).build();
- }
-
- /**
- * Creates a section validation for the given section.
- * @param owner owner, not null.
- * @param name the fully qualified section name
- * @param required flag, if the section is required to be present.
- * @param configModels additional configModels
- * @return a new builder, never null.
- */
- public static ConfigModel of(String owner, String name, boolean required, ConfigModel... configModels){
- return new Builder(owner, name).setRequired(required).addValidations(configModels).build();
- }
-
- /**
- * Internal constructor.
- * @param builder the builder, not null.
- */
- protected SectionModel(Builder builder) {
- super(builder.owner, builder.name, builder.childConfigModels);
- }
-
- @Override
- public ModelTarget getType(){
- return ModelTarget.Section;
- }
-
- @Override
- public Collection<Validation> validate(Configuration config) {
- Map<String,String> map = config.getProperties();
- String lookupKey = getName() + '.';
- boolean present = false;
- for(String key:map.keySet()){
- if(key.startsWith("_")){
- continue;
- }
- if(key.startsWith(lookupKey)){
- present = true;
- break;
- }
- }
- List<Validation> result = new ArrayList<>(1);
- if(isRequired() && !present) {
- result.add(Validation.createMissing(this));
- }
- result.addAll(super.validate(config));
- return result;
- }
-
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder();
- b.append(getType()).append(": ").append(getName());
- if(isRequired()) {
- b.append(", required: " ).append(isRequired());
- }
- for(ConfigModel val:getValidations()){
- b.append(", ").append(val.toString());
- }
- return b.toString();
- }
-
- /**
- * Builder for setting up a AreaConfigModel instance.
- */
- public static class Builder{
- /** The section owner. */
- private String owner;
- /** The section name. */
- private String name;
- /** The optional description. */
- private String description;
- /** The required flag. */
- private boolean required;
- /** The (optional) custom validations.*/
- private final List<ConfigModel> childConfigModels = new ArrayList<>();
-
- /**
- * Creates a new Builder.
- * @param owner owner, not null.
- * @param sectionName the section name, not null.
- */
- public Builder(String owner, String sectionName){
- this.owner = Objects.requireNonNull(owner);
- this.name = Objects.requireNonNull(sectionName);
- }
-
- /**
- * Add configModels.
- * @param configModels the configModels, not null.
- * @return the Builder for chaining.
- */
- public Builder addValidations(ConfigModel... configModels){
- this.childConfigModels.addAll(Arrays.asList(configModels));
- return this;
- }
-
- /**
- * Add configModels.
- * @param configModels the configModels, not null.
- * @return the Builder for chaining.
- */
- public Builder addValidations(Collection<ConfigModel> configModels){
- this.childConfigModels.addAll(configModels);
- return this;
- }
-
- /**
- * Sets the required flag.
- * @param required zhe flag.
- * @return the Builder for chaining.
- */
- public Builder setRequired(boolean required){
- this.required = required;
- return this;
- }
-
- /**
- * Set the )optional) description.
- * @param description the description.
- * @return the Builder for chaining.
- */
- public Builder setDescription(String description){
- this.description = description;
- return this;
- }
-
- /**
- * Set the section name
- * @param name the section name, not null.
- * @return the Builder for chaining.
- */
- public Builder setName(String name){
- this.name = Objects.requireNonNull(name);
- return this;
- }
-
- /**
- * Build a new ConfigModel instance.
- * @return the new ConfigModel instance, not null.
- */
- public ConfigModel build(){
- return new SectionModel(this);
- }
- }
-}
diff --git a/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java b/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java
deleted file mode 100644
index 8edf50d..0000000
--- a/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java
+++ /dev/null
@@ -1,68 +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 createObject 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.validation;
-
-import org.apache.tamaya.validation.spi.SectionModel;
-import org.apache.tamaya.validation.spi.ParameterModel;
-import org.apache.tamaya.validation.spi.GroupModel;
-import org.apache.tamaya.validation.spi.ModelProviderSpi;
-
-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 ConfigModelProviderTest implements ModelProviderSpi {
-
- private List<ConfigModel> configModels = new ArrayList<>(1);
-
- public ConfigModelProviderTest(){
- configModels.add(new TestConfigModel());
- configModels = Collections.unmodifiableList(configModels);
- }
-
- public Collection<ConfigModel> getConfigModels() {
- return configModels;
- }
-
- private static final class TestConfigModel extends GroupModel {
-
- public TestConfigModel(){
- super("TestConfigModel", "TestConfig", new SectionModel.Builder("TestConfigModel",
- "a.test.existing").setRequired(true).build(),
- ParameterModel.of("TestConfigModel", "a.test.existing.aParam", true),
- ParameterModel.of("TestConfigModel", "a.test.existing.optionalParam"),
- ParameterModel.of("TestConfigModel", "a.test.existing.aABCParam", false, "[ABC].*"),
- new SectionModel.Builder("TestConfigModel", "a.test.notexisting").setRequired(true).build(),
- ParameterModel.of("TestConfigModel", "a.test.notexisting.aParam", true),
- ParameterModel.of("TestConfigModel", "a.test.notexisting.optionalParam"),
- ParameterModel.of("TestConfigModel", "a.test.existing.aABCParam2", false, "[ABC].*"));
- }
- @Override
- public String getName() {
- return "TestConfigConfigModel";
- }
-
- }
-
-}
diff --git a/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java b/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java
deleted file mode 100644
index bca328c..0000000
--- a/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java
+++ /dev/null
@@ -1,53 +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 createObject 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.validation;
-
-import org.apache.tamaya.Configuration;
-import org.junit.Test;
-
-/**
- * Created by Anatole on 10.08.2015.
- */
-public class ValidationTests {
-
- @Test
- public void testValidate_Config(){
- System.err.println(ConfigModelManager.validate(Configuration.current()));
- }
-
- @Test
- public void testAllValidations(){
- System.err.println(ConfigModelManager.getModels());
- }
-
- @Test
- public void testConfigInfo(){
- System.err.println(ConfigModelManager.getConfigModelDescription(ConfigModelManager.getModels()));
- }
-
- @Test
- public void testValidateAll(){
- System.err.println("Including UNDEFINED: \n" + ConfigModelManager.validate(Configuration.current(), true));
- }
-
- @Test
- public void testModels(){
- System.err.println("MODELS: " +ConfigModelManager.getModels());
- }
-}
diff --git a/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java b/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java
deleted file mode 100644
index b6a1203..0000000
--- a/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java
+++ /dev/null
@@ -1,108 +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 createObject 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.validation.internal;
-
-import org.apache.tamaya.validation.ModelTarget;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Created by Anatole on 19.08.2015.
- */
-public class ConfigDocumentationBeanTest {
-
- private final ConfigDocumentationBean mbean = new ConfigDocumentationBean();
-
- @Test
- public void testValidate_NoUnknowns() throws Exception {
- String results = mbean.validate(false);
- assertNotNull(results);
- assertFalse(results.trim().isEmpty());
- assertTrue(results.contains("\"target\":\"Parameter\""));
- assertTrue(results.contains("\"result\":\"MISSING\""));
- assertFalse(results.contains("\"description\":\"Undefined key: "));
- assertFalse(results.contains(" \"result\":\"UNDEFINED\""));
- }
-
- @Test
- public void testValidate_WithUnknowns() throws Exception {
- String results = mbean.validate(true);
- assertNotNull(results);
- assertFalse(results.trim().isEmpty());
- // test transitive excludes createObject default sys properties
- assertFalse(results.contains("\"name\":\"java"));
- assertFalse(results.contains("\"name\":\"sun."));
- assertFalse(results.contains("\"name\":\"file."));
- // test others
- assertTrue(results.contains("\"target\":\"Parameter\""));
- assertTrue(results.contains("\"target\":\"Section\""));
- assertTrue(results.contains("\"result\":\"MISSING\""));
- assertTrue(results.contains("\"description\":\"Undefined key: "));
- assertTrue(results.contains(" \"result\":\"UNDEFINED\""));
- }
-
- @Test
- public void testGetConfigurationModel() throws Exception {
- String results = mbean.getConfigurationModel();
- assertNotNull(results);
- assertFalse(results.trim().isEmpty());
- assertTrue(results.contains("\"target\":\"Parameter\""));
- assertTrue(results.contains("\"name\":\"MyNumber\""));
- assertTrue(results.contains("\"name\":\"a.b.c\""));
- assertTrue(results.contains("\"required\":true"));
- }
-
- @Test
- public void testGetConfigurationModel_WithSection() throws Exception {
- String results = mbean.getConfigurationModel(ModelTarget.Parameter);
- assertNotNull(results);
- assertFalse(results.trim().isEmpty());
- assertTrue(results.contains("\"target\":\"Parameter\""));
- assertFalse(results.contains("\"target\":\"Section\""));
- assertTrue(results.contains("\"required\":true"));
- }
-
- @Test
- public void testFindConfigurationModels() throws Exception {
- String results = mbean.findConfigurationModels("a");
- assertNotNull(results);
- assertFalse(results.trim().isEmpty());
- assertFalse(results.contains("\"target\":\"Parameter\""));
- assertTrue(results.contains("\"target\":\"Section\""));
- }
-
- @Test
- public void testFindValidationModels() throws Exception {
- String results = mbean.findValidationModels("a", ModelTarget.Section);
- assertNotNull(results);
- assertFalse(results.trim().isEmpty());
- assertFalse(results.contains("\"target\":\"Parameter\""));
- assertTrue(results.contains("\"target\":\"Section\""));
- System.out.println(results);
- }
-
- @Test
- public void testToString() throws Exception {
- String toString = mbean.toString();
- System.out.println(toString);
- }
-}
\ No newline at end of file
diff --git a/validation/src/test/java/test/model/TestConfigAccessor.java b/validation/src/test/java/test/model/TestConfigAccessor.java
deleted file mode 100644
index 6ccc6fe..0000000
--- a/validation/src/test/java/test/model/TestConfigAccessor.java
+++ /dev/null
@@ -1,45 +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 createObject 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 test.model;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-
-import java.util.Map;
-
-/**
- * Created by atsticks on 30.04.16.
- */
-public final class TestConfigAccessor {
-
- private TestConfigAccessor(){}
-
- public static Map<String,String> readAllProperties(){
- return Configuration.current()
- .getProperties();
- }
-
- public static Configuration readConfiguration(){
- return Configuration.current();
- }
-
- public static String readProperty(Configuration config, String key){
- return config.get(key);
- }
-}