commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r766914 - in /commons/proper/configuration/trunk: conf/ src/java/org/apache/commons/configuration/beanutils/ src/java/org/apache/commons/configuration/interpol/
Date Mon, 20 Apr 2009 23:38:50 GMT
Author: rgoers
Date: Mon Apr 20 23:38:49 2009
New Revision: 766914

URL: http://svn.apache.org/viewvc?rev=766914&view=rev
Log:
Allow Collections in DefaultConfigurationBuilder so ExprLookup can have multiple variables

Modified:
    commons/proper/configuration/trunk/conf/testExpression.xml
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ExprLookup.java

Modified: commons/proper/configuration/trunk/conf/testExpression.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testExpression.xml?rev=766914&r1=766913&r2=766914&view=diff
==============================================================================
--- commons/proper/configuration/trunk/conf/testExpression.xml (original)
+++ commons/proper/configuration/trunk/conf/testExpression.xml Mon Apr 20 23:38:49 2009
@@ -15,6 +15,7 @@
               config-class="org.apache.commons.configuration.interpol.ExprLookup">
         <variables>
           <variable name="String" value="Class:org.apache.commons.lang.StringUtils"/>
+          <variable name="MDC" value="Class:org.slf4j.MDC"/>
         </variables>
       </lookup>
     </lookups>
@@ -25,7 +26,7 @@
     </providers>
   </header>
   <override>
-    <multifile filePattern='$$${expr:String.right("$[mdc:Id]", 2)}/testMultiConfiguration_$$${sys:Id}.xml'
+    <multifile filePattern='$$${expr:String.right(MDC.get("Id"), 2)}/testMultiConfiguration_$$${sys:Id}.xml'
                config-name="clientConfig" delimiterParsingDisabled="true">
        <expressionEngine
           config-class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine"/>

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java?rev=766914&r1=766913&r2=766914&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/BeanHelper.java
Mon Apr 20 23:38:49 2009
@@ -22,6 +22,8 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.Collection;
+import java.util.List;
 import java.beans.PropertyDescriptor;
 
 import org.apache.commons.beanutils.BeanUtils;
@@ -164,13 +166,39 @@
         Map nestedBeans = data.getNestedBeanDeclarations();
         if (nestedBeans != null)
         {
-            for (Iterator it = nestedBeans.entrySet().iterator(); it.hasNext();)
+            if (bean instanceof Collection)
             {
-                Map.Entry e = (Map.Entry) it.next();
-                String propName = (String) e.getKey();
-                Class defaultClass = getDefaultClass(bean, propName);
-                initProperty(bean, propName, createBean(
+                Collection coll = (Collection) bean;
+                if (nestedBeans.size() == 1)
+                {
+                    Map.Entry e = (Map.Entry) nestedBeans.entrySet().iterator().next();
+                    String propName = (String) e.getKey();
+                    Class defaultClass = getDefaultClass(bean, propName);
+                    if (e.getValue() instanceof List)
+                    {
+                        Iterator iter = ((List) e.getValue()).iterator();
+                        while (iter.hasNext())
+                        {
+                            coll.add(createBean((BeanDeclaration) iter.next(), defaultClass));
+                        }
+                    }
+                    else
+                    {
+                        BeanDeclaration decl = (BeanDeclaration) e.getValue();
+                        coll.add(createBean(decl, defaultClass));
+                    }
+                }
+            }
+            else
+            {
+                for (Iterator it = nestedBeans.entrySet().iterator(); it.hasNext();)
+                {
+                    Map.Entry e = (Map.Entry) it.next();
+                    String propName = (String) e.getKey();
+                    Class defaultClass = getDefaultClass(bean, propName);
+                    initProperty(bean, propName, createBean(
                         (BeanDeclaration) e.getValue(), defaultClass));
+                }
             }
         }
     }

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java?rev=766914&r1=766913&r2=766914&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
Mon Apr 20 23:38:49 2009
@@ -19,10 +19,13 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
 
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.PropertyConverter;
 import org.apache.commons.configuration.SubnodeConfiguration;
+import org.apache.commons.configuration.ConfigurationRuntimeException;
 import org.apache.commons.configuration.tree.ConfigurationNode;
 import org.apache.commons.configuration.tree.DefaultConfigurationNode;
 
@@ -310,7 +313,26 @@
             ConfigurationNode child = (ConfigurationNode) it.next();
             if (!isReservedNode(child))
             {
-                nested.put(child.getName(), createBeanDeclaration(child));
+                if (nested.containsKey(child.getName()))
+                {
+                    Object obj = nested.get(child.getName());
+                    List list;
+                    if (obj instanceof List)
+                    {
+                        list = (List) obj;
+                    }
+                    else
+                    {
+                        list = new ArrayList();
+                        list.add(obj);
+                        nested.put(child.getName(), list);
+                    }
+                    list.add(createBeanDeclaration(child));
+                }
+                else
+                {
+                    nested.put(child.getName(), createBeanDeclaration(child));
+                }
             }
         }
 
@@ -365,8 +387,24 @@
      */
     protected BeanDeclaration createBeanDeclaration(ConfigurationNode node)
     {
-        return new XMLBeanDeclaration(getConfiguration().configurationAt(
-                node.getName()), node);
+        List list = getConfiguration().configurationsAt(node.getName());
+        if (list.size() == 1)
+        {
+            return new XMLBeanDeclaration((SubnodeConfiguration) list.get(0), node);
+        }
+        else
+        {
+            Iterator iter = list.iterator();
+            while (iter.hasNext())
+            {
+                SubnodeConfiguration config = (SubnodeConfiguration) iter.next();
+                if (config.getRootNode().equals(node))
+                {
+                    return new XMLBeanDeclaration(config, node);
+                }
+            }
+            throw new ConfigurationRuntimeException("Unable to match node for " + node.getName());
+        }
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ExprLookup.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ExprLookup.java?rev=766914&r1=766913&r2=766914&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ExprLookup.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ExprLookup.java
Mon Apr 20 23:38:49 2009
@@ -203,10 +203,11 @@
      */
     public static class Variables extends ArrayList
     {
+        /*
         public void setVariable(Variable var)
         {
             add(var);
-        }
+        } */
 
         public Variable getVariable()
         {



Mime
View raw message