tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject [14/50] [abbrv] incubator-tamaya-extensions git commit: TAMAYA-158: Aligned metadata format for model extension with defaults.
Date Fri, 16 Sep 2016 22:03:24 GMT
TAMAYA-158: Aligned metadata format for model extension with defaults.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/c742739a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/c742739a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/c742739a

Branch: refs/heads/master
Commit: c742739a1e4a8d9545961085230f78f84d9359c2
Parents: 12261be
Author: anatole <anatole@apache.org>
Authored: Sun May 1 20:36:30 2016 +0200
Committer: anatole <anatole@apache.org>
Committed: Sun May 1 21:02:06 2016 +0200

----------------------------------------------------------------------
 .../model/internal/ConfigDocumentationBean.java |  4 +-
 .../ConfiguredInlineModelProviderSpi.java       |  3 +-
 .../ConfiguredResourcesModelProviderSpi.java    |  2 +-
 .../tamaya/model/spi/ConfigModelReader.java     | 82 ++++++--------------
 .../apache/tamaya/model/spi/SectionModel.java   |  3 +
 .../resources/META-INF/configmodel.properties   | 32 ++++----
 .../internal/ConfigDocumentationBeanTest.java   | 20 ++---
 .../resources/META-INF/configmodel.properties   | 78 +++++++++----------
 8 files changed, 95 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c742739a/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
----------------------------------------------------------------------
diff --git a/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
b/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
index 2d40ac0..3298025 100644
--- a/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
+++ b/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
@@ -161,7 +161,7 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
 
 
     private JsonObject toJsonObject(ConfigModel val) {
-        JsonObjectBuilder valJson = Json.createObjectBuilder().add("type", val.getType().toString())
+        JsonObjectBuilder valJson = Json.createObjectBuilder().add("target", val.getType().toString())
                 .add("name", val.getName());
         if(val.getDescription()!=null) {
             valJson.add("description", val.getDescription());
@@ -173,7 +173,7 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
     }
 
     private JsonObject toJsonObject(Validation val) {
-        JsonObjectBuilder valJson = Json.createObjectBuilder().add("type", val.getConfigModel().getType().toString())
+        JsonObjectBuilder valJson = Json.createObjectBuilder().add("target", val.getConfigModel().getType().toString())
                 .add("name", val.getConfigModel().getName());
         if(val.getConfigModel().isRequired()){
             valJson.add("required",true);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c742739a/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
b/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
index a15ce05..8111491 100644
--- a/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
+++ b/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
@@ -53,8 +53,7 @@ public class ConfiguredInlineModelProviderSpi implements ModelProviderSpi
{
         if (enabled) {
             LOG.info("Reading model configuration from config...");
             Map<String,String> config = ConfigurationProvider.getConfiguration().getProperties();
-            configModels.addAll(ConfigModelReader.loadValidations(config,
-                    "<Inline Configuration Model>"));
+            configModels.addAll(ConfigModelReader.loadValidations(config));
         }
         configModels = Collections.unmodifiableList(configModels);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c742739a/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
b/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
index 2a136aa..7c5836e 100644
--- a/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
+++ b/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
@@ -141,7 +141,7 @@ public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi
{
             for (final URL config : urls) {
                 try (InputStream is = config.openStream()) {
                     final ConfigurationData data = ConfigurationFormats.readConfigurationData(config);
-                    configModels.addAll(ConfigModelReader.loadValidations(data.getCombinedProperties(),
config.toString()));
+                    configModels.addAll(ConfigModelReader.loadValidations(data.getCombinedProperties()));
                 } catch (final Exception e) {
                     Logger.getLogger(getClass().getName()).log(Level.SEVERE,
                             "Error loading config model data from " + config, e);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c742739a/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
----------------------------------------------------------------------
diff --git a/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java b/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
index b380051..b8d95d0 100644
--- a/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
+++ b/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
@@ -35,7 +35,7 @@ import org.apache.tamaya.model.ConfigModel;
 public final class ConfigModelReader {
 
     /** The default model entries selector. */
-    private static final String DEFAULT_META_INFO_SELECTOR = "{model}";
+    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";
 
@@ -43,84 +43,48 @@ public final class ConfigModelReader {
      * Utility class only.
      */
     private ConfigModelReader(){}
-///*
-//    *//**
-//     * Loads validations as configured in the given properties.
-//     * @param props the properties to be read
-//     * @param selector
-//     * @return a collection of config validations.
-//     *//*
-//    public static Collection<ConfigModel> loadValidations(Map<String,String>
props, String selector) {
-//        Map<String,String> map = new HashMap<>();
-//        for(Map.Entry<String, String> en: props.entrySet()){
-//            if(!selector.matches(en.getKey())){
-//                map.put(en.getKey().toString(), props.get(en.getKey().toString()));
-//            }
-//        }
-//        return loadValidations(map);
-//    }*/
 
-    /**
-     * Loads validations as configured in the given properties.
-     * @param props the properties to be read
-     * @return a collection of config validations.
-     */
-    public static Collection<ConfigModel> loadValidations(Map<String,String>
props) {
-        return loadValidations(props, getSelector(props));
-    }
-
-    /**
-     * Evaluates the correct selector.
-     * @param props
-     * @return
-     */
-    private static String getSelector(Map<String,String> props){
-        String selector = props.get(META_INFO_SELECTOR_PARAM);
-        if(selector==null){
-            selector = DEFAULT_META_INFO_SELECTOR;
-        }
-        return selector;
-    }
 
     /**
      * 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.
      * @return a collection of config validations.
      */
-    public static Collection<ConfigModel> loadValidations(Map<String,String>
props, String selector) {
+    public static Collection<ConfigModel> loadValidations(Map<String,String>
props) {
         List<ConfigModel> result = new ArrayList<>();
         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()));
+            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 clazz = props.get(baseKey + ".class");
-            String type = props.get(baseKey + ".type");
+            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 + ".transitive");
+            String value = props.get(baseKey + ".model.transitive");
             boolean transitive = false;
             if(value!=null) {
                 transitive = Boolean.parseBoolean(value);
             }
-            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)) {
+            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(targetKey,
+                        description, type, requiredVal, regEx, validations));
+            } else if ("Section".equalsIgnoreCase(target)) {
                 if(transitive){
-                    result.add(createSectionValidation(baseKey.substring(selector.length()
+ 1)+".*", description, requiredVal,
-                            validations));
+                    result.add(createSectionValidation(targetKey+".*",
+                            description, requiredVal, validations));
                 } else {
-                    result.add(createSectionValidation(baseKey.substring(selector.length()
+ 1), description, requiredVal,
-                            validations));
+                    result.add(createSectionValidation(targetKey,
+                            description, requiredVal, validations));
                 }
             }
         }
@@ -144,7 +108,7 @@ public final class ConfigModelReader {
                 .setDescription(description).setExpression(regEx).setType(type);
 //        if (validations != null) {
 //            try {
-//                // TODO defined validator API
+//                // TODO define validator API
 ////                builder.addValidations(loadValidations(validations));
 //            } catch (Exception e) {
 //                LOGGER.log(Level.WARNING, "Failed to load validations for " + paramName,
e);
@@ -168,7 +132,7 @@ public final class ConfigModelReader {
                 .setDescription(description);
 //        if (validations != null) {
 //            try {
-//                // TODO defined validator API
+//                // TODO define validator API
 ////                builder.addValidations(loadValidations(valiadtions));
 //            } catch (Exception e) {
 //                LOGGER.log(Level.WARNING, "Failed to load validations for " + sectionName,
e);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c742739a/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java
----------------------------------------------------------------------
diff --git a/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java b/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java
index 9f55a2b..31eaa51 100644
--- a/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java
+++ b/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java
@@ -84,6 +84,9 @@ public class SectionModel extends GroupModel {
         String lookupKey = getName() + '.';
         boolean present = false;
         for(String key:map.keySet()){
+            if(key.startsWith("_")){
+                continue;
+            }
             if(key.startsWith(lookupKey)){
                 present = true;
                 break;

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c742739a/model/src/main/resources/META-INF/configmodel.properties
----------------------------------------------------------------------
diff --git a/model/src/main/resources/META-INF/configmodel.properties b/model/src/main/resources/META-INF/configmodel.properties
index 7861c9e..3381a09 100644
--- a/model/src/main/resources/META-INF/configmodel.properties
+++ b/model/src/main/resources/META-INF/configmodel.properties
@@ -17,19 +17,19 @@
 # under the License.
 #
 # Contains definitions for default system property areas.
-{model}.awt.class=Section
-{model}.awt.transitive=true
-{model}.file.class=Section
-{model}.file.transitive=true
-{model}.java.class=Section
-{model}.java.transitive=true
-{model}.line.class=Section
-{model}.line.transitive=true
-{model}.os.class=Section
-{model}.os.transitive=true
-{model}.path.class=Section
-{model}.path.transitive=true
-{model}.sun.class=Section
-{model}.sun.transitive=true
-{model}.user.class=Section
-{model}.user.transitive=true
+_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-extensions/blob/c742739a/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
----------------------------------------------------------------------
diff --git a/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
b/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
index d60e902..e791417 100644
--- a/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
+++ b/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
@@ -37,7 +37,7 @@ public class ConfigDocumentationBeanTest {
         String results = mbean.validate(false);
         assertNotNull(results);
         assertFalse(results.trim().isEmpty());
-        assertTrue(results.contains("\"type\":\"Parameter\""));
+        assertTrue(results.contains("\"target\":\"Parameter\""));
         assertTrue(results.contains("\"result\":\"MISSING\""));
         assertFalse(results.contains("\"description\":\"Undefined key: "));
         assertFalse(results.contains(" \"result\":\"UNDEFINED\""));
@@ -53,8 +53,8 @@ public class ConfigDocumentationBeanTest {
         assertFalse(results.contains("\"name\":\"sun."));
         assertFalse(results.contains("\"name\":\"file."));
         // test others
-        assertTrue(results.contains("\"type\":\"Parameter\""));
-        assertTrue(results.contains("\"type\":\"Section\""));
+        assertTrue(results.contains("\"target\":\"Parameter\""));
+        assertTrue(results.contains("\"target\":\"Section\""));
         assertTrue(results.contains("\"result\":\"MISSING\""));
         assertTrue(results.contains("\"description\":\"Undefined key: "));
         assertTrue(results.contains(" \"result\":\"UNDEFINED\""));
@@ -65,7 +65,7 @@ public class ConfigDocumentationBeanTest {
         String results = mbean.getConfigurationModel();
         assertNotNull(results);
         assertFalse(results.trim().isEmpty());
-        assertTrue(results.contains("\"type\":\"Parameter\""));
+        assertTrue(results.contains("\"target\":\"Parameter\""));
         assertTrue(results.contains("\"name\":\"MyNumber\""));
         assertTrue(results.contains("\"name\":\"a.b.c\""));
         assertTrue(results.contains("\"required\":true"));
@@ -76,8 +76,8 @@ public class ConfigDocumentationBeanTest {
         String results = mbean.getConfigurationModel(ModelTarget.Parameter);
         assertNotNull(results);
         assertFalse(results.trim().isEmpty());
-        assertTrue(results.contains("\"type\":\"Parameter\""));
-        assertFalse(results.contains("\"type\":\"Section\""));
+        assertTrue(results.contains("\"target\":\"Parameter\""));
+        assertFalse(results.contains("\"target\":\"Section\""));
         assertTrue(results.contains("\"required\":true"));
     }
 
@@ -86,8 +86,8 @@ public class ConfigDocumentationBeanTest {
         String results = mbean.findConfigurationModels("a");
         assertNotNull(results);
         assertFalse(results.trim().isEmpty());
-        assertFalse(results.contains("\"type\":\"Parameter\""));
-        assertTrue(results.contains("\"type\":\"Section\""));
+        assertFalse(results.contains("\"target\":\"Parameter\""));
+        assertTrue(results.contains("\"target\":\"Section\""));
     }
 
     @Test
@@ -95,8 +95,8 @@ public class ConfigDocumentationBeanTest {
         String results = mbean.findValidationModels("a", ModelTarget.Section);
         assertNotNull(results);
         assertFalse(results.trim().isEmpty());
-        assertFalse(results.contains("\"type\":\"Parameter\""));
-        assertTrue(results.contains("\"type\":\"Section\""));
+        assertFalse(results.contains("\"target\":\"Parameter\""));
+        assertTrue(results.contains("\"target\":\"Section\""));
         System.out.println(results);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c742739a/model/src/test/resources/META-INF/configmodel.properties
----------------------------------------------------------------------
diff --git a/model/src/test/resources/META-INF/configmodel.properties b/model/src/test/resources/META-INF/configmodel.properties
index 4561f3f..a7956dc 100644
--- a/model/src/test/resources/META-INF/configmodel.properties
+++ b/model/src/test/resources/META-INF/configmodel.properties
@@ -22,12 +22,12 @@
 ####################################################################################
 
 # Metamodel information
-{model}.provider=ConfigModel Extension
+_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)
+_MyNumber.model.target=Parameter
+_MyNumber.model.type=Integer
+_MyNumber.model.description=a (reusable) number type parameter (optional)
 
 ####################################################################################
 # Description of Configuration Sections (minimal, can be extended by other modules).
@@ -35,61 +35,61 @@
 ####################################################################################
 
 # 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
+_a.model.target=Section
+_a.params2.model.target=Parameter
+_a.params2.model.type=String
+_a.params2.model.required=true
+_a.params2.model.description=a required parameter
 
-{model}.a.paramInt.class=Parameter
-{model}.a.paramInt.type=ref:MyNumber
-{model}.a.paramInt.description=an optional parameter (default)
+_a.paramInt.model.target=Parameter
+_a.paramInt.model.type=ref:MyNumber
+_a.paramInt.model.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._number.model.target=Parameter
+_a._number.model.type=Integer
+_a._number.model.deprecated=true
+_a._number.model.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.model.target=Section
+_a.b.c.model.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.\
+_a.b.c.aRequiredSection.model.target=Section
+_a.b.c.aRequiredSection.model.required=true
+_a.b.c.aRequiredSection.model.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
+_a.b.c.aRequiredSection.subsection.model.target=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.b.c.aRequiredSection.subsection.param0.model.model.target=Parameter
+_a.b.c.aRequiredSection.subsection.param0.type=String
+_a.b.c.aRequiredSection.subsection.param0.model.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.param00.model.target=Parameter
+_a.b.c.aRequiredSection.subsection.param00.model.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.subsection.param1.model.target=Parameter
+_a.b.c.aRequiredSection.subsection.param1.model.type = String
+_a.b.c.aRequiredSection.subsection.param1.model.required = true
+_a.b.c.aRequiredSection.subsection.intParam.model.target=Parameter
+_a.b.c.aRequiredSection.subsection.intParam.model.type = Integer
+_a.b.c.aRequiredSection.subsection.intParam.model.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.nonempty-subsection.model.target=Section
+_a.b.c.aRequiredSection.nonempty-subsection.model.required=true
 
 # a.b.c.aRequiredSection.optional-subsection (section)
-{model}.a.b.c.aRequiredSection.optional-subsection.class=Section
+_a.b.c.aRequiredSection.optional-subsection.model.target=Section
 
 # a.b.c.aValidatedSection (section)
-{model}.a.b.c.aValidatedSection.class=Section
-{model}.a.b.c.aValidatedSection.description=A validated section.
-{model}.a.b.c.aValidatedSection.configModels=org.apache.tamaya.model.TestValidator
+_a.b.c.aValidatedSection.model.target=Section
+_a.b.c.aValidatedSection.model.description=A validated section.
+_a.b.c.aValidatedSection.model.validator=org.apache.tamaya.model.TestValidator
 
 
 


Mime
View raw message