http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigDocumentationMBean.java ---------------------------------------------------------------------- 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 dbacaa2..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 of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.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); -}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigModelReader.java ---------------------------------------------------------------------- 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 d730060..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 of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.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 of a - * configuration (containing other entriees as well) or be dedicated model definition properties read - * from any kind of 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 of 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 value, 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 value, 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(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidationMBean.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidationMBean.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidationMBean.java new file mode 100644 index 0000000..fc01e61 --- /dev/null +++ b/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidationMBean.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.validation.spi; + +import org.apache.tamaya.validation.ValidationTarget; + +/** + * JMX Management bean for accessing current configuration information + */ +public interface ConfigValidationMBean { + /** + * 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(ValidationTarget 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, ValidationTarget... type); +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidationReader.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidationReader.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidationReader.java new file mode 100644 index 0000000..0240304 --- /dev/null +++ b/validation/src/main/java/org/apache/tamaya/validation/spi/ConfigValidationReader.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.validation.spi; + +import java.util.*; + +import org.apache.tamaya.validation.ValidationModel; + +/** + * Utility class to read metamodel information from properties. Hereby these properties can be part of a + * configuration (containing other entriees as well) or be dedicated model definition properties read + * from any kind of source. + */ +public final class ConfigValidationReader { + + /** The default model entries selector. */ + private static final String DEFAULT_META_INFO_SELECTOR = ".model"; + + /** + * Utility class only. + */ + private ConfigValidationReader(){} + + + /** + * Loads validations as configured in the given properties. + * @param owner owner, not null. + * @param props the properties to be read + * @return a collection of config validations. + */ + public static Collection<ValidationModel> loadValidations(String owner, Map<String,String> props) { + List<ValidationModel> result = new ArrayList<>(); + Set<String> itemKeys = new HashSet<>(); + for (String 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"); + 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); + try { + if ("Parameter".equalsIgnoreCase(target)) { + result.add(validateParameter(owner, targetKey, + description, type, requiredVal, regEx, validations)); + } else if ("Section".equalsIgnoreCase(target)) { + if (transitive) { + result.add(validateSection(owner, targetKey + ".*", + description, requiredVal, validations)); + } else { + result.add(validateSection(owner, targetKey, + description, requiredVal, validations)); + } + } + }catch(Exception e){ + e.printStackTrace(); + } + } + 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 value, 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 ValidationModel validateParameter(String owner, String paramName, String description, String type, String reqVal, + String regEx, String validations) { + boolean required = "true".equalsIgnoreCase(reqVal); + ValidateParameter.Builder builder = ValidateParameter.builder(owner, paramName).setRequired(required) + .setDescription(description).setExpression(regEx); + if(type!=null) { + builder.setType(type); + } +// if(validations!=null) { +// builder.setValidations(validations); +// } + return builder.build(); + } + + /** + * Creates a section validation. + * @param sectionName the section's name, not null. + * @param description the optional description + * @param reqVal the required value, default is 'false'. + * @param validations the optional custom validations to be performed. + * @return the new validation for this section. + */ + private static ValidationModel validateSection(String owner, String sectionName, String description, String reqVal, + String validations) { + boolean required = "true".equalsIgnoreCase(reqVal); + ValidateSection.Builder builder = ValidateSection.builder(owner, sectionName).setRequired(required) + .setDescription(description); + // if(validations!=null) { +// builder.setValidations(validations); +// } + return builder.build(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/GroupModel.java ---------------------------------------------------------------------- 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 7266db7..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 of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.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()) + ", size: " + childModels.size() + ": " + getDescription(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ModelProviderSpi.java ---------------------------------------------------------------------- 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 9e2a4d4..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 of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.validation.spi; - -import org.apache.tamaya.validation.ConfigModel; - -import java.util.Collection; - -/** - * Model of a configuration state. A model can be a full model, or a partial model, validating only - * a configuration subset. This allows better user feedback because big configurations can be grouped - * and validated by multiple (partial) models. - */ -public interface ModelProviderSpi { - - /** - * Get the validation defined. - * - * @return the sections defined, never null. - */ - Collection<ConfigModel> getConfigModels(); - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java deleted file mode 100644 index f6acafe..0000000 --- a/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.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.Collection; -import java.util.List; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Default configuration Model for a configuration parameter. - */ -public class ParameterModel extends AbstractConfigModel { - /** Optional regular expression for validating the value. */ - private final String regEx; - /** The target type into which the value must be convertible. */ - private final Class<?> type; - - /** - * Internal constructor. - * @param builder the builder, 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; - } - - /** - * Get the required parameter type. - * - * @return the type. - */ - public Class<?> getParameterType() { - return 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.ofMissing(this)); - } - if (configValue != null && regEx != null) { - if (!configValue.matches(regEx)) { - result.add(Validation.ofError(this, "Config value not matching expression: " + regEx + ", was " + - configValue)); - } - } - return result; - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(); - b.append(getType()).append(": ").append(getName()); - if (isRequired()) { - b.append(", required: ").append(isRequired()); - } - if (regEx != null) { - b.append(", expression: ").append(regEx); - } - return b.toString(); - } - - /** - * Creates a new Builder instance. - * @param owner the owner name, not null. - * @param name the fully qualified parameter name. - * @return a new builder, never null. - */ - public static Builder builder(String owner, String name) { - return new Builder(owner, name); - } - - /** - * Creates a new ConfigModel - * @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 value. - * @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(); - } - - /** - * Creates a new ConfigModel - * @param owner the owner name, not null. - * @param name the fully qualified parameter name. - * @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(); - } - - /** - * Creates a new ConfigModel. The parameter will be defined as optional. - * @param owner the owner name, not null. - * @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(); - } - - - /** - * A new Builder for creating ParameterModel instances. - */ - 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; - - /** - * 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); - this.name = Objects.requireNonNull(name); - } - - /** - * Sets the target type. - * @param type the type, not null. - * @return the Builder for chaining - */ - public Builder setType(String type) { - try { - this.type = Class.forName(type); - } catch (ClassNotFoundException e) { - try { - this.type = Class.forName("java.ui.lang."+type); - } catch (ClassNotFoundException e2) { - Logger.getLogger(getClass().getName()).log(Level.INFO, "Failed to load parameter type: " + type, e2); - } - } - return this; - } - - /** - * Sets the required flag. - * @param required the required flag. - * @return the Builder for chaining - */ - public Builder setRequired(boolean required) { - this.required = required; - return this; - } - - /** - * Sets the optional description - * @param description the description - * @return the Builder for chaining - */ - public Builder setDescription(String description) { - this.description = description; - return this; - } - - /** - * 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) { - this.owner = Objects.requireNonNull(owner); - return this; - } - - /** - * Sets the fully qualified parameter name. - * @param name the fully qualified parameter name, not null. - * @return the Builder for chaining - */ - public Builder setName(String name) { - this.name = Objects.requireNonNull(name); - return this; - } - - /** - * Creates a new ConfigModel with the given parameters. - * @return a new ConfigModel , never null. - */ - public ConfigModel build() { - return new ParameterModel(this); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/SectionModel.java ---------------------------------------------------------------------- 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 23d9f91..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 of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.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.ofMissing(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); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateGroup.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateGroup.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateGroup.java new file mode 100644 index 0000000..6b7634c --- /dev/null +++ b/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateGroup.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.validation.spi; + +import org.apache.tamaya.validation.ValidationModel; +import org.apache.tamaya.validation.ValidationTarget; +import org.apache.tamaya.validation.Validation; + +import javax.config.Config; +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 ValidateGroup implements ValidationModel { + + private final String owner; + private final String name; + private boolean required; + private List<ValidationModel> childModels = new ArrayList<>(); + + public ValidateGroup(String owner, String name, ValidationModel... configModels){ + this(owner, name, Arrays.asList(configModels)); + } + + public ValidateGroup(String owner, String name, Collection<ValidationModel> configModels){ + this.owner = Objects.requireNonNull(owner); + this.name = Objects.requireNonNull(name); + this.childModels.addAll(configModels); + this.childModels = Collections.unmodifiableList(childModels); + for(ValidationModel 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 ValidationTarget getType() { + return ValidationTarget.Group; + } + + @Override + public String getDescription() { + if(childModels.isEmpty()){ + return null; + } + StringBuilder b = new StringBuilder(); + for(ValidationModel val: childModels){ + b.append(" >> ").append(val); + } + return b.toString(); + } + + public Collection<ValidationModel> getValidations(){ + return childModels; + } + + @Override + public Collection<Validation> validate(Config config) { + List<Validation> result = new ArrayList<>(1); + for(ValidationModel child: childModels){ + result.addAll(child.validate(config)); + } + return result; + } + + @Override + public String toString(){ + return String.valueOf(getType()) + ", size: " + childModels.size() + ": " + getDescription(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateParameter.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateParameter.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateParameter.java new file mode 100644 index 0000000..5d598f1 --- /dev/null +++ b/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateParameter.java @@ -0,0 +1,242 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.validation.spi; + +import org.apache.tamaya.validation.ValidationModel; +import org.apache.tamaya.validation.ValidationTarget; +import org.apache.tamaya.validation.Validation; + +import javax.config.Config; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Default configuration Model for a configuration parameter. + */ +public class ValidateParameter extends AbstractConfigModel { + /** Optional regular expression for validating the value. */ + private final String regEx; + /** The target type into which the value must be convertible. */ + private final Class<?> type; + + /** + * Internal constructor. + * @param builder the builder, not null. + */ + protected ValidateParameter(Builder builder) { + super(builder.owner, builder.name, builder.required, builder.description); + this.regEx = builder.regEx; + this.type = builder.type; + } + + @Override + public ValidationTarget getType() { + return ValidationTarget.Parameter; + } + + /** + * Get the required parameter type. + * + * @return the type. + */ + public Class<?> getParameterType() { + return type; + } + + @Override + public Collection<Validation> validate(Config config) { + List<Validation> result = new ArrayList<>(1); + String configValue = config.getValue(getName(), String.class); + if (configValue == null && isRequired()) { + result.add(Validation.checkMissing(this)); + } + if (configValue != null && regEx != null) { + if (!configValue.matches(regEx)) { + result.add(Validation.checkError(this, "Config value not matching expression: " + regEx + ", was " + + configValue)); + } + } + return result; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + b.append(getType()).append(": ").append(getName()); + if (isRequired()) { + b.append(", required: ").append(isRequired()); + } + if (regEx != null) { + b.append(", expression: ").append(regEx); + } + return b.toString(); + } + + /** + * Creates a new Builder instance. + * @param owner the owner name, not null. + * @param name the fully qualified parameter name. + * @return a new builder, never null. + */ + public static Builder builder(String owner, String name) { + return new Builder(owner, name); + } + + /** + * Creates a new ConfigModel + * @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 value. + * @return the new ConfigModel instance. + */ + public static ValidationModel of(String owner, String name, boolean required, String expression) { + return new Builder(owner, name).setRequired(required).setExpression(expression).build(); + } + + /** + * Creates a new ConfigModel + * @param owner the owner name, not null. + * @param name the fully qualified parameter name. + * @param required the required flag. + * @return the new ConfigModel instance. + */ + public static ValidationModel of(String owner, String name, boolean required) { + return new Builder(owner, name).setRequired(required).build(); + } + + /** + * Creates a new ConfigModel. The parameter will be defined as optional. + * @param owner the owner name, not null. + * @param name the fully qualified parameter name. + * @return the new ConfigModel instance. + */ + public static ValidationModel of(String owner, String name) { + return new Builder(owner, name).setRequired(false).build(); + } + + + /** + * A new Builder for creating ParameterModel instances. + */ + 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; + + /** + * 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); + this.name = Objects.requireNonNull(name); + } + + /** + * Sets the target type. + * @param type the type, not null. + * @return the Builder for chaining + */ + public Builder setType(String type) { + try { + this.type = Class.forName(type); + } catch (ClassNotFoundException e) { + try { + this.type = Class.forName("java.lang."+type); + } catch (ClassNotFoundException e2) { + Logger.getLogger(getClass().getName()).log(Level.INFO, "Failed to load parameter type: " + type, e2); + } + } + return this; + } + + /** + * Sets the required flag. + * @param required the required flag. + * @return the Builder for chaining + */ + public Builder setRequired(boolean required) { + this.required = required; + return this; + } + + /** + * Sets the optional description + * @param description the description + * @return the Builder for chaining + */ + public Builder setDescription(String description) { + this.description = description; + return this; + } + + /** + * 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) { + this.owner = Objects.requireNonNull(owner); + return this; + } + + /** + * Sets the fully qualified parameter name. + * @param name the fully qualified parameter name, not null. + * @return the Builder for chaining + */ + public Builder setName(String name) { + this.name = Objects.requireNonNull(name); + return this; + } + + /** + * Creates a new ConfigModel with the given parameters. + * @return a new ConfigModel , never null. + */ + public ValidationModel build() { + return new ValidateParameter(this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateSection.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateSection.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateSection.java new file mode 100644 index 0000000..99e24e7 --- /dev/null +++ b/validation/src/main/java/org/apache/tamaya/validation/spi/ValidateSection.java @@ -0,0 +1,201 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.validation.spi; + +import org.apache.tamaya.validation.ValidationModel; +import org.apache.tamaya.validation.ValidationTarget; +import org.apache.tamaya.validation.Validation; + +import javax.config.Config; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Objects; + +/** + * Default configuration Model for a configuration section. + */ +public class ValidateSection extends ValidateGroup { + + /** + * 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 ValidationModel 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 ValidationModel of(String owner, String name, boolean required, ValidationModel... configModels){ + return new Builder(owner, name).setRequired(required).addValidations(configModels).build(); + } + + /** + * Internal constructor. + * @param builder the builder, not null. + */ + protected ValidateSection(Builder builder) { + super(builder.owner, builder.name, builder.childConfigModels); + } + + @Override + public ValidationTarget getType(){ + return ValidationTarget.Section; + } + + @Override + public Collection<Validation> validate(Config config) { + Iterable<String> propertyNames = config.getPropertyNames(); + String lookupKey = getName() + '.'; + boolean present = false; + for(String key:propertyNames){ + if(key.startsWith("_")){ + continue; + } + if(key.startsWith(lookupKey)){ + present = true; + break; + } + } + List<Validation> result = new ArrayList<>(1); + if(isRequired() && !present) { + result.add(Validation.checkMissing(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(ValidationModel 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<ValidationModel> 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(ValidationModel... 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<ValidationModel> 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 ValidationModel build(){ + return new ValidateSection(this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/java/org/apache/tamaya/validation/spi/ValidationModelProviderSpi.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ValidationModelProviderSpi.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ValidationModelProviderSpi.java new file mode 100644 index 0000000..9e40d22 --- /dev/null +++ b/validation/src/main/java/org/apache/tamaya/validation/spi/ValidationModelProviderSpi.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.validation.spi; + +import org.apache.tamaya.validation.ValidationModel; + +import java.util.Collection; + +/** + * Model of a configuration state. A model can be a full model, or a partial model, validating only + * a configuration subset. This allows better user feedback because big configurations can be grouped + * and validated by multiple (partial) models. + */ +public interface ValidationModelProviderSpi { + + /** + * Get the validation defined. + * + * @return the sections defined, never null. + */ + Collection<ValidationModel> getConfigModels(); + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/resources/META-INF/configmodel.properties ---------------------------------------------------------------------- diff --git a/validation/src/main/resources/META-INF/configmodel.properties b/validation/src/main/resources/META-INF/configmodel.properties deleted file mode 100644 index 3381a09..0000000 --- a/validation/src/main/resources/META-INF/configmodel.properties +++ /dev/null @@ -1,35 +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 current the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -# Contains definitions for default system property areas. -_awt.model.target=Section -_awt.model.transitive=true -_file.model.target=Section -_file.model.transitive=true -_java.model.target=Section -_java.model.transitive=true -_line.model.target=Section -_line.model.transitive=true -_os.model.target=Section -_os.model.transitive=true -_path.model.target=Section -_path.model.transitive=true -_sun.model.target=Section -_sun.model.transitive=true -_user.model.target=Section -_user.model.transitive=true http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/resources/META-INF/configvalidation.properties ---------------------------------------------------------------------- diff --git a/validation/src/main/resources/META-INF/configvalidation.properties b/validation/src/main/resources/META-INF/configvalidation.properties new file mode 100644 index 0000000..3381a09 --- /dev/null +++ b/validation/src/main/resources/META-INF/configvalidation.properties @@ -0,0 +1,35 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# Contains definitions for default system property areas. +_awt.model.target=Section +_awt.model.transitive=true +_file.model.target=Section +_file.model.transitive=true +_java.model.target=Section +_java.model.transitive=true +_line.model.target=Section +_line.model.transitive=true +_os.model.target=Section +_os.model.transitive=true +_path.model.target=Section +_path.model.transitive=true +_sun.model.target=Section +_sun.model.transitive=true +_user.model.target=Section +_user.model.transitive=true http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener ---------------------------------------------------------------------- diff --git a/validation/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener b/validation/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener index e8b12e9..8523d8c 100644 --- a/validation/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener +++ b/validation/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener @@ -16,4 +16,4 @@ # specific language governing permissions and limitations # under the License. # -org.apache.tamaya.model.internal.ConfiguredTypeEventsModelPopulator \ No newline at end of file +org.apache.tamaya.validation.internal.ConfiguredTypeEventsModelPopulator \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigDocumentationMBean ---------------------------------------------------------------------- diff --git a/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigDocumentationMBean b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigDocumentationMBean deleted file mode 100644 index f41ad43..0000000 --- a/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigDocumentationMBean +++ /dev/null @@ -1,38 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy current the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -org.apache.tamaya.validation.internal.ConfigDocumentationBean \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigValidationMBean ---------------------------------------------------------------------- diff --git a/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigValidationMBean b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigValidationMBean new file mode 100644 index 0000000..d5549f3 --- /dev/null +++ b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigValidationMBean @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +org.apache.tamaya.validation.internal.ConfigValidationBean \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ModelProviderSpi ---------------------------------------------------------------------- diff --git a/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ModelProviderSpi b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ModelProviderSpi deleted file mode 100644 index 3866a74..0000000 --- a/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ModelProviderSpi +++ /dev/null @@ -1,41 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy current the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -org.apache.tamaya.validation.internal.ConfiguredPropertiesModelProviderSpi -org.apache.tamaya.validation.internal.ConfiguredInlineModelProviderSpi -org.apache.tamaya.validation.internal.ConfiguredResourcesModelProviderSpi -org.apache.tamaya.validation.internal.ConfiguredTypeEventsModelProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ValidationModelProviderSpi ---------------------------------------------------------------------- diff --git a/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ValidationModelProviderSpi b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ValidationModelProviderSpi new file mode 100644 index 0000000..2788871 --- /dev/null +++ b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ValidationModelProviderSpi @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +org.apache.tamaya.validation.internal.ConfiguredPropertiesModelProviderSpi +org.apache.tamaya.validation.internal.ConfiguredInlineModelProviderSpi +org.apache.tamaya.validation.internal.ConfiguredResourcesModelProviderSpi +org.apache.tamaya.validation.internal.ConfiguredTypeEventsModelProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java ---------------------------------------------------------------------- diff --git a/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java b/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java index dda2b67..ea5c375 100644 --- a/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java +++ b/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java @@ -18,10 +18,10 @@ */ 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 org.apache.tamaya.validation.spi.ValidateSection; +import org.apache.tamaya.validation.spi.ValidateParameter; +import org.apache.tamaya.validation.spi.ValidateGroup; +import org.apache.tamaya.validation.spi.ValidationModelProviderSpi; import java.util.ArrayList; import java.util.Collection; @@ -32,31 +32,31 @@ import java.util.List; /** * Created by Anatole on 09.08.2015. */ -public class ConfigModelProviderTest implements ModelProviderSpi { +public class ConfigModelProviderTest implements ValidationModelProviderSpi { - private List<ConfigModel> configModels = new ArrayList<>(1); + private List<ValidationModel> configModels = new ArrayList<>(1); public ConfigModelProviderTest(){ configModels.add(new TestConfigModel()); configModels = Collections.unmodifiableList(configModels); } - public Collection<ConfigModel> getConfigModels() { + public Collection<ValidationModel> getConfigModels() { return configModels; } - private static final class TestConfigModel extends GroupModel { + private static final class TestConfigModel extends ValidateGroup { public TestConfigModel(){ - super("TestConfigModel", "TestConfig", new SectionModel.Builder("TestConfigModel", + super("TestConfigModel", "TestConfig", new ValidateSection.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].*")); + ValidateParameter.of("TestConfigModel", "a.test.existing.aParam", true), + ValidateParameter.of("TestConfigModel", "a.test.existing.optionalParam"), + ValidateParameter.of("TestConfigModel", "a.test.existing.aABCParam", false, "[ABC].*"), + new ValidateSection.Builder("TestConfigModel", "a.test.notexisting").setRequired(true).build(), + ValidateParameter.of("TestConfigModel", "a.test.notexisting.aParam", true), + ValidateParameter.of("TestConfigModel", "a.test.notexisting.optionalParam"), + ValidateParameter.of("TestConfigModel", "a.test.existing.aABCParam2", false, "[ABC].*")); } @Override public String getName() { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java ---------------------------------------------------------------------- diff --git a/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java b/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java index 29c3801..5507584 100644 --- a/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java +++ b/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java @@ -20,6 +20,8 @@ package org.apache.tamaya.validation; import org.junit.Test; +import javax.config.ConfigProvider; + /** * Created by Anatole on 10.08.2015. */ @@ -27,26 +29,27 @@ public class ValidationTests { @Test public void testDefaults(){ - System.err.println(ConfigModelManager.validate()); + System.err.println(ValidationManager.getInstance().validate(ConfigProvider.getConfig())); } @Test public void testAllValidations(){ - System.err.println(ConfigModelManager.getModels()); + System.err.println(ValidationManager.getInstance().getModels()); } @Test public void testConfigInfo(){ - System.err.println(ConfigModelManager.getConfigInfoText()); + System.err.println(ValidationManager.getInstance().getConfigInfoText()); } @Test public void testAllValidationsInclUndefined(){ - System.err.println("Including UNDEFINED: \n" + ConfigModelManager.validate(true)); + System.err.println("Including UNDEFINED: \n" + ValidationManager.getInstance().validate( + ConfigProvider.getConfig(), true)); } @Test public void testModels(){ - System.err.println("MODELS: " +ConfigModelManager.getModels()); + System.err.println("MODELS: " + ValidationManager.getInstance().getModels()); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java ---------------------------------------------------------------------- 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 index 39bf657..ba19c7e 100644 --- a/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java +++ b/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java @@ -18,7 +18,7 @@ */ package org.apache.tamaya.validation.internal; -import org.apache.tamaya.validation.ModelTarget; +import org.apache.tamaya.validation.ValidationTarget; import org.junit.Test; import static org.junit.Assert.assertFalse; @@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue; */ public class ConfigDocumentationBeanTest { - private final ConfigDocumentationBean mbean = new ConfigDocumentationBean(); + private final ConfigValidationBean mbean = new ConfigValidationBean(); @Test public void testValidate_NoUnknowns() throws Exception { @@ -73,7 +73,7 @@ public class ConfigDocumentationBeanTest { @Test public void testGetConfigurationModel_WithSection() throws Exception { - String results = mbean.getConfigurationModel(ModelTarget.Parameter); + String results = mbean.getConfigurationModel(ValidationTarget.Parameter); assertNotNull(results); assertFalse(results.trim().isEmpty()); assertTrue(results.contains("\"target\":\"Parameter\"")); @@ -92,7 +92,7 @@ public class ConfigDocumentationBeanTest { @Test public void testFindValidationModels() throws Exception { - String results = mbean.findValidationModels("a", ModelTarget.Section); + String results = mbean.findValidationModels("a", ValidationTarget.Section); assertNotNull(results); assertFalse(results.trim().isEmpty()); assertFalse(results.contains("\"target\":\"Parameter\"")); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54b627b9/validation/src/test/java/test/model/TestConfigAccessor.java ---------------------------------------------------------------------- diff --git a/validation/src/test/java/test/model/TestConfigAccessor.java b/validation/src/test/java/test/model/TestConfigAccessor.java index 498d2b6..e3ed825 100644 --- a/validation/src/test/java/test/model/TestConfigAccessor.java +++ b/validation/src/test/java/test/model/TestConfigAccessor.java @@ -18,9 +18,10 @@ */ package test.model; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.functions.ConfigurationFunctions; +import javax.config.Config; +import javax.config.ConfigProvider; import java.util.Map; /** @@ -31,15 +32,14 @@ public final class TestConfigAccessor { private TestConfigAccessor(){} public static Map<String,String> readAllProperties(){ - return ConfigurationProvider.getConfiguration() - .getProperties(); + return ConfigurationFunctions.toMap(ConfigProvider.getConfig()); } - public static Configuration readConfiguration(){ - return ConfigurationProvider.getConfiguration(); + public static Config readConfiguration(){ + return ConfigProvider.getConfig(); } - public static String readProperty(Configuration config, String key){ - return config.get(key); + public static String readProperty(Config config, String key){ + return config.getOptionalValue(key, String.class).orElse(null); } }
