You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/08/17 10:10:18 UTC
[2/3] incubator-tamaya git commit: Unified model metadata. Simplified
implementation.
Unified model metadata.
Simplified implementation.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/0a8226a8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/0a8226a8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/0a8226a8
Branch: refs/heads/master
Commit: 0a8226a82333fb35c1a6f4c34c28fdbb4eaa992b
Parents: defad3c
Author: anatole <an...@apache.org>
Authored: Mon Aug 17 09:04:34 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Aug 17 10:09:58 2015 +0200
----------------------------------------------------------------------
sandbox/model/pom.xml | 14 ++
.../ConfiguredInlineModelProviderSpi.java | 68 +++++++
...nfiguredPropertiesValidationProviderSpi.java | 129 +++++++++++++
.../ConfiguredResourcesModelProviderSpi.java | 125 ++++++++++++
.../ConfiguredValidationProviderSpi.java | 188 -------------------
.../model/spi/ConfigValidationsReader.java | 169 +++++++++++++++++
...pache.tamaya.model.spi.ValidationProviderSpi | 4 +-
.../resources/META-INF/configmodel.properties | 96 ++++++++++
.../META-INF/configmodel/configmodel.properties | 96 ----------
.../src/test/resources/examples/configmodel.ini | 37 +---
.../test/resources/examples/configmodel.json | 147 +++++++--------
.../resources/examples/configmodel.properties | 81 ++++----
.../src/test/resources/examples/configmodel.xml | 130 +++++++------
.../test/resources/examples/configmodel.yaml | 74 +++++---
14 files changed, 834 insertions(+), 524 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/model/pom.xml b/sandbox/model/pom.xml
index 29484d9..92acf9b 100644
--- a/sandbox/model/pom.xml
+++ b/sandbox/model/pom.xml
@@ -48,6 +48,20 @@ under the License.
<scope>Test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-formats</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-json</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
new file mode 100644
index 0000000..614346f
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.model.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.model.Validation;
+import org.apache.tamaya.model.spi.ConfigValidationsReader;
+import org.apache.tamaya.model.spi.ValidationProviderSpi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+/**
+ * Validation provider that reads model metadata from the current {@link org.apache.tamaya.Configuration}.
+ */
+public class ConfiguredInlineModelProviderSpi implements ValidationProviderSpi {
+
+ /** 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 validations read. */
+ private List<Validation> validations = new ArrayList<>();
+
+
+ /**
+ * Constructor, typically called by the {@link java.util.ServiceLoader}.
+ */
+ public ConfiguredInlineModelProviderSpi() {
+ String enabledVal = ConfigurationProvider.getConfiguration().get(MODEL_EANABLED_PARAM);
+ boolean disabled = enabledVal==null? true: "false".equalsIgnoreCase(enabledVal);
+ if (!disabled) {
+ LOG.info("Reading model configuration from config...");
+ Map<String,String> config = ConfigurationProvider.getConfiguration().getProperties();
+ validations.addAll(ConfigValidationsReader.loadValidations(config,
+ "<Inline Configuration Model>"));
+ }
+ validations = Collections.unmodifiableList(validations);
+ }
+
+
+ @Override
+ public Collection<Validation> getValidations() {
+ return validations;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesValidationProviderSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesValidationProviderSpi.java b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesValidationProviderSpi.java
new file mode 100644
index 0000000..4bbfbd1
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredPropertiesValidationProviderSpi.java
@@ -0,0 +1,129 @@
+package org.apache.tamaya.model.internal;
+
+import org.apache.tamaya.model.Validation;
+import org.apache.tamaya.model.spi.AreaValidation;
+import org.apache.tamaya.model.spi.ConfigValidationsReader;
+import org.apache.tamaya.model.spi.ParameterValidation;
+import org.apache.tamaya.model.spi.ValidationProviderSpi;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Validation provider that reads model metadata from property files from
+ * {@code classpath*:META-INF/configmodel.properties} in the following format:
+ * <pre>
+ * ###################################################################################
+ * # Example of a configuration metamodel expressed via properties.
+ * ####################################################################################
+ *
+ * # Metamodel information
+ * [model].provider=ConfigModel Extension
+ *
+ * ####################################################################################
+ * # Description of 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.validations=org.apache.tamaya.model.TestValidator
+ * </pre>
+ */
+public class ConfiguredPropertiesValidationProviderSpi implements ValidationProviderSpi {
+
+ /** The logger. */
+ private static final Logger LOG = Logger.getLogger(ConfiguredPropertiesValidationProviderSpi.class.getName());
+ /** The validations read. */
+ private List<Validation> validations = new ArrayList<>();
+
+ public ConfiguredPropertiesValidationProviderSpi() {
+ try {
+ 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);
+ validations.addAll(ConfigValidationsReader.loadValidations(props, config.toString()));
+ } 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);
+ }
+ validations = Collections.unmodifiableList(validations);
+ }
+
+
+ @Override
+ public Collection<Validation> getValidations() {
+ return validations;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
new file mode 100644
index 0000000..1eb7cc5
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
@@ -0,0 +1,125 @@
+package org.apache.tamaya.model.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.model.Validation;
+import org.apache.tamaya.model.spi.AreaValidation;
+import org.apache.tamaya.model.spi.ConfigValidationsReader;
+import org.apache.tamaya.model.spi.ParameterValidation;
+import org.apache.tamaya.model.spi.ValidationProviderSpi;
+import org.apache.tamaya.resource.ConfigResources;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Validation provider that reads model metadata from property files from
+ * {@code classpath*:META-INF/configmodel.json} in the following format:
+ * <pre>
+ * </pre>
+ */
+public class ConfiguredResourcesModelProviderSpi implements ValidationProviderSpi {
+
+ /** The logger. */
+ private static final Logger LOG = Logger.getLogger(ConfiguredResourcesModelProviderSpi.class.getName());
+ /** The parameter that can be used to configure the location of 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 of 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 of 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 boolean available = checkAvailabilityFormats();
+ /** Initializes the flag showing if the resources module is present (optional). */
+ private static boolean resourcesExtensionAvailable = checkAvailabilityResources();
+
+ /** The validations read. */
+ private List<Validation> validations = new ArrayList<>();
+
+ /** Initializes the flag showing if the formats module is present (required). */
+ private static boolean checkAvailabilityFormats() {
+ try {
+ Class.forName(CONFIGURATION_FORMATS_CLASS);
+ return true;
+ } catch (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 (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 {
+ String resources = ConfigurationProvider.getConfiguration().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 = new ArrayList<>();
+ if(resourcesExtensionAvailable){
+ LOG.info("Using tamaya-resources extension to read model configuration from " + resources);
+ urls = ConfigResources.getResourceResolver().getResources(resources.split(","));
+ }
+ else{
+ LOG.info("Using default classloader resource location to read model configuration from " + resources);
+ urls = new ArrayList<>();
+ for(String resource:resources.split(",")){
+ if(!resource.trim().isEmpty()){
+ Enumeration<URL> configs = null;
+ try {
+ configs = getClass().getClassLoader().getResources(resource);
+ while (configs.hasMoreElements()) {
+ urls.add(configs.nextElement());
+ }
+ } catch (IOException e) {
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE,
+ "Error evaluating config model locations from "+resource, e);
+ }
+ }
+ }
+ }
+ // Reading configs
+ for(URL config:urls){
+ try (InputStream is = config.openStream()) {
+ ConfigurationData data = ConfigurationFormats.readConfigurationData(config);
+ validations.addAll(ConfigValidationsReader.loadValidations(data.getCombinedProperties(), config.toString()));
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE,
+ "Error loading config model data from " + config, e);
+ }
+ }
+ }
+ validations = Collections.unmodifiableList(validations);
+ }
+
+
+ @Override
+ public Collection<Validation> getValidations() {
+ return validations;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredValidationProviderSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredValidationProviderSpi.java b/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredValidationProviderSpi.java
deleted file mode 100644
index a3f77b8..0000000
--- a/sandbox/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredValidationProviderSpi.java
+++ /dev/null
@@ -1,188 +0,0 @@
-package org.apache.tamaya.model.internal;
-
-import org.apache.tamaya.model.Validation;
-import org.apache.tamaya.model.spi.AreaValidation;
-import org.apache.tamaya.model.spi.ParameterValidation;
-import org.apache.tamaya.model.spi.ValidationProviderSpi;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Validation provider that reads model metadata from property files with the following format:
- * <pre>
- * ###################################################################################
- * # Example of a configuration metamodel expressed via properties.
- * ####################################################################################
- *
- * # Metamodel information
- * [model].provider=ConfigModel Extension
- *
- * # reusable parameter definition, referenceable as MyNumber
- * [MyNumber].class=Parameter
- * [MyNumber].type=Integer
- * [MyNumber].description=a (reusable) number type parameter (optional)
- *
- * ####################################################################################
- * # Description of Configuration Sections (minimal, can be extended by other modules).
- * # By default its interpreted as a section !
- * ####################################################################################
- *
- * # a (section)
- * a.class=Section
- * a.params2.class=Parameter
- * a.params2.type=String
- * a.params2.required=true
- * a.params2.description=a required parameter
- *
- * a.paramInt.class=Parameter
- * a.paramInt.ref=MyNumber
- * a.paramInt.description=an optional parameter (default)
- *
- * a._number.class=Parameter
- * a._number.type=Integer
- * a._number.deprecated=true
- * a._number.mappedTo=a.paramInt
- *
- * # a.b.c (section)
- * a.b.c.class=Section
- * a.b.c.description=Just a test section
- *
- * # a.b.c.aRequiredSection (section)
- * a.b.c.aRequiredSection.class=Section
- * a.b.c.aRequiredSection.required=true
- * a.b.c.aRequiredSection.description=A section containing required parameters is called a required section.\
- * Sections can also explicitly be defined to be required, but without\
- * specifying the paramteres to be contained.,
- *
- * # a.b.c.aRequiredSection.subsection (section)
- * a.b.c.aRequiredSection.subsection.class=Section
- *
- * a.b.c.aRequiredSection.subsection.param0.class=Parameter
- * a.b.c.aRequiredSection.subsection.param0.type=String
- * a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
- * # A minmal String parameter
- * a.b.c.aRequiredSection.subsection.param00.class=Parameter
- * a.b.c.aRequiredSection.subsection.param00.type=String
- *
- * # a.b.c.aRequiredSection.subsection (section)
- * a.b.c.aRequiredSection.subsection.param1.class=Parameter
- * a.b.c.aRequiredSection.subsection.param1.type = String
- * a.b.c.aRequiredSection.subsection.param1.required = true
- * a.b.c.aRequiredSection.subsection.intParam.class=Parameter
- * a.b.c.aRequiredSection.subsection.intParam.type = Integer
- * a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
- *
- * # a.b.c.aRequiredSection.nonempty-subsection (section)
- * a.b.c.aRequiredSection.nonempty-subsection.class=Section
- * a.b.c.aRequiredSection.nonempty-subsection.required=true
- *
- * # a.b.c.aRequiredSection.optional-subsection (section)
- * a.b.c.aRequiredSection.optional-subsection.class=Section
- *
- * # a.b.c.aValidatedSection (section)
- * a.b.c.aValidatedSection.class=Section
- * a.b.c.aValidatedSection.description=A validated section.
- * a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator
- * </pre>
- */
-public class ConfiguredValidationProviderSpi implements ValidationProviderSpi {
-
- private List<Validation> validations = new ArrayList<>();
-
- public ConfiguredValidationProviderSpi() {
- try {
- Enumeration<URL> configs = getClass().getClassLoader().getResources("META-INF/configmodel/configmodel.properties");
- while (configs.hasMoreElements()) {
- URL config = configs.nextElement();
- try (InputStream is = config.openStream()) {
- Properties props = new Properties();
- props.load(is);
- loadValidations(props, config.toString());
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.SEVERE,
- "Error loading config metadata from " + config, e);
- }
- }
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.SEVERE,
- "Error loading config metadata from META-INF/configmodel/configmodel.properties", e);
- }
- validations = Collections.unmodifiableList(validations);
- }
-
- private void loadValidations(Properties props, String resource) {
- String provider = props.getProperty("[model].provider");
- if (provider == null) {
- provider = resource;
- }
- Set<String> itemKeys = new HashSet<>();
- for (Object key : props.keySet()) {
- if (key.toString().endsWith(".class")) {
- itemKeys.add(key.toString().substring(0, key.toString().length() - ".class".length()));
- }
- }
- for (String baseKey : itemKeys) {
- String clazz = props.getProperty(baseKey + ".class");
- String type = props.getProperty(baseKey + ".type");
- if(type==null){
- type = String.class.getName();
- }
- String description = props.getProperty(baseKey + ".description");
- String regEx = props.getProperty(baseKey + ".expression");
- String validations = props.getProperty(baseKey + ".validations");
- String requiredVal = props.getProperty(baseKey + ".required");
- if ("Parameter".equalsIgnoreCase(clazz)) {
- initParameter(baseKey, description, type, requiredVal, regEx, validations);
- } else if ("Section".equalsIgnoreCase(clazz)) {
- initSection(baseKey, description, requiredVal, validations);
- }
- }
- }
-
- private void initParameter(String name, String desc, String type, String reqVal, String regEx, String validations) {
- boolean required = "true".equalsIgnoreCase(reqVal);
- ParameterValidation.Builder builder = ParameterValidation.builder(name).setRequired(required)
- .setDescription(desc).setExpression(regEx).setType(type);
- if (validations != null) {
- try {
- // TODO defined validator API
-// builder.addValidations(validations);
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to load validations for " + name, e);
- }
- }
- this.validations.add(builder.build());
- }
-
- private void initSection(String name, String desc, String reqVal, String validations) {
- boolean required = "true".equalsIgnoreCase(reqVal);
- AreaValidation.Builder builder = AreaValidation.builder(name).setRequired(required)
- .setDescription(desc);
- if (validations != null) {
- try {
- // TODO defined validator API
-// builder.addValidations(validations);
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to load validations for " + name, e);
- }
- }
- this.validations.add(builder.build());
- }
-
-
- @Override
- public Collection<Validation> getValidations() {
- return validations;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ConfigValidationsReader.java
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ConfigValidationsReader.java b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ConfigValidationsReader.java
new file mode 100644
index 0000000..eaf9aec
--- /dev/null
+++ b/sandbox/model/src/main/java/org/apache/tamaya/model/spi/ConfigValidationsReader.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.model.spi;
+
+import org.apache.tamaya.model.Validation;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * 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 ConfigValidationsReader {
+
+ /** The logger used. */
+ private static final Logger LOGGER = Logger.getLogger(ConfigValidationsReader.class.getName());
+
+ /** The default model entries selector. */
+ private static final String DEFAULT_META_INFO_SELECTOR = "{model}";
+ /** parameter to change the selector to be used for filtering out the target values to be used. */
+ private static final String META_INFO_SELECTOR_PARAM = "org.apache.tamaya.model.integrated.selector";
+
+ /**
+ * Loads validations as configured in the given properties.
+ * @param props the properties to be read
+ * @param defaultProviderName the default provider name used if no explicit provider name is configured.
+ * @return a collection of config validations.
+ */
+ public static Collection<Validation> loadValidations(Properties props,
+ String defaultProviderName) {
+ Map<String,String> map = new HashMap<>();
+ for(Map.Entry<Object,Object> en: props.entrySet()){
+ map.put(en.getKey().toString(), props.getProperty(en.getKey().toString()));
+ }
+ return loadValidations(map, defaultProviderName);
+ }
+
+ /**
+ * Loads validations as configured in the given properties.
+ * @param props the properties to be read
+ * @param defaultProviderName the default provider name used if no explicit provider name is configured.
+ * @return a collection of config validations.
+ */
+ public static Collection<Validation> loadValidations(Map<String,String> props,
+ String defaultProviderName) {
+ String selector = props.get(META_INFO_SELECTOR_PARAM);
+ if(selector==null){
+ selector = DEFAULT_META_INFO_SELECTOR;
+ }
+ return loadValidations(props, selector, defaultProviderName);
+ }
+
+ /**
+ * Loads validations as configured in the given properties.
+ * @param props the properties to be read
+ * @param selector the selector (default is {model}), that identifies the model entries.
+ * @param defaultProviderName the default provider name used if no explicit provider name is configured.
+ * @return a collection of config validations.
+ */
+ public static Collection<Validation> loadValidations(Map<String,String> props, String selector,
+ String defaultProviderName) {
+ List<Validation> result = new ArrayList<>();
+ String provider = props.get(selector + ".__provider");
+ if (provider == null) {
+ provider = defaultProviderName;
+ }
+ Set<String> itemKeys = new HashSet<>();
+ for (Object key : props.keySet()) {
+ if (key.toString().endsWith(".class")) {
+ itemKeys.add(key.toString().substring(0, key.toString().length() - ".class".length()));
+ }
+ }
+ for (String baseKey : itemKeys) {
+ String clazz = props.get(baseKey + ".class");
+ String type = props.get(baseKey + ".type");
+ if (type == null) {
+ type = String.class.getName();
+ }
+ String description = props.get(baseKey + ".description");
+ String regEx = props.get(baseKey + ".expression");
+ String validations = props.get(baseKey + ".validations");
+ String requiredVal = props.get(baseKey + ".required");
+ if ("Parameter".equalsIgnoreCase(clazz)) {
+ result.add(createParameterValidation(baseKey.substring(selector.length() + 1), description, type,
+ requiredVal, regEx, validations));
+ } else if ("Section".equalsIgnoreCase(clazz)) {
+ result.add(createSectionValidation(baseKey.substring(selector.length() + 1), 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 Validation createParameterValidation(String paramName, String description, String type, String reqVal,
+ String regEx, String validations) {
+ boolean required = "true".equalsIgnoreCase(reqVal);
+ ParameterValidation.Builder builder = ParameterValidation.builder(paramName).setRequired(required)
+ .setDescription(description).setExpression(regEx).setType(type);
+ if (validations != null) {
+ try {
+ // TODO defined validator API
+// builder.addValidations(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 Validation createSectionValidation(String sectionName, String description, String reqVal,
+ String validations) {
+ boolean required = "true".equalsIgnoreCase(reqVal);
+ AreaValidation.Builder builder = AreaValidation.builder(sectionName).setRequired(required)
+ .setDescription(description);
+ if (validations != null) {
+ try {
+ // TODO defined validator API
+// builder.addValidations(validations);
+ } 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/blob/0a8226a8/sandbox/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
----------------------------------------------------------------------
diff --git a/sandbox/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi b/sandbox/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
index e2ba992..47c18de 100644
--- a/sandbox/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
+++ b/sandbox/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ValidationProviderSpi
@@ -16,4 +16,6 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.model.internal.ConfiguredValidationProviderSpi
+org.apache.tamaya.model.internal.ConfiguredPropertiesValidationProviderSpi
+org.apache.tamaya.model.internal.ConfiguredInlineModelProviderSpi
+org.apache.tamaya.model.internal.ConfiguredResourcesModelProviderSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/test/resources/META-INF/configmodel.properties
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/META-INF/configmodel.properties b/sandbox/model/src/test/resources/META-INF/configmodel.properties
new file mode 100644
index 0000000..af37705
--- /dev/null
+++ b/sandbox/model/src/test/resources/META-INF/configmodel.properties
@@ -0,0 +1,96 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+###################################################################################
+# Example of a configuration metamodel expressed via properties.
+####################################################################################
+
+# Metamodel information
+{model}.provider=ConfigModel Extension
+
+# reusable parameter definition, referenceable as MyNumber
+{model}.MyNumber.class=Parameter
+{model}.MyNumber.type=Integer
+{model}.MyNumber.description=a (reusable) number type parameter (optional)
+
+####################################################################################
+# Description of Configuration Sections (minimal, can be extended by other modules).
+# By default its interpreted as a section !
+####################################################################################
+
+# a (section)
+{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.type=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.validations=org.apache.tamaya.model.TestValidator
+
+
+
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/test/resources/META-INF/configmodel/configmodel.properties
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/META-INF/configmodel/configmodel.properties b/sandbox/model/src/test/resources/META-INF/configmodel/configmodel.properties
deleted file mode 100644
index 472abc3..0000000
--- a/sandbox/model/src/test/resources/META-INF/configmodel/configmodel.properties
+++ /dev/null
@@ -1,96 +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.
-#
-
-###################################################################################
-# Example of a configuration metamodel expressed via properties.
-####################################################################################
-
-# Metamodel information
-[model].provider=ConfigModel Extension
-
-# reusable parameter definition, referenceable as MyNumber
-[MyNumber].class=Parameter
-[MyNumber].type=Integer
-[MyNumber].description=a (reusable) number type parameter (optional)
-
-####################################################################################
-# Description of Configuration Sections (minimal, can be extended by other modules).
-# By default its interpreted as a section !
-####################################################################################
-
-# a (section)
-a.class=Section
-a.params2.class=Parameter
-a.params2.type=String
-a.params2.required=true
-a.params2.description=a required parameter
-
-a.paramInt.class=Parameter
-a.paramInt.ref=MyNumber
-a.paramInt.description=an optional parameter (default)
-
-a._number.class=Parameter
-a._number.type=Integer
-a._number.deprecated=true
-a._number.mappedTo=a.paramInt
-
-# a.b.c (section)
-a.b.c.class=Section
-a.b.c.description=Just a test section
-
-# a.b.c.aRequiredSection (section)
-a.b.c.aRequiredSection.class=Section
-a.b.c.aRequiredSection.required=true
-a.b.c.aRequiredSection.description=A section containing required parameters is called a required section.\
- Sections can also explicitly be defined to be required, but without\
- specifying the paramteres to be contained.,
-
-# a.b.c.aRequiredSection.subsection (section)
-a.b.c.aRequiredSection.subsection.class=Section
-
-a.b.c.aRequiredSection.subsection.param0.class=Parameter
-a.b.c.aRequiredSection.subsection.param0.type=String
-a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
-# A minmal String parameter
-a.b.c.aRequiredSection.subsection.param00.class=Parameter
-a.b.c.aRequiredSection.subsection.param00.type=String
-
-# a.b.c.aRequiredSection.subsection (section)
-a.b.c.aRequiredSection.subsection.param1.class=Parameter
-a.b.c.aRequiredSection.subsection.param1.type = String
-a.b.c.aRequiredSection.subsection.param1.required = true
-a.b.c.aRequiredSection.subsection.intParam.class=Parameter
-a.b.c.aRequiredSection.subsection.intParam.type = Integer
-a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
-
-# a.b.c.aRequiredSection.nonempty-subsection (section)
-a.b.c.aRequiredSection.nonempty-subsection.class=Section
-a.b.c.aRequiredSection.nonempty-subsection.required=true
-
-# a.b.c.aRequiredSection.optional-subsection (section)
-a.b.c.aRequiredSection.optional-subsection.class=Section
-
-# a.b.c.aValidatedSection (section)
-a.b.c.aValidatedSection.class=Section
-a.b.c.aValidatedSection.description=A validated section.
-a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator
-
-
-
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/test/resources/examples/configmodel.ini
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/examples/configmodel.ini b/sandbox/model/src/test/resources/examples/configmodel.ini
index e5f3c70..ec4070c 100644
--- a/sandbox/model/src/test/resources/examples/configmodel.ini
+++ b/sandbox/model/src/test/resources/examples/configmodel.ini
@@ -22,33 +22,10 @@
####################################################################################
####################################################################################
-# Metamodel information
-####################################################################################
-[model]
-class = Meta-model
-name = testmodel,
-provider = ConfigModel Extension,
-version = 1.0,
-release-date = 2001-01-23,
-author = Anatole Tresch,
-# model-format = alternate format reader type
-comments : = Late afternoon is best.\
- Backup contact is Nancy.
-
-####################################################################################
-# Reusable parameter definitions.
-####################################################################################
-// reusable parameter definition
-[MyNumber]
-class = "Parameter"
-type = Integer",
-description = a (reusable) number type parameter (optional)
-
-####################################################################################
# Description of Configuration Sections (minimal, can be extended by other modules).
# By default its interpreted as a section !
####################################################################################
-[a]
+[{model}a]
class = Section
params2.type = String
params2.required = true
@@ -59,18 +36,18 @@ _number.type = Integer
_number.deprecated = true
_number.mappedTo = "a.paramInt"
-[a.b.c]
+[{model}a.b.c]
class = Section
description = Just a test section
-[a.b.c.aRequiredSection]
+[{model}a.b.c.aRequiredSection]
class = Section
required = true
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]
+[{model}a.b.c.aRequiredSection.subsection]
class = Section
param0.type = String
param0.description = "a minmally documented String parameter"
@@ -82,14 +59,14 @@ param1.required = true
intParam.type = Integer
intParam.description = "an optional parameter (default)"
-[a.b.c.aRequiredSection.nonempty-subsection]
+[{model}a.b.c.aRequiredSection.nonempty-subsection]
class = Section
required = true
-[a.b.c.aRequiredSection.optional-subsection]
+[{model}a.b.c.aRequiredSection.optional-subsection]
class = Section
-[a.b.c.aValidatedSection]
+[{model}a.b.c.aValidatedSection]
class = Section
description = "A validation section."
validations = org.apache.tamaya.model.TestValidator?max=3
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/test/resources/examples/configmodel.json
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/examples/configmodel.json b/sandbox/model/src/test/resources/examples/configmodel.json
index 6c111ae..1fd831e 100644
--- a/sandbox/model/src/test/resources/examples/configmodel.json
+++ b/sandbox/model/src/test/resources/examples/configmodel.json
@@ -28,87 +28,86 @@
// Metamodel information
//##################################################################################
{
- "model": {
- "class": "Metamodel",
- "name": "testmodel",
- "provider": "ConfigModel Extension",
- "version": "1.0",
- "release-date": "2001-01-23",
- "author": "Anatole Tresch",
+ "{model}": {
+ "__name": "testmodel",
+ "__provider": "ConfigModel Extension",
+ "__version": "1.0",
+ "__release-date": "2001-01-23",
+ "__author": "Anatole Tresch",
// "modelformat": "alternate format reader type"
- "comments": "Late afternoon is best. Backup contact is Nancy."
- },
- // reusable parameter definition
- "MyNumber": {
- "class": "Parameter",
- "type": "Integer",
- "description": "an (reusable) number type parameter (optional)"
- },
- //##################################################################################
- // Description of Configuration Sections (minimal, can be extended by other modules).
- //##################################################################################
- "a": {
- "class": "Section",
- // required, default is parameter!
- "params2": {
- "required": true,
- "description": "a required parameter"
+ "__comments": "Late afternoon is best. Backup contact is Nancy.",
+ // reusable parameter definition
+ "MyNumber": {
+ "class": "Parameter",
+ "type": "Integer",
+ "template": true,
+ "description": "an (reusable) number type parameter (optional)"
},
- "paramInt": {
- // references a shared parameter definition.
- "ref": "MyNumber",
- "description": "an optional parameter (default)"
+ //##################################################################################
+ // Description of Configuration Sections (minimal, can be extended by other modules).
+ //##################################################################################
+ "a": {
+ "class": "Section",
+ // required, default is parameter!
+ "params2": {
+ "required": true,
+ "description": "a required parameter"
+ },
+ "paramInt": {
+ // references a shared parameter definition.
+ "ref": "MyNumber",
+ "description": "an optional parameter (default)"
+ },
+ "_number": {
+ "type": "Integer",
+ "deprecated": true,
+ // references a deprecated parameter, now mapped to 'a.paramInt'.
+ "mappedto": "a.paramInt"
+ }
},
- "_number": {
- "type": "Integer",
- "deprecated": true,
- // references a deprecated parameter, now mapped to 'a.paramInt'.
- "mappedto": "a.paramInt"
- }
- },
- "a.b.c": {
- "class": "Section",
- "description": "Just a test section."
- // a subsection, directly configured as child element.
- "aRequiredSection": {
+ "a.b.c": {
"class": "Section",
- "required": true,
- "description": "A section containing required parameters is called a required section."
- }
- },
- // a subsection, configured in its own section.
- "a.b.c.aRequiredSection.subsection": {
- "class": "Section",
- "param0": {
- "type": "String",
- "description": "a minmally documented String parameter"
+ "description": "Just a test section."
+ // a subsection, directly configured as child element.
+ "aRequiredSection": {
+ "class": "Section",
+ "required": true,
+ "description": "A section containing required parameters is called a required section."
+ }
+ },
+ // a subsection, configured in its own section.
+ "a.b.c.aRequiredSection.subsection": {
+ "class": "Section",
+ "param0": {
+ "type": "String",
+ "description": "a minmally documented String parameter"
+ },
+ // A minmally defined String parameter
+ "param00": {},
+ "param1": {
+ "type": "String",
+ "required": true,
+ "description": "a required parameter"
+ },
+ "intParam": {
+ "type": "Integer",
+ "required": true,
+ "description": "an optional parameter (default)"
+ }
},
- // A minmally defined String parameter
- "param00": {},
- "param1": {
- "type": "String",
- "required": true,
- "description": "a required parameter"
+ "a.b.c.aRequiredSection.nonempty-subsection": {
+ "class": "Section",
+ "required": true
},
- "intParam": {
- "type": "Integer",
- "required": true,
- "description": "an optional parameter (default)"
- }
- },
- "a.b.c.aRequiredSection.nonempty-subsection": {
- "class": "Section",
- "required": true
- },
- "a.b.c.aRequiredSection.optional-subsection": {
- "class": "Section"
- },
- "a.b.c.aRequiredSection.aValidatedSection": {
- "class": "Section",
- "description": "A validated section.",
- "validations":
- "org.apache.tamaya.model.validation.MaxItemValidator?max=3"
+ "a.b.c.aRequiredSection.optional-subsection": {
+ "class": "Section"
+ },
+ "a.b.c.aRequiredSection.aValidatedSection": {
+ "class": "Section",
+ "description": "A validated section.",
+ "validations": "org.apache.tamaya.model.validation.MaxItemValidator?max=3"
}
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/test/resources/examples/configmodel.properties
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/examples/configmodel.properties b/sandbox/model/src/test/resources/examples/configmodel.properties
index 7609511..4e69549 100644
--- a/sandbox/model/src/test/resources/examples/configmodel.properties
+++ b/sandbox/model/src/test/resources/examples/configmodel.properties
@@ -22,19 +22,12 @@
####################################################################################
# Metamodel information
-[model].class=Meta-model
-[model].name=testmodel
-[model].provider=ConfigModel Extension
-[model].version=1.0
-[model].release-date=2001-01-23
-[model].author=Anatole Tresch
-# [model].format=alternate format reader type
-[model].comments=Late afternoon is best. Backup contact is Nancy.
+{model}.__provider=ConfigModel Extension
# reusable parameter definition, referenceable as MyNumber
-[MyNumber].class=Parameter
-[MyNumber].type=Integer
-[MyNumber].description=a (reusable) number type parameter (optional)
+{model}.MyNumber.class=Parameter
+{model}.MyNumber.type=Integer
+{model}.MyNumber.description=a (reusable) number type parameter (optional)
####################################################################################
# Description of Configuration Sections (minimal, can be extended by other modules).
@@ -42,51 +35,61 @@
####################################################################################
# a (section)
-a.class=Section
-a.params2.type=String
-a.params2.required=true
-a.params2.description=a required parameter
-a.paramInt.ref=MyNumber
-a.paramInt.description=an optional parameter (default)
-a._number.type=Integer
-a._number.deprecated=true
-a._number.mappedTo=a.paramInt
+{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.type=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)
-a.b.c.class=Section
-a.b.c.description=Just a test section
+{model}.a.b.c.class=Section
+{model}.a.b.c.description=Just a test section
# a.b.c.aRequiredSection (section)
-a.b.c.aRequiredSection.class=Section
-a.b.c.aRequiredSection.required=true
-a.b.c.aRequiredSection.description=A section containing required parameters is called a required section.\
+{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)
-a.b.c.aRequiredSection.subsection.class=Section
-a.b.c.aRequiredSection.subsection.param0.type=String
-a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
+{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
-a.b.c.aRequiredSection.subsection.param00.type = String
+{model}.a.b.c.aRequiredSection.subsection.param00.class=Parameter
+{model}.a.b.c.aRequiredSection.subsection.param00.type=String
# a.b.c.aRequiredSection.subsection (section)
-a.b.c.aRequiredSection.subsection.param1.type = String
-a.b.c.aRequiredSection.subsection.param1.required = true
-a.b.c.aRequiredSection.subsection.intParam.type = Integer
-a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
+{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)
-a.b.c.aRequiredSection.nonempty-subsection.class=Section
-a.b.c.aRequiredSection.nonempty-subsection.required=true
+{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)
-a.b.c.aRequiredSection.optional-subsection.class=Section
+{model}.a.b.c.aRequiredSection.optional-subsection.class=Section
# a.b.c.aValidatedSection (section)
-a.b.c.aValidatedSection.class=Section
-a.b.c.aValidatedSection.description=A validated section.
-a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator?max=3
+{model}.a.b.c.aValidatedSection.class=Section
+{model}.a.b.c.aValidatedSection.description=A validated section.
+{model}.a.b.c.aValidatedSection.validations=org.apache.tamaya.model.TestValidator
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/test/resources/examples/configmodel.xml
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/examples/configmodel.xml b/sandbox/model/src/test/resources/examples/configmodel.xml
index bf35f79..dd78c05 100644
--- a/sandbox/model/src/test/resources/examples/configmodel.xml
+++ b/sandbox/model/src/test/resources/examples/configmodel.xml
@@ -28,72 +28,70 @@ under the License.
# Metamodel information
#################################################################################-->
-<model class="Metamodel">
- <name>testmodel</name>
- <provider>ConfigModel Extension</provider>
- <version>1.0</version>
- <release-date>2001-01-23</release-date>
- <author>Anatole Tresch</author>
- <!-- model-format>alternate format reader type</model-format -->
- <comments>Late afternoon is best.
- Backup contact is Nancy.
- </comments>
+<configuration>
+ <section name="{model}" __provider="ConfigModel Extension" version="1.0" __release-date="2001-01-23"
+ author="Anatole Tresch">
+ <!-- model-format>alternate format reader type</model-format -->
+ <__description>Late afternoon is best.
+ Backup contact is Nancy.
+ </__description>
- <!--################################################################################
- # Description of Configuration Sections (minimal, can be extended by other modules).
- #################################################################################-->
- <a class="Section">
- <params class="Parameter">
- <type>String</type>
- <required>true</required>
- <description>a required parameter</description>
- </params>
- <paramInt>
- <ref>MyNumber</ref>
- <required>true</required>
- <description>an optional parameter (default)</description>
- </paramInt>
- <_number>
- <type>Integer</type>
- <deprecated>true</deprecated>
- <mappedto>a.paramInt</mappedto>
- </_number>
- <b.c class="Section">
- <description>Just a test section.</description>
- <aRequiredSection class="Section">
- <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.
- </description>
- </aRequiredSection>
- </b.c>
- </a>
+ <!--################################################################################
+ # Description of Configuration Sections (minimal, can be extended by other modules).
+ #################################################################################-->
+ <section name="a">
+ <param name="params">
+ <type>String</type>
+ <required>true</required>
+ <description>a required parameter</description>
+ </param>
+ <param name="paramInt">
+ <ref>MyNumber</ref>
+ <required>true</required>
+ <description>an optional parameter (default)</description>
+ </param>
+ <param name="_number">
+ <type>Integer</type>
+ <deprecated>true</deprecated>
+ <mappedto>a.paramInt</mappedto>
+ </param>
+ <section name="b.c">
+ <description>Just a test section.</description>
+ <section name="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.
+ </description>
+ </section>
+ </section>
+ </section>
- <a.b.c.aRequiredSection.subsection class="Section">
- <param name="param0" type="String">a minmally documented String parameter</param>
- <!-- # A minmally defined String parameter -->
- <param00>
- <type>String</type>
- </param00>
- <param1>
- <type>String</type>
+ <section name="a.b.c.aRequiredSection.subsection">
+ <param name="param0" type="String">a minmally documented String parameter</param>
+ <!-- # A minmally defined String parameter -->
+ <param name="param00">
+ <type>String</type>
+ </param>
+ <param name="param1">
+ <type>String</type>
+ <required>true</required>
+ <description>a required parameter</description>description>
+ </param>
+ <param name="intParam">
+ <type>Integer</type>
+ <description>an optional parameter (default)</description>
+ </param>
+ <section name="b.c">
+ <description>Just a test section.</description>
+ </section>
+ </section>
+ <section name="a.b.c.aRequiredSection.nonempty-subsection">
<required>true</required>
- <description>a required parameter</description>description>
- </param1>
- <intParam>
- <type>Integer</type>
- <description>an optional parameter (default)</description>
- </intParam>
- <b.c class="Section">
- <description>Just a test section.</description>
- </b.c>
- </a.b.c.aRequiredSection.subsection>
- <a.b.c.aRequiredSection.nonempty-subsection>
- <required>true</required>
- </a.b.c.aRequiredSection.nonempty-subsection>
- <a.b.c.aRequiredSection.optional-subsection class="Section"/>
- <a.b.c.aRequiredSection.aValidatedSection>
- <validations>org.apache.tamaya.model.validation.MaxItemValidator?max=3"</validations>
- <description>A validation section.</description>
- </a.b.c.aRequiredSection.aValidatedSection>
-</model>
+ </section>
+ <section name="a.b.c.aRequiredSection.optional-subsection"/>
+ <section name="a.b.c.aRequiredSection.aValidatedSection">
+ <validations>org.apache.tamaya.model.validation.MaxItemValidator?max=3"</validations>
+ <description>A validation section.</description>
+ </section>
+ </section>
+</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0a8226a8/sandbox/model/src/test/resources/examples/configmodel.yaml
----------------------------------------------------------------------
diff --git a/sandbox/model/src/test/resources/examples/configmodel.yaml b/sandbox/model/src/test/resources/examples/configmodel.yaml
index 4c9cf12..a59246a 100644
--- a/sandbox/model/src/test/resources/examples/configmodel.yaml
+++ b/sandbox/model/src/test/resources/examples/configmodel.yaml
@@ -17,27 +17,24 @@
# under the License.
#
-
##################################################################################
# Example of a configuration metamodel expressed via YAML(tm).
# Structure is shown through indentation (one or more spaces).
# Sequence items are denoted by a dash,
# key value pairs within a map are separated by a colon.
####################################################################################
-tbd (adapt to others...)
####################################################################################
# Metamodel information
####################################################################################
-model: {
- class : "Metamodel",
- name : 'testmodel',
- provider : 'ValidationProviderSpi Extension',
- version : '1.0',
- release-date : 2001-01-23,
- author : 'Anatole Tresch',
+{model}: {
+ __name : 'testmodel',
+ __provider : 'ValidationProviderSpi Extension',
+ __version : '1.0',
+ __release-date : 2001-01-23,
+ __author : 'Anatole Tresch',
# model-format: 'alternate format reader type'
- comments: >
+ __description: >
Late afternoon is best.
Backup contact is Nancy.
}
@@ -46,47 +43,64 @@ model: {
# Description of Configuration Sections (minimal, can be extended by other modules).
####################################################################################
---
-a: {
-# Paramname Type Validations Description
- params2: 'String', 'required', 'a required parameter',
+{model}.a.params2: {
+ type : 'String',
+ required : true,
+ description : 'a required parameter',
paramInt: 'Integer', 'an optional parameter (default)',
}
---
-a.b.c: {
- __desc: 'Just a test section.'
+{model}.a.paramInt: {
+ type : 'Integer',
+ description : 'an optional parameter (default)',
+}
+---
+{model}.a.b.c: {
+ description: 'Just a test section.'
}
---
-a.b.c.aRequiredSection: {
- __validations: 'required',
- __desc: |
+{model}.a.b.c.aRequiredSection: {
+ required: true,
+ 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: {
-# Paramname Type Validations Description
- param0: 'String', 'a minmally documented String parameter}',
- param00: 'String', # A minmally defined String parameter
- param1: 'String', 'required', 'a required parameter',
- intParam: 'Integer', 'an optional parameter (default)'
+{model}.a.b.c.aRequiredSection.subsection: {
+ param0: {
+ type: 'String',
+ description: 'a minmally documented String parameter}'
+ }, ,
+ param00:{
+ type: 'String' # A minmally defined String parameter
+ },
+ param1: {
+ tpye: 'String',
+ required: true,
+ description: 'a required parameter'
+ },
+ intParam: {
+ type: 'Integer',
+ description: 'an optional parameter (default)'
+ }
}
...
---
-a.b.c.aRequiredSection.nonempty-subsection: {
- __validations: 'required'
+{model}.a.b.c.aRequiredSection.nonempty-subsection: {
+ required: true
}
...
---
-a.b.c.aRequiredSection.optional-subsection: {}
+{model}.a.b.c.aRequiredSection.optional-subsection: {}
...
---
-a.b.c.aRequiredSection.aValidatedSection: {
- __desc: 'A validation section.',
- __validations: 'org.apache.tamaya.model.validation.MaxItemValidator?max=3'
+{model}.a.b.c.aRequiredSection.aValidatedSection: {
+ description: 'A validation section.',
+ validations: 'org.apache.tamaya.model.validation.MaxItemValidator?max=3'
}