geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r427622 - in /geronimo/xbean/trunk: 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/java/org/apache/xbean/spring/example/ xbean-spring...
Date Tue, 01 Aug 2006 15:44:28 GMT
Author: gnodet
Date: Tue Aug  1 08:44:27 2006
New Revision: 427622

URL: http://svn.apache.org/viewvc?rev=427622&view=rev
Log:
XBEAN-25: Support for #null short hand for a null value

Added:
    geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
    geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
    geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
    geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
Modified:
    geronimo/xbean/trunk/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java
    geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/BeerService.java
    geronimo/xbean/trunk/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java
    geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/BeerService.java

Modified: geronimo/xbean/trunk/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java?rev=427622&r1=427621&r2=427622&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java
(original)
+++ geronimo/xbean/trunk/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java
Tue Aug  1 08:44:27 2006
@@ -99,6 +99,7 @@
     private static final String JAVA_PACKAGE_PREFIX = "java://";
 
     private static final String BEAN_REFERENCE_PREFIX = "#";
+    private static final String NULL_REFERENCE = "#null";
 
     private Set reservedElementNames = new HashSet(Arrays.asList(RESERVED_ELEMENT_NAMES));
     private Set reservedBeanAttributeNames = new HashSet(Arrays.asList(RESERVED_BEAN_ATTRIBUTE_NAMES));
@@ -312,23 +313,30 @@
     protected Object getValue(String value) {
         if (value == null)  return null;
 
-        boolean reference = false;
+        //
+        // If value is #null then we are explicitly setting the value null instead of an
empty string
+        //
+        if (NULL_REFERENCE.equals(value)) {
+            return null;
+        }
+
+        //
+        // If value starts with # then we have a ref
+        //
         if (value.startsWith(BEAN_REFERENCE_PREFIX)) {
+            // strip off the #
             value = value.substring(BEAN_REFERENCE_PREFIX.length());
 
-            // we could be an escaped string
+            // if the new value starts with a #, then we had an excaped value (e.g. ##value)
             if (!value.startsWith(BEAN_REFERENCE_PREFIX)) {
-                reference = true;
+                return new RuntimeBeanReference(value);
             }
         }
 
-        if (reference) {
-            // TOOD handle custom reference types like local or queries etc
-            return new RuntimeBeanReference(value);
-        }
-        else {
-            return value;
-        }
+        //
+        // Neither null nor a reference
+        //
+        return value;
     }
 
     protected String getLocalName(Element element) {

Added: geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java?rev=427622&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
(added)
+++ geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
Tue Aug  1 08:44:27 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");
+    }
+
+}

Modified: geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/BeerService.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/BeerService.java?rev=427622&r1=427621&r2=427622&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/BeerService.java
(original)
+++ geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/BeerService.java
Tue Aug  1 08:44:27 2006
@@ -30,6 +30,7 @@
 public class BeerService {
     private String id;
     private String name;
+    private String source = "tap";
 
     public String getId() {
         return id;
@@ -47,6 +48,13 @@
         this.name = name;
     }
 
+    public String getSource() {
+        return source;
+    }
+
+    public void setSource(String source) {
+        this.source = source;
+    }
 }
 // END SNIPPET: bean
 

Added: geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml?rev=427622&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
(added)
+++ geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
Tue Aug  1 08:44:27 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/trunk/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java?rev=427622&r1=427621&r2=427622&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java
(original)
+++ geronimo/xbean/trunk/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java
Tue Aug  1 08:44:27 2006
@@ -131,6 +131,7 @@
     private static final String JAVA_PACKAGE_PREFIX = "java://";
 
     private static final String BEAN_REFERENCE_PREFIX = "#";
+    private static final String NULL_REFERENCE = "#null";
 
     private Set reservedElementNames = new HashSet(Arrays.asList(RESERVED_ELEMENT_NAMES));
     private Set reservedBeanAttributeNames = new HashSet(Arrays.asList(RESERVED_BEAN_ATTRIBUTE_NAMES));
@@ -386,23 +387,30 @@
     protected Object getValue(String value) {
         if (value == null)  return null;
 
-        boolean reference = false;
+        //
+        // If value is #null then we are explicitly setting the value null instead of an
empty string
+        //
+        if (NULL_REFERENCE.equals(value)) {
+            return null;
+        }
+
+        //
+        // If value starts with # then we have a ref
+        //
         if (value.startsWith(BEAN_REFERENCE_PREFIX)) {
+            // strip off the #
             value = value.substring(BEAN_REFERENCE_PREFIX.length());
 
-            // we could be an escaped string
+            // if the new value starts with a #, then we had an excaped value (e.g. ##value)
             if (!value.startsWith(BEAN_REFERENCE_PREFIX)) {
-                reference = true;
+                return new RuntimeBeanReference(value);
             }
         }
 
-        if (reference) {
-            // TOOD handle custom reference types like local or queries etc
-            return new RuntimeBeanReference(value);
-        }
-        else {
-            return value;
-        }
+        //
+        // Neither null nor a reference
+        //
+        return value;
     }
 
     protected String getLocalName(Element element) {

Added: geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java?rev=427622&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
(added)
+++ geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/BeerNullTest.java
Tue Aug  1 08:44:27 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");
+    }
+
+}

Modified: geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/BeerService.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/BeerService.java?rev=427622&r1=427621&r2=427622&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/BeerService.java
(original)
+++ geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/BeerService.java
Tue Aug  1 08:44:27 2006
@@ -30,6 +30,7 @@
 public class BeerService {
     private String id;
     private String name;
+    private String source = "tap";
 
     public String getId() {
         return id;
@@ -47,6 +48,13 @@
         this.name = name;
     }
 
+    public String getSource() {
+        return source;
+    }
+
+    public void setSource(String source) {
+        this.source = source;
+    }
 }
 // END SNIPPET: bean
 

Added: geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml?rev=427622&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
(added)
+++ geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/beer-xbean-null.xml
Tue Aug  1 08:44:27 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 -->
+



Mime
View raw message