You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2005/10/09 20:34:01 UTC

svn commit: r312489 - in /jakarta/commons/proper/betwixt/trunk: ./ src/java/org/apache/commons/betwixt/digester/ src/test/org/apache/commons/betwixt/digester/ xdocs/

Author: rdonkin
Date: Sun Oct  9 11:33:51 2005
New Revision: 312489

URL: http://svn.apache.org/viewcvs?rev=312489&view=rev
Log:
Fixed missing support for text and options in multi-mappings. Factored out common code. Submitted by Brian Ferris. Issue #36916.

Added:
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/CommonRuleSet.java
    jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/digester/TestDigestMultiMapping.java
Modified:
    jakarta/commons/proper/betwixt/trunk/project.xml
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MultiMappingBeanInfoDigester.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java
    jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml

Modified: jakarta/commons/proper/betwixt/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/project.xml?rev=312489&r1=312488&r2=312489&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/project.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/project.xml Sun Oct  9 11:33:51 2005
@@ -140,6 +140,10 @@
       <name>Brian Pugh</name>
       <email></email>
     </contributor>
+    <contributor>
+      <name>Brian Ferris</name>
+      <email></email>
+    </contributor>
   </contributors>
 
   <dependencies>

Added: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/CommonRuleSet.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/CommonRuleSet.java?rev=312489&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/CommonRuleSet.java (added)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/CommonRuleSet.java Sun Oct  9 11:33:51 2005
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.commons.betwixt.digester;
+
+import org.apache.commons.digester.Digester;
+import org.apache.commons.digester.RuleSetBase;
+
+/**
+ * Rules common to both {@link org.apache.commons.betwixt.digester.MultiMappingBeanInfoDigester}
+ * and {@link org.apache.commons.betwixt.digester.XMLBeanInfoDigester}.
+ */
+public class CommonRuleSet extends RuleSetBase {
+
+    public void addRuleInstances(Digester digester) {
+        digester.addRule("*/element", new ElementRule());
+        digester.addRule( "*/text", new TextRule() );
+        digester.addRule("*/attribute", new AttributeRule());
+        digester.addRule("*/hide", new HideRule());
+        digester.addRule("*/addDefaults", new AddDefaultsRule());
+        
+        OptionRule optionRule = new OptionRule();
+        digester.addRule( "*/option", optionRule );
+        digester.addRule( "*/option/name", optionRule.getNameRule() );
+        digester.addRule( "*/option/value", optionRule.getValueRule() );
+
+    }
+
+}

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MultiMappingBeanInfoDigester.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MultiMappingBeanInfoDigester.java?rev=312489&r1=312488&r2=312489&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MultiMappingBeanInfoDigester.java (original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MultiMappingBeanInfoDigester.java Sun Oct  9 11:33:51 2005
@@ -41,11 +41,8 @@
 	        // add the various rules
 	        addRule("betwixt-config", new ConfigRule());
 	        addRule("betwixt-config/class", new ClassRule());
-	        addRule("*/element", new ElementRule());
-	        addRule("*/attribute", new AttributeRule());
-	        addRule("*/hide", new HideRule());
-	        addRule("*/addDefaults", new AddDefaultsRule());
-	    }
+	        addRuleSet(new CommonRuleSet());
+        }
         
 	    // now initialize
 	    //setAttributesForPrimitives(true);

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java?rev=312489&r1=312488&r2=312489&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java (original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java Sun Oct  9 11:33:51 2005
@@ -158,16 +158,8 @@
             // add the various rules
             
             addRule( "info", new InfoRule() );
-            addRule( "*/element", new ElementRule() );
-            addRule( "*/text", new TextRule() );
-            addRule( "*/attribute", new AttributeRule() );
-            addRule( "*/hide", new HideRule() );
-            addRule( "*/addDefaults", new AddDefaultsRule() );
+            addRuleSet(new CommonRuleSet());
             
-            OptionRule optionRule = new OptionRule();
-            addRule( "*/option", optionRule );
-            addRule( "*/option/name", optionRule.getNameRule() );
-            addRule( "*/option/value", optionRule.getValueRule() );
         }
         
         // now initialize

Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/digester/TestDigestMultiMapping.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/digester/TestDigestMultiMapping.java?rev=312489&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/digester/TestDigestMultiMapping.java (added)
+++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/digester/TestDigestMultiMapping.java Sun Oct  9 11:33:51 2005
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.commons.betwixt.digester;
+
+import java.io.StringReader;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.betwixt.ElementDescriptor;
+import org.apache.commons.betwixt.XMLBeanInfo;
+import org.apache.commons.betwixt.XMLIntrospector;
+import org.apache.commons.betwixt.dotbetwixt.ExampleBean;
+
+/**
+ * Tests for reading dot betwist files.
+ * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
+ * @version $Revision: 155402 $
+ */
+public class TestDigestMultiMapping extends TestCase {
+    
+    
+    public void testDigestWithOptions() throws Exception {
+        String xml = "<?xml version='1.0'?>" +
+        "<betwixt-config>" +
+        "  <class name=\"" + TestDigestMultiMapping.class.getName() + "\">" +
+        "    <element name=\"test-multi-mapping\">" +
+        "      <option>" +
+        "        <name>test-key-a</name>" +
+        "        <value>test-value-a</value>" +
+        "      </option>" +
+        "      <option>" +
+        "        <name>test-key-b</name>" +
+        "        <value>test-value-b</value>" +
+        "      </option>" +
+        "      <element name=\"maps\" property=\"maps\">" +
+        "        <option>" +
+        "          <name>test-key-c</name>" +
+        "          <value>test-value-c</value>" +
+        "        </option>" +
+        "      </element>" +
+        "    </element>" +
+        "  </class>" +
+        "</betwixt-config>";
+        
+        MultiMappingBeanInfoDigester digester = new MultiMappingBeanInfoDigester();
+        digester.setXMLIntrospector(new XMLIntrospector());
+        digester.setBeanClass(ExampleBean.class);
+        
+        digester.parse(new StringReader(xml));
+        Map beanInfoMap = digester.getBeanInfoMap(); 
+        assertTrue( beanInfoMap.containsKey(TestDigestMultiMapping.class));
+        
+        XMLBeanInfo xmlBeanInfo = (XMLBeanInfo) beanInfoMap.get(TestDigestMultiMapping.class);
+        assertNotNull(xmlBeanInfo);
+        
+        ElementDescriptor baseDescriptor = xmlBeanInfo.getElementDescriptor();
+        
+        assertEquals("Value one set on base", "test-value-a",  baseDescriptor.getOptions().getValue("test-key-a"));
+        assertEquals("Value two set on base", "test-value-b",  baseDescriptor.getOptions().getValue("test-key-b"));
+        assertNull("Value three not set on base",  baseDescriptor.getOptions().getValue("three"));
+
+        assertEquals("Number of child elements", 1, baseDescriptor.getElementDescriptors().length);
+        
+        ElementDescriptor childDescriptor = baseDescriptor.getElementDescriptors()[0];
+        assertNull("Value one set on base",  childDescriptor.getOptions().getValue("test-key-a"));
+        assertNull("Value two set on base",  childDescriptor.getOptions().getValue("test-key-b"));
+        assertEquals("Value three set on child", "test-value-c",  childDescriptor.getOptions().getValue("test-key-c"));
+    }
+}
\ No newline at end of file

Modified: jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml?rev=312489&r1=312488&r2=312489&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml Sun Oct  9 11:33:51 2005
@@ -200,6 +200,9 @@
     <subsection name='Since 0.7'>            
         <ul>
             <li>
+Added support for text and options into multi-mappings.
+            </li>
+            <li>
 Improved support for subclasses of Java collective types
 by factoring collective type recognition into strategy.
             </li>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org