geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r397934 - in /geronimo/xbean/trunk/xbean-spring/src: main/java/org/apache/xbean/spring/context/impl/ main/java/org/apache/xbean/spring/generator/ test/java/org/apache/xbean/spring/context/ test/java/org/apache/xbean/spring/example/ test/jav...
Date Fri, 28 Apr 2006 15:51:57 GMT
Author: gnodet
Date: Fri Apr 28 08:51:55 2006
New Revision: 397934

URL: http://svn.apache.org/viewcvs?rev=397934&view=rev
Log:
XBEAN-8: Support flat collections
XBEAN-9: Support flat properties

Added:
    geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingSpringTest.java
    geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingXBeanTest.java
    geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/Recipe.java
    geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/RecipeService.java
    geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-normal.xml
    geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-xbean.xml
Modified:
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/XBeanXmlBeanDefinitionParser.java
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/ElementMapping.java
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
    geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java?rev=397934&r1=397933&r2=397934&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java
Fri Apr 28 08:51:55 2006
@@ -191,4 +191,13 @@
     public String getMapKeyName(String elementName, String property) {
         return properties.getProperty(elementName + "." + property + ".map.keyName");
     }
+
+    public String getFlatCollectionProperty(String elementName, String property)
+    {
+        return properties.getProperty(elementName + "." + property + ".flatCollection");
+    }
+    
+    public boolean isFlatProperty(String elementName, String property)  {
+        return properties.getProperty(elementName + "." + property + ".flat") != null;
+    }
 }

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/XBeanXmlBeanDefinitionParser.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/XBeanXmlBeanDefinitionParser.java?rev=397934&r1=397933&r2=397934&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/XBeanXmlBeanDefinitionParser.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/XBeanXmlBeanDefinitionParser.java
Fri Apr 28 08:51:55 2006
@@ -37,6 +37,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.MutablePropertyValues;
+import org.springframework.beans.PropertyValue;
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanDefinitionHolder;
@@ -44,6 +45,7 @@
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.beans.factory.support.ManagedList;
 import org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.support.AbstractApplicationContext;
@@ -121,6 +123,39 @@
     /**
      * Parses the non-standard XML element as a Spring bean definition
      */
+    protected BeanDefinitionHolder parseBeanFromExtensionElement(Element element, String
parentClass, String property) {
+        String uri = element.getNamespaceURI();
+        String localName = getLocalName(element);
+
+        MappingMetaData metadata = findNamespaceProperties(uri, localName);
+        if (metadata != null) {
+            // lets see if we configured the localName to a bean class
+            String className = getPropertyDescriptor(parentClass, property).getPropertyType().getName();
+            if (className != null) {
+                return parseBeanFromExtensionElement(element, metadata, className);
+            }
+        }
+        return null;
+    }
+
+    private BeanDefinitionHolder parseBeanFromExtensionElement(Element element, MappingMetaData
metadata, String className) {
+        Element original = cloneElement(element);
+        // lets assume the class name == the package name plus the
+        element.setAttributeNS(null, "class", className);
+        addSpringAttributeValues(className, element);
+        BeanDefinitionHolder definition = parseBeanDefinitionElement(element, false);
+        addAttributeProperties(definition, metadata, className, original);
+        addContentProperty(definition, metadata, element);
+        addNestedPropertyElements(definition, metadata, className, element);
+        coerceNamespaceAwarePropertyValues(definition, element);
+        declareLifecycleMethods(definition, metadata, element);
+        namedConstructorArgs.processParameters(definition, metadata);
+        return definition;
+    }
+    
+    /**
+     * Parses the non-standard XML element as a Spring bean definition
+     */
     protected BeanDefinitionHolder parseBeanFromExtensionElement(Element element) {
         String uri = element.getNamespaceURI();
         String localName = getLocalName(element);
@@ -130,18 +165,7 @@
             // lets see if we configured the localName to a bean class
             String className = metadata.getClassName(localName);
             if (className != null) {
-                Element original = cloneElement(element);
-                // lets assume the class name == the package name plus the
-                element.setAttributeNS(null, "class", className);
-                addSpringAttributeValues(className, element);
-                BeanDefinitionHolder definition = parseBeanDefinitionElement(element, false);
-                addAttributeProperties(definition, metadata, className, original);
-                addContentProperty(definition, metadata, element);
-                addNestedPropertyElements(definition, metadata, className, element);
-                coerceNamespaceAwarePropertyValues(definition, element);
-                declareLifecycleMethods(definition, metadata, element);
-                namedConstructorArgs.processParameters(definition, metadata);
-                return definition;
+                return parseBeanFromExtensionElement(element, metadata, className);
             } else {
                 throw new BeanDefinitionStoreException("Unrecognized xbean element mapping:
" + localName + " in namespace " + uri);
             }
@@ -333,6 +357,7 @@
     protected void addNestedPropertyElements(BeanDefinitionHolder definition, MappingMetaData
metadata,
             String className, Element element) {
         NodeList nl = element.getChildNodes();
+
         for (int i = 0; i < nl.getLength(); i++) {
             Node node = nl.item(i);
             if (node instanceof Element) {
@@ -356,12 +381,33 @@
                         value = parseListElement(childElement, propertyName);
                     }
                     else {
-                        propertyName = metadata.getNestedProperty(getLocalName(element),
localName);
+                        propertyName = metadata.getFlatCollectionProperty(getLocalName(element),
localName);
                         if (propertyName != null) {
-                            // lets find the first child bean that parses fine
-                            value = parseChildExtensionBean(childElement);
+                            Object def = parseBeanFromExtensionElement(childElement);
+                            PropertyValue pv = definition.getBeanDefinition().getPropertyValues().getPropertyValue(propertyName);
+                            if (pv != null) {
+                                Collection l = (Collection) pv.getValue();
+                                l.add(def);
+                                continue;
+                            } else {
+                                ManagedList l = new ManagedList();
+                                l.add(def);
+                                value = l;
+                            }
+                        } else {
+                            propertyName = metadata.getNestedProperty(getLocalName(element),
localName);
+                            if (propertyName != null) {
+                                // lets find the first child bean that parses fine
+                                value = parseChildExtensionBean(childElement);
+                            }
                         }
                     }
+                    
+                    if (propertyName == null && metadata.isFlatProperty(getLocalName(element),
localName)) {
+                       value = parseBeanFromExtensionElement(childElement, className, localName);
+                       propertyName = localName;
+                    }
+                    
                     if (propertyName == null) {
                         value = tryParseNestedPropertyViaIntrospection(metadata, className,
childElement);
                         propertyName = localName;

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/ElementMapping.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/ElementMapping.java?rev=397934&r1=397933&r2=397934&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/ElementMapping.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/ElementMapping.java
Fri Apr 28 08:51:55 2006
@@ -42,9 +42,13 @@
     private final Set attributes;
     private final Map attributesByName;
     private final List constructors;
+    private final List flatProperties;
     private final Map maps;
+    private final Map flatCollections;
     
-    public ElementMapping(String namespace, String elementName, String className, String
description, boolean rootElement, String initMethod, String destroyMethod, String factoryMethod,
String contentProperty, Set attributes, List constructors, Map maps) {
+    public ElementMapping(String namespace, String elementName, String className, String
description, 
+            boolean rootElement, String initMethod, String destroyMethod, String factoryMethod,

+            String contentProperty, Set attributes, List constructors, List flatProperties,
Map maps, Map flatCollections) {
         if (namespace == null) throw new NullPointerException("namespace");
         if (elementName == null) throw new NullPointerException("elementName");
         if (className == null) throw new NullPointerException("className");
@@ -63,6 +67,8 @@
         this.constructors = constructors;
         this.attributes = Collections.unmodifiableSet(new TreeSet(attributes));
         this.maps = Collections.unmodifiableMap(maps);
+        this.flatProperties = Collections.unmodifiableList(flatProperties);
+        this.flatCollections = Collections.unmodifiableMap(flatCollections);
         
         Map attributesByName = new HashMap();
         for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
@@ -124,6 +130,14 @@
         return (MapMapping) maps.get(name);
     }
     
+    public Map getFlatCollections() {
+        return flatCollections;
+    }
+
+    public List getFlatProperties() {
+        return flatProperties;
+    }
+
     public List getConstructors() {
         return constructors;
     }

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java?rev=397934&r1=397933&r2=397934&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
Fri Apr 28 08:51:55 2006
@@ -16,17 +16,6 @@
  */
 package org.apache.xbean.spring.generator;
 
-import com.thoughtworks.qdox.JavaDocBuilder;
-import com.thoughtworks.qdox.model.BeanProperty;
-import com.thoughtworks.qdox.model.DocletTag;
-import com.thoughtworks.qdox.model.JavaClass;
-import com.thoughtworks.qdox.model.JavaMethod;
-import com.thoughtworks.qdox.model.JavaParameter;
-import com.thoughtworks.qdox.model.JavaSource;
-import com.thoughtworks.qdox.model.Type;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -39,6 +28,18 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.BeanProperty;
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaMethod;
+import com.thoughtworks.qdox.model.JavaParameter;
+import com.thoughtworks.qdox.model.JavaSource;
+import com.thoughtworks.qdox.model.Type;
+
 /**
  * @author Dain Sundstrom
  * @version $Id$
@@ -51,6 +52,9 @@
     public static final String DESTROY_METHOD_ANNOTATION = "org.apache.xbean.DestroyMethod";
     public static final String FACTORY_METHOD_ANNOTATION = "org.apache.xbean.FactoryMethod";
     public static final String MAP_ANNOTATION = "org.apache.xbean.Map";
+    public static final String FLAT_PROPERTY_ANNOTATION = "org.apache.xbean.Flat";
+    public static final String FLAT_COLLECTION_ANNOTATION = "org.apache.xbean.FlatCollection";
+    public static final String ELEMENT_ANNOTATION = "org.apache.xbean.Element";
     
     private static final Log log = LogFactory.getLog(QdoxMappingLoader.class);
     private final String defaultNamespace;
@@ -162,6 +166,8 @@
         String contentProperty = getProperty(xbeanTag, "contentProperty");
 
         Map mapsByPropertyName = new HashMap();
+        List flatProperties = new ArrayList();
+        Map flatCollections = new HashMap();
         Set attributes = new HashSet();
         Map attributesByPropertyName = new HashMap();
         BeanProperty[] beanProperties = javaClass.getBeanProperties();
@@ -183,6 +189,19 @@
                                 mapTag.getNamedParameter("keyName"));
                         mapsByPropertyName.put(beanProperty.getName(), mm);
                     }
+                    
+                    DocletTag flatColTag = acc.getTagByName(FLAT_COLLECTION_ANNOTATION);
+                    if (flatColTag != null) {
+                        String childName = flatColTag.getNamedParameter("childElement");
+                        if (childName == null)
+                            throw new InvalidModelException("Flat collections must specify
the childElement attribute.");
+                        flatCollections.put(beanProperty.getName(), childName);
+                    }
+                    
+                    DocletTag flatPropTag = acc.getTagByName(FLAT_PROPERTY_ANNOTATION);
+                    if (flatPropTag != null) {
+                        flatProperties.add(beanProperty.getName());
+                    }
                 }
             }
         }
@@ -246,7 +265,9 @@
                 contentProperty,
                 attributes,
                 constructorArgs,
-                mapsByPropertyName);
+                flatProperties,
+                mapsByPropertyName,
+                flatCollections);
     }
 
     private String getElementName(JavaClass javaClass, DocletTag tag) {

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java?rev=397934&r1=397933&r2=397934&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
Fri Apr 28 08:51:55 2006
@@ -95,12 +95,24 @@
             out.println(element.getElementName() + ".factoryMethod = " + factoryMethod);
         }
         
+        List flatProperties = element.getFlatProperties();
+        for (Iterator itr = flatProperties.iterator(); itr.hasNext();) {
+            out.println(element.getElementName() + "." + itr.next() + ".flat");
+        }
+
         Map maps = element.getMapMappings();
         for (Iterator itr = maps.entrySet().iterator(); itr.hasNext();) {
             Map.Entry entry = (Map.Entry) itr.next();
             MapMapping mm = (MapMapping) entry.getValue();
             out.println(element.getElementName() + "." + entry.getKey() + ".map.entryName
= " + mm.getEntryName());
             out.println(element.getElementName() + "." + entry.getKey() + ".map.keyName =
" + mm.getKeyName());
+        }
+        
+        Map flatCollections = element.getFlatCollections();
+        for (Iterator itr = flatCollections.entrySet().iterator(); itr.hasNext();) {
+            Map.Entry entry = (Map.Entry) itr.next();
+            String child = (String) entry.getValue();
+            out.println(element.getElementName() + "." + child + ".flatCollection = " + entry.getKey());
         }
     }
 

Added: geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingSpringTest.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingSpringTest.java?rev=397934&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingSpringTest.java
(added)
+++ geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingSpringTest.java
Fri Apr 28 08:51:55 2006
@@ -0,0 +1,50 @@
+/**
+ * 
+ * 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 java.util.List;
+
+import org.apache.xbean.spring.example.Recipe;
+import org.apache.xbean.spring.example.RecipeService;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+public class RecipeUsingSpringTest extends SpringTestSupport {
+
+    public void testRecipes() throws Exception {
+        RecipeService svc = (RecipeService) getBean("recipeService");
+
+        List list = svc.getRecipes();
+        assertNotNull(list);
+        assertEquals(2, list.size());
+        Recipe r = (Recipe) list.get(0);
+        assertEquals("Food", r.getIngredients());
+        assertEquals("Mash together", r.getInstructions());
+        
+        r = (Recipe) list.get(1);
+        assertEquals("Food", r.getIngredients());
+        assertEquals("Mash together", r.getInstructions());
+        
+        assertNotNull(svc.getTopRecipe());
+        assertEquals("Food", svc.getTopRecipe().getIngredients());
+    }
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/xbean/spring/context/recipe-normal.xml");
+    }
+
+}

Added: geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingXBeanTest.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingXBeanTest.java?rev=397934&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingXBeanTest.java
(added)
+++ geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/context/RecipeUsingXBeanTest.java
Fri Apr 28 08:51:55 2006
@@ -0,0 +1,28 @@
+/**
+ * 
+ * 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.springframework.context.support.AbstractXmlApplicationContext;
+
+public class RecipeUsingXBeanTest extends RecipeUsingSpringTest {
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/xbean/spring/context/recipe-xbean.xml");
+    }
+
+}

Added: geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/Recipe.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/Recipe.java?rev=397934&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/Recipe.java
(added)
+++ geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/Recipe.java
Fri Apr 28 08:51:55 2006
@@ -0,0 +1,49 @@
+/**
+ * 
+ * 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;
+
+/**
+ * @org.apache.xbean.XBean element="recipe"
+ * @author Dan Diephouse
+ */
+public class Recipe
+{
+    private String ingredients;
+    private String instructions;
+    
+    public String getInstructions()
+    {
+        return instructions;
+    }
+
+    public void setInstructions(String instructions)
+    {
+        this.instructions = instructions;
+    }
+
+    public String getIngredients()
+    {
+        return ingredients;
+    }
+
+    public void setIngredients(String ingredients)
+    {
+        this.ingredients = ingredients;
+    }
+
+}

Added: geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/RecipeService.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/RecipeService.java?rev=397934&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/RecipeService.java
(added)
+++ geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/example/RecipeService.java
Fri Apr 28 08:51:55 2006
@@ -0,0 +1,55 @@
+/**
+ * 
+ * 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.util.List;
+/**
+ * @org.apache.xbean.XBean element="recipe-service"
+ * @author Dan Diephouse
+ */
+public class RecipeService
+{
+    private List recipes;
+    private Recipe topRecipe;
+    
+    /**
+     * @org.apache.xbean.FlatCollection childElement="recipe"
+     * @return
+     */
+    public List getRecipes()
+    {
+        return recipes;
+    }
+
+    public void setRecipes(List recipes)
+    {
+        this.recipes = recipes;
+    }
+
+    /**
+     * @org.apache.xbean.Flat
+     * @return
+     */
+    public Recipe getTopRecipe() {
+        return topRecipe;
+    }
+
+    public void setTopRecipe(Recipe topRecipe) {
+        this.topRecipe = topRecipe;
+    }
+}

Modified: geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java?rev=397934&r1=397933&r2=397934&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
Fri Apr 28 08:51:55 2006
@@ -16,15 +16,16 @@
  */
 package org.apache.xbean.spring.generator;
 
-import junit.framework.TestCase;
-
+import java.beans.PropertyEditorManager;
 import java.io.File;
+import java.util.Arrays;
 import java.util.Iterator;
-import java.util.Set;
-import java.util.List;
 import java.util.LinkedList;
-import java.util.Arrays;
-import java.beans.PropertyEditorManager;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
 
 /**
  * @author Dain Sundstrom
@@ -65,6 +66,13 @@
         assertNotNull(beerId);
         AttributeMapping beerName = beer.getAttribute("name");
         assertNotNull(beerName);
+        
+        ElementMapping recipeService = defaultNamespace.getElement("recipe-service");
+        assertNotNull(recipeService);
+        
+        Map flatCollections = recipeService.getFlatCollections();
+        assertNotNull(flatCollections);
+        assertEquals(1, flatCollections.size());
     }
 
     public void testPropertyEditor() {

Added: geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-normal.xml
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-normal.xml?rev=397934&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-normal.xml
(added)
+++ geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-normal.xml
Fri Apr 28 08:51:55 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<beans>
+  <bean id="recipeService" class="org.apache.xbean.spring.example.RecipeService">
+    <property name="recipes">
+      <list>
+        <bean class="org.apache.xbean.spring.example.Recipe">
+          <property name="instructions" value="Mash together" />
+          <property name="ingredients" value="Food" />
+        </bean>
+        <bean class="org.apache.xbean.spring.example.Recipe">
+          <property name="instructions" value="Mash together" />
+          <property name="ingredients" value="Food" />
+        </bean>
+      </list>
+    </property>
+    <property name="topRecipe"> 
+      <bean class="org.apache.xbean.spring.example.Recipe">
+        <property name="instructions" value="Mash together" />
+        <property name="ingredients" value="Food" />
+      </bean>
+    </property>
+  </bean>
+</beans>

Added: geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-xbean.xml
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-xbean.xml?rev=397934&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-xbean.xml
(added)
+++ geronimo/xbean/trunk/xbean-spring/src/test/resources/org/apache/xbean/spring/context/recipe-xbean.xml
Fri Apr 28 08:51:55 2006
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:x="http://xbean.apache.org/schemas/pizza" xmlns:foo="urn:foo">
+
+  <x:recipe-service id="recipeService">
+    <x:topRecipe>
+      <x:instructions>Mash together</x:instructions>
+      <x:ingredients>Food</x:ingredients>
+    </x:topRecipe>
+    <x:recipe>
+      <x:instructions>Mash together</x:instructions>
+      <x:ingredients>Food</x:ingredients>
+    </x:recipe>
+    <x:recipe>
+      <x:instructions>Mash together</x:instructions>
+      <x:ingredients>Food</x:ingredients>
+    </x:recipe>
+  </x:recipe-service>
+
+</beans>



Mime
View raw message