geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r429336 - in /geronimo/xbean/trunk: xbean-spring-common/src/main/java/org/apache/xbean/spring/context/impl/ xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/ xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v...
Date Mon, 07 Aug 2006 13:25:08 GMT
Author: chirino
Date: Mon Aug  7 06:25:07 2006
New Revision: 429336

URL: http://svn.apache.org/viewvc?rev=429336&view=rev
Log:
http://issues.apache.org/jira/browse/XBEAN-36

Added:
    geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java
    geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/KegService.java
    geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java
    geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml
    geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java
    geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/KegService.java
    geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java
    geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml
Modified:
    geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java
    geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/AttributeMapping.java
    geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
    geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
    geronimo/xbean/trunk/xbean-spring-v1/src/main/java/org/apache/xbean/spring/context/v1/XBeanXmlBeanDefinitionParser.java
    geronimo/xbean/trunk/xbean-spring-v2/src/main/java/org/apache/xbean/spring/context/v2/XBeanNamespaceHandler.java

Modified: geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java?rev=429336&r1=429335&r2=429336&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java
(original)
+++ geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java
Mon Aug  7 06:25:07 2006
@@ -200,4 +200,10 @@
     public boolean isFlatProperty(String elementName, String property)  {
         return properties.getProperty(elementName + "." + property + ".flat") != null;
     }
+    
+    public String getPropertyEditor(String elementName, String property)
+    {
+        return properties.getProperty(elementName + "." + property + ".propertyEditor");
+    }
+
 }

Modified: geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/AttributeMapping.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/AttributeMapping.java?rev=429336&r1=429335&r2=429336&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/AttributeMapping.java
(original)
+++ geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/AttributeMapping.java
Mon Aug  7 06:25:07 2006
@@ -29,9 +29,11 @@
     private final String value;
     private final boolean fixed;
     private final boolean required;
+	private final String propertyEditor;
 
-    public AttributeMapping(String attributeName, String propertyName, String description,
Type type, String value, boolean fixed, boolean required) {
-        if (attributeName == null) throw new NullPointerException("attributeName");
+    public AttributeMapping(String attributeName, String propertyName, String description,
Type type, String value, boolean fixed, boolean required, String propertyEditor) {
+        this.propertyEditor = propertyEditor;
+		if (attributeName == null) throw new NullPointerException("attributeName");
         if (propertyName == null) throw new NullPointerException("propertyName");
         if (type == null) throw new NullPointerException("type");
         this.attributeName = attributeName;
@@ -86,4 +88,8 @@
     public int compareTo(Object obj) {
         return attributeName.compareTo(((AttributeMapping) obj).attributeName);
     }
+
+	public String getPropertyEditor() {
+		return propertyEditor;
+	}
 }

Modified: geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java?rev=429336&r1=429335&r2=429336&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
(original)
+++ geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
Mon Aug  7 06:25:07 2006
@@ -306,6 +306,7 @@
         boolean fixed = getBooleanProperty(propertyTag, "fixed");
         boolean required = getBooleanProperty(propertyTag, "required");
         String nestedType = getProperty(propertyTag, "nestedType");
+        String propertyEditor = getProperty(propertyTag, "propertyEditor");
 
         return new AttributeMapping(attribute,
                 beanProperty.getName(),
@@ -313,7 +314,8 @@
                 toMappingType(beanProperty.getType(), nestedType),
                 defaultValue,
                 fixed,
-                required);
+                required,
+                propertyEditor);
     }
 
     private static DocletTag getPropertyTag(BeanProperty beanProperty) {
@@ -383,7 +385,8 @@
                 toMappingType(parameter.getType(), null),
                 null,
                 false,
-                false);
+                false,
+                null);
     }
 
     private String getParameterDescription(JavaParameter parameter) {

Modified: geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java?rev=429336&r1=429335&r2=429336&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
(original)
+++ geronimo/xbean/trunk/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
Mon Aug  7 06:25:07 2006
@@ -107,6 +107,13 @@
             out.println(element.getElementName() + ".factoryMethod = " + factoryMethod);
         }
         
+        for (Iterator iter = element.getAttributes().iterator(); iter.hasNext();) {
+			AttributeMapping attribute = (AttributeMapping) iter.next();
+			if( attribute.getPropertyEditor() !=null ) {
+	            out.println(element.getElementName() + "."+attribute.getPropertyName()+ ".propertyEditor
= " + attribute.getPropertyEditor());
+			}
+		}
+        
         List flatProperties = element.getFlatProperties();
         for (Iterator itr = flatProperties.iterator(); itr.hasNext();) {
             out.println(element.getElementName() + "." + itr.next() + ".flat");

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=429336&r1=429335&r2=429336&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
Mon Aug  7 06:25:07 2006
@@ -21,10 +21,10 @@
 import java.beans.IntrospectionException;
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
+import java.beans.PropertyEditor;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.ByteArrayOutputStream;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Enumeration;
@@ -286,9 +286,10 @@
             }
             Enumeration enumeration = properties.propertyNames();
             while (enumeration.hasMoreElements()) {
-                name = (String) enumeration.nextElement();
-                Object value = getValue(properties.getProperty(name));
-                definition.getBeanDefinition().getPropertyValues().addPropertyValue(name,
value);
+                String propertyName = (String) enumeration.nextElement();
+                String propertyEditor = metadata.getPropertyEditor(getLocalName(element),
propertyName);
+                Object value = getValue(properties.getProperty(propertyName), propertyEditor);
+                definition.getBeanDefinition().getPropertyValues().addPropertyValue(propertyName,
value);
             }
         }
     }
@@ -306,15 +307,16 @@
     protected void addProperty(BeanDefinitionHolder definition, MappingMetaData metadata,
Element element,
             String localName, String value) {
         String propertyName = metadata.getPropertyName(getLocalName(element), localName);
+        String propertyEditor = metadata.getPropertyEditor(getLocalName(element), propertyName);
         if (propertyName != null) {
             QNameHelper.addPropertyValue(
                             definition.getBeanDefinition().getPropertyValues(),
                             propertyName, 
-                            getValue(value));
+                            getValue(value, propertyEditor));
         }
     }
 
-    protected Object getValue(String value) {
+    protected Object getValue(String value, String propertyEditor) {
         if (value == null)  return null;
 
         //
@@ -337,13 +339,32 @@
             }
         }
 
+        if( propertyEditor!=null ) {
+        	PropertyEditor p = createPropertyEditor(propertyEditor);
+        	p.setAsText(value);
+        	return p.getValue();
+        }
+        
         //
         // Neither null nor a reference
         //
         return value;
     }
 
-    protected String getLocalName(Element element) {
+    protected PropertyEditor createPropertyEditor(String propertyEditor) {    	
+    	ClassLoader cl = Thread.currentThread().getContextClassLoader();
+    	if( cl==null ) {
+    		cl = XBeanXmlBeanDefinitionParser.class.getClassLoader();
+    	}
+    	
+    	try {
+    		return (PropertyEditor)cl.loadClass(propertyEditor).newInstance();
+    	} catch (Throwable e){
+    		throw new IllegalArgumentException("Could not load property editor: "+propertyEditor,
e);
+    	}
+	}
+
+	protected String getLocalName(Element element) {
         String localName = element.getLocalName();
         if (localName == null) {
             localName = element.getNodeName();
@@ -565,9 +586,9 @@
                     String key = childElement.getAttribute(keyName);
                     if (key == null) throw new RuntimeException("No key defined for map "
+ entryName);
 
-                    Object keyValue = getValue(key);
+                    Object keyValue = getValue(key, null);
 
-                    Object value = getValue(getElementText(childElement));
+                    Object value = getValue(getElementText(childElement), null);
 
                     map.put(keyValue, value);
                 }

Added: geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java?rev=429336&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java
(added)
+++ geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java
Mon Aug  7 06:25:07 2006
@@ -0,0 +1,51 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,  as applicable.
+ * 
+ * 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.apache.xbean.spring.example.KegService;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * Used to verify that per propety Property Editors work correctly.
+ * 
+ * @author chirino
+ * @version $Id$
+ * @since 2.2
+ */
+public class KegXBeanTest extends SpringTestSupport {
+
+    public void testBeer() throws Exception {
+    	 
+        KegService ml1000 = (KegService) getBean("ml1000");
+        KegService empty = (KegService) getBean("empty");        
+        KegService pints5 = (KegService) getBean("pints5");
+        KegService liter20 = (KegService) getBean("liter20");
+        
+        assertEquals(1000, ml1000.getRemaining());
+        assertEquals(0, empty.getRemaining());
+        assertEquals(8750, pints5.getRemaining());        
+        assertEquals(20000, liter20.getRemaining());
+        
+    }
+
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/xbean/spring/context/keg-xbean.xml");
+    }
+
+}

Added: geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/KegService.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/KegService.java?rev=429336&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/KegService.java
(added)
+++ geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/KegService.java
Mon Aug  7 06:25:07 2006
@@ -0,0 +1,58 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,  as applicable.
+ * 
+ * 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.example;
+
+//START SNIPPET: java
+/**
+ * @org.apache.xbean.XBean element="keg" 
+ * 
+ * Used to verify that property PropertyEditors work correctly.
+ * 
+ * @author chirino
+ */
+public class KegService {
+	
+    private long remaining;
+
+	/**
+	 * Gets the amount of beer remaining in the keg (in ml)
+	 * 
+	 * @param remaining
+	 */
+	public long getRemaining() {
+		return remaining;
+	}
+
+	/**
+	 * Sets the amount of beer remaining in the keg (in ml)
+	 * 
+     * @org.apache.xbean.Property propertyEditor="org.apache.xbean.spring.example.MilliLittersPropertyEditor"
+	 * @param remaining
+	 */
+	public void setRemaining(long remaining) {
+		this.remaining = remaining;
+	}
+	
+	public long dispense( long amount ) {
+		this.remaining -= amount;
+		return this.remaining;
+	}
+
+}
+// END SNIPPET: java
+

Added: geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java?rev=429336&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java
(added)
+++ geronimo/xbean/trunk/xbean-spring-v1/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java
Mon Aug  7 06:25:07 2006
@@ -0,0 +1,65 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,  as applicable.
+ * 
+ * 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.example;
+
+import java.beans.PropertyEditorSupport;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+//START SNIPPET: java
+/**
+ * 
+ * Used to verify that per property PropertyEditors work correctly.
+ * 
+ * @author chirino
+ */
+public class MilliLittersPropertyEditor extends PropertyEditorSupport {
+
+	public void setAsText(String text) throws IllegalArgumentException {
+
+		Pattern p = Pattern.compile("^(\\d+)\\s*(l(iter)?)?$", Pattern.CASE_INSENSITIVE);
+		Matcher m = p.matcher(text);
+		if( m.matches() ) {
+			setValue(new Long(Long.parseLong(m.group(1))*1000));
+			return;
+		}
+		
+		p = Pattern.compile("^(\\d+)\\s*(ml)?$", Pattern.CASE_INSENSITIVE);
+		m = p.matcher(text);
+		if( m.matches() ) {
+			setValue(new Long(Long.parseLong(m.group(1))));
+			return;
+		}
+
+		p = Pattern.compile("^(\\d+)\\s*pints?$", Pattern.CASE_INSENSITIVE);
+	    m = p.matcher(text);
+		if( m.matches() ) {
+			long pints = Long.parseLong(m.group(1));
+			setValue(new Long( (long)(pints * 1750) ));
+			return;
+		}
+		
+		throw new IllegalArgumentException("Could convert not to long (in ml) for "+ text);		
+	}
+
+	public String getAsText() {
+		Long value = (Long) getValue();
+		return (value != null ? value.toString() : "");
+	}
+}
+//END SNIPPET: java

Added: geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml?rev=429336&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml
(added)
+++ geronimo/xbean/trunk/xbean-spring-v1/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml
Mon Aug  7 06:25:07 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- START SNIPPET: xml -->
+<beans xmlns:x="http://xbean.apache.org/schemas/pizza">
+
+  <x:keg id="ml1000" remaining="1000 ml"/>
+  <x:keg id="pints5" remaining="5 pints"/>
+  <x:keg id="liter20" remaining="20 liter"/>
+  <x:keg id="empty" remaining="0"/>
+
+</beans>
+<!-- END SNIPPET: xml -->
\ No newline at end of file

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=429336&r1=429335&r2=429336&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
Mon Aug  7 06:25:07 2006
@@ -19,6 +19,7 @@
 
 import java.beans.BeanInfo;
 import java.beans.PropertyDescriptor;
+import java.beans.PropertyEditor;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -362,9 +363,11 @@
             }
             Enumeration enumeration = properties.propertyNames();
             while (enumeration.hasMoreElements()) {
-                name = (String) enumeration.nextElement();
-                Object value = getValue(properties.getProperty(name));
-                definition.getBeanDefinition().getPropertyValues().addPropertyValue(name,
value);
+                String propertyName = (String) enumeration.nextElement();
+                String propertyEditor = metadata.getPropertyEditor(getLocalName(element),
propertyName);
+                
+                Object value = getValue(properties.getProperty(propertyName), propertyEditor);
+                definition.getBeanDefinition().getPropertyValues().addPropertyValue(propertyName,
value);
             }
         }
     }
@@ -382,13 +385,14 @@
     protected void addProperty(BeanDefinitionHolder definition, MappingMetaData metadata,
Element element,
             String localName, String value) {
         String propertyName = metadata.getPropertyName(getLocalName(element), localName);
+        String propertyEditor = metadata.getPropertyEditor(getLocalName(element), propertyName);
         if (propertyName != null) {
             definition.getBeanDefinition().getPropertyValues().addPropertyValue(
-                            propertyName, getValue(value));
+                            propertyName, getValue(value,propertyEditor));
         }
     }
 
-    protected Object getValue(String value) {
+    protected Object getValue(String value, String propertyEditor) {
         if (value == null)  return null;
 
         //
@@ -411,12 +415,31 @@
             }
         }
 
+        if( propertyEditor!=null ) {
+        	PropertyEditor p = createPropertyEditor(propertyEditor);
+        	p.setAsText(value);
+        	return p.getValue();
+        }
+        
         //
         // Neither null nor a reference
         //
         return value;
     }
 
+    protected PropertyEditor createPropertyEditor(String propertyEditor) {    	
+    	ClassLoader cl = Thread.currentThread().getContextClassLoader();
+    	if( cl==null ) {
+    		cl = XBeanNamespaceHandler.class.getClassLoader();
+    	}
+    	
+    	try {
+    		return (PropertyEditor)cl.loadClass(propertyEditor).newInstance();
+    	} catch (Throwable e){
+    		throw new IllegalArgumentException("Could not load property editor: "+propertyEditor,
e);
+    	}
+	}
+
     protected String getLocalName(Element element) {
         String localName = element.getLocalName();
         if (localName == null) {
@@ -588,9 +611,9 @@
                     String key = childElement.getAttribute(keyName);
                     if (key == null) throw new RuntimeException("No key defined for map "
+ entryName);
 
-                    Object keyValue = getValue(key);
+                    Object keyValue = getValue(key, null);
 
-                    Object value = getValue(getElementText(childElement));
+                    Object value = getValue(getElementText(childElement), null);
 
                     map.put(keyValue, value);
                 }

Added: geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java?rev=429336&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java
(added)
+++ geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/context/KegXBeanTest.java
Mon Aug  7 06:25:07 2006
@@ -0,0 +1,51 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,  as applicable.
+ * 
+ * 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.apache.xbean.spring.example.KegService;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * Used to verify that per propety Property Editors work correctly.
+ * 
+ * @author chirino
+ * @version $Id$
+ * @since 2.2
+ */
+public class KegXBeanTest extends SpringTestSupport {
+
+    public void testBeer() throws Exception {
+    	 
+        KegService ml1000 = (KegService) getBean("ml1000");
+        KegService empty = (KegService) getBean("empty");        
+        KegService pints5 = (KegService) getBean("pints5");
+        KegService liter20 = (KegService) getBean("liter20");
+        
+        assertEquals(1000, ml1000.getRemaining());
+        assertEquals(0, empty.getRemaining());
+        assertEquals(8750, pints5.getRemaining());        
+        assertEquals(20000, liter20.getRemaining());
+        
+    }
+
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/xbean/spring/context/keg-xbean.xml");
+    }
+
+}

Added: geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/KegService.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/KegService.java?rev=429336&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/KegService.java
(added)
+++ geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/KegService.java
Mon Aug  7 06:25:07 2006
@@ -0,0 +1,58 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,  as applicable.
+ * 
+ * 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.example;
+
+//START SNIPPET: java
+/**
+ * @org.apache.xbean.XBean element="keg" 
+ * 
+ * Used to verify that property PropertyEditors work correctly.
+ * 
+ * @author chirino
+ */
+public class KegService {
+	
+    private long remaining;
+
+	/**
+	 * Gets the amount of beer remaining in the keg (in ml)
+	 * 
+	 * @param remaining
+	 */
+	public long getRemaining() {
+		return remaining;
+	}
+
+	/**
+	 * Sets the amount of beer remaining in the keg (in ml)
+	 * 
+     * @org.apache.xbean.Property propertyEditor="org.apache.xbean.spring.example.MilliLittersPropertyEditor"
+	 * @param remaining
+	 */
+	public void setRemaining(long remaining) {
+		this.remaining = remaining;
+	}
+	
+	public long dispense( long amount ) {
+		this.remaining -= amount;
+		return this.remaining;
+	}
+
+}
+// END SNIPPET: java
+

Added: geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java?rev=429336&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java
(added)
+++ geronimo/xbean/trunk/xbean-spring-v2/src/test/java/org/apache/xbean/spring/example/MilliLittersPropertyEditor.java
Mon Aug  7 06:25:07 2006
@@ -0,0 +1,65 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,  as applicable.
+ * 
+ * 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.example;
+
+import java.beans.PropertyEditorSupport;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+//START SNIPPET: java
+/**
+ * 
+ * Used to verify that per property PropertyEditors work correctly.
+ * 
+ * @author chirino
+ */
+public class MilliLittersPropertyEditor extends PropertyEditorSupport {
+
+	public void setAsText(String text) throws IllegalArgumentException {
+
+		Pattern p = Pattern.compile("^(\\d+)\\s*(l(iter)?)?$", Pattern.CASE_INSENSITIVE);
+		Matcher m = p.matcher(text);
+		if( m.matches() ) {
+			setValue(new Long(Long.parseLong(m.group(1))*1000));
+			return;
+		}
+		
+		p = Pattern.compile("^(\\d+)\\s*(ml)?$", Pattern.CASE_INSENSITIVE);
+		m = p.matcher(text);
+		if( m.matches() ) {
+			setValue(new Long(Long.parseLong(m.group(1))));
+			return;
+		}
+
+		p = Pattern.compile("^(\\d+)\\s*pints?$", Pattern.CASE_INSENSITIVE);
+	    m = p.matcher(text);
+		if( m.matches() ) {
+			long pints = Long.parseLong(m.group(1));
+			setValue(new Long( (long)(pints * 1750) ));
+			return;
+		}
+		
+		throw new IllegalArgumentException("Could convert not to long (in ml) for "+ text);		
+	}
+
+	public String getAsText() {
+		Long value = (Long) getValue();
+		return (value != null ? value.toString() : "");
+	}
+}
+//END SNIPPET: java

Added: geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml?rev=429336&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml
(added)
+++ geronimo/xbean/trunk/xbean-spring-v2/src/test/resources/org/apache/xbean/spring/context/keg-xbean.xml
Mon Aug  7 06:25:07 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- START SNIPPET: xml -->
+<beans xmlns:x="http://xbean.apache.org/schemas/pizza">
+
+  <x:keg id="ml1000" remaining="1000 ml"/>
+  <x:keg id="pints5" remaining="5 pints"/>
+  <x:keg id="liter20" remaining="20 liter"/>
+  <x:keg id="empty" remaining="0"/>
+
+</beans>
+<!-- END SNIPPET: xml -->



Mime
View raw message