geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r422102 - in /geronimo/xbean/branches/colossus: xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/ xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/ xbean-spring-v1/src/test/resources/org/apache/xbean/spring/cont...
Date Sat, 15 Jul 2006 00:00:55 GMT
Author: dain
Date: Fri Jul 14 17:00:54 2006
New Revision: 422102

URL: http://svn.apache.org/viewvc?rev=422102&view=rev
Log:
XBEAN-24  Support mixed nested properties and complex elements
Added new files from XBEAN-25 and XBEAN-26 which I forgot to commit even after warning everyone
else about the new files

Added:
    geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
    geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
    geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
    geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
Modified:
    geronimo/xbean/branches/colossus/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java
    geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml
    geronimo/xbean/branches/colossus/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java
    geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml

Modified: geronimo/xbean/branches/colossus/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java?rev=422102&r1=422101&r2=422102&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java
Fri Jul 14 17:00:54 2006
@@ -24,7 +24,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.Method;
+import java.io.ByteArrayOutputStream;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Enumeration;
@@ -267,24 +267,28 @@
             addProperty(definition, metadata, element, name, value);
         }
         else {
-            // lets stry parse a nested properties file
+            StringBuffer buffer = new StringBuffer();
             NodeList childNodes = element.getChildNodes();
-            if (childNodes.getLength() == 1 && childNodes.item(0) instanceof Text)
{
-                Text text = (Text) childNodes.item(0);
-                ByteArrayInputStream in = new ByteArrayInputStream(text.getData().getBytes());
-                Properties properties = new Properties();
-                try {
-                    properties.load(in);
-                }
-                catch (IOException e) {
-                    return;
-                }
-                Enumeration enumeration = properties.propertyNames();
-                while (enumeration.hasMoreElements()) {
-                    name = (String) enumeration.nextElement();
-                    Object value = properties.getProperty(name);
-                    definition.getBeanDefinition().getPropertyValues().addPropertyValue(name,
value);
+            for (int i = 0, size = childNodes.getLength(); i < size; i++) {
+                Node node = childNodes.item(i);
+                if (node instanceof Text) {
+                    buffer.append(((Text) node).getData());
                 }
+            }
+
+            ByteArrayInputStream in = new ByteArrayInputStream(buffer.toString().getBytes());
+            Properties properties = new Properties();
+            try {
+                properties.load(in);
+            }
+            catch (IOException e) {
+                return;
+            }
+            Enumeration enumeration = properties.propertyNames();
+            while (enumeration.hasMoreElements()) {
+                name = (String) enumeration.nextElement();
+                Object value = getValue(properties.getProperty(name));
+                definition.getBeanDefinition().getPropertyValues().addPropertyValue(name,
value);
             }
         }
     }

Added: geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java?rev=422102&view=auto
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
(added)
+++ geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
Fri Jul 14 17:00:54 2006
@@ -0,0 +1,47 @@
+/**
+ *
+ * Copyright 2006 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.xbean.spring.context;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.example.BeerService;
+
+/**
+ * @author Dain Sundstrom
+ * @version $Id$
+ * @since 2.6
+ */
+public class BeerNullTest extends SpringTestSupport {
+
+    public void testBeer() throws Exception {
+        BeerService beer = (BeerService) getBean("beerService");
+
+        assertEquals("name", "Stella", beer.getName());
+        assertEquals("id", "123", beer.getId());
+        assertEquals("source", "tap", beer.getSource());
+
+        BeerService beer2 = (BeerService) getBean("beerService2");
+
+        assertEquals("name", "Blue Moon", beer2.getName());
+        assertEquals("id", "123", beer2.getId());
+        assertNull("source", beer2.getSource());
+    }
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/xbean/spring/context/beer-xbean-null.xml");
+    }
+
+}

Added: geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml?rev=422102&view=auto
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
(added)
+++ geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
Fri Jul 14 17:00:54 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- START SNIPPET: xml -->
+<beans xmlns:b="http://xbean.apache.org/schemas/pizza" xmlns:s="http://xbean.apache.org/schemas/spring/1.0">
+
+  <b:beer s:id="beerService" id="123" name="Stella"/>
+
+  <b:beer s:id="beerService2" id="123" name="Blue Moon" source="#null"/>
+
+</beans>
+<!-- END SNIPPET: xml -->
+

Modified: geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml?rev=422102&r1=422101&r2=422102&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml
Fri Jul 14 17:00:54 2006
@@ -3,11 +3,14 @@
 <beans xmlns:p="java://org.apache.xbean.spring.example">
 
   <p:PizzaService id="pizzaService">
-      topping   Salami
       cheese    Edam
-      size      17
+
+    <!-- properties can have complex elements mixed in -->
+    <p:topping>Salami</p:topping>
+
+       size      17
   </p:PizzaService>
-  
+
 </beans>
 
 <!-- END SNIPPET: xml -->

Modified: geronimo/xbean/branches/colossus/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java?rev=422102&r1=422101&r2=422102&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java
Fri Jul 14 17:00:54 2006
@@ -343,24 +343,28 @@
             addProperty(definition, metadata, element, name, value);
         }
         else {
-            // lets stry parse a nested properties file
+            StringBuffer buffer = new StringBuffer();
             NodeList childNodes = element.getChildNodes();
-            if (childNodes.getLength() == 1 && childNodes.item(0) instanceof Text)
{
-                Text text = (Text) childNodes.item(0);
-                ByteArrayInputStream in = new ByteArrayInputStream(text.getData().getBytes());
-                Properties properties = new Properties();
-                try {
-                    properties.load(in);
-                }
-                catch (IOException e) {
-                    return;
-                }
-                Enumeration enumeration = properties.propertyNames();
-                while (enumeration.hasMoreElements()) {
-                    name = (String) enumeration.nextElement();
-                    Object value = properties.getProperty(name);
-                    definition.getBeanDefinition().getPropertyValues().addPropertyValue(name,
value);
+            for (int i = 0, size = childNodes.getLength(); i < size; i++) {
+                Node node = childNodes.item(i);
+                if (node instanceof Text) {
+                    buffer.append(((Text) node).getData());
                 }
+            }
+
+            ByteArrayInputStream in = new ByteArrayInputStream(buffer.toString().getBytes());
+            Properties properties = new Properties();
+            try {
+                properties.load(in);
+            }
+            catch (IOException e) {
+                return;
+            }
+            Enumeration enumeration = properties.propertyNames();
+            while (enumeration.hasMoreElements()) {
+                name = (String) enumeration.nextElement();
+                Object value = getValue(properties.getProperty(name));
+                definition.getBeanDefinition().getPropertyValues().addPropertyValue(name,
value);
             }
         }
     }

Added: geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java?rev=422102&view=auto
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
(added)
+++ geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
Fri Jul 14 17:00:54 2006
@@ -0,0 +1,47 @@
+/**
+ *
+ * Copyright 2006 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.xbean.spring.context;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.example.BeerService;
+
+/**
+ * @author Dain Sundstrom
+ * @version $Id$
+ * @since 2.6
+ */
+public class BeerNullTest extends SpringTestSupport {
+
+    public void testBeer() throws Exception {
+        BeerService beer = (BeerService) getBean("beerService");
+
+        assertEquals("name", "Stella", beer.getName());
+        assertEquals("id", "123", beer.getId());
+        assertEquals("source", "tap", beer.getSource());
+
+        BeerService beer2 = (BeerService) getBean("beerService2");
+
+        assertEquals("name", "Blue Moon", beer2.getName());
+        assertEquals("id", "123", beer2.getId());
+        assertNull("source", beer2.getSource());
+    }
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/xbean/spring/context/beer-xbean-null.xml");
+    }
+
+}

Added: geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml?rev=422102&view=auto
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
(added)
+++ geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
Fri Jul 14 17:00:54 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- START SNIPPET: xml -->
+<beans xmlns:b="http://xbean.apache.org/schemas/pizza" xmlns:s="http://xbean.apache.org/schemas/spring/1.0">
+
+  <b:beer s:id="beerService" id="123" name="Stella"/>
+
+  <b:beer s:id="beerService2" id="123" name="Blue Moon" source="#null"/>
+
+</beans>
+<!-- END SNIPPET: xml -->
+

Modified: geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml?rev=422102&r1=422101&r2=422102&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/pizza-xbean-properties.xml
Fri Jul 14 17:00:54 2006
@@ -3,11 +3,14 @@
 <beans xmlns:p="java://org.apache.xbean.spring.example">
 
   <p:PizzaService id="pizzaService">
-      topping   Salami
       cheese    Edam
-      size      17
+
+    <!-- properties can have complex elements mixed in -->
+    <p:topping>Salami</p:topping>
+
+       size      17
   </p:PizzaService>
-  
+
 </beans>
 
 <!-- END SNIPPET: xml -->



Mime
View raw message