Author: rdonkin Date: Sat Dec 10 01:45:51 2005 New Revision: 355731 URL: http://svn.apache.org/viewcvs?rev=355731&view=rev Log: Fix for problem when using primitive collectivesdefined by a dot betwixt file.
Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.betwixt jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.java jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestStringCollections.java Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java?rev=355731&r1=355730&r2=355731&view=diff ============================================================================== --- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java (original) +++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java Sat Dec 10 01:45:51 2005 @@ -385,8 +385,17 @@ } else { elementDescriptor .setUpdater(new MethodUpdater(updateMethod)); - elementDescriptor.setSingularPropertyType(updateMethod - .getParameterTypes()[0]); + Class singularType = updateMethod.getParameterTypes()[0]; + elementDescriptor.setSingularPropertyType(singularType); + if (singularType != null) + { + boolean isPrimitive = getXMLIntrospector().isPrimitiveType(singularType); + if (isPrimitive) + { + log.debug("Primitive collective: setting hollow to false"); + elementDescriptor.setHollow(false); + } + } if (log.isTraceEnabled()) { log.trace("Set custom updater on " + elementDescriptor); } Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.betwixt URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.betwixt?rev=355731&view=auto ============================================================================== --- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.betwixt (added) +++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.betwixt Sat Dec 10 01:45:51 2005 @@ -0,0 +1,8 @@ +<?xml version='1.0'?> +<info> + <element name='PoemBean'> + <element name='lines'> + <element name='line' property='lines' updater='addLine'/> + </element> + </element> +</info> \ No newline at end of file Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.java?rev=355731&view=auto ============================================================================== --- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.java (added) +++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/PoemBean.java Sat Dec 10 01:45:51 2005 @@ -0,0 +1,32 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; + +public class PoemBean { + + private List lines = new ArrayList(); + + public List getLines() { + return lines; + } + + public void addLine(String line) { + lines.add(line); + } +} Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestStringCollections.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestStringCollections.java?rev=355731&view=auto ============================================================================== --- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestStringCollections.java (added) +++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestStringCollections.java Sat Dec 10 01:45:51 2005 @@ -0,0 +1,91 @@ +/* + * 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; + +import java.io.StringReader; +import java.io.StringWriter; + +import org.apache.commons.betwixt.io.BeanReader; +import org.apache.commons.betwixt.io.BeanWriter; + +import junit.framework.TestCase; + +public class TestStringCollections extends AbstractTestCase { + + public TestStringCollections(String testName) { + super(testName); + } + + public void testIntrospection() throws Exception { + XMLIntrospector introspector = new XMLIntrospector(); + XMLBeanInfo xmlBeanInfo = introspector.introspect(PoemBean.class); + ElementDescriptor beanDescriptor = xmlBeanInfo.getElementDescriptor(); + ElementDescriptor[] beanChildren = beanDescriptor.getElementDescriptors(); + assertEquals("Only one child", 1, beanChildren.length); + ElementDescriptor[] linesChildren = beanChildren[0].getElementDescriptors(); + assertEquals("Only one lines child", 1, linesChildren.length); + assertFalse("Line child is not hollow", linesChildren[0].isHollow()); + } + + public void testWritePoem() throws Exception { + String expected = "<?xml version='1.0'?>" + + "<PoemBean>" + + "<lines>" + + "<line>It is an ancient Mariner,</line>" + + "<line>And he stoppeth one of three.</line>" + + "<line>\"By thy long grey beard and the glittering eye,</line>" + + "<line>Now wherefore stopp'st thou me?\"</line>" + + "</lines>" + + "</PoemBean>"; + PoemBean bean = new PoemBean(); + bean.addLine("It is an ancient Mariner,"); + bean.addLine("And he stoppeth one of three."); + bean.addLine("\"By thy long grey beard and the glittering eye,"); + bean.addLine("Now wherefore stopp'st thou me?\""); + + StringWriter out = new StringWriter(); + out.write("<?xml version='1.0'?>"); + BeanWriter writer = new BeanWriter(out); + writer.getBindingConfiguration().setMapIDs(false); + writer.write(bean); + + String xml = out.toString(); + xmlAssertIsomorphic(parseString(expected), parseString(xml)); + } + + public void testReadPoem() throws Exception { + String xml = "<?xml version='1.0'?>" + + "<PoemBean>" + + "<lines>" + + "<line>It is an ancient Mariner,</line>" + + "<line>And he stoppeth one of three.</line>" + + "<line>\"By thy long grey beard and the glittering eye,</line>" + + "<line>Now wherefore stopp'st thou me?\"</line>" + + "</lines>" + + "</PoemBean>"; + BeanReader reader = new BeanReader(); + reader.registerBeanClass(PoemBean.class); + PoemBean bean = (PoemBean) reader.parse(new StringReader(xml)); + assertNotNull("Expected bean to be output"); + Object[] lines = bean.getLines().toArray(); + assertEquals("Expected four lines", 4, lines.length); + assertEquals("First line of Rime Of The Ancient Mariner", "It is an ancient Mariner,", lines[0]); + assertEquals("Second line of Rime Of The Ancient Mariner", "And he stoppeth one of three.", lines[1]); + assertEquals("Third line of Rime Of The Ancient Mariner", "\"By thy long grey beard and the glittering eye,", lines[2]); + assertEquals("Fourth line of Rime Of The Ancient Mariner", "Now wherefore stopp'st thou me?\"", lines[3]); + + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]