geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r422101 - 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/example/ xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v...
Date Fri, 14 Jul 2006 23:56:15 GMT
Author: dain
Date: Fri Jul 14 16:56:14 2006
New Revision: 422101

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

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/java/org/apache/xbean/spring/example/BeerService.java
    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/java/org/apache/xbean/spring/example/BeerService.java

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=422101&r1=422100&r2=422101&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 16:56:14 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) {

Modified: geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/BeerService.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/BeerService.java?rev=422101&r1=422100&r2=422101&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/BeerService.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/BeerService.java
Fri Jul 14 16:56:14 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
 

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=422101&r1=422100&r2=422101&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 16:56:14 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) {

Modified: geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/BeerService.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/BeerService.java?rev=422101&r1=422100&r2=422101&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/BeerService.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/BeerService.java
Fri Jul 14 16:56:14 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
 



Mime
View raw message